org-agenda.el (org-agenda-ndays): Fix bug
[org-mode.git] / lisp / org-agenda.el
blobf81b715e0ea6484fc5aed4e8fa14dc697c2a2324
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (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-tags-todo-honor-ignore-options nil
744 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
745 The variables
746 `org-agenda-todo-ignore-with-date',
747 `org-agenda-todo-ignore-timestamp',
748 `org-agenda-todo-ignore-scheduled',
749 `org-agenda-todo-ignore-deadlines'
750 make the global TODO list skip entries that have time stamps of certain
751 kinds. If this option is set, the same options will also apply for the
752 tags-todo search, which is the general tags/property matcher
753 restricted to unfinished TODO entries only."
754 :group 'org-agenda-skip
755 :group 'org-agenda-todo-list
756 :group 'org-agenda-match-view
757 :type 'boolean)
759 (defcustom org-agenda-skip-scheduled-if-done nil
760 "Non-nil means don't show scheduled items in agenda when they are done.
761 This is relevant for the daily/weekly agenda, not for the TODO list. And
762 it applies only to the actual date of the scheduling. Warnings about
763 an item with a past scheduling dates are always turned off when the item
764 is DONE."
765 :group 'org-agenda-skip
766 :group 'org-agenda-daily/weekly
767 :type 'boolean)
769 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
770 "Non-nil means skip scheduling line if same entry shows because of deadline.
771 In the agenda of today, an entry can show up multiple times because
772 it is both scheduled and has a nearby deadline, and maybe a plain time
773 stamp as well.
774 When this variable is t, then only the deadline is shown and the fact that
775 the entry is scheduled today or was scheduled previously is not shown.
776 When this variable is nil, the entry will be shown several times. When
777 the variable is the symbol `not-today', then skip scheduled previously,
778 but not scheduled today."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type '(choice
782 (const :tag "Never" nil)
783 (const :tag "Always" t)
784 (const :tag "Not when scheduled today" not-today)))
786 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
787 "Non-nil means skip timestamp line if same entry shows because of deadline.
788 In the agenda of today, an entry can show up multiple times
789 because it has both a plain timestamp and has a nearby deadline.
790 When this variable is t, then only the deadline is shown and the
791 fact that the entry has a timestamp for or including today is not
792 shown. When this variable is nil, the entry will be shown
793 several times."
794 :group 'org-agenda-skip
795 :group 'org-agenda-daily/weekly
796 :version "24.1"
797 :type '(choice
798 (const :tag "Never" nil)
799 (const :tag "Always" t)))
801 (defcustom org-agenda-skip-deadline-if-done nil
802 "Non-nil means don't show deadlines when the corresponding item is done.
803 When nil, the deadline is still shown and should give you a happy feeling.
804 This is relevant for the daily/weekly agenda. And it applied only to the
805 actually date of the deadline. Warnings about approaching and past-due
806 deadlines are always turned off when the item is DONE."
807 :group 'org-agenda-skip
808 :group 'org-agenda-daily/weekly
809 :type 'boolean)
811 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
812 "Non-nil means skip deadline prewarning when entry is also scheduled.
813 This will apply on all days where a prewarning for the deadline would
814 be shown, but not at the day when the entry is actually due. On that day,
815 the deadline will be shown anyway.
816 This variable may be set to nil, t, or a number which will then give
817 the number of days before the actual deadline when the prewarnings
818 should resume.
819 This can be used in a workflow where the first showing of the deadline will
820 trigger you to schedule it, and then you don't want to be reminded of it
821 because you will take care of it on the day when scheduled."
822 :group 'org-agenda-skip
823 :group 'org-agenda-daily/weekly
824 :version "24.1"
825 :type '(choice
826 (const :tag "Alwas show prewarning" nil)
827 (const :tag "Remove prewarning if entry is scheduled" t)
828 (integer :tag "Restart prewarning N days before deadline")))
830 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
831 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
832 When non-nil, after the search for timestamps has matched once in an
833 entry, the rest of the entry will not be searched."
834 :group 'org-agenda-skip
835 :type 'boolean)
837 (defcustom org-agenda-skip-timestamp-if-done nil
838 "Non-nil means don't select item by timestamp or -range if it is DONE."
839 :group 'org-agenda-skip
840 :group 'org-agenda-daily/weekly
841 :type 'boolean)
843 (defcustom org-agenda-dim-blocked-tasks t
844 "Non-nil means dim blocked tasks in the agenda display.
845 This causes some overhead during agenda construction, but if you
846 have turned on `org-enforce-todo-dependencies',
847 `org-enforce-todo-checkbox-dependencies', or any other blocking
848 mechanism, this will create useful feedback in the agenda.
850 Instead of t, this variable can also have the value `invisible'.
851 Then blocked tasks will be invisible and only become visible when
852 they become unblocked. An exemption to this behavior is when a task is
853 blocked because of unchecked checkboxes below it. Since checkboxes do
854 not show up in the agenda views, making this task invisible you remove any
855 trace from agenda views that there is something to do. Therefore, a task
856 that is blocked because of checkboxes will never be made invisible, it
857 will only be dimmed."
858 :group 'org-agenda-daily/weekly
859 :group 'org-agenda-todo-list
860 :type '(choice
861 (const :tag "Do not dim" nil)
862 (const :tag "Dim to a gray face" t)
863 (const :tag "Make invisible" invisible)))
865 (defcustom org-timeline-show-empty-dates 3
866 "Non-nil means `org-timeline' also shows dates without an entry.
867 When nil, only the days which actually have entries are shown.
868 When t, all days between the first and the last date are shown.
869 When an integer, show also empty dates, but if there is a gap of more than
870 N days, just insert a special line indicating the size of the gap."
871 :group 'org-agenda-skip
872 :type '(choice
873 (const :tag "None" nil)
874 (const :tag "All" t)
875 (integer :tag "at most")))
877 (defgroup org-agenda-startup nil
878 "Options concerning initial settings in the Agenda in Org Mode."
879 :tag "Org Agenda Startup"
880 :group 'org-agenda)
882 (defcustom org-agenda-menu-show-matcher t
883 "Non-nil means show the match string in the agenda dispatcher menu.
884 When nil, the matcher string is not shown, but is put into the help-echo
885 property so than moving the mouse over the command shows it.
886 Setting it to nil is good if matcher strings are very long and/or if
887 you want to use two-columns display (see `org-agenda-menu-two-columns')."
888 :group 'org-agenda
889 :version "24.1"
890 :type 'boolean)
892 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
894 (defcustom org-agenda-menu-two-columns nil
895 "Non-nil means, use two columns to show custom commands in the dispatcher.
896 If you use this, you probably want to set `org-agenda-menu-show-matcher'
897 to nil."
898 :group 'org-agenda
899 :version "24.1"
900 :type 'boolean)
902 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
903 (defcustom org-agenda-finalize-hook nil
904 "Hook run just before displaying an agenda buffer.
905 The buffer is still writable when the hook is called.
907 You can modify some of the buffer substrings but you should be
908 extra careful not to modify the text properties of the agenda
909 headlines as the agenda display heavily relies on them."
910 :group 'org-agenda-startup
911 :type 'hook)
913 (defcustom org-agenda-mouse-1-follows-link nil
914 "Non-nil means mouse-1 on a link will follow the link in the agenda.
915 A longer mouse click will still set point. Does not work on XEmacs.
916 Needs to be set before org.el is loaded."
917 :group 'org-agenda-startup
918 :type 'boolean)
920 (defcustom org-agenda-start-with-follow-mode nil
921 "The initial value of follow mode in a newly created agenda window."
922 :group 'org-agenda-startup
923 :type 'boolean)
925 (defcustom org-agenda-follow-indirect nil
926 "Non-nil means `org-agenda-follow-mode' displays only the
927 current item's tree, in an indirect buffer."
928 :group 'org-agenda
929 :version "24.1"
930 :type 'boolean)
932 (defcustom org-agenda-show-outline-path t
933 "Non-nil means show outline path in echo area after line motion."
934 :group 'org-agenda-startup
935 :type 'boolean)
937 (defcustom org-agenda-start-with-entry-text-mode nil
938 "The initial value of entry-text-mode in a newly created agenda window."
939 :group 'org-agenda-startup
940 :type 'boolean)
942 (defcustom org-agenda-entry-text-maxlines 5
943 "Number of text lines to be added when `E' is pressed in the agenda.
945 Note that this variable only used during agenda display. Add add entry text
946 when exporting the agenda, configure the variable
947 `org-agenda-add-entry-ext-maxlines'."
948 :group 'org-agenda
949 :type 'integer)
951 (defcustom org-agenda-entry-text-exclude-regexps nil
952 "List of regular expressions to clean up entry text.
953 The complete matches of all regular expressions in this list will be
954 removed from entry text before it is shown in the agenda."
955 :group 'org-agenda
956 :type '(repeat (regexp)))
958 (defvar org-agenda-entry-text-cleanup-hook nil
959 "Hook that is run after basic cleanup of entry text to be shown in agenda.
960 This cleanup is done in a temporary buffer, so the function may inspect and
961 change the entire buffer.
962 Some default stuff like drawers and scheduling/deadline dates will already
963 have been removed when this is called, as will any matches for regular
964 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
966 (defvar org-agenda-include-inactive-timestamps nil
967 "Non-nil means include inactive time stamps in agenda and timeline.
968 Dynamically scoped.")
970 (defgroup org-agenda-windows nil
971 "Options concerning the windows used by the Agenda in Org Mode."
972 :tag "Org Agenda Windows"
973 :group 'org-agenda)
975 (defcustom org-agenda-window-setup 'reorganize-frame
976 "How the agenda buffer should be displayed.
977 Possible values for this option are:
979 current-window Show agenda in the current window, keeping all other windows.
980 other-window Use `switch-to-buffer-other-window' to display agenda.
981 reorganize-frame Show only two windows on the current frame, the current
982 window and the agenda.
983 other-frame Use `switch-to-buffer-other-frame' to display agenda.
984 Also, when exiting the agenda, kill that frame.
985 See also the variable `org-agenda-restore-windows-after-quit'."
986 :group 'org-agenda-windows
987 :type '(choice
988 (const current-window)
989 (const other-frame)
990 (const other-window)
991 (const reorganize-frame)))
993 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
994 "The min and max height of the agenda window as a fraction of frame height.
995 The value of the variable is a cons cell with two numbers between 0 and 1.
996 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
997 :group 'org-agenda-windows
998 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1000 (defcustom org-agenda-restore-windows-after-quit nil
1001 "Non-nil means restore window configuration upon exiting agenda.
1002 Before the window configuration is changed for displaying the agenda,
1003 the current status is recorded. When the agenda is exited with
1004 `q' or `x' and this option is set, the old state is restored. If
1005 `org-agenda-window-setup' is `other-frame', the value of this
1006 option will be ignored."
1007 :group 'org-agenda-windows
1008 :type 'boolean)
1010 (defcustom org-agenda-ndays nil
1011 "Number of days to include in overview display.
1012 Should be 1 or 7.
1013 Obsolete, see `org-agenda-span'."
1014 :group 'org-agenda-daily/weekly
1015 :type 'integer)
1017 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1019 (defcustom org-agenda-span 'week
1020 "Number of days to include in overview display.
1021 Can be day, week, month, year, or any number of days.
1022 Custom commands can set this variable in the options section."
1023 :group 'org-agenda-daily/weekly
1024 :type '(choice (const :tag "Day" day)
1025 (const :tag "Week" week)
1026 (const :tag "Month" month)
1027 (const :tag "Year" year)
1028 (integer :tag "Custom")))
1030 (defcustom org-agenda-start-on-weekday 1
1031 "Non-nil means start the overview always on the specified weekday.
1032 0 denotes Sunday, 1 denotes Monday etc.
1033 When nil, always start on the current day.
1034 Custom commands can set this variable in the options section."
1035 :group 'org-agenda-daily/weekly
1036 :type '(choice (const :tag "Today" nil)
1037 (integer :tag "Weekday No.")))
1039 (defcustom org-agenda-show-all-dates t
1040 "Non-nil means `org-agenda' shows every day in the selected range.
1041 When nil, only the days which actually have entries are shown."
1042 :group 'org-agenda-daily/weekly
1043 :type 'boolean)
1045 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1046 "Format string for displaying dates in the agenda.
1047 Used by the daily/weekly agenda and by the timeline. This should be
1048 a format string understood by `format-time-string', or a function returning
1049 the formatted date as a string. The function must take a single argument,
1050 a calendar-style date list like (month day year)."
1051 :group 'org-agenda-daily/weekly
1052 :type '(choice
1053 (string :tag "Format string")
1054 (function :tag "Function")))
1056 (defun org-agenda-format-date-aligned (date)
1057 "Format a date string for display in the daily/weekly agenda, or timeline.
1058 This function makes sure that dates are aligned for easy reading."
1059 (require 'cal-iso)
1060 (let* ((dayname (calendar-day-name date))
1061 (day (cadr date))
1062 (day-of-week (calendar-day-of-week date))
1063 (month (car date))
1064 (monthname (calendar-month-name month))
1065 (year (nth 2 date))
1066 (iso-week (org-days-to-iso-week
1067 (calendar-absolute-from-gregorian date)))
1068 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1069 (1- year))
1070 ((and (= month 12) (<= iso-week 1))
1071 (1+ year))
1072 (t year)))
1073 (weekstring (if (= day-of-week 1)
1074 (format " W%02d" iso-week)
1075 "")))
1076 (format "%-10s %2d %s %4d%s"
1077 dayname day monthname year weekstring)))
1079 (defcustom org-agenda-time-leading-zero nil
1080 "Non-nil means use leading zero for military times in agenda.
1081 For example, 9:30am would become 09:30 rather than 9:30."
1082 :group 'org-agenda-daily/weekly
1083 :version "24.1"
1084 :type 'boolean)
1086 (defcustom org-agenda-timegrid-use-ampm nil
1087 "When set, show AM/PM style timestamps on the timegrid."
1088 :group 'org-agenda
1089 :version "24.1"
1090 :type 'boolean)
1092 (defun org-agenda-time-of-day-to-ampm (time)
1093 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1094 (let* ((hour-number (string-to-number (substring time 0 -3)))
1095 (minute (substring time -2))
1096 (ampm "am"))
1097 (cond
1098 ((equal hour-number 12)
1099 (setq ampm "pm"))
1100 ((> hour-number 12)
1101 (setq ampm "pm")
1102 (setq hour-number (- hour-number 12))))
1103 (concat
1104 (if org-agenda-time-leading-zero
1105 (format "%02d" hour-number)
1106 (format "%02s" (number-to-string hour-number)))
1107 ":" minute ampm)))
1109 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1110 "Conditionally convert TIME to AM/PM format
1111 based on `org-agenda-timegrid-use-ampm'"
1112 (if org-agenda-timegrid-use-ampm
1113 (org-agenda-time-of-day-to-ampm time)
1114 time))
1116 (defcustom org-agenda-weekend-days '(6 0)
1117 "Which days are weekend?
1118 These days get the special face `org-agenda-date-weekend' in the agenda
1119 and timeline buffers."
1120 :group 'org-agenda-daily/weekly
1121 :type '(set :greedy t
1122 (const :tag "Monday" 1)
1123 (const :tag "Tuesday" 2)
1124 (const :tag "Wednesday" 3)
1125 (const :tag "Thursday" 4)
1126 (const :tag "Friday" 5)
1127 (const :tag "Saturday" 6)
1128 (const :tag "Sunday" 0)))
1130 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1131 "Non-nil means jump to today when moving a past date forward in time.
1132 When using S-right in the agenda to move a a date forward, and the date
1133 stamp currently points to the past, the first key press will move it
1134 to today. WHen nil, just move one day forward even if the date stays
1135 in the past."
1136 :group 'org-agenda-daily/weekly
1137 :version "24.1"
1138 :type 'boolean)
1140 (defcustom org-agenda-include-diary nil
1141 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1142 Custom commands can set this variable in the options section."
1143 :group 'org-agenda-daily/weekly
1144 :type 'boolean)
1146 (defcustom org-agenda-include-deadlines t
1147 "If non-nil, include entries within their deadline warning period.
1148 Custom commands can set this variable in the options section."
1149 :group 'org-agenda-daily/weekly
1150 :version "24.1"
1151 :type 'boolean)
1153 (defcustom org-agenda-repeating-timestamp-show-all t
1154 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1155 When set to a list of strings, only show occurrences of repeating
1156 stamps for these TODO keywords. When nil, only one occurrence is
1157 shown, either today or the nearest into the future."
1158 :group 'org-agenda-daily/weekly
1159 :type '(choice
1160 (const :tag "Show repeating stamps" t)
1161 (repeat :tag "Show repeating stamps for these TODO keywords"
1162 (string :tag "TODO Keyword"))
1163 (const :tag "Don't show repeating stamps" nil)))
1165 (defcustom org-scheduled-past-days 10000
1166 "No. of days to continue listing scheduled items that are not marked DONE.
1167 When an item is scheduled on a date, it shows up in the agenda on this
1168 day and will be listed until it is marked done for the number of days
1169 given here."
1170 :group 'org-agenda-daily/weekly
1171 :type 'integer)
1173 (defcustom org-agenda-log-mode-items '(closed clock)
1174 "List of items that should be shown in agenda log mode.
1175 This list may contain the following symbols:
1177 closed Show entries that have been closed on that day.
1178 clock Show entries that have received clocked time on that day.
1179 state Show all logged state changes.
1180 Note that instead of changing this variable, you can also press `C-u l' in
1181 the agenda to display all available LOG items temporarily."
1182 :group 'org-agenda-daily/weekly
1183 :type '(set :greedy t (const closed) (const clock) (const state)))
1185 (defcustom org-agenda-clock-consistency-checks
1186 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1187 :gap-ok-around ("4:00")
1188 :default-face ((:background "DarkRed") (:foreground "white"))
1189 :overlap-face nil :gap-face nil :no-end-time-face nil
1190 :long-face nil :short-face nil)
1191 "This is a property list, with the following keys:
1193 :max-duration Mark clocking chunks that are longer than this time.
1194 This is a time string like \"HH:MM\", or the number
1195 of minutes as an integer.
1197 :min-duration Mark clocking chunks that are shorter that this.
1198 This is a time string like \"HH:MM\", or the number
1199 of minutes as an integer.
1201 :max-gap Mark gaps between clocking chunks that are longer than
1202 this duration. A number of minutes, or a string
1203 like \"HH:MM\".
1205 :gap-ok-around List of times during the day which are usually not working
1206 times. When a gap is detected, but the gap contains any
1207 of these times, the gap is *not* reported. For example,
1208 if this is (\"4:00\" \"13:00\") then gaps that contain
1209 4:00 in the morning (i.e. the night) and 13:00
1210 (i.e. a typical lunch time) do not cause a warning.
1211 You should have at least one time during the night in this
1212 list, or otherwise the first task each morning will trigger
1213 a warning because it follows a long gap.
1215 Furthermore, the following properties can be used to define faces for
1216 issue display.
1218 :default-face the default face, if the specific face is undefined
1219 :overlap-face face for overlapping clocks
1220 :gap-face face for gaps between clocks
1221 :no-end-time-face face for incomplete clocks
1222 :long-face face for clock intervals that are too long
1223 :short-face face for clock intervals that are too short"
1224 :group 'org-agenda-daily/weekly
1225 :group 'org-clock
1226 :version "24.1"
1227 :type 'plist)
1229 (defcustom org-agenda-log-mode-add-notes t
1230 "Non-nil means add first line of notes to log entries in agenda views.
1231 If a log item like a state change or a clock entry is associated with
1232 notes, the first line of these notes will be added to the entry in the
1233 agenda display."
1234 :group 'org-agenda-daily/weekly
1235 :type 'boolean)
1237 (defcustom org-agenda-start-with-log-mode nil
1238 "The initial value of log-mode in a newly created agenda window.
1239 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1240 explanations on the possible values."
1241 :group 'org-agenda-startup
1242 :group 'org-agenda-daily/weekly
1243 :type '(choice (const :tag "Don't show log items" nil)
1244 (const :tag "Show only log items" 'only)
1245 (const :tag "Show all possible log items" 'clockcheck)
1246 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1247 (choice (const :tag "Show closed log items" 'closed)
1248 (const :tag "Show clocked log items" 'clock)
1249 (const :tag "Show all logged state changes" 'state)))))
1251 (defcustom org-agenda-start-with-clockreport-mode nil
1252 "The initial value of clockreport-mode in a newly created agenda window."
1253 :group 'org-agenda-startup
1254 :group 'org-agenda-daily/weekly
1255 :type 'boolean)
1257 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1258 "Property list with parameters for the clocktable in clockreport mode.
1259 This is the display mode that shows a clock table in the daily/weekly
1260 agenda, the properties for this dynamic block can be set here.
1261 The usual clocktable parameters are allowed here, but you cannot set
1262 the properties :name, :tstart, :tend, :block, and :scope - these will
1263 be overwritten to make sure the content accurately reflects the
1264 current display in the agenda."
1265 :group 'org-agenda-daily/weekly
1266 :type 'plist)
1268 (defcustom org-agenda-search-view-always-boolean nil
1269 "Non-nil means the search string is interpreted as individual parts.
1271 The search string for search view can either be interpreted as a phrase,
1272 or as a list of snippets that define a boolean search for a number of
1273 strings.
1275 When this is non-nil, the string will be split on whitespace, and each
1276 snippet will be searched individually, and all must match in order to
1277 select an entry. A snippet is then a single string of non-white
1278 characters, or a string in double quotes, or a regexp in {} braces.
1279 If a snippet is preceded by \"-\", the snippet must *not* match.
1280 \"+\" is syntactic sugar for positive selection. Each snippet may
1281 be found as a full word or a partial word, but see the variable
1282 `org-agenda-search-view-force-full-words'.
1284 When this is nil, search will look for the entire search phrase as one,
1285 with each space character matching any amount of whitespace, including
1286 line breaks.
1288 Even when this is nil, you can still switch to Boolean search dynamically
1289 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1290 is a regexp marked with braces like \"{abc}\", this will also switch to
1291 boolean search."
1292 :group 'org-agenda-search-view
1293 :version "24.1"
1294 :type 'boolean)
1296 (if (fboundp 'defvaralias)
1297 (defvaralias 'org-agenda-search-view-search-words-only
1298 'org-agenda-search-view-always-boolean))
1300 (defcustom org-agenda-search-view-force-full-words nil
1301 "Non-nil means, search words must be matches as complete words.
1302 When nil, they may also match part of a word."
1303 :group 'org-agenda-search-view
1304 :version "24.1"
1305 :type 'boolean)
1307 (defgroup org-agenda-time-grid nil
1308 "Options concerning the time grid in the Org-mode Agenda."
1309 :tag "Org Agenda Time Grid"
1310 :group 'org-agenda)
1312 (defcustom org-agenda-search-headline-for-time t
1313 "Non-nil means search headline for a time-of-day.
1314 If the headline contains a time-of-day in one format or another, it will
1315 be used to sort the entry into the time sequence of items for a day.
1316 Some people have time stamps in the headline that refer to the creation
1317 time or so, and then this produces an unwanted side effect. If this is
1318 the case for your, use this variable to turn off searching the headline
1319 for a time."
1320 :group 'org-agenda-time-grid
1321 :type 'boolean)
1323 (defcustom org-agenda-use-time-grid t
1324 "Non-nil means show a time grid in the agenda schedule.
1325 A time grid is a set of lines for specific times (like every two hours between
1326 8:00 and 20:00). The items scheduled for a day at specific times are
1327 sorted in between these lines.
1328 For details about when the grid will be shown, and what it will look like, see
1329 the variable `org-agenda-time-grid'."
1330 :group 'org-agenda-time-grid
1331 :type 'boolean)
1333 (defcustom org-agenda-time-grid
1334 '((daily today require-timed)
1335 "----------------"
1336 (800 1000 1200 1400 1600 1800 2000))
1338 "The settings for time grid for agenda display.
1339 This is a list of three items. The first item is again a list. It contains
1340 symbols specifying conditions when the grid should be displayed:
1342 daily if the agenda shows a single day
1343 weekly if the agenda shows an entire week
1344 today show grid on current date, independent of daily/weekly display
1345 require-timed show grid only if at least one item has a time specification
1347 The second item is a string which will be placed behind the grid time.
1349 The third item is a list of integers, indicating the times that should have
1350 a grid line."
1351 :group 'org-agenda-time-grid
1352 :type
1353 '(list
1354 (set :greedy t :tag "Grid Display Options"
1355 (const :tag "Show grid in single day agenda display" daily)
1356 (const :tag "Show grid in weekly agenda display" weekly)
1357 (const :tag "Always show grid for today" today)
1358 (const :tag "Show grid only if any timed entries are present"
1359 require-timed)
1360 (const :tag "Skip grid times already present in an entry"
1361 remove-match))
1362 (string :tag "Grid String")
1363 (repeat :tag "Grid Times" (integer :tag "Time"))))
1365 (defcustom org-agenda-show-current-time-in-grid t
1366 "Non-nil means show the current time in the time grid."
1367 :group 'org-agenda-time-grid
1368 :version "24.1"
1369 :type 'boolean)
1371 (defcustom org-agenda-current-time-string
1372 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1373 "The string for the current time marker in the agenda."
1374 :group 'org-agenda-time-grid
1375 :version "24.1"
1376 :type 'string)
1378 (defgroup org-agenda-sorting nil
1379 "Options concerning sorting in the Org-mode Agenda."
1380 :tag "Org Agenda Sorting"
1381 :group 'org-agenda)
1383 (defcustom org-agenda-sorting-strategy
1384 '((agenda habit-down time-up priority-down category-keep)
1385 (todo priority-down category-keep)
1386 (tags priority-down category-keep)
1387 (search category-keep))
1388 "Sorting structure for the agenda items of a single day.
1389 This is a list of symbols which will be used in sequence to determine
1390 if an entry should be listed before another entry. The following
1391 symbols are recognized:
1393 time-up Put entries with time-of-day indications first, early first
1394 time-down Put entries with time-of-day indications first, late first
1395 category-keep Keep the default order of categories, corresponding to the
1396 sequence in `org-agenda-files'.
1397 category-up Sort alphabetically by category, A-Z.
1398 category-down Sort alphabetically by category, Z-A.
1399 tag-up Sort alphabetically by last tag, A-Z.
1400 tag-down Sort alphabetically by last tag, Z-A.
1401 priority-up Sort numerically by priority, high priority last.
1402 priority-down Sort numerically by priority, high priority first.
1403 todo-state-up Sort by todo state, tasks that are done last.
1404 todo-state-down Sort by todo state, tasks that are done first.
1405 effort-up Sort numerically by estimated effort, high effort last.
1406 effort-down Sort numerically by estimated effort, high effort first.
1407 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1408 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1409 habit-up Put entries that are habits first
1410 habit-down Put entries that are habits last
1411 alpha-up Sort headlines alphabetically
1412 alpha-down Sort headlines alphabetically, reversed
1414 The different possibilities will be tried in sequence, and testing stops
1415 if one comparison returns a \"not-equal\". For example, the default
1416 '(time-up category-keep priority-down)
1417 means: Pull out all entries having a specified time of day and sort them,
1418 in order to make a time schedule for the current day the first thing in the
1419 agenda listing for the day. Of the entries without a time indication, keep
1420 the grouped in categories, don't sort the categories, but keep them in
1421 the sequence given in `org-agenda-files'. Within each category sort by
1422 priority.
1424 Leaving out `category-keep' would mean that items will be sorted across
1425 categories by priority.
1427 Instead of a single list, this can also be a set of list for specific
1428 contents, with a context symbol in the car of the list, any of
1429 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1431 Custom commands can bind this variable in the options section."
1432 :group 'org-agenda-sorting
1433 :type `(choice
1434 (repeat :tag "General" ,org-sorting-choice)
1435 (list :tag "Individually"
1436 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1437 (repeat ,org-sorting-choice))
1438 (cons (const :tag "Strategy for TODO lists" todo)
1439 (repeat ,org-sorting-choice))
1440 (cons (const :tag "Strategy for Tags matches" tags)
1441 (repeat ,org-sorting-choice))
1442 (cons (const :tag "Strategy for search matches" search)
1443 (repeat ,org-sorting-choice)))))
1445 (defcustom org-agenda-cmp-user-defined nil
1446 "A function to define the comparison `user-defined'.
1447 This function must receive two arguments, agenda entry a and b.
1448 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1449 the user comparison, return nil.
1450 When this is defined, you can make `user-defined-up' and `user-defined-down'
1451 part of an agenda sorting strategy."
1452 :group 'org-agenda-sorting
1453 :type 'symbol)
1455 (defcustom org-sort-agenda-notime-is-late t
1456 "Non-nil means items without time are considered late.
1457 This is only relevant for sorting. When t, items which have no explicit
1458 time like 15:30 will be considered as 99:01, i.e. later than any items which
1459 do have a time. When nil, the default time is before 0:00. You can use this
1460 option to decide if the schedule for today should come before or after timeless
1461 agenda entries."
1462 :group 'org-agenda-sorting
1463 :type 'boolean)
1465 (defcustom org-sort-agenda-noeffort-is-high t
1466 "Non-nil means items without effort estimate are sorted as high effort.
1467 This also applies when filtering an agenda view with respect to the
1468 < or > effort operator. Then, tasks with no effort defined will be treated
1469 as tasks with high effort.
1470 When nil, such items are sorted as 0 minutes effort."
1471 :group 'org-agenda-sorting
1472 :type 'boolean)
1474 (defgroup org-agenda-line-format nil
1475 "Options concerning the entry prefix in the Org-mode agenda display."
1476 :tag "Org Agenda Line Format"
1477 :group 'org-agenda)
1479 (defcustom org-agenda-prefix-format
1480 '((agenda . " %i %-12:c%?-12t% s")
1481 (timeline . " % s")
1482 (todo . " %i %-12:c")
1483 (tags . " %i %-12:c")
1484 (search . " %i %-12:c"))
1485 "Format specifications for the prefix of items in the agenda views.
1486 An alist with five entries, each for the different agenda types. The
1487 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1488 The values are format strings.
1490 This format works similar to a printf format, with the following meaning:
1492 %c the category of the item, \"Diary\" for entries from the diary,
1493 or as given by the CATEGORY keyword or derived from the file name
1494 %e the effort required by the item
1495 %i the icon category of the item, see `org-agenda-category-icon-alist'
1496 %T the last tag of the item (ignore inherited tags, which come first)
1497 %t the HH:MM time-of-day specification if one applies to the entry
1498 %s Scheduling/Deadline information, a short string
1499 %(expression) Eval EXPRESSION and replace the control string
1500 by the result
1502 All specifiers work basically like the standard `%s' of printf, but may
1503 contain two additional characters: a question mark just after the `%'
1504 and a whitespace/punctuation character just before the final letter.
1506 If the first character after `%' is a question mark, the entire field
1507 will only be included if the corresponding value applies to the current
1508 entry. This is useful for fields which should have fixed width when
1509 present, but zero width when absent. For example, \"%?-12t\" will
1510 result in a 12 character time field if a time of the day is specified,
1511 but will completely disappear in entries which do not contain a time.
1513 If there is punctuation or whitespace character just before the final
1514 format letter, this character will be appended to the field value if
1515 the value is not empty. For example, the format \"%-12:c\" leads to
1516 \"Diary: \" if the category is \"Diary\". If the category were be
1517 empty, no additional colon would be inserted.
1519 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1520 which means:
1522 - Indent the line with two space characters
1523 - Give the category a 12 chars wide field, padded with whitespace on
1524 the right (because of `-'). Append a colon if there is a category
1525 (because of `:').
1526 - If there is a time-of-day, put it into a 12 chars wide field. If no
1527 time, don't put in an empty field, just skip it (because of '?').
1528 - Finally, put the scheduling information.
1530 See also the variables `org-agenda-remove-times-when-in-prefix' and
1531 `org-agenda-remove-tags'.
1533 Custom commands can set this variable in the options section."
1534 :type '(choice
1535 (string :tag "General format")
1536 (list :greedy t :tag "View dependent"
1537 (cons (const agenda) (string :tag "Format"))
1538 (cons (const timeline) (string :tag "Format"))
1539 (cons (const todo) (string :tag "Format"))
1540 (cons (const tags) (string :tag "Format"))
1541 (cons (const search) (string :tag "Format"))))
1542 :group 'org-agenda-line-format)
1544 (defvar org-prefix-format-compiled nil
1545 "The compiled prefix format and associated variables.
1546 This is a list where first element is a list of variable bindings, and second
1547 element is the compiled format expression. See the variable
1548 `org-agenda-prefix-format'.")
1550 (defcustom org-agenda-todo-keyword-format "%-1s"
1551 "Format for the TODO keyword in agenda lines.
1552 Set this to something like \"%-12s\" if you want all TODO keywords
1553 to occupy a fixed space in the agenda display."
1554 :group 'org-agenda-line-format
1555 :type 'string)
1557 (defcustom org-agenda-diary-sexp-prefix nil
1558 "A regexp that matches part of a diary sexp entry
1559 which should be treated as scheduling/deadline information in
1560 `org-agenda'.
1562 For example, you can use this to extract the `diary-remind-message' from
1563 `diary-remind' entries."
1564 :group 'org-agenda-line-format
1565 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1567 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1568 "Text preceding timerange entries in the agenda view.
1569 This is a list with two strings. The first applies when the range
1570 is entirely on one day. The second applies if the range spans several days.
1571 The strings may have two \"%d\" format specifiers which will be filled
1572 with the sequence number of the days, and the total number of days in the
1573 range, respectively."
1574 :group 'org-agenda-line-format
1575 :type '(list
1576 (string :tag "Deadline today ")
1577 (choice :tag "Deadline relative"
1578 (string :tag "Format string")
1579 (function))))
1581 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1582 "Text preceding scheduled items in the agenda view.
1583 This is a list with two strings. The first applies when the item is
1584 scheduled on the current day. The second applies when it has been scheduled
1585 previously, it may contain a %d indicating that this is the nth time that
1586 this item is scheduled, due to automatic rescheduling of unfinished items
1587 for the following day. So this number is one larger than the number of days
1588 that passed since this item was scheduled first."
1589 :group 'org-agenda-line-format
1590 :type '(list
1591 (string :tag "Scheduled today ")
1592 (string :tag "Scheduled previously")))
1594 (defcustom org-agenda-inactive-leader "["
1595 "Text preceding item pulled into the agenda by inactive time stamps.
1596 These entries are added to the agenda when pressing \"[\"."
1597 :group 'org-agenda-line-format
1598 :version "24.1"
1599 :type '(list
1600 (string :tag "Scheduled today ")
1601 (string :tag "Scheduled previously")))
1603 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1604 "Text preceding deadline items in the agenda view.
1605 This is a list with two strings. The first applies when the item has its
1606 deadline on the current day. The second applies when it is in the past or
1607 in the future, it may contain %d to capture how many days away the deadline
1608 is (was)."
1609 :group 'org-agenda-line-format
1610 :type '(list
1611 (string :tag "Deadline today ")
1612 (choice :tag "Deadline relative"
1613 (string :tag "Format string")
1614 (function))))
1616 (defcustom org-agenda-remove-times-when-in-prefix t
1617 "Non-nil means remove duplicate time specifications in agenda items.
1618 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1619 time-of-day specification in a headline or diary entry is extracted and
1620 placed into the prefix. If this option is non-nil, the original specification
1621 \(a timestamp or -range, or just a plain time(range) specification like
1622 11:30-4pm) will be removed for agenda display. This makes the agenda less
1623 cluttered.
1624 The option can be t or nil. It may also be the symbol `beg', indicating
1625 that the time should only be removed when it is located at the beginning of
1626 the headline/diary entry."
1627 :group 'org-agenda-line-format
1628 :type '(choice
1629 (const :tag "Always" t)
1630 (const :tag "Never" nil)
1631 (const :tag "When at beginning of entry" beg)))
1633 (defcustom org-agenda-remove-timeranges-from-blocks nil
1634 "Non-nil means remove time ranges specifications in agenda
1635 items that span on several days."
1636 :group 'org-agenda-line-format
1637 :version "24.1"
1638 :type 'boolean)
1640 (defcustom org-agenda-default-appointment-duration nil
1641 "Default duration for appointments that only have a starting time.
1642 When nil, no duration is specified in such cases.
1643 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1644 :group 'org-agenda-line-format
1645 :type '(choice
1646 (integer :tag "Minutes")
1647 (const :tag "No default duration")))
1649 (defcustom org-agenda-show-inherited-tags t
1650 "Non-nil means show inherited tags in each agenda line."
1651 :group 'org-agenda-line-format
1652 :type 'boolean)
1654 (defcustom org-agenda-hide-tags-regexp nil
1655 "Regular expression used to filter away specific tags in agenda views.
1656 This means that these tags will be present, but not be shown in the agenda
1657 line. Secondary filtering will still work on the hidden tags.
1658 Nil means don't hide any tags."
1659 :group 'org-agenda-line-format
1660 :type '(choice
1661 (const :tag "Hide none" nil)
1662 (string :tag "Regexp ")))
1664 (defcustom org-agenda-remove-tags nil
1665 "Non-nil means remove the tags from the headline copy in the agenda.
1666 When this is the symbol `prefix', only remove tags when
1667 `org-agenda-prefix-format' contains a `%T' specifier."
1668 :group 'org-agenda-line-format
1669 :type '(choice
1670 (const :tag "Always" t)
1671 (const :tag "Never" nil)
1672 (const :tag "When prefix format contains %T" prefix)))
1674 (if (fboundp 'defvaralias)
1675 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1676 'org-agenda-remove-tags))
1678 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1679 "Shift tags in agenda items to this column.
1680 If this number is positive, it specifies the column. If it is negative,
1681 it means that the tags should be flushright to that column. For example,
1682 -80 works well for a normal 80 character screen."
1683 :group 'org-agenda-line-format
1684 :type 'integer)
1686 (if (fboundp 'defvaralias)
1687 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1689 (defcustom org-agenda-fontify-priorities 'cookies
1690 "Non-nil means highlight low and high priorities in agenda.
1691 When t, the highest priority entries are bold, lowest priority italic.
1692 However, settings in `org-priority-faces' will overrule these faces.
1693 When this variable is the symbol `cookies', only fontify the
1694 cookies, not the entire task.
1695 This may also be an association list of priority faces, whose
1696 keys are the character values of `org-highest-priority',
1697 `org-default-priority', and `org-lowest-priority' (the default values
1698 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1699 color as a string, or a list like `(:background \"Red\")'.
1700 If it is a color, the variable `org-faces-easy-properties'
1701 determines if it is a foreground or a background color."
1702 :group 'org-agenda-line-format
1703 :type '(choice
1704 (const :tag "Never" nil)
1705 (const :tag "Defaults" t)
1706 (const :tag "Cookies only" cookies)
1707 (repeat :tag "Specify"
1708 (list (character :tag "Priority" :value ?A)
1709 (choice :tag "Face "
1710 (string :tag "Color")
1711 (sexp :tag "Face"))))))
1713 (defcustom org-agenda-day-face-function nil
1714 "Function called to determine what face should be used to display a day.
1715 The only argument passed to that function is the day. It should
1716 returns a face, or nil if does not want to specify a face and let
1717 the normal rules apply."
1718 :group 'org-agenda-line-format
1719 :version "24.1"
1720 :type 'function)
1722 (defcustom org-agenda-category-icon-alist nil
1723 "Alist of category icon to be displayed in agenda views.
1725 Each entry should have the following format:
1727 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1729 Where CATEGORY-REGEXP is a regexp matching the categories where
1730 the icon should be displayed.
1731 FILE-OR-DATA either a file path or a string containing image data.
1733 The other fields can be omitted safely if not needed:
1734 TYPE indicates the image type.
1735 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1736 image data.
1737 PROPS are additional image attributes to assign to the image,
1738 like, e.g. `:ascent center'.
1740 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1742 If you want to set the display properties yourself, just put a
1743 list as second element:
1745 (CATEGORY-REGEXP (MY PROPERTY LIST))
1747 For example, to display a 16px horizontal space for Emacs
1748 category, you can use:
1750 (\"Emacs\" '(space . (:width (16))))"
1751 :group 'org-agenda-line-format
1752 :version "24.1"
1753 :type '(alist :key-type (string :tag "Regexp matching category")
1754 :value-type (choice (list :tag "Icon"
1755 (string :tag "File or data")
1756 (symbol :tag "Type")
1757 (boolean :tag "Data?")
1758 (repeat :tag "Extra image properties" :inline t symbol))
1759 (list :tag "Display properties" sexp))))
1761 (defgroup org-agenda-column-view nil
1762 "Options concerning column view in the agenda."
1763 :tag "Org Agenda Column View"
1764 :group 'org-agenda)
1766 (defcustom org-agenda-columns-show-summaries t
1767 "Non-nil means show summaries for columns displayed in the agenda view."
1768 :group 'org-agenda-column-view
1769 :type 'boolean)
1771 (defcustom org-agenda-columns-compute-summary-properties t
1772 "Non-nil means recompute all summary properties before column view.
1773 When column view in the agenda is listing properties that have a summary
1774 operator, it can go to all relevant buffers and recompute the summaries
1775 there. This can mean overhead for the agenda column view, but is necessary
1776 to have thing up to date.
1777 As a special case, a CLOCKSUM property also makes sure that the clock
1778 computations are current."
1779 :group 'org-agenda-column-view
1780 :type 'boolean)
1782 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1783 "Non-nil means the duration of an appointment will add to day effort.
1784 The property to which appointment durations will be added is the one given
1785 in the option `org-effort-property'. If an appointment does not have
1786 an end time, `org-agenda-default-appointment-duration' will be used. If that
1787 is not set, an appointment without end time will not contribute to the time
1788 estimate."
1789 :group 'org-agenda-column-view
1790 :type 'boolean)
1792 (defcustom org-agenda-auto-exclude-function nil
1793 "A function called with a tag to decide if it is filtered on '/ RET'.
1794 The sole argument to the function, which is called once for each
1795 possible tag, is a string giving the name of the tag. The
1796 function should return either nil if the tag should be included
1797 as normal, or \"-<TAG>\" to exclude the tag.
1798 Note that for the purpose of tag filtering, only the lower-case version of
1799 all tags will be considered, so that this function will only ever see
1800 the lower-case version of all tags."
1801 :group 'org-agenda
1802 :type 'function)
1804 (defcustom org-agenda-bulk-custom-functions nil
1805 "Alist of characters and custom functions for bulk actions.
1806 For example, this value makes those two functions available:
1808 '((?R set-category)
1809 (?C bulk-cut))
1811 With selected entries in an agenda buffer, `B R' will call
1812 the custom function `set-category' on the selected entries.
1813 Note that functions in this alist don't need to be quoted."
1814 :type 'alist
1815 :version "24.1"
1816 :group 'org-agenda)
1818 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1819 "Execute BODY with point at location given by `org-hd-marker' property.
1820 If STRING is non-nil, the text property will be fetched from position 0
1821 in that string. If STRING is nil, it will be fetched from the beginning
1822 of the current line."
1823 (org-with-gensyms (marker)
1824 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1825 'org-hd-marker ,string)))
1826 (with-current-buffer (marker-buffer ,marker)
1827 (save-excursion
1828 (goto-char ,marker)
1829 ,@body)))))
1830 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1832 (defun org-add-agenda-custom-command (entry)
1833 "Replace or add a command in `org-agenda-custom-commands'.
1834 This is mostly for hacking and trying a new command - once the command
1835 works you probably want to add it to `org-agenda-custom-commands' for good."
1836 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1837 (if ass
1838 (setcdr ass (cdr entry))
1839 (push entry org-agenda-custom-commands))))
1841 ;;; Define the org-agenda-mode
1843 (defvar org-agenda-mode-map (make-sparse-keymap)
1844 "Keymap for `org-agenda-mode'.")
1845 (if (fboundp 'defvaralias)
1846 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1848 (defvar org-agenda-menu) ; defined later in this file.
1849 (defvar org-agenda-restrict nil) ; defined later in this file.
1850 (defvar org-agenda-follow-mode nil)
1851 (defvar org-agenda-entry-text-mode nil)
1852 (defvar org-agenda-clockreport-mode nil)
1853 (defvar org-agenda-show-log nil)
1854 (defvar org-agenda-redo-command nil)
1855 (defvar org-agenda-query-string nil)
1856 (defvar org-agenda-mode-hook nil
1857 "Hook run after `org-agenda-mode' is turned on.
1858 The buffer is still writable when this hook is called.")
1859 (defvar org-agenda-type nil)
1860 (defvar org-agenda-force-single-file nil)
1861 (defvar org-agenda-bulk-marked-entries nil
1862 "List of markers that refer to marked entries in the agenda.")
1864 ;;; Multiple agenda buffers support
1866 (defcustom org-agenda-sticky nil
1867 "Non-nil means agenda q key will bury agenda buffers.
1868 Agenda commands will then show existing buffer instead of generating new ones.
1869 When nil, `q' will kill the single agenda buffer."
1870 :group 'org-agenda
1871 :type 'boolean
1872 :set (lambda (var val)
1873 (if (boundp var)
1874 (org-toggle-sticky-agenda (if val 1 0))
1875 (set var val))))
1877 ;;;###autoload
1878 (defun org-toggle-sticky-agenda (&optional arg)
1879 "Toggle `org-agenda-sticky'."
1880 (interactive "P")
1881 (let ((new-value (if arg
1882 (> (prefix-numeric-value arg) 0)
1883 (not org-agenda-sticky))))
1884 (if (equal new-value org-agenda-sticky)
1885 (and (org-called-interactively-p 'interactive)
1886 (message "Sticky agenda was already %s"
1887 (if org-agenda-sticky "enabled" "disabled")))
1888 (setq org-agenda-sticky new-value)
1889 (org-agenda-kill-all-agenda-buffers)
1890 (and (org-called-interactively-p 'interactive)
1891 (message "Sticky agenda was %s"
1892 (if org-agenda-sticky "enabled" "disabled"))))))
1894 (defvar org-agenda-buffer nil
1895 "Agenda buffer currently being generated.")
1897 (defvar org-agenda-last-prefix-arg nil)
1898 (defvar org-agenda-this-buffer-name nil)
1899 (defvar org-agenda-doing-sticky-redo nil)
1900 (defvar org-agenda-this-buffer-is-sticky nil)
1902 (defconst org-agenda-local-vars
1903 '(org-agenda-this-buffer-name
1904 org-agenda-undo-list
1905 org-agenda-pending-undo-list
1906 org-agenda-follow-mode
1907 org-agenda-entry-text-mode
1908 org-agenda-clockreport-mode
1909 org-agenda-show-log
1910 org-agenda-redo-command
1911 org-agenda-query-string
1912 org-agenda-type
1913 org-agenda-bulk-marked-entries
1914 org-agenda-undo-has-started-in
1915 org-agenda-info
1916 org-agenda-tag-filter-overlays
1917 org-agenda-cat-filter-overlays
1918 org-agenda-pre-window-conf
1919 org-agenda-columns-active
1920 org-agenda-tag-filter
1921 org-agenda-category-filter
1922 org-agenda-markers
1923 org-agenda-last-search-view-search-was-boolean
1924 org-agenda-filtered-by-category
1925 org-agenda-filter-form
1926 org-agenda-show-window
1927 org-agenda-cycle-counter
1928 org-agenda-last-prefix-arg)
1929 "Variables that must be local in agenda buffers to allow multiple buffers.")
1931 (defun org-agenda-mode ()
1932 "Mode for time-sorted view on action items in Org-mode files.
1934 The following commands are available:
1936 \\{org-agenda-mode-map}"
1937 (interactive)
1938 (cond (org-agenda-doing-sticky-redo
1939 ;; Refreshing sticky agenda-buffer
1941 ;; Preserve the value of `org-agenda-local-vars' variables,
1942 ;; while letting `kill-all-local-variables' kill the rest
1943 (let ((save (buffer-local-variables)))
1944 (kill-all-local-variables)
1945 (mapc 'make-local-variable org-agenda-local-vars)
1946 (dolist (elem save)
1947 (let ((var (car elem))
1948 (val (cdr elem)))
1949 (when (and val
1950 (member var org-agenda-local-vars))
1951 (set var val)))))
1952 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1953 (org-agenda-sticky
1954 ;; Creating a sticky Agenda buffer for the first time
1955 (kill-all-local-variables)
1956 (mapc 'make-local-variable org-agenda-local-vars)
1957 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1959 ;; Creating a non-sticky agenda buffer
1960 (kill-all-local-variables)
1961 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1962 (setq org-agenda-undo-list nil
1963 org-agenda-pending-undo-list nil
1964 org-agenda-bulk-marked-entries nil)
1965 (setq major-mode 'org-agenda-mode)
1966 ;; Keep global-font-lock-mode from turning on font-lock-mode
1967 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1968 (setq mode-name "Org-Agenda")
1969 (use-local-map org-agenda-mode-map)
1970 (easy-menu-add org-agenda-menu)
1971 (if org-startup-truncated (setq truncate-lines t))
1972 (org-set-local 'line-move-visual nil)
1973 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1974 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1975 ;; Make sure properties are removed when copying text
1976 (make-local-variable 'filter-buffer-substring-functions)
1977 (add-hook 'filter-buffer-substring-functions
1978 (lambda (fun start end delete)
1979 (substring-no-properties (funcall fun start end delete))))
1980 (unless org-agenda-keep-modes
1981 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1982 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1983 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1984 org-agenda-show-log org-agenda-start-with-log-mode))
1986 (easy-menu-change
1987 '("Agenda") "Agenda Files"
1988 (append
1989 (list
1990 (vector
1991 (if (get 'org-agenda-files 'org-restrict)
1992 "Restricted to single file"
1993 "Edit File List")
1994 '(org-edit-agenda-file-list)
1995 (not (get 'org-agenda-files 'org-restrict)))
1996 "--")
1997 (mapcar 'org-file-menu-entry (org-agenda-files))))
1998 (org-agenda-set-mode-name)
1999 (apply
2000 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2001 (list 'org-agenda-mode-hook)))
2003 (substitute-key-definition 'undo 'org-agenda-undo
2004 org-agenda-mode-map global-map)
2005 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2006 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2007 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2008 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2009 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2010 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2011 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2012 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2013 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2014 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2015 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2016 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2017 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2018 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2019 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2020 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2021 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2022 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2023 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2024 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2025 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2026 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2027 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2028 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2029 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2030 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2031 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2032 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2033 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2034 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2035 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2036 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2037 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2038 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2039 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2040 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2041 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2042 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2043 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2044 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2045 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2046 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2047 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2048 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2049 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2051 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2052 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2053 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2054 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2055 (while l (org-defkey org-agenda-mode-map
2056 (int-to-string (pop l)) 'digit-argument)))
2058 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2059 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2060 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2061 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2062 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2063 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2064 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2065 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2066 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2067 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2068 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2069 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2070 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2071 'org-clock-modify-effort-estimate)
2072 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2073 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2074 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2075 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2076 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2077 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2078 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2079 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2080 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2081 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2082 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2083 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2084 (substitute-key-definition 'next-line 'org-agenda-next-line
2085 org-agenda-mode-map global-map)
2086 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2087 org-agenda-mode-map global-map)
2088 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2089 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2090 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2091 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2092 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2093 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2094 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2095 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2096 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2097 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2098 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2099 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2100 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2101 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2102 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2103 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2104 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2105 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2106 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2107 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2108 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2109 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2110 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2111 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2112 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2113 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2114 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2115 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2116 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2117 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2119 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2120 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2121 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2122 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2123 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2124 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2125 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2126 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2127 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2128 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2129 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2130 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2132 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2133 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2134 (when org-agenda-mouse-1-follows-link
2135 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2136 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2137 '("Agenda"
2138 ("Agenda Files")
2139 "--"
2140 ("Agenda Dates"
2141 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2142 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2143 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2144 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2145 "--"
2146 ("View"
2147 ["Day View" org-agenda-day-view
2148 :active (org-agenda-check-type nil 'agenda)
2149 :style radio :selected (eq org-agenda-current-span 'day)
2150 :keys "v d (or just d)"]
2151 ["Week View" org-agenda-week-view
2152 :active (org-agenda-check-type nil 'agenda)
2153 :style radio :selected (eq org-agenda-current-span 'week)
2154 :keys "v w (or just w)"]
2155 ["Month View" org-agenda-month-view
2156 :active (org-agenda-check-type nil 'agenda)
2157 :style radio :selected (eq org-agenda-current-span 'month)
2158 :keys "v m"]
2159 ["Year View" org-agenda-year-view
2160 :active (org-agenda-check-type nil 'agenda)
2161 :style radio :selected (eq org-agenda-current-span 'year)
2162 :keys "v y"]
2163 "--"
2164 ["Include Diary" org-agenda-toggle-diary
2165 :style toggle :selected org-agenda-include-diary
2166 :active (org-agenda-check-type nil 'agenda)]
2167 ["Include Deadlines" org-agenda-toggle-deadlines
2168 :style toggle :selected org-agenda-include-deadlines
2169 :active (org-agenda-check-type nil 'agenda)]
2170 ["Use Time Grid" org-agenda-toggle-time-grid
2171 :style toggle :selected org-agenda-use-time-grid
2172 :active (org-agenda-check-type nil 'agenda)]
2173 "--"
2174 ["Show clock report" org-agenda-clockreport-mode
2175 :style toggle :selected org-agenda-clockreport-mode
2176 :active (org-agenda-check-type nil 'agenda)]
2177 ["Show some entry text" org-agenda-entry-text-mode
2178 :style toggle :selected org-agenda-entry-text-mode
2179 :active t]
2180 "--"
2181 ["Show Logbook entries" org-agenda-log-mode
2182 :style toggle :selected org-agenda-show-log
2183 :active (org-agenda-check-type nil 'agenda 'timeline)
2184 :keys "v l (or just l)"]
2185 ["Include archived trees" org-agenda-archives-mode
2186 :style toggle :selected org-agenda-archives-mode :active t
2187 :keys "v a"]
2188 ["Include archive files" (org-agenda-archives-mode t)
2189 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2190 :keys "v A"]
2191 "--"
2192 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2193 ["Write view to file" org-agenda-write t]
2194 ["Rebuild buffer" org-agenda-redo t]
2195 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2196 "--"
2197 ["Show original entry" org-agenda-show t]
2198 ["Go To (other window)" org-agenda-goto t]
2199 ["Go To (this window)" org-agenda-switch-to t]
2200 ["Capture with cursor date" org-agenda-capture t]
2201 ["Follow Mode" org-agenda-follow-mode
2202 :style toggle :selected org-agenda-follow-mode :active t]
2203 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2204 "--"
2205 ("TODO"
2206 ["Cycle TODO" org-agenda-todo t]
2207 ["Next TODO set" org-agenda-todo-nextset t]
2208 ["Previous TODO set" org-agenda-todo-previousset t]
2209 ["Add note" org-agenda-add-note t])
2210 ("Archive/Refile/Delete"
2211 ["Archive default" org-agenda-archive-default t]
2212 ["Archive default" org-agenda-archive-default-with-confirmation t]
2213 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2214 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2215 ["Archive subtree" org-agenda-archive t]
2216 "--"
2217 ["Refile" org-agenda-refile t]
2218 "--"
2219 ["Delete subtree" org-agenda-kill t])
2220 ("Bulk action"
2221 ["Mark entry" org-agenda-bulk-mark t]
2222 ["Mark all" org-agenda-bulk-mark-all t]
2223 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2224 ["Unmark entry" org-agenda-bulk-unmark t]
2225 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2226 ["Act on all marked" org-agenda-bulk-action t]
2227 "--"
2228 ("Tags and Properties"
2229 ["Show all Tags" org-agenda-show-tags t]
2230 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2231 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2232 "--"
2233 ["Column View" org-columns t])
2234 ("Deadline/Schedule"
2235 ["Schedule" org-agenda-schedule t]
2236 ["Set Deadline" org-agenda-deadline t]
2237 "--"
2238 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2239 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2240 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2241 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2242 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2243 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2244 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2245 ("Clock and Effort"
2246 ["Clock in" org-agenda-clock-in t]
2247 ["Clock out" org-agenda-clock-out t]
2248 ["Clock cancel" org-agenda-clock-cancel t]
2249 ["Goto running clock" org-clock-goto t]
2250 "--"
2251 ["Set Effort" org-agenda-set-effort t]
2252 ["Change clocked effort" org-clock-modify-effort-estimate
2253 (org-clock-is-active)])
2254 ("Priority"
2255 ["Set Priority" org-agenda-priority t]
2256 ["Increase Priority" org-agenda-priority-up t]
2257 ["Decrease Priority" org-agenda-priority-down t]
2258 ["Show Priority" org-agenda-show-priority t])
2259 ("Calendar/Diary"
2260 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2261 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2262 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2263 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2264 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2265 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2266 "--"
2267 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2268 "--"
2269 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2270 "--"
2271 ("MobileOrg"
2272 ["Push Files and Views" org-mobile-push t]
2273 ["Get Captured and Flagged" org-mobile-pull t]
2274 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2275 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2276 "--"
2277 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2278 "--"
2279 ["Quit" org-agenda-quit t]
2280 ["Exit and Release Buffers" org-agenda-exit t]
2283 ;;; Agenda undo
2285 (defvar org-agenda-allow-remote-undo t
2286 "Non-nil means allow remote undo from the agenda buffer.")
2287 (defvar org-agenda-undo-has-started-in nil
2288 "Buffers that have already seen `undo-start' in the current undo sequence.")
2290 (defun org-agenda-undo ()
2291 "Undo a remote editing step in the agenda.
2292 This undoes changes both in the agenda buffer and in the remote buffer
2293 that have been changed along."
2294 (interactive)
2295 (or org-agenda-allow-remote-undo
2296 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2297 (if (not (eq this-command last-command))
2298 (setq org-agenda-undo-has-started-in nil
2299 org-agenda-pending-undo-list org-agenda-undo-list))
2300 (if (not org-agenda-pending-undo-list)
2301 (error "No further undo information"))
2302 (let* ((entry (pop org-agenda-pending-undo-list))
2303 buf line cmd rembuf)
2304 (setq cmd (pop entry) line (pop entry))
2305 (setq rembuf (nth 2 entry))
2306 (org-with-remote-undo rembuf
2307 (while (bufferp (setq buf (pop entry)))
2308 (if (pop entry)
2309 (with-current-buffer buf
2310 (let ((last-undo-buffer buf)
2311 (inhibit-read-only t))
2312 (unless (memq buf org-agenda-undo-has-started-in)
2313 (push buf org-agenda-undo-has-started-in)
2314 (make-local-variable 'pending-undo-list)
2315 (undo-start))
2316 (while (and pending-undo-list
2317 (listp pending-undo-list)
2318 (not (car pending-undo-list)))
2319 (pop pending-undo-list))
2320 (undo-more 1))))))
2321 (org-goto-line line)
2322 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2324 (defun org-verify-change-for-undo (l1 l2)
2325 "Verify that a real change occurred between the undo lists L1 and L2."
2326 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2327 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2328 (not (eq l1 l2)))
2330 ;;; Agenda dispatch
2332 (defvar org-agenda-restrict-begin (make-marker))
2333 (defvar org-agenda-restrict-end (make-marker))
2334 (defvar org-agenda-last-dispatch-buffer nil)
2335 (defvar org-agenda-overriding-restriction nil)
2337 (defcustom org-agenda-custom-commands-contexts nil
2338 "Alist of custom agenda keys and contextual rules.
2340 For example, if you have a custom agenda command \"p\" and you
2341 want this command to be accessible only from plain text files,
2342 use this:
2344 '((\"p\" (in-file . \"\\.txt\")))
2346 Here are the available contexts definitions:
2348 in-file: command displayed only in matching files
2349 in-mode: command displayed only in matching modes
2350 not-in-file: command not displayed in matching files
2351 not-in-mode: command not displayed in matching modes
2352 [function]: a custom function taking no argument
2354 If you define several checks, the agenda command will be
2355 accessible if there is at least one valid check.
2357 You can also bind a key to another agenda custom command
2358 depending on contextual rules.
2360 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2362 Here it means: in .txt files, use \"p\" as the key for the
2363 agenda command otherwise associated with \"q\". (The command
2364 originally associated with \"q\" is not displayed to avoid
2365 duplicates.)"
2366 ;; :version "24.3"
2367 :group 'org-agenda-custom-commands
2368 :type '(repeat (list :tag "Rule"
2369 (string :tag " Agenda key")
2370 (string :tag "Replace by command")
2371 (repeat :tag "Available when"
2372 (choice
2373 (cons :tag "Condition"
2374 (choice
2375 (const :tag "In file" in-file)
2376 (const :tag "Not in file" not-in-file)
2377 (const :tag "In mode" in-mode)
2378 (const :tag "Not in mode" not-in-mode))
2379 (regexp))
2380 (function :tag "Custom function"))))))
2382 (defvar org-keys nil)
2383 (defvar org-match nil)
2384 ;;;###autoload
2385 (defun org-agenda (&optional arg org-keys restriction)
2386 "Dispatch agenda commands to collect entries to the agenda buffer.
2387 Prompts for a command to execute. Any prefix arg will be passed
2388 on to the selected command. The default selections are:
2390 a Call `org-agenda-list' to display the agenda for current day or week.
2391 t Call `org-todo-list' to display the global todo list.
2392 T Call `org-todo-list' to display the global todo list, select only
2393 entries with a specific TODO keyword (the user gets a prompt).
2394 m Call `org-tags-view' to display headlines with tags matching
2395 a condition (the user is prompted for the condition).
2396 M Like `m', but select only TODO entries, no ordinary headlines.
2397 L Create a timeline for the current buffer.
2398 e Export views to associated files.
2399 s Search entries for keywords.
2400 S Search entries for keywords, only with TODO keywords.
2401 / Multi occur across all agenda files and also files listed
2402 in `org-agenda-text-search-extra-files'.
2403 < Restrict agenda commands to buffer, subtree, or region.
2404 Press several times to get the desired effect.
2405 > Remove a previous restriction.
2406 # List \"stuck\" projects.
2407 ! Configure what \"stuck\" means.
2408 C Configure custom agenda commands.
2410 More commands can be added by configuring the variable
2411 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2412 searches can be pre-defined in this way.
2414 If the current buffer is in Org-mode and visiting a file, you can also
2415 first press `<' once to indicate that the agenda should be temporarily
2416 \(until the next use of \\[org-agenda]) restricted to the current file.
2417 Pressing `<' twice means to restrict to the current subtree or region
2418 \(if active)."
2419 (interactive "P")
2420 (catch 'exit
2421 (let* ((prefix-descriptions nil)
2422 (org-agenda-buffer-name org-agenda-buffer-name)
2423 (org-agenda-window-setup (if (equal (buffer-name)
2424 org-agenda-buffer-name)
2425 'current-window
2426 org-agenda-window-setup))
2427 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2428 (org-agenda-custom-commands
2429 ;; normalize different versions
2430 (delq nil
2431 (mapcar
2432 (lambda (x)
2433 (cond ((stringp (cdr x))
2434 (push x prefix-descriptions)
2435 nil)
2436 ((stringp (nth 1 x)) x)
2437 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2438 (t (cons (car x) (cons "" (cdr x))))))
2439 org-agenda-custom-commands)))
2440 (org-agenda-custom-commands
2441 (org-contextualize-keys
2442 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2443 (buf (current-buffer))
2444 (bfn (buffer-file-name (buffer-base-buffer)))
2445 entry key type org-match lprops ans)
2446 ;; Turn off restriction unless there is an overriding one,
2447 (unless org-agenda-overriding-restriction
2448 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2449 ;; There is a request to keep the file list in place
2450 (put 'org-agenda-files 'org-restrict nil))
2451 (setq org-agenda-restrict nil)
2452 (move-marker org-agenda-restrict-begin nil)
2453 (move-marker org-agenda-restrict-end nil))
2454 ;; Delete old local properties
2455 (put 'org-agenda-redo-command 'org-lprops nil)
2456 ;; Delete previously set last-arguments
2457 (put 'org-agenda-redo-command 'last-args nil)
2458 ;; Remember where this call originated
2459 (setq org-agenda-last-dispatch-buffer (current-buffer))
2460 (unless org-keys
2461 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2462 org-keys (car ans)
2463 restriction (cdr ans)))
2464 ;; If we have sticky agenda buffers, set a name for the buffer,
2465 ;; depending on the invoking keys. The user may still set this
2466 ;; as a command option, which will overwrite what we do here.
2467 (if org-agenda-sticky
2468 (setq org-agenda-buffer-name
2469 (format "*Org Agenda(%s)*" org-keys)))
2470 ;; Establish the restriction, if any
2471 (when (and (not org-agenda-overriding-restriction) restriction)
2472 (put 'org-agenda-files 'org-restrict (list bfn))
2473 (cond
2474 ((eq restriction 'region)
2475 (setq org-agenda-restrict t)
2476 (move-marker org-agenda-restrict-begin (region-beginning))
2477 (move-marker org-agenda-restrict-end (region-end)))
2478 ((eq restriction 'subtree)
2479 (save-excursion
2480 (setq org-agenda-restrict t)
2481 (org-back-to-heading t)
2482 (move-marker org-agenda-restrict-begin (point))
2483 (move-marker org-agenda-restrict-end
2484 (progn (org-end-of-subtree t)))))))
2486 ;; For example the todo list should not need it (but does...)
2487 (cond
2488 ((setq entry (assoc org-keys org-agenda-custom-commands))
2489 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2490 (progn
2491 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2492 lprops (nth 4 entry))
2493 (if org-agenda-sticky
2494 (setq org-agenda-buffer-name
2495 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2496 (format "*Org Agenda(%s)*" org-keys))))
2497 (put 'org-agenda-redo-command 'org-lprops lprops)
2498 (cond
2499 ((eq type 'agenda)
2500 (org-let lprops '(org-agenda-list current-prefix-arg)))
2501 ((eq type 'alltodo)
2502 (org-let lprops '(org-todo-list current-prefix-arg)))
2503 ((eq type 'search)
2504 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2505 ((eq type 'stuck)
2506 (org-let lprops '(org-agenda-list-stuck-projects
2507 current-prefix-arg)))
2508 ((eq type 'tags)
2509 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2510 ((eq type 'tags-todo)
2511 (org-let lprops '(org-tags-view '(4) org-match)))
2512 ((eq type 'todo)
2513 (org-let lprops '(org-todo-list org-match)))
2514 ((eq type 'tags-tree)
2515 (org-check-for-org-mode)
2516 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2517 ((eq type 'todo-tree)
2518 (org-check-for-org-mode)
2519 (org-let lprops
2520 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2521 (regexp-quote org-match) "\\>"))))
2522 ((eq type 'occur-tree)
2523 (org-check-for-org-mode)
2524 (org-let lprops '(org-occur org-match)))
2525 ((functionp type)
2526 (org-let lprops '(funcall type org-match)))
2527 ((fboundp type)
2528 (org-let lprops '(funcall type org-match)))
2529 (t (error "Invalid custom agenda command type %s" type))))
2530 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2531 ((equal org-keys "C")
2532 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2533 (customize-variable 'org-agenda-custom-commands))
2534 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2535 ((equal org-keys "s") (call-interactively 'org-search-view))
2536 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2537 ((equal org-keys "t") (call-interactively 'org-todo-list))
2538 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2539 ((equal org-keys "m") (call-interactively 'org-tags-view))
2540 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2541 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2542 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2543 (org-add-hook
2544 'post-command-hook
2545 (lambda ()
2546 (unless (current-message)
2547 (let* ((m (org-agenda-get-any-marker))
2548 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2549 (when note
2550 (message (concat
2551 "FLAGGING-NOTE ([?] for more info): "
2552 (org-add-props
2553 (replace-regexp-in-string
2554 "\\\\n" "//"
2555 (copy-sequence note))
2556 nil 'face 'org-warning)))))))
2557 t t))
2558 ((equal org-keys "L")
2559 (unless (derived-mode-p 'org-mode)
2560 (error "This is not an Org-mode file"))
2561 (unless restriction
2562 (put 'org-agenda-files 'org-restrict (list bfn))
2563 (org-call-with-arg 'org-timeline arg)))
2564 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2565 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2566 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2567 (t (error "Invalid agenda key"))))))
2569 (defun org-agenda-append-agenda ()
2570 "Append another agenda view to the current one.
2571 This function allows interactive building of block agendas.
2572 Agenda views are separated by `org-agenda-block-separator'."
2573 (interactive)
2574 (unless (derived-mode-p 'org-agenda-mode)
2575 (error "Can only append from within agenda buffer"))
2576 (let ((org-agenda-multi t))
2577 (org-agenda)
2578 (widen)
2579 (org-agenda-finalize)
2580 (org-agenda-fit-window-to-buffer)))
2582 (defun org-agenda-normalize-custom-commands (cmds)
2583 (delq nil
2584 (mapcar
2585 (lambda (x)
2586 (cond ((stringp (cdr x)) nil)
2587 ((stringp (nth 1 x)) x)
2588 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2589 (t (cons (car x) (cons "" (cdr x))))))
2590 cmds)))
2592 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2593 "The user interface for selecting an agenda command."
2594 (catch 'exit
2595 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2596 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2597 (region-p (org-region-active-p))
2598 (custom org-agenda-custom-commands)
2599 (selstring "")
2600 restriction second-time
2601 c entry key type match prefixes rmheader header-end custom1 desc
2602 line lines left right n n1)
2603 (save-window-excursion
2604 (delete-other-windows)
2605 (org-switch-to-buffer-other-window " *Agenda Commands*")
2606 (erase-buffer)
2607 (insert (eval-when-compile
2608 (let ((header
2609 "Press key for an agenda command: < Buffer, subtree/region restriction
2610 -------------------------------- > Remove restriction
2611 a Agenda for current week or day e Export agenda views
2612 t List of all TODO entries T Entries with special TODO kwd
2613 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2614 s Search for keywords S Like s, but only TODO entries
2615 L Timeline for current buffer # List stuck projects (!=configure)
2616 / Multi-occur C Configure custom agenda commands
2617 ? Find :FLAGGED: entries * Toggle sticky agenda views
2619 (start 0))
2620 (while (string-match
2621 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2622 header start)
2623 (setq start (match-end 0))
2624 (add-text-properties (match-beginning 2) (match-end 2)
2625 '(face bold) header))
2626 header)))
2627 (setq header-end (move-marker (make-marker) (point)))
2628 (while t
2629 (setq custom1 custom)
2630 (when (eq rmheader t)
2631 (org-goto-line 1)
2632 (re-search-forward ":" nil t)
2633 (delete-region (match-end 0) (point-at-eol))
2634 (forward-char 1)
2635 (looking-at "-+")
2636 (delete-region (match-end 0) (point-at-eol))
2637 (move-marker header-end (match-end 0)))
2638 (goto-char header-end)
2639 (delete-region (point) (point-max))
2641 ;; Produce all the lines that describe custom commands and prefixes
2642 (setq lines nil)
2643 (while (setq entry (pop custom1))
2644 (setq key (car entry) desc (nth 1 entry)
2645 type (nth 2 entry)
2646 match (nth 3 entry))
2647 (if (> (length key) 1)
2648 (add-to-list 'prefixes (string-to-char key))
2649 (setq line
2650 (format
2651 "%-4s%-14s"
2652 (org-add-props (copy-sequence key)
2653 '(face bold))
2654 (cond
2655 ((string-match "\\S-" desc) desc)
2656 ((eq type 'agenda) "Agenda for current week or day")
2657 ((eq type 'alltodo) "List of all TODO entries")
2658 ((eq type 'search) "Word search")
2659 ((eq type 'stuck) "List of stuck projects")
2660 ((eq type 'todo) "TODO keyword")
2661 ((eq type 'tags) "Tags query")
2662 ((eq type 'tags-todo) "Tags (TODO)")
2663 ((eq type 'tags-tree) "Tags tree")
2664 ((eq type 'todo-tree) "TODO kwd tree")
2665 ((eq type 'occur-tree) "Occur tree")
2666 ((functionp type) (if (symbolp type)
2667 (symbol-name type)
2668 "Lambda expression"))
2669 (t "???"))))
2670 (if org-agenda-menu-show-matcher
2671 (setq line
2672 (concat line ": "
2673 (cond
2674 ((stringp match)
2675 (setq match (copy-sequence match))
2676 (org-add-props match nil 'face 'org-warning))
2677 ((listp type)
2678 (format "set of %d commands" (length type))))))
2679 (if (org-string-nw-p match)
2680 (add-text-properties
2681 0 (length line) (list 'help-echo
2682 (concat "Matcher: " match)) line)))
2683 (push line lines)))
2684 (setq lines (nreverse lines))
2685 (when prefixes
2686 (mapc (lambda (x)
2687 (push
2688 (format "%s %s"
2689 (org-add-props (char-to-string x)
2690 nil 'face 'bold)
2691 (or (cdr (assoc (concat selstring
2692 (char-to-string x))
2693 prefix-descriptions))
2694 "Prefix key"))
2695 lines))
2696 prefixes))
2698 ;; Check if we should display in two columns
2699 (if org-agenda-menu-two-columns
2700 (progn
2701 (setq n (length lines)
2702 n1 (+ (/ n 2) (mod n 2))
2703 right (nthcdr n1 lines)
2704 left (copy-sequence lines))
2705 (setcdr (nthcdr (1- n1) left) nil))
2706 (setq left lines right nil))
2707 (while left
2708 (insert "\n" (pop left))
2709 (when right
2710 (if (< (current-column) 40)
2711 (move-to-column 40 t)
2712 (insert " "))
2713 (insert (pop right))))
2715 ;; Make the window the right size
2716 (goto-char (point-min))
2717 (if second-time
2718 (if (not (pos-visible-in-window-p (point-max)))
2719 (org-fit-window-to-buffer))
2720 (setq second-time t)
2721 (org-fit-window-to-buffer))
2723 ;; Ask for selection
2724 (message "Press key for agenda command%s:"
2725 (if (or restrict-ok org-agenda-overriding-restriction)
2726 (if org-agenda-overriding-restriction
2727 " (restriction lock active)"
2728 (if restriction
2729 (format " (restricted to %s)" restriction)
2730 " (unrestricted)"))
2731 ""))
2732 (setq c (read-char-exclusive))
2733 (message "")
2734 (cond
2735 ((assoc (char-to-string c) custom)
2736 (setq selstring (concat selstring (char-to-string c)))
2737 (throw 'exit (cons selstring restriction)))
2738 ((memq c prefixes)
2739 (setq selstring (concat selstring (char-to-string c))
2740 prefixes nil
2741 rmheader (or rmheader t)
2742 custom (delq nil (mapcar
2743 (lambda (x)
2744 (if (or (= (length (car x)) 1)
2745 (/= (string-to-char (car x)) c))
2747 (cons (substring (car x) 1) (cdr x))))
2748 custom))))
2749 ((eq c ?*)
2750 (call-interactively 'org-toggle-sticky-agenda)
2751 (sit-for 2))
2752 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2753 (message "Restriction is only possible in Org-mode buffers")
2754 (ding) (sit-for 1))
2755 ((eq c ?1)
2756 (org-agenda-remove-restriction-lock 'noupdate)
2757 (setq restriction 'buffer))
2758 ((eq c ?0)
2759 (org-agenda-remove-restriction-lock 'noupdate)
2760 (setq restriction (if region-p 'region 'subtree)))
2761 ((eq c ?<)
2762 (org-agenda-remove-restriction-lock 'noupdate)
2763 (setq restriction
2764 (cond
2765 ((eq restriction 'buffer)
2766 (if region-p 'region 'subtree))
2767 ((memq restriction '(subtree region))
2768 nil)
2769 (t 'buffer))))
2770 ((eq c ?>)
2771 (org-agenda-remove-restriction-lock 'noupdate)
2772 (setq restriction nil))
2773 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2774 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2775 ((and (> (length selstring) 0) (eq c ?\d))
2776 (delete-window)
2777 (org-agenda-get-restriction-and-command prefix-descriptions))
2779 ((equal c ?q) (error "Abort"))
2780 (t (error "Invalid key %c" c))))))))
2782 (defun org-agenda-fit-window-to-buffer ()
2783 "Fit the window to the buffer size."
2784 (and (memq org-agenda-window-setup '(reorganize-frame))
2785 (fboundp 'fit-window-to-buffer)
2786 (org-fit-window-to-buffer
2788 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2789 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2791 (defvar org-cmd nil)
2792 (defvar org-agenda-overriding-cmd nil)
2793 (defvar org-agenda-overriding-arguments nil)
2794 (defvar org-agenda-overriding-cmd-arguments nil)
2795 (defun org-agenda-run-series (name series)
2796 (org-let (nth 1 series) '(org-agenda-prepare name))
2797 ;; We need to reset agenda markers here, because when constructing a
2798 ;; block agenda, the individual blocks do not do that.
2799 (org-agenda-reset-markers)
2800 (let* ((org-agenda-multi t)
2801 (redo (list 'org-agenda-run-series name (list 'quote series)))
2802 (cmds (car series))
2803 (gprops (nth 1 series))
2804 match ;; The byte compiler incorrectly complains about this. Keep it!
2805 org-cmd type lprops)
2806 (while (setq org-cmd (pop cmds))
2807 (setq type (car org-cmd)
2808 match (eval (nth 1 org-cmd))
2809 lprops (nth 2 org-cmd))
2810 (let ((org-agenda-overriding-arguments
2811 (if (eq org-agenda-overriding-cmd org-cmd)
2812 (or org-agenda-overriding-arguments
2813 org-agenda-overriding-cmd-arguments))))
2814 (cond
2815 ((eq type 'agenda)
2816 (org-let2 gprops lprops
2817 '(call-interactively 'org-agenda-list)))
2818 ((eq type 'alltodo)
2819 (org-let2 gprops lprops
2820 '(call-interactively 'org-todo-list)))
2821 ((eq type 'search)
2822 (org-let2 gprops lprops
2823 '(org-search-view current-prefix-arg match nil)))
2824 ((eq type 'stuck)
2825 (org-let2 gprops lprops
2826 '(call-interactively 'org-agenda-list-stuck-projects)))
2827 ((eq type 'tags)
2828 (org-let2 gprops lprops
2829 '(org-tags-view current-prefix-arg match)))
2830 ((eq type 'tags-todo)
2831 (org-let2 gprops lprops
2832 '(org-tags-view '(4) match)))
2833 ((eq type 'todo)
2834 (org-let2 gprops lprops
2835 '(org-todo-list match)))
2836 ((fboundp type)
2837 (org-let2 gprops lprops
2838 '(funcall type match)))
2839 (t (error "Invalid type in command series")))))
2840 (widen)
2841 (let ((inhibit-read-only t))
2842 (add-text-properties (point-min) (point-max)
2843 `(org-serie t org-serie-redo-cmd ,redo)))
2844 (setq org-agenda-redo-command redo)
2845 (goto-char (point-min)))
2846 (org-agenda-fit-window-to-buffer)
2847 (org-let (nth 1 series) '(org-agenda-finalize)))
2849 ;;;###autoload
2850 (defmacro org-batch-agenda (cmd-key &rest parameters)
2851 "Run an agenda command in batch mode and send the result to STDOUT.
2852 If CMD-KEY is a string of length 1, it is used as a key in
2853 `org-agenda-custom-commands' and triggers this command. If it is a
2854 longer string it is used as a tags/todo match string.
2855 Parameters are alternating variable names and values that will be bound
2856 before running the agenda command."
2857 (org-eval-in-environment (org-make-parameter-alist parameters)
2858 (if (> (length cmd-key) 2)
2859 (org-tags-view nil cmd-key)
2860 (org-agenda nil cmd-key)))
2861 (set-buffer org-agenda-buffer-name)
2862 (princ (buffer-string)))
2863 (def-edebug-spec org-batch-agenda (form &rest sexp))
2865 (defvar org-agenda-info nil)
2867 ;;;###autoload
2868 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2869 "Run an agenda command in batch mode and send the result to STDOUT.
2870 If CMD-KEY is a string of length 1, it is used as a key in
2871 `org-agenda-custom-commands' and triggers this command. If it is a
2872 longer string it is used as a tags/todo match string.
2873 Parameters are alternating variable names and values that will be bound
2874 before running the agenda command.
2876 The output gives a line for each selected agenda item. Each
2877 item is a list of comma-separated values, like this:
2879 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2881 category The category of the item
2882 head The headline, without TODO kwd, TAGS and PRIORITY
2883 type The type of the agenda entry, can be
2884 todo selected in TODO match
2885 tagsmatch selected in tags match
2886 diary imported from diary
2887 deadline a deadline on given date
2888 scheduled scheduled on given date
2889 timestamp entry has timestamp on given date
2890 closed entry was closed on given date
2891 upcoming-deadline warning about deadline
2892 past-scheduled forwarded scheduled item
2893 block entry has date block including g. date
2894 todo The todo keyword, if any
2895 tags All tags including inherited ones, separated by colons
2896 date The relevant date, like 2007-2-14
2897 time The time, like 15:00-16:50
2898 extra Sting with extra planning info
2899 priority-l The priority letter if any was given
2900 priority-n The computed numerical priority
2901 agenda-day The day in the agenda where this is listed"
2902 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2903 (org-make-parameter-alist parameters))
2904 (if (> (length cmd-key) 2)
2905 (org-tags-view nil cmd-key)
2906 (org-agenda nil cmd-key)))
2907 (set-buffer org-agenda-buffer-name)
2908 (let* ((lines (org-split-string (buffer-string) "\n"))
2909 line)
2910 (while (setq line (pop lines))
2911 (catch 'next
2912 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2913 (setq org-agenda-info
2914 (org-fix-agenda-info (text-properties-at 0 line)))
2915 (princ
2916 (mapconcat 'org-agenda-export-csv-mapper
2917 '(org-category txt type todo tags date time extra
2918 priority-letter priority agenda-day)
2919 ","))
2920 (princ "\n")))))
2921 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2923 (defun org-fix-agenda-info (props)
2924 "Make sure all properties on an agenda item have a canonical form.
2925 This ensures the export commands can easily use it."
2926 (let (tmp re)
2927 (when (setq tmp (plist-get props 'tags))
2928 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2929 (when (setq tmp (plist-get props 'date))
2930 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2931 (let ((calendar-date-display-form '(year "-" month "-" day)))
2932 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2934 (setq tmp (calendar-date-string tmp)))
2935 (setq props (plist-put props 'date tmp)))
2936 (when (setq tmp (plist-get props 'day))
2937 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2938 (let ((calendar-date-display-form '(year "-" month "-" day)))
2939 (setq tmp (calendar-date-string tmp)))
2940 (setq props (plist-put props 'day tmp))
2941 (setq props (plist-put props 'agenda-day tmp)))
2942 (when (setq tmp (plist-get props 'txt))
2943 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2944 (plist-put props 'priority-letter (match-string 1 tmp))
2945 (setq tmp (replace-match "" t t tmp)))
2946 (when (and (setq re (plist-get props 'org-todo-regexp))
2947 (setq re (concat "\\`\\.*" re " ?"))
2948 (string-match re tmp))
2949 (plist-put props 'todo (match-string 1 tmp))
2950 (setq tmp (replace-match "" t t tmp)))
2951 (plist-put props 'txt tmp)))
2952 props)
2954 (defun org-agenda-export-csv-mapper (prop)
2955 (let ((res (plist-get org-agenda-info prop)))
2956 (setq res
2957 (cond
2958 ((not res) "")
2959 ((stringp res) res)
2960 (t (prin1-to-string res))))
2961 (while (string-match "," res)
2962 (setq res (replace-match ";" t t res)))
2963 (org-trim res)))
2965 ;;;###autoload
2966 (defun org-store-agenda-views (&rest parameters)
2967 (interactive)
2968 (eval (list 'org-batch-store-agenda-views)))
2970 ;;;###autoload
2971 (defmacro org-batch-store-agenda-views (&rest parameters)
2972 "Run all custom agenda commands that have a file argument."
2973 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2974 (pop-up-frames nil)
2975 (dir default-directory)
2976 (pars (org-make-parameter-alist parameters))
2977 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
2978 (save-window-excursion
2979 (while cmds
2980 (setq cmd (pop cmds)
2981 thiscmdkey (car cmd)
2982 thiscmdcmd (cdr cmd)
2983 match (nth 2 thiscmdcmd)
2984 bufname (if org-agenda-sticky
2985 (or (and (stringp match)
2986 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
2987 (format "*Org Agenda(%s)*" thiscmdkey))
2988 org-agenda-buffer-name)
2989 cmd-or-set (nth 2 cmd)
2990 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2991 files (nth (if (listp cmd-or-set) 4 5) cmd))
2992 (if (stringp files) (setq files (list files)))
2993 (when files
2994 (org-eval-in-environment (append org-agenda-exporter-settings
2995 opts pars)
2996 (org-agenda nil thiscmdkey))
2997 (set-buffer bufname)
2998 (while files
2999 (org-eval-in-environment (append org-agenda-exporter-settings
3000 opts pars)
3001 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3002 (and (get-buffer bufname)
3003 (kill-buffer bufname)))))))
3004 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3006 (defvar org-agenda-current-span nil
3007 "The current span used in the agenda view.") ; local variable in the agenda buffer
3008 (defun org-agenda-mark-header-line (pos)
3009 "Mark the line at POS as an agenda structure header."
3010 (save-excursion
3011 (goto-char pos)
3012 (put-text-property (point-at-bol) (point-at-eol)
3013 'org-agenda-structural-header t)
3014 (when org-agenda-title-append
3015 (put-text-property (point-at-bol) (point-at-eol)
3016 'org-agenda-title-append org-agenda-title-append))))
3018 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3019 (defvar org-agenda-write-buffer-name "Agenda View")
3020 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3021 "Write the current buffer (an agenda view) as a file.
3022 Depending on the extension of the file name, plain text (.txt),
3023 HTML (.html or .htm) or Postscript (.ps) is produced.
3024 If the extension is .ics, run icalendar export over all files used
3025 to construct the agenda and limit the export to entries listed in the
3026 agenda now.
3027 With prefix argument OPEN, open the new file immediately.
3028 If NOSETTINGS is given, do not scope the settings of
3029 `org-agenda-exporter-settings' into the export commands. This is used when
3030 the settings have already been scoped and we do not wish to overrule other,
3031 higher priority settings.
3032 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3033 (interactive "FWrite agenda to file: \nP")
3034 (if (not (file-writable-p file))
3035 (error "Cannot write agenda to file %s" file))
3036 (org-let (if nosettings nil org-agenda-exporter-settings)
3037 '(save-excursion
3038 (save-window-excursion
3039 (org-agenda-mark-filtered-text)
3040 (let ((bs (copy-sequence (buffer-string))) beg)
3041 (org-agenda-unmark-filtered-text)
3042 (with-temp-buffer
3043 (rename-buffer org-agenda-write-buffer-name t)
3044 (set-buffer-modified-p nil)
3045 (insert bs)
3046 (org-agenda-remove-marked-text 'org-filtered)
3047 (while (setq beg (text-property-any (point-min) (point-max)
3048 'org-filtered t))
3049 (delete-region
3050 beg (or (next-single-property-change beg 'org-filtered)
3051 (point-max))))
3052 (run-hooks 'org-agenda-before-write-hook)
3053 (cond
3054 ((org-bound-and-true-p org-mobile-creating-agendas)
3055 (org-mobile-write-agenda-for-mobile file))
3056 ((string-match "\\.html?\\'" file)
3057 (require 'htmlize)
3058 (set-buffer (htmlize-buffer (current-buffer)))
3059 (when org-agenda-export-html-style
3060 ;; replace <style> section with org-agenda-export-html-style
3061 (goto-char (point-min))
3062 (kill-region (- (search-forward "<style") 6)
3063 (search-forward "</style>"))
3064 (insert org-agenda-export-html-style))
3065 (write-file file)
3066 (kill-buffer (current-buffer))
3067 (message "HTML written to %s" file))
3068 ((string-match "\\.ps\\'" file)
3069 (require 'ps-print)
3070 (ps-print-buffer-with-faces file)
3071 (message "Postscript written to %s" file))
3072 ((string-match "\\.pdf\\'" file)
3073 (require 'ps-print)
3074 (ps-print-buffer-with-faces
3075 (concat (file-name-sans-extension file) ".ps"))
3076 (call-process "ps2pdf" nil nil nil
3077 (expand-file-name
3078 (concat (file-name-sans-extension file) ".ps"))
3079 (expand-file-name file))
3080 (delete-file (concat (file-name-sans-extension file) ".ps"))
3081 (message "PDF written to %s" file))
3082 ((string-match "\\.ics\\'" file)
3083 (require 'org-icalendar)
3084 (let ((org-agenda-marker-table
3085 (org-create-marker-find-array
3086 (org-agenda-collect-markers)))
3087 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3088 (org-combined-agenda-icalendar-file file))
3089 (apply 'org-export-icalendar 'combine
3090 (org-agenda-files nil 'ifmode))))
3092 (let ((bs (buffer-string)))
3093 (find-file file)
3094 (erase-buffer)
3095 (insert bs)
3096 (save-buffer 0)
3097 (kill-buffer (current-buffer))
3098 (message "Plain text written to %s" file))))))))
3099 (set-buffer (or agenda-bufname
3100 (and (called-interactively-p 'any) (buffer-name))
3101 org-agenda-buffer-name)))
3102 (when open (org-open-file file)))
3104 (defvar org-agenda-tag-filter-overlays nil)
3105 (defvar org-agenda-cat-filter-overlays nil)
3107 (defun org-agenda-mark-filtered-text ()
3108 "Mark all text hidden by filtering with a text property."
3109 (let ((inhibit-read-only t))
3110 (mapc
3111 (lambda (o)
3112 (when (equal (overlay-buffer o) (current-buffer))
3113 (put-text-property
3114 (overlay-start o) (overlay-end o)
3115 'org-filtered t)))
3116 (append org-agenda-tag-filter-overlays
3117 org-agenda-cat-filter-overlays))))
3119 (defun org-agenda-unmark-filtered-text ()
3120 "Remove the filtering text property."
3121 (let ((inhibit-read-only t))
3122 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3124 (defun org-agenda-remove-marked-text (property &optional value)
3125 "Delete all text marked with VALUE of PROPERTY.
3126 VALUE defaults to t."
3127 (let (beg)
3128 (setq value (or value t))
3129 (while (setq beg (text-property-any (point-min) (point-max)
3130 property value))
3131 (delete-region
3132 beg (or (next-single-property-change beg 'org-filtered)
3133 (point-max))))))
3135 (defun org-agenda-add-entry-text ()
3136 "Add entry text to agenda lines.
3137 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3138 entry text following headings shown in the agenda.
3139 Drawers will be excluded, also the line with scheduling/deadline info."
3140 (when (and (> org-agenda-add-entry-text-maxlines 0)
3141 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3142 (let (m txt)
3143 (goto-char (point-min))
3144 (while (not (eobp))
3145 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3146 (beginning-of-line 2)
3147 (setq txt (org-agenda-get-some-entry-text
3148 m org-agenda-add-entry-text-maxlines " > "))
3149 (end-of-line 1)
3150 (if (string-match "\\S-" txt)
3151 (insert "\n" txt)
3152 (or (eobp) (forward-char 1))))))))
3154 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3155 &rest keep)
3156 "Extract entry text from MARKER, at most N-LINES lines.
3157 This will ignore drawers etc, just get the text.
3158 If INDENT is given, prefix every line with this string. If KEEP is
3159 given, it is a list of symbols, defining stuff that should not be
3160 removed from the entry content. Currently only `planning' is allowed here."
3161 (let (txt drawer-re kwd-time-re ind)
3162 (save-excursion
3163 (with-current-buffer (marker-buffer marker)
3164 (if (not (derived-mode-p 'org-mode))
3165 (setq txt "")
3166 (save-excursion
3167 (save-restriction
3168 (widen)
3169 (goto-char marker)
3170 (end-of-line 1)
3171 (setq txt (buffer-substring
3172 (min (1+ (point)) (point-max))
3173 (progn (outline-next-heading) (point)))
3174 drawer-re org-drawer-regexp
3175 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3176 ".*\n?"))
3177 (with-temp-buffer
3178 (insert txt)
3179 (when org-agenda-add-entry-text-descriptive-links
3180 (goto-char (point-min))
3181 (while (org-activate-bracket-links (point-max))
3182 (add-text-properties (match-beginning 0) (match-end 0)
3183 '(face org-link))))
3184 (goto-char (point-min))
3185 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3186 (set-text-properties (match-beginning 0) (match-end 0)
3187 nil))
3188 (goto-char (point-min))
3189 (while (re-search-forward drawer-re nil t)
3190 (delete-region
3191 (match-beginning 0)
3192 (progn (re-search-forward
3193 "^[ \t]*:END:.*\n?" nil 'move)
3194 (point))))
3195 (unless (member 'planning keep)
3196 (goto-char (point-min))
3197 (while (re-search-forward kwd-time-re nil t)
3198 (replace-match "")))
3199 (goto-char (point-min))
3200 (when org-agenda-entry-text-exclude-regexps
3201 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3202 (while (setq re (pop re-list))
3203 (goto-char (point-min))
3204 (while (re-search-forward re nil t)
3205 (replace-match "")))))
3206 (goto-char (point-max))
3207 (skip-chars-backward " \t\n")
3208 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3210 ;; find and remove min common indentation
3211 (goto-char (point-min))
3212 (untabify (point-min) (point-max))
3213 (setq ind (org-get-indentation))
3214 (while (not (eobp))
3215 (unless (looking-at "[ \t]*$")
3216 (setq ind (min ind (org-get-indentation))))
3217 (beginning-of-line 2))
3218 (goto-char (point-min))
3219 (while (not (eobp))
3220 (unless (looking-at "[ \t]*$")
3221 (move-to-column ind)
3222 (delete-region (point-at-bol) (point)))
3223 (beginning-of-line 2))
3225 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3227 (goto-char (point-min))
3228 (when indent
3229 (while (and (not (eobp)) (re-search-forward "^" nil t))
3230 (replace-match indent t t)))
3231 (goto-char (point-min))
3232 (while (looking-at "[ \t]*\n") (replace-match ""))
3233 (goto-char (point-max))
3234 (when (> (org-current-line)
3235 n-lines)
3236 (org-goto-line (1+ n-lines))
3237 (backward-char 1))
3238 (setq txt (buffer-substring (point-min) (point)))))))))
3239 txt))
3241 (defun org-agenda-collect-markers ()
3242 "Collect the markers pointing to entries in the agenda buffer."
3243 (let (m markers)
3244 (save-excursion
3245 (goto-char (point-min))
3246 (while (not (eobp))
3247 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3248 (org-get-at-bol 'org-marker)))
3249 (push m markers))
3250 (beginning-of-line 2)))
3251 (nreverse markers)))
3253 (defun org-create-marker-find-array (marker-list)
3254 "Create a alist of files names with all marker positions in that file."
3255 (let (f tbl m a p)
3256 (while (setq m (pop marker-list))
3257 (setq p (marker-position m)
3258 f (buffer-file-name (or (buffer-base-buffer
3259 (marker-buffer m))
3260 (marker-buffer m))))
3261 (if (setq a (assoc f tbl))
3262 (push (marker-position m) (cdr a))
3263 (push (list f p) tbl)))
3264 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3265 tbl)))
3267 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3268 (defun org-check-agenda-marker-table ()
3269 "Check of the current entry is on the marker list."
3270 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3272 (and (setq a (assoc file org-agenda-marker-table))
3273 (save-match-data
3274 (save-excursion
3275 (org-back-to-heading t)
3276 (member (point) (cdr a)))))))
3278 (defun org-check-for-org-mode ()
3279 "Make sure current buffer is in org-mode. Error if not."
3280 (or (derived-mode-p 'org-mode)
3281 (error "Cannot execute org-mode agenda command on buffer in %s"
3282 major-mode)))
3284 ;;; Agenda prepare and finalize
3286 (defvar org-agenda-multi nil) ; dynamically scoped
3287 (defvar org-agenda-pre-window-conf nil)
3288 (defvar org-agenda-columns-active nil)
3289 (defvar org-agenda-name nil)
3290 (defvar org-agenda-tag-filter nil)
3291 (defvar org-agenda-category-filter nil)
3292 (defvar org-agenda-top-category-filter nil)
3293 (defvar org-agenda-tag-filter-while-redo nil)
3294 (defvar org-agenda-tag-filter-preset nil
3295 "A preset of the tags filter used for secondary agenda filtering.
3296 This must be a list of strings, each string must be a single tag preceded
3297 by \"+\" or \"-\".
3298 This variable should not be set directly, but agenda custom commands can
3299 bind it in the options section. The preset filter is a global property of
3300 the entire agenda view. In a block agenda, it will not work reliably to
3301 define a filter for one of the individual blocks. You need to set it in
3302 the global options and expect it to be applied to the entire view.")
3304 (defvar org-agenda-category-filter-preset nil
3305 "A preset of the category filter used for secondary agenda filtering.
3306 This must be a list of strings, each string must be a single category
3307 preceded by \"+\" or \"-\".
3308 This variable should not be set directly, but agenda custom commands can
3309 bind it in the options section. The preset filter is a global property of
3310 the entire agenda view. In a block agenda, it will not work reliably to
3311 define a filter for one of the individual blocks. You need to set it in
3312 the global options and expect it to be applied to the entire view.")
3315 (defun org-agenda-use-sticky-p ()
3316 "Return non-nil if an agenda buffer named
3317 `org-agenda-buffer-name' exists and should be shown instead of
3318 generating a new one."
3319 (and
3320 ;; turned off by user
3321 org-agenda-sticky
3322 ;; For multi-agenda buffer already exists
3323 (not org-agenda-multi)
3324 ;; buffer found
3325 (get-buffer org-agenda-buffer-name)
3326 ;; C-u parameter is same as last call
3327 (with-current-buffer (get-buffer org-agenda-buffer-name)
3328 (and
3329 (equal current-prefix-arg
3330 org-agenda-last-prefix-arg)
3331 ;; In case user turned stickiness on, while having existing
3332 ;; Agenda buffer active, don't reuse that buffer, because it
3333 ;; does not have org variables local
3334 org-agenda-this-buffer-is-sticky))))
3336 (defun org-agenda-prepare-window (abuf)
3337 "Setup agenda buffer in the window."
3338 (let* ((awin (get-buffer-window abuf))
3339 wconf)
3340 (cond
3341 ((equal (current-buffer) abuf) nil)
3342 (awin (select-window awin))
3343 ((not (setq wconf (current-window-configuration))))
3344 ((equal org-agenda-window-setup 'current-window)
3345 (org-pop-to-buffer-same-window abuf))
3346 ((equal org-agenda-window-setup 'other-window)
3347 (org-switch-to-buffer-other-window abuf))
3348 ((equal org-agenda-window-setup 'other-frame)
3349 (switch-to-buffer-other-frame abuf))
3350 ((equal org-agenda-window-setup 'reorganize-frame)
3351 (delete-other-windows)
3352 (org-switch-to-buffer-other-window abuf)))
3353 ;; additional test in case agenda is invoked from within agenda
3354 ;; buffer via elisp link
3355 (unless (equal (current-buffer) abuf)
3356 (org-pop-to-buffer-same-window abuf))
3357 (setq org-agenda-pre-window-conf
3358 (or org-agenda-pre-window-conf wconf))))
3360 (defun org-agenda-prepare (&optional name)
3361 (if (org-agenda-use-sticky-p)
3362 (progn
3363 ;; Popup existing buffer
3364 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3365 (message "Sticky Agenda buffer, use `r' to refresh")
3366 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3367 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3368 (setq org-todo-keywords-for-agenda nil)
3369 (setq org-drawers-for-agenda nil)
3370 (unless org-agenda-persistent-filter
3371 (setq org-agenda-tag-filter nil
3372 org-agenda-category-filter nil))
3373 (put 'org-agenda-tag-filter :preset-filter
3374 org-agenda-tag-filter-preset)
3375 (put 'org-agenda-category-filter :preset-filter
3376 org-agenda-category-filter-preset)
3377 (if org-agenda-multi
3378 (progn
3379 (setq buffer-read-only nil)
3380 (goto-char (point-max))
3381 (unless (or (bobp) org-agenda-compact-blocks
3382 (not org-agenda-block-separator))
3383 (insert "\n"
3384 (if (stringp org-agenda-block-separator)
3385 org-agenda-block-separator
3386 (make-string (window-width) org-agenda-block-separator))
3387 "\n"))
3388 (narrow-to-region (point) (point-max)))
3389 (setq org-done-keywords-for-agenda nil)
3391 ;; Setting any org variables that are in org-agenda-local-vars
3392 ;; list need to be done after the prepare call
3393 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3394 (setq buffer-read-only nil)
3395 (org-agenda-reset-markers)
3396 (let ((inhibit-read-only t)) (erase-buffer))
3397 (org-agenda-mode)
3398 (setq org-agenda-buffer (current-buffer))
3399 (setq org-agenda-contributing-files nil)
3400 (setq org-agenda-columns-active nil)
3401 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3402 (setq org-todo-keywords-for-agenda
3403 (org-uniquify org-todo-keywords-for-agenda))
3404 (setq org-done-keywords-for-agenda
3405 (org-uniquify org-done-keywords-for-agenda))
3406 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3407 (setq org-agenda-last-prefix-arg current-prefix-arg)
3408 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3409 (and name (not org-agenda-name)
3410 (org-set-local 'org-agenda-name name)))
3411 (setq buffer-read-only nil)))
3413 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3414 (defun org-agenda-finalize ()
3415 "Finishing touch for the agenda buffer, called just before displaying it."
3416 (unless org-agenda-multi
3417 (save-excursion
3418 (let ((inhibit-read-only t))
3419 (goto-char (point-min))
3420 (while (org-activate-bracket-links (point-max))
3421 (add-text-properties (match-beginning 0) (match-end 0)
3422 '(face org-link)))
3423 (org-agenda-align-tags)
3424 (unless org-agenda-with-colors
3425 (remove-text-properties (point-min) (point-max) '(face nil))))
3426 (if (and (boundp 'org-agenda-overriding-columns-format)
3427 org-agenda-overriding-columns-format)
3428 (org-set-local 'org-agenda-overriding-columns-format
3429 org-agenda-overriding-columns-format))
3430 (if (and (boundp 'org-agenda-view-columns-initially)
3431 org-agenda-view-columns-initially)
3432 (org-agenda-columns))
3433 (when org-agenda-fontify-priorities
3434 (org-agenda-fontify-priorities))
3435 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3436 (org-agenda-dim-blocked-tasks))
3437 (org-agenda-mark-clocking-task)
3438 (when org-agenda-entry-text-mode
3439 (org-agenda-entry-text-hide)
3440 (org-agenda-entry-text-show))
3441 (if (functionp 'org-habit-insert-consistency-graphs)
3442 (org-habit-insert-consistency-graphs))
3443 (let ((inhibit-read-only t))
3444 (run-hooks 'org-agenda-finalize-hook))
3445 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3446 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3447 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3448 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3449 (org-agenda-filter-apply org-agenda-category-filter 'category))
3450 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3452 (defun org-agenda-mark-clocking-task ()
3453 "Mark the current clock entry in the agenda if it is present."
3454 (mapc (lambda (o)
3455 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3456 (delete-overlay o)))
3457 (overlays-in (point-min) (point-max)))
3458 (when (marker-buffer org-clock-hd-marker)
3459 (save-excursion
3460 (goto-char (point-min))
3461 (let (s ov)
3462 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3463 (goto-char s)
3464 (when (equal (org-get-at-bol 'org-hd-marker)
3465 org-clock-hd-marker)
3466 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3467 (overlay-put ov 'type 'org-agenda-clocking)
3468 (overlay-put ov 'face 'org-agenda-clocking)
3469 (overlay-put ov 'help-echo
3470 "The clock is running in this item")))))))
3472 (defun org-agenda-fontify-priorities ()
3473 "Make highest priority lines bold, and lowest italic."
3474 (interactive)
3475 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3476 (delete-overlay o)))
3477 (overlays-in (point-min) (point-max)))
3478 (save-excursion
3479 (let ((inhibit-read-only t)
3480 b e p ov h l)
3481 (goto-char (point-min))
3482 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3483 (setq h (or (get-char-property (point) 'org-highest-priority)
3484 org-highest-priority)
3485 l (or (get-char-property (point) 'org-lowest-priority)
3486 org-lowest-priority)
3487 p (string-to-char (match-string 1))
3488 b (match-beginning 0)
3489 e (if (eq org-agenda-fontify-priorities 'cookies)
3490 (match-end 0)
3491 (point-at-eol))
3492 ov (make-overlay b e))
3493 (overlay-put
3494 ov 'face
3495 (cond ((org-face-from-face-or-color
3496 'priority nil
3497 (cdr (assoc p org-priority-faces))))
3498 ((and (listp org-agenda-fontify-priorities)
3499 (org-face-from-face-or-color
3500 'priority nil
3501 (cdr (assoc p org-agenda-fontify-priorities)))))
3502 ((equal p l) 'italic)
3503 ((equal p h) 'bold)))
3504 (overlay-put ov 'org-type 'org-priority)))))
3506 (defun org-agenda-dim-blocked-tasks ()
3507 "Dim currently blocked TODO's in the agenda display."
3508 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3509 (delete-overlay o)))
3510 (overlays-in (point-min) (point-max)))
3511 (save-excursion
3512 (let ((inhibit-read-only t)
3513 (org-depend-tag-blocked nil)
3514 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3515 org-blocked-by-checkboxes
3516 invis1 b e p ov h l)
3517 (goto-char (point-min))
3518 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3519 (and pos (goto-char (1+ pos))))
3520 (setq org-blocked-by-checkboxes nil invis1 invis)
3521 (let ((marker (org-get-at-bol 'org-hd-marker)))
3522 (when (and marker
3523 (with-current-buffer (marker-buffer marker)
3524 (save-excursion (goto-char marker)
3525 (org-entry-blocked-p))))
3526 (if org-blocked-by-checkboxes (setq invis1 nil))
3527 (setq b (if invis1
3528 (max (point-min) (1- (point-at-bol)))
3529 (point-at-bol))
3530 e (point-at-eol)
3531 ov (make-overlay b e))
3532 (if invis1
3533 (overlay-put ov 'invisible t)
3534 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3535 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3537 (defvar org-agenda-skip-function nil
3538 "Function to be called at each match during agenda construction.
3539 If this function returns nil, the current match should not be skipped.
3540 Otherwise, the function must return a position from where the search
3541 should be continued.
3542 This may also be a Lisp form, it will be evaluated.
3543 Never set this variable using `setq' or so, because then it will apply
3544 to all future agenda commands. If you do want a global skipping condition,
3545 use the option `org-agenda-skip-function-global' instead.
3546 The correct usage for `org-agenda-skip-function' is to bind it with
3547 `let' to scope it dynamically into the agenda-constructing command.
3548 A good way to set it is through options in `org-agenda-custom-commands'.")
3550 (defun org-agenda-skip ()
3551 "Throw to `:skip' in places that should be skipped.
3552 Also moves point to the end of the skipped region, so that search can
3553 continue from there."
3554 (let ((p (point-at-bol)) to)
3555 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3556 (get-text-property p :org-archived)
3557 (org-end-of-subtree t)
3558 (throw :skip t))
3559 (and org-agenda-skip-comment-trees
3560 (get-text-property p :org-comment)
3561 (org-end-of-subtree t)
3562 (throw :skip t))
3563 (if (equal (char-after p) ?#) (throw :skip t))
3564 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3565 (org-agenda-skip-eval org-agenda-skip-function)))
3566 (goto-char to)
3567 (throw :skip t))))
3569 (defun org-agenda-skip-eval (form)
3570 "If FORM is a function or a list, call (or eval) is and return result.
3571 `save-excursion' and `save-match-data' are wrapped around the call, so point
3572 and match data are returned to the previous state no matter what these
3573 functions do."
3574 (let (fp)
3575 (and form
3576 (or (setq fp (functionp form))
3577 (consp form))
3578 (save-excursion
3579 (save-match-data
3580 (if fp
3581 (funcall form)
3582 (eval form)))))))
3584 (defvar org-agenda-markers nil
3585 "List of all currently active markers created by `org-agenda'.")
3586 (defvar org-agenda-last-marker-time (org-float-time)
3587 "Creation time of the last agenda marker.")
3589 (defun org-agenda-new-marker (&optional pos)
3590 "Return a new agenda marker.
3591 Org-mode keeps a list of these markers and resets them when they are
3592 no longer in use."
3593 (let ((m (copy-marker (or pos (point)))))
3594 (setq org-agenda-last-marker-time (org-float-time))
3595 (if org-agenda-buffer
3596 (with-current-buffer org-agenda-buffer
3597 (push m org-agenda-markers))
3598 (push m org-agenda-markers))
3601 (defun org-agenda-reset-markers ()
3602 "Reset markers created by `org-agenda'."
3603 (while org-agenda-markers
3604 (move-marker (pop org-agenda-markers) nil)))
3606 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3607 "Save relative positions of markers in region.
3608 This check for agenda markers in all agenda buffers currently active."
3609 (dolist (buf (buffer-list))
3610 (with-current-buffer buf
3611 (when (eq major-mode 'org-agenda-mode)
3612 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3613 org-agenda-markers)))))
3615 ;;; Entry text mode
3617 (defun org-agenda-entry-text-show-here ()
3618 "Add some text from the entry as context to the current line."
3619 (let (m txt o)
3620 (setq m (org-get-at-bol 'org-hd-marker))
3621 (unless (marker-buffer m)
3622 (error "No marker points to an entry here"))
3623 (setq txt (concat "\n" (org-no-properties
3624 (org-agenda-get-some-entry-text
3625 m org-agenda-entry-text-maxlines " > "))))
3626 (when (string-match "\\S-" txt)
3627 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3628 (overlay-put o 'evaporate t)
3629 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3630 (overlay-put o 'after-string txt))))
3632 (defun org-agenda-entry-text-show ()
3633 "Add entry context for all agenda lines."
3634 (interactive)
3635 (save-excursion
3636 (goto-char (point-max))
3637 (beginning-of-line 1)
3638 (while (not (bobp))
3639 (when (org-get-at-bol 'org-hd-marker)
3640 (org-agenda-entry-text-show-here))
3641 (beginning-of-line 0))))
3643 (defun org-agenda-entry-text-hide ()
3644 "Remove any shown entry context."
3645 (delq nil
3646 (mapcar (lambda (o)
3647 (if (eq (overlay-get o 'org-overlay-type)
3648 'agenda-entry-content)
3649 (progn (delete-overlay o) t)))
3650 (overlays-in (point-min) (point-max)))))
3652 (defun org-agenda-get-day-face (date)
3653 "Return the face DATE should be displayed with."
3654 (or (and (functionp org-agenda-day-face-function)
3655 (funcall org-agenda-day-face-function date))
3656 (cond ((org-agenda-todayp date)
3657 'org-agenda-date-today)
3658 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3659 'org-agenda-date-weekend)
3660 (t 'org-agenda-date))))
3662 ;;; Agenda timeline
3664 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3666 (defun org-timeline (&optional dotodo)
3667 "Show a time-sorted view of the entries in the current org file.
3668 Only entries with a time stamp of today or later will be listed. With
3669 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3670 under the current date.
3671 If the buffer contains an active region, only check the region for
3672 dates."
3673 (interactive "P")
3674 (let* ((dopast t)
3675 (org-agenda-show-log-scoped org-agenda-show-log)
3676 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3677 (current-buffer))))
3678 (date (calendar-current-date))
3679 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3680 (end (if (org-region-active-p) (region-end) (point-max)))
3681 (day-numbers (org-get-all-dates
3682 beg end 'no-ranges
3683 t org-agenda-show-log-scoped ; always include today
3684 org-timeline-show-empty-dates))
3685 (org-deadline-warning-days 0)
3686 (org-agenda-only-exact-dates t)
3687 (today (org-today))
3688 (past t)
3689 args
3690 s e rtn d emptyp)
3691 (setq org-agenda-redo-command
3692 (list 'progn
3693 (list 'org-switch-to-buffer-other-window (current-buffer))
3694 (list 'org-timeline (list 'quote dotodo))))
3695 (if (not dopast)
3696 ;; Remove past dates from the list of dates.
3697 (setq day-numbers (delq nil (mapcar (lambda(x)
3698 (if (>= x today) x nil))
3699 day-numbers))))
3700 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3701 (org-compile-prefix-format 'timeline)
3702 (org-set-sorting-strategy 'timeline)
3703 (if org-agenda-show-log-scoped (push :closed args))
3704 (push :timestamp args)
3705 (push :deadline args)
3706 (push :scheduled args)
3707 (push :sexp args)
3708 (if dotodo (push :todo args))
3709 (insert "Timeline of file " entry "\n")
3710 (add-text-properties (point-min) (point)
3711 (list 'face 'org-agenda-structure))
3712 (org-agenda-mark-header-line (point-min))
3713 (while (setq d (pop day-numbers))
3714 (if (and (listp d) (eq (car d) :omitted))
3715 (progn
3716 (setq s (point))
3717 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3718 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3719 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3720 (if (and (>= d today)
3721 dopast
3722 past)
3723 (progn
3724 (setq past nil)
3725 (insert (make-string 79 ?-) "\n")))
3726 (setq date (calendar-gregorian-from-absolute d))
3727 (setq s (point))
3728 (setq rtn (and (not emptyp)
3729 (apply 'org-agenda-get-day-entries entry
3730 date args)))
3731 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3732 (progn
3733 (insert
3734 (if (stringp org-agenda-format-date)
3735 (format-time-string org-agenda-format-date
3736 (org-time-from-absolute date))
3737 (funcall org-agenda-format-date date))
3738 "\n")
3739 (put-text-property s (1- (point)) 'face
3740 (org-agenda-get-day-face date))
3741 (put-text-property s (1- (point)) 'org-date-line t)
3742 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3743 (if (equal d today)
3744 (put-text-property s (1- (point)) 'org-today t))
3745 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3746 (put-text-property s (1- (point)) 'day d)))))
3747 (goto-char (point-min))
3748 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3749 (point-min)))
3750 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3751 (org-agenda-finalize)
3752 (setq buffer-read-only t)))
3754 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3755 "Return a list of all relevant day numbers from BEG to END buffer positions.
3756 If NO-RANGES is non-nil, include only the start and end dates of a range,
3757 not every single day in the range. If FORCE-TODAY is non-nil, make
3758 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3759 inactive time stamps (those in square brackets) are included.
3760 When EMPTY is non-nil, also include days without any entries."
3761 (let ((re (concat
3762 (if pre-re pre-re "")
3763 (if inactive org-ts-regexp-both org-ts-regexp)))
3764 dates dates1 date day day1 day2 ts1 ts2 pos)
3765 (if force-today
3766 (setq dates (list (org-today))))
3767 (save-excursion
3768 (goto-char beg)
3769 (while (re-search-forward re end t)
3770 (setq day (time-to-days (org-time-string-to-time
3771 (substring (match-string 1) 0 10)
3772 (current-buffer) (match-beginning 0))))
3773 (or (memq day dates) (push day dates)))
3774 (unless no-ranges
3775 (goto-char beg)
3776 (while (re-search-forward org-tr-regexp end t)
3777 (setq pos (match-beginning 0))
3778 (setq ts1 (substring (match-string 1) 0 10)
3779 ts2 (substring (match-string 2) 0 10)
3780 day1 (time-to-days (org-time-string-to-time
3781 ts1 (current-buffer) pos))
3782 day2 (time-to-days (org-time-string-to-time
3783 ts2 (current-buffer) pos)))
3784 (while (< (setq day1 (1+ day1)) day2)
3785 (or (memq day1 dates) (push day1 dates)))))
3786 (setq dates (sort dates '<))
3787 (when empty
3788 (while (setq day (pop dates))
3789 (setq day2 (car dates))
3790 (push day dates1)
3791 (when (and day2 empty)
3792 (if (or (eq empty t)
3793 (and (numberp empty) (<= (- day2 day) empty)))
3794 (while (< (setq day (1+ day)) day2)
3795 (push (list day) dates1))
3796 (push (cons :omitted (- day2 day)) dates1))))
3797 (setq dates (nreverse dates1)))
3798 dates)))
3800 ;;; Agenda Daily/Weekly
3802 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3803 "Start day for the agenda view.
3804 Custom commands can set this variable in the options section.")
3805 (defvar org-starting-day nil) ; local variable in the agenda buffer
3806 (defvar org-arg-loc nil) ; local variable
3808 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3809 "List of types searched for when creating the daily/weekly agenda.
3810 This variable is a list of symbols that controls the types of
3811 items that appear in the daily/weekly agenda. Allowed symbols in this
3812 list are are
3814 :timestamp List items containing a date stamp or date range matching
3815 the selected date. This includes sexp entries in
3816 angular brackets.
3818 :sexp List entries resulting from plain diary-like sexps.
3820 :deadline List deadline due on that date. When the date is today,
3821 also list any deadlines past due, or due within
3822 `org-deadline-warning-days'. `:deadline' must appear before
3823 `:scheduled' if the setting of
3824 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3825 any effect.
3827 :scheduled List all items which are scheduled for the given date.
3828 The diary for *today* also contains items which were
3829 scheduled earlier and are not yet marked DONE.
3831 By default, all four types are turned on.
3833 Never set this variable globally using `setq', because then it
3834 will apply to all future agenda commands. Instead, bind it with
3835 `let' to scope it dynamically into the agenda-constructing
3836 command. A good way to set it is through options in
3837 `org-agenda-custom-commands'. For a more flexible (though
3838 somewhat less efficient) way of determining what is included in
3839 the daily/weekly agenda, see `org-agenda-skip-function'.")
3841 (defvar org-agenda-buffer-tmp-name nil)
3842 ;;;###autoload
3843 (defun org-agenda-list (&optional arg start-day span)
3844 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3845 The view will be for the current day or week, but from the overview buffer
3846 you will be able to go to other days/weeks.
3848 With a numeric prefix argument in an interactive call, the agenda will
3849 span ARG days. Lisp programs should instead specify SPAN to change
3850 the number of days. SPAN defaults to `org-agenda-span'.
3852 START-DAY defaults to TODAY, or to the most recent match for the weekday
3853 given in `org-agenda-start-on-weekday'."
3854 (interactive "P")
3855 (if org-agenda-overriding-arguments
3856 (setq arg (car org-agenda-overriding-arguments)
3857 start-day (nth 1 org-agenda-overriding-arguments)
3858 span (nth 2 org-agenda-overriding-arguments)))
3859 (if (and (integerp arg) (> arg 0))
3860 (setq span arg arg nil))
3861 (catch 'exit
3862 (setq org-agenda-buffer-name
3863 (or org-agenda-buffer-tmp-name
3864 (if org-agenda-sticky
3865 (cond ((and org-keys (stringp org-match))
3866 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3867 (org-keys
3868 (format "*Org Agenda(%s)*" org-keys))
3869 (t "*Org Agenda(a)*")))
3870 org-agenda-buffer-name))
3871 (org-agenda-prepare "Day/Week")
3872 (setq start-day (or start-day org-agenda-start-day))
3873 (if (stringp start-day)
3874 ;; Convert to an absolute day number
3875 (setq start-day (time-to-days (org-read-date nil t start-day))))
3876 (org-compile-prefix-format 'agenda)
3877 (org-set-sorting-strategy 'agenda)
3878 (let* ((span (org-agenda-ndays-to-span
3879 (or span org-agenda-ndays org-agenda-span)))
3880 (today (org-today))
3881 (sd (or start-day today))
3882 (ndays (org-agenda-span-to-ndays span sd))
3883 (org-agenda-start-on-weekday
3884 (if (eq ndays 7)
3885 org-agenda-start-on-weekday))
3886 (thefiles (org-agenda-files nil 'ifmode))
3887 (files thefiles)
3888 (start (if (or (null org-agenda-start-on-weekday)
3889 (< ndays 7))
3891 (let* ((nt (calendar-day-of-week
3892 (calendar-gregorian-from-absolute sd)))
3893 (n1 org-agenda-start-on-weekday)
3894 (d (- nt n1)))
3895 (- sd (+ (if (< d 0) 7 0) d)))))
3896 (day-numbers (list start))
3897 (day-cnt 0)
3898 (inhibit-redisplay (not debug-on-error))
3899 (org-agenda-show-log-scoped org-agenda-show-log)
3900 s e rtn rtnall file date d start-pos end-pos todayp
3901 clocktable-start clocktable-end filter)
3902 (setq org-agenda-redo-command
3903 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3904 (dotimes (n (1- ndays))
3905 (push (1+ (car day-numbers)) day-numbers))
3906 (setq day-numbers (nreverse day-numbers))
3907 (setq clocktable-start (car day-numbers)
3908 clocktable-end (1+ (or (org-last day-numbers) 0)))
3909 (org-set-local 'org-starting-day (car day-numbers))
3910 (org-set-local 'org-arg-loc arg)
3911 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3912 (unless org-agenda-compact-blocks
3913 (let* ((d1 (car day-numbers))
3914 (d2 (org-last day-numbers))
3915 (w1 (org-days-to-iso-week d1))
3916 (w2 (org-days-to-iso-week d2)))
3917 (setq s (point))
3918 (if org-agenda-overriding-header
3919 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3920 nil 'face 'org-agenda-structure) "\n")
3921 (insert (org-agenda-span-name span)
3922 "-agenda"
3923 (if (< (- d2 d1) 350)
3924 (if (= w1 w2)
3925 (format " (W%02d)" w1)
3926 (format " (W%02d-W%02d)" w1 w2))
3928 ":\n")))
3929 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3930 'org-date-line t))
3931 (org-agenda-mark-header-line s))
3932 (while (setq d (pop day-numbers))
3933 (setq date (calendar-gregorian-from-absolute d)
3934 s (point))
3935 (if (or (setq todayp (= d today))
3936 (and (not start-pos) (= d sd)))
3937 (setq start-pos (point))
3938 (if (and start-pos (not end-pos))
3939 (setq end-pos (point))))
3940 (setq files thefiles
3941 rtnall nil)
3942 (while (setq file (pop files))
3943 (catch 'nextfile
3944 (org-check-agenda-file file)
3945 (let ((org-agenda-entry-types org-agenda-entry-types))
3946 (unless org-agenda-include-deadlines
3947 (setq org-agenda-entry-types
3948 (delq :deadline org-agenda-entry-types)))
3949 (cond
3950 ((memq org-agenda-show-log-scoped '(only clockcheck))
3951 (setq rtn (org-agenda-get-day-entries
3952 file date :closed)))
3953 (org-agenda-show-log-scoped
3954 (setq rtn (apply 'org-agenda-get-day-entries
3955 file date
3956 (append '(:closed) org-agenda-entry-types))))
3958 (setq rtn (apply 'org-agenda-get-day-entries
3959 file date
3960 org-agenda-entry-types)))))
3961 (setq rtnall (append rtnall rtn)))) ;; all entries
3962 (if org-agenda-include-diary
3963 (let ((org-agenda-search-headline-for-time t))
3964 (require 'diary-lib)
3965 (setq rtn (org-get-entries-from-diary date))
3966 (setq rtnall (append rtnall rtn))))
3967 (if (or rtnall org-agenda-show-all-dates)
3968 (progn
3969 (setq day-cnt (1+ day-cnt))
3970 (insert
3971 (if (stringp org-agenda-format-date)
3972 (format-time-string org-agenda-format-date
3973 (org-time-from-absolute date))
3974 (funcall org-agenda-format-date date))
3975 "\n")
3976 (put-text-property s (1- (point)) 'face
3977 (org-agenda-get-day-face date))
3978 (put-text-property s (1- (point)) 'org-date-line t)
3979 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3980 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3981 (when todayp
3982 (put-text-property s (1- (point)) 'org-today t))
3983 (setq rtnall
3984 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3985 (if rtnall (insert ;; all entries
3986 (org-agenda-finalize-entries rtnall)
3987 "\n"))
3988 (put-text-property s (1- (point)) 'day d)
3989 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3990 (when (and org-agenda-clockreport-mode clocktable-start)
3991 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3992 ;; the above line is to ensure the restricted range!
3993 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3994 tbl)
3995 (setq p (org-plist-delete p :block))
3996 (setq p (plist-put p :tstart clocktable-start))
3997 (setq p (plist-put p :tend clocktable-end))
3998 (setq p (plist-put p :scope 'agenda))
3999 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4000 (setq filter (or org-agenda-tag-filter-while-redo
4001 (get 'org-agenda-tag-filter :preset-filter))))
4002 (setq p (plist-put p :tags (mapconcat (lambda (x)
4003 (if (string-match "[<>=]" x)
4006 filter ""))))
4007 (setq tbl (apply 'org-get-clocktable p))
4008 (insert tbl)))
4009 (goto-char (point-min))
4010 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4011 (unless (and (pos-visible-in-window-p (point-min))
4012 (pos-visible-in-window-p (point-max)))
4013 (goto-char (1- (point-max)))
4014 (recenter -1)
4015 (if (not (pos-visible-in-window-p (or start-pos 1)))
4016 (progn
4017 (goto-char (or start-pos 1))
4018 (recenter 1))))
4019 (goto-char (or start-pos 1))
4020 (add-text-properties (point-min) (point-max)
4021 `(org-agenda-type agenda
4022 org-last-args (,arg ,start-day ,span)
4023 org-redo-cmd ,org-agenda-redo-command
4024 org-serie-cmd ,org-cmd))
4025 (if (eq org-agenda-show-log-scoped 'clockcheck)
4026 (org-agenda-show-clocking-issues))
4027 (org-agenda-finalize)
4028 (setq buffer-read-only t)
4029 (message ""))))
4031 (defun org-agenda-ndays-to-span (n)
4032 "Return a span symbol for a span of N days, or N if none matches."
4033 (cond ((symbolp n) n)
4034 ((= n 1) 'day)
4035 ((= n 7) 'week)
4036 (t n)))
4038 (defun org-agenda-span-to-ndays (span &optional start-day)
4039 "Return ndays from SPAN, possibly starting at START-DAY."
4040 (cond ((numberp span) span)
4041 ((eq span 'day) 1)
4042 ((eq span 'week) 7)
4043 ((eq span 'month)
4044 (let ((date (calendar-gregorian-from-absolute start-day)))
4045 (calendar-last-day-of-month (car date) (caddr date))))
4046 ((eq span 'year)
4047 (let ((date (calendar-gregorian-from-absolute start-day)))
4048 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4050 (defun org-agenda-span-name (span)
4051 "Return a SPAN name."
4052 (if (null span)
4054 (if (symbolp span)
4055 (capitalize (symbol-name span))
4056 (format "%d days" span))))
4058 ;;; Agenda word search
4060 (defvar org-agenda-search-history nil)
4062 (defvar org-search-syntax-table nil
4063 "Special syntax table for org-mode search.
4064 In this table, we have single quotes not as word constituents, to
4065 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4067 (defvar org-mode-syntax-table) ; From org.el
4068 (defun org-search-syntax-table ()
4069 (unless org-search-syntax-table
4070 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4071 (modify-syntax-entry ?' "." org-search-syntax-table)
4072 (modify-syntax-entry ?` "." org-search-syntax-table))
4073 org-search-syntax-table)
4075 (defvar org-agenda-last-search-view-search-was-boolean nil)
4077 ;;;###autoload
4078 (defun org-search-view (&optional todo-only string edit-at)
4079 "Show all entries that contain a phrase or words or regular expressions.
4081 With optional prefix argument TODO-ONLY, only consider entries that are
4082 TODO entries. The argument STRING can be used to pass a default search
4083 string into this function. If EDIT-AT is non-nil, it means that the
4084 user should get a chance to edit this string, with cursor at position
4085 EDIT-AT.
4087 The search string can be viewed either as a phrase that should be found as
4088 is, or it can be broken into a number of snippets, each of which must match
4089 in a Boolean way to select an entry. The default depends on the variable
4090 `org-agenda-search-view-always-boolean'.
4091 Even if this is turned off (the default) you can always switch to
4092 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4094 The default is a direct search of the whole phrase, where each space in
4095 the search string can expand to an arbitrary amount of whitespace,
4096 including newlines.
4098 If using a Boolean search, the search string is split on whitespace and
4099 each snippet is searched separately, with logical AND to select an entry.
4100 Words prefixed with a minus must *not* occur in the entry. Words without
4101 a prefix or prefixed with a plus must occur in the entry. Matching is
4102 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4103 match whole words, not parts of a word) if
4104 `org-agenda-search-view-force-full-words' is set (default is nil).
4106 Boolean search snippets enclosed by curly braces are interpreted as
4107 regular expressions that must or (when preceded with \"-\") must not
4108 match in the entry. Snippets enclosed into double quotes will be taken
4109 as a whole, to include whitespace.
4111 - If the search string starts with an asterisk, search only in headlines.
4112 - If (possibly after the leading star) the search string starts with an
4113 exclamation mark, this also means to look at TODO entries only, an effect
4114 that can also be achieved with a prefix argument.
4115 - If (possibly after star and exclamation mark) the search string starts
4116 with a colon, this will mean that the (non-regexp) snippets of the
4117 Boolean search must match as full words.
4119 This command searches the agenda files, and in addition the files listed
4120 in `org-agenda-text-search-extra-files'."
4121 (interactive "P")
4122 (if org-agenda-overriding-arguments
4123 (setq todo-only (car org-agenda-overriding-arguments)
4124 string (nth 1 org-agenda-overriding-arguments)
4125 edit-at (nth 2 org-agenda-overriding-arguments)))
4126 (let* ((props (list 'face nil
4127 'done-face 'org-agenda-done
4128 'org-not-done-regexp org-not-done-regexp
4129 'org-todo-regexp org-todo-regexp
4130 'org-complex-heading-regexp org-complex-heading-regexp
4131 'mouse-face 'highlight
4132 'help-echo (format "mouse-2 or RET jump to location")))
4133 (full-words org-agenda-search-view-force-full-words)
4134 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4135 regexp rtn rtnall files file pos
4136 marker category category-pos tags c neg re boolean
4137 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4138 (unless (and (not edit-at)
4139 (stringp string)
4140 (string-match "\\S-" string))
4141 (setq string (read-string
4142 (if org-agenda-search-view-always-boolean
4143 "[+-]Word/{Regexp} ...: "
4144 "Phrase or [+-]Word/{Regexp} ...: ")
4145 (cond
4146 ((integerp edit-at) (cons string edit-at))
4147 (edit-at string))
4148 'org-agenda-search-history)))
4149 (catch 'exit
4150 (if org-agenda-sticky
4151 (setq org-agenda-buffer-name
4152 (if (stringp string)
4153 (format "*Org Agenda(%s:%s)*"
4154 (or org-keys (or (and todo-only "S") "s")) string)
4155 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4156 (org-agenda-prepare "SEARCH")
4157 (org-compile-prefix-format 'search)
4158 (org-set-sorting-strategy 'search)
4159 (setq org-agenda-redo-command
4160 (list 'org-search-view (if todo-only t nil)
4161 (list 'if 'current-prefix-arg nil string)))
4162 (setq org-agenda-query-string string)
4163 (if (equal (string-to-char string) ?*)
4164 (setq hdl-only t
4165 words (substring string 1))
4166 (setq words string))
4167 (when (equal (string-to-char words) ?!)
4168 (setq todo-only t
4169 words (substring words 1)))
4170 (when (equal (string-to-char words) ?:)
4171 (setq full-words t
4172 words (substring words 1)))
4173 (if (or org-agenda-search-view-always-boolean
4174 (member (string-to-char words) '(?- ?+ ?\{)))
4175 (setq boolean t))
4176 (setq words (org-split-string words))
4177 (let (www w)
4178 (while (setq w (pop words))
4179 (while (and (string-match "\\\\\\'" w) words)
4180 (setq w (concat (substring w 0 -1) " " (pop words))))
4181 (push w www))
4182 (setq words (nreverse www) www nil)
4183 (while (setq w (pop words))
4184 (when (and (string-match "\\`[-+]?{" w)
4185 (not (string-match "}\\'" w)))
4186 (while (and words (not (string-match "}\\'" (car words))))
4187 (setq w (concat w " " (pop words))))
4188 (setq w (concat w " " (pop words))))
4189 (push w www))
4190 (setq words (nreverse www)))
4191 (setq org-agenda-last-search-view-search-was-boolean boolean)
4192 (when boolean
4193 (let (wds w)
4194 (while (setq w (pop words))
4195 (if (or (equal (substring w 0 1) "\"")
4196 (and (> (length w) 1)
4197 (member (substring w 0 1) '("+" "-"))
4198 (equal (substring w 1 2) "\"")))
4199 (while (and words (not (equal (substring w -1) "\"")))
4200 (setq w (concat w " " (pop words)))))
4201 (and (string-match "\\`\\([-+]?\\)\"" w)
4202 (setq w (replace-match "\\1" nil nil w)))
4203 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4204 (push w wds))
4205 (setq words (nreverse wds))))
4206 (if boolean
4207 (mapc (lambda (w)
4208 (setq c (string-to-char w))
4209 (if (equal c ?-)
4210 (setq neg t w (substring w 1))
4211 (if (equal c ?+)
4212 (setq neg nil w (substring w 1))
4213 (setq neg nil)))
4214 (if (string-match "\\`{.*}\\'" w)
4215 (setq re (substring w 1 -1))
4216 (if full-words
4217 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4218 (setq re (regexp-quote (downcase w)))))
4219 (if neg (push re regexps-) (push re regexps+)))
4220 words)
4221 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4222 regexps+))
4223 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4224 (if (not regexps+)
4225 (setq regexp org-outline-regexp-bol)
4226 (setq regexp (pop regexps+))
4227 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4228 regexp))))
4229 (setq files (org-agenda-files nil 'ifmode))
4230 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4231 (pop org-agenda-text-search-extra-files)
4232 (setq files (org-add-archive-files files)))
4233 (setq files (append files org-agenda-text-search-extra-files)
4234 rtnall nil)
4235 (while (setq file (pop files))
4236 (setq ee nil)
4237 (catch 'nextfile
4238 (org-check-agenda-file file)
4239 (setq buffer (if (file-exists-p file)
4240 (org-get-agenda-file-buffer file)
4241 (error "No such file %s" file)))
4242 (if (not buffer)
4243 ;; If file does not exist, make sure an error message is sent
4244 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4245 file))))
4246 (with-current-buffer buffer
4247 (with-syntax-table (org-search-syntax-table)
4248 (unless (derived-mode-p 'org-mode)
4249 (error "Agenda file %s is not in `org-mode'" file))
4250 (let ((case-fold-search t))
4251 (save-excursion
4252 (save-restriction
4253 (if org-agenda-restrict
4254 (narrow-to-region org-agenda-restrict-begin
4255 org-agenda-restrict-end)
4256 (widen))
4257 (goto-char (point-min))
4258 (unless (or (org-at-heading-p)
4259 (outline-next-heading))
4260 (throw 'nextfile t))
4261 (goto-char (max (point-min) (1- (point))))
4262 (while (re-search-forward regexp nil t)
4263 (org-back-to-heading t)
4264 (skip-chars-forward "* ")
4265 (setq beg (point-at-bol)
4266 beg1 (point)
4267 end (progn (outline-next-heading) (point)))
4268 (catch :skip
4269 (goto-char beg)
4270 (org-agenda-skip)
4271 (setq str (buffer-substring-no-properties
4272 (point-at-bol)
4273 (if hdl-only (point-at-eol) end)))
4274 (mapc (lambda (wr) (when (string-match wr str)
4275 (goto-char (1- end))
4276 (throw :skip t)))
4277 regexps-)
4278 (mapc (lambda (wr) (unless (string-match wr str)
4279 (goto-char (1- end))
4280 (throw :skip t)))
4281 (if todo-only
4282 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4283 regexps+)
4284 regexps+))
4285 (goto-char beg)
4286 (setq marker (org-agenda-new-marker (point))
4287 category (org-get-category)
4288 category-pos (get-text-property (point) 'org-category-position)
4289 tags (org-get-tags-at (point))
4290 txt (org-agenda-format-item
4292 (buffer-substring-no-properties
4293 beg1 (point-at-eol))
4294 category tags t))
4295 (org-add-props txt props
4296 'org-marker marker 'org-hd-marker marker
4297 'org-todo-regexp org-todo-regexp
4298 'org-complex-heading-regexp org-complex-heading-regexp
4299 'priority 1000 'org-category category
4300 'org-category-position category-pos
4301 'type "search")
4302 (push txt ee)
4303 (goto-char (1- end))))))))))
4304 (setq rtn (nreverse ee))
4305 (setq rtnall (append rtnall rtn)))
4306 (if org-agenda-overriding-header
4307 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4308 nil 'face 'org-agenda-structure) "\n")
4309 (insert "Search words: ")
4310 (add-text-properties (point-min) (1- (point))
4311 (list 'face 'org-agenda-structure))
4312 (setq pos (point))
4313 (insert string "\n")
4314 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4315 (setq pos (point))
4316 (unless org-agenda-multi
4317 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4318 (add-text-properties pos (1- (point))
4319 (list 'face 'org-agenda-structure))))
4320 (org-agenda-mark-header-line (point-min))
4321 (when rtnall
4322 (insert (org-agenda-finalize-entries rtnall) "\n"))
4323 (goto-char (point-min))
4324 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4325 (add-text-properties (point-min) (point-max)
4326 `(org-agenda-type search
4327 org-last-args (,todo-only ,string ,edit-at)
4328 org-redo-cmd ,org-agenda-redo-command
4329 org-serie-cmd ,org-cmd))
4330 (org-agenda-finalize)
4331 (setq buffer-read-only t))))
4333 ;;; Agenda TODO list
4335 (defvar org-select-this-todo-keyword nil)
4336 (defvar org-last-arg nil)
4338 ;;;###autoload
4339 (defun org-todo-list (&optional arg)
4340 "Show all (not done) TODO entries from all agenda file in a single list.
4341 The prefix arg can be used to select a specific TODO keyword and limit
4342 the list to these. When using \\[universal-argument], you will be prompted
4343 for a keyword. A numeric prefix directly selects the Nth keyword in
4344 `org-todo-keywords-1'."
4345 (interactive "P")
4346 (if org-agenda-overriding-arguments
4347 (setq arg org-agenda-overriding-arguments))
4348 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4349 (let* ((today (org-today))
4350 (date (calendar-gregorian-from-absolute today))
4351 (kwds org-todo-keywords-for-agenda)
4352 (completion-ignore-case t)
4353 (org-select-this-todo-keyword
4354 (if (stringp arg) arg
4355 (and arg (integerp arg) (> arg 0)
4356 (nth (1- arg) kwds))))
4357 rtn rtnall files file pos)
4358 (when (equal arg '(4))
4359 (setq org-select-this-todo-keyword
4360 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4361 (mapcar 'list kwds) nil nil)))
4362 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4363 (catch 'exit
4364 (if org-agenda-sticky
4365 (setq org-agenda-buffer-name
4366 (if (stringp org-select-this-todo-keyword)
4367 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4368 org-select-this-todo-keyword)
4369 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4370 (org-agenda-prepare "TODO")
4371 (org-compile-prefix-format 'todo)
4372 (org-set-sorting-strategy 'todo)
4373 (setq org-agenda-redo-command
4374 `(org-todo-list (or current-prefix-arg (quote ,arg))))
4375 (setq files (org-agenda-files nil 'ifmode)
4376 rtnall nil)
4377 (while (setq file (pop files))
4378 (catch 'nextfile
4379 (org-check-agenda-file file)
4380 (setq rtn (org-agenda-get-day-entries file date :todo))
4381 (setq rtnall (append rtnall rtn))))
4382 (if org-agenda-overriding-header
4383 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4384 nil 'face 'org-agenda-structure) "\n")
4385 (insert "Global list of TODO items of type: ")
4386 (add-text-properties (point-min) (1- (point))
4387 (list 'face 'org-agenda-structure
4388 'short-heading
4389 (concat "ToDo: "
4390 (or org-select-this-todo-keyword "ALL"))))
4391 (org-agenda-mark-header-line (point-min))
4392 (setq pos (point))
4393 (insert (or org-select-this-todo-keyword "ALL") "\n")
4394 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4395 (setq pos (point))
4396 (unless org-agenda-multi
4397 (insert "Available with `N r': (0)[ALL]")
4398 (let ((n 0) s)
4399 (mapc (lambda (x)
4400 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4401 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4402 (insert "\n "))
4403 (insert " " s))
4404 kwds))
4405 (insert "\n"))
4406 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4407 (org-agenda-mark-header-line (point-min))
4408 (when rtnall
4409 (insert (org-agenda-finalize-entries rtnall) "\n"))
4410 (goto-char (point-min))
4411 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4412 (add-text-properties (point-min) (point-max)
4413 `(org-agenda-type todo
4414 org-last-args ,arg
4415 org-redo-cmd ,org-agenda-redo-command
4416 org-serie-cmd ,org-cmd))
4417 (org-agenda-finalize)
4418 (setq buffer-read-only t))))
4420 ;;; Agenda tags match
4422 ;;;###autoload
4423 (defun org-tags-view (&optional todo-only match)
4424 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4425 The prefix arg TODO-ONLY limits the search to TODO entries."
4426 (interactive "P")
4427 (if org-agenda-overriding-arguments
4428 (setq todo-only (car org-agenda-overriding-arguments)
4429 match (nth 1 org-agenda-overriding-arguments)))
4430 (let* ((org-tags-match-list-sublevels
4431 org-tags-match-list-sublevels)
4432 (completion-ignore-case t)
4433 rtn rtnall files file pos matcher
4434 buffer)
4435 (when (and (stringp match) (not (string-match "\\S-" match)))
4436 (setq match nil))
4437 (setq matcher (org-make-tags-matcher match)
4438 match (car matcher) matcher (cdr matcher))
4439 (catch 'exit
4440 (if org-agenda-sticky
4441 (setq org-agenda-buffer-name
4442 (if (stringp match)
4443 (format "*Org Agenda(%s:%s)*"
4444 (or org-keys (or (and todo-only "M") "m")) match)
4445 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4446 (org-agenda-prepare (concat "TAGS " match))
4447 (org-compile-prefix-format 'tags)
4448 (org-set-sorting-strategy 'tags)
4449 (setq org-agenda-query-string match)
4450 (setq org-agenda-redo-command
4451 (list 'org-tags-view `(quote ,todo-only)
4452 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4453 (setq files (org-agenda-files nil 'ifmode)
4454 rtnall nil)
4455 (while (setq file (pop files))
4456 (catch 'nextfile
4457 (org-check-agenda-file file)
4458 (setq buffer (if (file-exists-p file)
4459 (org-get-agenda-file-buffer file)
4460 (error "No such file %s" file)))
4461 (if (not buffer)
4462 ;; If file does not exist, error message to agenda
4463 (setq rtn (list
4464 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4465 rtnall (append rtnall rtn))
4466 (with-current-buffer buffer
4467 (unless (derived-mode-p 'org-mode)
4468 (error "Agenda file %s is not in `org-mode'" file))
4469 (save-excursion
4470 (save-restriction
4471 (if org-agenda-restrict
4472 (narrow-to-region org-agenda-restrict-begin
4473 org-agenda-restrict-end)
4474 (widen))
4475 (setq rtn (org-scan-tags 'agenda matcher todo-only))
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 "Headlines with TAGS match: ")
4481 (add-text-properties (point-min) (1- (point))
4482 (list 'face 'org-agenda-structure
4483 'short-heading
4484 (concat "Match: " match)))
4485 (setq pos (point))
4486 (insert match "\n")
4487 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4488 (setq pos (point))
4489 (unless org-agenda-multi
4490 (insert "Press `C-u r' to search again with new search string\n"))
4491 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4492 (org-agenda-mark-header-line (point-min))
4493 (when rtnall
4494 (insert (org-agenda-finalize-entries rtnall) "\n"))
4495 (goto-char (point-min))
4496 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4497 (add-text-properties (point-min) (point-max)
4498 `(org-agenda-type tags
4499 org-last-args (,todo-only ,match)
4500 org-redo-cmd ,org-agenda-redo-command
4501 org-serie-cmd ,org-cmd))
4502 (org-agenda-finalize)
4503 (setq buffer-read-only t))))
4505 ;;; Agenda Finding stuck projects
4507 (defvar org-agenda-skip-regexp nil
4508 "Regular expression used in skipping subtrees for the agenda.
4509 This is basically a temporary global variable that can be set and then
4510 used by user-defined selections using `org-agenda-skip-function'.")
4512 (defvar org-agenda-overriding-header nil
4513 "When set during agenda, todo and tags searches it replaces the header.
4514 This variable should not be set directly, but custom commands can bind it
4515 in the options section.")
4517 (defun org-agenda-skip-entry-when-regexp-matches ()
4518 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4519 If yes, it returns the end position of this entry, causing agenda commands
4520 to skip the entry but continuing the search in the subtree. This is a
4521 function that can be put into `org-agenda-skip-function' for the duration
4522 of a command."
4523 (let ((end (save-excursion (org-end-of-subtree t)))
4524 skip)
4525 (save-excursion
4526 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4527 (and skip end)))
4529 (defun org-agenda-skip-subtree-when-regexp-matches ()
4530 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4531 If yes, it returns the end position of this tree, causing agenda commands
4532 to skip this subtree. This is a function that can be put into
4533 `org-agenda-skip-function' for the duration of a command."
4534 (let ((end (save-excursion (org-end-of-subtree t)))
4535 skip)
4536 (save-excursion
4537 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4538 (and skip end)))
4540 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4541 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4542 If yes, it returns the end position of the current entry (NOT the tree),
4543 causing agenda commands to skip the entry but continuing the search in
4544 the subtree. This is a function that can be put into
4545 `org-agenda-skip-function' for the duration of a command. An important
4546 use of this function is for the stuck project list."
4547 (let ((end (save-excursion (org-end-of-subtree t)))
4548 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4549 skip)
4550 (save-excursion
4551 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4552 (and skip entry-end)))
4554 (defun org-agenda-skip-entry-if (&rest conditions)
4555 "Skip entry if any of CONDITIONS is true.
4556 See `org-agenda-skip-if' for details."
4557 (org-agenda-skip-if nil conditions))
4559 (defun org-agenda-skip-subtree-if (&rest conditions)
4560 "Skip entry if any of CONDITIONS is true.
4561 See `org-agenda-skip-if' for details."
4562 (org-agenda-skip-if t conditions))
4564 (defun org-agenda-skip-if (subtree conditions)
4565 "Checks current entity for CONDITIONS.
4566 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4567 the entry (i.e. the text before the next heading) is checked.
4569 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4570 from different tests. Valid conditions are:
4572 scheduled Check if there is a scheduled cookie
4573 notscheduled Check if there is no scheduled cookie
4574 deadline Check if there is a deadline
4575 notdeadline Check if there is no deadline
4576 timestamp Check if there is a timestamp (also deadline or scheduled)
4577 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4578 regexp Check if regexp matches
4579 notregexp Check if regexp does not match.
4580 todo Check if TODO keyword matches
4581 nottodo Check if TODO keyword does not match
4583 The regexp is taken from the conditions list, it must come right after
4584 the `regexp' or `notregexp' element.
4586 `todo' and `nottodo' accept as an argument a list of todo
4587 keywords, which may include \"*\" to match any todo keyword.
4589 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4591 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4593 Instead of a list, a keyword class may be given. For example:
4595 (org-agenda-skip-entry-if 'nottodo 'done)
4597 would skip entries that haven't been marked with any of \"DONE\"
4598 keywords. Possible classes are: `todo', `done', `any'.
4600 If any of these conditions is met, this function returns the end point of
4601 the entity, causing the search to continue from there. This is a function
4602 that can be put into `org-agenda-skip-function' for the duration of a command."
4603 (let (beg end m)
4604 (org-back-to-heading t)
4605 (setq beg (point)
4606 end (if subtree
4607 (progn (org-end-of-subtree t) (point))
4608 (progn (outline-next-heading) (1- (point)))))
4609 (goto-char beg)
4610 (and
4612 (and (memq 'scheduled conditions)
4613 (re-search-forward org-scheduled-time-regexp end t))
4614 (and (memq 'notscheduled conditions)
4615 (not (re-search-forward org-scheduled-time-regexp end t)))
4616 (and (memq 'deadline conditions)
4617 (re-search-forward org-deadline-time-regexp end t))
4618 (and (memq 'notdeadline conditions)
4619 (not (re-search-forward org-deadline-time-regexp end t)))
4620 (and (memq 'timestamp conditions)
4621 (re-search-forward org-ts-regexp end t))
4622 (and (memq 'nottimestamp conditions)
4623 (not (re-search-forward org-ts-regexp end t)))
4624 (and (setq m (memq 'regexp conditions))
4625 (stringp (nth 1 m))
4626 (re-search-forward (nth 1 m) end t))
4627 (and (setq m (memq 'notregexp conditions))
4628 (stringp (nth 1 m))
4629 (not (re-search-forward (nth 1 m) end t)))
4630 (and (or
4631 (setq m (memq 'nottodo conditions))
4632 (setq m (memq 'todo-unblocked conditions))
4633 (setq m (memq 'nottodo-unblocked conditions))
4634 (setq m (memq 'todo conditions)))
4635 (org-agenda-skip-if-todo m end)))
4636 end)))
4638 (defun org-agenda-skip-if-todo (args end)
4639 "Helper function for `org-agenda-skip-if', do not use it directly.
4640 ARGS is a list with first element either `todo', `nottodo',
4641 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4642 a list of TODO keywords, or a state symbol `todo' or `done' or
4643 `any'."
4644 (let ((kw (car args))
4645 (arg (cadr args))
4646 todo-wds todo-re)
4647 (setq todo-wds
4648 (org-uniquify
4649 (cond
4650 ((listp arg) ;; list of keywords
4651 (if (member "*" arg)
4652 (mapcar 'substring-no-properties org-todo-keywords-1)
4653 arg))
4654 ((symbolp arg) ;; keyword class name
4655 (cond
4656 ((eq arg 'todo)
4657 (org-delete-all org-done-keywords
4658 (mapcar 'substring-no-properties
4659 org-todo-keywords-1)))
4660 ((eq arg 'done) org-done-keywords)
4661 ((eq arg 'any)
4662 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4663 (setq todo-re
4664 (concat "^\\*+[ \t]+\\<\\("
4665 (mapconcat 'identity todo-wds "\\|")
4666 "\\)\\>"))
4667 (cond
4668 ((eq kw 'todo) (re-search-forward todo-re end t))
4669 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4670 ((eq kw 'todo-unblocked)
4671 (catch 'unblocked
4672 (while (re-search-forward todo-re end t)
4673 (or (org-entry-blocked-p) (throw 'unblocked t)))
4674 nil))
4675 ((eq kw 'nottodo-unblocked)
4676 (catch 'unblocked
4677 (while (re-search-forward todo-re end t)
4678 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4682 ;;;###autoload
4683 (defun org-agenda-list-stuck-projects (&rest ignore)
4684 "Create agenda view for projects that are stuck.
4685 Stuck projects are project that have no next actions. For the definitions
4686 of what a project is and how to check if it stuck, customize the variable
4687 `org-stuck-projects'."
4688 (interactive)
4689 (let* ((org-agenda-skip-function
4690 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4691 ;; We could have used org-agenda-skip-if here.
4692 (org-agenda-overriding-header
4693 (or org-agenda-overriding-header "List of stuck projects: "))
4694 (matcher (nth 0 org-stuck-projects))
4695 (todo (nth 1 org-stuck-projects))
4696 (todo-wds (if (member "*" todo)
4697 (progn
4698 (org-agenda-prepare-buffers (org-agenda-files
4699 nil 'ifmode))
4700 (org-delete-all
4701 org-done-keywords-for-agenda
4702 (copy-sequence org-todo-keywords-for-agenda)))
4703 todo))
4704 (todo-re (concat "^\\*+[ \t]+\\("
4705 (mapconcat 'identity todo-wds "\\|")
4706 "\\)\\>"))
4707 (tags (nth 2 org-stuck-projects))
4708 (tags-re (if (member "*" tags)
4709 (concat org-outline-regexp-bol
4710 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4711 (if tags
4712 (concat org-outline-regexp-bol
4713 ".*:\\("
4714 (mapconcat 'identity tags "\\|")
4715 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4716 (gen-re (nth 3 org-stuck-projects))
4717 (re-list
4718 (delq nil
4719 (list
4720 (if todo todo-re)
4721 (if tags tags-re)
4722 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4723 gen-re)))))
4724 (setq org-agenda-skip-regexp
4725 (if re-list
4726 (mapconcat 'identity re-list "\\|")
4727 (error "No information how to identify unstuck projects")))
4728 (org-tags-view nil matcher)
4729 (with-current-buffer org-agenda-buffer-name
4730 (setq org-agenda-redo-command
4731 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4733 ;;; Diary integration
4735 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4736 (defvar diary-list-entries-hook)
4737 (defvar diary-time-regexp)
4738 (defun org-get-entries-from-diary (date)
4739 "Get the (Emacs Calendar) diary entries for DATE."
4740 (require 'diary-lib)
4741 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4742 (diary-display-hook '(fancy-diary-display))
4743 (diary-display-function 'fancy-diary-display)
4744 (pop-up-frames nil)
4745 (diary-list-entries-hook
4746 (cons 'org-diary-default-entry diary-list-entries-hook))
4747 (diary-file-name-prefix-function nil) ; turn this feature off
4748 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4749 entries
4750 (org-disable-agenda-to-diary t))
4751 (save-excursion
4752 (save-window-excursion
4753 (funcall (if (fboundp 'diary-list-entries)
4754 'diary-list-entries 'list-diary-entries)
4755 date 1)))
4756 (if (not (get-buffer diary-fancy-buffer))
4757 (setq entries nil)
4758 (with-current-buffer diary-fancy-buffer
4759 (setq buffer-read-only nil)
4760 (if (zerop (buffer-size))
4761 ;; No entries
4762 (setq entries nil)
4763 ;; Omit the date and other unnecessary stuff
4764 (org-agenda-cleanup-fancy-diary)
4765 ;; Add prefix to each line and extend the text properties
4766 (if (zerop (buffer-size))
4767 (setq entries nil)
4768 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4769 (setq entries
4770 (with-temp-buffer
4771 (insert entries) (goto-char (point-min))
4772 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4773 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4774 (replace-match (concat "; " (match-string 1)))))
4775 (buffer-string)))))
4776 (set-buffer-modified-p nil)
4777 (kill-buffer diary-fancy-buffer)))
4778 (when entries
4779 (setq entries (org-split-string entries "\n"))
4780 (setq entries
4781 (mapcar
4782 (lambda (x)
4783 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4784 ;; Extend the text properties to the beginning of the line
4785 (org-add-props x (text-properties-at (1- (length x)) x)
4786 'type "diary" 'date date 'face 'org-agenda-diary))
4787 entries)))))
4789 (defvar org-agenda-cleanup-fancy-diary-hook nil
4790 "Hook run when the fancy diary buffer is cleaned up.")
4792 (defun org-agenda-cleanup-fancy-diary ()
4793 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4794 This gets rid of the date, the underline under the date, and
4795 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4796 date. It also removes lines that contain only whitespace."
4797 (goto-char (point-min))
4798 (if (looking-at ".*?:[ \t]*")
4799 (progn
4800 (replace-match "")
4801 (re-search-forward "\n=+$" nil t)
4802 (replace-match "")
4803 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4804 (re-search-forward "\n=+$" nil t)
4805 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4806 (goto-char (point-min))
4807 (while (re-search-forward "^ +\n" nil t)
4808 (replace-match ""))
4809 (goto-char (point-min))
4810 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4811 (replace-match ""))
4812 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4814 ;; Make sure entries from the diary have the right text properties.
4815 (eval-after-load "diary-lib"
4816 '(if (boundp 'diary-modify-entry-list-string-function)
4817 ;; We can rely on the hook, nothing to do
4819 ;; Hook not available, must use advice to make this work
4820 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4821 "Make the position visible."
4822 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4823 (stringp string)
4824 buffer-file-name)
4825 (setq string (org-modify-diary-entry-string string))))))
4827 (defun org-modify-diary-entry-string (string)
4828 "Add text properties to string, allowing org-mode to act on it."
4829 (org-add-props string nil
4830 'mouse-face 'highlight
4831 'help-echo (if buffer-file-name
4832 (format "mouse-2 or RET jump to diary file %s"
4833 (abbreviate-file-name buffer-file-name))
4835 'org-agenda-diary-link t
4836 'org-marker (org-agenda-new-marker (point-at-bol))))
4838 (defun org-diary-default-entry ()
4839 "Add a dummy entry to the diary.
4840 Needed to avoid empty dates which mess up holiday display."
4841 ;; Catch the error if dealing with the new add-to-diary-alist
4842 (when org-disable-agenda-to-diary
4843 (condition-case nil
4844 (org-add-to-diary-list original-date "Org-mode dummy" "")
4845 (error
4846 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4848 (defun org-add-to-diary-list (&rest args)
4849 (if (fboundp 'diary-add-to-list)
4850 (apply 'diary-add-to-list args)
4851 (apply 'add-to-diary-list args)))
4853 (defvar org-diary-last-run-time nil)
4855 ;;;###autoload
4856 (defun org-diary (&rest args)
4857 "Return diary information from org files.
4858 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4859 It accesses org files and extracts information from those files to be
4860 listed in the diary. The function accepts arguments specifying what
4861 items should be listed. For a list of arguments allowed here, see the
4862 variable `org-agenda-entry-types'.
4864 The call in the diary file should look like this:
4866 &%%(org-diary) ~/path/to/some/orgfile.org
4868 Use a separate line for each org file to check. Or, if you omit the file name,
4869 all files listed in `org-agenda-files' will be checked automatically:
4871 &%%(org-diary)
4873 If you don't give any arguments (as in the example above), the default
4874 arguments (:deadline :scheduled :timestamp :sexp) are used.
4875 So the example above may also be written as
4877 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4879 The function expects the lisp variables `entry' and `date' to be provided
4880 by the caller, because this is how the calendar works. Don't use this
4881 function from a program - use `org-agenda-get-day-entries' instead."
4882 (when (> (- (org-float-time)
4883 org-agenda-last-marker-time)
4885 ;; I am not sure if this works with sticky agendas, because the marker
4886 ;; list is then no longer a global variable.
4887 (org-agenda-reset-markers))
4888 (org-compile-prefix-format 'agenda)
4889 (org-set-sorting-strategy 'agenda)
4890 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4891 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4892 (list entry)
4893 (org-agenda-files t)))
4894 (time (org-float-time))
4895 file rtn results)
4896 (when (or (not org-diary-last-run-time)
4897 (> (- time
4898 org-diary-last-run-time)
4900 (org-agenda-prepare-buffers files))
4901 (setq org-diary-last-run-time time)
4902 ;; If this is called during org-agenda, don't return any entries to
4903 ;; the calendar. Org Agenda will list these entries itself.
4904 (if org-disable-agenda-to-diary (setq files nil))
4905 (while (setq file (pop files))
4906 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4907 (setq results (append results rtn)))
4908 (if results
4909 (concat (org-agenda-finalize-entries results) "\n"))))
4911 ;;; Agenda entry finders
4913 (defun org-agenda-get-day-entries (file date &rest args)
4914 "Does the work for `org-diary' and `org-agenda'.
4915 FILE is the path to a file to be checked for entries. DATE is date like
4916 the one returned by `calendar-current-date'. ARGS are symbols indicating
4917 which kind of entries should be extracted. For details about these, see
4918 the documentation of `org-diary'."
4919 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4920 (let* ((org-startup-folded nil)
4921 (org-startup-align-all-tables nil)
4922 (buffer (if (file-exists-p file)
4923 (org-get-agenda-file-buffer file)
4924 (error "No such file %s" file)))
4925 arg results rtn deadline-results)
4926 (if (not buffer)
4927 ;; If file does not exist, make sure an error message ends up in diary
4928 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4929 (with-current-buffer buffer
4930 (unless (derived-mode-p 'org-mode)
4931 (error "Agenda file %s is not in `org-mode'" file))
4932 (setq org-agenda-buffer (or org-agenda-buffer buffer))
4933 (let ((case-fold-search nil))
4934 (save-excursion
4935 (save-restriction
4936 (if org-agenda-restrict
4937 (narrow-to-region org-agenda-restrict-begin
4938 org-agenda-restrict-end)
4939 (widen))
4940 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4941 (while (setq arg (pop args))
4942 (cond
4943 ((and (eq arg :todo)
4944 (equal date (calendar-gregorian-from-absolute
4945 (org-today))))
4946 (setq rtn (org-agenda-get-todos))
4947 (setq results (append results rtn)))
4948 ((eq arg :timestamp)
4949 (setq rtn (org-agenda-get-blocks))
4950 (setq results (append results rtn))
4951 (setq rtn (org-agenda-get-timestamps deadline-results))
4952 (setq results (append results rtn)))
4953 ((eq arg :sexp)
4954 (setq rtn (org-agenda-get-sexps))
4955 (setq results (append results rtn)))
4956 ((eq arg :scheduled)
4957 (setq rtn (org-agenda-get-scheduled deadline-results))
4958 (setq results (append results rtn)))
4959 ((eq arg :closed)
4960 (setq rtn (org-agenda-get-progress))
4961 (setq results (append results rtn)))
4962 ((eq arg :deadline)
4963 (setq rtn (org-agenda-get-deadlines))
4964 (setq deadline-results (copy-sequence rtn))
4965 (setq results (append results rtn))))))))
4966 results))))
4968 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4969 (defun org-agenda-get-todos ()
4970 "Return the TODO information for agenda display."
4971 (let* ((props (list 'face nil
4972 'done-face 'org-agenda-done
4973 'org-not-done-regexp org-not-done-regexp
4974 'org-todo-regexp org-todo-regexp
4975 'org-complex-heading-regexp org-complex-heading-regexp
4976 'mouse-face 'highlight
4977 'help-echo
4978 (format "mouse-2 or RET jump to org file %s"
4979 (abbreviate-file-name buffer-file-name))))
4980 (regexp (format org-heading-keyword-regexp-format
4981 (cond
4982 ((and org-select-this-todo-keyword
4983 (equal org-select-this-todo-keyword "*"))
4984 org-todo-regexp)
4985 (org-select-this-todo-keyword
4986 (concat "\\("
4987 (mapconcat 'identity
4988 (org-split-string
4989 org-select-this-todo-keyword
4990 "|")
4991 "\\|") "\\)"))
4992 (t org-not-done-regexp))))
4993 marker priority category category-pos tags todo-state
4994 ee txt beg end)
4995 (goto-char (point-min))
4996 (while (re-search-forward regexp nil t)
4997 (catch :skip
4998 (save-match-data
4999 (beginning-of-line)
5000 (org-agenda-skip)
5001 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5002 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5003 (goto-char (1+ beg))
5004 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5005 (throw :skip nil)))
5006 (goto-char (match-beginning 2))
5007 (setq marker (org-agenda-new-marker (match-beginning 0))
5008 category (org-get-category)
5009 category-pos (get-text-property (point) 'org-category-position)
5010 txt (org-trim
5011 (buffer-substring (match-beginning 2) (match-end 0)))
5012 tags (org-get-tags-at (point))
5013 txt (org-agenda-format-item "" txt category tags t)
5014 priority (1+ (org-get-priority txt))
5015 todo-state (org-get-todo-state))
5016 (org-add-props txt props
5017 'org-marker marker 'org-hd-marker marker
5018 'priority priority 'org-category category
5019 'org-category-position category-pos
5020 'type "todo" 'todo-state todo-state)
5021 (push txt ee)
5022 (if org-agenda-todo-list-sublevels
5023 (goto-char (match-end 2))
5024 (org-end-of-subtree 'invisible))))
5025 (nreverse ee)))
5027 (defun org-agenda-todo-custom-ignore-p (time n)
5028 "Check whether timestamp is farther away then n number of days.
5029 This function is invoked if `org-agenda-todo-ignore-deadlines',
5030 `org-agenda-todo-ignore-scheduled' or
5031 `org-agenda-todo-ignore-timestamp' is set to an integer."
5032 (let ((days (org-days-to-time time)))
5033 (if (>= n 0)
5034 (>= days n)
5035 (<= days n))))
5037 ;;;###autoload
5038 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5039 (&optional end)
5040 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5041 (when (or org-agenda-todo-ignore-with-date
5042 org-agenda-todo-ignore-scheduled
5043 org-agenda-todo-ignore-deadlines
5044 org-agenda-todo-ignore-timestamp)
5045 (setq end (or end (save-excursion (outline-next-heading) (point))))
5046 (save-excursion
5047 (or (and org-agenda-todo-ignore-with-date
5048 (re-search-forward org-ts-regexp end t))
5049 (and org-agenda-todo-ignore-scheduled
5050 (re-search-forward org-scheduled-time-regexp end t)
5051 (cond
5052 ((eq org-agenda-todo-ignore-scheduled 'future)
5053 (> (org-days-to-time (match-string 1)) 0))
5054 ((eq org-agenda-todo-ignore-scheduled 'past)
5055 (<= (org-days-to-time (match-string 1)) 0))
5056 ((numberp org-agenda-todo-ignore-scheduled)
5057 (org-agenda-todo-custom-ignore-p
5058 (match-string 1) org-agenda-todo-ignore-scheduled))
5059 (t)))
5060 (and org-agenda-todo-ignore-deadlines
5061 (re-search-forward org-deadline-time-regexp end t)
5062 (cond
5063 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5064 ((eq org-agenda-todo-ignore-deadlines 'far)
5065 (not (org-deadline-close (match-string 1))))
5066 ((eq org-agenda-todo-ignore-deadlines 'future)
5067 (> (org-days-to-time (match-string 1)) 0))
5068 ((eq org-agenda-todo-ignore-deadlines 'past)
5069 (<= (org-days-to-time (match-string 1)) 0))
5070 ((numberp org-agenda-todo-ignore-deadlines)
5071 (org-agenda-todo-custom-ignore-p
5072 (match-string 1) org-agenda-todo-ignore-deadlines))
5073 (t (org-deadline-close (match-string 1)))))
5074 (and org-agenda-todo-ignore-timestamp
5075 (let ((buffer (current-buffer))
5076 (regexp
5077 (concat
5078 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5079 (start (point)))
5080 ;; Copy current buffer into a temporary one
5081 (with-temp-buffer
5082 (insert-buffer-substring buffer start end)
5083 (goto-char (point-min))
5084 ;; Delete SCHEDULED and DEADLINE items
5085 (while (re-search-forward regexp end t)
5086 (delete-region (match-beginning 0) (match-end 0)))
5087 (goto-char (point-min))
5088 ;; No search for timestamp left
5089 (when (re-search-forward org-ts-regexp nil t)
5090 (cond
5091 ((eq org-agenda-todo-ignore-timestamp 'future)
5092 (> (org-days-to-time (match-string 1)) 0))
5093 ((eq org-agenda-todo-ignore-timestamp 'past)
5094 (<= (org-days-to-time (match-string 1)) 0))
5095 ((numberp org-agenda-todo-ignore-timestamp)
5096 (org-agenda-todo-custom-ignore-p
5097 (match-string 1) org-agenda-todo-ignore-timestamp))
5098 (t))))))))))
5100 (defconst org-agenda-no-heading-message
5101 "No heading for this item in buffer or region.")
5103 (defun org-agenda-get-timestamps (&optional deadline-results)
5104 "Return the date stamp information for agenda display."
5105 (let* ((props (list 'face 'org-agenda-calendar-event
5106 'org-not-done-regexp org-not-done-regexp
5107 'org-todo-regexp org-todo-regexp
5108 'org-complex-heading-regexp org-complex-heading-regexp
5109 'mouse-face 'highlight
5110 'help-echo
5111 (format "mouse-2 or RET jump to org file %s"
5112 (abbreviate-file-name buffer-file-name))))
5113 (d1 (calendar-absolute-from-gregorian date))
5115 (deadline-position-alist
5116 (mapcar (lambda (a) (and (setq mm (get-text-property
5117 0 'org-hd-marker a))
5118 (cons (marker-position mm) a)))
5119 deadline-results))
5120 (remove-re org-ts-regexp)
5121 (regexp
5122 (concat
5123 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5124 (regexp-quote
5125 (substring
5126 (format-time-string
5127 (car org-time-stamp-formats)
5128 (apply 'encode-time ; DATE bound by calendar
5129 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5130 1 11))
5131 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5132 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5133 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5134 donep tmp priority category category-pos ee txt timestr tags
5135 b0 b3 e3 head todo-state end-of-match show-all warntime)
5136 (goto-char (point-min))
5137 (while (setq end-of-match (re-search-forward regexp nil t))
5138 (setq b0 (match-beginning 0)
5139 b3 (match-beginning 3) e3 (match-end 3)
5140 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5141 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5142 (member todo-state
5143 org-agenda-repeating-timestamp-show-all)))
5144 (catch :skip
5145 (and (org-at-date-range-p) (throw :skip nil))
5146 (org-agenda-skip)
5147 (if (and (match-end 1)
5148 (not (= d1 (org-time-string-to-absolute
5149 (match-string 1) d1 nil show-all
5150 (current-buffer) b0))))
5151 (throw :skip nil))
5152 (if (and e3
5153 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5154 (throw :skip nil))
5155 (setq tmp (buffer-substring (max (point-min)
5156 (- b0 org-ds-keyword-length))
5158 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5159 inactivep (= (char-after b0) ?\[)
5160 deadlinep (string-match org-deadline-regexp tmp)
5161 scheduledp (string-match org-scheduled-regexp tmp)
5162 closedp (and org-agenda-include-inactive-timestamps
5163 (string-match org-closed-string tmp))
5164 clockp (and org-agenda-include-inactive-timestamps
5165 (or (string-match org-clock-string tmp)
5166 (string-match "]-+\\'" tmp)))
5167 warntime (org-entry-get (point) "APPT_WARNTIME")
5168 donep (member todo-state org-done-keywords))
5169 (if (or scheduledp deadlinep closedp clockp
5170 (and donep org-agenda-skip-timestamp-if-done))
5171 (throw :skip t))
5172 (if (string-match ">" timestr)
5173 ;; substring should only run to end of time stamp
5174 (setq timestr (substring timestr 0 (match-end 0))))
5175 (setq marker (org-agenda-new-marker b0)
5176 category (org-get-category b0)
5177 category-pos (get-text-property b0 'org-category-position))
5178 (save-excursion
5179 (if (not (re-search-backward org-outline-regexp-bol nil t))
5180 (setq txt org-agenda-no-heading-message)
5181 (goto-char (match-beginning 0))
5182 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5183 (assoc (point) deadline-position-alist))
5184 (throw :skip nil))
5185 (setq hdmarker (org-agenda-new-marker)
5186 tags (org-get-tags-at))
5187 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5188 (setq head (or (match-string 1) ""))
5189 (setq txt (org-agenda-format-item
5190 (if inactivep org-agenda-inactive-leader nil)
5191 head category tags timestr
5192 remove-re t)))
5193 (setq priority (org-get-priority txt))
5194 (org-add-props txt props
5195 'org-marker marker 'org-hd-marker hdmarker)
5196 (org-add-props txt nil 'priority priority
5197 'org-category category 'date date
5198 'org-category-position category-pos
5199 'todo-state todo-state
5200 'warntime warntime
5201 'type "timestamp")
5202 (push txt ee))
5203 (if org-agenda-skip-additional-timestamps-same-entry
5204 (outline-next-heading)
5205 (goto-char end-of-match))))
5206 (nreverse ee)))
5208 (defun org-agenda-get-sexps ()
5209 "Return the sexp information for agenda display."
5210 (require 'diary-lib)
5211 (let* ((props (list 'face 'org-agenda-calendar-sexp
5212 'mouse-face 'highlight
5213 'help-echo
5214 (format "mouse-2 or RET jump to org file %s"
5215 (abbreviate-file-name buffer-file-name))))
5216 (regexp "^&?%%(")
5217 marker category extra category-pos ee txt tags entry
5218 result beg b sexp sexp-entry todo-state warntime)
5219 (goto-char (point-min))
5220 (while (re-search-forward regexp nil t)
5221 (catch :skip
5222 (org-agenda-skip)
5223 (setq beg (match-beginning 0))
5224 (goto-char (1- (match-end 0)))
5225 (setq b (point))
5226 (forward-sexp 1)
5227 (setq sexp (buffer-substring b (point)))
5228 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5229 (org-trim (match-string 1))
5230 ""))
5231 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5232 (when result
5233 (setq marker (org-agenda-new-marker beg)
5234 category (org-get-category beg)
5235 category-pos (get-text-property beg 'org-category-position)
5236 tags (save-excursion (org-backward-heading-same-level 0)
5237 (org-get-tags-at))
5238 todo-state (org-get-todo-state)
5239 warntime (org-entry-get (point) "APPT_WARNTIME"))
5241 (dolist (r (if (stringp result)
5242 (list result)
5243 result)) ;; we expect a list here
5244 (when (and org-agenda-diary-sexp-prefix
5245 (string-match org-agenda-diary-sexp-prefix r))
5246 (setq extra (match-string 0 r)
5247 r (replace-match "" nil nil r)))
5248 (if (string-match "\\S-" r)
5249 (setq txt r)
5250 (setq txt "SEXP entry returned empty string"))
5252 (setq txt (org-agenda-format-item
5253 extra txt category tags 'time))
5254 (org-add-props txt props 'org-marker marker)
5255 (org-add-props txt nil
5256 'org-category category 'date date 'todo-state todo-state
5257 'org-category-position category-pos 'tags tags
5258 'type "sexp" 'warntime warntime)
5259 (push txt ee)))))
5260 (nreverse ee)))
5262 ;; Calendar sanity: define some functions that are independent of
5263 ;; `calendar-date-style'.
5264 ;; Normally I would like to use ISO format when calling the diary functions,
5265 ;; but to make sure we still have Emacs 22 compatibility we bind
5266 ;; also `european-calendar-style' and use european format
5267 (defun org-anniversary (year month day &optional mark)
5268 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5269 (org-no-warnings
5270 (let ((calendar-date-style 'european) (european-calendar-style t))
5271 (diary-anniversary day month year mark))))
5272 (defun org-cyclic (N year month day &optional mark)
5273 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5274 (org-no-warnings
5275 (let ((calendar-date-style 'european) (european-calendar-style t))
5276 (diary-cyclic N day month year mark))))
5277 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5278 "Like `diary-block', but with fixed (ISO) order of arguments."
5279 (org-no-warnings
5280 (let ((calendar-date-style 'european) (european-calendar-style t))
5281 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5282 (defun org-date (year month day &optional mark)
5283 "Like `diary-date', but with fixed (ISO) order of arguments."
5284 (org-no-warnings
5285 (let ((calendar-date-style 'european) (european-calendar-style t))
5286 (diary-date day month year mark))))
5287 (defalias 'org-float 'diary-float)
5289 ;; Define the` org-class' function
5290 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5291 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5292 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5293 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5294 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5295 `holidays', then any date that is known by the Emacs calendar to be a
5296 holiday will also be skipped."
5297 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5298 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5299 (d (calendar-absolute-from-gregorian date)))
5300 (and
5301 (<= date1 d)
5302 (<= d date2)
5303 (= (calendar-day-of-week date) dayname)
5304 (or (not skip-weeks)
5305 (progn
5306 (require 'cal-iso)
5307 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5308 (not (and (memq 'holidays skip-weeks)
5309 (calendar-check-holidays date)))
5310 entry)))
5312 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5313 "Like `org-class', but honor `calendar-date-style'.
5314 The order of the first 2 times 3 arguments depends on the variable
5315 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5316 So for American calendars, give this as MONTH DAY YEAR, for European as
5317 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5318 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5319 is any number of ISO weeks in the block period for which the item should
5320 be skipped.
5322 This function is here only for backward compatibility and it is deprecated,
5323 please use `org-class' instead."
5324 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5325 (date2 (org-order-calendar-date-args m2 d2 y2)))
5326 (org-class
5327 (nth 2 date1) (car date1) (nth 1 date1)
5328 (nth 2 date2) (car date2) (nth 1 date2)
5329 dayname skip-weeks)))
5330 (make-obsolete 'org-diary-class 'org-class "")
5332 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5333 (defalias 'org-get-closed 'org-agenda-get-progress)
5334 (defun org-agenda-get-progress ()
5335 "Return the logged TODO entries for agenda display."
5336 (let* ((props (list 'mouse-face 'highlight
5337 'org-not-done-regexp org-not-done-regexp
5338 'org-todo-regexp org-todo-regexp
5339 'org-complex-heading-regexp org-complex-heading-regexp
5340 'help-echo
5341 (format "mouse-2 or RET jump to org file %s"
5342 (abbreviate-file-name buffer-file-name))))
5343 (items (if (consp org-agenda-show-log-scoped)
5344 org-agenda-show-log-scoped
5345 (if (eq org-agenda-show-log-scoped 'clockcheck)
5346 '(clock)
5347 org-agenda-log-mode-items)))
5348 (parts
5349 (delq nil
5350 (list
5351 (if (memq 'closed items) (concat "\\<" org-closed-string))
5352 (if (memq 'clock items) (concat "\\<" org-clock-string))
5353 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5354 (parts-re (if parts (mapconcat 'identity parts "\\|")
5355 (error "`org-agenda-log-mode-items' is empty")))
5356 (regexp (concat
5357 "\\(" parts-re "\\)"
5358 " *\\["
5359 (regexp-quote
5360 (substring
5361 (format-time-string
5362 (car org-time-stamp-formats)
5363 (apply 'encode-time ; DATE bound by calendar
5364 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5365 1 11))))
5366 (org-agenda-search-headline-for-time nil)
5367 marker hdmarker priority category category-pos tags closedp
5368 statep clockp state ee txt extra timestr rest clocked)
5369 (goto-char (point-min))
5370 (while (re-search-forward regexp nil t)
5371 (catch :skip
5372 (org-agenda-skip)
5373 (setq marker (org-agenda-new-marker (match-beginning 0))
5374 closedp (equal (match-string 1) org-closed-string)
5375 statep (equal (string-to-char (match-string 1)) ?-)
5376 clockp (not (or closedp statep))
5377 state (and statep (match-string 2))
5378 category (org-get-category (match-beginning 0))
5379 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5380 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5381 (when (string-match "\\]" timestr)
5382 ;; substring should only run to end of time stamp
5383 (setq rest (substring timestr (match-end 0))
5384 timestr (substring timestr 0 (match-end 0)))
5385 (if (and (not closedp) (not statep)
5386 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5387 rest))
5388 (progn (setq timestr (concat (substring timestr 0 -1)
5389 "-" (match-string 1 rest) "]"))
5390 (setq clocked (match-string 2 rest)))
5391 (setq clocked "-")))
5392 (save-excursion
5393 (setq extra
5394 (cond
5395 ((not org-agenda-log-mode-add-notes) nil)
5396 (statep
5397 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5398 (match-string 1)))
5399 (clockp
5400 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5401 (match-string 1)))))
5402 (if (not (re-search-backward org-outline-regexp-bol nil t))
5403 (setq txt org-agenda-no-heading-message)
5404 (goto-char (match-beginning 0))
5405 (setq hdmarker (org-agenda-new-marker)
5406 tags (org-get-tags-at))
5407 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5408 (setq txt (match-string 1))
5409 (when extra
5410 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5411 (setq txt (concat (substring txt 0 (match-beginning 1))
5412 " - " extra " " (match-string 2 txt)))
5413 (setq txt (concat txt " - " extra))))
5414 (setq txt (org-agenda-format-item
5415 (cond
5416 (closedp "Closed: ")
5417 (statep (concat "State: (" state ")"))
5418 (t (concat "Clocked: (" clocked ")")))
5419 txt category tags timestr)))
5420 (setq priority 100000)
5421 (org-add-props txt props
5422 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5423 'priority priority 'org-category category
5424 'org-category-position category-pos
5425 'type "closed" 'date date
5426 'undone-face 'org-warning 'done-face 'org-agenda-done)
5427 (push txt ee))
5428 (goto-char (point-at-eol))))
5429 (nreverse ee)))
5431 (defun org-agenda-show-clocking-issues ()
5432 "Add overlays, showing issues with clocking.
5433 See also the user option `org-agenda-clock-consistency-checks'."
5434 (interactive)
5435 (let* ((pl org-agenda-clock-consistency-checks)
5436 (re (concat "^[ \t]*"
5437 org-clock-string
5438 "[ \t]+"
5439 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5440 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5441 (tlstart 0.)
5442 (tlend 0.)
5443 (maxtime (org-hh:mm-string-to-minutes
5444 (or (plist-get pl :max-duration) "24:00")))
5445 (mintime (org-hh:mm-string-to-minutes
5446 (or (plist-get pl :min-duration) 0)))
5447 (maxgap (org-hh:mm-string-to-minutes
5448 ;; default 30:00 means never complain
5449 (or (plist-get pl :max-gap) "30:00")))
5450 (gapok (mapcar 'org-hh:mm-string-to-minutes
5451 (plist-get pl :gap-ok-around)))
5452 (def-face (or (plist-get pl :default-face)
5453 '((:background "DarkRed") (:foreground "white"))))
5454 issue face m te ts dt ov)
5455 (goto-char (point-min))
5456 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5457 (setq issue nil face def-face)
5458 (catch 'next
5459 (setq m (org-get-at-bol 'org-marker)
5460 te nil ts nil)
5461 (unless (and m (markerp m))
5462 (setq issue "No valid clock line") (throw 'next t))
5463 (org-with-point-at m
5464 (save-excursion
5465 (goto-char (point-at-bol))
5466 (unless (looking-at re)
5467 (error "No valid Clock line")
5468 (throw 'next t))
5469 (unless (match-end 3)
5470 (setq issue "No end time"
5471 face (or (plist-get pl :no-end-time-face) face))
5472 (throw 'next t))
5473 (setq ts (match-string 1)
5474 te (match-string 3)
5475 ts (org-float-time
5476 (apply 'encode-time (org-parse-time-string ts)))
5477 te (org-float-time
5478 (apply 'encode-time (org-parse-time-string te)))
5479 dt (- te ts))))
5480 (cond
5481 ((> dt (* 60 maxtime))
5482 ;; a very long clocking chunk
5483 (setq issue (format "Clocking interval is very long: %s"
5484 (org-minutes-to-hh:mm-string
5485 (floor (/ (float dt) 60.))))
5486 face (or (plist-get pl :long-face) face)))
5487 ((< dt (* 60 mintime))
5488 ;; a very short clocking chunk
5489 (setq issue (format "Clocking interval is very short: %s"
5490 (org-minutes-to-hh:mm-string
5491 (floor (/ (float dt) 60.))))
5492 face (or (plist-get pl :short-face) face)))
5493 ((and (> tlend 0) (< ts tlend))
5494 ;; Two clock entries are overlapping
5495 (setq issue (format "Clocking overlap: %d minutes"
5496 (/ (- tlend ts) 60))
5497 face (or (plist-get pl :overlap-face) face)))
5498 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5499 ;; There is a gap, lets see if we need to report it
5500 (unless (org-agenda-check-clock-gap tlend ts gapok)
5501 (setq issue (format "Clocking gap: %d minutes"
5502 (/ (- ts tlend) 60))
5503 face (or (plist-get pl :gap-face) face))))
5504 (t nil)))
5505 (setq tlend (or te tlend) tlstart (or ts tlstart))
5506 (when issue
5507 ;; OK, there was some issue, add an overlay to show the issue
5508 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5509 (overlay-put ov 'before-string
5510 (concat
5511 (org-add-props
5512 (format "%-43s" (concat " " issue))
5514 'face face)
5515 "\n"))
5516 (overlay-put ov 'evaporate t)))))
5518 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5519 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5520 (catch 'exit
5521 (unless ok-list
5522 ;; there are no OK times for gaps...
5523 (throw 'exit nil))
5524 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5525 ;; This is more than 24 hours, so it is OK.
5526 ;; because we have at least one OK time, that must be in the
5527 ;; 24 hour interval.
5528 (throw 'exit t))
5529 ;; We have a shorter gap.
5530 ;; Now we have to get the minute of the day when these times are
5531 (let* ((t1dec (decode-time (seconds-to-time t1)))
5532 (t2dec (decode-time (seconds-to-time t2)))
5533 ;; compute the minute on the day
5534 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5535 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5536 (when (< min2 min1)
5537 ;; if min2 is smaller than min1, this means it is on the next day.
5538 ;; Wrap it to after midnight.
5539 (setq min2 (+ min2 1440)))
5540 ;; Now check if any of the OK times is in the gap
5541 (mapc (lambda (x)
5542 ;; Wrap the time to after midnight if necessary
5543 (if (< x min1) (setq x (+ x 1440)))
5544 ;; Check if in interval
5545 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5546 ok-list)
5547 ;; Nope, this gap is not OK
5548 nil)))
5550 (defun org-agenda-get-deadlines ()
5551 "Return the deadline information for agenda display."
5552 (let* ((props (list 'mouse-face 'highlight
5553 'org-not-done-regexp org-not-done-regexp
5554 'org-todo-regexp org-todo-regexp
5555 'org-complex-heading-regexp org-complex-heading-regexp
5556 'help-echo
5557 (format "mouse-2 or RET jump to org file %s"
5558 (abbreviate-file-name buffer-file-name))))
5559 (regexp org-deadline-time-regexp)
5560 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5561 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5562 d2 diff dfrac wdays pos pos1 category category-pos
5563 tags suppress-prewarning ee txt head face s todo-state
5564 show-all upcomingp donep timestr warntime)
5565 (goto-char (point-min))
5566 (while (re-search-forward regexp nil t)
5567 (setq suppress-prewarning nil)
5568 (catch :skip
5569 (org-agenda-skip)
5570 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5571 (save-match-data
5572 (string-match org-scheduled-time-regexp
5573 (buffer-substring (point-at-bol)
5574 (point-at-eol)))))
5575 (setq suppress-prewarning
5576 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5577 org-agenda-skip-deadline-prewarning-if-scheduled
5578 0)))
5579 (setq s (match-string 1)
5580 txt nil
5581 pos (1- (match-beginning 1))
5582 todo-state (save-match-data (org-get-todo-state))
5583 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5584 (member todo-state
5585 org-agenda-repeating-timestamp-show-all))
5586 d2 (org-time-string-to-absolute
5587 (match-string 1) d1 'past show-all
5588 (current-buffer) pos)
5589 diff (- d2 d1)
5590 wdays (if suppress-prewarning
5591 (let ((org-deadline-warning-days suppress-prewarning))
5592 (org-get-wdays s))
5593 (org-get-wdays s))
5594 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5595 upcomingp (and todayp (> diff 0)))
5596 ;; When to show a deadline in the calendar:
5597 ;; If the expiration is within wdays warning time.
5598 ;; Past-due deadlines are only shown on the current date
5599 (if (and (or (and (<= diff wdays)
5600 (and todayp (not org-agenda-only-exact-dates)))
5601 (= diff 0)))
5602 (save-excursion
5603 ;; (setq todo-state (org-get-todo-state))
5604 (setq donep (member todo-state org-done-keywords))
5605 (if (and donep
5606 (or org-agenda-skip-deadline-if-done
5607 (not (= diff 0))))
5608 (setq txt nil)
5609 (setq category (org-get-category)
5610 warntime (org-entry-get (point) "APPT_WARNTIME")
5611 category-pos (get-text-property (point) 'org-category-position))
5612 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5613 (setq txt org-agenda-no-heading-message)
5614 (goto-char (match-end 0))
5615 (setq pos1 (match-beginning 0))
5616 (setq tags (org-get-tags-at pos1))
5617 (setq head (buffer-substring-no-properties
5618 (point)
5619 (progn (skip-chars-forward "^\r\n")
5620 (point))))
5621 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5622 (setq timestr
5623 (concat (substring s (match-beginning 1)) " "))
5624 (setq timestr 'time))
5625 (setq txt (org-agenda-format-item
5626 (if (= diff 0)
5627 (car org-agenda-deadline-leaders)
5628 (if (functionp
5629 (nth 1 org-agenda-deadline-leaders))
5630 (funcall
5631 (nth 1 org-agenda-deadline-leaders)
5632 diff date)
5633 (format (nth 1 org-agenda-deadline-leaders)
5634 diff)))
5635 head category tags
5636 (if (not (= diff 0)) nil timestr)))))
5637 (when txt
5638 (setq face (org-agenda-deadline-face dfrac))
5639 (org-add-props txt props
5640 'org-marker (org-agenda-new-marker pos)
5641 'warntime warntime
5642 'org-hd-marker (org-agenda-new-marker pos1)
5643 'priority (+ (- diff)
5644 (org-get-priority txt))
5645 'org-category category
5646 'org-category-position category-pos
5647 'todo-state todo-state
5648 'type (if upcomingp "upcoming-deadline" "deadline")
5649 'date (if upcomingp date d2)
5650 'face (if donep 'org-agenda-done face)
5651 'undone-face face 'done-face 'org-agenda-done)
5652 (push txt ee))))))
5653 (nreverse ee)))
5655 (defun org-agenda-deadline-face (fraction)
5656 "Return the face to displaying a deadline item.
5657 FRACTION is what fraction of the head-warning time has passed."
5658 (let ((faces org-agenda-deadline-faces) f)
5659 (catch 'exit
5660 (while (setq f (pop faces))
5661 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5663 (defun org-agenda-get-scheduled (&optional deadline-results)
5664 "Return the scheduled information for agenda display."
5665 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5666 'org-todo-regexp org-todo-regexp
5667 'org-complex-heading-regexp org-complex-heading-regexp
5668 'done-face 'org-agenda-done
5669 'mouse-face 'highlight
5670 'help-echo
5671 (format "mouse-2 or RET jump to org file %s"
5672 (abbreviate-file-name buffer-file-name))))
5673 (regexp org-scheduled-time-regexp)
5674 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5675 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5677 (deadline-position-alist
5678 (mapcar (lambda (a) (and (setq mm (get-text-property
5679 0 'org-hd-marker a))
5680 (cons (marker-position mm) a)))
5681 deadline-results))
5682 d2 diff pos pos1 category category-pos tags donep
5683 ee txt head pastschedp todo-state face timestr s habitp show-all
5684 did-habit-check-p warntime)
5685 (goto-char (point-min))
5686 (while (re-search-forward regexp nil t)
5687 (catch :skip
5688 (org-agenda-skip)
5689 (setq s (match-string 1)
5690 txt nil
5691 pos (1- (match-beginning 1))
5692 todo-state (save-match-data (org-get-todo-state))
5693 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5694 (member todo-state
5695 org-agenda-repeating-timestamp-show-all))
5696 d2 (org-time-string-to-absolute
5697 (match-string 1) d1 'past show-all
5698 (current-buffer) pos)
5699 diff (- d2 d1)
5700 warntime (org-entry-get (point) "APPT_WARNTIME"))
5701 (setq pastschedp (and todayp (< diff 0)))
5702 (setq did-habit-check-p nil)
5703 ;; When to show a scheduled item in the calendar:
5704 ;; If it is on or past the date.
5705 (when (or (and (< diff 0)
5706 (< (abs diff) org-scheduled-past-days)
5707 (and todayp (not org-agenda-only-exact-dates)))
5708 (= diff 0)
5709 ;; org-is-habit-p uses org-entry-get, which is expansive
5710 ;; so we go extra mile to only call it once
5711 (and todayp
5712 (boundp 'org-habit-show-all-today)
5713 org-habit-show-all-today
5714 (setq did-habit-check-p t)
5715 (setq habitp (and (functionp 'org-is-habit-p)
5716 (org-is-habit-p)))))
5717 (save-excursion
5718 (setq donep (member todo-state org-done-keywords))
5719 (if (and donep
5720 (or org-agenda-skip-scheduled-if-done
5721 (not (= diff 0))
5722 (and (functionp 'org-is-habit-p)
5723 (org-is-habit-p))))
5724 (setq txt nil)
5725 (setq habitp (if did-habit-check-p habitp
5726 (and (functionp 'org-is-habit-p)
5727 (org-is-habit-p))))
5728 (setq category (org-get-category)
5729 category-pos (get-text-property (point) 'org-category-position))
5730 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5731 (setq txt org-agenda-no-heading-message)
5732 (goto-char (match-end 0))
5733 (setq pos1 (match-beginning 0))
5734 (if habitp
5735 (if (or (not org-habit-show-habits)
5736 (and (not todayp)
5737 (boundp 'org-habit-show-habits-only-for-today)
5738 org-habit-show-habits-only-for-today))
5739 (throw :skip nil))
5740 (if (and
5741 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5742 (and org-agenda-skip-scheduled-if-deadline-is-shown
5743 pastschedp))
5744 (setq mm (assoc pos1 deadline-position-alist)))
5745 (throw :skip nil)))
5746 (setq tags (org-get-tags-at))
5747 (setq head (buffer-substring-no-properties
5748 (point)
5749 (progn (skip-chars-forward "^\r\n") (point))))
5750 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5751 (setq timestr
5752 (concat (substring s (match-beginning 1)) " "))
5753 (setq timestr 'time))
5754 (setq txt (org-agenda-format-item
5755 (if (= diff 0)
5756 (car org-agenda-scheduled-leaders)
5757 (format (nth 1 org-agenda-scheduled-leaders)
5758 (- 1 diff)))
5759 head category tags
5760 (if (not (= diff 0)) nil timestr)
5761 nil habitp))))
5762 (when txt
5763 (setq face
5764 (cond
5765 ((and (not habitp) pastschedp)
5766 'org-scheduled-previously)
5767 (todayp 'org-scheduled-today)
5768 (t 'org-scheduled))
5769 habitp (and habitp (org-habit-parse-todo)))
5770 (org-add-props txt props
5771 'undone-face face
5772 'face (if donep 'org-agenda-done face)
5773 'org-marker (org-agenda-new-marker pos)
5774 'org-hd-marker (org-agenda-new-marker pos1)
5775 'type (if pastschedp "past-scheduled" "scheduled")
5776 'date (if pastschedp d2 date)
5777 'warntime warntime
5778 'priority (if habitp
5779 (org-habit-get-priority habitp)
5780 (+ 94 (- 5 diff) (org-get-priority txt)))
5781 'org-category category
5782 'category-position category-pos
5783 'org-habit-p habitp
5784 'todo-state todo-state)
5785 (push txt ee))))))
5786 (nreverse ee)))
5788 (defun org-agenda-get-blocks ()
5789 "Return the date-range information for agenda display."
5790 (let* ((props (list 'face nil
5791 'org-not-done-regexp org-not-done-regexp
5792 'org-todo-regexp org-todo-regexp
5793 'org-complex-heading-regexp org-complex-heading-regexp
5794 'mouse-face 'highlight
5795 'help-echo
5796 (format "mouse-2 or RET jump to org file %s"
5797 (abbreviate-file-name buffer-file-name))))
5798 (regexp org-tr-regexp)
5799 (d0 (calendar-absolute-from-gregorian date))
5800 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
5801 todo-state tags pos head donep)
5802 (goto-char (point-min))
5803 (while (re-search-forward regexp nil t)
5804 (catch :skip
5805 (org-agenda-skip)
5806 (setq pos (point))
5807 (let ((start-time (match-string 1))
5808 (end-time (match-string 2)))
5809 (setq s1 (match-string 1)
5810 s2 (match-string 2)
5811 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5812 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5813 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5814 ;; Only allow days between the limits, because the normal
5815 ;; date stamps will catch the limits.
5816 (save-excursion
5817 (setq todo-state (org-get-todo-state))
5818 (setq donep (member todo-state org-done-keywords))
5819 (if (and donep org-agenda-skip-timestamp-if-done)
5820 (throw :skip t))
5821 (setq marker (org-agenda-new-marker (point)))
5822 (setq category (org-get-category)
5823 category-pos (get-text-property (point) 'org-category-position))
5824 (if (not (re-search-backward org-outline-regexp-bol nil t))
5825 (setq txt org-agenda-no-heading-message)
5826 (goto-char (match-beginning 0))
5827 (setq hdmarker (org-agenda-new-marker (point)))
5828 (setq tags (org-get-tags-at))
5829 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5830 (setq head (match-string 1))
5831 (let ((remove-re
5832 (if org-agenda-remove-timeranges-from-blocks
5833 (concat
5834 "<" (regexp-quote s1) ".*?>"
5835 "--"
5836 "<" (regexp-quote s2) ".*?>")
5837 nil)))
5838 (setq txt (org-agenda-format-item
5839 (format
5840 (nth (if (= d1 d2) 0 1)
5841 org-agenda-timerange-leaders)
5842 (1+ (- d0 d1)) (1+ (- d2 d1)))
5843 head category tags
5844 (cond ((and (= d1 d0) (= d2 d0))
5845 (concat "<" start-time ">--<" end-time ">"))
5846 ((= d1 d0)
5847 (concat "<" start-time ">"))
5848 ((= d2 d0)
5849 (concat "<" end-time ">")))
5850 remove-re t))))
5851 (org-add-props txt props
5852 'org-marker marker 'org-hd-marker hdmarker
5853 'type "block" 'date date
5854 'todo-state todo-state
5855 'priority (org-get-priority txt) 'org-category category
5856 'org-category-position category-pos)
5857 (push txt ee))))
5858 (goto-char pos)))
5859 ;; Sort the entries by expiration date.
5860 (nreverse ee)))
5862 ;;; Agenda presentation and sorting
5864 (defvar org-prefix-has-time nil
5865 "A flag, set by `org-compile-prefix-format'.
5866 The flag is set if the currently compiled format contains a `%t'.")
5867 (defvar org-prefix-has-tag nil
5868 "A flag, set by `org-compile-prefix-format'.
5869 The flag is set if the currently compiled format contains a `%T'.")
5870 (defvar org-prefix-has-effort nil
5871 "A flag, set by `org-compile-prefix-format'.
5872 The flag is set if the currently compiled format contains a `%e'.")
5873 (defvar org-prefix-category-length nil
5874 "Used by `org-compile-prefix-format' to remember the category field width.")
5875 (defvar org-prefix-category-max-length nil
5876 "Used by `org-compile-prefix-format' to remember the category field width.")
5878 (defun org-agenda-get-category-icon (category)
5879 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5880 (dolist (entry org-agenda-category-icon-alist)
5881 (when (org-string-match-p (car entry) category)
5882 (if (listp (cadr entry))
5883 (return (cadr entry))
5884 (return (apply 'create-image (cdr entry)))))))
5886 (defun org-agenda-format-item (extra txt &optional category tags dotime
5887 remove-re habitp)
5888 "Format TXT to be inserted into the agenda buffer.
5889 In particular, it adds the prefix and corresponding text properties. EXTRA
5890 must be a string and replaces the `%s' specifier in the prefix format.
5891 CATEGORY (string, symbol or nil) may be used to overrule the default
5892 category taken from local variable or file name. It will replace the `%c'
5893 specifier in the format. DOTIME, when non-nil, indicates that a
5894 time-of-day should be extracted from TXT for sorting of this entry, and for
5895 the `%t' specifier in the format. When DOTIME is a string, this string is
5896 searched for a time before TXT is. TAGS can be the tags of the headline.
5897 Any match of REMOVE-RE will be removed from TXT."
5898 ;; We keep the org-prefix-* variable values along with a compiled
5899 ;; formatter, so that multiple agendas existing at the same time, do
5900 ;; not step on each other toes.
5902 ;; It was inconvenient to make these variables buffer local in
5903 ;; Agenda buffers, because this function expects to be called with
5904 ;; the buffer where item comes from being current, and not agenda
5905 ;; buffer
5906 (let* ((bindings (car org-prefix-format-compiled))
5907 (formatter (cadr org-prefix-format-compiled)))
5908 (loop for (var value) in bindings
5909 do (set var value))
5910 (save-match-data
5911 ;; Diary entries sometimes have extra whitespace at the beginning
5912 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5914 ;; Fix the tags part in txt
5915 (setq txt (org-agenda-fix-displayed-tags
5916 txt tags
5917 org-agenda-show-inherited-tags
5918 org-agenda-hide-tags-regexp))
5919 (let* ((category (or category
5920 (if (stringp org-category)
5921 org-category
5922 (and org-category (symbol-name org-category)))
5923 (if buffer-file-name
5924 (file-name-sans-extension
5925 (file-name-nondirectory buffer-file-name))
5926 "")))
5927 (category-icon (org-agenda-get-category-icon category))
5928 (category-icon (if category-icon
5929 (propertize " " 'display category-icon)
5930 ""))
5931 ;; time, tag, effort are needed for the eval of the prefix format
5932 (tag (if tags (nth (1- (length tags)) tags) ""))
5933 time effort neffort
5934 (ts (if dotime (concat
5935 (if (stringp dotime) dotime "")
5936 (and org-agenda-search-headline-for-time txt))))
5937 (time-of-day (and dotime (org-get-time-of-day ts)))
5938 stamp plain s0 s1 s2 rtn srp l
5939 duration thecategory)
5940 (and (derived-mode-p 'org-mode) buffer-file-name
5941 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5942 (when (and dotime time-of-day)
5943 ;; Extract starting and ending time and move them to prefix
5944 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5945 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5946 (setq s0 (match-string 0 ts)
5947 srp (and stamp (match-end 3))
5948 s1 (match-string (if plain 1 2) ts)
5949 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5951 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5952 ;; them, we might want to remove them there to avoid duplication.
5953 ;; The user can turn this off with a variable.
5954 (if (and org-prefix-has-time
5955 org-agenda-remove-times-when-in-prefix (or stamp plain)
5956 (string-match (concat (regexp-quote s0) " *") txt)
5957 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5958 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5959 (= (match-beginning 0) 0)
5961 (setq txt (replace-match "" nil nil txt))))
5962 ;; Normalize the time(s) to 24 hour
5963 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5964 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5966 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5967 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5968 (setq s2
5969 (org-minutes-to-hh:mm-string
5970 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5972 ;; Compute the duration
5973 (when s2
5974 (setq duration (- (org-hh:mm-string-to-minutes s2)
5975 (org-hh:mm-string-to-minutes s1)))))
5977 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5978 txt)
5979 ;; Tags are in the string
5980 (if (or (eq org-agenda-remove-tags t)
5981 (and org-agenda-remove-tags
5982 org-prefix-has-tag))
5983 (setq txt (replace-match "" t t txt))
5984 (setq txt (replace-match
5985 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5986 (match-string 2 txt))
5987 t t txt))))
5988 (when (derived-mode-p 'org-mode)
5989 (setq effort
5990 (condition-case nil
5991 (org-get-effort
5992 (or (get-text-property 0 'org-hd-marker txt)
5993 (get-text-property 0 'org-marker txt)))
5994 (error nil)))
5995 (when effort
5996 (setq neffort (org-duration-string-to-minutes effort)
5997 effort (setq effort (concat "[" effort "]")))))
5998 ;; prevent erroring out with %e format when there is no effort
5999 (or effort (setq effort ""))
6001 (when remove-re
6002 (while (string-match remove-re txt)
6003 (setq txt (replace-match "" t t txt))))
6005 ;; Set org-heading property on `txt' to mark the start of the
6006 ;; heading.
6007 (add-text-properties 0 (length txt) '(org-heading t) txt)
6009 ;; Prepare the variables needed in the eval of the compiled format
6010 (setq time (cond (s2 (concat
6011 (org-agenda-time-of-day-to-ampm-maybe s1)
6012 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6013 (if org-agenda-timegrid-use-ampm " ")))
6014 (s1 (concat
6015 (org-agenda-time-of-day-to-ampm-maybe s1)
6016 (if org-agenda-timegrid-use-ampm
6017 "........ "
6018 "......")))
6019 (t ""))
6020 extra (or (and (not habitp) extra) "")
6021 category (if (symbolp category) (symbol-name category) category)
6022 thecategory (copy-sequence category))
6023 (if (string-match org-bracket-link-regexp category)
6024 (progn
6025 (setq l (if (match-end 3)
6026 (- (match-end 3) (match-beginning 3))
6027 (- (match-end 1) (match-beginning 1))))
6028 (when (< l (or org-prefix-category-length 0))
6029 (setq category (copy-sequence category))
6030 (org-add-props category nil
6031 'extra-space (make-string
6032 (- org-prefix-category-length l 1) ?\ ))))
6033 (if (and org-prefix-category-max-length
6034 (>= (length category) org-prefix-category-max-length))
6035 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6036 ;; Evaluate the compiled format
6037 (setq rtn (concat (eval formatter) txt))
6039 ;; And finally add the text properties
6040 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6041 (org-add-props rtn nil
6042 'org-category (if thecategory (downcase thecategory) category)
6043 'tags (mapcar 'org-downcase-keep-props tags)
6044 'org-highest-priority org-highest-priority
6045 'org-lowest-priority org-lowest-priority
6046 'time-of-day time-of-day
6047 'duration duration
6048 'effort effort
6049 'effort-minutes neffort
6050 'txt txt
6051 'time time
6052 'extra extra
6053 'format org-prefix-format-compiled
6054 'dotime dotime)))))
6056 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6057 "Remove tags string from TXT, and add a modified list of tags.
6058 The modified list may contain inherited tags, and tags matched by
6059 `org-agenda-hide-tags-regexp' will be removed."
6060 (when (or add-inherited hide-re)
6061 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6062 (setq txt (substring txt 0 (match-beginning 0))))
6063 (setq tags
6064 (delq nil
6065 (mapcar (lambda (tg)
6066 (if (or (and hide-re (string-match hide-re tg))
6067 (and (not add-inherited)
6068 (get-text-property 0 'inherited tg)))
6070 tg))
6071 tags)))
6072 (when tags
6073 (let ((have-i (get-text-property 0 'inherited (car tags)))
6075 (setq txt (concat txt " :"
6076 (mapconcat
6077 (lambda (x)
6078 (setq i (get-text-property 0 'inherited x))
6079 (if (and have-i (not i))
6080 (progn
6081 (setq have-i nil)
6082 (concat ":" x))
6084 tags ":")
6085 (if have-i "::" ":"))))))
6086 txt)
6088 (defun org-downcase-keep-props (s)
6089 (let ((props (text-properties-at 0 s)))
6090 (setq s (downcase s))
6091 (add-text-properties 0 (length s) props s)
6094 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6095 (defvar org-agenda-sorting-strategy-selected nil)
6097 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6098 (catch 'exit
6099 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6100 ((and todayp (member 'today (car org-agenda-time-grid))))
6101 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6102 ((member 'weekly (car org-agenda-time-grid)))
6103 (t (throw 'exit list)))
6104 (let* ((have (delq nil (mapcar
6105 (lambda (x) (get-text-property 1 'time-of-day x))
6106 list)))
6107 (string (nth 1 org-agenda-time-grid))
6108 (gridtimes (nth 2 org-agenda-time-grid))
6109 (req (car org-agenda-time-grid))
6110 (remove (member 'remove-match req))
6111 new time)
6112 (if (and (member 'require-timed req) (not have))
6113 ;; don't show empty grid
6114 (throw 'exit list))
6115 (while (setq time (pop gridtimes))
6116 (unless (and remove (member time have))
6117 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6118 (push (org-agenda-format-item
6119 nil string "" nil
6120 (concat (substring time 0 -2) ":" (substring time -2)))
6121 new)
6122 (put-text-property
6123 2 (length (car new)) 'face 'org-time-grid (car new))))
6124 (when (and todayp org-agenda-show-current-time-in-grid)
6125 (push (org-agenda-format-item
6127 org-agenda-current-time-string
6128 "" nil
6129 (format-time-string "%H:%M "))
6130 new)
6131 (put-text-property
6132 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6134 (if (member 'time-up org-agenda-sorting-strategy-selected)
6135 (append new list)
6136 (append list new)))))
6138 (defun org-compile-prefix-format (key)
6139 "Compile the prefix format into a Lisp form that can be evaluated.
6140 The resulting form and associated variable bindings is returned
6141 and stored in the variable `org-prefix-format-compiled'."
6142 (setq org-prefix-has-time nil org-prefix-has-tag nil
6143 org-prefix-category-length nil
6144 org-prefix-has-effort nil)
6145 (let ((s (cond
6146 ((stringp org-agenda-prefix-format)
6147 org-agenda-prefix-format)
6148 ((assq key org-agenda-prefix-format)
6149 (cdr (assq key org-agenda-prefix-format)))
6150 (t " %-12:c%?-12t% s")))
6151 (start 0)
6152 varform vars var e c f opt)
6153 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6154 s start)
6155 (setq var (or (cdr (assoc (match-string 4 s)
6156 '(("c" . category) ("t" . time) ("s" . extra)
6157 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6158 'eval)
6159 c (or (match-string 3 s) "")
6160 opt (match-beginning 1)
6161 start (1+ (match-beginning 0)))
6162 (if (equal var 'time) (setq org-prefix-has-time t))
6163 (if (equal var 'tag) (setq org-prefix-has-tag t))
6164 (if (equal var 'effort) (setq org-prefix-has-effort t))
6165 (setq f (concat "%" (match-string 2 s) "s"))
6166 (when (equal var 'category)
6167 (setq org-prefix-category-length
6168 (floor (abs (string-to-number (match-string 2 s)))))
6169 (setq org-prefix-category-max-length
6170 (let ((x (match-string 2 s)))
6171 (save-match-data
6172 (if (string-match "\\.[0-9]+" x)
6173 (string-to-number (substring (match-string 0 x) 1)))))))
6174 (if (eq var 'eval)
6175 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6176 (if opt
6177 (setq varform
6178 `(if (equal "" ,var)
6180 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6181 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6182 (setq s (replace-match "%s" t nil s))
6183 (push varform vars))
6184 (setq vars (nreverse vars))
6185 (with-current-buffer (or org-agenda-buffer (current-buffer))
6186 (setq org-prefix-format-compiled
6187 (list
6188 `((org-prefix-has-time ,org-prefix-has-time)
6189 (org-prefix-has-tag ,org-prefix-has-tag)
6190 (org-prefix-category-length ,org-prefix-category-length)
6191 (org-prefix-has-effort ,org-prefix-has-effort))
6192 `(format ,s ,@vars))))))
6194 (defun org-set-sorting-strategy (key)
6195 (if (symbolp (car org-agenda-sorting-strategy))
6196 ;; the old format
6197 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6198 (setq org-agenda-sorting-strategy-selected
6199 (or (cdr (assq key org-agenda-sorting-strategy))
6200 (cdr (assq 'agenda org-agenda-sorting-strategy))
6201 '(time-up category-keep priority-down)))))
6203 (defun org-get-time-of-day (s &optional string mod24)
6204 "Check string S for a time of day.
6205 If found, return it as a military time number between 0 and 2400.
6206 If not found, return nil.
6207 The optional STRING argument forces conversion into a 5 character wide string
6208 HH:MM."
6209 (save-match-data
6210 (when
6211 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6212 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6213 (let* ((h (string-to-number (match-string 1 s)))
6214 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6215 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6216 (am-p (equal ampm "am"))
6217 (h1 (cond ((not ampm) h)
6218 ((= h 12) (if am-p 0 12))
6219 (t (+ h (if am-p 0 12)))))
6220 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6221 (mod h1 24) h1))
6222 (t0 (+ (* 100 h2) m))
6223 (t1 (concat (if (>= h1 24) "+" " ")
6224 (if (and org-agenda-time-leading-zero
6225 (< t0 1000)) "0" "")
6226 (if (< t0 100) "0" "")
6227 (if (< t0 10) "0" "")
6228 (int-to-string t0))))
6229 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6231 (defvar org-agenda-before-sorting-filter-function nil
6232 "Function to be applied to agenda items prior to sorting.
6233 Prior to sorting also means just before they are inserted into the agenda.
6235 To aid sorting, you may revisit the original entries and add more text
6236 properties which will later be used by the sorting functions.
6238 The function should take a string argument, an agenda line.
6239 It has access to the text properties in that line, which contain among
6240 other things, the property `org-hd-marker' that points to the entry
6241 where the line comes from. Note that not all lines going into the agenda
6242 have this property, only most.
6244 The function should return the modified string. It is probably best
6245 to ONLY change text properties.
6247 You can also use this function as a filter, by returning nil for lines
6248 you don't want to have in the agenda at all. For this application, you
6249 could bind the variable in the options section of a custom command.")
6251 (defun org-agenda-finalize-entries (list &optional nosort)
6252 "Sort and concatenate the agenda items."
6253 (setq list (mapcar 'org-agenda-highlight-todo list))
6254 (if nosort
6255 list
6256 (when org-agenda-before-sorting-filter-function
6257 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6258 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6260 (defun org-agenda-highlight-todo (x)
6261 (let ((org-done-keywords org-done-keywords-for-agenda)
6262 (case-fold-search nil)
6264 (if (eq x 'line)
6265 (save-excursion
6266 (beginning-of-line 1)
6267 (setq re (org-get-at-bol 'org-todo-regexp))
6268 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6269 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6270 (add-text-properties (match-beginning 0) (match-end 1)
6271 (list 'face (org-get-todo-face 1)))
6272 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6273 (delete-region (match-beginning 1) (1- (match-end 0)))
6274 (goto-char (match-beginning 1))
6275 (insert (format org-agenda-todo-keyword-format s)))))
6276 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6277 (setq re (get-text-property 0 'org-todo-regexp x))
6278 (when (and re
6279 ;; Test `pl' because if there's no heading content,
6280 ;; there's no point matching to highlight. Note
6281 ;; that if we didn't test `pl' first, and there
6282 ;; happened to be no keyword from `org-todo-regexp'
6283 ;; on this heading line, then the `equal' comparison
6284 ;; afterwards would spuriously succeed in the case
6285 ;; where `pl' is nil -- causing an args-out-of-range
6286 ;; error when we try to add text properties to text
6287 ;; that isn't there.
6289 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6290 x pl) pl))
6291 (add-text-properties
6292 (or (match-end 1) (match-end 0)) (match-end 0)
6293 (list 'face (org-get-todo-face (match-string 2 x)))
6295 (when (match-end 1)
6296 (setq x (concat (substring x 0 (match-end 1))
6297 (format org-agenda-todo-keyword-format
6298 (match-string 2 x))
6299 (org-add-props " " (text-properties-at 0 x))
6300 (substring x (match-end 3)))))))
6301 x)))
6303 (defsubst org-cmp-priority (a b)
6304 "Compare the priorities of string A and B."
6305 (let ((pa (or (get-text-property 1 'priority a) 0))
6306 (pb (or (get-text-property 1 'priority b) 0)))
6307 (cond ((> pa pb) +1)
6308 ((< pa pb) -1))))
6310 (defsubst org-cmp-effort (a b)
6311 "Compare the effort values of string A and B."
6312 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6313 (ea (or (get-text-property 1 'effort-minutes a) def))
6314 (eb (or (get-text-property 1 'effort-minutes b) def)))
6315 (cond ((> ea eb) +1)
6316 ((< ea eb) -1))))
6318 (defsubst org-cmp-category (a b)
6319 "Compare the string values of categories of strings A and B."
6320 (let ((ca (or (get-text-property 1 'org-category a) ""))
6321 (cb (or (get-text-property 1 'org-category b) "")))
6322 (cond ((string-lessp ca cb) -1)
6323 ((string-lessp cb ca) +1))))
6325 (defsubst org-cmp-todo-state (a b)
6326 "Compare the todo states of strings A and B."
6327 (let* ((ma (or (get-text-property 1 'org-marker a)
6328 (get-text-property 1 'org-hd-marker a)))
6329 (mb (or (get-text-property 1 'org-marker b)
6330 (get-text-property 1 'org-hd-marker b)))
6331 (fa (and ma (marker-buffer ma)))
6332 (fb (and mb (marker-buffer mb)))
6333 (todo-kwds
6334 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6335 (and fb (with-current-buffer fb org-todo-keywords-1))))
6336 (ta (or (get-text-property 1 'todo-state a) ""))
6337 (tb (or (get-text-property 1 'todo-state b) ""))
6338 (la (- (length (member ta todo-kwds))))
6339 (lb (- (length (member tb todo-kwds))))
6340 (donepa (member ta org-done-keywords-for-agenda))
6341 (donepb (member tb org-done-keywords-for-agenda)))
6342 (cond ((and donepa (not donepb)) -1)
6343 ((and (not donepa) donepb) +1)
6344 ((< la lb) -1)
6345 ((< lb la) +1))))
6347 (defsubst org-cmp-alpha (a b)
6348 "Compare the headlines, alphabetically."
6349 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6350 (plb (text-property-any 0 (length b) 'org-heading t b))
6351 (ta (and pla (substring a pla)))
6352 (tb (and plb (substring b plb))))
6353 (when pla
6354 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6355 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6356 (setq ta (substring ta (match-end 0))))
6357 (setq ta (downcase ta)))
6358 (when plb
6359 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6360 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6361 (setq tb (substring tb (match-end 0))))
6362 (setq tb (downcase tb)))
6363 (cond ((not ta) +1)
6364 ((not tb) -1)
6365 ((string-lessp ta tb) -1)
6366 ((string-lessp tb ta) +1))))
6368 (defsubst org-cmp-tag (a b)
6369 "Compare the string values of the first tags of A and B."
6370 (let ((ta (car (last (get-text-property 1 'tags a))))
6371 (tb (car (last (get-text-property 1 'tags b)))))
6372 (cond ((not ta) +1)
6373 ((not tb) -1)
6374 ((string-lessp ta tb) -1)
6375 ((string-lessp tb ta) +1))))
6377 (defsubst org-cmp-time (a b)
6378 "Compare the time-of-day values of strings A and B."
6379 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6380 (ta (or (get-text-property 1 'time-of-day a) def))
6381 (tb (or (get-text-property 1 'time-of-day b) def)))
6382 (cond ((< ta tb) -1)
6383 ((< tb ta) +1))))
6385 (defsubst org-cmp-habit-p (a b)
6386 "Compare the todo states of strings A and B."
6387 (let ((ha (get-text-property 1 'org-habit-p a))
6388 (hb (get-text-property 1 'org-habit-p b)))
6389 (cond ((and ha (not hb)) -1)
6390 ((and (not ha) hb) +1))))
6392 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6394 (defun org-entries-lessp (a b)
6395 "Predicate for sorting agenda entries."
6396 ;; The following variables will be used when the form is evaluated.
6397 ;; So even though the compiler complains, keep them.
6398 (let* ((ss org-agenda-sorting-strategy-selected)
6399 (time-up (and (org-em 'time-up 'time-down ss)
6400 (org-cmp-time a b)))
6401 (time-down (if time-up (- time-up) nil))
6402 (priority-up (and (org-em 'priority-up 'priority-down ss)
6403 (org-cmp-priority a b)))
6404 (priority-down (if priority-up (- priority-up) nil))
6405 (effort-up (and (org-em 'effort-up 'effort-down ss)
6406 (org-cmp-effort a b)))
6407 (effort-down (if effort-up (- effort-up) nil))
6408 (category-up (and (or (org-em 'category-up 'category-down ss)
6409 (memq 'category-keep ss))
6410 (org-cmp-category a b)))
6411 (category-down (if category-up (- category-up) nil))
6412 (category-keep (if category-up +1 nil))
6413 (tag-up (and (org-em 'tag-up 'tag-down ss)
6414 (org-cmp-tag a b)))
6415 (tag-down (if tag-up (- tag-up) nil))
6416 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6417 (org-cmp-todo-state a b)))
6418 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6419 (habit-up (and (org-em 'habit-up 'habit-down ss)
6420 (org-cmp-habit-p a b)))
6421 (habit-down (if habit-up (- habit-up) nil))
6422 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6423 (org-cmp-alpha a b)))
6424 (alpha-down (if alpha-up (- alpha-up) nil))
6425 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6426 user-defined-up user-defined-down)
6427 (if (and need-user-cmp org-agenda-cmp-user-defined
6428 (functionp org-agenda-cmp-user-defined))
6429 (setq user-defined-up
6430 (funcall org-agenda-cmp-user-defined a b)
6431 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6432 (cdr (assoc
6433 (eval (cons 'or org-agenda-sorting-strategy-selected))
6434 '((-1 . t) (1 . nil) (nil . nil))))))
6436 ;;; Agenda restriction lock
6438 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6439 "Overlay to mark the headline to which agenda commands are restricted.")
6440 (overlay-put org-agenda-restriction-lock-overlay
6441 'face 'org-agenda-restriction-lock)
6442 (overlay-put org-agenda-restriction-lock-overlay
6443 'help-echo "Agendas are currently limited to this subtree.")
6444 (org-detach-overlay org-agenda-restriction-lock-overlay)
6446 (defun org-agenda-set-restriction-lock (&optional type)
6447 "Set restriction lock for agenda, to current subtree or file.
6448 Restriction will be the file if TYPE is `file', or if type is the
6449 universal prefix '(4), or if the cursor is before the first headline
6450 in the file. Otherwise, restriction will be to the current subtree."
6451 (interactive "P")
6452 (and (equal type '(4)) (setq type 'file))
6453 (setq type (cond
6454 (type type)
6455 ((org-at-heading-p) 'subtree)
6456 ((condition-case nil (org-back-to-heading t) (error nil))
6457 'subtree)
6458 (t 'file)))
6459 (if (eq type 'subtree)
6460 (progn
6461 (setq org-agenda-restrict t)
6462 (setq org-agenda-overriding-restriction 'subtree)
6463 (put 'org-agenda-files 'org-restrict
6464 (list (buffer-file-name (buffer-base-buffer))))
6465 (org-back-to-heading t)
6466 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6467 (move-marker org-agenda-restrict-begin (point))
6468 (move-marker org-agenda-restrict-end
6469 (save-excursion (org-end-of-subtree t)))
6470 (message "Locking agenda restriction to subtree"))
6471 (put 'org-agenda-files 'org-restrict
6472 (list (buffer-file-name (buffer-base-buffer))))
6473 (setq org-agenda-restrict nil)
6474 (setq org-agenda-overriding-restriction 'file)
6475 (move-marker org-agenda-restrict-begin nil)
6476 (move-marker org-agenda-restrict-end nil)
6477 (message "Locking agenda restriction to file"))
6478 (setq current-prefix-arg nil)
6479 (org-agenda-maybe-redo))
6481 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6482 "Remove the agenda restriction lock."
6483 (interactive "P")
6484 (org-detach-overlay org-agenda-restriction-lock-overlay)
6485 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6486 (setq org-agenda-overriding-restriction nil)
6487 (setq org-agenda-restrict nil)
6488 (put 'org-agenda-files 'org-restrict nil)
6489 (move-marker org-agenda-restrict-begin nil)
6490 (move-marker org-agenda-restrict-end nil)
6491 (setq current-prefix-arg nil)
6492 (message "Agenda restriction lock removed")
6493 (or noupdate (org-agenda-maybe-redo)))
6495 (defun org-agenda-maybe-redo ()
6496 "If there is any window showing the agenda view, update it."
6497 (let ((w (get-buffer-window org-agenda-buffer-name t))
6498 (w0 (selected-window)))
6499 (when w
6500 (select-window w)
6501 (org-agenda-redo)
6502 (select-window w0)
6503 (if org-agenda-overriding-restriction
6504 (message "Agenda view shifted to new %s restriction"
6505 org-agenda-overriding-restriction)
6506 (message "Agenda restriction lock removed")))))
6508 ;;; Agenda commands
6510 (defun org-agenda-check-type (error &rest types)
6511 "Check if agenda buffer is of allowed type.
6512 If ERROR is non-nil, throw an error, otherwise just return nil."
6513 (if (not org-agenda-type)
6514 (error "No Org agenda currently displayed")
6515 (if (memq org-agenda-type types)
6517 (if error
6518 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6519 nil))))
6521 (defun org-agenda-Quit (&optional arg)
6522 "Exit agenda by removing the window or the buffer."
6523 (interactive)
6524 (if org-agenda-columns-active
6525 (org-columns-quit)
6526 (let ((buf (current-buffer)))
6527 (if (eq org-agenda-window-setup 'other-frame)
6528 (progn
6529 (org-agenda-reset-markers)
6530 (kill-buffer buf)
6531 (org-columns-remove-overlays)
6532 (setq org-agenda-archives-mode nil)
6533 (delete-frame))
6534 (and (not (eq org-agenda-window-setup 'current-window))
6535 (not (one-window-p))
6536 (delete-window))
6537 (org-agenda-reset-markers)
6538 (kill-buffer buf)
6539 (org-columns-remove-overlays)
6540 (setq org-agenda-archives-mode nil)))
6541 ;; Maybe restore the pre-agenda window configuration.
6542 (and org-agenda-restore-windows-after-quit
6543 (not (eq org-agenda-window-setup 'other-frame))
6544 org-agenda-pre-window-conf
6545 (set-window-configuration org-agenda-pre-window-conf)
6546 (setq org-agenda-pre-window-conf nil))))
6548 (defun org-agenda-quit ()
6549 "Exit agenda by killing agenda buffer or burying it when
6550 `org-agenda-sticky' is non-NIL"
6551 (interactive)
6552 (if org-agenda-columns-active
6553 (org-columns-quit)
6554 (if org-agenda-sticky
6555 (let ((buf (current-buffer)))
6556 (if (eq org-agenda-window-setup 'other-frame)
6557 (progn
6558 (delete-frame))
6559 (and (not (eq org-agenda-window-setup 'current-window))
6560 (not (one-window-p))
6561 (delete-window)))
6562 (with-current-buffer buf
6563 (bury-buffer)
6564 ;; Maybe restore the pre-agenda window configuration.
6565 (and org-agenda-restore-windows-after-quit
6566 (not (eq org-agenda-window-setup 'other-frame))
6567 org-agenda-pre-window-conf
6568 (set-window-configuration org-agenda-pre-window-conf)
6569 (setq org-agenda-pre-window-conf nil))))
6570 (org-agenda-Quit))))
6572 (defun org-agenda-exit ()
6573 "Exit agenda by removing the window or the buffer.
6574 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6575 Org-mode buffers visited directly by the user will not be touched."
6576 (interactive)
6577 (org-release-buffers org-agenda-new-buffers)
6578 (setq org-agenda-new-buffers nil)
6579 (org-agenda-Quit))
6581 (defun org-agenda-kill-all-agenda-buffers ()
6582 "Kill all buffers in `org-agena-mode'.
6583 This is used when toggling sticky agendas. You can also explicitly invoke it
6584 with `C-c a C-k'."
6585 (interactive)
6586 (let (blist)
6587 (dolist (buf (buffer-list))
6588 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6589 (push buf blist)))
6590 (mapc 'kill-buffer blist)))
6592 (defun org-agenda-execute (arg)
6593 "Execute another agenda command, keeping same window.
6594 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6595 in the agenda."
6596 (interactive "P")
6597 (let ((org-agenda-window-setup 'current-window))
6598 (org-agenda arg)))
6600 (defun org-agenda-redo (&optional all)
6601 "Rebuild possibly ALL agenda view(s) in the current buffer."
6602 (interactive "P")
6603 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6604 (cpa (unless (eq all t) current-prefix-arg))
6605 (org-agenda-doing-sticky-redo org-agenda-sticky)
6606 (org-agenda-sticky nil)
6607 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6608 org-agenda-buffer-name))
6609 (org-agenda-keep-modes t)
6610 (tag-filter org-agenda-tag-filter)
6611 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6612 (top-cat-filter org-agenda-top-category-filter)
6613 (cat-filter org-agenda-category-filter)
6614 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6615 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6616 (cols org-agenda-columns-active)
6617 (line (org-current-line))
6618 (window-line (- line (org-current-line (window-start))))
6619 (lprops (get 'org-agenda-redo-command 'org-lprops))
6620 (redo-cmd (get-text-property p 'org-redo-cmd))
6621 (last-args (get-text-property p 'org-last-args))
6622 (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
6623 (org-agenda-overriding-cmd-arguments
6624 (unless (eq all t)
6625 (cond ((listp last-args)
6626 (cons (or cpa (car last-args)) (cdr last-args)))
6627 ((stringp last-args)
6628 last-args))))
6629 (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
6630 (put 'org-agenda-tag-filter :preset-filter nil)
6631 (put 'org-agenda-category-filter :preset-filter nil)
6632 (and cols (org-columns-quit))
6633 (message "Rebuilding agenda buffer...")
6634 (if serie-redo-cmd
6635 (eval serie-redo-cmd)
6636 (org-let lprops '(eval redo-cmd)))
6637 (setq org-agenda-undo-list nil
6638 org-agenda-pending-undo-list nil)
6639 (message "Rebuilding agenda buffer...done")
6640 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6641 (put 'org-agenda-category-filter :preset-filter cat-preset)
6642 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6643 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6644 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6645 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6646 (org-goto-line line)
6647 (recenter window-line)))
6649 (defvar org-global-tags-completion-table nil)
6650 (defvar org-agenda-filter-form nil)
6651 (defvar org-agenda-filtered-by-category nil)
6653 (defun org-agenda-filter-by-category (strip)
6654 "Keep only those lines in the agenda buffer that have a specific category.
6655 The category is that of the current line."
6656 (interactive "P")
6657 (if (and org-agenda-filtered-by-category
6658 org-agenda-category-filter)
6659 (org-agenda-filter-show-all-cat)
6660 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6661 (if cat (org-agenda-filter-apply
6662 (list (concat (if strip "-" "+") cat)) 'category)
6663 (error "No category at point")))))
6665 (defun org-find-top-category (&optional pos)
6666 (save-excursion
6667 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6668 (if pos (goto-char pos))
6669 ;; Skip up to the topmost parent
6670 (while (ignore-errors (outline-up-heading 1) t))
6671 (ignore-errors
6672 (nth 4 (org-heading-components))))))
6674 (defvar org-agenda-filtered-by-top-category nil)
6676 (defun org-agenda-filter-by-top-category (strip)
6677 "Keep only those lines in the agenda buffer that have a specific category.
6678 The category is that of the current line."
6679 (interactive "P")
6680 (if org-agenda-filtered-by-top-category
6681 (progn
6682 (setq org-agenda-filtered-by-top-category nil
6683 org-agenda-top-category-filter nil)
6684 (org-agenda-filter-show-all-cat))
6685 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6686 (if cat (org-agenda-filter-top-category-apply cat strip)
6687 (error "No top-level category at point")))))
6689 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6690 "Keep only those lines in the agenda buffer that have a specific tag.
6691 The tag is selected with its fast selection letter, as configured.
6692 With prefix argument STRIP, remove all lines that do have the tag.
6693 A lisp caller can specify CHAR. NARROW means that the new tag should be
6694 used to narrow the search - the interactive user can also press `-' or `+'
6695 to switch to narrowing."
6696 (interactive "P")
6697 (let* ((alist org-tag-alist-for-agenda)
6698 (tag-chars (mapconcat
6699 (lambda (x) (if (and (not (symbolp (car x)))
6700 (cdr x))
6701 (char-to-string (cdr x))
6702 ""))
6703 alist ""))
6704 (efforts (org-split-string
6705 (or (cdr (assoc (concat org-effort-property "_ALL")
6706 org-global-properties))
6707 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6708 "")))
6709 (effort-op org-agenda-filter-effort-default-operator)
6710 (effort-prompt "")
6711 (inhibit-read-only t)
6712 (current org-agenda-tag-filter)
6713 maybe-refresh a n tag)
6714 (unless char
6715 (message
6716 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6717 (if narrow "Narrow" "Filter") tag-chars
6718 (if org-agenda-auto-exclude-function "[RET], " ""))
6719 (setq char (read-char-exclusive)))
6720 (when (member char '(?+ ?-))
6721 ;; Narrowing down
6722 (cond ((equal char ?-) (setq strip t narrow t))
6723 ((equal char ?+) (setq strip nil narrow t)))
6724 (message
6725 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6726 (setq char (read-char-exclusive)))
6727 (when (member char '(?< ?> ?= ??))
6728 ;; An effort operator
6729 (setq effort-op (char-to-string char))
6730 (setq alist nil) ; to make sure it will be interpreted as effort.
6731 (unless (equal char ??)
6732 (loop for i from 0 to 9 do
6733 (setq effort-prompt
6734 (concat
6735 effort-prompt " ["
6736 (if (= i 9) "0" (int-to-string (1+ i)))
6737 "]" (nth i efforts))))
6738 (message "Effort%s: %s " effort-op effort-prompt)
6739 (setq char (read-char-exclusive))
6740 (when (or (< char ?0) (> char ?9))
6741 (error "Need 1-9,0 to select effort"))))
6742 (when (equal char ?\t)
6743 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6744 (org-set-local 'org-global-tags-completion-table
6745 (org-global-tags-completion-table)))
6746 (let ((completion-ignore-case t))
6747 (setq tag (org-icompleting-read
6748 "Tag: " org-global-tags-completion-table))))
6749 (cond
6750 ((equal char ?\r)
6751 (org-agenda-filter-show-all-tag)
6752 (when org-agenda-auto-exclude-function
6753 (setq org-agenda-tag-filter '())
6754 (dolist (tag (org-agenda-get-represented-tags))
6755 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6756 (if modifier
6757 (push modifier org-agenda-tag-filter))))
6758 (if (not (null org-agenda-tag-filter))
6759 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6760 (setq maybe-refresh t))
6761 ((equal char ?/)
6762 (org-agenda-filter-show-all-tag)
6763 (when (get 'org-agenda-tag-filter :preset-filter)
6764 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6765 (setq maybe-refresh t))
6766 ((equal char ?. )
6767 (setq org-agenda-tag-filter
6768 (mapcar (lambda(tag) (concat "+" tag))
6769 (org-get-at-bol 'tags)))
6770 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6771 (setq maybe-refresh t))
6772 ((or (equal char ?\ )
6773 (setq a (rassoc char alist))
6774 (and (>= char ?0) (<= char ?9)
6775 (setq n (if (= char ?0) 9 (- char ?0 1))
6776 tag (concat effort-op (nth n efforts))
6777 a (cons tag nil)))
6778 (and (= char ??)
6779 (setq tag "?eff")
6780 a (cons tag nil))
6781 (and tag (setq a (cons tag nil))))
6782 (org-agenda-filter-show-all-tag)
6783 (setq tag (car a))
6784 (setq org-agenda-tag-filter
6785 (cons (concat (if strip "-" "+") tag)
6786 (if narrow current nil)))
6787 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6788 (setq maybe-refresh t))
6789 (t (error "Invalid tag selection character %c" char)))
6790 (when (and maybe-refresh
6791 (eq org-agenda-clockreport-mode 'with-filter))
6792 (org-agenda-redo))))
6794 (defun org-agenda-get-represented-tags ()
6795 "Get a list of all tags currently represented in the agenda."
6796 (let (p tags)
6797 (save-excursion
6798 (goto-char (point-min))
6799 (while (setq p (next-single-property-change (point) 'tags))
6800 (goto-char p)
6801 (mapc (lambda (x) (add-to-list 'tags x))
6802 (get-text-property (point) 'tags))))
6803 tags))
6805 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6806 "Refine the current filter. See `org-agenda-filter-by-tag'."
6807 (interactive "P")
6808 (org-agenda-filter-by-tag strip char 'refine))
6810 (defun org-agenda-filter-make-matcher ()
6811 "Create the form that tests a line for agenda filter."
6812 (let (f f1)
6813 ;; first compute the tag-filter matcher
6814 (dolist (x (delete-dups
6815 (append (get 'org-agenda-tag-filter
6816 :preset-filter) org-agenda-tag-filter)))
6817 (if (member x '("-" "+"))
6818 (setq f1 (if (equal x "-") 'tags '(not tags)))
6819 (if (string-match "[<=>?]" x)
6820 (setq f1 (org-agenda-filter-effort-form x))
6821 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6822 (if (equal (string-to-char x) ?-)
6823 (setq f1 (list 'not f1))))
6824 (push f1 f))
6825 ;; then compute the category-filter matcher
6826 (dolist (x (delete-dups
6827 (append (get 'org-agenda-category-filter
6828 :preset-filter) org-agenda-category-filter)))
6829 (if (equal "-" (substring x 0 1))
6830 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6831 (setq f1 (list 'equal (substring x 1) 'cat)))
6832 (push f1 f))
6833 (cons 'and (nreverse f))))
6835 (defun org-agenda-filter-effort-form (e)
6836 "Return the form to compare the effort of the current line with what E says.
6837 E looks like \"+<2:25\"."
6838 (let (op)
6839 (setq e (substring e 1))
6840 (setq op (string-to-char e) e (substring e 1))
6841 (setq op (cond ((equal op ?<) '<=)
6842 ((equal op ?>) '>=)
6843 ((equal op ??) op)
6844 (t '=)))
6845 (list 'org-agenda-compare-effort (list 'quote op)
6846 (org-duration-string-to-minutes e))))
6848 (defun org-agenda-compare-effort (op value)
6849 "Compare the effort of the current line with VALUE, using OP.
6850 If the line does not have an effort defined, return nil."
6851 (let ((eff (org-get-at-bol 'effort-minutes)))
6852 (if (equal op ??)
6853 (not eff)
6854 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6855 value))))
6857 (defun org-agenda-filter-apply (filter type)
6858 "Set FILTER as the new agenda filter and apply it."
6859 (let (tags cat)
6860 (if (eq type 'tag)
6861 (setq org-agenda-tag-filter filter)
6862 (setq org-agenda-category-filter filter))
6863 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6864 (if (and (eq type 'category)
6865 (not (equal (substring (car filter) 0 1) "-")))
6866 ;; Only set `org-agenda-filtered-by-category' to t
6867 ;; when a unique category is used as the filter
6868 (setq org-agenda-filtered-by-category t))
6869 (org-agenda-set-mode-name)
6870 (save-excursion
6871 (goto-char (point-min))
6872 (while (not (eobp))
6873 (if (org-get-at-bol 'org-marker)
6874 (progn
6875 (setq tags (org-get-at-bol 'tags) ; used in eval
6876 cat (get-text-property (point) 'org-category))
6877 (if (not (eval org-agenda-filter-form))
6878 (org-agenda-filter-hide-line type))
6879 (beginning-of-line 2))
6880 (beginning-of-line 2))))
6881 (if (get-char-property (point) 'invisible)
6882 (ignore-errors (org-agenda-previous-line)))))
6884 (defun org-agenda-filter-top-category-apply (category &optional negative)
6885 "Set FILTER as the new agenda filter and apply it."
6886 (org-agenda-set-mode-name)
6887 (save-excursion
6888 (goto-char (point-min))
6889 (while (not (eobp))
6890 (let* ((pos (org-get-at-bol 'org-hd-marker))
6891 (topcat (and pos (org-find-top-category pos))))
6892 (if (and topcat (funcall (if negative 'identity 'not)
6893 (string= category topcat)))
6894 (org-agenda-filter-hide-line 'category)))
6895 (beginning-of-line 2)))
6896 (if (get-char-property (point) 'invisible)
6897 (org-agenda-previous-line))
6898 (setq org-agenda-top-category-filter category
6899 org-agenda-filtered-by-top-category t))
6901 (defun org-agenda-filter-hide-line (type)
6902 (let (ov)
6903 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6904 (point-at-eol)))
6905 (overlay-put ov 'invisible t)
6906 (overlay-put ov 'type type)
6907 (if (eq type 'tag)
6908 (push ov org-agenda-tag-filter-overlays)
6909 (push ov org-agenda-cat-filter-overlays))))
6911 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6912 (setq pos (or pos (point)))
6913 (save-excursion
6914 (dolist (ov (overlays-at pos))
6915 (when (and (overlay-get ov 'invisible)
6916 (eq (overlay-get ov 'type) 'tag))
6917 (goto-char pos)
6918 (if (< (overlay-start ov) (point-at-eol))
6919 (move-overlay ov (point-at-eol)
6920 (overlay-end ov)))))))
6922 (defun org-agenda-filter-show-all-tag nil
6923 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6924 (setq org-agenda-tag-filter-overlays nil
6925 org-agenda-tag-filter nil
6926 org-agenda-filter-form nil)
6927 (org-agenda-set-mode-name))
6929 (defun org-agenda-filter-show-all-cat nil
6930 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6931 (setq org-agenda-cat-filter-overlays nil
6932 org-agenda-filtered-by-category nil
6933 org-agenda-category-filter nil
6934 org-agenda-filter-form nil)
6935 (org-agenda-set-mode-name))
6937 (defun org-agenda-manipulate-query-add ()
6938 "Manipulate the query by adding a search term with positive selection.
6939 Positive selection means the term must be matched for selection of an entry."
6940 (interactive)
6941 (org-agenda-manipulate-query ?\[))
6942 (defun org-agenda-manipulate-query-subtract ()
6943 "Manipulate the query by adding a search term with negative selection.
6944 Negative selection means term must not be matched for selection of an entry."
6945 (interactive)
6946 (org-agenda-manipulate-query ?\]))
6947 (defun org-agenda-manipulate-query-add-re ()
6948 "Manipulate the query by adding a search regexp with positive selection.
6949 Positive selection means the regexp must match for selection of an entry."
6950 (interactive)
6951 (org-agenda-manipulate-query ?\{))
6952 (defun org-agenda-manipulate-query-subtract-re ()
6953 "Manipulate the query by adding a search regexp with negative selection.
6954 Negative selection means regexp must not match for selection of an entry."
6955 (interactive)
6956 (org-agenda-manipulate-query ?\}))
6957 (defun org-agenda-manipulate-query (char)
6958 (cond
6959 ((memq org-agenda-type '(timeline agenda))
6960 (let ((org-agenda-include-inactive-timestamps t))
6961 (org-agenda-redo))
6962 (message "Display now includes inactive timestamps as well"))
6963 ((eq org-agenda-type 'search)
6964 (org-add-to-string
6965 'org-agenda-query-string
6966 (if org-agenda-last-search-view-search-was-boolean
6967 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6968 (?\{ . " +{}") (?\} . " -{}"))))
6969 " "))
6970 (setq org-agenda-redo-command
6971 (list 'org-search-view
6972 (car (get-text-property (point) 'org-last-args))
6973 org-agenda-query-string
6974 (+ (length org-agenda-query-string)
6975 (if (member char '(?\{ ?\})) 0 1))))
6976 (set-register org-agenda-query-register org-agenda-query-string)
6977 (let ((org-agenda-overriding-arguments
6978 (cdr org-agenda-redo-command)))
6979 (org-agenda-redo)))
6980 (t (error "Cannot manipulate query for %s-type agenda buffers"
6981 org-agenda-type))))
6983 (defun org-add-to-string (var string)
6984 (set var (concat (symbol-value var) string)))
6986 (defun org-agenda-goto-date (span)
6987 "Jump to DATE in agenda."
6988 (interactive "P")
6989 (let* ((org-read-date-prefer-future
6990 (eval org-agenda-jump-prefer-future))
6991 (date (org-read-date))
6992 (org-agenda-sticky-orig org-agenda-sticky)
6993 (org-agenda-buffer-tmp-name (buffer-name))
6994 (args (get-text-property (point) 'org-last-args))
6995 (0-arg (or current-prefix-arg (car args)))
6996 (2-arg (nth 2 args))
6997 (newcmd (list 'org-agenda-list 0-arg date
6998 (org-agenda-span-to-ndays 2-arg)))
6999 (newargs (cdr newcmd))
7000 (inhibit-read-only t)
7001 org-agenda-sticky)
7002 (if (not (org-agenda-check-type t 'agenda))
7003 (error "Not available in non-agenda blocks")
7004 (add-text-properties (point-min) (point-max)
7005 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7006 (org-agenda-redo)
7007 (setq org-agenda-sticky org-agenda-sticky-orig
7008 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7010 (defun org-agenda-goto-today ()
7011 "Go to today."
7012 (interactive)
7013 (org-agenda-check-type t 'timeline 'agenda)
7014 (let* ((args (get-text-property (point) 'org-last-args))
7015 (curspan (nth 2 args))
7016 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7017 (cond
7018 (tdpos (goto-char tdpos))
7019 ((eq org-agenda-type 'agenda)
7020 (let* ((sd (org-agenda-compute-starting-span
7021 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7022 (org-agenda-overriding-arguments args))
7023 (setf (nth 1 org-agenda-overriding-arguments) sd)
7024 (org-agenda-redo)
7025 (org-agenda-find-same-or-today-or-agenda)))
7026 (t (error "Cannot find today")))))
7028 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7029 (goto-char
7030 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7031 (text-property-any (point-min) (point-max) 'org-today t)
7032 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7033 (and (get-text-property (point) 'org-serie)
7034 (org-agenda-goto-block-beginning))
7035 (point-min))))
7037 (defun org-agenda-goto-block-beginning ()
7038 "Go the agenda block beginning."
7039 (interactive)
7040 (if (not (derived-mode-p 'org-agenda-mode))
7041 (error "Cannot execute this command outside of org-agenda-mode buffers")
7042 (let (dest)
7043 (save-excursion
7044 (unless (looking-at "\\'")
7045 (forward-char))
7046 (let* ((prop 'org-agenda-structural-header)
7047 (p (previous-single-property-change (point) prop))
7048 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7049 (1- (point))) prop)))
7050 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7051 (if (not dest)
7052 (error "Cannot find the beginning of the blog")
7053 (goto-char dest)
7054 (move-beginning-of-line 1)))))
7056 (defun org-agenda-later (arg)
7057 "Go forward in time by thee current span.
7058 With prefix ARG, go forward that many times the current span."
7059 (interactive "p")
7060 (org-agenda-check-type t 'agenda)
7061 (let* ((args (get-text-property (point) 'org-last-args))
7062 (span (or (nth 2 args) org-agenda-current-span))
7063 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7064 (greg (calendar-gregorian-from-absolute sd))
7065 (cnt (org-get-at-bol 'org-day-cnt))
7066 greg2)
7067 (cond
7068 ((numberp span)
7069 (setq sd (+ span sd)))
7070 ((eq span 'day)
7071 (setq sd (+ arg sd)))
7072 ((eq span 'week)
7073 (setq sd (+ (* 7 arg) sd)))
7074 ((eq span 'month)
7075 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7076 sd (calendar-absolute-from-gregorian greg2))
7077 (setcar greg2 (1+ (car greg2))))
7078 ((eq span 'year)
7079 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7080 sd (calendar-absolute-from-gregorian greg2))
7081 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7083 (setq sd (+ (* span arg) sd))))
7084 (let ((org-agenda-overriding-cmd
7085 ;; `cmd' may have been set by `org-agenda-run-series' which
7086 ;; uses `org-agenda-overriding-cmd' to decide whether
7087 ;; overriding is allowed for `cmd'
7088 (get-text-property (point) 'org-serie-cmd))
7089 (org-agenda-overriding-arguments
7090 (list (car args) sd span)))
7091 (org-agenda-redo)
7092 (org-agenda-find-same-or-today-or-agenda cnt))))
7094 (defun org-agenda-earlier (arg)
7095 "Go backward in time by the current span.
7096 With prefix ARG, go backward that many times the current span."
7097 (interactive "p")
7098 (org-agenda-later (- arg)))
7100 (defun org-agenda-view-mode-dispatch ()
7101 "Call one of the view mode commands."
7102 (interactive)
7103 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7104 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7105 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7106 (let ((a (read-char-exclusive)))
7107 (case a
7108 (?\ (call-interactively 'org-agenda-reset-view))
7109 (?d (call-interactively 'org-agenda-day-view))
7110 (?w (call-interactively 'org-agenda-week-view))
7111 (?m (call-interactively 'org-agenda-month-view))
7112 (?y (call-interactively 'org-agenda-year-view))
7113 (?l (call-interactively 'org-agenda-log-mode))
7114 (?L (org-agenda-log-mode '(4)))
7115 (?c (org-agenda-log-mode 'clockcheck))
7116 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7117 (?a (call-interactively 'org-agenda-archives-mode))
7118 (?A (org-agenda-archives-mode 'files))
7119 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7120 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7121 (?G (call-interactively 'org-agenda-toggle-time-grid))
7122 (?D (call-interactively 'org-agenda-toggle-diary))
7123 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7124 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7125 (org-agenda-check-type t 'timeline 'agenda)
7126 (org-agenda-redo))
7127 (message "Display now includes inactive timestamps as well"))
7128 (?q (message "Abort"))
7129 (otherwise (error "Invalid key" )))))
7131 (defun org-agenda-reset-view ()
7132 "Switch to default view for agenda."
7133 (interactive)
7134 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7135 (defun org-agenda-day-view (&optional day-of-year)
7136 "Switch to daily view for agenda.
7137 With argument DAY-OF-YEAR, switch to that day of the year."
7138 (interactive "P")
7139 (org-agenda-change-time-span 'day day-of-year))
7140 (defun org-agenda-week-view (&optional iso-week)
7141 "Switch to daily view for agenda.
7142 With argument ISO-WEEK, switch to the corresponding ISO week.
7143 If ISO-WEEK has more then 2 digits, only the last two encode the
7144 week. Any digits before this encode a year. So 200712 means
7145 week 12 of year 2007. Years in the range 1938-2037 can also be
7146 written as 2-digit years."
7147 (interactive "P")
7148 (org-agenda-change-time-span 'week iso-week))
7149 (defun org-agenda-month-view (&optional month)
7150 "Switch to monthly view for agenda.
7151 With argument MONTH, switch to that month."
7152 (interactive "P")
7153 (org-agenda-change-time-span 'month month))
7154 (defun org-agenda-year-view (&optional year)
7155 "Switch to yearly view for agenda.
7156 With argument YEAR, switch to that year.
7157 If MONTH has more then 2 digits, only the last two encode the
7158 month. Any digits before this encode a year. So 200712 means
7159 December year 2007. Years in the range 1938-2037 can also be
7160 written as 2-digit years."
7161 (interactive "P")
7162 (when year
7163 (setq year (org-small-year-to-year year)))
7164 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7165 (org-agenda-change-time-span 'year year)
7166 (error "Abort")))
7168 (defun org-agenda-change-time-span (span &optional n)
7169 "Change the agenda view to SPAN.
7170 SPAN may be `day', `week', `month', `year'."
7171 (org-agenda-check-type t 'agenda)
7172 (let* ((args (get-text-property (point) 'org-last-args))
7173 (curspan (nth 2 args)))
7174 (if (and (not n) (equal curspan span))
7175 (error "Viewing span is already \"%s\"" span))
7176 (let* ((sd (or (org-get-at-bol 'day)
7177 (nth 1 args)
7178 org-starting-day))
7179 (sd (org-agenda-compute-starting-span sd span n))
7180 (org-agenda-overriding-cmd
7181 (get-text-property (point) 'org-serie-cmd))
7182 (org-agenda-overriding-arguments
7183 (list (car args) sd span)))
7184 (org-agenda-redo)
7185 (org-agenda-find-same-or-today-or-agenda))
7186 (org-agenda-set-mode-name)
7187 (message "Switched to %s view" span)))
7189 (defun org-agenda-compute-starting-span (sd span &optional n)
7190 "Compute starting date for agenda.
7191 SPAN may be `day', `week', `month', `year'. The return value
7192 is a cons cell with the starting date and the number of days,
7193 so that the date SD will be in that range."
7194 (let* ((greg (calendar-gregorian-from-absolute sd))
7195 (dg (nth 1 greg))
7196 (mg (car greg))
7197 (yg (nth 2 greg)))
7198 (cond
7199 ((eq span 'day)
7200 (when n
7201 (setq sd (+ (calendar-absolute-from-gregorian
7202 (list mg 1 yg))
7203 n -1))))
7204 ((eq span 'week)
7205 (let* ((nt (calendar-day-of-week
7206 (calendar-gregorian-from-absolute sd)))
7207 (d (if org-agenda-start-on-weekday
7208 (- nt org-agenda-start-on-weekday)
7211 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7212 (when n
7213 (require 'cal-iso)
7214 (when (> n 99)
7215 (setq y1 (org-small-year-to-year (/ n 100))
7216 n (mod n 100)))
7217 (setq sd
7218 (calendar-absolute-from-iso
7219 (list n 1
7220 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7221 ((eq span 'month)
7222 (let (y1)
7223 (when (and n (> n 99))
7224 (setq y1 (org-small-year-to-year (/ n 100))
7225 n (mod n 100)))
7226 (setq sd (calendar-absolute-from-gregorian
7227 (list (or n mg) 1 (or y1 yg))))))
7228 ((eq span 'year)
7229 (setq sd (calendar-absolute-from-gregorian
7230 (list 1 1 (or n yg))))))
7231 sd))
7233 (defun org-agenda-next-date-line (&optional arg)
7234 "Jump to the next line indicating a date in agenda buffer."
7235 (interactive "p")
7236 (org-agenda-check-type t 'agenda 'timeline)
7237 (beginning-of-line 1)
7238 ;; This does not work if user makes date format that starts with a blank
7239 (if (looking-at "^\\S-") (forward-char 1))
7240 (if (not (re-search-forward "^\\S-" nil t arg))
7241 (progn
7242 (backward-char 1)
7243 (error "No next date after this line in this buffer")))
7244 (goto-char (match-beginning 0)))
7246 (defun org-agenda-previous-date-line (&optional arg)
7247 "Jump to the previous line indicating a date in agenda buffer."
7248 (interactive "p")
7249 (org-agenda-check-type t 'agenda 'timeline)
7250 (beginning-of-line 1)
7251 (if (not (re-search-backward "^\\S-" nil t arg))
7252 (error "No previous date before this line in this buffer")))
7254 ;; Initialize the highlight
7255 (defvar org-hl (make-overlay 1 1))
7256 (overlay-put org-hl 'face 'highlight)
7258 (defun org-highlight (begin end &optional buffer)
7259 "Highlight a region with overlay."
7260 (move-overlay org-hl begin end (or buffer (current-buffer))))
7262 (defun org-unhighlight ()
7263 "Detach overlay INDEX."
7264 (org-detach-overlay org-hl))
7266 (defun org-unhighlight-once ()
7267 "Remove the highlight from its position, and this function from the hook."
7268 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7269 (org-unhighlight))
7271 (defun org-agenda-follow-mode ()
7272 "Toggle follow mode in an agenda buffer."
7273 (interactive)
7274 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7275 (org-agenda-set-mode-name)
7276 (org-agenda-do-context-action)
7277 (message "Follow mode is %s"
7278 (if org-agenda-follow-mode "on" "off")))
7280 (defun org-agenda-entry-text-mode (&optional arg)
7281 "Toggle entry text mode in an agenda buffer."
7282 (interactive "P")
7283 (setq org-agenda-entry-text-mode (or (integerp arg)
7284 (not org-agenda-entry-text-mode)))
7285 (org-agenda-entry-text-hide)
7286 (and org-agenda-entry-text-mode
7287 (let ((org-agenda-entry-text-maxlines
7288 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7289 (org-agenda-entry-text-show)))
7290 (org-agenda-set-mode-name)
7291 (message "Entry text mode is %s. Maximum number of lines is %d"
7292 (if org-agenda-entry-text-mode "on" "off")
7293 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7295 (defun org-agenda-clockreport-mode (&optional with-filter)
7296 "Toggle clocktable mode in an agenda buffer.
7297 With prefix arg WITH-FILTER, make the clocktable respect the current
7298 agenda filter."
7299 (interactive "P")
7300 (org-agenda-check-type t 'agenda)
7301 (if with-filter
7302 (setq org-agenda-clockreport-mode 'with-filter)
7303 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7304 (org-agenda-set-mode-name)
7305 (org-agenda-redo)
7306 (message "Clocktable mode is %s"
7307 (if org-agenda-clockreport-mode "on" "off")))
7309 (defun org-agenda-log-mode (&optional special)
7310 "Toggle log mode in an agenda buffer.
7311 With argument SPECIAL, show all possible log items, not only the ones
7312 configured in `org-agenda-log-mode-items'.
7313 With a double `C-u' prefix arg, show *only* log items, nothing else."
7314 (interactive "P")
7315 (org-agenda-check-type t 'agenda 'timeline)
7316 (setq org-agenda-show-log
7317 (cond
7318 ((equal special '(16)) 'only)
7319 ((eq special 'clockcheck)
7320 (if (eq org-agenda-show-log 'clockcheck)
7321 nil 'clockcheck))
7322 (special '(closed clock state))
7323 (t (not org-agenda-show-log))))
7324 (org-agenda-set-mode-name)
7325 (org-agenda-redo)
7326 (message "Log mode is %s"
7327 (if org-agenda-show-log "on" "off")))
7329 (defun org-agenda-archives-mode (&optional with-files)
7330 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7331 When called with a prefix argument, include all archive files as well."
7332 (interactive "P")
7333 (setq org-agenda-archives-mode
7334 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7335 (org-agenda-set-mode-name)
7336 (org-agenda-redo)
7337 (message
7338 "%s"
7339 (cond
7340 ((eq org-agenda-archives-mode nil)
7341 "No archives are included")
7342 ((eq org-agenda-archives-mode 'trees)
7343 (format "Trees with :%s: tag are included" org-archive-tag))
7344 ((eq org-agenda-archives-mode t)
7345 (format "Trees with :%s: tag and all active archive files are included"
7346 org-archive-tag)))))
7348 (defun org-agenda-toggle-diary ()
7349 "Toggle diary inclusion in an agenda buffer."
7350 (interactive)
7351 (org-agenda-check-type t 'agenda)
7352 (setq org-agenda-include-diary (not org-agenda-include-diary))
7353 (org-agenda-redo)
7354 (org-agenda-set-mode-name)
7355 (message "Diary inclusion turned %s"
7356 (if org-agenda-include-diary "on" "off")))
7358 (defun org-agenda-toggle-deadlines ()
7359 "Toggle inclusion of entries with a deadline in an agenda buffer."
7360 (interactive)
7361 (org-agenda-check-type t 'agenda)
7362 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7363 (org-agenda-redo)
7364 (org-agenda-set-mode-name)
7365 (message "Deadlines inclusion turned %s"
7366 (if org-agenda-include-deadlines "on" "off")))
7368 (defun org-agenda-toggle-time-grid ()
7369 "Toggle time grid in an agenda buffer."
7370 (interactive)
7371 (org-agenda-check-type t 'agenda)
7372 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7373 (org-agenda-redo)
7374 (org-agenda-set-mode-name)
7375 (message "Time-grid turned %s"
7376 (if org-agenda-use-time-grid "on" "off")))
7378 (defun org-agenda-set-mode-name ()
7379 "Set the mode name to indicate all the small mode settings."
7380 (setq mode-name
7381 (list "Org-Agenda"
7382 (if (get 'org-agenda-files 'org-restrict) " []" "")
7384 '(:eval (org-agenda-span-name org-agenda-current-span))
7385 (if org-agenda-follow-mode " Follow" "")
7386 (if org-agenda-entry-text-mode " ETxt" "")
7387 (if org-agenda-include-diary " Diary" "")
7388 (if org-agenda-include-deadlines " Ddl" "")
7389 (if org-agenda-use-time-grid " Grid" "")
7390 (if (and (boundp 'org-habit-show-habits)
7391 org-habit-show-habits) " Habit" "")
7392 (cond
7393 ((consp org-agenda-show-log) " LogAll")
7394 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7395 (org-agenda-show-log " Log")
7396 (t ""))
7397 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7398 :preset-filter))
7399 '(:eval (org-propertize
7400 (concat " <"
7401 (mapconcat
7402 'identity
7403 (append
7404 (get 'org-agenda-category-filter :preset-filter)
7405 org-agenda-category-filter)
7407 ">")
7408 'face 'org-agenda-filter-category
7409 'help-echo "Category used in filtering"))
7411 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7412 :preset-filter))
7413 '(:eval (org-propertize
7414 (concat " {"
7415 (mapconcat
7416 'identity
7417 (append
7418 (get 'org-agenda-tag-filter :preset-filter)
7419 org-agenda-tag-filter)
7421 "}")
7422 'face 'org-agenda-filter-tags
7423 'help-echo "Tags used in filtering"))
7425 (if org-agenda-archives-mode
7426 (if (eq org-agenda-archives-mode t)
7427 " Archives"
7428 (format " :%s:" org-archive-tag))
7430 (if org-agenda-clockreport-mode
7431 (if (eq org-agenda-clockreport-mode 'with-filter)
7432 " Clock{}" " Clock")
7433 "")))
7434 (force-mode-line-update))
7436 (defun org-agenda-post-command-hook ()
7437 (setq org-agenda-type
7438 (or (get-text-property (point) 'org-agenda-type)
7439 (get-text-property (max (point-min) (1- (point)))
7440 'org-agenda-type))))
7442 (defun org-agenda-next-line ()
7443 "Move cursor to the next line, and show if follow mode is active."
7444 (interactive)
7445 (call-interactively 'next-line)
7446 (org-agenda-do-context-action))
7448 (defun org-agenda-previous-line ()
7449 "Move cursor to the previous line, and show if follow-mode is active."
7450 (interactive)
7451 (call-interactively 'previous-line)
7452 (org-agenda-do-context-action))
7454 (defun org-agenda-next-item (n)
7455 "Move cursor to next agenda item."
7456 (interactive "p")
7457 (let ((col (current-column)))
7458 (dotimes (c n)
7459 (when (next-single-property-change (point-at-eol) 'org-marker)
7460 (move-end-of-line 1)
7461 (goto-char (next-single-property-change (point) 'org-marker))))
7462 (org-move-to-column col))
7463 (org-agenda-do-context-action))
7465 (defun org-agenda-previous-item (n)
7466 "Move cursor to next agenda item."
7467 (interactive "p")
7468 (dotimes (c n)
7469 (let ((col (current-column))
7470 (goto (save-excursion
7471 (move-end-of-line 0)
7472 (previous-single-property-change (point) 'org-marker))))
7473 (if goto (goto-char goto))
7474 (org-move-to-column col)))
7475 (org-agenda-do-context-action))
7477 (defun org-agenda-do-context-action ()
7478 "Show outline path and, maybe, follow mode window."
7479 (let ((m (org-get-at-bol 'org-marker)))
7480 (when (and (markerp m) (marker-buffer m))
7481 (and org-agenda-follow-mode
7482 (if org-agenda-follow-indirect
7483 (org-agenda-tree-to-indirect-buffer nil)
7484 (org-agenda-show)))
7485 (and org-agenda-show-outline-path
7486 (org-with-point-at m (org-display-outline-path t))))))
7488 (defun org-agenda-show-priority ()
7489 "Show the priority of the current item.
7490 This priority is composed of the main priority given with the [#A] cookies,
7491 and by additional input from the age of a schedules or deadline entry."
7492 (interactive)
7493 (let* ((pri (org-get-at-bol 'priority)))
7494 (message "Priority is %d" (if pri pri -1000))))
7496 (defun org-agenda-show-tags ()
7497 "Show the tags applicable to the current item."
7498 (interactive)
7499 (let* ((tags (org-get-at-bol 'tags)))
7500 (if tags
7501 (message "Tags are :%s:"
7502 (org-no-properties (mapconcat 'identity tags ":")))
7503 (message "No tags associated with this line"))))
7505 (defun org-agenda-goto (&optional highlight)
7506 "Go to the Org-mode file which contains the item at point."
7507 (interactive)
7508 (let* ((marker (or (org-get-at-bol 'org-marker)
7509 (org-agenda-error)))
7510 (buffer (marker-buffer marker))
7511 (pos (marker-position marker)))
7512 (switch-to-buffer-other-window buffer)
7513 (widen)
7514 (push-mark)
7515 (goto-char pos)
7516 (when (derived-mode-p 'org-mode)
7517 (org-show-context 'agenda)
7518 (save-excursion
7519 (and (outline-next-heading)
7520 (org-flag-heading nil)))) ; show the next heading
7521 (when (outline-invisible-p)
7522 (show-entry)) ; display invisible text
7523 (recenter (/ (window-height) 2))
7524 (run-hooks 'org-agenda-after-show-hook)
7525 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7527 (defvar org-agenda-after-show-hook nil
7528 "Normal hook run after an item has been shown from the agenda.
7529 Point is in the buffer where the item originated.")
7531 (defun org-agenda-kill ()
7532 "Kill the entry or subtree belonging to the current agenda entry."
7533 (interactive)
7534 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7535 (let* ((bufname-orig (buffer-name))
7536 (marker (or (org-get-at-bol 'org-marker)
7537 (org-agenda-error)))
7538 (buffer (marker-buffer marker))
7539 (pos (marker-position marker))
7540 (type (org-get-at-bol 'type))
7541 dbeg dend (n 0) conf)
7542 (org-with-remote-undo buffer
7543 (with-current-buffer buffer
7544 (save-excursion
7545 (goto-char pos)
7546 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7547 (setq dbeg (progn (org-back-to-heading t) (point))
7548 dend (org-end-of-subtree t t))
7549 (setq dbeg (point-at-bol)
7550 dend (min (point-max) (1+ (point-at-eol)))))
7551 (goto-char dbeg)
7552 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7553 (setq conf (or (eq t org-agenda-confirm-kill)
7554 (and (numberp org-agenda-confirm-kill)
7555 (> n org-agenda-confirm-kill))))
7556 (and conf
7557 (not (y-or-n-p
7558 (format "Delete entry with %d lines in buffer \"%s\"? "
7559 n (buffer-name buffer))))
7560 (error "Abort"))
7561 (let ((org-agenda-buffer-name bufname-orig))
7562 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7563 (with-current-buffer buffer (delete-region dbeg dend))
7564 (message "Agenda item and source killed"))))
7566 (defvar org-archive-default-command) ; defined in org-archive.el
7567 (defun org-agenda-archive-default ()
7568 "Archive the entry or subtree belonging to the current agenda entry."
7569 (interactive)
7570 (require 'org-archive)
7571 (org-agenda-archive-with org-archive-default-command))
7573 (defun org-agenda-archive-default-with-confirmation ()
7574 "Archive the entry or subtree belonging to the current agenda entry."
7575 (interactive)
7576 (require 'org-archive)
7577 (org-agenda-archive-with org-archive-default-command 'confirm))
7579 (defun org-agenda-archive ()
7580 "Archive the entry or subtree belonging to the current agenda entry."
7581 (interactive)
7582 (org-agenda-archive-with 'org-archive-subtree))
7584 (defun org-agenda-archive-to-archive-sibling ()
7585 "Move the entry to the archive sibling."
7586 (interactive)
7587 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7589 (defun org-agenda-archive-with (cmd &optional confirm)
7590 "Move the entry to the archive sibling."
7591 (interactive)
7592 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7593 (let* ((bufname-orig (buffer-name))
7594 (marker (or (org-get-at-bol 'org-marker)
7595 (org-agenda-error)))
7596 (buffer (marker-buffer marker))
7597 (pos (marker-position marker)))
7598 (org-with-remote-undo buffer
7599 (with-current-buffer buffer
7600 (if (derived-mode-p 'org-mode)
7601 (if (and confirm
7602 (not (y-or-n-p "Archive this subtree or entry? ")))
7603 (error "Abort")
7604 (save-excursion
7605 (goto-char pos)
7606 (let ((org-agenda-buffer-name bufname-orig))
7607 (org-remove-subtree-entries-from-agenda))
7608 (org-back-to-heading t)
7609 (funcall cmd)))
7610 (error "Archiving works only in Org-mode files"))))))
7612 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7613 "Remove all lines in the agenda that correspond to a given subtree.
7614 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7615 If this information is not given, the function uses the tree at point."
7616 (let ((buf (or buf (current-buffer))) m p)
7617 (save-excursion
7618 (unless (and beg end)
7619 (org-back-to-heading t)
7620 (setq beg (point))
7621 (org-end-of-subtree t)
7622 (setq end (point)))
7623 (set-buffer (get-buffer org-agenda-buffer-name))
7624 (save-excursion
7625 (goto-char (point-max))
7626 (beginning-of-line 1)
7627 (while (not (bobp))
7628 (when (and (setq m (org-get-at-bol 'org-marker))
7629 (equal buf (marker-buffer m))
7630 (setq p (marker-position m))
7631 (>= p beg)
7632 (< p end))
7633 (let ((inhibit-read-only t))
7634 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7635 (beginning-of-line 0))))))
7637 (defun org-agenda-refile (&optional goto rfloc no-update)
7638 "Refile the item at point."
7639 (interactive "P")
7640 (if (equal goto '(16))
7641 (org-refile-goto-last-stored)
7642 (let* ((buffer-orig (buffer-name))
7643 (marker (or (org-get-at-bol 'org-hd-marker)
7644 (org-agenda-error)))
7645 (buffer (marker-buffer marker))
7646 (pos (marker-position marker))
7647 (rfloc (or rfloc
7648 (org-refile-get-location
7649 (if goto "Goto" "Refile to") buffer
7650 org-refile-allow-creating-parent-nodes))))
7651 (with-current-buffer buffer
7652 (save-excursion
7653 (save-restriction
7654 (widen)
7655 (goto-char marker)
7656 (let ((org-agenda-buffer-name buffer-orig))
7657 (org-remove-subtree-entries-from-agenda))
7658 (org-refile goto buffer rfloc)))))
7659 (unless no-update (org-agenda-redo))))
7661 (defun org-agenda-open-link (&optional arg)
7662 "Follow the link in the current line, if any.
7663 This looks for a link in the displayed line in the agenda. It also looks
7664 at the text of the entry itself."
7665 (interactive "P")
7666 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7667 (org-get-at-bol 'org-marker)))
7668 (buffer (and marker (marker-buffer marker)))
7669 (prefix (buffer-substring
7670 (point-at-bol) (point-at-eol))))
7671 (cond
7672 (buffer
7673 (with-current-buffer buffer
7674 (save-excursion
7675 (save-restriction
7676 (widen)
7677 (goto-char marker)
7678 (org-offer-links-in-entry arg prefix)))))
7679 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7680 (save-excursion
7681 (beginning-of-line 1)
7682 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7683 (org-open-link-from-string (match-string 1)))
7684 (t (error "No link to open here")))))
7686 (defun org-agenda-copy-local-variable (var)
7687 "Get a variable from a referenced buffer and install it here."
7688 (let ((m (org-get-at-bol 'org-marker)))
7689 (when (and m (buffer-live-p (marker-buffer m)))
7690 (org-set-local var (with-current-buffer (marker-buffer m)
7691 (symbol-value var))))))
7693 (defun org-agenda-switch-to (&optional delete-other-windows)
7694 "Go to the Org-mode file which contains the item at point."
7695 (interactive)
7696 (if (and org-return-follows-link
7697 (not (org-get-at-bol 'org-marker))
7698 (org-in-regexp org-bracket-link-regexp))
7699 (org-open-link-from-string (match-string 0))
7700 (let* ((marker (or (org-get-at-bol 'org-marker)
7701 (org-agenda-error)))
7702 (buffer (marker-buffer marker))
7703 (pos (marker-position marker)))
7704 (org-pop-to-buffer-same-window buffer)
7705 (and delete-other-windows (delete-other-windows))
7706 (widen)
7707 (goto-char pos)
7708 (when (derived-mode-p 'org-mode)
7709 (org-show-context 'agenda)
7710 (save-excursion
7711 (and (outline-next-heading)
7712 (org-flag-heading nil))) ; show the next heading
7713 (when (outline-invisible-p)
7714 (show-entry)) ; display invisible text
7715 (run-hooks 'org-agenda-after-show-hook)))))
7717 (defun org-agenda-goto-mouse (ev)
7718 "Go to the Org-mode file which contains the item at the mouse click."
7719 (interactive "e")
7720 (mouse-set-point ev)
7721 (org-agenda-goto))
7723 (defun org-agenda-show (&optional full-entry)
7724 "Display the Org-mode file which contains the item at point.
7725 With prefix argument FULL-ENTRY, make the entire entry visible
7726 if it was hidden in the outline."
7727 (interactive "P")
7728 (let ((win (selected-window)))
7729 (if full-entry
7730 (let ((org-show-entry-below t))
7731 (org-agenda-goto t))
7732 (org-agenda-goto t))
7733 (select-window win)))
7735 (defvar org-agenda-show-window nil)
7736 (defun org-agenda-show-and-scroll-up (&optional arg)
7737 "Display the Org-mode file which contains the item at point.
7738 When called repeatedly, scroll the window that is displaying the buffer.
7739 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7740 `show-subtree' to display the item, so that drawers and logbooks stay
7741 folded."
7742 (interactive "P")
7743 (let ((win (selected-window)))
7744 (if (and (window-live-p org-agenda-show-window)
7745 (eq this-command last-command))
7746 (progn
7747 (select-window org-agenda-show-window)
7748 (ignore-errors (scroll-up)))
7749 (org-agenda-goto t)
7750 (if arg (org-show-entry) (show-subtree))
7751 (setq org-agenda-show-window (selected-window)))
7752 (select-window win)))
7754 (defun org-agenda-show-scroll-down ()
7755 "Scroll down the window showing the agenda."
7756 (interactive)
7757 (let ((win (selected-window)))
7758 (when (window-live-p org-agenda-show-window)
7759 (select-window org-agenda-show-window)
7760 (ignore-errors (scroll-down))
7761 (select-window win))))
7763 (defun org-agenda-show-1 (&optional more)
7764 "Display the Org-mode file which contains the item at point.
7765 The prefix arg selects the amount of information to display:
7767 0 hide the subtree
7768 1 just show the entry according to defaults.
7769 2 show the children view
7770 3 show the subtree view
7771 4 show the entire subtree and any LOGBOOK drawers
7772 5 show the entire subtree and any drawers
7773 With prefix argument FULL-ENTRY, make the entire entry visible
7774 if it was hidden in the outline."
7775 (interactive "p")
7776 (let ((win (selected-window)))
7777 (org-agenda-goto t)
7778 (org-recenter-heading 1)
7779 (cond
7780 ((= more 0)
7781 (hide-subtree)
7782 (save-excursion
7783 (org-back-to-heading)
7784 (run-hook-with-args 'org-cycle-hook 'folded))
7785 (message "Remote: FOLDED"))
7786 ((and (org-called-interactively-p 'any) (= more 1))
7787 (message "Remote: show with default settings"))
7788 ((= more 2)
7789 (show-entry)
7790 (show-children)
7791 (save-excursion
7792 (org-back-to-heading)
7793 (run-hook-with-args 'org-cycle-hook 'children))
7794 (message "Remote: CHILDREN"))
7795 ((= more 3)
7796 (show-subtree)
7797 (save-excursion
7798 (org-back-to-heading)
7799 (run-hook-with-args 'org-cycle-hook 'subtree))
7800 (message "Remote: SUBTREE"))
7801 ((= more 4)
7802 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7803 (org-drawer-regexp
7804 (concat "^[ \t]*:\\("
7805 (mapconcat 'regexp-quote org-drawers "\\|")
7806 "\\):[ \t]*$")))
7807 (show-subtree)
7808 (save-excursion
7809 (org-back-to-heading)
7810 (org-cycle-hide-drawers 'subtree)))
7811 (message "Remote: SUBTREE AND LOGBOOK"))
7812 ((> more 4)
7813 (show-subtree)
7814 (message "Remote: SUBTREE AND ALL DRAWERS")))
7815 (select-window win)))
7817 (defun org-recenter-heading (n)
7818 (save-excursion
7819 (org-back-to-heading)
7820 (recenter n)))
7822 (defvar org-agenda-cycle-counter nil)
7823 (defun org-agenda-cycle-show (&optional n)
7824 "Show the current entry in another window, with default settings.
7825 Default settings are taken from `org-show-hierarchy-above' and siblings.
7826 When use repeatedly in immediate succession, the remote entry will cycle
7827 through visibility
7829 children -> subtree -> folded
7831 When called with a numeric prefix arg, that arg will be passed through to
7832 `org-agenda-show-1'. For the interpretation of that argument, see the
7833 docstring of `org-agenda-show-1'."
7834 (interactive "P")
7835 (if (integerp n)
7836 (setq org-agenda-cycle-counter n)
7837 (if (not (eq last-command this-command))
7838 (setq org-agenda-cycle-counter 1)
7839 (if (equal org-agenda-cycle-counter 0)
7840 (setq org-agenda-cycle-counter 2)
7841 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7842 (if (> org-agenda-cycle-counter 3)
7843 (setq org-agenda-cycle-counter 0)))))
7844 (org-agenda-show-1 org-agenda-cycle-counter))
7846 (defun org-agenda-recenter (arg)
7847 "Display the Org-mode file which contains the item at point and recenter."
7848 (interactive "P")
7849 (let ((win (selected-window)))
7850 (org-agenda-goto t)
7851 (recenter arg)
7852 (select-window win)))
7854 (defun org-agenda-show-mouse (ev)
7855 "Display the Org-mode file which contains the item at the mouse click."
7856 (interactive "e")
7857 (mouse-set-point ev)
7858 (org-agenda-show))
7860 (defun org-agenda-check-no-diary ()
7861 "Check if the entry is a diary link and abort if yes."
7862 (if (org-get-at-bol 'org-agenda-diary-link)
7863 (org-agenda-error)))
7865 (defun org-agenda-error ()
7866 (error "Command not allowed in this line"))
7868 (defun org-agenda-tree-to-indirect-buffer (arg)
7869 "Show the subtree corresponding to the current entry in an indirect buffer.
7870 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
7872 With a numerical prefix ARG, go up to this level and then take that tree.
7873 With a negative numeric ARG, go up by this number of levels.
7874 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7875 use the dedicated frame)."
7876 (interactive "P")
7877 (if current-prefix-arg
7878 (org-agenda-do-tree-to-indirect-buffer arg)
7879 (let ((agenda-buffer (buffer-name))
7880 (agenda-window (selected-window))
7881 (indirect-window
7882 (and org-last-indirect-buffer
7883 (get-buffer-window org-last-indirect-buffer))))
7884 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
7885 (unless (or (eq org-indirect-buffer-display 'new-frame)
7886 (eq org-indirect-buffer-display 'dedicated-frame))
7887 (unwind-protect
7888 (progn
7889 (unless (and indirect-window (window-live-p indirect-window)))
7890 (setq indirect-window (split-window agenda-window)))
7891 (and indirect-window (select-window indirect-window))
7892 (switch-to-buffer org-last-indirect-buffer :norecord)
7893 (fit-window-to-buffer indirect-window)))
7894 (select-window (get-buffer-window agenda-buffer)))))
7896 (defun org-agenda-do-tree-to-indirect-buffer (arg)
7897 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7898 (org-agenda-check-no-diary)
7899 (let* ((marker (or (org-get-at-bol 'org-marker)
7900 (org-agenda-error)))
7901 (buffer (marker-buffer marker))
7902 (pos (marker-position marker)))
7903 (with-current-buffer buffer
7904 (save-excursion
7905 (goto-char pos)
7906 (funcall 'org-tree-to-indirect-buffer arg)))))
7908 (defvar org-last-heading-marker (make-marker)
7909 "Marker pointing to the headline that last changed its TODO state
7910 by a remote command from the agenda.")
7912 (defun org-agenda-todo-nextset ()
7913 "Switch TODO entry to next sequence."
7914 (interactive)
7915 (org-agenda-todo 'nextset))
7917 (defun org-agenda-todo-previousset ()
7918 "Switch TODO entry to previous sequence."
7919 (interactive)
7920 (org-agenda-todo 'previousset))
7922 (defun org-agenda-todo (&optional arg)
7923 "Cycle TODO state of line at point, also in Org-mode file.
7924 This changes the line at point, all other lines in the agenda referring to
7925 the same tree node, and the headline of the tree node in the Org-mode file."
7926 (interactive "P")
7927 (org-agenda-check-no-diary)
7928 (let* ((col (current-column))
7929 (marker (or (org-get-at-bol 'org-marker)
7930 (org-agenda-error)))
7931 (buffer (marker-buffer marker))
7932 (pos (marker-position marker))
7933 (hdmarker (org-get-at-bol 'org-hd-marker))
7934 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7935 (inhibit-read-only t)
7936 org-agenda-headline-snapshot-before-repeat newhead just-one)
7937 (org-with-remote-undo buffer
7938 (with-current-buffer buffer
7939 (widen)
7940 (goto-char pos)
7941 (org-show-context 'agenda)
7942 (save-excursion
7943 (and (outline-next-heading)
7944 (org-flag-heading nil))) ; show the next heading
7945 (let ((current-prefix-arg arg))
7946 (call-interactively 'org-todo))
7947 (and (bolp) (forward-char 1))
7948 (setq newhead (org-get-heading))
7949 (when (and (org-bound-and-true-p
7950 org-agenda-headline-snapshot-before-repeat)
7951 (not (equal org-agenda-headline-snapshot-before-repeat
7952 newhead))
7953 todayp)
7954 (setq newhead org-agenda-headline-snapshot-before-repeat
7955 just-one t))
7956 (save-excursion
7957 (org-back-to-heading)
7958 (move-marker org-last-heading-marker (point))))
7959 (beginning-of-line 1)
7960 (save-excursion
7961 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7962 (org-move-to-column col))))
7964 (defun org-agenda-add-note (&optional arg)
7965 "Add a time-stamped note to the entry at point."
7966 (interactive "P")
7967 (org-agenda-check-no-diary)
7968 (let* ((marker (or (org-get-at-bol 'org-marker)
7969 (org-agenda-error)))
7970 (buffer (marker-buffer marker))
7971 (pos (marker-position marker))
7972 (hdmarker (org-get-at-bol 'org-hd-marker))
7973 (inhibit-read-only t))
7974 (with-current-buffer buffer
7975 (widen)
7976 (goto-char pos)
7977 (org-show-context 'agenda)
7978 (save-excursion
7979 (and (outline-next-heading)
7980 (org-flag-heading nil))) ; show the next heading
7981 (org-add-note))))
7983 (defun org-agenda-change-all-lines (newhead hdmarker
7984 &optional fixface just-this)
7985 "Change all lines in the agenda buffer which match HDMARKER.
7986 The new content of the line will be NEWHEAD (as modified by
7987 `org-agenda-format-item'). HDMARKER is checked with
7988 `equal' against all `org-hd-marker' text properties in the file.
7989 If FIXFACE is non-nil, the face of each item is modified according to
7990 the new TODO state.
7991 If JUST-THIS is non-nil, change just the current line, not all.
7992 If FORCE-TAGS is non nil, the car of it returns the new tags."
7993 (let* ((inhibit-read-only t)
7994 (line (org-current-line))
7995 (org-agenda-buffer (current-buffer))
7996 (thetags (with-current-buffer (marker-buffer hdmarker)
7997 (save-excursion (save-restriction (widen)
7998 (goto-char hdmarker)
7999 (org-get-tags-at)))))
8000 props m pl undone-face done-face finish new dotime cat tags)
8001 (save-excursion
8002 (goto-char (point-max))
8003 (beginning-of-line 1)
8004 (while (not finish)
8005 (setq finish (bobp))
8006 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8007 (or (not just-this) (= (org-current-line) line))
8008 (equal m hdmarker))
8009 (setq props (text-properties-at (point))
8010 dotime (org-get-at-bol 'dotime)
8011 cat (org-get-at-bol 'org-category)
8012 tags thetags
8014 (let ((org-prefix-format-compiled
8015 (or (get-text-property (point) 'format)
8016 org-prefix-format-compiled))
8017 (extra (org-get-at-bol 'extra)))
8018 (with-current-buffer (marker-buffer hdmarker)
8019 (save-excursion
8020 (save-restriction
8021 (widen)
8022 (org-agenda-format-item extra newhead cat tags dotime)))))
8023 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8024 undone-face (org-get-at-bol 'undone-face)
8025 done-face (org-get-at-bol 'done-face))
8026 (beginning-of-line 1)
8027 (cond
8028 ((equal new "")
8029 (and (looking-at ".*\n?") (replace-match "")))
8030 ((looking-at ".*")
8031 (replace-match new t t)
8032 (beginning-of-line 1)
8033 (add-text-properties (point-at-bol) (point-at-eol) props)
8034 (when fixface
8035 (add-text-properties
8036 (point-at-bol) (point-at-eol)
8037 (list 'face
8038 (if org-last-todo-state-is-todo
8039 undone-face done-face))))
8040 (org-agenda-highlight-todo 'line)
8041 (beginning-of-line 1))
8042 (t (error "Line update did not work"))))
8043 (beginning-of-line 0)))
8044 (org-agenda-finalize)))
8046 (defun org-agenda-align-tags (&optional line)
8047 "Align all tags in agenda items to `org-agenda-tags-column'."
8048 (let ((inhibit-read-only t) l c)
8049 (save-excursion
8050 (goto-char (if line (point-at-bol) (point-min)))
8051 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8052 (if line (point-at-eol) nil) t)
8053 (add-text-properties
8054 (match-beginning 2) (match-end 2)
8055 (list 'face (delq nil (let ((prop (get-text-property
8056 (match-beginning 2) 'face)))
8057 (or (listp prop) (setq prop (list prop)))
8058 (if (memq 'org-tag prop)
8059 prop
8060 (cons 'org-tag prop))))))
8061 (setq l (- (match-end 2) (match-beginning 2))
8062 c (if (< org-agenda-tags-column 0)
8063 (- (abs org-agenda-tags-column) l)
8064 org-agenda-tags-column))
8065 (delete-region (match-beginning 1) (match-end 1))
8066 (goto-char (match-beginning 1))
8067 (insert (org-add-props
8068 (make-string (max 1 (- c (current-column))) ?\ )
8069 (plist-put (copy-sequence (text-properties-at (point)))
8070 'face nil))))
8071 (goto-char (point-min))
8072 (org-font-lock-add-tag-faces (point-max)))))
8074 (defun org-agenda-priority-up ()
8075 "Increase the priority of line at point, also in Org-mode file."
8076 (interactive)
8077 (org-agenda-priority 'up))
8079 (defun org-agenda-priority-down ()
8080 "Decrease the priority of line at point, also in Org-mode file."
8081 (interactive)
8082 (org-agenda-priority 'down))
8084 (defun org-agenda-priority (&optional force-direction)
8085 "Set the priority of line at point, also in Org-mode file.
8086 This changes the line at point, all other lines in the agenda referring to
8087 the same tree node, and the headline of the tree node in the Org-mode file."
8088 (interactive)
8089 (unless org-enable-priority-commands
8090 (error "Priority commands are disabled"))
8091 (org-agenda-check-no-diary)
8092 (let* ((marker (or (org-get-at-bol 'org-marker)
8093 (org-agenda-error)))
8094 (hdmarker (org-get-at-bol 'org-hd-marker))
8095 (buffer (marker-buffer hdmarker))
8096 (pos (marker-position hdmarker))
8097 (inhibit-read-only t)
8098 newhead)
8099 (org-with-remote-undo buffer
8100 (with-current-buffer buffer
8101 (widen)
8102 (goto-char pos)
8103 (org-show-context 'agenda)
8104 (save-excursion
8105 (and (outline-next-heading)
8106 (org-flag-heading nil))) ; show the next heading
8107 (funcall 'org-priority force-direction)
8108 (end-of-line 1)
8109 (setq newhead (org-get-heading)))
8110 (org-agenda-change-all-lines newhead hdmarker)
8111 (beginning-of-line 1))))
8113 ;; FIXME: should fix the tags property of the agenda line.
8114 (defun org-agenda-set-tags (&optional tag onoff)
8115 "Set tags for the current headline."
8116 (interactive)
8117 (org-agenda-check-no-diary)
8118 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8119 (call-interactively 'org-change-tag-in-region)
8120 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8121 (org-agenda-error)))
8122 (buffer (marker-buffer hdmarker))
8123 (pos (marker-position hdmarker))
8124 (inhibit-read-only t)
8125 newhead)
8126 (org-with-remote-undo buffer
8127 (with-current-buffer buffer
8128 (widen)
8129 (goto-char pos)
8130 (save-excursion
8131 (org-show-context 'agenda))
8132 (save-excursion
8133 (and (outline-next-heading)
8134 (org-flag-heading nil))) ; show the next heading
8135 (goto-char pos)
8136 (if tag
8137 (org-toggle-tag tag onoff)
8138 (call-interactively 'org-set-tags))
8139 (end-of-line 1)
8140 (setq newhead (org-get-heading)))
8141 (org-agenda-change-all-lines newhead hdmarker)
8142 (beginning-of-line 1)))))
8144 (defun org-agenda-set-property ()
8145 "Set a property for the current headline."
8146 (interactive)
8147 (org-agenda-check-no-diary)
8148 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8149 (org-agenda-error)))
8150 (buffer (marker-buffer hdmarker))
8151 (pos (marker-position hdmarker))
8152 (inhibit-read-only t)
8153 newhead)
8154 (org-with-remote-undo buffer
8155 (with-current-buffer buffer
8156 (widen)
8157 (goto-char pos)
8158 (save-excursion
8159 (org-show-context 'agenda))
8160 (save-excursion
8161 (and (outline-next-heading)
8162 (org-flag-heading nil))) ; show the next heading
8163 (goto-char pos)
8164 (call-interactively 'org-set-property)))))
8166 (defun org-agenda-set-effort ()
8167 "Set the effort property for the current headline."
8168 (interactive)
8169 (org-agenda-check-no-diary)
8170 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8171 (org-agenda-error)))
8172 (buffer (marker-buffer hdmarker))
8173 (pos (marker-position hdmarker))
8174 (inhibit-read-only t)
8175 newhead)
8176 (org-with-remote-undo buffer
8177 (with-current-buffer buffer
8178 (widen)
8179 (goto-char pos)
8180 (save-excursion
8181 (org-show-context 'agenda))
8182 (save-excursion
8183 (and (outline-next-heading)
8184 (org-flag-heading nil))) ; show the next heading
8185 (goto-char pos)
8186 (call-interactively 'org-set-effort)
8187 (end-of-line 1)
8188 (setq newhead (org-get-heading)))
8189 (org-agenda-change-all-lines newhead hdmarker))))
8191 (defun org-agenda-toggle-archive-tag ()
8192 "Toggle the archive tag for the current entry."
8193 (interactive)
8194 (org-agenda-check-no-diary)
8195 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8196 (org-agenda-error)))
8197 (buffer (marker-buffer hdmarker))
8198 (pos (marker-position hdmarker))
8199 (inhibit-read-only t)
8200 newhead)
8201 (org-with-remote-undo buffer
8202 (with-current-buffer buffer
8203 (widen)
8204 (goto-char pos)
8205 (org-show-context 'agenda)
8206 (save-excursion
8207 (and (outline-next-heading)
8208 (org-flag-heading nil))) ; show the next heading
8209 (call-interactively 'org-toggle-archive-tag)
8210 (end-of-line 1)
8211 (setq newhead (org-get-heading)))
8212 (org-agenda-change-all-lines newhead hdmarker)
8213 (beginning-of-line 1))))
8215 (defun org-agenda-do-date-later (arg)
8216 (interactive "P")
8217 (cond
8218 ((or (equal arg '(16))
8219 (memq last-command
8220 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8221 (setq this-command 'org-agenda-date-later-minutes)
8222 (org-agenda-date-later-minutes 1))
8223 ((or (equal arg '(4))
8224 (memq last-command
8225 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8226 (setq this-command 'org-agenda-date-later-hours)
8227 (org-agenda-date-later-hours 1))
8229 (org-agenda-date-later (prefix-numeric-value arg)))))
8231 (defun org-agenda-do-date-earlier (arg)
8232 (interactive "P")
8233 (cond
8234 ((or (equal arg '(16))
8235 (memq last-command
8236 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8237 (setq this-command 'org-agenda-date-earlier-minutes)
8238 (org-agenda-date-earlier-minutes 1))
8239 ((or (equal arg '(4))
8240 (memq last-command
8241 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8242 (setq this-command 'org-agenda-date-earlier-hours)
8243 (org-agenda-date-earlier-hours 1))
8245 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8247 (defun org-agenda-date-later (arg &optional what)
8248 "Change the date of this item to ARG day(s) later."
8249 (interactive "p")
8250 (org-agenda-check-type t 'agenda 'timeline)
8251 (org-agenda-check-no-diary)
8252 (let* ((marker (or (org-get-at-bol 'org-marker)
8253 (org-agenda-error)))
8254 (buffer (marker-buffer marker))
8255 (pos (marker-position marker))
8256 cdate today)
8257 (org-with-remote-undo buffer
8258 (with-current-buffer buffer
8259 (widen)
8260 (goto-char pos)
8261 (if (not (org-at-timestamp-p))
8262 (error "Cannot find time stamp"))
8263 (when (and org-agenda-move-date-from-past-immediately-to-today
8264 (equal arg 1)
8265 (or (not what) (eq what 'day))
8266 (not (save-match-data (org-at-date-range-p))))
8267 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8268 cdate (calendar-absolute-from-gregorian
8269 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8270 today (org-today))
8271 (if (> today cdate)
8272 ;; immediately shift to today
8273 (setq arg (- today cdate))))
8274 (org-timestamp-change arg (or what 'day))
8275 (when (and (org-at-date-range-p)
8276 (re-search-backward org-tr-regexp-both (point-at-bol)))
8277 (let ((end org-last-changed-timestamp))
8278 (org-timestamp-change arg (or what 'day))
8279 (setq org-last-changed-timestamp
8280 (concat org-last-changed-timestamp "--" end)))))
8281 (org-agenda-show-new-time marker org-last-changed-timestamp))
8282 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8284 (defun org-agenda-date-earlier (arg &optional what)
8285 "Change the date of this item to ARG day(s) earlier."
8286 (interactive "p")
8287 (org-agenda-date-later (- arg) what))
8289 (defun org-agenda-date-later-minutes (arg)
8290 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8291 (interactive "p")
8292 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8293 (org-agenda-date-later arg 'minute))
8295 (defun org-agenda-date-earlier-minutes (arg)
8296 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8297 (interactive "p")
8298 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8299 (org-agenda-date-earlier arg 'minute))
8301 (defun org-agenda-date-later-hours (arg)
8302 "Change the time of this item, in hour steps."
8303 (interactive "p")
8304 (org-agenda-date-later arg 'hour))
8306 (defun org-agenda-date-earlier-hours (arg)
8307 "Change the time of this item, in hour steps."
8308 (interactive "p")
8309 (org-agenda-date-earlier arg 'hour))
8311 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8312 "Show new date stamp via text properties."
8313 ;; We use text properties to make this undoable
8314 (let ((inhibit-read-only t)
8315 (buffer-invisibility-spec))
8316 (setq stamp (concat " " prefix " => " stamp))
8317 (save-excursion
8318 (goto-char (point-max))
8319 (while (not (bobp))
8320 (when (equal marker (org-get-at-bol 'org-marker))
8321 (org-move-to-column (- (window-width) (length stamp)) t)
8322 (org-agenda-fix-tags-filter-overlays-at (point))
8323 (if (featurep 'xemacs)
8324 ;; Use `duplicable' property to trigger undo recording
8325 (let ((ex (make-extent nil nil))
8326 (gl (make-glyph stamp)))
8327 (set-glyph-face gl 'secondary-selection)
8328 (set-extent-properties
8329 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8330 (insert-extent ex (1- (point)) (point-at-eol)))
8331 (add-text-properties
8332 (1- (point)) (point-at-eol)
8333 (list 'display (org-add-props stamp nil
8334 'face 'secondary-selection))))
8335 (beginning-of-line 1))
8336 (beginning-of-line 0)))))
8338 (defun org-agenda-date-prompt (arg)
8339 "Change the date of this item. Date is prompted for, with default today.
8340 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8341 be used to request time specification in the time stamp."
8342 (interactive "P")
8343 (org-agenda-check-type t 'agenda 'timeline)
8344 (org-agenda-check-no-diary)
8345 (let* ((marker (or (org-get-at-bol 'org-marker)
8346 (org-agenda-error)))
8347 (buffer (marker-buffer marker))
8348 (pos (marker-position marker)))
8349 (org-with-remote-undo buffer
8350 (with-current-buffer buffer
8351 (widen)
8352 (goto-char pos)
8353 (if (not (org-at-timestamp-p t))
8354 (error "Cannot find time stamp"))
8355 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8356 (org-agenda-show-new-time marker org-last-changed-timestamp))
8357 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8359 (defun org-agenda-schedule (arg &optional time)
8360 "Schedule the item at point.
8361 ARG is passed through to `org-schedule'."
8362 (interactive "P")
8363 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8364 (org-agenda-check-no-diary)
8365 (let* ((marker (or (org-get-at-bol 'org-marker)
8366 (org-agenda-error)))
8367 (type (marker-insertion-type marker))
8368 (buffer (marker-buffer marker))
8369 (pos (marker-position marker))
8370 (org-insert-labeled-timestamps-at-point nil)
8372 (set-marker-insertion-type marker t)
8373 (org-with-remote-undo buffer
8374 (with-current-buffer buffer
8375 (widen)
8376 (goto-char pos)
8377 (setq ts (org-schedule arg time)))
8378 (org-agenda-show-new-time marker ts "S"))
8379 (message "Item scheduled for %s" ts)))
8381 (defun org-agenda-deadline (arg &optional time)
8382 "Schedule the item at point.
8383 ARG is passed through to `org-deadline'."
8384 (interactive "P")
8385 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8386 (org-agenda-check-no-diary)
8387 (let* ((marker (or (org-get-at-bol 'org-marker)
8388 (org-agenda-error)))
8389 (buffer (marker-buffer marker))
8390 (pos (marker-position marker))
8391 (org-insert-labeled-timestamps-at-point nil)
8393 (org-with-remote-undo buffer
8394 (with-current-buffer buffer
8395 (widen)
8396 (goto-char pos)
8397 (setq ts (org-deadline arg time)))
8398 (org-agenda-show-new-time marker ts "D"))
8399 (message "Deadline for this item set to %s" ts)))
8401 (defun org-agenda-clock-in (&optional arg)
8402 "Start the clock on the currently selected item."
8403 (interactive "P")
8404 (org-agenda-check-no-diary)
8405 (if (equal arg '(4))
8406 (org-clock-in arg)
8407 (let* ((marker (or (org-get-at-bol 'org-marker)
8408 (org-agenda-error)))
8409 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8410 marker))
8411 (pos (marker-position marker))
8412 newhead)
8413 (org-with-remote-undo (marker-buffer marker)
8414 (with-current-buffer (marker-buffer marker)
8415 (widen)
8416 (goto-char pos)
8417 (org-show-context 'agenda)
8418 (org-show-entry)
8419 (org-cycle-hide-drawers 'children)
8420 (org-clock-in arg)
8421 (setq newhead (org-get-heading)))
8422 (org-agenda-change-all-lines newhead hdmarker)))))
8424 (defun org-agenda-clock-out ()
8425 "Stop the currently running clock."
8426 (interactive)
8427 (unless (marker-buffer org-clock-marker)
8428 (error "No running clock"))
8429 (let ((marker (make-marker)) newhead)
8430 (org-with-remote-undo (marker-buffer org-clock-marker)
8431 (with-current-buffer (marker-buffer org-clock-marker)
8432 (save-excursion
8433 (save-restriction
8434 (widen)
8435 (goto-char org-clock-marker)
8436 (org-back-to-heading t)
8437 (move-marker marker (point))
8438 (org-clock-out)
8439 (setq newhead (org-get-heading))))))
8440 (org-agenda-change-all-lines newhead marker)
8441 (move-marker marker nil)))
8443 (defun org-agenda-clock-cancel (&optional arg)
8444 "Cancel the currently running clock."
8445 (interactive "P")
8446 (unless (marker-buffer org-clock-marker)
8447 (error "No running clock"))
8448 (org-with-remote-undo (marker-buffer org-clock-marker)
8449 (org-clock-cancel)))
8451 (defun org-agenda-clock-goto ()
8452 "Jump to the currently clocked in task within the agenda.
8453 If the currently clocked in task is not listed in the agenda
8454 buffer, display it in another window."
8455 (interactive)
8456 (let (pos)
8457 (mapc (lambda (o)
8458 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8459 (setq pos (overlay-start o))))
8460 (overlays-in (point-min) (point-max)))
8461 (cond (pos (goto-char pos))
8462 ;; If the currently clocked entry is not in the agenda
8463 ;; buffer, we visit it in another window:
8464 (org-clock-current-task
8465 (org-switch-to-buffer-other-window (org-clock-goto)))
8466 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8468 (defun org-agenda-diary-entry-in-org-file ()
8469 "Make a diary entry in the file `org-agenda-diary-file'."
8470 (let (d1 d2 char (text "") dp1 dp2)
8471 (if (equal (buffer-name) "*Calendar*")
8472 (setq d1 (calendar-cursor-to-date t)
8473 d2 (car calendar-mark-ring))
8474 (setq dp1 (get-text-property (point-at-bol) 'day))
8475 (unless dp1 (error "No date defined in current line"))
8476 (setq d1 (calendar-gregorian-from-absolute dp1)
8477 d2 (and (ignore-errors (mark))
8478 (save-excursion
8479 (goto-char (mark))
8480 (setq dp2 (get-text-property (point-at-bol) 'day)))
8481 (calendar-gregorian-from-absolute dp2))))
8482 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8483 (setq char (read-char-exclusive))
8484 (cond
8485 ((equal char ?d)
8486 (setq text (read-string "Day entry: "))
8487 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8488 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8489 ((equal char ?a)
8490 (setq d1 (list (car d1) (nth 1 d1)
8491 (read-number (format "Reference year [%d]: " (nth 2 d1))
8492 (nth 2 d1))))
8493 (setq text (read-string "Anniversary (use %d to show years): "))
8494 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8495 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8496 ((equal char ?b)
8497 (setq text (read-string "Block entry: "))
8498 (unless (and d1 d2 (not (equal d1 d2)))
8499 (error "No block of days selected"))
8500 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8501 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8502 ((equal char ?j)
8503 (org-switch-to-buffer-other-window
8504 (find-file-noselect org-agenda-diary-file))
8505 (require 'org-datetree)
8506 (org-datetree-find-date-create d1)
8507 (org-reveal t))
8508 (t (error "Invalid selection character `%c'" char)))))
8510 (defcustom org-agenda-insert-diary-strategy 'date-tree
8511 "Where in `org-agenda-diary-file' should new entries be added?
8512 Valid values:
8514 date-tree in the date tree, as child of the date
8515 top-level as top-level entries at the end of the file."
8516 :group 'org-agenda
8517 :type '(choice
8518 (const :tag "in a date tree" date-tree)
8519 (const :tag "as top level at end of file" top-level)))
8521 (defcustom org-agenda-insert-diary-extract-time nil
8522 "Non-nil means extract any time specification from the diary entry."
8523 :group 'org-agenda
8524 :version "24.1"
8525 :type 'boolean)
8527 (defcustom org-agenda-bulk-mark-char ">"
8528 "A single-character string to be used as the bulk mark."
8529 :group 'org-agenda
8530 :version "24.1"
8531 :type 'string)
8533 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8534 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8535 If TEXT is not empty, it will become the headline of the new entry, and
8536 the resulting entry will not be shown. When TEXT is empty, switch to
8537 `org-agenda-diary-file' and let the user finish the entry there."
8538 (let ((cw (current-window-configuration)))
8539 (org-switch-to-buffer-other-window
8540 (find-file-noselect org-agenda-diary-file))
8541 (widen)
8542 (goto-char (point-min))
8543 (cond
8544 ((eq type 'anniversary)
8545 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8546 (progn
8547 (or (org-at-heading-p t)
8548 (progn
8549 (outline-next-heading)
8550 (insert "* Anniversaries\n\n")
8551 (beginning-of-line -1)))))
8552 (outline-next-heading)
8553 (org-back-over-empty-lines)
8554 (backward-char 1)
8555 (insert "\n")
8556 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8557 (nth 2 d1) (car d1) (nth 1 d1) text)))
8558 ((eq type 'day)
8559 (let ((org-prefix-has-time t)
8560 (org-agenda-time-leading-zero t)
8561 fmt time time2)
8562 (if org-agenda-insert-diary-extract-time
8563 ;; Use org-agenda-format-item to parse text for a time-range and
8564 ;; remove it. FIXME: This is a hack, we should refactor
8565 ;; that function to make time extraction available separately
8566 (setq fmt (org-agenda-format-item nil text nil nil t)
8567 time (get-text-property 0 'time fmt)
8568 time2 (if (> (length time) 0)
8569 ;; split-string removes trailing ...... if
8570 ;; no end time given. First space
8571 ;; separates time from date.
8572 (concat " " (car (split-string time "\\.")))
8573 nil)
8574 text (get-text-property 0 'txt fmt)))
8575 (if (eq org-agenda-insert-diary-strategy 'top-level)
8576 (org-agenda-insert-diary-as-top-level text)
8577 (require 'org-datetree)
8578 (org-datetree-find-date-create d1)
8579 (org-agenda-insert-diary-make-new-entry text))
8580 (org-insert-time-stamp (org-time-from-absolute
8581 (calendar-absolute-from-gregorian d1))
8582 nil nil nil nil time2))
8583 (end-of-line 0))
8584 ((eq type 'block)
8585 (if (> (calendar-absolute-from-gregorian d1)
8586 (calendar-absolute-from-gregorian d2))
8587 (setq d1 (prog1 d2 (setq d2 d1))))
8588 (if (eq org-agenda-insert-diary-strategy 'top-level)
8589 (org-agenda-insert-diary-as-top-level text)
8590 (require 'org-datetree)
8591 (org-datetree-find-date-create d1)
8592 (org-agenda-insert-diary-make-new-entry text))
8593 (org-insert-time-stamp (org-time-from-absolute
8594 (calendar-absolute-from-gregorian d1)))
8595 (insert "--")
8596 (org-insert-time-stamp (org-time-from-absolute
8597 (calendar-absolute-from-gregorian d2)))
8598 (end-of-line 0)))
8599 (if (string-match "\\S-" text)
8600 (progn
8601 (set-window-configuration cw)
8602 (message "%s entry added to %s"
8603 (capitalize (symbol-name type))
8604 (abbreviate-file-name org-agenda-diary-file)))
8605 (org-reveal t)
8606 (message "Please finish entry here"))))
8608 (defun org-agenda-insert-diary-as-top-level (text)
8609 "Make new entry as a top-level entry at the end of the file.
8610 Add TEXT as headline, and position the cursor in the second line so that
8611 a timestamp can be added there."
8612 (widen)
8613 (goto-char (point-max))
8614 (or (bolp) (insert "\n"))
8615 (insert "* " text "\n")
8616 (if org-adapt-indentation (org-indent-to-column 2)))
8618 (defun org-agenda-insert-diary-make-new-entry (text)
8619 "Make new entry as last child of current entry.
8620 Add TEXT as headline, and position the cursor in the second line so that
8621 a timestamp can be added there."
8622 (let ((org-show-following-heading t)
8623 (org-show-siblings t)
8624 (org-show-hierarchy-above t)
8625 (org-show-entry-below t)
8626 col)
8627 (outline-next-heading)
8628 (org-back-over-empty-lines)
8629 (or (looking-at "[ \t]*$")
8630 (progn (insert "\n") (backward-char 1)))
8631 (org-insert-heading nil t)
8632 (org-do-demote)
8633 (setq col (current-column))
8634 (insert text "\n")
8635 (if org-adapt-indentation (org-indent-to-column col))
8636 (let ((org-show-following-heading t)
8637 (org-show-siblings t)
8638 (org-show-hierarchy-above t)
8639 (org-show-entry-below t))
8640 (org-show-context))))
8642 (defun org-agenda-diary-entry ()
8643 "Make a diary entry, like the `i' command from the calendar.
8644 All the standard commands work: block, weekly etc.
8645 When `org-agenda-diary-file' points to a file,
8646 `org-agenda-diary-entry-in-org-file' is called instead to create
8647 entries in that Org-mode file."
8648 (interactive)
8649 (org-agenda-check-type t 'agenda 'timeline)
8650 (if (not (eq org-agenda-diary-file 'diary-file))
8651 (org-agenda-diary-entry-in-org-file)
8652 (require 'diary-lib)
8653 (let* ((char (progn
8654 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8655 (read-char-exclusive)))
8656 (cmd (cdr (assoc char
8657 '((?d . insert-diary-entry)
8658 (?w . insert-weekly-diary-entry)
8659 (?m . insert-monthly-diary-entry)
8660 (?y . insert-yearly-diary-entry)
8661 (?a . insert-anniversary-diary-entry)
8662 (?b . insert-block-diary-entry)
8663 (?c . insert-cyclic-diary-entry)))))
8664 (oldf (symbol-function 'calendar-cursor-to-date))
8665 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8666 (point (point))
8667 (mark (or (mark t) (point))))
8668 (unless cmd
8669 (error "No command associated with <%c>" char))
8670 (unless (and (get-text-property point 'day)
8671 (or (not (equal ?b char))
8672 (get-text-property mark 'day)))
8673 (error "Don't know which date to use for diary entry"))
8674 ;; We implement this by hacking the `calendar-cursor-to-date' function
8675 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8676 (let ((calendar-mark-ring
8677 (list (calendar-gregorian-from-absolute
8678 (or (get-text-property mark 'day)
8679 (get-text-property point 'day))))))
8680 (unwind-protect
8681 (progn
8682 (fset 'calendar-cursor-to-date
8683 (lambda (&optional error dummy)
8684 (calendar-gregorian-from-absolute
8685 (get-text-property point 'day))))
8686 (call-interactively cmd))
8687 (fset 'calendar-cursor-to-date oldf))))))
8689 (defun org-agenda-execute-calendar-command (cmd)
8690 "Execute a calendar command from the agenda, with the date associated to
8691 the cursor position."
8692 (org-agenda-check-type t 'agenda 'timeline)
8693 (require 'diary-lib)
8694 (unless (get-text-property (point) 'day)
8695 (error "Don't know which date to use for calendar command"))
8696 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8697 (point (point))
8698 (date (calendar-gregorian-from-absolute
8699 (get-text-property point 'day)))
8700 ;; the following 2 vars are needed in the calendar
8701 (displayed-month (car date))
8702 (displayed-year (nth 2 date)))
8703 (unwind-protect
8704 (progn
8705 (fset 'calendar-cursor-to-date
8706 (lambda (&optional error dummy)
8707 (calendar-gregorian-from-absolute
8708 (get-text-property point 'day))))
8709 (call-interactively cmd))
8710 (fset 'calendar-cursor-to-date oldf))))
8712 (defun org-agenda-phases-of-moon ()
8713 "Display the phases of the moon for the 3 months around the cursor date."
8714 (interactive)
8715 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8717 (defun org-agenda-holidays ()
8718 "Display the holidays for the 3 months around the cursor date."
8719 (interactive)
8720 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8722 (defvar calendar-longitude) ; defined in calendar.el
8723 (defvar calendar-latitude) ; defined in calendar.el
8724 (defvar calendar-location-name) ; defined in calendar.el
8726 (defun org-agenda-sunrise-sunset (arg)
8727 "Display sunrise and sunset for the cursor date.
8728 Latitude and longitude can be specified with the variables
8729 `calendar-latitude' and `calendar-longitude'. When called with prefix
8730 argument, latitude and longitude will be prompted for."
8731 (interactive "P")
8732 (require 'solar)
8733 (let ((calendar-longitude (if arg nil calendar-longitude))
8734 (calendar-latitude (if arg nil calendar-latitude))
8735 (calendar-location-name
8736 (if arg "the given coordinates" calendar-location-name)))
8737 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8739 (defun org-agenda-goto-calendar ()
8740 "Open the Emacs calendar with the date at the cursor."
8741 (interactive)
8742 (org-agenda-check-type t 'agenda 'timeline)
8743 (let* ((day (or (get-text-property (point) 'day)
8744 (error "Don't know which date to open in calendar")))
8745 (date (calendar-gregorian-from-absolute day))
8746 (calendar-move-hook nil)
8747 (calendar-view-holidays-initially-flag nil)
8748 (calendar-view-diary-initially-flag nil))
8749 (calendar)
8750 (calendar-goto-date date)))
8752 ;;;###autoload
8753 (defun org-calendar-goto-agenda ()
8754 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8755 This is a command that has to be installed in `calendar-mode-map'."
8756 (interactive)
8757 (org-agenda-list nil (calendar-absolute-from-gregorian
8758 (calendar-cursor-to-date))
8759 nil))
8761 (defun org-agenda-convert-date ()
8762 (interactive)
8763 (org-agenda-check-type t 'agenda 'timeline)
8764 (let ((day (get-text-property (point) 'day))
8765 date s)
8766 (unless day
8767 (error "Don't know which date to convert"))
8768 (setq date (calendar-gregorian-from-absolute day))
8769 (setq s (concat
8770 "Gregorian: " (calendar-date-string date) "\n"
8771 "ISO: " (calendar-iso-date-string date) "\n"
8772 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8773 "Julian: " (calendar-julian-date-string date) "\n"
8774 "Astron. JD: " (calendar-astro-date-string date)
8775 " (Julian date number at noon UTC)\n"
8776 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8777 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8778 "French: " (calendar-french-date-string date) "\n"
8779 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8780 "Mayan: " (calendar-mayan-date-string date) "\n"
8781 "Coptic: " (calendar-coptic-date-string date) "\n"
8782 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8783 "Persian: " (calendar-persian-date-string date) "\n"
8784 "Chinese: " (calendar-chinese-date-string date) "\n"))
8785 (with-output-to-temp-buffer "*Dates*"
8786 (princ s))
8787 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8789 ;;; Bulk commands
8791 (defun org-agenda-bulk-marked-p ()
8792 (eq (get-char-property (point-at-bol) 'type)
8793 'org-marked-entry-overlay))
8795 (defun org-agenda-bulk-mark (&optional arg)
8796 "Mark the entry at point for future bulk action."
8797 (interactive "p")
8798 (dotimes (i (or arg 1))
8799 (unless (org-get-at-bol 'org-agenda-diary-link)
8800 (let* ((m (org-get-at-bol 'org-hd-marker))
8802 (unless (org-agenda-bulk-marked-p)
8803 (unless m (error "Nothing to mark at point"))
8804 (push m org-agenda-bulk-marked-entries)
8805 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8806 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8807 (org-get-todo-face "TODO")
8808 'evaporate)
8809 (overlay-put ov 'type 'org-marked-entry-overlay))
8810 (beginning-of-line 2)
8811 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8812 (beginning-of-line 2))
8813 (message "%d entries marked for bulk action"
8814 (length org-agenda-bulk-marked-entries))))))
8816 (defun org-agenda-bulk-mark-all ()
8817 "Mark all entries for future agenda bulk action."
8818 (interactive)
8819 (org-agenda-bulk-mark-regexp "."))
8821 (defun org-agenda-bulk-mark-regexp (regexp)
8822 "Mark entries matching REGEXP for future agenda bulk action."
8823 (interactive "sMark entries matching regexp: ")
8824 (let ((entries-marked 0))
8825 (save-excursion
8826 (goto-char (point-min))
8827 (goto-char (next-single-property-change (point) 'txt))
8828 (while (re-search-forward regexp nil t)
8829 (when (string-match regexp (get-text-property (point) 'txt))
8830 (setq entries-marked (1+ entries-marked))
8831 (call-interactively 'org-agenda-bulk-mark))))
8832 (if (not entries-marked)
8833 (message "No entry matching this regexp."))))
8835 (defun org-agenda-bulk-unmark (&optional arg)
8836 "Unmark the entry at point for future bulk action."
8837 (interactive "P")
8838 (if arg
8839 (org-agenda-bulk-unmark-all)
8840 (cond ((org-agenda-bulk-marked-p)
8841 (org-agenda-bulk-remove-overlays
8842 (point-at-bol) (+ 2 (point-at-bol)))
8843 (setq org-agenda-bulk-marked-entries
8844 (delete (org-get-at-bol 'org-hd-marker)
8845 org-agenda-bulk-marked-entries))
8846 (beginning-of-line 2)
8847 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8848 (beginning-of-line 2))
8849 (message "%d entries left marked for bulk action"
8850 (length org-agenda-bulk-marked-entries)))
8851 (t (message "No entry to unmark here")))))
8853 (defun org-agenda-bulk-toggle ()
8854 "Toggle marking the entry at point for bulk action."
8855 (interactive)
8856 (if (org-agenda-bulk-marked-p)
8857 (org-agenda-bulk-unmark)
8858 (org-agenda-bulk-mark)))
8860 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8861 "Remove the mark overlays between BEG and END in the agenda buffer.
8862 BEG and END default to the buffer limits.
8864 This only removes the overlays, it does not remove the markers
8865 from the list in `org-agenda-bulk-marked-entries'."
8866 (interactive)
8867 (mapc (lambda (ov)
8868 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8869 (delete-overlay ov)))
8870 (overlays-in (or beg (point-min)) (or end (point-max)))))
8872 (defun org-agenda-bulk-unmark-all ()
8873 "Remove all marks in the agenda buffer.
8874 This will remove the markers and the overlays."
8875 (interactive)
8876 (if (null org-agenda-bulk-marked-entries)
8877 (message "No entry to unmark")
8878 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8879 (setq org-agenda-bulk-marked-entries nil)
8880 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8882 (defcustom org-agenda-persistent-marks nil
8883 "Non-nil means marked items will stay marked after a bulk action.
8884 You can toggle this interactively by typing `p' when prompted for a
8885 bulk action."
8886 :group 'org-agenda
8887 :version "24.1"
8888 :type 'boolean)
8890 (defun org-agenda-bulk-action (&optional arg)
8891 "Execute an remote-editing action on all marked entries.
8892 The prefix arg is passed through to the command if possible."
8893 (interactive "P")
8894 ;; Make sure we have markers, and only valid ones
8895 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8896 (mapc
8897 (lambda (m)
8898 (unless (and (markerp m)
8899 (marker-buffer m)
8900 (buffer-live-p (marker-buffer m))
8901 (marker-position m))
8902 (error "Marker %s for bulk command is invalid" m)))
8903 org-agenda-bulk-marked-entries)
8905 ;; Prompt for the bulk command
8906 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8907 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
8908 "[S]catter [f]unction "
8909 (when org-agenda-bulk-custom-functions
8910 (concat " Custom: ["
8911 (mapconcat (lambda(f) (char-to-string (car f)))
8912 org-agenda-bulk-custom-functions "")
8913 "]"))))
8914 (catch 'exit
8915 (let* ((action (read-char-exclusive))
8916 (org-log-refile (if org-log-refile 'time nil))
8917 (entries (reverse org-agenda-bulk-marked-entries))
8918 (org-overriding-default-time
8919 (if (get-text-property (point) 'org-agenda-date-header)
8920 (org-get-cursor-date)))
8921 redo-at-end
8922 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8923 (cond
8924 ((equal action ?p)
8925 (let ((org-agenda-persistent-marks
8926 (not org-agenda-persistent-marks)))
8927 (org-agenda-bulk-action)
8928 (throw 'exit nil)))
8930 ((equal action ?$)
8931 (setq cmd '(org-agenda-archive)))
8933 ((equal action ?A)
8934 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8936 ((member action '(?r ?w))
8937 (setq rfloc (org-refile-get-location
8938 "Refile to"
8939 (marker-buffer (car entries))
8940 org-refile-allow-creating-parent-nodes))
8941 (if (nth 3 rfloc)
8942 (setcar (nthcdr 3 rfloc)
8943 (move-marker (make-marker) (nth 3 rfloc)
8944 (or (get-file-buffer (nth 1 rfloc))
8945 (find-buffer-visiting (nth 1 rfloc))
8946 (error "This should not happen")))))
8948 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8949 redo-at-end t))
8951 ((equal action ?t)
8952 (setq state (org-icompleting-read
8953 "Todo state: "
8954 (with-current-buffer (marker-buffer (car entries))
8955 (mapcar 'list org-todo-keywords-1))))
8956 (setq cmd `(let ((org-inhibit-blocking t)
8957 (org-inhibit-logging 'note))
8958 (org-agenda-todo ,state))))
8960 ((memq action '(?- ?+))
8961 (setq tag (org-icompleting-read
8962 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8963 (with-current-buffer (marker-buffer (car entries))
8964 (delq nil
8965 (mapcar (lambda (x)
8966 (if (stringp (car x)) x)) org-tag-alist)))))
8967 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8969 ((memq action '(?s ?d))
8970 (let* ((time
8971 (unless arg
8972 (org-read-date
8973 nil nil nil
8974 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
8975 org-overriding-default-time)))
8976 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8977 (setq cmd `(eval '(,c1 arg ,time)))))
8979 ((equal action ?S)
8980 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8981 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8982 (let ((days (read-number
8983 (format "Scatter tasks across how many %sdays: "
8984 (if arg "week" "")) 7)))
8985 (setq cmd
8986 `(let ((distance (1+ (random ,days))))
8987 (if arg
8988 (let ((dist distance)
8989 (day-of-week
8990 (calendar-day-of-week
8991 (calendar-gregorian-from-absolute (org-today)))))
8992 (dotimes (i (1+ dist))
8993 (while (member day-of-week org-agenda-weekend-days)
8994 (incf distance)
8995 (incf day-of-week)
8996 (if (= day-of-week 7)
8997 (setq day-of-week 0)))
8998 (incf day-of-week)
8999 (if (= day-of-week 7)
9000 (setq day-of-week 0)))))
9001 ;; silently fail when try to replan a sexp entry
9002 (condition-case nil
9003 (let* ((date (calendar-gregorian-from-absolute
9004 (+ (org-today) distance)))
9005 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9006 (nth 2 date))))
9007 (org-agenda-schedule nil time))
9008 (error nil)))))))
9010 ((assoc action org-agenda-bulk-custom-functions)
9011 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9012 redo-at-end t))
9014 ((equal action ?f)
9015 (setq cmd (list (intern
9016 (org-icompleting-read "Function: "
9017 obarray 'fboundp t nil nil)))))
9019 (t (error "Invalid bulk action")))
9021 ;; Sort the markers, to make sure that parents are handled before children
9022 (setq entries (sort entries
9023 (lambda (a b)
9024 (cond
9025 ((equal (marker-buffer a) (marker-buffer b))
9026 (< (marker-position a) (marker-position b)))
9028 (string< (buffer-name (marker-buffer a))
9029 (buffer-name (marker-buffer b))))))))
9031 ;; Now loop over all markers and apply cmd
9032 (while (setq e (pop entries))
9033 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9034 (if (not pos)
9035 (progn (message "Skipping removed entry at %s" e)
9036 (setq cntskip (1+ cntskip)))
9037 (goto-char pos)
9038 (let (org-loop-over-headlines-in-active-region)
9039 (eval cmd))
9040 (setq cnt (1+ cnt))))
9041 (when redo-at-end (org-agenda-redo))
9042 (unless org-agenda-persistent-marks
9043 (org-agenda-bulk-unmark-all))
9044 (message "Acted on %d entries%s%s"
9046 (if (= cntskip 0)
9048 (format ", skipped %d (disappeared before their turn)"
9049 cntskip))
9050 (if (not org-agenda-persistent-marks)
9051 "" " (kept marked)"))))))
9053 (defun org-agenda-capture ()
9054 "Call `org-capture' with the date at point."
9055 (interactive)
9056 (if (not (eq major-mode 'org-agenda-mode))
9057 (error "You cannot do this outside of agenda buffers")
9058 (let ((org-overriding-default-time
9059 (org-get-cursor-date)))
9060 (call-interactively 'org-capture))))
9062 ;;; Flagging notes
9064 (defun org-agenda-show-the-flagging-note ()
9065 "Display the flagging note in the other window.
9066 When called a second time in direct sequence, offer to remove the FLAGGING
9067 tag and (if present) the flagging note."
9068 (interactive)
9069 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9070 (win (selected-window))
9071 note heading newhead)
9072 (unless hdmarker
9073 (error "No linked entry at point"))
9074 (if (and (eq this-command last-command)
9075 (y-or-n-p "Unflag and remove any flagging note? "))
9076 (progn
9077 (org-agenda-remove-flag hdmarker)
9078 (let ((win (get-buffer-window "*Flagging Note*")))
9079 (and win (delete-window win)))
9080 (message "Entry unflagged"))
9081 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9082 (unless note
9083 (error "No flagging note"))
9084 (org-kill-new note)
9085 (org-switch-to-buffer-other-window "*Flagging Note*")
9086 (erase-buffer)
9087 (insert note)
9088 (goto-char (point-min))
9089 (while (re-search-forward "\\\\n" nil t)
9090 (replace-match "\n" t t))
9091 (goto-char (point-min))
9092 (select-window win)
9093 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9095 (defun org-agenda-remove-flag (marker)
9096 "Remove the FLAGGED tag and any flagging note in the entry."
9097 (let (newhead)
9098 (org-with-point-at marker
9099 (org-toggle-tag "FLAGGED" 'off)
9100 (org-entry-delete nil "THEFLAGGINGNOTE")
9101 (setq newhead (org-get-heading)))
9102 (org-agenda-change-all-lines newhead marker)
9103 (message "Entry unflagged")))
9105 (defun org-agenda-get-any-marker (&optional pos)
9106 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9107 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9109 ;;; Appointment reminders
9111 (defvar appt-time-msg-list) ; defined in appt.el
9113 ;;;###autoload
9114 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9115 "Activate appointments found in `org-agenda-files'.
9116 With a \\[universal-argument] prefix, refresh the list of
9117 appointments.
9119 If FILTER is t, interactively prompt the user for a regular
9120 expression, and filter out entries that don't match it.
9122 If FILTER is a string, use this string as a regular expression
9123 for filtering entries out.
9125 If FILTER is a function, filter out entries against which
9126 calling the function returns nil. This function takes one
9127 argument: an entry from `org-agenda-get-day-entries'.
9129 FILTER can also be an alist with the car of each cell being
9130 either 'headline or 'category. For example:
9132 '((headline \"IMPORTANT\")
9133 (category \"Work\"))
9135 will only add headlines containing IMPORTANT or headlines
9136 belonging to the \"Work\" category.
9138 ARGS are symbols indicating what kind of entries to consider.
9139 By default `org-agenda-to-appt' will use :deadline, :scheduled
9140 and :timestamp entries. See the docstring of `org-diary' for
9141 details and examples.
9143 If an entry as a APPT_WARNTIME property, its value will be used
9144 to override `appt-message-warning-time'."
9145 (interactive "P")
9146 (if refresh (setq appt-time-msg-list nil))
9147 (if (eq filter t)
9148 (setq filter (read-from-minibuffer "Regexp filter: ")))
9149 (let* ((cnt 0) ; count added events
9150 (scope (or args '(:deadline :scheduled :timestamp)))
9151 (org-agenda-new-buffers nil)
9152 (org-deadline-warning-days 0)
9153 ;; Do not use `org-today' here because appt only takes
9154 ;; time and without date as argument, so it may pass wrong
9155 ;; information otherwise
9156 (today (org-date-to-gregorian
9157 (time-to-days (current-time))))
9158 (org-agenda-restrict nil)
9159 (files (org-agenda-files 'unrestricted)) entries file
9160 (org-agenda-buffer nil))
9161 ;; Get all entries which may contain an appt
9162 (org-agenda-prepare-buffers files)
9163 (while (setq file (pop files))
9164 (setq entries
9165 (delq nil
9166 (append entries
9167 (apply 'org-agenda-get-day-entries
9168 file today scope)))))
9169 ;; Map thru entries and find if we should filter them out
9170 (mapc
9171 (lambda(x)
9172 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9173 (cat (get-text-property 1 'org-category x))
9174 (tod (get-text-property 1 'time-of-day x))
9175 (ok (or (null filter)
9176 (and (stringp filter) (string-match filter evt))
9177 (and (functionp filter) (funcall filter x))
9178 (and (listp filter)
9179 (let ((cat-filter (cadr (assoc 'category filter)))
9180 (evt-filter (cadr (assoc 'headline filter))))
9181 (or (and (stringp cat-filter)
9182 (string-match cat-filter cat))
9183 (and (stringp evt-filter)
9184 (string-match evt-filter evt)))))))
9185 (wrn (get-text-property 1 'warntime x)))
9186 ;; FIXME: Shall we remove text-properties for the appt text?
9187 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9188 (when (and ok tod)
9189 (setq tod (concat "00" (number-to-string tod))
9190 tod (when (string-match
9191 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9192 (concat (match-string 1 tod) ":"
9193 (match-string 2 tod))))
9194 (if (version< emacs-version "23.3")
9195 (appt-add tod evt)
9196 (appt-add tod evt wrn))
9197 (setq cnt (1+ cnt))))) entries)
9198 (org-release-buffers org-agenda-new-buffers)
9199 (if (eq cnt 0)
9200 (message "No event to add")
9201 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9203 (defun org-agenda-todayp (date)
9204 "Does DATE mean today, when considering `org-extend-today-until'?"
9205 (let ((today (org-today))
9206 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9207 date)))
9208 (eq date today)))
9210 (defun org-agenda-todo-yesterday (&optional arg)
9211 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9212 (interactive "P")
9213 (let* ((hour (third (decode-time
9214 (org-current-time))))
9215 (org-extend-today-until (1+ hour)))
9216 (org-agenda-todo arg)))
9218 (provide 'org-agenda)
9220 ;;; org-agenda.el ends here