org-jsinfo.el (org-infojs-template): Fix copyright years
[org-mode/org-tableheadings.git] / lisp / org-agenda.el
blobd74444c5a8e747e414b2cf515457408acd0ff128
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-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 "Always 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 nil
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 :version "24.3"
861 :type '(choice
862 (const :tag "Do not dim" nil)
863 (const :tag "Dim to a gray face" t)
864 (const :tag "Make invisible" invisible)))
866 (defcustom org-timeline-show-empty-dates 3
867 "Non-nil means `org-timeline' also shows dates without an entry.
868 When nil, only the days which actually have entries are shown.
869 When t, all days between the first and the last date are shown.
870 When an integer, show also empty dates, but if there is a gap of more than
871 N days, just insert a special line indicating the size of the gap."
872 :group 'org-agenda-skip
873 :type '(choice
874 (const :tag "None" nil)
875 (const :tag "All" t)
876 (integer :tag "at most")))
878 (defgroup org-agenda-startup nil
879 "Options concerning initial settings in the Agenda in Org Mode."
880 :tag "Org Agenda Startup"
881 :group 'org-agenda)
883 (defcustom org-agenda-menu-show-matcher t
884 "Non-nil means show the match string in the agenda dispatcher menu.
885 When nil, the matcher string is not shown, but is put into the help-echo
886 property so than moving the mouse over the command shows it.
887 Setting it to nil is good if matcher strings are very long and/or if
888 you want to use two-columns display (see `org-agenda-menu-two-columns')."
889 :group 'org-agenda
890 :version "24.1"
891 :type 'boolean)
893 (org-define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
895 (defcustom org-agenda-menu-two-columns nil
896 "Non-nil means, use two columns to show custom commands in the dispatcher.
897 If you use this, you probably want to set `org-agenda-menu-show-matcher'
898 to nil."
899 :group 'org-agenda
900 :version "24.1"
901 :type 'boolean)
903 (org-define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
904 (defcustom org-agenda-finalize-hook nil
905 "Hook run just before displaying an agenda buffer.
906 The buffer is still writable when the hook is called.
908 You can modify some of the buffer substrings but you should be
909 extra careful not to modify the text properties of the agenda
910 headlines as the agenda display heavily relies on them."
911 :group 'org-agenda-startup
912 :type 'hook)
914 (defcustom org-agenda-mouse-1-follows-link nil
915 "Non-nil means mouse-1 on a link will follow the link in the agenda.
916 A longer mouse click will still set point. Does not work on XEmacs.
917 Needs to be set before org.el is loaded."
918 :group 'org-agenda-startup
919 :type 'boolean)
921 (defcustom org-agenda-start-with-follow-mode nil
922 "The initial value of follow mode in a newly created agenda window."
923 :group 'org-agenda-startup
924 :type 'boolean)
926 (defcustom org-agenda-follow-indirect nil
927 "Non-nil means `org-agenda-follow-mode' displays only the
928 current item's tree, in an indirect buffer."
929 :group 'org-agenda
930 :version "24.1"
931 :type 'boolean)
933 (defcustom org-agenda-show-outline-path t
934 "Non-nil means show outline path in echo area after line motion."
935 :group 'org-agenda-startup
936 :type 'boolean)
938 (defcustom org-agenda-start-with-entry-text-mode nil
939 "The initial value of entry-text-mode in a newly created agenda window."
940 :group 'org-agenda-startup
941 :type 'boolean)
943 (defcustom org-agenda-entry-text-maxlines 5
944 "Number of text lines to be added when `E' is pressed in the agenda.
946 Note that this variable only used during agenda display. Add add entry text
947 when exporting the agenda, configure the variable
948 `org-agenda-add-entry-ext-maxlines'."
949 :group 'org-agenda
950 :type 'integer)
952 (defcustom org-agenda-entry-text-exclude-regexps nil
953 "List of regular expressions to clean up entry text.
954 The complete matches of all regular expressions in this list will be
955 removed from entry text before it is shown in the agenda."
956 :group 'org-agenda
957 :type '(repeat (regexp)))
959 (defvar org-agenda-entry-text-cleanup-hook nil
960 "Hook that is run after basic cleanup of entry text to be shown in agenda.
961 This cleanup is done in a temporary buffer, so the function may inspect and
962 change the entire buffer.
963 Some default stuff like drawers and scheduling/deadline dates will already
964 have been removed when this is called, as will any matches for regular
965 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
967 (defvar org-agenda-include-inactive-timestamps nil
968 "Non-nil means include inactive time stamps in agenda and timeline.
969 Dynamically scoped.")
971 (defgroup org-agenda-windows nil
972 "Options concerning the windows used by the Agenda in Org Mode."
973 :tag "Org Agenda Windows"
974 :group 'org-agenda)
976 (defcustom org-agenda-window-setup 'reorganize-frame
977 "How the agenda buffer should be displayed.
978 Possible values for this option are:
980 current-window Show agenda in the current window, keeping all other windows.
981 other-window Use `switch-to-buffer-other-window' to display agenda.
982 reorganize-frame Show only two windows on the current frame, the current
983 window and the agenda.
984 other-frame Use `switch-to-buffer-other-frame' to display agenda.
985 Also, when exiting the agenda, kill that frame.
986 See also the variable `org-agenda-restore-windows-after-quit'."
987 :group 'org-agenda-windows
988 :type '(choice
989 (const current-window)
990 (const other-frame)
991 (const other-window)
992 (const reorganize-frame)))
994 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
995 "The min and max height of the agenda window as a fraction of frame height.
996 The value of the variable is a cons cell with two numbers between 0 and 1.
997 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
998 :group 'org-agenda-windows
999 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1001 (defcustom org-agenda-restore-windows-after-quit nil
1002 "Non-nil means restore window configuration upon exiting agenda.
1003 Before the window configuration is changed for displaying the agenda,
1004 the current status is recorded. When the agenda is exited with
1005 `q' or `x' and this option is set, the old state is restored. If
1006 `org-agenda-window-setup' is `other-frame', the value of this
1007 option will be ignored."
1008 :group 'org-agenda-windows
1009 :type 'boolean)
1011 (defcustom org-agenda-ndays nil
1012 "Number of days to include in overview display.
1013 Should be 1 or 7.
1014 Obsolete, see `org-agenda-span'."
1015 :group 'org-agenda-daily/weekly
1016 :type 'integer)
1018 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1020 (defcustom org-agenda-span 'week
1021 "Number of days to include in overview display.
1022 Can be day, week, month, year, or any number of days.
1023 Custom commands can set this variable in the options section."
1024 :group 'org-agenda-daily/weekly
1025 :type '(choice (const :tag "Day" day)
1026 (const :tag "Week" week)
1027 (const :tag "Month" month)
1028 (const :tag "Year" year)
1029 (integer :tag "Custom")))
1031 (defcustom org-agenda-start-on-weekday 1
1032 "Non-nil means start the overview always on the specified weekday.
1033 0 denotes Sunday, 1 denotes Monday etc.
1034 When nil, always start on the current day.
1035 Custom commands can set this variable in the options section."
1036 :group 'org-agenda-daily/weekly
1037 :type '(choice (const :tag "Today" nil)
1038 (integer :tag "Weekday No.")))
1040 (defcustom org-agenda-show-all-dates t
1041 "Non-nil means `org-agenda' shows every day in the selected range.
1042 When nil, only the days which actually have entries are shown."
1043 :group 'org-agenda-daily/weekly
1044 :type 'boolean)
1046 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1047 "Format string for displaying dates in the agenda.
1048 Used by the daily/weekly agenda and by the timeline. This should be
1049 a format string understood by `format-time-string', or a function returning
1050 the formatted date as a string. The function must take a single argument,
1051 a calendar-style date list like (month day year)."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice
1054 (string :tag "Format string")
1055 (function :tag "Function")))
1057 (defun org-agenda-format-date-aligned (date)
1058 "Format a date string for display in the daily/weekly agenda, or timeline.
1059 This function makes sure that dates are aligned for easy reading."
1060 (require 'cal-iso)
1061 (let* ((dayname (calendar-day-name date))
1062 (day (cadr date))
1063 (day-of-week (calendar-day-of-week date))
1064 (month (car date))
1065 (monthname (calendar-month-name month))
1066 (year (nth 2 date))
1067 (iso-week (org-days-to-iso-week
1068 (calendar-absolute-from-gregorian date)))
1069 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1070 (1- year))
1071 ((and (= month 12) (<= iso-week 1))
1072 (1+ year))
1073 (t year)))
1074 (weekstring (if (= day-of-week 1)
1075 (format " W%02d" iso-week)
1076 "")))
1077 (format "%-10s %2d %s %4d%s"
1078 dayname day monthname year weekstring)))
1080 (defcustom org-agenda-time-leading-zero nil
1081 "Non-nil means use leading zero for military times in agenda.
1082 For example, 9:30am would become 09:30 rather than 9:30."
1083 :group 'org-agenda-daily/weekly
1084 :version "24.1"
1085 :type 'boolean)
1087 (defcustom org-agenda-timegrid-use-ampm nil
1088 "When set, show AM/PM style timestamps on the timegrid."
1089 :group 'org-agenda
1090 :version "24.1"
1091 :type 'boolean)
1093 (defun org-agenda-time-of-day-to-ampm (time)
1094 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1095 (let* ((hour-number (string-to-number (substring time 0 -3)))
1096 (minute (substring time -2))
1097 (ampm "am"))
1098 (cond
1099 ((equal hour-number 12)
1100 (setq ampm "pm"))
1101 ((> hour-number 12)
1102 (setq ampm "pm")
1103 (setq hour-number (- hour-number 12))))
1104 (concat
1105 (if org-agenda-time-leading-zero
1106 (format "%02d" hour-number)
1107 (format "%02s" (number-to-string hour-number)))
1108 ":" minute ampm)))
1110 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1111 "Conditionally convert TIME to AM/PM format
1112 based on `org-agenda-timegrid-use-ampm'"
1113 (if org-agenda-timegrid-use-ampm
1114 (org-agenda-time-of-day-to-ampm time)
1115 time))
1117 (defcustom org-agenda-weekend-days '(6 0)
1118 "Which days are weekend?
1119 These days get the special face `org-agenda-date-weekend' in the agenda
1120 and timeline buffers."
1121 :group 'org-agenda-daily/weekly
1122 :type '(set :greedy t
1123 (const :tag "Monday" 1)
1124 (const :tag "Tuesday" 2)
1125 (const :tag "Wednesday" 3)
1126 (const :tag "Thursday" 4)
1127 (const :tag "Friday" 5)
1128 (const :tag "Saturday" 6)
1129 (const :tag "Sunday" 0)))
1131 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1132 "Non-nil means jump to today when moving a past date forward in time.
1133 When using S-right in the agenda to move a a date forward, and the date
1134 stamp currently points to the past, the first key press will move it
1135 to today. WHen nil, just move one day forward even if the date stays
1136 in the past."
1137 :group 'org-agenda-daily/weekly
1138 :version "24.1"
1139 :type 'boolean)
1141 (defcustom org-agenda-include-diary nil
1142 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1143 Custom commands can set this variable in the options section."
1144 :group 'org-agenda-daily/weekly
1145 :type 'boolean)
1147 (defcustom org-agenda-include-deadlines t
1148 "If non-nil, include entries within their deadline warning period.
1149 Custom commands can set this variable in the options section."
1150 :group 'org-agenda-daily/weekly
1151 :version "24.1"
1152 :type 'boolean)
1154 (defcustom org-agenda-repeating-timestamp-show-all t
1155 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1156 When set to a list of strings, only show occurrences of repeating
1157 stamps for these TODO keywords. When nil, only one occurrence is
1158 shown, either today or the nearest into the future."
1159 :group 'org-agenda-daily/weekly
1160 :type '(choice
1161 (const :tag "Show repeating stamps" t)
1162 (repeat :tag "Show repeating stamps for these TODO keywords"
1163 (string :tag "TODO Keyword"))
1164 (const :tag "Don't show repeating stamps" nil)))
1166 (defcustom org-scheduled-past-days 10000
1167 "No. of days to continue listing scheduled items that are not marked DONE.
1168 When an item is scheduled on a date, it shows up in the agenda on this
1169 day and will be listed until it is marked done for the number of days
1170 given here."
1171 :group 'org-agenda-daily/weekly
1172 :type 'integer)
1174 (defcustom org-agenda-log-mode-items '(closed clock)
1175 "List of items that should be shown in agenda log mode.
1176 This list may contain the following symbols:
1178 closed Show entries that have been closed on that day.
1179 clock Show entries that have received clocked time on that day.
1180 state Show all logged state changes.
1181 Note that instead of changing this variable, you can also press `C-u l' in
1182 the agenda to display all available LOG items temporarily."
1183 :group 'org-agenda-daily/weekly
1184 :type '(set :greedy t (const closed) (const clock) (const state)))
1186 (defcustom org-agenda-clock-consistency-checks
1187 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1188 :gap-ok-around ("4:00")
1189 :default-face ((:background "DarkRed") (:foreground "white"))
1190 :overlap-face nil :gap-face nil :no-end-time-face nil
1191 :long-face nil :short-face nil)
1192 "This is a property list, with the following keys:
1194 :max-duration Mark clocking chunks that are longer than this time.
1195 This is a time string like \"HH:MM\", or the number
1196 of minutes as an integer.
1198 :min-duration Mark clocking chunks that are shorter that this.
1199 This is a time string like \"HH:MM\", or the number
1200 of minutes as an integer.
1202 :max-gap Mark gaps between clocking chunks that are longer than
1203 this duration. A number of minutes, or a string
1204 like \"HH:MM\".
1206 :gap-ok-around List of times during the day which are usually not working
1207 times. When a gap is detected, but the gap contains any
1208 of these times, the gap is *not* reported. For example,
1209 if this is (\"4:00\" \"13:00\") then gaps that contain
1210 4:00 in the morning (i.e. the night) and 13:00
1211 (i.e. a typical lunch time) do not cause a warning.
1212 You should have at least one time during the night in this
1213 list, or otherwise the first task each morning will trigger
1214 a warning because it follows a long gap.
1216 Furthermore, the following properties can be used to define faces for
1217 issue display.
1219 :default-face the default face, if the specific face is undefined
1220 :overlap-face face for overlapping clocks
1221 :gap-face face for gaps between clocks
1222 :no-end-time-face face for incomplete clocks
1223 :long-face face for clock intervals that are too long
1224 :short-face face for clock intervals that are too short"
1225 :group 'org-agenda-daily/weekly
1226 :group 'org-clock
1227 :version "24.1"
1228 :type 'plist)
1230 (defcustom org-agenda-log-mode-add-notes t
1231 "Non-nil means add first line of notes to log entries in agenda views.
1232 If a log item like a state change or a clock entry is associated with
1233 notes, the first line of these notes will be added to the entry in the
1234 agenda display."
1235 :group 'org-agenda-daily/weekly
1236 :type 'boolean)
1238 (defcustom org-agenda-start-with-log-mode nil
1239 "The initial value of log-mode in a newly created agenda window.
1240 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1241 explanations on the possible values."
1242 :group 'org-agenda-startup
1243 :group 'org-agenda-daily/weekly
1244 :type '(choice (const :tag "Don't show log items" nil)
1245 (const :tag "Show only log items" 'only)
1246 (const :tag "Show all possible log items" 'clockcheck)
1247 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1248 (choice (const :tag "Show closed log items" 'closed)
1249 (const :tag "Show clocked log items" 'clock)
1250 (const :tag "Show all logged state changes" 'state)))))
1252 (defcustom org-agenda-start-with-clockreport-mode nil
1253 "The initial value of clockreport-mode in a newly created agenda window."
1254 :group 'org-agenda-startup
1255 :group 'org-agenda-daily/weekly
1256 :type 'boolean)
1258 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1259 "Property list with parameters for the clocktable in clockreport mode.
1260 This is the display mode that shows a clock table in the daily/weekly
1261 agenda, the properties for this dynamic block can be set here.
1262 The usual clocktable parameters are allowed here, but you cannot set
1263 the properties :name, :tstart, :tend, :block, and :scope - these will
1264 be overwritten to make sure the content accurately reflects the
1265 current display in the agenda."
1266 :group 'org-agenda-daily/weekly
1267 :type 'plist)
1269 (defcustom org-agenda-search-view-always-boolean nil
1270 "Non-nil means the search string is interpreted as individual parts.
1272 The search string for search view can either be interpreted as a phrase,
1273 or as a list of snippets that define a boolean search for a number of
1274 strings.
1276 When this is non-nil, the string will be split on whitespace, and each
1277 snippet will be searched individually, and all must match in order to
1278 select an entry. A snippet is then a single string of non-white
1279 characters, or a string in double quotes, or a regexp in {} braces.
1280 If a snippet is preceded by \"-\", the snippet must *not* match.
1281 \"+\" is syntactic sugar for positive selection. Each snippet may
1282 be found as a full word or a partial word, but see the variable
1283 `org-agenda-search-view-force-full-words'.
1285 When this is nil, search will look for the entire search phrase as one,
1286 with each space character matching any amount of whitespace, including
1287 line breaks.
1289 Even when this is nil, you can still switch to Boolean search dynamically
1290 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1291 is a regexp marked with braces like \"{abc}\", this will also switch to
1292 boolean search."
1293 :group 'org-agenda-search-view
1294 :version "24.1"
1295 :type 'boolean)
1297 (if (fboundp 'defvaralias)
1298 (defvaralias 'org-agenda-search-view-search-words-only
1299 'org-agenda-search-view-always-boolean))
1301 (defcustom org-agenda-search-view-force-full-words nil
1302 "Non-nil means, search words must be matches as complete words.
1303 When nil, they may also match part of a word."
1304 :group 'org-agenda-search-view
1305 :version "24.1"
1306 :type 'boolean)
1308 (defgroup org-agenda-time-grid nil
1309 "Options concerning the time grid in the Org-mode Agenda."
1310 :tag "Org Agenda Time Grid"
1311 :group 'org-agenda)
1313 (defcustom org-agenda-search-headline-for-time t
1314 "Non-nil means search headline for a time-of-day.
1315 If the headline contains a time-of-day in one format or another, it will
1316 be used to sort the entry into the time sequence of items for a day.
1317 Some people have time stamps in the headline that refer to the creation
1318 time or so, and then this produces an unwanted side effect. If this is
1319 the case for your, use this variable to turn off searching the headline
1320 for a time."
1321 :group 'org-agenda-time-grid
1322 :type 'boolean)
1324 (defcustom org-agenda-use-time-grid t
1325 "Non-nil means show a time grid in the agenda schedule.
1326 A time grid is a set of lines for specific times (like every two hours between
1327 8:00 and 20:00). The items scheduled for a day at specific times are
1328 sorted in between these lines.
1329 For details about when the grid will be shown, and what it will look like, see
1330 the variable `org-agenda-time-grid'."
1331 :group 'org-agenda-time-grid
1332 :type 'boolean)
1334 (defcustom org-agenda-time-grid
1335 '((daily today require-timed)
1336 "----------------"
1337 (800 1000 1200 1400 1600 1800 2000))
1339 "The settings for time grid for agenda display.
1340 This is a list of three items. The first item is again a list. It contains
1341 symbols specifying conditions when the grid should be displayed:
1343 daily if the agenda shows a single day
1344 weekly if the agenda shows an entire week
1345 today show grid on current date, independent of daily/weekly display
1346 require-timed show grid only if at least one item has a time specification
1348 The second item is a string which will be placed behind the grid time.
1350 The third item is a list of integers, indicating the times that should have
1351 a grid line."
1352 :group 'org-agenda-time-grid
1353 :type
1354 '(list
1355 (set :greedy t :tag "Grid Display Options"
1356 (const :tag "Show grid in single day agenda display" daily)
1357 (const :tag "Show grid in weekly agenda display" weekly)
1358 (const :tag "Always show grid for today" today)
1359 (const :tag "Show grid only if any timed entries are present"
1360 require-timed)
1361 (const :tag "Skip grid times already present in an entry"
1362 remove-match))
1363 (string :tag "Grid String")
1364 (repeat :tag "Grid Times" (integer :tag "Time"))))
1366 (defcustom org-agenda-show-current-time-in-grid t
1367 "Non-nil means show the current time in the time grid."
1368 :group 'org-agenda-time-grid
1369 :version "24.1"
1370 :type 'boolean)
1372 (defcustom org-agenda-current-time-string
1373 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1374 "The string for the current time marker in the agenda."
1375 :group 'org-agenda-time-grid
1376 :version "24.1"
1377 :type 'string)
1379 (defgroup org-agenda-sorting nil
1380 "Options concerning sorting in the Org-mode Agenda."
1381 :tag "Org Agenda Sorting"
1382 :group 'org-agenda)
1384 (defcustom org-agenda-sorting-strategy
1385 '((agenda habit-down time-up priority-down category-keep)
1386 (todo priority-down category-keep)
1387 (tags priority-down category-keep)
1388 (search category-keep))
1389 "Sorting structure for the agenda items of a single day.
1390 This is a list of symbols which will be used in sequence to determine
1391 if an entry should be listed before another entry. The following
1392 symbols are recognized:
1394 time-up Put entries with time-of-day indications first, early first
1395 time-down Put entries with time-of-day indications first, late first
1396 category-keep Keep the default order of categories, corresponding to the
1397 sequence in `org-agenda-files'.
1398 category-up Sort alphabetically by category, A-Z.
1399 category-down Sort alphabetically by category, Z-A.
1400 tag-up Sort alphabetically by last tag, A-Z.
1401 tag-down Sort alphabetically by last tag, Z-A.
1402 priority-up Sort numerically by priority, high priority last.
1403 priority-down Sort numerically by priority, high priority first.
1404 todo-state-up Sort by todo state, tasks that are done last.
1405 todo-state-down Sort by todo state, tasks that are done first.
1406 effort-up Sort numerically by estimated effort, high effort last.
1407 effort-down Sort numerically by estimated effort, high effort first.
1408 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1409 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1410 habit-up Put entries that are habits first
1411 habit-down Put entries that are habits last
1412 alpha-up Sort headlines alphabetically
1413 alpha-down Sort headlines alphabetically, reversed
1415 The different possibilities will be tried in sequence, and testing stops
1416 if one comparison returns a \"not-equal\". For example, the default
1417 '(time-up category-keep priority-down)
1418 means: Pull out all entries having a specified time of day and sort them,
1419 in order to make a time schedule for the current day the first thing in the
1420 agenda listing for the day. Of the entries without a time indication, keep
1421 the grouped in categories, don't sort the categories, but keep them in
1422 the sequence given in `org-agenda-files'. Within each category sort by
1423 priority.
1425 Leaving out `category-keep' would mean that items will be sorted across
1426 categories by priority.
1428 Instead of a single list, this can also be a set of list for specific
1429 contents, with a context symbol in the car of the list, any of
1430 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1432 Custom commands can bind this variable in the options section."
1433 :group 'org-agenda-sorting
1434 :type `(choice
1435 (repeat :tag "General" ,org-sorting-choice)
1436 (list :tag "Individually"
1437 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1438 (repeat ,org-sorting-choice))
1439 (cons (const :tag "Strategy for TODO lists" todo)
1440 (repeat ,org-sorting-choice))
1441 (cons (const :tag "Strategy for Tags matches" tags)
1442 (repeat ,org-sorting-choice))
1443 (cons (const :tag "Strategy for search matches" search)
1444 (repeat ,org-sorting-choice)))))
1446 (defcustom org-agenda-cmp-user-defined nil
1447 "A function to define the comparison `user-defined'.
1448 This function must receive two arguments, agenda entry a and b.
1449 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1450 the user comparison, return nil.
1451 When this is defined, you can make `user-defined-up' and `user-defined-down'
1452 part of an agenda sorting strategy."
1453 :group 'org-agenda-sorting
1454 :type 'symbol)
1456 (defcustom org-sort-agenda-notime-is-late t
1457 "Non-nil means items without time are considered late.
1458 This is only relevant for sorting. When t, items which have no explicit
1459 time like 15:30 will be considered as 99:01, i.e. later than any items which
1460 do have a time. When nil, the default time is before 0:00. You can use this
1461 option to decide if the schedule for today should come before or after timeless
1462 agenda entries."
1463 :group 'org-agenda-sorting
1464 :type 'boolean)
1466 (defcustom org-sort-agenda-noeffort-is-high t
1467 "Non-nil means items without effort estimate are sorted as high effort.
1468 This also applies when filtering an agenda view with respect to the
1469 < or > effort operator. Then, tasks with no effort defined will be treated
1470 as tasks with high effort.
1471 When nil, such items are sorted as 0 minutes effort."
1472 :group 'org-agenda-sorting
1473 :type 'boolean)
1475 (defgroup org-agenda-line-format nil
1476 "Options concerning the entry prefix in the Org-mode agenda display."
1477 :tag "Org Agenda Line Format"
1478 :group 'org-agenda)
1480 (defcustom org-agenda-prefix-format
1481 '((agenda . " %i %-12:c%?-12t% s")
1482 (timeline . " % s")
1483 (todo . " %i %-12:c")
1484 (tags . " %i %-12:c")
1485 (search . " %i %-12:c"))
1486 "Format specifications for the prefix of items in the agenda views.
1487 An alist with five entries, each for the different agenda types. The
1488 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1489 The values are format strings.
1491 This format works similar to a printf format, with the following meaning:
1493 %c the category of the item, \"Diary\" for entries from the diary,
1494 or as given by the CATEGORY keyword or derived from the file name
1495 %e the effort required by the item
1496 %i the icon category of the item, see `org-agenda-category-icon-alist'
1497 %T the last tag of the item (ignore inherited tags, which come first)
1498 %t the HH:MM time-of-day specification if one applies to the entry
1499 %s Scheduling/Deadline information, a short string
1500 %(expression) Eval EXPRESSION and replace the control string
1501 by the result
1503 All specifiers work basically like the standard `%s' of printf, but may
1504 contain two additional characters: a question mark just after the `%'
1505 and a whitespace/punctuation character just before the final letter.
1507 If the first character after `%' is a question mark, the entire field
1508 will only be included if the corresponding value applies to the current
1509 entry. This is useful for fields which should have fixed width when
1510 present, but zero width when absent. For example, \"%?-12t\" will
1511 result in a 12 character time field if a time of the day is specified,
1512 but will completely disappear in entries which do not contain a time.
1514 If there is punctuation or whitespace character just before the final
1515 format letter, this character will be appended to the field value if
1516 the value is not empty. For example, the format \"%-12:c\" leads to
1517 \"Diary: \" if the category is \"Diary\". If the category were be
1518 empty, no additional colon would be inserted.
1520 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1521 which means:
1523 - Indent the line with two space characters
1524 - Give the category a 12 chars wide field, padded with whitespace on
1525 the right (because of `-'). Append a colon if there is a category
1526 (because of `:').
1527 - If there is a time-of-day, put it into a 12 chars wide field. If no
1528 time, don't put in an empty field, just skip it (because of '?').
1529 - Finally, put the scheduling information.
1531 See also the variables `org-agenda-remove-times-when-in-prefix' and
1532 `org-agenda-remove-tags'.
1534 Custom commands can set this variable in the options section."
1535 :type '(choice
1536 (string :tag "General format")
1537 (list :greedy t :tag "View dependent"
1538 (cons (const agenda) (string :tag "Format"))
1539 (cons (const timeline) (string :tag "Format"))
1540 (cons (const todo) (string :tag "Format"))
1541 (cons (const tags) (string :tag "Format"))
1542 (cons (const search) (string :tag "Format"))))
1543 :group 'org-agenda-line-format)
1545 (defvar org-prefix-format-compiled nil
1546 "The compiled prefix format and associated variables.
1547 This is a list where first element is a list of variable bindings, and second
1548 element is the compiled format expression. See the variable
1549 `org-agenda-prefix-format'.")
1551 (defcustom org-agenda-todo-keyword-format "%-1s"
1552 "Format for the TODO keyword in agenda lines.
1553 Set this to something like \"%-12s\" if you want all TODO keywords
1554 to occupy a fixed space in the agenda display."
1555 :group 'org-agenda-line-format
1556 :type 'string)
1558 (defcustom org-agenda-diary-sexp-prefix nil
1559 "A regexp that matches part of a diary sexp entry
1560 which should be treated as scheduling/deadline information in
1561 `org-agenda'.
1563 For example, you can use this to extract the `diary-remind-message' from
1564 `diary-remind' entries."
1565 :group 'org-agenda-line-format
1566 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1568 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1569 "Text preceding timerange entries in the agenda view.
1570 This is a list with two strings. The first applies when the range
1571 is entirely on one day. The second applies if the range spans several days.
1572 The strings may have two \"%d\" format specifiers which will be filled
1573 with the sequence number of the days, and the total number of days in the
1574 range, respectively."
1575 :group 'org-agenda-line-format
1576 :type '(list
1577 (string :tag "Deadline today ")
1578 (choice :tag "Deadline relative"
1579 (string :tag "Format string")
1580 (function))))
1582 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1583 "Text preceding scheduled items in the agenda view.
1584 This is a list with two strings. The first applies when the item is
1585 scheduled on the current day. The second applies when it has been scheduled
1586 previously, it may contain a %d indicating that this is the nth time that
1587 this item is scheduled, due to automatic rescheduling of unfinished items
1588 for the following day. So this number is one larger than the number of days
1589 that passed since this item was scheduled first."
1590 :group 'org-agenda-line-format
1591 :type '(list
1592 (string :tag "Scheduled today ")
1593 (string :tag "Scheduled previously")))
1595 (defcustom org-agenda-inactive-leader "["
1596 "Text preceding item pulled into the agenda by inactive time stamps.
1597 These entries are added to the agenda when pressing \"[\"."
1598 :group 'org-agenda-line-format
1599 :version "24.1"
1600 :type '(list
1601 (string :tag "Scheduled today ")
1602 (string :tag "Scheduled previously")))
1604 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1605 "Text preceding deadline items in the agenda view.
1606 This is a list with two strings. The first applies when the item has its
1607 deadline on the current day. The second applies when it is in the past or
1608 in the future, it may contain %d to capture how many days away the deadline
1609 is (was)."
1610 :group 'org-agenda-line-format
1611 :type '(list
1612 (string :tag "Deadline today ")
1613 (choice :tag "Deadline relative"
1614 (string :tag "Format string")
1615 (function))))
1617 (defcustom org-agenda-remove-times-when-in-prefix t
1618 "Non-nil means remove duplicate time specifications in agenda items.
1619 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1620 time-of-day specification in a headline or diary entry is extracted and
1621 placed into the prefix. If this option is non-nil, the original specification
1622 \(a timestamp or -range, or just a plain time(range) specification like
1623 11:30-4pm) will be removed for agenda display. This makes the agenda less
1624 cluttered.
1625 The option can be t or nil. It may also be the symbol `beg', indicating
1626 that the time should only be removed when it is located at the beginning of
1627 the headline/diary entry."
1628 :group 'org-agenda-line-format
1629 :type '(choice
1630 (const :tag "Always" t)
1631 (const :tag "Never" nil)
1632 (const :tag "When at beginning of entry" beg)))
1634 (defcustom org-agenda-remove-timeranges-from-blocks nil
1635 "Non-nil means remove time ranges specifications in agenda
1636 items that span on several days."
1637 :group 'org-agenda-line-format
1638 :version "24.1"
1639 :type 'boolean)
1641 (defcustom org-agenda-default-appointment-duration nil
1642 "Default duration for appointments that only have a starting time.
1643 When nil, no duration is specified in such cases.
1644 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1645 :group 'org-agenda-line-format
1646 :type '(choice
1647 (integer :tag "Minutes")
1648 (const :tag "No default duration")))
1650 (defcustom org-agenda-show-inherited-tags t
1651 "Non-nil means show inherited tags in each agenda line."
1652 :group 'org-agenda-line-format
1653 :type 'boolean)
1655 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1656 "List of agenda view types where to use tag inheritance.
1658 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1659 controlled by `org-use-tag-inheritance'. In other agenda types,
1660 `org-use-tag-inheritance' is not used when selecting the agenda
1661 entries, but you may want the agenda to use the inherited tags
1662 anyway, e.g. for later tag filtering.
1664 The default value reset tags in every agenda type. Setting this
1665 option to nil will speed up non-tags agenda view a lot.
1667 Allowed value are 'todo, 'search, 'timeline and 'agenda."
1668 :version "24.3"
1669 :group 'org-agenda
1670 :type '(repeat (symbol :tag "Agenda type")))
1672 (defcustom org-agenda-hide-tags-regexp nil
1673 "Regular expression used to filter away specific tags in agenda views.
1674 This means that these tags will be present, but not be shown in the agenda
1675 line. Secondary filtering will still work on the hidden tags.
1676 Nil means don't hide any tags."
1677 :group 'org-agenda-line-format
1678 :type '(choice
1679 (const :tag "Hide none" nil)
1680 (string :tag "Regexp ")))
1682 (defcustom org-agenda-remove-tags nil
1683 "Non-nil means remove the tags from the headline copy in the agenda.
1684 When this is the symbol `prefix', only remove tags when
1685 `org-agenda-prefix-format' contains a `%T' specifier."
1686 :group 'org-agenda-line-format
1687 :type '(choice
1688 (const :tag "Always" t)
1689 (const :tag "Never" nil)
1690 (const :tag "When prefix format contains %T" prefix)))
1692 (if (fboundp 'defvaralias)
1693 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1694 'org-agenda-remove-tags))
1696 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1697 "Shift tags in agenda items to this column.
1698 If this number is positive, it specifies the column. If it is negative,
1699 it means that the tags should be flushright to that column. For example,
1700 -80 works well for a normal 80 character screen."
1701 :group 'org-agenda-line-format
1702 :type 'integer)
1704 (if (fboundp 'defvaralias)
1705 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1707 (defcustom org-agenda-fontify-priorities 'cookies
1708 "Non-nil means highlight low and high priorities in agenda.
1709 When t, the highest priority entries are bold, lowest priority italic.
1710 However, settings in `org-priority-faces' will overrule these faces.
1711 When this variable is the symbol `cookies', only fontify the
1712 cookies, not the entire task.
1713 This may also be an association list of priority faces, whose
1714 keys are the character values of `org-highest-priority',
1715 `org-default-priority', and `org-lowest-priority' (the default values
1716 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1717 color as a string, or a list like `(:background \"Red\")'.
1718 If it is a color, the variable `org-faces-easy-properties'
1719 determines if it is a foreground or a background color."
1720 :group 'org-agenda-line-format
1721 :type '(choice
1722 (const :tag "Never" nil)
1723 (const :tag "Defaults" t)
1724 (const :tag "Cookies only" cookies)
1725 (repeat :tag "Specify"
1726 (list (character :tag "Priority" :value ?A)
1727 (choice :tag "Face "
1728 (string :tag "Color")
1729 (sexp :tag "Face"))))))
1731 (defcustom org-agenda-day-face-function nil
1732 "Function called to determine what face should be used to display a day.
1733 The only argument passed to that function is the day. It should
1734 returns a face, or nil if does not want to specify a face and let
1735 the normal rules apply."
1736 :group 'org-agenda-line-format
1737 :version "24.1"
1738 :type 'function)
1740 (defcustom org-agenda-category-icon-alist nil
1741 "Alist of category icon to be displayed in agenda views.
1743 Each entry should have the following format:
1745 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1747 Where CATEGORY-REGEXP is a regexp matching the categories where
1748 the icon should be displayed.
1749 FILE-OR-DATA either a file path or a string containing image data.
1751 The other fields can be omitted safely if not needed:
1752 TYPE indicates the image type.
1753 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1754 image data.
1755 PROPS are additional image attributes to assign to the image,
1756 like, e.g. `:ascent center'.
1758 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1760 If you want to set the display properties yourself, just put a
1761 list as second element:
1763 (CATEGORY-REGEXP (MY PROPERTY LIST))
1765 For example, to display a 16px horizontal space for Emacs
1766 category, you can use:
1768 (\"Emacs\" '(space . (:width (16))))"
1769 :group 'org-agenda-line-format
1770 :version "24.1"
1771 :type '(alist :key-type (string :tag "Regexp matching category")
1772 :value-type (choice (list :tag "Icon"
1773 (string :tag "File or data")
1774 (symbol :tag "Type")
1775 (boolean :tag "Data?")
1776 (repeat :tag "Extra image properties" :inline t symbol))
1777 (list :tag "Display properties" sexp))))
1779 (defgroup org-agenda-column-view nil
1780 "Options concerning column view in the agenda."
1781 :tag "Org Agenda Column View"
1782 :group 'org-agenda)
1784 (defcustom org-agenda-columns-show-summaries t
1785 "Non-nil means show summaries for columns displayed in the agenda view."
1786 :group 'org-agenda-column-view
1787 :type 'boolean)
1789 (defcustom org-agenda-columns-compute-summary-properties t
1790 "Non-nil means recompute all summary properties before column view.
1791 When column view in the agenda is listing properties that have a summary
1792 operator, it can go to all relevant buffers and recompute the summaries
1793 there. This can mean overhead for the agenda column view, but is necessary
1794 to have thing up to date.
1795 As a special case, a CLOCKSUM property also makes sure that the clock
1796 computations are current."
1797 :group 'org-agenda-column-view
1798 :type 'boolean)
1800 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1801 "Non-nil means the duration of an appointment will add to day effort.
1802 The property to which appointment durations will be added is the one given
1803 in the option `org-effort-property'. If an appointment does not have
1804 an end time, `org-agenda-default-appointment-duration' will be used. If that
1805 is not set, an appointment without end time will not contribute to the time
1806 estimate."
1807 :group 'org-agenda-column-view
1808 :type 'boolean)
1810 (defcustom org-agenda-auto-exclude-function nil
1811 "A function called with a tag to decide if it is filtered on '/ RET'.
1812 The sole argument to the function, which is called once for each
1813 possible tag, is a string giving the name of the tag. The
1814 function should return either nil if the tag should be included
1815 as normal, or \"-<TAG>\" to exclude the tag.
1816 Note that for the purpose of tag filtering, only the lower-case version of
1817 all tags will be considered, so that this function will only ever see
1818 the lower-case version of all tags."
1819 :group 'org-agenda
1820 :type 'function)
1822 (defcustom org-agenda-bulk-custom-functions nil
1823 "Alist of characters and custom functions for bulk actions.
1824 For example, this value makes those two functions available:
1826 '((?R set-category)
1827 (?C bulk-cut))
1829 With selected entries in an agenda buffer, `B R' will call
1830 the custom function `set-category' on the selected entries.
1831 Note that functions in this alist don't need to be quoted."
1832 :type 'alist
1833 :version "24.1"
1834 :group 'org-agenda)
1836 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1837 "Execute BODY with point at location given by `org-hd-marker' property.
1838 If STRING is non-nil, the text property will be fetched from position 0
1839 in that string. If STRING is nil, it will be fetched from the beginning
1840 of the current line."
1841 (org-with-gensyms (marker)
1842 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1843 'org-hd-marker ,string)))
1844 (with-current-buffer (marker-buffer ,marker)
1845 (save-excursion
1846 (goto-char ,marker)
1847 ,@body)))))
1848 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1850 (defun org-add-agenda-custom-command (entry)
1851 "Replace or add a command in `org-agenda-custom-commands'.
1852 This is mostly for hacking and trying a new command - once the command
1853 works you probably want to add it to `org-agenda-custom-commands' for good."
1854 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1855 (if ass
1856 (setcdr ass (cdr entry))
1857 (push entry org-agenda-custom-commands))))
1859 ;;; Define the org-agenda-mode
1861 (defvar org-agenda-mode-map (make-sparse-keymap)
1862 "Keymap for `org-agenda-mode'.")
1863 (if (fboundp 'defvaralias)
1864 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1866 (defvar org-agenda-menu) ; defined later in this file.
1867 (defvar org-agenda-restrict nil) ; defined later in this file.
1868 (defvar org-agenda-follow-mode nil)
1869 (defvar org-agenda-entry-text-mode nil)
1870 (defvar org-agenda-clockreport-mode nil)
1871 (defvar org-agenda-show-log nil)
1872 (defvar org-agenda-redo-command nil)
1873 (defvar org-agenda-query-string nil)
1874 (defvar org-agenda-mode-hook nil
1875 "Hook run after `org-agenda-mode' is turned on.
1876 The buffer is still writable when this hook is called.")
1877 (defvar org-agenda-type nil)
1878 (defvar org-agenda-force-single-file nil)
1879 (defvar org-agenda-bulk-marked-entries nil
1880 "List of markers that refer to marked entries in the agenda.")
1882 ;;; Multiple agenda buffers support
1884 (defcustom org-agenda-sticky nil
1885 "Non-nil means agenda q key will bury agenda buffers.
1886 Agenda commands will then show existing buffer instead of generating new ones.
1887 When nil, `q' will kill the single agenda buffer."
1888 :group 'org-agenda
1889 :version "24.3"
1890 :type 'boolean)
1893 ;;;###autoload
1894 (defun org-toggle-sticky-agenda (&optional arg)
1895 "Toggle `org-agenda-sticky'."
1896 (interactive "P")
1897 (let ((new-value (if arg
1898 (> (prefix-numeric-value arg) 0)
1899 (not org-agenda-sticky))))
1900 (if (equal new-value org-agenda-sticky)
1901 (and (org-called-interactively-p 'interactive)
1902 (message "Sticky agenda was already %s"
1903 (if org-agenda-sticky "enabled" "disabled")))
1904 (setq org-agenda-sticky new-value)
1905 (org-agenda-kill-all-agenda-buffers)
1906 (and (org-called-interactively-p 'interactive)
1907 (message "Sticky agenda was %s"
1908 (if org-agenda-sticky "enabled" "disabled"))))))
1910 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1911 Toggle `org-agenda-sticky'.
1913 \(fn &optional ARG)" t nil)
1915 (defvar org-agenda-buffer nil
1916 "Agenda buffer currently being generated.")
1918 (defvar org-agenda-last-prefix-arg nil)
1919 (defvar org-agenda-this-buffer-name nil)
1920 (defvar org-agenda-doing-sticky-redo nil)
1921 (defvar org-agenda-this-buffer-is-sticky nil)
1923 (defconst org-agenda-local-vars
1924 '(org-agenda-this-buffer-name
1925 org-agenda-undo-list
1926 org-agenda-pending-undo-list
1927 org-agenda-follow-mode
1928 org-agenda-entry-text-mode
1929 org-agenda-clockreport-mode
1930 org-agenda-show-log
1931 org-agenda-redo-command
1932 org-agenda-query-string
1933 org-agenda-type
1934 org-agenda-bulk-marked-entries
1935 org-agenda-undo-has-started-in
1936 org-agenda-info
1937 org-agenda-tag-filter-overlays
1938 org-agenda-cat-filter-overlays
1939 org-agenda-pre-window-conf
1940 org-agenda-columns-active
1941 org-agenda-tag-filter
1942 org-agenda-category-filter
1943 org-agenda-markers
1944 org-agenda-last-search-view-search-was-boolean
1945 org-agenda-filtered-by-category
1946 org-agenda-filter-form
1947 org-agenda-show-window
1948 org-agenda-cycle-counter
1949 org-agenda-last-prefix-arg)
1950 "Variables that must be local in agenda buffers to allow multiple buffers.")
1952 (defun org-agenda-mode ()
1953 "Mode for time-sorted view on action items in Org-mode files.
1955 The following commands are available:
1957 \\{org-agenda-mode-map}"
1958 (interactive)
1959 (cond (org-agenda-doing-sticky-redo
1960 ;; Refreshing sticky agenda-buffer
1962 ;; Preserve the value of `org-agenda-local-vars' variables,
1963 ;; while letting `kill-all-local-variables' kill the rest
1964 (let ((save (buffer-local-variables)))
1965 (kill-all-local-variables)
1966 (mapc 'make-local-variable org-agenda-local-vars)
1967 (dolist (elem save)
1968 (let ((var (car elem))
1969 (val (cdr elem)))
1970 (when (and val
1971 (member var org-agenda-local-vars))
1972 (set var val)))))
1973 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1974 (org-agenda-sticky
1975 ;; Creating a sticky Agenda buffer for the first time
1976 (kill-all-local-variables)
1977 (mapc 'make-local-variable org-agenda-local-vars)
1978 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1980 ;; Creating a non-sticky agenda buffer
1981 (kill-all-local-variables)
1982 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1983 (setq org-agenda-undo-list nil
1984 org-agenda-pending-undo-list nil
1985 org-agenda-bulk-marked-entries nil)
1986 (setq major-mode 'org-agenda-mode)
1987 ;; Keep global-font-lock-mode from turning on font-lock-mode
1988 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1989 (setq mode-name "Org-Agenda")
1990 (use-local-map org-agenda-mode-map)
1991 (easy-menu-add org-agenda-menu)
1992 (if org-startup-truncated (setq truncate-lines t))
1993 (org-set-local 'line-move-visual nil)
1994 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1995 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1996 ;; Make sure properties are removed when copying text
1997 (make-local-variable 'filter-buffer-substring-functions)
1998 (add-hook 'filter-buffer-substring-functions
1999 (lambda (fun start end delete)
2000 (substring-no-properties (funcall fun start end delete))))
2001 (unless org-agenda-keep-modes
2002 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2003 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2004 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2005 org-agenda-show-log org-agenda-start-with-log-mode))
2007 (easy-menu-change
2008 '("Agenda") "Agenda Files"
2009 (append
2010 (list
2011 (vector
2012 (if (get 'org-agenda-files 'org-restrict)
2013 "Restricted to single file"
2014 "Edit File List")
2015 '(org-edit-agenda-file-list)
2016 (not (get 'org-agenda-files 'org-restrict)))
2017 "--")
2018 (mapcar 'org-file-menu-entry (org-agenda-files))))
2019 (org-agenda-set-mode-name)
2020 (apply
2021 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2022 (list 'org-agenda-mode-hook)))
2024 (substitute-key-definition 'undo 'org-agenda-undo
2025 org-agenda-mode-map global-map)
2026 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2027 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2028 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2029 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2030 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2031 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2032 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2033 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2034 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2035 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2036 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2037 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2038 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2039 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2040 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2041 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2042 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2043 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2044 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2045 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2046 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2047 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2048 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2049 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2050 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2051 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2052 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2053 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2054 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2055 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2056 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2057 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2058 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2059 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2060 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2061 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2062 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2063 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2064 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2065 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2066 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2067 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2068 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2069 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2070 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2071 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2073 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2074 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2075 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2076 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2077 (while l (org-defkey org-agenda-mode-map
2078 (int-to-string (pop l)) 'digit-argument)))
2080 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2081 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2082 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2083 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2084 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2085 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2086 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2087 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2088 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2089 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2090 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2091 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2092 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2093 'org-clock-modify-effort-estimate)
2094 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2095 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2096 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2097 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2098 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2099 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2100 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2101 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2102 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2103 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2104 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2105 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2106 (substitute-key-definition 'next-line 'org-agenda-next-line
2107 org-agenda-mode-map global-map)
2108 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2109 org-agenda-mode-map global-map)
2110 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2111 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2112 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2113 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2114 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2115 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2116 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2117 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2118 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2119 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2120 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2121 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2123 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2125 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2126 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2127 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2128 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2129 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2130 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2131 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2132 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2133 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2134 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2135 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2136 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2137 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2138 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2139 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2141 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2142 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2143 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2144 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2145 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2146 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2147 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2148 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2149 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2150 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2151 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2152 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2154 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2155 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2156 (when org-agenda-mouse-1-follows-link
2157 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2158 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2159 '("Agenda"
2160 ("Agenda Files")
2161 "--"
2162 ("Agenda Dates"
2163 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2164 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2165 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2166 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2167 "--"
2168 ("View"
2169 ["Day View" org-agenda-day-view
2170 :active (org-agenda-check-type nil 'agenda)
2171 :style radio :selected (eq org-agenda-current-span 'day)
2172 :keys "v d (or just d)"]
2173 ["Week View" org-agenda-week-view
2174 :active (org-agenda-check-type nil 'agenda)
2175 :style radio :selected (eq org-agenda-current-span 'week)
2176 :keys "v w (or just w)"]
2177 ["Month View" org-agenda-month-view
2178 :active (org-agenda-check-type nil 'agenda)
2179 :style radio :selected (eq org-agenda-current-span 'month)
2180 :keys "v m"]
2181 ["Year View" org-agenda-year-view
2182 :active (org-agenda-check-type nil 'agenda)
2183 :style radio :selected (eq org-agenda-current-span 'year)
2184 :keys "v y"]
2185 "--"
2186 ["Include Diary" org-agenda-toggle-diary
2187 :style toggle :selected org-agenda-include-diary
2188 :active (org-agenda-check-type nil 'agenda)]
2189 ["Include Deadlines" org-agenda-toggle-deadlines
2190 :style toggle :selected org-agenda-include-deadlines
2191 :active (org-agenda-check-type nil 'agenda)]
2192 ["Use Time Grid" org-agenda-toggle-time-grid
2193 :style toggle :selected org-agenda-use-time-grid
2194 :active (org-agenda-check-type nil 'agenda)]
2195 "--"
2196 ["Show clock report" org-agenda-clockreport-mode
2197 :style toggle :selected org-agenda-clockreport-mode
2198 :active (org-agenda-check-type nil 'agenda)]
2199 ["Show some entry text" org-agenda-entry-text-mode
2200 :style toggle :selected org-agenda-entry-text-mode
2201 :active t]
2202 "--"
2203 ["Show Logbook entries" org-agenda-log-mode
2204 :style toggle :selected org-agenda-show-log
2205 :active (org-agenda-check-type nil 'agenda 'timeline)
2206 :keys "v l (or just l)"]
2207 ["Include archived trees" org-agenda-archives-mode
2208 :style toggle :selected org-agenda-archives-mode :active t
2209 :keys "v a"]
2210 ["Include archive files" (org-agenda-archives-mode t)
2211 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2212 :keys "v A"]
2213 "--"
2214 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2215 ["Write view to file" org-agenda-write t]
2216 ["Rebuild buffer" org-agenda-redo t]
2217 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2218 "--"
2219 ["Show original entry" org-agenda-show t]
2220 ["Go To (other window)" org-agenda-goto t]
2221 ["Go To (this window)" org-agenda-switch-to t]
2222 ["Capture with cursor date" org-agenda-capture t]
2223 ["Follow Mode" org-agenda-follow-mode
2224 :style toggle :selected org-agenda-follow-mode :active t]
2225 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2226 "--"
2227 ("TODO"
2228 ["Cycle TODO" org-agenda-todo t]
2229 ["Next TODO set" org-agenda-todo-nextset t]
2230 ["Previous TODO set" org-agenda-todo-previousset t]
2231 ["Add note" org-agenda-add-note t])
2232 ("Archive/Refile/Delete"
2233 ["Archive default" org-agenda-archive-default t]
2234 ["Archive default" org-agenda-archive-default-with-confirmation t]
2235 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2236 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2237 ["Archive subtree" org-agenda-archive t]
2238 "--"
2239 ["Refile" org-agenda-refile t]
2240 "--"
2241 ["Delete subtree" org-agenda-kill t])
2242 ("Bulk action"
2243 ["Mark entry" org-agenda-bulk-mark t]
2244 ["Mark all" org-agenda-bulk-mark-all t]
2245 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2246 ["Unmark entry" org-agenda-bulk-unmark t]
2247 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2248 ["Act on all marked" org-agenda-bulk-action t]
2249 "--"
2250 ("Tags and Properties"
2251 ["Show all Tags" org-agenda-show-tags t]
2252 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2253 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2254 "--"
2255 ["Column View" org-columns t])
2256 ("Deadline/Schedule"
2257 ["Schedule" org-agenda-schedule t]
2258 ["Set Deadline" org-agenda-deadline t]
2259 "--"
2260 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2261 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2262 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2263 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2264 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2265 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2266 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2267 ("Clock and Effort"
2268 ["Clock in" org-agenda-clock-in t]
2269 ["Clock out" org-agenda-clock-out t]
2270 ["Clock cancel" org-agenda-clock-cancel t]
2271 ["Goto running clock" org-clock-goto t]
2272 "--"
2273 ["Set Effort" org-agenda-set-effort t]
2274 ["Change clocked effort" org-clock-modify-effort-estimate
2275 (org-clock-is-active)])
2276 ("Priority"
2277 ["Set Priority" org-agenda-priority t]
2278 ["Increase Priority" org-agenda-priority-up t]
2279 ["Decrease Priority" org-agenda-priority-down t]
2280 ["Show Priority" org-show-priority t])
2281 ("Calendar/Diary"
2282 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2283 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2284 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2285 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2286 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2287 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2288 "--"
2289 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2290 "--"
2291 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2292 "--"
2293 ("MobileOrg"
2294 ["Push Files and Views" org-mobile-push t]
2295 ["Get Captured and Flagged" org-mobile-pull t]
2296 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2297 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2298 "--"
2299 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2300 "--"
2301 ["Quit" org-agenda-quit t]
2302 ["Exit and Release Buffers" org-agenda-exit t]
2305 ;;; Agenda undo
2307 (defvar org-agenda-allow-remote-undo t
2308 "Non-nil means allow remote undo from the agenda buffer.")
2309 (defvar org-agenda-undo-has-started-in nil
2310 "Buffers that have already seen `undo-start' in the current undo sequence.")
2312 (defun org-agenda-undo ()
2313 "Undo a remote editing step in the agenda.
2314 This undoes changes both in the agenda buffer and in the remote buffer
2315 that have been changed along."
2316 (interactive)
2317 (or org-agenda-allow-remote-undo
2318 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2319 (if (not (eq this-command last-command))
2320 (setq org-agenda-undo-has-started-in nil
2321 org-agenda-pending-undo-list org-agenda-undo-list))
2322 (if (not org-agenda-pending-undo-list)
2323 (error "No further undo information"))
2324 (let* ((entry (pop org-agenda-pending-undo-list))
2325 buf line cmd rembuf)
2326 (setq cmd (pop entry) line (pop entry))
2327 (setq rembuf (nth 2 entry))
2328 (org-with-remote-undo rembuf
2329 (while (bufferp (setq buf (pop entry)))
2330 (if (pop entry)
2331 (with-current-buffer buf
2332 (let ((last-undo-buffer buf)
2333 (inhibit-read-only t))
2334 (unless (memq buf org-agenda-undo-has-started-in)
2335 (push buf org-agenda-undo-has-started-in)
2336 (make-local-variable 'pending-undo-list)
2337 (undo-start))
2338 (while (and pending-undo-list
2339 (listp pending-undo-list)
2340 (not (car pending-undo-list)))
2341 (pop pending-undo-list))
2342 (undo-more 1))))))
2343 (org-goto-line line)
2344 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2346 (defun org-verify-change-for-undo (l1 l2)
2347 "Verify that a real change occurred between the undo lists L1 and L2."
2348 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2349 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2350 (not (eq l1 l2)))
2352 ;;; Agenda dispatch
2354 (defvar org-agenda-restrict-begin (make-marker))
2355 (defvar org-agenda-restrict-end (make-marker))
2356 (defvar org-agenda-last-dispatch-buffer nil)
2357 (defvar org-agenda-overriding-restriction nil)
2359 (defcustom org-agenda-custom-commands-contexts nil
2360 "Alist of custom agenda keys and contextual rules.
2362 For example, if you have a custom agenda command \"p\" and you
2363 want this command to be accessible only from plain text files,
2364 use this:
2366 '((\"p\" (in-file . \"\\.txt\")))
2368 Here are the available contexts definitions:
2370 in-file: command displayed only in matching files
2371 in-mode: command displayed only in matching modes
2372 not-in-file: command not displayed in matching files
2373 not-in-mode: command not displayed in matching modes
2374 [function]: a custom function taking no argument
2376 If you define several checks, the agenda command will be
2377 accessible if there is at least one valid check.
2379 You can also bind a key to another agenda custom command
2380 depending on contextual rules.
2382 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2384 Here it means: in .txt files, use \"p\" as the key for the
2385 agenda command otherwise associated with \"q\". (The command
2386 originally associated with \"q\" is not displayed to avoid
2387 duplicates.)"
2388 :version "24.3"
2389 :group 'org-agenda-custom-commands
2390 :type '(repeat (list :tag "Rule"
2391 (string :tag " Agenda key")
2392 (string :tag "Replace by command")
2393 (repeat :tag "Available when"
2394 (choice
2395 (cons :tag "Condition"
2396 (choice
2397 (const :tag "In file" in-file)
2398 (const :tag "Not in file" not-in-file)
2399 (const :tag "In mode" in-mode)
2400 (const :tag "Not in mode" not-in-mode))
2401 (regexp))
2402 (function :tag "Custom function"))))))
2404 (defvar org-keys nil)
2405 (defvar org-match nil)
2406 ;;;###autoload
2407 (defun org-agenda (&optional arg org-keys restriction)
2408 "Dispatch agenda commands to collect entries to the agenda buffer.
2409 Prompts for a command to execute. Any prefix arg will be passed
2410 on to the selected command. The default selections are:
2412 a Call `org-agenda-list' to display the agenda for current day or week.
2413 t Call `org-todo-list' to display the global todo list.
2414 T Call `org-todo-list' to display the global todo list, select only
2415 entries with a specific TODO keyword (the user gets a prompt).
2416 m Call `org-tags-view' to display headlines with tags matching
2417 a condition (the user is prompted for the condition).
2418 M Like `m', but select only TODO entries, no ordinary headlines.
2419 L Create a timeline for the current buffer.
2420 e Export views to associated files.
2421 s Search entries for keywords.
2422 S Search entries for keywords, only with TODO keywords.
2423 / Multi occur across all agenda files and also files listed
2424 in `org-agenda-text-search-extra-files'.
2425 < Restrict agenda commands to buffer, subtree, or region.
2426 Press several times to get the desired effect.
2427 > Remove a previous restriction.
2428 # List \"stuck\" projects.
2429 ! Configure what \"stuck\" means.
2430 C Configure custom agenda commands.
2432 More commands can be added by configuring the variable
2433 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2434 searches can be pre-defined in this way.
2436 If the current buffer is in Org-mode and visiting a file, you can also
2437 first press `<' once to indicate that the agenda should be temporarily
2438 \(until the next use of \\[org-agenda]) restricted to the current file.
2439 Pressing `<' twice means to restrict to the current subtree or region
2440 \(if active)."
2441 (interactive "P")
2442 (catch 'exit
2443 (let* ((prefix-descriptions nil)
2444 (org-agenda-buffer-name org-agenda-buffer-name)
2445 (org-agenda-window-setup (if (equal (buffer-name)
2446 org-agenda-buffer-name)
2447 'current-window
2448 org-agenda-window-setup))
2449 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2450 (org-agenda-custom-commands
2451 ;; normalize different versions
2452 (delq nil
2453 (mapcar
2454 (lambda (x)
2455 (cond ((stringp (cdr x))
2456 (push x prefix-descriptions)
2457 nil)
2458 ((stringp (nth 1 x)) x)
2459 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2460 (t (cons (car x) (cons "" (cdr x))))))
2461 org-agenda-custom-commands)))
2462 (org-agenda-custom-commands
2463 (org-contextualize-keys
2464 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2465 (buf (current-buffer))
2466 (bfn (buffer-file-name (buffer-base-buffer)))
2467 entry key type org-match lprops ans)
2468 ;; Turn off restriction unless there is an overriding one,
2469 (unless org-agenda-overriding-restriction
2470 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2471 ;; There is a request to keep the file list in place
2472 (put 'org-agenda-files 'org-restrict nil))
2473 (setq org-agenda-restrict nil)
2474 (move-marker org-agenda-restrict-begin nil)
2475 (move-marker org-agenda-restrict-end nil))
2476 ;; Delete old local properties
2477 (put 'org-agenda-redo-command 'org-lprops nil)
2478 ;; Delete previously set last-arguments
2479 (put 'org-agenda-redo-command 'last-args nil)
2480 ;; Remember where this call originated
2481 (setq org-agenda-last-dispatch-buffer (current-buffer))
2482 (unless org-keys
2483 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2484 org-keys (car ans)
2485 restriction (cdr ans)))
2486 ;; If we have sticky agenda buffers, set a name for the buffer,
2487 ;; depending on the invoking keys. The user may still set this
2488 ;; as a command option, which will overwrite what we do here.
2489 (if org-agenda-sticky
2490 (setq org-agenda-buffer-name
2491 (format "*Org Agenda(%s)*" org-keys)))
2492 ;; Establish the restriction, if any
2493 (when (and (not org-agenda-overriding-restriction) restriction)
2494 (put 'org-agenda-files 'org-restrict (list bfn))
2495 (cond
2496 ((eq restriction 'region)
2497 (setq org-agenda-restrict t)
2498 (move-marker org-agenda-restrict-begin (region-beginning))
2499 (move-marker org-agenda-restrict-end (region-end)))
2500 ((eq restriction 'subtree)
2501 (save-excursion
2502 (setq org-agenda-restrict t)
2503 (org-back-to-heading t)
2504 (move-marker org-agenda-restrict-begin (point))
2505 (move-marker org-agenda-restrict-end
2506 (progn (org-end-of-subtree t)))))))
2508 ;; For example the todo list should not need it (but does...)
2509 (cond
2510 ((setq entry (assoc org-keys org-agenda-custom-commands))
2511 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2512 (progn
2513 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2514 lprops (nth 4 entry))
2515 (if org-agenda-sticky
2516 (setq org-agenda-buffer-name
2517 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2518 (format "*Org Agenda(%s)*" org-keys))))
2519 (put 'org-agenda-redo-command 'org-lprops lprops)
2520 (cond
2521 ((eq type 'agenda)
2522 (org-let lprops '(org-agenda-list current-prefix-arg)))
2523 ((eq type 'alltodo)
2524 (org-let lprops '(org-todo-list current-prefix-arg)))
2525 ((eq type 'search)
2526 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2527 ((eq type 'stuck)
2528 (org-let lprops '(org-agenda-list-stuck-projects
2529 current-prefix-arg)))
2530 ((eq type 'tags)
2531 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2532 ((eq type 'tags-todo)
2533 (org-let lprops '(org-tags-view '(4) org-match)))
2534 ((eq type 'todo)
2535 (org-let lprops '(org-todo-list org-match)))
2536 ((eq type 'tags-tree)
2537 (org-check-for-org-mode)
2538 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2539 ((eq type 'todo-tree)
2540 (org-check-for-org-mode)
2541 (org-let lprops
2542 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2543 (regexp-quote org-match) "\\>"))))
2544 ((eq type 'occur-tree)
2545 (org-check-for-org-mode)
2546 (org-let lprops '(org-occur org-match)))
2547 ((functionp type)
2548 (org-let lprops '(funcall type org-match)))
2549 ((fboundp type)
2550 (org-let lprops '(funcall type org-match)))
2551 (t (error "Invalid custom agenda command type %s" type))))
2552 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2553 ((equal org-keys "C")
2554 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2555 (customize-variable 'org-agenda-custom-commands))
2556 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2557 ((equal org-keys "s") (call-interactively 'org-search-view))
2558 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2559 ((equal org-keys "t") (call-interactively 'org-todo-list))
2560 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2561 ((equal org-keys "m") (call-interactively 'org-tags-view))
2562 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2563 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2564 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2565 (org-add-hook
2566 'post-command-hook
2567 (lambda ()
2568 (unless (current-message)
2569 (let* ((m (org-agenda-get-any-marker))
2570 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2571 (when note
2572 (message (concat
2573 "FLAGGING-NOTE ([?] for more info): "
2574 (org-add-props
2575 (replace-regexp-in-string
2576 "\\\\n" "//"
2577 (copy-sequence note))
2578 nil 'face 'org-warning)))))))
2579 t t))
2580 ((equal org-keys "L")
2581 (unless (derived-mode-p 'org-mode)
2582 (error "This is not an Org-mode file"))
2583 (unless restriction
2584 (put 'org-agenda-files 'org-restrict (list bfn))
2585 (org-call-with-arg 'org-timeline arg)))
2586 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2587 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2588 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2589 (t (error "Invalid agenda key"))))))
2591 (autoload 'org-agenda "org-agenda" "\
2592 Dispatch agenda commands to collect entries to the agenda buffer.
2593 Prompts for a command to execute. Any prefix arg will be passed
2594 on to the selected command. The default selections are:
2596 a Call `org-agenda-list' to display the agenda for current day or week.
2597 t Call `org-todo-list' to display the global todo list.
2598 T Call `org-todo-list' to display the global todo list, select only
2599 entries with a specific TODO keyword (the user gets a prompt).
2600 m Call `org-tags-view' to display headlines with tags matching
2601 a condition (the user is prompted for the condition).
2602 M Like `m', but select only TODO entries, no ordinary headlines.
2603 L Create a timeline for the current buffer.
2604 e Export views to associated files.
2605 s Search entries for keywords.
2606 S Search entries for keywords, only with TODO keywords.
2607 / Multi occur across all agenda files and also files listed
2608 in `org-agenda-text-search-extra-files'.
2609 < Restrict agenda commands to buffer, subtree, or region.
2610 Press several times to get the desired effect.
2611 > Remove a previous restriction.
2612 # List \"stuck\" projects.
2613 ! Configure what \"stuck\" means.
2614 C Configure custom agenda commands.
2616 More commands can be added by configuring the variable
2617 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2618 searches can be pre-defined in this way.
2620 If the current buffer is in Org-mode and visiting a file, you can also
2621 first press `<' once to indicate that the agenda should be temporarily
2622 \(until the next use of \\[org-agenda]) restricted to the current file.
2623 Pressing `<' twice means to restrict to the current subtree or region
2624 \(if active).
2626 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2628 (defun org-agenda-append-agenda ()
2629 "Append another agenda view to the current one.
2630 This function allows interactive building of block agendas.
2631 Agenda views are separated by `org-agenda-block-separator'."
2632 (interactive)
2633 (unless (derived-mode-p 'org-agenda-mode)
2634 (error "Can only append from within agenda buffer"))
2635 (let ((org-agenda-multi t))
2636 (org-agenda)
2637 (widen)
2638 (org-agenda-finalize)
2639 (org-agenda-fit-window-to-buffer)))
2641 (defun org-agenda-normalize-custom-commands (cmds)
2642 (delq nil
2643 (mapcar
2644 (lambda (x)
2645 (cond ((stringp (cdr x)) nil)
2646 ((stringp (nth 1 x)) x)
2647 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2648 (t (cons (car x) (cons "" (cdr x))))))
2649 cmds)))
2651 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2652 "The user interface for selecting an agenda command."
2653 (catch 'exit
2654 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2655 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2656 (region-p (org-region-active-p))
2657 (custom org-agenda-custom-commands)
2658 (selstring "")
2659 restriction second-time
2660 c entry key type match prefixes rmheader header-end custom1 desc
2661 line lines left right n n1)
2662 (save-window-excursion
2663 (delete-other-windows)
2664 (org-switch-to-buffer-other-window " *Agenda Commands*")
2665 (erase-buffer)
2666 (insert (eval-when-compile
2667 (let ((header
2668 "Press key for an agenda command: < Buffer, subtree/region restriction
2669 -------------------------------- > Remove restriction
2670 a Agenda for current week or day e Export agenda views
2671 t List of all TODO entries T Entries with special TODO kwd
2672 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2673 s Search for keywords S Like s, but only TODO entries
2674 L Timeline for current buffer # List stuck projects (!=configure)
2675 / Multi-occur C Configure custom agenda commands
2676 ? Find :FLAGGED: entries * Toggle sticky agenda views
2678 (start 0))
2679 (while (string-match
2680 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2681 header start)
2682 (setq start (match-end 0))
2683 (add-text-properties (match-beginning 2) (match-end 2)
2684 '(face bold) header))
2685 header)))
2686 (setq header-end (point-marker))
2687 (while t
2688 (setq custom1 custom)
2689 (when (eq rmheader t)
2690 (org-goto-line 1)
2691 (re-search-forward ":" nil t)
2692 (delete-region (match-end 0) (point-at-eol))
2693 (forward-char 1)
2694 (looking-at "-+")
2695 (delete-region (match-end 0) (point-at-eol))
2696 (move-marker header-end (match-end 0)))
2697 (goto-char header-end)
2698 (delete-region (point) (point-max))
2700 ;; Produce all the lines that describe custom commands and prefixes
2701 (setq lines nil)
2702 (while (setq entry (pop custom1))
2703 (setq key (car entry) desc (nth 1 entry)
2704 type (nth 2 entry)
2705 match (nth 3 entry))
2706 (if (> (length key) 1)
2707 (add-to-list 'prefixes (string-to-char key))
2708 (setq line
2709 (format
2710 "%-4s%-14s"
2711 (org-add-props (copy-sequence key)
2712 '(face bold))
2713 (cond
2714 ((string-match "\\S-" desc) desc)
2715 ((eq type 'agenda) "Agenda for current week or day")
2716 ((eq type 'alltodo) "List of all TODO entries")
2717 ((eq type 'search) "Word search")
2718 ((eq type 'stuck) "List of stuck projects")
2719 ((eq type 'todo) "TODO keyword")
2720 ((eq type 'tags) "Tags query")
2721 ((eq type 'tags-todo) "Tags (TODO)")
2722 ((eq type 'tags-tree) "Tags tree")
2723 ((eq type 'todo-tree) "TODO kwd tree")
2724 ((eq type 'occur-tree) "Occur tree")
2725 ((functionp type) (if (symbolp type)
2726 (symbol-name type)
2727 "Lambda expression"))
2728 (t "???"))))
2729 (if org-agenda-menu-show-matcher
2730 (setq line
2731 (concat line ": "
2732 (cond
2733 ((stringp match)
2734 (setq match (copy-sequence match))
2735 (org-add-props match nil 'face 'org-warning))
2736 ((listp type)
2737 (format "set of %d commands" (length type))))))
2738 (if (org-string-nw-p match)
2739 (add-text-properties
2740 0 (length line) (list 'help-echo
2741 (concat "Matcher: " match)) line)))
2742 (push line lines)))
2743 (setq lines (nreverse lines))
2744 (when prefixes
2745 (mapc (lambda (x)
2746 (push
2747 (format "%s %s"
2748 (org-add-props (char-to-string x)
2749 nil 'face 'bold)
2750 (or (cdr (assoc (concat selstring
2751 (char-to-string x))
2752 prefix-descriptions))
2753 "Prefix key"))
2754 lines))
2755 prefixes))
2757 ;; Check if we should display in two columns
2758 (if org-agenda-menu-two-columns
2759 (progn
2760 (setq n (length lines)
2761 n1 (+ (/ n 2) (mod n 2))
2762 right (nthcdr n1 lines)
2763 left (copy-sequence lines))
2764 (setcdr (nthcdr (1- n1) left) nil))
2765 (setq left lines right nil))
2766 (while left
2767 (insert "\n" (pop left))
2768 (when right
2769 (if (< (current-column) 40)
2770 (move-to-column 40 t)
2771 (insert " "))
2772 (insert (pop right))))
2774 ;; Make the window the right size
2775 (goto-char (point-min))
2776 (if second-time
2777 (if (not (pos-visible-in-window-p (point-max)))
2778 (org-fit-window-to-buffer))
2779 (setq second-time t)
2780 (org-fit-window-to-buffer))
2782 ;; Ask for selection
2783 (message "Press key for agenda command%s:"
2784 (if (or restrict-ok org-agenda-overriding-restriction)
2785 (if org-agenda-overriding-restriction
2786 " (restriction lock active)"
2787 (if restriction
2788 (format " (restricted to %s)" restriction)
2789 " (unrestricted)"))
2790 ""))
2791 (setq c (read-char-exclusive))
2792 (message "")
2793 (cond
2794 ((assoc (char-to-string c) custom)
2795 (setq selstring (concat selstring (char-to-string c)))
2796 (throw 'exit (cons selstring restriction)))
2797 ((memq c prefixes)
2798 (setq selstring (concat selstring (char-to-string c))
2799 prefixes nil
2800 rmheader (or rmheader t)
2801 custom (delq nil (mapcar
2802 (lambda (x)
2803 (if (or (= (length (car x)) 1)
2804 (/= (string-to-char (car x)) c))
2806 (cons (substring (car x) 1) (cdr x))))
2807 custom))))
2808 ((eq c ?*)
2809 (call-interactively 'org-toggle-sticky-agenda)
2810 (sit-for 2))
2811 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2812 (message "Restriction is only possible in Org-mode buffers")
2813 (ding) (sit-for 1))
2814 ((eq c ?1)
2815 (org-agenda-remove-restriction-lock 'noupdate)
2816 (setq restriction 'buffer))
2817 ((eq c ?0)
2818 (org-agenda-remove-restriction-lock 'noupdate)
2819 (setq restriction (if region-p 'region 'subtree)))
2820 ((eq c ?<)
2821 (org-agenda-remove-restriction-lock 'noupdate)
2822 (setq restriction
2823 (cond
2824 ((eq restriction 'buffer)
2825 (if region-p 'region 'subtree))
2826 ((memq restriction '(subtree region))
2827 nil)
2828 (t 'buffer))))
2829 ((eq c ?>)
2830 (org-agenda-remove-restriction-lock 'noupdate)
2831 (setq restriction nil))
2832 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2833 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2834 ((and (> (length selstring) 0) (eq c ?\d))
2835 (delete-window)
2836 (org-agenda-get-restriction-and-command prefix-descriptions))
2838 ((equal c ?q) (error "Abort"))
2839 (t (error "Invalid key %c" c))))))))
2841 (defun org-agenda-fit-window-to-buffer ()
2842 "Fit the window to the buffer size."
2843 (and (memq org-agenda-window-setup '(reorganize-frame))
2844 (fboundp 'fit-window-to-buffer)
2845 (org-fit-window-to-buffer
2847 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2848 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2850 (defvar org-cmd nil)
2851 (defvar org-agenda-overriding-cmd nil)
2852 (defvar org-agenda-overriding-arguments nil)
2853 (defvar org-agenda-overriding-cmd-arguments nil)
2854 (defun org-agenda-run-series (name series)
2855 (org-let (nth 1 series) '(org-agenda-prepare name))
2856 ;; We need to reset agenda markers here, because when constructing a
2857 ;; block agenda, the individual blocks do not do that.
2858 (org-agenda-reset-markers)
2859 (let* ((org-agenda-multi t)
2860 (redo (list 'org-agenda-run-series name (list 'quote series)))
2861 (cmds (car series))
2862 (gprops (nth 1 series))
2863 match ;; The byte compiler incorrectly complains about this. Keep it!
2864 org-cmd type lprops)
2865 (while (setq org-cmd (pop cmds))
2866 (setq type (car org-cmd)
2867 match (eval (nth 1 org-cmd))
2868 lprops (nth 2 org-cmd))
2869 (let ((org-agenda-overriding-arguments
2870 (if (eq org-agenda-overriding-cmd org-cmd)
2871 (or org-agenda-overriding-arguments
2872 org-agenda-overriding-cmd-arguments))))
2873 (cond
2874 ((eq type 'agenda)
2875 (org-let2 gprops lprops
2876 '(call-interactively 'org-agenda-list)))
2877 ((eq type 'alltodo)
2878 (org-let2 gprops lprops
2879 '(call-interactively 'org-todo-list)))
2880 ((eq type 'search)
2881 (org-let2 gprops lprops
2882 '(org-search-view current-prefix-arg match nil)))
2883 ((eq type 'stuck)
2884 (org-let2 gprops lprops
2885 '(call-interactively 'org-agenda-list-stuck-projects)))
2886 ((eq type 'tags)
2887 (org-let2 gprops lprops
2888 '(org-tags-view current-prefix-arg match)))
2889 ((eq type 'tags-todo)
2890 (org-let2 gprops lprops
2891 '(org-tags-view '(4) match)))
2892 ((eq type 'todo)
2893 (org-let2 gprops lprops
2894 '(org-todo-list match)))
2895 ((fboundp type)
2896 (org-let2 gprops lprops
2897 '(funcall type match)))
2898 (t (error "Invalid type in command series")))))
2899 (widen)
2900 (let ((inhibit-read-only t))
2901 (add-text-properties (point-min) (point-max)
2902 `(org-series t org-series-redo-cmd ,redo)))
2903 (setq org-agenda-redo-command redo)
2904 (goto-char (point-min)))
2905 (org-agenda-fit-window-to-buffer)
2906 (org-let (nth 1 series) '(org-agenda-finalize)))
2908 ;;;###autoload
2909 (defmacro org-batch-agenda (cmd-key &rest parameters)
2910 "Run an agenda command in batch mode and send the result to STDOUT.
2911 If CMD-KEY is a string of length 1, it is used as a key in
2912 `org-agenda-custom-commands' and triggers this command. If it is a
2913 longer string it is used as a tags/todo match string.
2914 Parameters are alternating variable names and values that will be bound
2915 before running the agenda command."
2916 (org-eval-in-environment (org-make-parameter-alist parameters)
2917 (if (> (length cmd-key) 2)
2918 (org-tags-view nil cmd-key)
2919 (org-agenda nil cmd-key)))
2920 (set-buffer org-agenda-buffer-name)
2921 (princ (buffer-string)))
2923 (autoload 'org-batch-agenda "org-agenda" "\
2924 Run an agenda command in batch mode and send the result to STDOUT.
2925 If CMD-KEY is a string of length 1, it is used as a key in
2926 `org-agenda-custom-commands' and triggers this command. If it is a
2927 longer string it is used as a tags/todo match string.
2928 Parameters are alternating variable names and values that will be bound
2929 before running the agenda command.
2931 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2932 (def-edebug-spec org-batch-agenda (form &rest sexp))
2934 (defvar org-agenda-info nil)
2936 ;;;###autoload
2937 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2938 "Run an agenda command in batch mode and send the result to STDOUT.
2939 If CMD-KEY is a string of length 1, it is used as a key in
2940 `org-agenda-custom-commands' and triggers this command. If it is a
2941 longer string it is used as a tags/todo match string.
2942 Parameters are alternating variable names and values that will be bound
2943 before running the agenda command.
2945 The output gives a line for each selected agenda item. Each
2946 item is a list of comma-separated values, like this:
2948 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2950 category The category of the item
2951 head The headline, without TODO kwd, TAGS and PRIORITY
2952 type The type of the agenda entry, can be
2953 todo selected in TODO match
2954 tagsmatch selected in tags match
2955 diary imported from diary
2956 deadline a deadline on given date
2957 scheduled scheduled on given date
2958 timestamp entry has timestamp on given date
2959 closed entry was closed on given date
2960 upcoming-deadline warning about deadline
2961 past-scheduled forwarded scheduled item
2962 block entry has date block including g. date
2963 todo The todo keyword, if any
2964 tags All tags including inherited ones, separated by colons
2965 date The relevant date, like 2007-2-14
2966 time The time, like 15:00-16:50
2967 extra Sting with extra planning info
2968 priority-l The priority letter if any was given
2969 priority-n The computed numerical priority
2970 agenda-day The day in the agenda where this is listed"
2971 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2972 (org-make-parameter-alist parameters))
2973 (if (> (length cmd-key) 2)
2974 (org-tags-view nil cmd-key)
2975 (org-agenda nil cmd-key)))
2976 (set-buffer org-agenda-buffer-name)
2977 (let* ((lines (org-split-string (buffer-string) "\n"))
2978 line)
2979 (while (setq line (pop lines))
2980 (catch 'next
2981 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2982 (setq org-agenda-info
2983 (org-fix-agenda-info (text-properties-at 0 line)))
2984 (princ
2985 (mapconcat 'org-agenda-export-csv-mapper
2986 '(org-category txt type todo tags date time extra
2987 priority-letter priority agenda-day)
2988 ","))
2989 (princ "\n")))))
2991 (autoload 'org-batch-agenda-csv "org-agenda" "\
2992 Run an agenda command in batch mode and send the result to STDOUT.
2993 If CMD-KEY is a string of length 1, it is used as a key in
2994 `org-agenda-custom-commands' and triggers this command. If it is a
2995 longer string it is used as a tags/todo match string.
2996 Parameters are alternating variable names and values that will be bound
2997 before running the agenda command.
2999 The output gives a line for each selected agenda item. Each
3000 item is a list of comma-separated values, like this:
3002 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3004 category The category of the item
3005 head The headline, without TODO kwd, TAGS and PRIORITY
3006 type The type of the agenda entry, can be
3007 todo selected in TODO match
3008 tagsmatch selected in tags match
3009 diary imported from diary
3010 deadline a deadline on given date
3011 scheduled scheduled on given date
3012 timestamp entry has timestamp on given date
3013 closed entry was closed on given date
3014 upcoming-deadline warning about deadline
3015 past-scheduled forwarded scheduled item
3016 block entry has date block including g. date
3017 todo The todo keyword, if any
3018 tags All tags including inherited ones, separated by colons
3019 date The relevant date, like 2007-2-14
3020 time The time, like 15:00-16:50
3021 extra Sting with extra planning info
3022 priority-l The priority letter if any was given
3023 priority-n The computed numerical priority
3024 agenda-day The day in the agenda where this is listed
3026 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3027 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3029 (defun org-fix-agenda-info (props)
3030 "Make sure all properties on an agenda item have a canonical form.
3031 This ensures the export commands can easily use it."
3032 (let (tmp re)
3033 (when (setq tmp (plist-get props 'tags))
3034 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3035 (when (setq tmp (plist-get props 'date))
3036 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3037 (let ((calendar-date-display-form '(year "-" month "-" day)))
3038 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3040 (setq tmp (calendar-date-string tmp)))
3041 (setq props (plist-put props 'date tmp)))
3042 (when (setq tmp (plist-get props 'day))
3043 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3044 (let ((calendar-date-display-form '(year "-" month "-" day)))
3045 (setq tmp (calendar-date-string tmp)))
3046 (setq props (plist-put props 'day tmp))
3047 (setq props (plist-put props 'agenda-day tmp)))
3048 (when (setq tmp (plist-get props 'txt))
3049 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3050 (plist-put props 'priority-letter (match-string 1 tmp))
3051 (setq tmp (replace-match "" t t tmp)))
3052 (when (and (setq re (plist-get props 'org-todo-regexp))
3053 (setq re (concat "\\`\\.*" re " ?"))
3054 (string-match re tmp))
3055 (plist-put props 'todo (match-string 1 tmp))
3056 (setq tmp (replace-match "" t t tmp)))
3057 (plist-put props 'txt tmp)))
3058 props)
3060 (defun org-agenda-export-csv-mapper (prop)
3061 (let ((res (plist-get org-agenda-info prop)))
3062 (setq res
3063 (cond
3064 ((not res) "")
3065 ((stringp res) res)
3066 (t (prin1-to-string res))))
3067 (while (string-match "," res)
3068 (setq res (replace-match ";" t t res)))
3069 (org-trim res)))
3071 ;;;###autoload
3072 (defun org-store-agenda-views (&rest parameters)
3073 (interactive)
3074 (eval (list 'org-batch-store-agenda-views)))
3076 (autoload 'org-store-agenda-views "org-agenda" "\
3079 \(fn &rest PARAMETERS)" t nil)
3081 ;;;###autoload
3082 (defmacro org-batch-store-agenda-views (&rest parameters)
3083 "Run all custom agenda commands that have a file argument."
3084 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3085 (pop-up-frames nil)
3086 (dir default-directory)
3087 (pars (org-make-parameter-alist parameters))
3088 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3089 (save-window-excursion
3090 (while cmds
3091 (setq cmd (pop cmds)
3092 thiscmdkey (car cmd)
3093 thiscmdcmd (cdr cmd)
3094 match (nth 2 thiscmdcmd)
3095 bufname (if org-agenda-sticky
3096 (or (and (stringp match)
3097 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3098 (format "*Org Agenda(%s)*" thiscmdkey))
3099 org-agenda-buffer-name)
3100 cmd-or-set (nth 2 cmd)
3101 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3102 files (nth (if (listp cmd-or-set) 4 5) cmd))
3103 (if (stringp files) (setq files (list files)))
3104 (when files
3105 (org-eval-in-environment (append org-agenda-exporter-settings
3106 opts pars)
3107 (org-agenda nil thiscmdkey))
3108 (set-buffer bufname)
3109 (while files
3110 (org-eval-in-environment (append org-agenda-exporter-settings
3111 opts pars)
3112 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3113 (and (get-buffer bufname)
3114 (kill-buffer bufname)))))))
3116 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3117 Run all custom agenda commands that have a file argument.
3119 \(fn &rest PARAMETERS)" nil t)
3120 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3122 (defvar org-agenda-current-span nil
3123 "The current span used in the agenda view.") ; local variable in the agenda buffer
3124 (defun org-agenda-mark-header-line (pos)
3125 "Mark the line at POS as an agenda structure header."
3126 (save-excursion
3127 (goto-char pos)
3128 (put-text-property (point-at-bol) (point-at-eol)
3129 'org-agenda-structural-header t)
3130 (when org-agenda-title-append
3131 (put-text-property (point-at-bol) (point-at-eol)
3132 'org-agenda-title-append org-agenda-title-append))))
3134 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3135 (defvar org-agenda-write-buffer-name "Agenda View")
3136 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3137 "Write the current buffer (an agenda view) as a file.
3138 Depending on the extension of the file name, plain text (.txt),
3139 HTML (.html or .htm) or Postscript (.ps) is produced.
3140 If the extension is .ics, run icalendar export over all files used
3141 to construct the agenda and limit the export to entries listed in the
3142 agenda now.
3143 With prefix argument OPEN, open the new file immediately.
3144 If NOSETTINGS is given, do not scope the settings of
3145 `org-agenda-exporter-settings' into the export commands. This is used when
3146 the settings have already been scoped and we do not wish to overrule other,
3147 higher priority settings.
3148 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3149 (interactive "FWrite agenda to file: \nP")
3150 (if (not (file-writable-p file))
3151 (error "Cannot write agenda to file %s" file))
3152 (org-let (if nosettings nil org-agenda-exporter-settings)
3153 '(save-excursion
3154 (save-window-excursion
3155 (org-agenda-mark-filtered-text)
3156 (let ((bs (copy-sequence (buffer-string))) beg)
3157 (org-agenda-unmark-filtered-text)
3158 (with-temp-buffer
3159 (rename-buffer org-agenda-write-buffer-name t)
3160 (set-buffer-modified-p nil)
3161 (insert bs)
3162 (org-agenda-remove-marked-text 'org-filtered)
3163 (while (setq beg (text-property-any (point-min) (point-max)
3164 'org-filtered t))
3165 (delete-region
3166 beg (or (next-single-property-change beg 'org-filtered)
3167 (point-max))))
3168 (run-hooks 'org-agenda-before-write-hook)
3169 (cond
3170 ((org-bound-and-true-p org-mobile-creating-agendas)
3171 (org-mobile-write-agenda-for-mobile file))
3172 ((string-match "\\.html?\\'" file)
3173 (require 'htmlize)
3174 (set-buffer (htmlize-buffer (current-buffer)))
3175 (when org-agenda-export-html-style
3176 ;; replace <style> section with org-agenda-export-html-style
3177 (goto-char (point-min))
3178 (kill-region (- (search-forward "<style") 6)
3179 (search-forward "</style>"))
3180 (insert org-agenda-export-html-style))
3181 (write-file file)
3182 (kill-buffer (current-buffer))
3183 (message "HTML written to %s" file))
3184 ((string-match "\\.ps\\'" file)
3185 (require 'ps-print)
3186 (ps-print-buffer-with-faces file)
3187 (message "Postscript written to %s" file))
3188 ((string-match "\\.pdf\\'" file)
3189 (require 'ps-print)
3190 (ps-print-buffer-with-faces
3191 (concat (file-name-sans-extension file) ".ps"))
3192 (call-process "ps2pdf" nil nil nil
3193 (expand-file-name
3194 (concat (file-name-sans-extension file) ".ps"))
3195 (expand-file-name file))
3196 (delete-file (concat (file-name-sans-extension file) ".ps"))
3197 (message "PDF written to %s" file))
3198 ((string-match "\\.ics\\'" file)
3199 (require 'org-icalendar)
3200 (let ((org-agenda-marker-table
3201 (org-create-marker-find-array
3202 (org-agenda-collect-markers)))
3203 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3204 (org-combined-agenda-icalendar-file file))
3205 (apply 'org-export-icalendar 'combine
3206 (org-agenda-files nil 'ifmode))))
3208 (let ((bs (buffer-string)))
3209 (find-file file)
3210 (erase-buffer)
3211 (insert bs)
3212 (save-buffer 0)
3213 (kill-buffer (current-buffer))
3214 (message "Plain text written to %s" file))))))))
3215 (set-buffer (or agenda-bufname
3216 (and (org-called-interactively-p 'any) (buffer-name))
3217 org-agenda-buffer-name)))
3218 (when open (org-open-file file)))
3220 (defvar org-agenda-tag-filter-overlays nil)
3221 (defvar org-agenda-cat-filter-overlays nil)
3223 (defun org-agenda-mark-filtered-text ()
3224 "Mark all text hidden by filtering with a text property."
3225 (let ((inhibit-read-only t))
3226 (mapc
3227 (lambda (o)
3228 (when (equal (overlay-buffer o) (current-buffer))
3229 (put-text-property
3230 (overlay-start o) (overlay-end o)
3231 'org-filtered t)))
3232 (append org-agenda-tag-filter-overlays
3233 org-agenda-cat-filter-overlays))))
3235 (defun org-agenda-unmark-filtered-text ()
3236 "Remove the filtering text property."
3237 (let ((inhibit-read-only t))
3238 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3240 (defun org-agenda-remove-marked-text (property &optional value)
3241 "Delete all text marked with VALUE of PROPERTY.
3242 VALUE defaults to t."
3243 (let (beg)
3244 (setq value (or value t))
3245 (while (setq beg (text-property-any (point-min) (point-max)
3246 property value))
3247 (delete-region
3248 beg (or (next-single-property-change beg 'org-filtered)
3249 (point-max))))))
3251 (defun org-agenda-add-entry-text ()
3252 "Add entry text to agenda lines.
3253 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3254 entry text following headings shown in the agenda.
3255 Drawers will be excluded, also the line with scheduling/deadline info."
3256 (when (and (> org-agenda-add-entry-text-maxlines 0)
3257 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3258 (let (m txt)
3259 (goto-char (point-min))
3260 (while (not (eobp))
3261 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3262 (beginning-of-line 2)
3263 (setq txt (org-agenda-get-some-entry-text
3264 m org-agenda-add-entry-text-maxlines " > "))
3265 (end-of-line 1)
3266 (if (string-match "\\S-" txt)
3267 (insert "\n" txt)
3268 (or (eobp) (forward-char 1))))))))
3270 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3271 &rest keep)
3272 "Extract entry text from MARKER, at most N-LINES lines.
3273 This will ignore drawers etc, just get the text.
3274 If INDENT is given, prefix every line with this string. If KEEP is
3275 given, it is a list of symbols, defining stuff that should not be
3276 removed from the entry content. Currently only `planning' is allowed here."
3277 (let (txt drawer-re kwd-time-re ind)
3278 (save-excursion
3279 (with-current-buffer (marker-buffer marker)
3280 (if (not (derived-mode-p 'org-mode))
3281 (setq txt "")
3282 (save-excursion
3283 (save-restriction
3284 (widen)
3285 (goto-char marker)
3286 (end-of-line 1)
3287 (setq txt (buffer-substring
3288 (min (1+ (point)) (point-max))
3289 (progn (outline-next-heading) (point)))
3290 drawer-re org-drawer-regexp
3291 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3292 ".*\n?"))
3293 (with-temp-buffer
3294 (insert txt)
3295 (when org-agenda-add-entry-text-descriptive-links
3296 (goto-char (point-min))
3297 (while (org-activate-bracket-links (point-max))
3298 (add-text-properties (match-beginning 0) (match-end 0)
3299 '(face org-link))))
3300 (goto-char (point-min))
3301 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3302 (set-text-properties (match-beginning 0) (match-end 0)
3303 nil))
3304 (goto-char (point-min))
3305 (while (re-search-forward drawer-re nil t)
3306 (delete-region
3307 (match-beginning 0)
3308 (progn (re-search-forward
3309 "^[ \t]*:END:.*\n?" nil 'move)
3310 (point))))
3311 (unless (member 'planning keep)
3312 (goto-char (point-min))
3313 (while (re-search-forward kwd-time-re nil t)
3314 (replace-match "")))
3315 (goto-char (point-min))
3316 (when org-agenda-entry-text-exclude-regexps
3317 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3318 (while (setq re (pop re-list))
3319 (goto-char (point-min))
3320 (while (re-search-forward re nil t)
3321 (replace-match "")))))
3322 (goto-char (point-max))
3323 (skip-chars-backward " \t\n")
3324 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3326 ;; find and remove min common indentation
3327 (goto-char (point-min))
3328 (untabify (point-min) (point-max))
3329 (setq ind (org-get-indentation))
3330 (while (not (eobp))
3331 (unless (looking-at "[ \t]*$")
3332 (setq ind (min ind (org-get-indentation))))
3333 (beginning-of-line 2))
3334 (goto-char (point-min))
3335 (while (not (eobp))
3336 (unless (looking-at "[ \t]*$")
3337 (move-to-column ind)
3338 (delete-region (point-at-bol) (point)))
3339 (beginning-of-line 2))
3341 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3343 (goto-char (point-min))
3344 (when indent
3345 (while (and (not (eobp)) (re-search-forward "^" nil t))
3346 (replace-match indent t t)))
3347 (goto-char (point-min))
3348 (while (looking-at "[ \t]*\n") (replace-match ""))
3349 (goto-char (point-max))
3350 (when (> (org-current-line)
3351 n-lines)
3352 (org-goto-line (1+ n-lines))
3353 (backward-char 1))
3354 (setq txt (buffer-substring (point-min) (point)))))))))
3355 txt))
3357 (defun org-agenda-collect-markers ()
3358 "Collect the markers pointing to entries in the agenda buffer."
3359 (let (m markers)
3360 (save-excursion
3361 (goto-char (point-min))
3362 (while (not (eobp))
3363 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3364 (org-get-at-bol 'org-marker)))
3365 (push m markers))
3366 (beginning-of-line 2)))
3367 (nreverse markers)))
3369 (defun org-create-marker-find-array (marker-list)
3370 "Create a alist of files names with all marker positions in that file."
3371 (let (f tbl m a p)
3372 (while (setq m (pop marker-list))
3373 (setq p (marker-position m)
3374 f (buffer-file-name (or (buffer-base-buffer
3375 (marker-buffer m))
3376 (marker-buffer m))))
3377 (if (setq a (assoc f tbl))
3378 (push (marker-position m) (cdr a))
3379 (push (list f p) tbl)))
3380 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3381 tbl)))
3383 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3384 (defun org-check-agenda-marker-table ()
3385 "Check of the current entry is on the marker list."
3386 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3388 (and (setq a (assoc file org-agenda-marker-table))
3389 (save-match-data
3390 (save-excursion
3391 (org-back-to-heading t)
3392 (member (point) (cdr a)))))))
3394 (defun org-check-for-org-mode ()
3395 "Make sure current buffer is in org-mode. Error if not."
3396 (or (derived-mode-p 'org-mode)
3397 (error "Cannot execute org-mode agenda command on buffer in %s"
3398 major-mode)))
3400 ;;; Agenda prepare and finalize
3402 (defvar org-agenda-multi nil) ; dynamically scoped
3403 (defvar org-agenda-pre-window-conf nil)
3404 (defvar org-agenda-columns-active nil)
3405 (defvar org-agenda-name nil)
3406 (defvar org-agenda-tag-filter nil)
3407 (defvar org-agenda-category-filter nil)
3408 (defvar org-agenda-top-category-filter nil)
3409 (defvar org-agenda-tag-filter-while-redo nil)
3410 (defvar org-agenda-tag-filter-preset nil
3411 "A preset of the tags filter used for secondary agenda filtering.
3412 This must be a list of strings, each string must be a single tag preceded
3413 by \"+\" or \"-\".
3414 This variable should not be set directly, but agenda custom commands can
3415 bind it in the options section. The preset filter is a global property of
3416 the entire agenda view. In a block agenda, it will not work reliably to
3417 define a filter for one of the individual blocks. You need to set it in
3418 the global options and expect it to be applied to the entire view.")
3420 (defvar org-agenda-category-filter-preset nil
3421 "A preset of the category filter used for secondary agenda filtering.
3422 This must be a list of strings, each string must be a single category
3423 preceded by \"+\" or \"-\".
3424 This variable should not be set directly, but agenda custom commands can
3425 bind it in the options section. The preset filter is a global property of
3426 the entire agenda view. In a block agenda, it will not work reliably to
3427 define a filter for one of the individual blocks. You need to set it in
3428 the global options and expect it to be applied to the entire view.")
3431 (defun org-agenda-use-sticky-p ()
3432 "Return non-nil if an agenda buffer named
3433 `org-agenda-buffer-name' exists and should be shown instead of
3434 generating a new one."
3435 (and
3436 ;; turned off by user
3437 org-agenda-sticky
3438 ;; For multi-agenda buffer already exists
3439 (not org-agenda-multi)
3440 ;; buffer found
3441 (get-buffer org-agenda-buffer-name)
3442 ;; C-u parameter is same as last call
3443 (with-current-buffer (get-buffer org-agenda-buffer-name)
3444 (and
3445 (equal current-prefix-arg
3446 org-agenda-last-prefix-arg)
3447 ;; In case user turned stickiness on, while having existing
3448 ;; Agenda buffer active, don't reuse that buffer, because it
3449 ;; does not have org variables local
3450 org-agenda-this-buffer-is-sticky))))
3452 (defun org-agenda-prepare-window (abuf)
3453 "Setup agenda buffer in the window."
3454 (let* ((awin (get-buffer-window abuf))
3455 wconf)
3456 (cond
3457 ((equal (current-buffer) abuf) nil)
3458 (awin (select-window awin))
3459 ((not (setq wconf (current-window-configuration))))
3460 ((equal org-agenda-window-setup 'current-window)
3461 (org-pop-to-buffer-same-window abuf))
3462 ((equal org-agenda-window-setup 'other-window)
3463 (org-switch-to-buffer-other-window abuf))
3464 ((equal org-agenda-window-setup 'other-frame)
3465 (switch-to-buffer-other-frame abuf))
3466 ((equal org-agenda-window-setup 'reorganize-frame)
3467 (delete-other-windows)
3468 (org-switch-to-buffer-other-window abuf)))
3469 ;; additional test in case agenda is invoked from within agenda
3470 ;; buffer via elisp link
3471 (unless (equal (current-buffer) abuf)
3472 (org-pop-to-buffer-same-window abuf))
3473 (setq org-agenda-pre-window-conf
3474 (or org-agenda-pre-window-conf wconf))))
3476 (defun org-agenda-prepare (&optional name)
3477 (if (org-agenda-use-sticky-p)
3478 (progn
3479 ;; Popup existing buffer
3480 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3481 (message "Sticky Agenda buffer, use `r' to refresh")
3482 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3483 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3484 (setq org-todo-keywords-for-agenda nil)
3485 (setq org-drawers-for-agenda nil)
3486 (unless org-agenda-persistent-filter
3487 (setq org-agenda-tag-filter nil
3488 org-agenda-category-filter nil))
3489 (put 'org-agenda-tag-filter :preset-filter
3490 org-agenda-tag-filter-preset)
3491 (put 'org-agenda-category-filter :preset-filter
3492 org-agenda-category-filter-preset)
3493 (if org-agenda-multi
3494 (progn
3495 (setq buffer-read-only nil)
3496 (goto-char (point-max))
3497 (unless (or (bobp) org-agenda-compact-blocks
3498 (not org-agenda-block-separator))
3499 (insert "\n"
3500 (if (stringp org-agenda-block-separator)
3501 org-agenda-block-separator
3502 (make-string (window-width) org-agenda-block-separator))
3503 "\n"))
3504 (narrow-to-region (point) (point-max)))
3505 (setq org-done-keywords-for-agenda nil)
3507 ;; Setting any org variables that are in org-agenda-local-vars
3508 ;; list need to be done after the prepare call
3509 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3510 (setq buffer-read-only nil)
3511 (org-agenda-reset-markers)
3512 (let ((inhibit-read-only t)) (erase-buffer))
3513 (org-agenda-mode)
3514 (setq org-agenda-buffer (current-buffer))
3515 (setq org-agenda-contributing-files nil)
3516 (setq org-agenda-columns-active nil)
3517 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3518 (setq org-todo-keywords-for-agenda
3519 (org-uniquify org-todo-keywords-for-agenda))
3520 (setq org-done-keywords-for-agenda
3521 (org-uniquify org-done-keywords-for-agenda))
3522 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3523 (setq org-agenda-last-prefix-arg current-prefix-arg)
3524 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3525 (and name (not org-agenda-name)
3526 (org-set-local 'org-agenda-name name)))
3527 (setq buffer-read-only nil)))
3529 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3530 (defun org-agenda-finalize ()
3531 "Finishing touch for the agenda buffer, called just before displaying it."
3532 (unless org-agenda-multi
3533 (save-excursion
3534 (let ((inhibit-read-only t))
3535 (goto-char (point-min))
3536 (save-excursion
3537 (while (org-activate-bracket-links (point-max))
3538 (add-text-properties (match-beginning 0) (match-end 0)
3539 '(face org-link))))
3540 (save-excursion
3541 (while (org-activate-plain-links (point-max))
3542 (add-text-properties (match-beginning 0) (match-end 0)
3543 '(face org-link))))
3544 (unless (eq org-agenda-remove-tags t)
3545 (org-agenda-align-tags))
3546 (unless org-agenda-with-colors
3547 (remove-text-properties (point-min) (point-max) '(face nil))))
3548 (if (and (boundp 'org-agenda-overriding-columns-format)
3549 org-agenda-overriding-columns-format)
3550 (org-set-local 'org-agenda-overriding-columns-format
3551 org-agenda-overriding-columns-format))
3552 (if (and (boundp 'org-agenda-view-columns-initially)
3553 org-agenda-view-columns-initially)
3554 (org-agenda-columns))
3555 (when org-agenda-fontify-priorities
3556 (org-agenda-fontify-priorities))
3557 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3558 (org-agenda-dim-blocked-tasks))
3559 ;; We need to widen when `org-agenda-finalize' is called from
3560 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3561 (when org-clock-current-task
3562 (save-restriction
3563 (widen)
3564 (org-agenda-mark-clocking-task)))
3565 (when org-agenda-entry-text-mode
3566 (org-agenda-entry-text-hide)
3567 (org-agenda-entry-text-show))
3568 (if (and (functionp 'org-habit-insert-consistency-graphs)
3569 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3570 (org-habit-insert-consistency-graphs))
3571 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3572 (when (delq nil (mapcar (lambda (tp) (org-agenda-check-type nil tp))
3573 org-agenda-use-tag-inheritance))
3574 (let (mrk)
3575 (save-excursion
3576 (goto-char (point-min))
3577 (while (equal (forward-line) 0)
3578 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3579 (get-text-property (point) 'org-hd-marker)))
3580 (put-text-property (point-at-bol) (point-at-eol)
3581 'tags (org-with-point-at mrk
3582 (delete-dups
3583 (mapcar 'downcase (org-get-tags-at))))))))))
3584 (let ((inhibit-read-only t))
3585 (run-hooks 'org-agenda-finalize-hook))
3586 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3587 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3588 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3589 (org-agenda-filter-apply org-agenda-category-filter 'category))
3590 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3592 (defun org-agenda-mark-clocking-task ()
3593 "Mark the current clock entry in the agenda if it is present."
3594 (mapc (lambda (o)
3595 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3596 (delete-overlay o)))
3597 (overlays-in (point-min) (point-max)))
3598 (when (marker-buffer org-clock-hd-marker)
3599 (save-excursion
3600 (goto-char (point-min))
3601 (let (s ov)
3602 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3603 (goto-char s)
3604 (when (equal (org-get-at-bol 'org-hd-marker)
3605 org-clock-hd-marker)
3606 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3607 (overlay-put ov 'type 'org-agenda-clocking)
3608 (overlay-put ov 'face 'org-agenda-clocking)
3609 (overlay-put ov 'help-echo
3610 "The clock is running in this item")))))))
3612 (defun org-agenda-fontify-priorities ()
3613 "Make highest priority lines bold, and lowest italic."
3614 (interactive)
3615 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3616 (delete-overlay o)))
3617 (overlays-in (point-min) (point-max)))
3618 (save-excursion
3619 (let ((inhibit-read-only t)
3620 b e p ov h l)
3621 (goto-char (point-min))
3622 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3623 (setq h (or (get-char-property (point) 'org-highest-priority)
3624 org-highest-priority)
3625 l (or (get-char-property (point) 'org-lowest-priority)
3626 org-lowest-priority)
3627 p (string-to-char (match-string 1))
3628 b (match-beginning 0)
3629 e (if (eq org-agenda-fontify-priorities 'cookies)
3630 (match-end 0)
3631 (point-at-eol))
3632 ov (make-overlay b e))
3633 (overlay-put
3634 ov 'face
3635 (cond ((org-face-from-face-or-color
3636 'priority nil
3637 (cdr (assoc p org-priority-faces))))
3638 ((and (listp org-agenda-fontify-priorities)
3639 (org-face-from-face-or-color
3640 'priority nil
3641 (cdr (assoc p org-agenda-fontify-priorities)))))
3642 ((equal p l) 'italic)
3643 ((equal p h) 'bold)))
3644 (overlay-put ov 'org-type 'org-priority)))))
3646 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3647 (interactive "P")
3648 "Dim currently blocked TODO's in the agenda display."
3649 (message "Dim or hide blocked tasks...")
3650 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3651 (delete-overlay o)))
3652 (overlays-in (point-min) (point-max)))
3653 (save-excursion
3654 (let ((inhibit-read-only t)
3655 (org-depend-tag-blocked nil)
3656 (invis (or (not (null invisible))
3657 (eq org-agenda-dim-blocked-tasks 'invisible)))
3658 org-blocked-by-checkboxes
3659 invis1 b e p ov h l)
3660 (goto-char (point-min))
3661 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3662 (and pos (goto-char (1+ pos))))
3663 (setq org-blocked-by-checkboxes nil invis1 invis)
3664 (let ((marker (org-get-at-bol 'org-hd-marker)))
3665 (when (and marker
3666 (with-current-buffer (marker-buffer marker)
3667 (save-excursion (goto-char marker)
3668 (org-entry-blocked-p))))
3669 (if org-blocked-by-checkboxes (setq invis1 nil))
3670 (setq b (if invis1
3671 (max (point-min) (1- (point-at-bol)))
3672 (point-at-bol))
3673 e (point-at-eol)
3674 ov (make-overlay b e))
3675 (if invis1
3676 (overlay-put ov 'invisible t)
3677 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3678 (overlay-put ov 'org-type 'org-blocked-todo))))))
3679 (message "Dim or hide blocked tasks...done"))
3681 (defvar org-agenda-skip-function nil
3682 "Function to be called at each match during agenda construction.
3683 If this function returns nil, the current match should not be skipped.
3684 Otherwise, the function must return a position from where the search
3685 should be continued.
3686 This may also be a Lisp form, it will be evaluated.
3687 Never set this variable using `setq' or so, because then it will apply
3688 to all future agenda commands. If you do want a global skipping condition,
3689 use the option `org-agenda-skip-function-global' instead.
3690 The correct usage for `org-agenda-skip-function' is to bind it with
3691 `let' to scope it dynamically into the agenda-constructing command.
3692 A good way to set it is through options in `org-agenda-custom-commands'.")
3694 (defun org-agenda-skip ()
3695 "Throw to `:skip' in places that should be skipped.
3696 Also moves point to the end of the skipped region, so that search can
3697 continue from there."
3698 (let ((p (point-at-bol)) to)
3699 (when (org-in-src-block-p t) (throw :skip t))
3700 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3701 (get-text-property p :org-archived)
3702 (org-end-of-subtree t)
3703 (throw :skip t))
3704 (and org-agenda-skip-comment-trees
3705 (get-text-property p :org-comment)
3706 (org-end-of-subtree t)
3707 (throw :skip t))
3708 (if (equal (char-after p) ?#) (throw :skip t))
3709 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3710 (org-agenda-skip-eval org-agenda-skip-function)))
3711 (goto-char to)
3712 (throw :skip t))))
3714 (defun org-agenda-skip-eval (form)
3715 "If FORM is a function or a list, call (or eval) is and return result.
3716 `save-excursion' and `save-match-data' are wrapped around the call, so point
3717 and match data are returned to the previous state no matter what these
3718 functions do."
3719 (let (fp)
3720 (and form
3721 (or (setq fp (functionp form))
3722 (consp form))
3723 (save-excursion
3724 (save-match-data
3725 (if fp
3726 (funcall form)
3727 (eval form)))))))
3729 (defvar org-agenda-markers nil
3730 "List of all currently active markers created by `org-agenda'.")
3731 (defvar org-agenda-last-marker-time (org-float-time)
3732 "Creation time of the last agenda marker.")
3734 (defun org-agenda-new-marker (&optional pos)
3735 "Return a new agenda marker.
3736 Org-mode keeps a list of these markers and resets them when they are
3737 no longer in use."
3738 (let ((m (copy-marker (or pos (point)))))
3739 (setq org-agenda-last-marker-time (org-float-time))
3740 (if org-agenda-buffer
3741 (with-current-buffer org-agenda-buffer
3742 (push m org-agenda-markers))
3743 (push m org-agenda-markers))
3746 (defun org-agenda-reset-markers ()
3747 "Reset markers created by `org-agenda'."
3748 (while org-agenda-markers
3749 (move-marker (pop org-agenda-markers) nil)))
3751 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3752 "Save relative positions of markers in region.
3753 This check for agenda markers in all agenda buffers currently active."
3754 (dolist (buf (buffer-list))
3755 (with-current-buffer buf
3756 (when (eq major-mode 'org-agenda-mode)
3757 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3758 org-agenda-markers)))))
3760 ;;; Entry text mode
3762 (defun org-agenda-entry-text-show-here ()
3763 "Add some text from the entry as context to the current line."
3764 (let (m txt o)
3765 (setq m (org-get-at-bol 'org-hd-marker))
3766 (unless (marker-buffer m)
3767 (error "No marker points to an entry here"))
3768 (setq txt (concat "\n" (org-no-properties
3769 (org-agenda-get-some-entry-text
3770 m org-agenda-entry-text-maxlines " > "))))
3771 (when (string-match "\\S-" txt)
3772 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3773 (overlay-put o 'evaporate t)
3774 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3775 (overlay-put o 'after-string txt))))
3777 (defun org-agenda-entry-text-show ()
3778 "Add entry context for all agenda lines."
3779 (interactive)
3780 (save-excursion
3781 (goto-char (point-max))
3782 (beginning-of-line 1)
3783 (while (not (bobp))
3784 (when (org-get-at-bol 'org-hd-marker)
3785 (org-agenda-entry-text-show-here))
3786 (beginning-of-line 0))))
3788 (defun org-agenda-entry-text-hide ()
3789 "Remove any shown entry context."
3790 (delq nil
3791 (mapcar (lambda (o)
3792 (if (eq (overlay-get o 'org-overlay-type)
3793 'agenda-entry-content)
3794 (progn (delete-overlay o) t)))
3795 (overlays-in (point-min) (point-max)))))
3797 (defun org-agenda-get-day-face (date)
3798 "Return the face DATE should be displayed with."
3799 (or (and (functionp org-agenda-day-face-function)
3800 (funcall org-agenda-day-face-function date))
3801 (cond ((org-agenda-todayp date)
3802 'org-agenda-date-today)
3803 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3804 'org-agenda-date-weekend)
3805 (t 'org-agenda-date))))
3807 ;;; Agenda timeline
3809 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3811 (defun org-timeline (&optional dotodo)
3812 "Show a time-sorted view of the entries in the current org file.
3813 Only entries with a time stamp of today or later will be listed. With
3814 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3815 under the current date.
3816 If the buffer contains an active region, only check the region for
3817 dates."
3818 (interactive "P")
3819 (let* ((dopast t)
3820 (org-agenda-show-log-scoped org-agenda-show-log)
3821 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3822 (current-buffer))))
3823 (date (calendar-current-date))
3824 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3825 (end (if (org-region-active-p) (region-end) (point-max)))
3826 (day-numbers (org-get-all-dates
3827 beg end 'no-ranges
3828 t org-agenda-show-log-scoped ; always include today
3829 org-timeline-show-empty-dates))
3830 (org-deadline-warning-days 0)
3831 (org-agenda-only-exact-dates t)
3832 (today (org-today))
3833 (past t)
3834 args
3835 s e rtn d emptyp)
3836 (setq org-agenda-redo-command
3837 (list 'progn
3838 (list 'org-switch-to-buffer-other-window (current-buffer))
3839 (list 'org-timeline (list 'quote dotodo))))
3840 (if (not dopast)
3841 ;; Remove past dates from the list of dates.
3842 (setq day-numbers (delq nil (mapcar (lambda(x)
3843 (if (>= x today) x nil))
3844 day-numbers))))
3845 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3846 (org-compile-prefix-format 'timeline)
3847 (org-set-sorting-strategy 'timeline)
3848 (if org-agenda-show-log-scoped (push :closed args))
3849 (push :timestamp args)
3850 (push :deadline args)
3851 (push :scheduled args)
3852 (push :sexp args)
3853 (if dotodo (push :todo args))
3854 (insert "Timeline of file " entry "\n")
3855 (add-text-properties (point-min) (point)
3856 (list 'face 'org-agenda-structure))
3857 (org-agenda-mark-header-line (point-min))
3858 (while (setq d (pop day-numbers))
3859 (if (and (listp d) (eq (car d) :omitted))
3860 (progn
3861 (setq s (point))
3862 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3863 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3864 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3865 (if (and (>= d today)
3866 dopast
3867 past)
3868 (progn
3869 (setq past nil)
3870 (insert (make-string 79 ?-) "\n")))
3871 (setq date (calendar-gregorian-from-absolute d))
3872 (setq s (point))
3873 (setq rtn (and (not emptyp)
3874 (apply 'org-agenda-get-day-entries entry
3875 date args)))
3876 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3877 (progn
3878 (insert
3879 (if (stringp org-agenda-format-date)
3880 (format-time-string org-agenda-format-date
3881 (org-time-from-absolute date))
3882 (funcall org-agenda-format-date date))
3883 "\n")
3884 (put-text-property s (1- (point)) 'face
3885 (org-agenda-get-day-face date))
3886 (put-text-property s (1- (point)) 'org-date-line t)
3887 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3888 (if (equal d today)
3889 (put-text-property s (1- (point)) 'org-today t))
3890 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3891 (put-text-property s (1- (point)) 'day d)))))
3892 (goto-char (point-min))
3893 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3894 (point-min)))
3895 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3896 (org-agenda-finalize)
3897 (setq buffer-read-only t)))
3899 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3900 "Return a list of all relevant day numbers from BEG to END buffer positions.
3901 If NO-RANGES is non-nil, include only the start and end dates of a range,
3902 not every single day in the range. If FORCE-TODAY is non-nil, make
3903 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3904 inactive time stamps (those in square brackets) are included.
3905 When EMPTY is non-nil, also include days without any entries."
3906 (let ((re (concat
3907 (if pre-re pre-re "")
3908 (if inactive org-ts-regexp-both org-ts-regexp)))
3909 dates dates1 date day day1 day2 ts1 ts2 pos)
3910 (if force-today
3911 (setq dates (list (org-today))))
3912 (save-excursion
3913 (goto-char beg)
3914 (while (re-search-forward re end t)
3915 (setq day (time-to-days (org-time-string-to-time
3916 (substring (match-string 1) 0 10)
3917 (current-buffer) (match-beginning 0))))
3918 (or (memq day dates) (push day dates)))
3919 (unless no-ranges
3920 (goto-char beg)
3921 (while (re-search-forward org-tr-regexp end t)
3922 (setq pos (match-beginning 0))
3923 (setq ts1 (substring (match-string 1) 0 10)
3924 ts2 (substring (match-string 2) 0 10)
3925 day1 (time-to-days (org-time-string-to-time
3926 ts1 (current-buffer) pos))
3927 day2 (time-to-days (org-time-string-to-time
3928 ts2 (current-buffer) pos)))
3929 (while (< (setq day1 (1+ day1)) day2)
3930 (or (memq day1 dates) (push day1 dates)))))
3931 (setq dates (sort dates '<))
3932 (when empty
3933 (while (setq day (pop dates))
3934 (setq day2 (car dates))
3935 (push day dates1)
3936 (when (and day2 empty)
3937 (if (or (eq empty t)
3938 (and (numberp empty) (<= (- day2 day) empty)))
3939 (while (< (setq day (1+ day)) day2)
3940 (push (list day) dates1))
3941 (push (cons :omitted (- day2 day)) dates1))))
3942 (setq dates (nreverse dates1)))
3943 dates)))
3945 ;;; Agenda Daily/Weekly
3947 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3948 "Start day for the agenda view.
3949 Custom commands can set this variable in the options section.")
3950 (defvar org-starting-day nil) ; local variable in the agenda buffer
3951 (defvar org-arg-loc nil) ; local variable
3953 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3954 "List of types searched for when creating the daily/weekly agenda.
3955 This variable is a list of symbols that controls the types of
3956 items that appear in the daily/weekly agenda. Allowed symbols in this
3957 list are are
3959 :timestamp List items containing a date stamp or date range matching
3960 the selected date. This includes sexp entries in
3961 angular brackets.
3963 :sexp List entries resulting from plain diary-like sexps.
3965 :deadline List deadline due on that date. When the date is today,
3966 also list any deadlines past due, or due within
3967 `org-deadline-warning-days'. `:deadline' must appear before
3968 `:scheduled' if the setting of
3969 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3970 any effect.
3972 :scheduled List all items which are scheduled for the given date.
3973 The diary for *today* also contains items which were
3974 scheduled earlier and are not yet marked DONE.
3976 By default, all four types are turned on.
3978 Never set this variable globally using `setq', because then it
3979 will apply to all future agenda commands. Instead, bind it with
3980 `let' to scope it dynamically into the agenda-constructing
3981 command. A good way to set it is through options in
3982 `org-agenda-custom-commands'. For a more flexible (though
3983 somewhat less efficient) way of determining what is included in
3984 the daily/weekly agenda, see `org-agenda-skip-function'.")
3986 (defvar org-agenda-buffer-tmp-name nil)
3987 ;;;###autoload
3988 (defun org-agenda-list (&optional arg start-day span)
3989 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3990 The view will be for the current day or week, but from the overview buffer
3991 you will be able to go to other days/weeks.
3993 With a numeric prefix argument in an interactive call, the agenda will
3994 span ARG days. Lisp programs should instead specify SPAN to change
3995 the number of days. SPAN defaults to `org-agenda-span'.
3997 START-DAY defaults to TODAY, or to the most recent match for the weekday
3998 given in `org-agenda-start-on-weekday'."
3999 (interactive "P")
4000 (if org-agenda-overriding-arguments
4001 (setq arg (car org-agenda-overriding-arguments)
4002 start-day (nth 1 org-agenda-overriding-arguments)
4003 span (nth 2 org-agenda-overriding-arguments)))
4004 (if (and (integerp arg) (> arg 0))
4005 (setq span arg arg nil))
4006 (catch 'exit
4007 (setq org-agenda-buffer-name
4008 (or org-agenda-buffer-tmp-name
4009 (if org-agenda-sticky
4010 (cond ((and org-keys (stringp org-match))
4011 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4012 (org-keys
4013 (format "*Org Agenda(%s)*" org-keys))
4014 (t "*Org Agenda(a)*")))
4015 org-agenda-buffer-name))
4016 (org-agenda-prepare "Day/Week")
4017 (setq start-day (or start-day org-agenda-start-day))
4018 (if (stringp start-day)
4019 ;; Convert to an absolute day number
4020 (setq start-day (time-to-days (org-read-date nil t start-day))))
4021 (org-compile-prefix-format 'agenda)
4022 (org-set-sorting-strategy 'agenda)
4023 (let* ((span (org-agenda-ndays-to-span
4024 (or span org-agenda-ndays org-agenda-span)))
4025 (today (org-today))
4026 (sd (or start-day today))
4027 (ndays (org-agenda-span-to-ndays span sd))
4028 (org-agenda-start-on-weekday
4029 (if (eq ndays 7)
4030 org-agenda-start-on-weekday))
4031 (thefiles (org-agenda-files nil 'ifmode))
4032 (files thefiles)
4033 (start (if (or (null org-agenda-start-on-weekday)
4034 (< ndays 7))
4036 (let* ((nt (calendar-day-of-week
4037 (calendar-gregorian-from-absolute sd)))
4038 (n1 org-agenda-start-on-weekday)
4039 (d (- nt n1)))
4040 (- sd (+ (if (< d 0) 7 0) d)))))
4041 (day-numbers (list start))
4042 (day-cnt 0)
4043 (inhibit-redisplay (not debug-on-error))
4044 (org-agenda-show-log-scoped org-agenda-show-log)
4045 s e rtn rtnall file date d start-pos end-pos todayp
4046 clocktable-start clocktable-end filter)
4047 (setq org-agenda-redo-command
4048 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4049 (dotimes (n (1- ndays))
4050 (push (1+ (car day-numbers)) day-numbers))
4051 (setq day-numbers (nreverse day-numbers))
4052 (setq clocktable-start (car day-numbers)
4053 clocktable-end (1+ (or (org-last day-numbers) 0)))
4054 (org-set-local 'org-starting-day (car day-numbers))
4055 (org-set-local 'org-arg-loc arg)
4056 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4057 (unless org-agenda-compact-blocks
4058 (let* ((d1 (car day-numbers))
4059 (d2 (org-last day-numbers))
4060 (w1 (org-days-to-iso-week d1))
4061 (w2 (org-days-to-iso-week d2)))
4062 (setq s (point))
4063 (if org-agenda-overriding-header
4064 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4065 nil 'face 'org-agenda-structure) "\n")
4066 (insert (org-agenda-span-name span)
4067 "-agenda"
4068 (if (< (- d2 d1) 350)
4069 (if (= w1 w2)
4070 (format " (W%02d)" w1)
4071 (format " (W%02d-W%02d)" w1 w2))
4073 ":\n")))
4074 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4075 'org-date-line t))
4076 (org-agenda-mark-header-line s))
4077 (while (setq d (pop day-numbers))
4078 (setq date (calendar-gregorian-from-absolute d)
4079 s (point))
4080 (if (or (setq todayp (= d today))
4081 (and (not start-pos) (= d sd)))
4082 (setq start-pos (point))
4083 (if (and start-pos (not end-pos))
4084 (setq end-pos (point))))
4085 (setq files thefiles
4086 rtnall nil)
4087 (while (setq file (pop files))
4088 (catch 'nextfile
4089 (org-check-agenda-file file)
4090 (let ((org-agenda-entry-types org-agenda-entry-types))
4091 (unless org-agenda-include-deadlines
4092 (setq org-agenda-entry-types
4093 (delq :deadline org-agenda-entry-types)))
4094 (cond
4095 ((memq org-agenda-show-log-scoped '(only clockcheck))
4096 (setq rtn (org-agenda-get-day-entries
4097 file date :closed)))
4098 (org-agenda-show-log-scoped
4099 (setq rtn (apply 'org-agenda-get-day-entries
4100 file date
4101 (append '(:closed) org-agenda-entry-types))))
4103 (setq rtn (apply 'org-agenda-get-day-entries
4104 file date
4105 org-agenda-entry-types)))))
4106 (setq rtnall (append rtnall rtn)))) ;; all entries
4107 (if org-agenda-include-diary
4108 (let ((org-agenda-search-headline-for-time t))
4109 (require 'diary-lib)
4110 (setq rtn (org-get-entries-from-diary date))
4111 (setq rtnall (append rtnall rtn))))
4112 (if (or rtnall org-agenda-show-all-dates)
4113 (progn
4114 (setq day-cnt (1+ day-cnt))
4115 (insert
4116 (if (stringp org-agenda-format-date)
4117 (format-time-string org-agenda-format-date
4118 (org-time-from-absolute date))
4119 (funcall org-agenda-format-date date))
4120 "\n")
4121 (put-text-property s (1- (point)) 'face
4122 (org-agenda-get-day-face date))
4123 (put-text-property s (1- (point)) 'org-date-line t)
4124 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4125 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4126 (when todayp
4127 (put-text-property s (1- (point)) 'org-today t))
4128 (setq rtnall
4129 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4130 (if rtnall (insert ;; all entries
4131 (org-agenda-finalize-entries rtnall)
4132 "\n"))
4133 (put-text-property s (1- (point)) 'day d)
4134 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4135 (when (and org-agenda-clockreport-mode clocktable-start)
4136 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4137 ;; the above line is to ensure the restricted range!
4138 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4139 tbl)
4140 (setq p (org-plist-delete p :block))
4141 (setq p (plist-put p :tstart clocktable-start))
4142 (setq p (plist-put p :tend clocktable-end))
4143 (setq p (plist-put p :scope 'agenda))
4144 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4145 (setq filter (or org-agenda-tag-filter-while-redo
4146 (get 'org-agenda-tag-filter :preset-filter))))
4147 (setq p (plist-put p :tags (mapconcat (lambda (x)
4148 (if (string-match "[<>=]" x)
4151 filter ""))))
4152 (setq tbl (apply 'org-clock-get-clocktable p))
4153 (insert tbl)))
4154 (goto-char (point-min))
4155 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4156 (unless (and (pos-visible-in-window-p (point-min))
4157 (pos-visible-in-window-p (point-max)))
4158 (goto-char (1- (point-max)))
4159 (recenter -1)
4160 (if (not (pos-visible-in-window-p (or start-pos 1)))
4161 (progn
4162 (goto-char (or start-pos 1))
4163 (recenter 1))))
4164 (goto-char (or start-pos 1))
4165 (add-text-properties (point-min) (point-max)
4166 `(org-agenda-type agenda
4167 org-last-args (,arg ,start-day ,span)
4168 org-redo-cmd ,org-agenda-redo-command
4169 org-series-cmd ,org-cmd))
4170 (if (eq org-agenda-show-log-scoped 'clockcheck)
4171 (org-agenda-show-clocking-issues))
4172 (org-agenda-finalize)
4173 (setq buffer-read-only t)
4174 (message ""))))
4176 (autoload 'org-agenda-list "org-agenda" "\
4177 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4178 The view will be for the current day or week, but from the overview buffer
4179 you will be able to go to other days/weeks.
4181 With a numeric prefix argument in an interactive call, the agenda will
4182 span ARG days. Lisp programs should instead specify SPAN to change
4183 the number of days. SPAN defaults to `org-agenda-span'.
4185 START-DAY defaults to TODAY, or to the most recent match for the weekday
4186 given in `org-agenda-start-on-weekday'.
4188 \(fn &optional ARG START-DAY SPAN)" t nil)
4190 (defun org-agenda-ndays-to-span (n)
4191 "Return a span symbol for a span of N days, or N if none matches."
4192 (cond ((symbolp n) n)
4193 ((= n 1) 'day)
4194 ((= n 7) 'week)
4195 (t n)))
4197 (defun org-agenda-span-to-ndays (span &optional start-day)
4198 "Return ndays from SPAN, possibly starting at START-DAY."
4199 (cond ((numberp span) span)
4200 ((eq span 'day) 1)
4201 ((eq span 'week) 7)
4202 ((eq span 'month)
4203 (let ((date (calendar-gregorian-from-absolute start-day)))
4204 (calendar-last-day-of-month (car date) (caddr date))))
4205 ((eq span 'year)
4206 (let ((date (calendar-gregorian-from-absolute start-day)))
4207 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4209 (defun org-agenda-span-name (span)
4210 "Return a SPAN name."
4211 (if (null span)
4213 (if (symbolp span)
4214 (capitalize (symbol-name span))
4215 (format "%d days" span))))
4217 ;;; Agenda word search
4219 (defvar org-agenda-search-history nil)
4221 (defvar org-search-syntax-table nil
4222 "Special syntax table for org-mode search.
4223 In this table, we have single quotes not as word constituents, to
4224 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4226 (defvar org-mode-syntax-table) ; From org.el
4227 (defun org-search-syntax-table ()
4228 (unless org-search-syntax-table
4229 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4230 (modify-syntax-entry ?' "." org-search-syntax-table)
4231 (modify-syntax-entry ?` "." org-search-syntax-table))
4232 org-search-syntax-table)
4234 (defvar org-agenda-last-search-view-search-was-boolean nil)
4236 ;;;###autoload
4237 (defun org-search-view (&optional todo-only string edit-at)
4238 "Show all entries that contain a phrase or words or regular expressions.
4240 With optional prefix argument TODO-ONLY, only consider entries that are
4241 TODO entries. The argument STRING can be used to pass a default search
4242 string into this function. If EDIT-AT is non-nil, it means that the
4243 user should get a chance to edit this string, with cursor at position
4244 EDIT-AT.
4246 The search string can be viewed either as a phrase that should be found as
4247 is, or it can be broken into a number of snippets, each of which must match
4248 in a Boolean way to select an entry. The default depends on the variable
4249 `org-agenda-search-view-always-boolean'.
4250 Even if this is turned off (the default) you can always switch to
4251 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4253 The default is a direct search of the whole phrase, where each space in
4254 the search string can expand to an arbitrary amount of whitespace,
4255 including newlines.
4257 If using a Boolean search, the search string is split on whitespace and
4258 each snippet is searched separately, with logical AND to select an entry.
4259 Words prefixed with a minus must *not* occur in the entry. Words without
4260 a prefix or prefixed with a plus must occur in the entry. Matching is
4261 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4262 match whole words, not parts of a word) if
4263 `org-agenda-search-view-force-full-words' is set (default is nil).
4265 Boolean search snippets enclosed by curly braces are interpreted as
4266 regular expressions that must or (when preceded with \"-\") must not
4267 match in the entry. Snippets enclosed into double quotes will be taken
4268 as a whole, to include whitespace.
4270 - If the search string starts with an asterisk, search only in headlines.
4271 - If (possibly after the leading star) the search string starts with an
4272 exclamation mark, this also means to look at TODO entries only, an effect
4273 that can also be achieved with a prefix argument.
4274 - If (possibly after star and exclamation mark) the search string starts
4275 with a colon, this will mean that the (non-regexp) snippets of the
4276 Boolean search must match as full words.
4278 This command searches the agenda files, and in addition the files listed
4279 in `org-agenda-text-search-extra-files'."
4280 (interactive "P")
4281 (if org-agenda-overriding-arguments
4282 (setq todo-only (car org-agenda-overriding-arguments)
4283 string (nth 1 org-agenda-overriding-arguments)
4284 edit-at (nth 2 org-agenda-overriding-arguments)))
4285 (let* ((props (list 'face nil
4286 'done-face 'org-agenda-done
4287 'org-not-done-regexp org-not-done-regexp
4288 'org-todo-regexp org-todo-regexp
4289 'org-complex-heading-regexp org-complex-heading-regexp
4290 'mouse-face 'highlight
4291 'help-echo (format "mouse-2 or RET jump to location")))
4292 (full-words org-agenda-search-view-force-full-words)
4293 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4294 regexp rtn rtnall files file pos
4295 marker category category-pos tags c neg re boolean
4296 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4297 (unless (and (not edit-at)
4298 (stringp string)
4299 (string-match "\\S-" string))
4300 (setq string (read-string
4301 (if org-agenda-search-view-always-boolean
4302 "[+-]Word/{Regexp} ...: "
4303 "Phrase or [+-]Word/{Regexp} ...: ")
4304 (cond
4305 ((integerp edit-at) (cons string edit-at))
4306 (edit-at string))
4307 'org-agenda-search-history)))
4308 (catch 'exit
4309 (if org-agenda-sticky
4310 (setq org-agenda-buffer-name
4311 (if (stringp string)
4312 (format "*Org Agenda(%s:%s)*"
4313 (or org-keys (or (and todo-only "S") "s")) string)
4314 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4315 (org-agenda-prepare "SEARCH")
4316 (org-compile-prefix-format 'search)
4317 (org-set-sorting-strategy 'search)
4318 (setq org-agenda-redo-command
4319 (list 'org-search-view (if todo-only t nil)
4320 (list 'if 'current-prefix-arg nil string)))
4321 (setq org-agenda-query-string string)
4322 (if (equal (string-to-char string) ?*)
4323 (setq hdl-only t
4324 words (substring string 1))
4325 (setq words string))
4326 (when (equal (string-to-char words) ?!)
4327 (setq todo-only t
4328 words (substring words 1)))
4329 (when (equal (string-to-char words) ?:)
4330 (setq full-words t
4331 words (substring words 1)))
4332 (if (or org-agenda-search-view-always-boolean
4333 (member (string-to-char words) '(?- ?+ ?\{)))
4334 (setq boolean t))
4335 (setq words (org-split-string words))
4336 (let (www w)
4337 (while (setq w (pop words))
4338 (while (and (string-match "\\\\\\'" w) words)
4339 (setq w (concat (substring w 0 -1) " " (pop words))))
4340 (push w www))
4341 (setq words (nreverse www) www nil)
4342 (while (setq w (pop words))
4343 (when (and (string-match "\\`[-+]?{" w)
4344 (not (string-match "}\\'" w)))
4345 (while (and words (not (string-match "}\\'" (car words))))
4346 (setq w (concat w " " (pop words))))
4347 (setq w (concat w " " (pop words))))
4348 (push w www))
4349 (setq words (nreverse www)))
4350 (setq org-agenda-last-search-view-search-was-boolean boolean)
4351 (when boolean
4352 (let (wds w)
4353 (while (setq w (pop words))
4354 (if (or (equal (substring w 0 1) "\"")
4355 (and (> (length w) 1)
4356 (member (substring w 0 1) '("+" "-"))
4357 (equal (substring w 1 2) "\"")))
4358 (while (and words (not (equal (substring w -1) "\"")))
4359 (setq w (concat w " " (pop words)))))
4360 (and (string-match "\\`\\([-+]?\\)\"" w)
4361 (setq w (replace-match "\\1" nil nil w)))
4362 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4363 (push w wds))
4364 (setq words (nreverse wds))))
4365 (if boolean
4366 (mapc (lambda (w)
4367 (setq c (string-to-char w))
4368 (if (equal c ?-)
4369 (setq neg t w (substring w 1))
4370 (if (equal c ?+)
4371 (setq neg nil w (substring w 1))
4372 (setq neg nil)))
4373 (if (string-match "\\`{.*}\\'" w)
4374 (setq re (substring w 1 -1))
4375 (if full-words
4376 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4377 (setq re (regexp-quote (downcase w)))))
4378 (if neg (push re regexps-) (push re regexps+)))
4379 words)
4380 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4381 regexps+))
4382 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4383 (if (not regexps+)
4384 (setq regexp org-outline-regexp-bol)
4385 (setq regexp (pop regexps+))
4386 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4387 regexp))))
4388 (setq files (org-agenda-files nil 'ifmode))
4389 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4390 (pop org-agenda-text-search-extra-files)
4391 (setq files (org-add-archive-files files)))
4392 (setq files (append files org-agenda-text-search-extra-files)
4393 rtnall nil)
4394 (while (setq file (pop files))
4395 (setq ee nil)
4396 (catch 'nextfile
4397 (org-check-agenda-file file)
4398 (setq buffer (if (file-exists-p file)
4399 (org-get-agenda-file-buffer file)
4400 (error "No such file %s" file)))
4401 (if (not buffer)
4402 ;; If file does not exist, make sure an error message is sent
4403 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4404 file))))
4405 (with-current-buffer buffer
4406 (with-syntax-table (org-search-syntax-table)
4407 (unless (derived-mode-p 'org-mode)
4408 (error "Agenda file %s is not in `org-mode'" file))
4409 (let ((case-fold-search t))
4410 (save-excursion
4411 (save-restriction
4412 (if org-agenda-restrict
4413 (narrow-to-region org-agenda-restrict-begin
4414 org-agenda-restrict-end)
4415 (widen))
4416 (goto-char (point-min))
4417 (unless (or (org-at-heading-p)
4418 (outline-next-heading))
4419 (throw 'nextfile t))
4420 (goto-char (max (point-min) (1- (point))))
4421 (while (re-search-forward regexp nil t)
4422 (org-back-to-heading t)
4423 (skip-chars-forward "* ")
4424 (setq beg (point-at-bol)
4425 beg1 (point)
4426 end (progn (outline-next-heading) (point)))
4427 (catch :skip
4428 (goto-char beg)
4429 (org-agenda-skip)
4430 (setq str (buffer-substring-no-properties
4431 (point-at-bol)
4432 (if hdl-only (point-at-eol) end)))
4433 (mapc (lambda (wr) (when (string-match wr str)
4434 (goto-char (1- end))
4435 (throw :skip t)))
4436 regexps-)
4437 (mapc (lambda (wr) (unless (string-match wr str)
4438 (goto-char (1- end))
4439 (throw :skip t)))
4440 (if todo-only
4441 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4442 regexps+)
4443 regexps+))
4444 (goto-char beg)
4445 (setq marker (org-agenda-new-marker (point))
4446 category (org-get-category)
4447 category-pos (get-text-property (point) 'org-category-position)
4448 tags (org-get-tags-at nil t)
4449 txt (org-agenda-format-item
4451 (buffer-substring-no-properties
4452 beg1 (point-at-eol))
4453 category tags t))
4454 (org-add-props txt props
4455 'org-marker marker 'org-hd-marker marker
4456 'org-todo-regexp org-todo-regexp
4457 'org-complex-heading-regexp org-complex-heading-regexp
4458 'priority 1000 'org-category category
4459 'org-category-position category-pos
4460 'type "search")
4461 (push txt ee)
4462 (goto-char (1- end))))))))))
4463 (setq rtn (nreverse ee))
4464 (setq rtnall (append rtnall rtn)))
4465 (if org-agenda-overriding-header
4466 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4467 nil 'face 'org-agenda-structure) "\n")
4468 (insert "Search words: ")
4469 (add-text-properties (point-min) (1- (point))
4470 (list 'face 'org-agenda-structure))
4471 (setq pos (point))
4472 (insert string "\n")
4473 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4474 (setq pos (point))
4475 (unless org-agenda-multi
4476 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4477 (add-text-properties pos (1- (point))
4478 (list 'face 'org-agenda-structure))))
4479 (org-agenda-mark-header-line (point-min))
4480 (when rtnall
4481 (insert (org-agenda-finalize-entries rtnall) "\n"))
4482 (goto-char (point-min))
4483 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4484 (add-text-properties (point-min) (point-max)
4485 `(org-agenda-type search
4486 org-last-args (,todo-only ,string ,edit-at)
4487 org-redo-cmd ,org-agenda-redo-command
4488 org-series-cmd ,org-cmd))
4489 (org-agenda-finalize)
4490 (setq buffer-read-only t))))
4492 (autoload 'org-search-view "org-agenda" "\
4493 Show all entries that contain a phrase or words or regular expressions.
4495 With optional prefix argument TODO-ONLY, only consider entries that are
4496 TODO entries. The argument STRING can be used to pass a default search
4497 string into this function. If EDIT-AT is non-nil, it means that the
4498 user should get a chance to edit this string, with cursor at position
4499 EDIT-AT.
4501 The search string can be viewed either as a phrase that should be found as
4502 is, or it can be broken into a number of snippets, each of which must match
4503 in a Boolean way to select an entry. The default depends on the variable
4504 `org-agenda-search-view-always-boolean'.
4505 Even if this is turned off (the default) you can always switch to
4506 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4508 The default is a direct search of the whole phrase, where each space in
4509 the search string can expand to an arbitrary amount of whitespace,
4510 including newlines.
4512 If using a Boolean search, the search string is split on whitespace and
4513 each snippet is searched separately, with logical AND to select an entry.
4514 Words prefixed with a minus must *not* occur in the entry. Words without
4515 a prefix or prefixed with a plus must occur in the entry. Matching is
4516 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4517 match whole words, not parts of a word) if
4518 `org-agenda-search-view-force-full-words' is set (default is nil).
4520 Boolean search snippets enclosed by curly braces are interpreted as
4521 regular expressions that must or (when preceded with \"-\") must not
4522 match in the entry. Snippets enclosed into double quotes will be taken
4523 as a whole, to include whitespace.
4525 - If the search string starts with an asterisk, search only in headlines.
4526 - If (possibly after the leading star) the search string starts with an
4527 exclamation mark, this also means to look at TODO entries only, an effect
4528 that can also be achieved with a prefix argument.
4529 - If (possibly after star and exclamation mark) the search string starts
4530 with a colon, this will mean that the (non-regexp) snippets of the
4531 Boolean search must match as full words.
4533 This command searches the agenda files, and in addition the files listed
4534 in `org-agenda-text-search-extra-files'.
4536 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4538 ;;; Agenda TODO list
4540 (defvar org-select-this-todo-keyword nil)
4541 (defvar org-last-arg nil)
4543 ;;;###autoload
4544 (defun org-todo-list (&optional arg)
4545 "Show all (not done) TODO entries from all agenda file in a single list.
4546 The prefix arg can be used to select a specific TODO keyword and limit
4547 the list to these. When using \\[universal-argument], you will be prompted
4548 for a keyword. A numeric prefix directly selects the Nth keyword in
4549 `org-todo-keywords-1'."
4550 (interactive "P")
4551 (if org-agenda-overriding-arguments
4552 (setq arg org-agenda-overriding-arguments))
4553 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4554 (let* ((today (org-today))
4555 (date (calendar-gregorian-from-absolute today))
4556 (kwds org-todo-keywords-for-agenda)
4557 (completion-ignore-case t)
4558 (org-select-this-todo-keyword
4559 (if (stringp arg) arg
4560 (and arg (integerp arg) (> arg 0)
4561 (nth (1- arg) kwds))))
4562 rtn rtnall files file pos)
4563 (when (equal arg '(4))
4564 (setq org-select-this-todo-keyword
4565 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4566 (mapcar 'list kwds) nil nil)))
4567 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4568 (catch 'exit
4569 (if org-agenda-sticky
4570 (setq org-agenda-buffer-name
4571 (if (stringp org-select-this-todo-keyword)
4572 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4573 org-select-this-todo-keyword)
4574 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4575 (org-agenda-prepare "TODO")
4576 (org-compile-prefix-format 'todo)
4577 (org-set-sorting-strategy 'todo)
4578 (setq org-agenda-redo-command
4579 `(org-todo-list (or (and (numberp current-prefix-arg)
4580 current-prefix-arg)
4581 ,org-select-this-todo-keyword
4582 current-prefix-arg ,arg)))
4583 (setq files (org-agenda-files nil 'ifmode)
4584 rtnall nil)
4585 (while (setq file (pop files))
4586 (catch 'nextfile
4587 (org-check-agenda-file file)
4588 (setq rtn (org-agenda-get-day-entries file date :todo))
4589 (setq rtnall (append rtnall rtn))))
4590 (if org-agenda-overriding-header
4591 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4592 nil 'face 'org-agenda-structure) "\n")
4593 (insert "Global list of TODO items of type: ")
4594 (add-text-properties (point-min) (1- (point))
4595 (list 'face 'org-agenda-structure
4596 'short-heading
4597 (concat "ToDo: "
4598 (or org-select-this-todo-keyword "ALL"))))
4599 (org-agenda-mark-header-line (point-min))
4600 (setq pos (point))
4601 (insert (or org-select-this-todo-keyword "ALL") "\n")
4602 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4603 (setq pos (point))
4604 (unless org-agenda-multi
4605 (insert "Available with `N r': (0)[ALL]")
4606 (let ((n 0) s)
4607 (mapc (lambda (x)
4608 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4609 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4610 (insert "\n "))
4611 (insert " " s))
4612 kwds))
4613 (insert "\n"))
4614 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4615 (org-agenda-mark-header-line (point-min))
4616 (when rtnall
4617 (insert (org-agenda-finalize-entries rtnall) "\n"))
4618 (goto-char (point-min))
4619 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4620 (add-text-properties (point-min) (point-max)
4621 `(org-agenda-type todo
4622 org-last-args ,arg
4623 org-redo-cmd ,org-agenda-redo-command
4624 org-series-cmd ,org-cmd))
4625 (org-agenda-finalize)
4626 (setq buffer-read-only t))))
4628 (autoload 'org-todo-list "org-agenda" "\
4629 Show all (not done) TODO entries from all agenda file in a single list.
4630 The prefix arg can be used to select a specific TODO keyword and limit
4631 the list to these. When using \\[universal-argument], you will be prompted
4632 for a keyword. A numeric prefix directly selects the Nth keyword in
4633 `org-todo-keywords-1'.
4635 \(fn &optional ARG)" t nil)
4637 ;;; Agenda tags match
4639 ;;;###autoload
4640 (defun org-tags-view (&optional todo-only match)
4641 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4642 The prefix arg TODO-ONLY limits the search to TODO entries."
4643 (interactive "P")
4644 (if org-agenda-overriding-arguments
4645 (setq todo-only (car org-agenda-overriding-arguments)
4646 match (nth 1 org-agenda-overriding-arguments)))
4647 (let* ((org-tags-match-list-sublevels
4648 org-tags-match-list-sublevels)
4649 (completion-ignore-case t)
4650 rtn rtnall files file pos matcher
4651 buffer)
4652 (when (and (stringp match) (not (string-match "\\S-" match)))
4653 (setq match nil))
4654 (setq matcher (org-make-tags-matcher match)
4655 match (car matcher) matcher (cdr matcher))
4656 (catch 'exit
4657 (if org-agenda-sticky
4658 (setq org-agenda-buffer-name
4659 (if (stringp match)
4660 (format "*Org Agenda(%s:%s)*"
4661 (or org-keys (or (and todo-only "M") "m")) match)
4662 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4663 (org-agenda-prepare (concat "TAGS " match))
4664 (org-compile-prefix-format 'tags)
4665 (org-set-sorting-strategy 'tags)
4666 (setq org-agenda-query-string match)
4667 (setq org-agenda-redo-command
4668 (list 'org-tags-view `(quote ,todo-only)
4669 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4670 (setq files (org-agenda-files nil 'ifmode)
4671 rtnall nil)
4672 (while (setq file (pop files))
4673 (catch 'nextfile
4674 (org-check-agenda-file file)
4675 (setq buffer (if (file-exists-p file)
4676 (org-get-agenda-file-buffer file)
4677 (error "No such file %s" file)))
4678 (if (not buffer)
4679 ;; If file does not exist, error message to agenda
4680 (setq rtn (list
4681 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4682 rtnall (append rtnall rtn))
4683 (with-current-buffer buffer
4684 (unless (derived-mode-p 'org-mode)
4685 (error "Agenda file %s is not in `org-mode'" file))
4686 (save-excursion
4687 (save-restriction
4688 (if org-agenda-restrict
4689 (narrow-to-region org-agenda-restrict-begin
4690 org-agenda-restrict-end)
4691 (widen))
4692 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4693 (setq rtnall (append rtnall rtn))))))))
4694 (if org-agenda-overriding-header
4695 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4696 nil 'face 'org-agenda-structure) "\n")
4697 (insert "Headlines with TAGS match: ")
4698 (add-text-properties (point-min) (1- (point))
4699 (list 'face 'org-agenda-structure
4700 'short-heading
4701 (concat "Match: " match)))
4702 (setq pos (point))
4703 (insert match "\n")
4704 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4705 (setq pos (point))
4706 (unless org-agenda-multi
4707 (insert "Press `C-u r' to search again with new search string\n"))
4708 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4709 (org-agenda-mark-header-line (point-min))
4710 (when rtnall
4711 (insert (org-agenda-finalize-entries rtnall) "\n"))
4712 (goto-char (point-min))
4713 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4714 (add-text-properties (point-min) (point-max)
4715 `(org-agenda-type tags
4716 org-last-args (,todo-only ,match)
4717 org-redo-cmd ,org-agenda-redo-command
4718 org-series-cmd ,org-cmd))
4719 (org-agenda-finalize)
4720 (setq buffer-read-only t))))
4722 (autoload 'org-tags-view "org-agenda" "\
4723 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4724 The prefix arg TODO-ONLY limits the search to TODO entries.
4726 \(fn &optional TODO-ONLY MATCH)" t nil)
4728 ;;; Agenda Finding stuck projects
4730 (defvar org-agenda-skip-regexp nil
4731 "Regular expression used in skipping subtrees for the agenda.
4732 This is basically a temporary global variable that can be set and then
4733 used by user-defined selections using `org-agenda-skip-function'.")
4735 (defvar org-agenda-overriding-header nil
4736 "When set during agenda, todo and tags searches it replaces the header.
4737 This variable should not be set directly, but custom commands can bind it
4738 in the options section.")
4740 (defun org-agenda-skip-entry-when-regexp-matches ()
4741 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4742 If yes, it returns the end position of this entry, causing agenda commands
4743 to skip the entry but continuing the search in the subtree. This is a
4744 function that can be put into `org-agenda-skip-function' for the duration
4745 of a command."
4746 (let ((end (save-excursion (org-end-of-subtree t)))
4747 skip)
4748 (save-excursion
4749 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4750 (and skip end)))
4752 (defun org-agenda-skip-subtree-when-regexp-matches ()
4753 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4754 If yes, it returns the end position of this tree, causing agenda commands
4755 to skip this subtree. This is a function that can be put into
4756 `org-agenda-skip-function' for the duration of a command."
4757 (let ((end (save-excursion (org-end-of-subtree t)))
4758 skip)
4759 (save-excursion
4760 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4761 (and skip end)))
4763 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4764 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4765 If yes, it returns the end position of the current entry (NOT the tree),
4766 causing agenda commands to skip the entry but continuing the search in
4767 the subtree. This is a function that can be put into
4768 `org-agenda-skip-function' for the duration of a command. An important
4769 use of this function is for the stuck project list."
4770 (let ((end (save-excursion (org-end-of-subtree t)))
4771 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4772 skip)
4773 (save-excursion
4774 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4775 (and skip entry-end)))
4777 (defun org-agenda-skip-entry-if (&rest conditions)
4778 "Skip entry if any of CONDITIONS is true.
4779 See `org-agenda-skip-if' for details."
4780 (org-agenda-skip-if nil conditions))
4782 (defun org-agenda-skip-subtree-if (&rest conditions)
4783 "Skip entry if any of CONDITIONS is true.
4784 See `org-agenda-skip-if' for details."
4785 (org-agenda-skip-if t conditions))
4787 (defun org-agenda-skip-if (subtree conditions)
4788 "Checks current entity for CONDITIONS.
4789 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4790 the entry (i.e. the text before the next heading) is checked.
4792 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4793 from different tests. Valid conditions are:
4795 scheduled Check if there is a scheduled cookie
4796 notscheduled Check if there is no scheduled cookie
4797 deadline Check if there is a deadline
4798 notdeadline Check if there is no deadline
4799 timestamp Check if there is a timestamp (also deadline or scheduled)
4800 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4801 regexp Check if regexp matches
4802 notregexp Check if regexp does not match.
4803 todo Check if TODO keyword matches
4804 nottodo Check if TODO keyword does not match
4806 The regexp is taken from the conditions list, it must come right after
4807 the `regexp' or `notregexp' element.
4809 `todo' and `nottodo' accept as an argument a list of todo
4810 keywords, which may include \"*\" to match any todo keyword.
4812 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4814 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4816 Instead of a list, a keyword class may be given. For example:
4818 (org-agenda-skip-entry-if 'nottodo 'done)
4820 would skip entries that haven't been marked with any of \"DONE\"
4821 keywords. Possible classes are: `todo', `done', `any'.
4823 If any of these conditions is met, this function returns the end point of
4824 the entity, causing the search to continue from there. This is a function
4825 that can be put into `org-agenda-skip-function' for the duration of a command."
4826 (let (beg end m)
4827 (org-back-to-heading t)
4828 (setq beg (point)
4829 end (if subtree
4830 (progn (org-end-of-subtree t) (point))
4831 (progn (outline-next-heading) (1- (point)))))
4832 (goto-char beg)
4833 (and
4835 (and (memq 'scheduled conditions)
4836 (re-search-forward org-scheduled-time-regexp end t))
4837 (and (memq 'notscheduled conditions)
4838 (not (re-search-forward org-scheduled-time-regexp end t)))
4839 (and (memq 'deadline conditions)
4840 (re-search-forward org-deadline-time-regexp end t))
4841 (and (memq 'notdeadline conditions)
4842 (not (re-search-forward org-deadline-time-regexp end t)))
4843 (and (memq 'timestamp conditions)
4844 (re-search-forward org-ts-regexp end t))
4845 (and (memq 'nottimestamp conditions)
4846 (not (re-search-forward org-ts-regexp end t)))
4847 (and (setq m (memq 'regexp conditions))
4848 (stringp (nth 1 m))
4849 (re-search-forward (nth 1 m) end t))
4850 (and (setq m (memq 'notregexp conditions))
4851 (stringp (nth 1 m))
4852 (not (re-search-forward (nth 1 m) end t)))
4853 (and (or
4854 (setq m (memq 'nottodo conditions))
4855 (setq m (memq 'todo-unblocked conditions))
4856 (setq m (memq 'nottodo-unblocked conditions))
4857 (setq m (memq 'todo conditions)))
4858 (org-agenda-skip-if-todo m end)))
4859 end)))
4861 (defun org-agenda-skip-if-todo (args end)
4862 "Helper function for `org-agenda-skip-if', do not use it directly.
4863 ARGS is a list with first element either `todo', `nottodo',
4864 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4865 a list of TODO keywords, or a state symbol `todo' or `done' or
4866 `any'."
4867 (let ((kw (car args))
4868 (arg (cadr args))
4869 todo-wds todo-re)
4870 (setq todo-wds
4871 (org-uniquify
4872 (cond
4873 ((listp arg) ;; list of keywords
4874 (if (member "*" arg)
4875 (mapcar 'substring-no-properties org-todo-keywords-1)
4876 arg))
4877 ((symbolp arg) ;; keyword class name
4878 (cond
4879 ((eq arg 'todo)
4880 (org-delete-all org-done-keywords
4881 (mapcar 'substring-no-properties
4882 org-todo-keywords-1)))
4883 ((eq arg 'done) org-done-keywords)
4884 ((eq arg 'any)
4885 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4886 (setq todo-re
4887 (concat "^\\*+[ \t]+\\<\\("
4888 (mapconcat 'identity todo-wds "\\|")
4889 "\\)\\>"))
4890 (cond
4891 ((eq kw 'todo) (re-search-forward todo-re end t))
4892 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4893 ((eq kw 'todo-unblocked)
4894 (catch 'unblocked
4895 (while (re-search-forward todo-re end t)
4896 (or (org-entry-blocked-p) (throw 'unblocked t)))
4897 nil))
4898 ((eq kw 'nottodo-unblocked)
4899 (catch 'unblocked
4900 (while (re-search-forward todo-re end t)
4901 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4905 ;;;###autoload
4906 (defun org-agenda-list-stuck-projects (&rest ignore)
4907 "Create agenda view for projects that are stuck.
4908 Stuck projects are project that have no next actions. For the definitions
4909 of what a project is and how to check if it stuck, customize the variable
4910 `org-stuck-projects'."
4911 (interactive)
4912 (let* ((org-agenda-skip-function
4913 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4914 ;; We could have used org-agenda-skip-if here.
4915 (org-agenda-overriding-header
4916 (or org-agenda-overriding-header "List of stuck projects: "))
4917 (matcher (nth 0 org-stuck-projects))
4918 (todo (nth 1 org-stuck-projects))
4919 (todo-wds (if (member "*" todo)
4920 (progn
4921 (org-agenda-prepare-buffers (org-agenda-files
4922 nil 'ifmode))
4923 (org-delete-all
4924 org-done-keywords-for-agenda
4925 (copy-sequence org-todo-keywords-for-agenda)))
4926 todo))
4927 (todo-re (concat "^\\*+[ \t]+\\("
4928 (mapconcat 'identity todo-wds "\\|")
4929 "\\)\\>"))
4930 (tags (nth 2 org-stuck-projects))
4931 (tags-re (if (member "*" tags)
4932 (concat org-outline-regexp-bol
4933 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4934 (if tags
4935 (concat org-outline-regexp-bol
4936 ".*:\\("
4937 (mapconcat 'identity tags "\\|")
4938 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4939 (gen-re (nth 3 org-stuck-projects))
4940 (re-list
4941 (delq nil
4942 (list
4943 (if todo todo-re)
4944 (if tags tags-re)
4945 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4946 gen-re)))))
4947 (setq org-agenda-skip-regexp
4948 (if re-list
4949 (mapconcat 'identity re-list "\\|")
4950 (error "No information how to identify unstuck projects")))
4951 (org-tags-view nil matcher)
4952 (with-current-buffer org-agenda-buffer-name
4953 (setq org-agenda-redo-command
4954 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4956 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4957 Create agenda view for projects that are stuck.
4958 Stuck projects are project that have no next actions. For the definitions
4959 of what a project is and how to check if it stuck, customize the variable
4960 `org-stuck-projects'.
4962 \(fn &rest IGNORE)" t nil)
4964 ;;; Diary integration
4966 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4967 (defvar diary-list-entries-hook)
4968 (defvar diary-time-regexp)
4969 (defun org-get-entries-from-diary (date)
4970 "Get the (Emacs Calendar) diary entries for DATE."
4971 (require 'diary-lib)
4972 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4973 (diary-display-hook '(fancy-diary-display))
4974 (diary-display-function 'fancy-diary-display)
4975 (pop-up-frames nil)
4976 (diary-list-entries-hook
4977 (cons 'org-diary-default-entry diary-list-entries-hook))
4978 (diary-file-name-prefix-function nil) ; turn this feature off
4979 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4980 entries
4981 (org-disable-agenda-to-diary t))
4982 (save-excursion
4983 (save-window-excursion
4984 (funcall (if (fboundp 'diary-list-entries)
4985 'diary-list-entries 'list-diary-entries)
4986 date 1)))
4987 (if (not (get-buffer diary-fancy-buffer))
4988 (setq entries nil)
4989 (with-current-buffer diary-fancy-buffer
4990 (setq buffer-read-only nil)
4991 (if (zerop (buffer-size))
4992 ;; No entries
4993 (setq entries nil)
4994 ;; Omit the date and other unnecessary stuff
4995 (org-agenda-cleanup-fancy-diary)
4996 ;; Add prefix to each line and extend the text properties
4997 (if (zerop (buffer-size))
4998 (setq entries nil)
4999 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5000 (setq entries
5001 (with-temp-buffer
5002 (insert entries) (goto-char (point-min))
5003 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5004 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5005 (replace-match (concat "; " (match-string 1)))))
5006 (buffer-string)))))
5007 (set-buffer-modified-p nil)
5008 (kill-buffer diary-fancy-buffer)))
5009 (when entries
5010 (setq entries (org-split-string entries "\n"))
5011 (setq entries
5012 (mapcar
5013 (lambda (x)
5014 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
5015 ;; Extend the text properties to the beginning of the line
5016 (org-add-props x (text-properties-at (1- (length x)) x)
5017 'type "diary" 'date date 'face 'org-agenda-diary))
5018 entries)))))
5020 (defvar org-agenda-cleanup-fancy-diary-hook nil
5021 "Hook run when the fancy diary buffer is cleaned up.")
5023 (defun org-agenda-cleanup-fancy-diary ()
5024 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5025 This gets rid of the date, the underline under the date, and
5026 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5027 date. It also removes lines that contain only whitespace."
5028 (goto-char (point-min))
5029 (if (looking-at ".*?:[ \t]*")
5030 (progn
5031 (replace-match "")
5032 (re-search-forward "\n=+$" nil t)
5033 (replace-match "")
5034 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5035 (re-search-forward "\n=+$" nil t)
5036 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5037 (goto-char (point-min))
5038 (while (re-search-forward "^ +\n" nil t)
5039 (replace-match ""))
5040 (goto-char (point-min))
5041 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5042 (replace-match ""))
5043 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5045 ;; Make sure entries from the diary have the right text properties.
5046 (eval-after-load "diary-lib"
5047 '(if (boundp 'diary-modify-entry-list-string-function)
5048 ;; We can rely on the hook, nothing to do
5050 ;; Hook not available, must use advice to make this work
5051 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5052 "Make the position visible."
5053 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5054 (stringp string)
5055 buffer-file-name)
5056 (setq string (org-modify-diary-entry-string string))))))
5058 (defun org-modify-diary-entry-string (string)
5059 "Add text properties to string, allowing org-mode to act on it."
5060 (org-add-props string nil
5061 'mouse-face 'highlight
5062 'help-echo (if buffer-file-name
5063 (format "mouse-2 or RET jump to diary file %s"
5064 (abbreviate-file-name buffer-file-name))
5066 'org-agenda-diary-link t
5067 'org-marker (org-agenda-new-marker (point-at-bol))))
5069 (defun org-diary-default-entry ()
5070 "Add a dummy entry to the diary.
5071 Needed to avoid empty dates which mess up holiday display."
5072 ;; Catch the error if dealing with the new add-to-diary-alist
5073 (when org-disable-agenda-to-diary
5074 (condition-case nil
5075 (org-add-to-diary-list original-date "Org-mode dummy" "")
5076 (error
5077 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5079 (defun org-add-to-diary-list (&rest args)
5080 (if (fboundp 'diary-add-to-list)
5081 (apply 'diary-add-to-list args)
5082 (apply 'add-to-diary-list args)))
5084 (defvar org-diary-last-run-time nil)
5086 ;;;###autoload
5087 (defun org-diary (&rest args)
5088 "Return diary information from org files.
5089 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5090 It accesses org files and extracts information from those files to be
5091 listed in the diary. The function accepts arguments specifying what
5092 items should be listed. For a list of arguments allowed here, see the
5093 variable `org-agenda-entry-types'.
5095 The call in the diary file should look like this:
5097 &%%(org-diary) ~/path/to/some/orgfile.org
5099 Use a separate line for each org file to check. Or, if you omit the file name,
5100 all files listed in `org-agenda-files' will be checked automatically:
5102 &%%(org-diary)
5104 If you don't give any arguments (as in the example above), the default
5105 arguments (:deadline :scheduled :timestamp :sexp) are used.
5106 So the example above may also be written as
5108 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5110 The function expects the lisp variables `entry' and `date' to be provided
5111 by the caller, because this is how the calendar works. Don't use this
5112 function from a program - use `org-agenda-get-day-entries' instead."
5113 (when (> (- (org-float-time)
5114 org-agenda-last-marker-time)
5116 ;; I am not sure if this works with sticky agendas, because the marker
5117 ;; list is then no longer a global variable.
5118 (org-agenda-reset-markers))
5119 (org-compile-prefix-format 'agenda)
5120 (org-set-sorting-strategy 'agenda)
5121 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5122 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5123 (list entry)
5124 (org-agenda-files t)))
5125 (time (org-float-time))
5126 file rtn results)
5127 (when (or (not org-diary-last-run-time)
5128 (> (- time
5129 org-diary-last-run-time)
5131 (org-agenda-prepare-buffers files))
5132 (setq org-diary-last-run-time time)
5133 ;; If this is called during org-agenda, don't return any entries to
5134 ;; the calendar. Org Agenda will list these entries itself.
5135 (if org-disable-agenda-to-diary (setq files nil))
5136 (while (setq file (pop files))
5137 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5138 (setq results (append results rtn)))
5139 (if results
5140 (concat (org-agenda-finalize-entries results) "\n"))))
5142 (autoload 'org-diary "org-agenda" "\
5143 Return diary information from org files.
5144 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5145 It accesses org files and extracts information from those files to be
5146 listed in the diary. The function accepts arguments specifying what
5147 items should be listed. For a list of arguments allowed here, see the
5148 variable `org-agenda-entry-types'.
5150 The call in the diary file should look like this:
5152 &%%(org-diary) ~/path/to/some/orgfile.org
5154 Use a separate line for each org file to check. Or, if you omit the file name,
5155 all files listed in `org-agenda-files' will be checked automatically:
5157 &%%(org-diary)
5159 If you don't give any arguments (as in the example above), the default
5160 arguments (:deadline :scheduled :timestamp :sexp) are used.
5161 So the example above may also be written as
5163 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5165 The function expects the lisp variables `entry' and `date' to be provided
5166 by the caller, because this is how the calendar works. Don't use this
5167 function from a program - use `org-agenda-get-day-entries' instead.
5169 \(fn &rest ARGS)" nil nil)
5171 ;;; Agenda entry finders
5173 (defun org-agenda-get-day-entries (file date &rest args)
5174 "Does the work for `org-diary' and `org-agenda'.
5175 FILE is the path to a file to be checked for entries. DATE is date like
5176 the one returned by `calendar-current-date'. ARGS are symbols indicating
5177 which kind of entries should be extracted. For details about these, see
5178 the documentation of `org-diary'."
5179 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5180 (let* ((org-startup-folded nil)
5181 (org-startup-align-all-tables nil)
5182 (buffer (if (file-exists-p file)
5183 (org-get-agenda-file-buffer file)
5184 (error "No such file %s" file)))
5185 arg results rtn deadline-results)
5186 (if (not buffer)
5187 ;; If file does not exist, make sure an error message ends up in diary
5188 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5189 (with-current-buffer buffer
5190 (unless (derived-mode-p 'org-mode)
5191 (error "Agenda file %s is not in `org-mode'" file))
5192 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5193 (let ((case-fold-search nil))
5194 (save-excursion
5195 (save-restriction
5196 (if org-agenda-restrict
5197 (narrow-to-region org-agenda-restrict-begin
5198 org-agenda-restrict-end)
5199 (widen))
5200 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5201 (while (setq arg (pop args))
5202 (cond
5203 ((and (eq arg :todo)
5204 (equal date (calendar-gregorian-from-absolute
5205 (org-today))))
5206 (setq rtn (org-agenda-get-todos))
5207 (setq results (append results rtn)))
5208 ((eq arg :timestamp)
5209 (setq rtn (org-agenda-get-blocks))
5210 (setq results (append results rtn))
5211 (setq rtn (org-agenda-get-timestamps deadline-results))
5212 (setq results (append results rtn)))
5213 ((eq arg :sexp)
5214 (setq rtn (org-agenda-get-sexps))
5215 (setq results (append results rtn)))
5216 ((eq arg :scheduled)
5217 (setq rtn (org-agenda-get-scheduled deadline-results))
5218 (setq results (append results rtn)))
5219 ((eq arg :closed)
5220 (setq rtn (org-agenda-get-progress))
5221 (setq results (append results rtn)))
5222 ((eq arg :deadline)
5223 (setq rtn (org-agenda-get-deadlines))
5224 (setq deadline-results (copy-sequence rtn))
5225 (setq results (append results rtn))))))))
5226 results))))
5228 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5229 (defun org-agenda-get-todos ()
5230 "Return the TODO information for agenda display."
5231 (let* ((props (list 'face nil
5232 'done-face 'org-agenda-done
5233 'org-not-done-regexp org-not-done-regexp
5234 'org-todo-regexp org-todo-regexp
5235 'org-complex-heading-regexp org-complex-heading-regexp
5236 'mouse-face 'highlight
5237 'help-echo
5238 (format "mouse-2 or RET jump to org file %s"
5239 (abbreviate-file-name buffer-file-name))))
5240 (regexp (format org-heading-keyword-regexp-format
5241 (cond
5242 ((and org-select-this-todo-keyword
5243 (equal org-select-this-todo-keyword "*"))
5244 org-todo-regexp)
5245 (org-select-this-todo-keyword
5246 (concat "\\("
5247 (mapconcat 'identity
5248 (org-split-string
5249 org-select-this-todo-keyword
5250 "|")
5251 "\\|") "\\)"))
5252 (t org-not-done-regexp))))
5253 marker priority category category-pos tags todo-state
5254 ee txt beg end)
5255 (goto-char (point-min))
5256 (while (re-search-forward regexp nil t)
5257 (catch :skip
5258 (save-match-data
5259 (beginning-of-line)
5260 (org-agenda-skip)
5261 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5262 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5263 (goto-char (1+ beg))
5264 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5265 (throw :skip nil)))
5266 (goto-char (match-beginning 2))
5267 (setq marker (org-agenda-new-marker (match-beginning 0))
5268 category (org-get-category)
5269 category-pos (get-text-property (point) 'org-category-position)
5270 txt (org-trim
5271 (buffer-substring (match-beginning 2) (match-end 0)))
5272 tags (org-get-tags-at nil t)
5273 txt (org-agenda-format-item "" txt category tags t)
5274 priority (1+ (org-get-priority txt))
5275 todo-state (org-get-todo-state))
5276 (org-add-props txt props
5277 'org-marker marker 'org-hd-marker marker
5278 'priority priority 'org-category category
5279 'org-category-position category-pos
5280 'type "todo" 'todo-state todo-state)
5281 (push txt ee)
5282 (if org-agenda-todo-list-sublevels
5283 (goto-char (match-end 2))
5284 (org-end-of-subtree 'invisible))))
5285 (nreverse ee)))
5287 (defun org-agenda-todo-custom-ignore-p (time n)
5288 "Check whether timestamp is farther away than n number of days.
5289 This function is invoked if `org-agenda-todo-ignore-deadlines',
5290 `org-agenda-todo-ignore-scheduled' or
5291 `org-agenda-todo-ignore-timestamp' is set to an integer."
5292 (let ((days (org-days-to-time time)))
5293 (if (>= n 0)
5294 (>= days n)
5295 (<= days n))))
5297 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5298 (&optional end)
5299 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5300 (when (or org-agenda-todo-ignore-with-date
5301 org-agenda-todo-ignore-scheduled
5302 org-agenda-todo-ignore-deadlines
5303 org-agenda-todo-ignore-timestamp)
5304 (setq end (or end (save-excursion (outline-next-heading) (point))))
5305 (save-excursion
5306 (or (and org-agenda-todo-ignore-with-date
5307 (re-search-forward org-ts-regexp end t))
5308 (and org-agenda-todo-ignore-scheduled
5309 (re-search-forward org-scheduled-time-regexp end t)
5310 (cond
5311 ((eq org-agenda-todo-ignore-scheduled 'future)
5312 (> (org-days-to-time (match-string 1)) 0))
5313 ((eq org-agenda-todo-ignore-scheduled 'past)
5314 (<= (org-days-to-time (match-string 1)) 0))
5315 ((numberp org-agenda-todo-ignore-scheduled)
5316 (org-agenda-todo-custom-ignore-p
5317 (match-string 1) org-agenda-todo-ignore-scheduled))
5318 (t)))
5319 (and org-agenda-todo-ignore-deadlines
5320 (re-search-forward org-deadline-time-regexp end t)
5321 (cond
5322 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5323 ((eq org-agenda-todo-ignore-deadlines 'far)
5324 (not (org-deadline-close (match-string 1))))
5325 ((eq org-agenda-todo-ignore-deadlines 'future)
5326 (> (org-days-to-time (match-string 1)) 0))
5327 ((eq org-agenda-todo-ignore-deadlines 'past)
5328 (<= (org-days-to-time (match-string 1)) 0))
5329 ((numberp org-agenda-todo-ignore-deadlines)
5330 (org-agenda-todo-custom-ignore-p
5331 (match-string 1) org-agenda-todo-ignore-deadlines))
5332 (t (org-deadline-close (match-string 1)))))
5333 (and org-agenda-todo-ignore-timestamp
5334 (let ((buffer (current-buffer))
5335 (regexp
5336 (concat
5337 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5338 (start (point)))
5339 ;; Copy current buffer into a temporary one
5340 (with-temp-buffer
5341 (insert-buffer-substring buffer start end)
5342 (goto-char (point-min))
5343 ;; Delete SCHEDULED and DEADLINE items
5344 (while (re-search-forward regexp end t)
5345 (delete-region (match-beginning 0) (match-end 0)))
5346 (goto-char (point-min))
5347 ;; No search for timestamp left
5348 (when (re-search-forward org-ts-regexp nil t)
5349 (cond
5350 ((eq org-agenda-todo-ignore-timestamp 'future)
5351 (> (org-days-to-time (match-string 1)) 0))
5352 ((eq org-agenda-todo-ignore-timestamp 'past)
5353 (<= (org-days-to-time (match-string 1)) 0))
5354 ((numberp org-agenda-todo-ignore-timestamp)
5355 (org-agenda-todo-custom-ignore-p
5356 (match-string 1) org-agenda-todo-ignore-timestamp))
5357 (t))))))))))
5359 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5360 Do we have a reason to ignore this TODO entry because it has a time stamp?
5362 \(fn &optional END)" nil nil)
5364 (defconst org-agenda-no-heading-message
5365 "No heading for this item in buffer or region.")
5367 (defun org-agenda-get-timestamps (&optional deadline-results)
5368 "Return the date stamp information for agenda display."
5369 (let* ((props (list 'face 'org-agenda-calendar-event
5370 'org-not-done-regexp org-not-done-regexp
5371 'org-todo-regexp org-todo-regexp
5372 'org-complex-heading-regexp org-complex-heading-regexp
5373 'mouse-face 'highlight
5374 'help-echo
5375 (format "mouse-2 or RET jump to org file %s"
5376 (abbreviate-file-name buffer-file-name))))
5377 (d1 (calendar-absolute-from-gregorian date))
5379 (deadline-position-alist
5380 (mapcar (lambda (a) (and (setq mm (get-text-property
5381 0 'org-hd-marker a))
5382 (cons (marker-position mm) a)))
5383 deadline-results))
5384 (remove-re org-ts-regexp)
5385 (regexp
5386 (concat
5387 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5388 (regexp-quote
5389 (substring
5390 (format-time-string
5391 (car org-time-stamp-formats)
5392 (apply 'encode-time ; DATE bound by calendar
5393 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5394 1 11))
5395 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5396 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5397 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5398 donep tmp priority category category-pos ee txt timestr tags
5399 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5400 (goto-char (point-min))
5401 (while (setq end-of-match (re-search-forward regexp nil t))
5402 (setq b0 (match-beginning 0)
5403 b3 (match-beginning 3) e3 (match-end 3)
5404 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5405 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5406 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5407 (member todo-state
5408 org-agenda-repeating-timestamp-show-all)))
5409 (catch :skip
5410 (and (org-at-date-range-p) (throw :skip nil))
5411 (org-agenda-skip)
5412 (if (and (match-end 1)
5413 (not (= d1 (org-time-string-to-absolute
5414 (match-string 1) d1 nil show-all
5415 (current-buffer) b0))))
5416 (throw :skip nil))
5417 (if (and e3
5418 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5419 (throw :skip nil))
5420 (setq tmp (buffer-substring (max (point-min)
5421 (- b0 org-ds-keyword-length))
5423 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5424 inactivep (= (char-after b0) ?\[)
5425 deadlinep (string-match org-deadline-regexp tmp)
5426 scheduledp (string-match org-scheduled-regexp tmp)
5427 closedp (and org-agenda-include-inactive-timestamps
5428 (string-match org-closed-string tmp))
5429 clockp (and org-agenda-include-inactive-timestamps
5430 (or (string-match org-clock-string tmp)
5431 (string-match "]-+\\'" tmp)))
5432 warntime (get-text-property (point) 'org-appt-warntime)
5433 donep (member todo-state org-done-keywords))
5434 (if (or scheduledp deadlinep closedp clockp
5435 (and donep org-agenda-skip-timestamp-if-done))
5436 (throw :skip t))
5437 (if (string-match ">" timestr)
5438 ;; substring should only run to end of time stamp
5439 (setq timestr (substring timestr 0 (match-end 0))))
5440 (setq marker (org-agenda-new-marker b0)
5441 category (org-get-category b0)
5442 category-pos (get-text-property b0 'org-category-position))
5443 (save-excursion
5444 (if (not (re-search-backward org-outline-regexp-bol nil t))
5445 (setq txt org-agenda-no-heading-message)
5446 (goto-char (match-beginning 0))
5447 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5448 (assoc (point) deadline-position-alist))
5449 (throw :skip nil))
5450 (setq hdmarker (org-agenda-new-marker)
5451 tags (org-get-tags-at nil t))
5452 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5453 (setq head (or (match-string 1) ""))
5454 (setq txt (org-agenda-format-item
5455 (if inactivep org-agenda-inactive-leader nil)
5456 head category tags timestr
5457 remove-re habitp)))
5458 (setq priority (org-get-priority txt))
5459 (org-add-props txt props
5460 'org-marker marker 'org-hd-marker hdmarker)
5461 (org-add-props txt nil 'priority priority
5462 'org-category category 'date date
5463 'org-category-position category-pos
5464 'todo-state todo-state
5465 'warntime warntime
5466 'type "timestamp")
5467 (push txt ee))
5468 (if org-agenda-skip-additional-timestamps-same-entry
5469 (outline-next-heading)
5470 (goto-char end-of-match))))
5471 (nreverse ee)))
5473 (defun org-agenda-get-sexps ()
5474 "Return the sexp information for agenda display."
5475 (require 'diary-lib)
5476 (let* ((props (list 'face 'org-agenda-calendar-sexp
5477 'mouse-face 'highlight
5478 'help-echo
5479 (format "mouse-2 or RET jump to org file %s"
5480 (abbreviate-file-name buffer-file-name))))
5481 (regexp "^&?%%(")
5482 marker category extra category-pos ee txt tags entry
5483 result beg b sexp sexp-entry todo-state warntime)
5484 (goto-char (point-min))
5485 (while (re-search-forward regexp nil t)
5486 (catch :skip
5487 (org-agenda-skip)
5488 (setq beg (match-beginning 0))
5489 (goto-char (1- (match-end 0)))
5490 (setq b (point))
5491 (forward-sexp 1)
5492 (setq sexp (buffer-substring b (point)))
5493 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5494 (org-trim (match-string 1))
5495 ""))
5496 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5497 (when result
5498 (setq marker (org-agenda-new-marker beg)
5499 category (org-get-category beg)
5500 category-pos (get-text-property beg 'org-category-position)
5501 tags (save-excursion (org-back-to-heading t) (org-get-tags-at nil t))
5502 todo-state (org-get-todo-state)
5503 warntime (get-text-property (point) 'org-appt-warntime)
5504 extra nil)
5506 (dolist (r (if (stringp result)
5507 (list result)
5508 result)) ;; we expect a list here
5509 (when (and org-agenda-diary-sexp-prefix
5510 (string-match org-agenda-diary-sexp-prefix r))
5511 (setq extra (match-string 0 r)
5512 r (replace-match "" nil nil r)))
5513 (if (string-match "\\S-" r)
5514 (setq txt r)
5515 (setq txt "SEXP entry returned empty string"))
5517 (setq txt (org-agenda-format-item
5518 extra txt category tags 'time))
5519 (org-add-props txt props 'org-marker marker)
5520 (org-add-props txt nil
5521 'org-category category 'date date 'todo-state todo-state
5522 'org-category-position category-pos 'tags tags
5523 'type "sexp" 'warntime warntime)
5524 (push txt ee)))))
5525 (nreverse ee)))
5527 ;; Calendar sanity: define some functions that are independent of
5528 ;; `calendar-date-style'.
5529 ;; Normally I would like to use ISO format when calling the diary functions,
5530 ;; but to make sure we still have Emacs 22 compatibility we bind
5531 ;; also `european-calendar-style' and use european format
5532 (defun org-anniversary (year month day &optional mark)
5533 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5534 (org-no-warnings
5535 (let ((calendar-date-style 'european) (european-calendar-style t))
5536 (diary-anniversary day month year mark))))
5537 (defun org-cyclic (N year month day &optional mark)
5538 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5539 (org-no-warnings
5540 (let ((calendar-date-style 'european) (european-calendar-style t))
5541 (diary-cyclic N day month year mark))))
5542 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5543 "Like `diary-block', but with fixed (ISO) order of arguments."
5544 (org-no-warnings
5545 (let ((calendar-date-style 'european) (european-calendar-style t))
5546 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5547 (defun org-date (year month day &optional mark)
5548 "Like `diary-date', but with fixed (ISO) order of arguments."
5549 (org-no-warnings
5550 (let ((calendar-date-style 'european) (european-calendar-style t))
5551 (diary-date day month year mark))))
5553 ;; Define the` org-class' function
5554 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5555 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5556 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5557 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5558 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5559 `holidays', then any date that is known by the Emacs calendar to be a
5560 holiday will also be skipped."
5561 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5562 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5563 (d (calendar-absolute-from-gregorian date)))
5564 (and
5565 (<= date1 d)
5566 (<= d date2)
5567 (= (calendar-day-of-week date) dayname)
5568 (or (not skip-weeks)
5569 (progn
5570 (require 'cal-iso)
5571 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5572 (not (and (memq 'holidays skip-weeks)
5573 (calendar-check-holidays date)))
5574 entry)))
5576 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5577 "Like `org-class', but honor `calendar-date-style'.
5578 The order of the first 2 times 3 arguments depends on the variable
5579 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5580 So for American calendars, give this as MONTH DAY YEAR, for European as
5581 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5582 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5583 is any number of ISO weeks in the block period for which the item should
5584 be skipped.
5586 This function is here only for backward compatibility and it is deprecated,
5587 please use `org-class' instead."
5588 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5589 (date2 (org-order-calendar-date-args m2 d2 y2)))
5590 (org-class
5591 (nth 2 date1) (car date1) (nth 1 date1)
5592 (nth 2 date2) (car date2) (nth 1 date2)
5593 dayname skip-weeks)))
5594 (make-obsolete 'org-diary-class 'org-class "")
5596 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5597 (defalias 'org-get-closed 'org-agenda-get-progress)
5598 (defun org-agenda-get-progress ()
5599 "Return the logged TODO entries for agenda display."
5600 (let* ((props (list 'mouse-face 'highlight
5601 'org-not-done-regexp org-not-done-regexp
5602 'org-todo-regexp org-todo-regexp
5603 'org-complex-heading-regexp org-complex-heading-regexp
5604 'help-echo
5605 (format "mouse-2 or RET jump to org file %s"
5606 (abbreviate-file-name buffer-file-name))))
5607 (items (if (consp org-agenda-show-log-scoped)
5608 org-agenda-show-log-scoped
5609 (if (eq org-agenda-show-log-scoped 'clockcheck)
5610 '(clock)
5611 org-agenda-log-mode-items)))
5612 (parts
5613 (delq nil
5614 (list
5615 (if (memq 'closed items) (concat "\\<" org-closed-string))
5616 (if (memq 'clock items) (concat "\\<" org-clock-string))
5617 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5618 (parts-re (if parts (mapconcat 'identity parts "\\|")
5619 (error "`org-agenda-log-mode-items' is empty")))
5620 (regexp (concat
5621 "\\(" parts-re "\\)"
5622 " *\\["
5623 (regexp-quote
5624 (substring
5625 (format-time-string
5626 (car org-time-stamp-formats)
5627 (apply 'encode-time ; DATE bound by calendar
5628 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5629 1 11))))
5630 (org-agenda-search-headline-for-time nil)
5631 marker hdmarker priority category category-pos tags closedp
5632 statep clockp state ee txt extra timestr rest clocked)
5633 (goto-char (point-min))
5634 (while (re-search-forward regexp nil t)
5635 (catch :skip
5636 (org-agenda-skip)
5637 (setq marker (org-agenda-new-marker (match-beginning 0))
5638 closedp (equal (match-string 1) org-closed-string)
5639 statep (equal (string-to-char (match-string 1)) ?-)
5640 clockp (not (or closedp statep))
5641 state (and statep (match-string 2))
5642 category (org-get-category (match-beginning 0))
5643 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5644 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5645 (when (string-match "\\]" timestr)
5646 ;; substring should only run to end of time stamp
5647 (setq rest (substring timestr (match-end 0))
5648 timestr (substring timestr 0 (match-end 0)))
5649 (if (and (not closedp) (not statep)
5650 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5651 rest))
5652 (progn (setq timestr (concat (substring timestr 0 -1)
5653 "-" (match-string 1 rest) "]"))
5654 (setq clocked (match-string 2 rest)))
5655 (setq clocked "-")))
5656 (save-excursion
5657 (setq extra
5658 (cond
5659 ((not org-agenda-log-mode-add-notes) nil)
5660 (statep
5661 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5662 (match-string 1)))
5663 (clockp
5664 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5665 (match-string 1)))))
5666 (if (not (re-search-backward org-outline-regexp-bol nil t))
5667 (setq txt org-agenda-no-heading-message)
5668 (goto-char (match-beginning 0))
5669 (setq hdmarker (org-agenda-new-marker)
5670 tags (org-get-tags-at nil t))
5671 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5672 (setq txt (match-string 1))
5673 (when extra
5674 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5675 (setq txt (concat (substring txt 0 (match-beginning 1))
5676 " - " extra " " (match-string 2 txt)))
5677 (setq txt (concat txt " - " extra))))
5678 (setq txt (org-agenda-format-item
5679 (cond
5680 (closedp "Closed: ")
5681 (statep (concat "State: (" state ")"))
5682 (t (concat "Clocked: (" clocked ")")))
5683 txt category tags timestr)))
5684 (setq priority 100000)
5685 (org-add-props txt props
5686 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5687 'priority priority 'org-category category
5688 'org-category-position category-pos
5689 'type "closed" 'date date
5690 'undone-face 'org-warning 'done-face 'org-agenda-done)
5691 (push txt ee))
5692 (goto-char (point-at-eol))))
5693 (nreverse ee)))
5695 (defun org-agenda-show-clocking-issues ()
5696 "Add overlays, showing issues with clocking.
5697 See also the user option `org-agenda-clock-consistency-checks'."
5698 (interactive)
5699 (let* ((pl org-agenda-clock-consistency-checks)
5700 (re (concat "^[ \t]*"
5701 org-clock-string
5702 "[ \t]+"
5703 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5704 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5705 (tlstart 0.)
5706 (tlend 0.)
5707 (maxtime (org-hh:mm-string-to-minutes
5708 (or (plist-get pl :max-duration) "24:00")))
5709 (mintime (org-hh:mm-string-to-minutes
5710 (or (plist-get pl :min-duration) 0)))
5711 (maxgap (org-hh:mm-string-to-minutes
5712 ;; default 30:00 means never complain
5713 (or (plist-get pl :max-gap) "30:00")))
5714 (gapok (mapcar 'org-hh:mm-string-to-minutes
5715 (plist-get pl :gap-ok-around)))
5716 (def-face (or (plist-get pl :default-face)
5717 '((:background "DarkRed") (:foreground "white"))))
5718 issue face m te ts dt ov)
5719 (goto-char (point-min))
5720 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5721 (setq issue nil face def-face)
5722 (catch 'next
5723 (setq m (org-get-at-bol 'org-marker)
5724 te nil ts nil)
5725 (unless (and m (markerp m))
5726 (setq issue "No valid clock line") (throw 'next t))
5727 (org-with-point-at m
5728 (save-excursion
5729 (goto-char (point-at-bol))
5730 (unless (looking-at re)
5731 (error "No valid Clock line")
5732 (throw 'next t))
5733 (unless (match-end 3)
5734 (setq issue "No end time"
5735 face (or (plist-get pl :no-end-time-face) face))
5736 (throw 'next t))
5737 (setq ts (match-string 1)
5738 te (match-string 3)
5739 ts (org-float-time
5740 (apply 'encode-time (org-parse-time-string ts)))
5741 te (org-float-time
5742 (apply 'encode-time (org-parse-time-string te)))
5743 dt (- te ts))))
5744 (cond
5745 ((> dt (* 60 maxtime))
5746 ;; a very long clocking chunk
5747 (setq issue (format "Clocking interval is very long: %s"
5748 (org-minutes-to-hh:mm-string
5749 (floor (/ (float dt) 60.))))
5750 face (or (plist-get pl :long-face) face)))
5751 ((< dt (* 60 mintime))
5752 ;; a very short clocking chunk
5753 (setq issue (format "Clocking interval is very short: %s"
5754 (org-minutes-to-hh:mm-string
5755 (floor (/ (float dt) 60.))))
5756 face (or (plist-get pl :short-face) face)))
5757 ((and (> tlend 0) (< ts tlend))
5758 ;; Two clock entries are overlapping
5759 (setq issue (format "Clocking overlap: %d minutes"
5760 (/ (- tlend ts) 60))
5761 face (or (plist-get pl :overlap-face) face)))
5762 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5763 ;; There is a gap, lets see if we need to report it
5764 (unless (org-agenda-check-clock-gap tlend ts gapok)
5765 (setq issue (format "Clocking gap: %d minutes"
5766 (/ (- ts tlend) 60))
5767 face (or (plist-get pl :gap-face) face))))
5768 (t nil)))
5769 (setq tlend (or te tlend) tlstart (or ts tlstart))
5770 (when issue
5771 ;; OK, there was some issue, add an overlay to show the issue
5772 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5773 (overlay-put ov 'before-string
5774 (concat
5775 (org-add-props
5776 (format "%-43s" (concat " " issue))
5778 'face face)
5779 "\n"))
5780 (overlay-put ov 'evaporate t)))))
5782 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5783 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5784 (catch 'exit
5785 (unless ok-list
5786 ;; there are no OK times for gaps...
5787 (throw 'exit nil))
5788 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5789 ;; This is more than 24 hours, so it is OK.
5790 ;; because we have at least one OK time, that must be in the
5791 ;; 24 hour interval.
5792 (throw 'exit t))
5793 ;; We have a shorter gap.
5794 ;; Now we have to get the minute of the day when these times are
5795 (let* ((t1dec (decode-time (seconds-to-time t1)))
5796 (t2dec (decode-time (seconds-to-time t2)))
5797 ;; compute the minute on the day
5798 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5799 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5800 (when (< min2 min1)
5801 ;; if min2 is smaller than min1, this means it is on the next day.
5802 ;; Wrap it to after midnight.
5803 (setq min2 (+ min2 1440)))
5804 ;; Now check if any of the OK times is in the gap
5805 (mapc (lambda (x)
5806 ;; Wrap the time to after midnight if necessary
5807 (if (< x min1) (setq x (+ x 1440)))
5808 ;; Check if in interval
5809 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5810 ok-list)
5811 ;; Nope, this gap is not OK
5812 nil)))
5814 (defun org-agenda-get-deadlines ()
5815 "Return the deadline information for agenda display."
5816 (let* ((props (list 'mouse-face 'highlight
5817 'org-not-done-regexp org-not-done-regexp
5818 'org-todo-regexp org-todo-regexp
5819 'org-complex-heading-regexp org-complex-heading-regexp
5820 'help-echo
5821 (format "mouse-2 or RET jump to org file %s"
5822 (abbreviate-file-name buffer-file-name))))
5823 (regexp org-deadline-time-regexp)
5824 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5825 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5826 d2 diff dfrac wdays pos pos1 category category-pos
5827 tags suppress-prewarning ee txt head face s todo-state
5828 show-all upcomingp donep timestr warntime)
5829 (goto-char (point-min))
5830 (while (re-search-forward regexp nil t)
5831 (setq suppress-prewarning nil)
5832 (catch :skip
5833 (org-agenda-skip)
5834 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5835 (save-match-data
5836 (string-match org-scheduled-time-regexp
5837 (buffer-substring (point-at-bol)
5838 (point-at-eol)))))
5839 (setq suppress-prewarning
5840 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5841 org-agenda-skip-deadline-prewarning-if-scheduled
5842 0)))
5843 (setq s (match-string 1)
5844 txt nil
5845 pos (1- (match-beginning 1))
5846 todo-state (save-match-data (org-get-todo-state))
5847 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5848 (member todo-state
5849 org-agenda-repeating-timestamp-show-all))
5850 d2 (org-time-string-to-absolute
5851 (match-string 1) d1 'past show-all
5852 (current-buffer) pos)
5853 diff (- d2 d1)
5854 wdays (if suppress-prewarning
5855 (let ((org-deadline-warning-days suppress-prewarning))
5856 (org-get-wdays s))
5857 (org-get-wdays s))
5858 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5859 upcomingp (and todayp (> diff 0)))
5860 ;; When to show a deadline in the calendar:
5861 ;; If the expiration is within wdays warning time.
5862 ;; Past-due deadlines are only shown on the current date
5863 (if (and (or (and (<= diff wdays)
5864 (and todayp (not org-agenda-only-exact-dates)))
5865 (= diff 0)))
5866 (save-excursion
5867 ;; (setq todo-state (org-get-todo-state))
5868 (setq donep (member todo-state org-done-keywords))
5869 (if (and donep
5870 (or org-agenda-skip-deadline-if-done
5871 (not (= diff 0))))
5872 (setq txt nil)
5873 (setq category (org-get-category)
5874 warntime (get-text-property (point) 'org-appt-warntime)
5875 category-pos (get-text-property (point) 'org-category-position))
5876 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5877 (setq txt org-agenda-no-heading-message)
5878 (goto-char (match-end 0))
5879 (setq pos1 (match-beginning 0))
5880 (setq tags (org-get-tags-at pos1 t))
5881 (setq head (buffer-substring-no-properties
5882 (point)
5883 (progn (skip-chars-forward "^\r\n")
5884 (point))))
5885 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5886 (setq timestr
5887 (concat (substring s (match-beginning 1)) " "))
5888 (setq timestr 'time))
5889 (setq txt (org-agenda-format-item
5890 (if (= diff 0)
5891 (car org-agenda-deadline-leaders)
5892 (if (functionp
5893 (nth 1 org-agenda-deadline-leaders))
5894 (funcall
5895 (nth 1 org-agenda-deadline-leaders)
5896 diff date)
5897 (format (nth 1 org-agenda-deadline-leaders)
5898 diff)))
5899 head category tags
5900 (if (not (= diff 0)) nil timestr)))))
5901 (when txt
5902 (setq face (org-agenda-deadline-face dfrac))
5903 (org-add-props txt props
5904 'org-marker (org-agenda-new-marker pos)
5905 'warntime warntime
5906 'org-hd-marker (org-agenda-new-marker pos1)
5907 'priority (+ (- diff)
5908 (org-get-priority txt))
5909 'org-category category
5910 'org-category-position category-pos
5911 'todo-state todo-state
5912 'type (if upcomingp "upcoming-deadline" "deadline")
5913 'date (if upcomingp date d2)
5914 'face (if donep 'org-agenda-done face)
5915 'undone-face face 'done-face 'org-agenda-done)
5916 (push txt ee))))))
5917 (nreverse ee)))
5919 (defun org-agenda-deadline-face (fraction)
5920 "Return the face to displaying a deadline item.
5921 FRACTION is what fraction of the head-warning time has passed."
5922 (let ((faces org-agenda-deadline-faces) f)
5923 (catch 'exit
5924 (while (setq f (pop faces))
5925 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5927 (defun org-agenda-get-scheduled (&optional deadline-results)
5928 "Return the scheduled information for agenda display."
5929 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5930 'org-todo-regexp org-todo-regexp
5931 'org-complex-heading-regexp org-complex-heading-regexp
5932 'done-face 'org-agenda-done
5933 'mouse-face 'highlight
5934 'help-echo
5935 (format "mouse-2 or RET jump to org file %s"
5936 (abbreviate-file-name buffer-file-name))))
5937 (regexp org-scheduled-time-regexp)
5938 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5939 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5941 (deadline-position-alist
5942 (mapcar (lambda (a) (and (setq mm (get-text-property
5943 0 'org-hd-marker a))
5944 (cons (marker-position mm) a)))
5945 deadline-results))
5946 d2 diff pos pos1 category category-pos tags donep
5947 ee txt head pastschedp todo-state face timestr s habitp show-all
5948 did-habit-check-p warntime)
5949 (goto-char (point-min))
5950 (while (re-search-forward regexp nil t)
5951 (catch :skip
5952 (org-agenda-skip)
5953 (setq s (match-string 1)
5954 txt nil
5955 pos (1- (match-beginning 1))
5956 todo-state (save-match-data (org-get-todo-state))
5957 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5958 (member todo-state
5959 org-agenda-repeating-timestamp-show-all))
5960 d2 (org-time-string-to-absolute
5961 (match-string 1) d1 'past show-all
5962 (current-buffer) pos)
5963 diff (- d2 d1)
5964 warntime (get-text-property (point) 'org-appt-warntime))
5965 (setq pastschedp (and todayp (< diff 0)))
5966 (setq did-habit-check-p nil)
5967 ;; When to show a scheduled item in the calendar:
5968 ;; If it is on or past the date.
5969 (when (or (and (< diff 0)
5970 (< (abs diff) org-scheduled-past-days)
5971 (and todayp (not org-agenda-only-exact-dates)))
5972 (= diff 0)
5973 ;; org-is-habit-p uses org-entry-get, which is expansive
5974 ;; so we go extra mile to only call it once
5975 (and todayp
5976 (boundp 'org-habit-show-all-today)
5977 org-habit-show-all-today
5978 (setq did-habit-check-p t)
5979 (setq habitp (and (functionp 'org-is-habit-p)
5980 (org-is-habit-p)))))
5981 (save-excursion
5982 (setq donep (member todo-state org-done-keywords))
5983 (if (and donep
5984 (or org-agenda-skip-scheduled-if-done
5985 (not (= diff 0))
5986 (and (functionp 'org-is-habit-p)
5987 (org-is-habit-p))))
5988 (setq txt nil)
5989 (setq habitp (if did-habit-check-p habitp
5990 (and (functionp 'org-is-habit-p)
5991 (org-is-habit-p))))
5992 (setq category (org-get-category)
5993 category-pos (get-text-property (point) 'org-category-position))
5994 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5995 (setq txt org-agenda-no-heading-message)
5996 (goto-char (match-end 0))
5997 (setq pos1 (match-beginning 0))
5998 (if habitp
5999 (if (or (not org-habit-show-habits)
6000 (and (not todayp)
6001 (boundp 'org-habit-show-habits-only-for-today)
6002 org-habit-show-habits-only-for-today))
6003 (throw :skip nil))
6004 (if (and
6005 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6006 (and org-agenda-skip-scheduled-if-deadline-is-shown
6007 pastschedp))
6008 (setq mm (assoc pos1 deadline-position-alist)))
6009 (throw :skip nil)))
6010 (setq tags (org-get-tags-at nil t))
6011 (setq head (buffer-substring-no-properties
6012 (point)
6013 (progn (skip-chars-forward "^\r\n") (point))))
6014 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6015 (setq timestr
6016 (concat (substring s (match-beginning 1)) " "))
6017 (setq timestr 'time))
6018 (setq txt (org-agenda-format-item
6019 (if (= diff 0)
6020 (car org-agenda-scheduled-leaders)
6021 (format (nth 1 org-agenda-scheduled-leaders)
6022 (- 1 diff)))
6023 head category tags
6024 (if (not (= diff 0)) nil timestr)
6025 nil habitp))))
6026 (when txt
6027 (setq face
6028 (cond
6029 ((and (not habitp) pastschedp)
6030 'org-scheduled-previously)
6031 (todayp 'org-scheduled-today)
6032 (t 'org-scheduled))
6033 habitp (and habitp (org-habit-parse-todo)))
6034 (org-add-props txt props
6035 'undone-face face
6036 'face (if donep 'org-agenda-done face)
6037 'org-marker (org-agenda-new-marker pos)
6038 'org-hd-marker (org-agenda-new-marker pos1)
6039 'type (if pastschedp "past-scheduled" "scheduled")
6040 'date (if pastschedp d2 date)
6041 'warntime warntime
6042 'priority (if habitp
6043 (org-habit-get-priority habitp)
6044 (+ 94 (- 5 diff) (org-get-priority txt)))
6045 'org-category category
6046 'category-position category-pos
6047 'org-habit-p habitp
6048 'todo-state todo-state)
6049 (push txt ee))))))
6050 (nreverse ee)))
6052 (defun org-agenda-get-blocks ()
6053 "Return the date-range information for agenda display."
6054 (let* ((props (list 'face nil
6055 'org-not-done-regexp org-not-done-regexp
6056 'org-todo-regexp org-todo-regexp
6057 'org-complex-heading-regexp org-complex-heading-regexp
6058 'mouse-face 'highlight
6059 'help-echo
6060 (format "mouse-2 or RET jump to org file %s"
6061 (abbreviate-file-name buffer-file-name))))
6062 (regexp org-tr-regexp)
6063 (d0 (calendar-absolute-from-gregorian date))
6064 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6065 todo-state tags pos head donep)
6066 (goto-char (point-min))
6067 (while (re-search-forward regexp nil t)
6068 (catch :skip
6069 (org-agenda-skip)
6070 (setq pos (point))
6071 (let ((start-time (match-string 1))
6072 (end-time (match-string 2)))
6073 (setq s1 (match-string 1)
6074 s2 (match-string 2)
6075 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6076 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6077 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6078 ;; Only allow days between the limits, because the normal
6079 ;; date stamps will catch the limits.
6080 (save-excursion
6081 (setq todo-state (org-get-todo-state))
6082 (setq donep (member todo-state org-done-keywords))
6083 (if (and donep org-agenda-skip-timestamp-if-done)
6084 (throw :skip t))
6085 (setq marker (org-agenda-new-marker (point)))
6086 (setq category (org-get-category)
6087 category-pos (get-text-property (point) 'org-category-position))
6088 (if (not (re-search-backward org-outline-regexp-bol nil t))
6089 (setq txt org-agenda-no-heading-message)
6090 (goto-char (match-beginning 0))
6091 (setq hdmarker (org-agenda-new-marker (point)))
6092 (setq tags (org-get-tags-at nil t))
6093 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6094 (setq head (match-string 1))
6095 (let ((remove-re
6096 (if org-agenda-remove-timeranges-from-blocks
6097 (concat
6098 "<" (regexp-quote s1) ".*?>"
6099 "--"
6100 "<" (regexp-quote s2) ".*?>")
6101 nil)))
6102 (setq txt (org-agenda-format-item
6103 (format
6104 (nth (if (= d1 d2) 0 1)
6105 org-agenda-timerange-leaders)
6106 (1+ (- d0 d1)) (1+ (- d2 d1)))
6107 head category tags
6108 (cond ((and (= d1 d0) (= d2 d0))
6109 (concat "<" start-time ">--<" end-time ">"))
6110 ((= d1 d0)
6111 (concat "<" start-time ">"))
6112 ((= d2 d0)
6113 (concat "<" end-time ">")))
6114 remove-re))))
6115 (org-add-props txt props
6116 'org-marker marker 'org-hd-marker hdmarker
6117 'type "block" 'date date
6118 'todo-state todo-state
6119 'priority (org-get-priority txt) 'org-category category
6120 'org-category-position category-pos)
6121 (push txt ee))))
6122 (goto-char pos)))
6123 ;; Sort the entries by expiration date.
6124 (nreverse ee)))
6126 ;;; Agenda presentation and sorting
6128 (defvar org-prefix-has-time nil
6129 "A flag, set by `org-compile-prefix-format'.
6130 The flag is set if the currently compiled format contains a `%t'.")
6131 (defvar org-prefix-has-tag nil
6132 "A flag, set by `org-compile-prefix-format'.
6133 The flag is set if the currently compiled format contains a `%T'.")
6134 (defvar org-prefix-has-effort nil
6135 "A flag, set by `org-compile-prefix-format'.
6136 The flag is set if the currently compiled format contains a `%e'.")
6137 (defvar org-prefix-category-length nil
6138 "Used by `org-compile-prefix-format' to remember the category field width.")
6139 (defvar org-prefix-category-max-length nil
6140 "Used by `org-compile-prefix-format' to remember the category field width.")
6142 (defun org-agenda-get-category-icon (category)
6143 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6144 (dolist (entry org-agenda-category-icon-alist)
6145 (when (org-string-match-p (car entry) category)
6146 (if (listp (cadr entry))
6147 (return (cadr entry))
6148 (return (apply 'create-image (cdr entry)))))))
6150 (defun org-agenda-format-item (extra txt &optional category tags dotime
6151 remove-re habitp)
6152 "Format TXT to be inserted into the agenda buffer.
6153 In particular, it adds the prefix and corresponding text properties. EXTRA
6154 must be a string and replaces the `%s' specifier in the prefix format.
6155 CATEGORY (string, symbol or nil) may be used to overrule the default
6156 category taken from local variable or file name. It will replace the `%c'
6157 specifier in the format. DOTIME, when non-nil, indicates that a
6158 time-of-day should be extracted from TXT for sorting of this entry, and for
6159 the `%t' specifier in the format. When DOTIME is a string, this string is
6160 searched for a time before TXT is. TAGS can be the tags of the headline.
6161 Any match of REMOVE-RE will be removed from TXT."
6162 ;; We keep the org-prefix-* variable values along with a compiled
6163 ;; formatter, so that multiple agendas existing at the same time, do
6164 ;; not step on each other toes.
6166 ;; It was inconvenient to make these variables buffer local in
6167 ;; Agenda buffers, because this function expects to be called with
6168 ;; the buffer where item comes from being current, and not agenda
6169 ;; buffer
6170 (let* ((bindings (car org-prefix-format-compiled))
6171 (formatter (cadr org-prefix-format-compiled)))
6172 (loop for (var value) in bindings
6173 do (set var value))
6174 (save-match-data
6175 ;; Diary entries sometimes have extra whitespace at the beginning
6176 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
6178 ;; Fix the tags part in txt
6179 (setq txt (org-agenda-fix-displayed-tags
6180 txt tags
6181 org-agenda-show-inherited-tags
6182 org-agenda-hide-tags-regexp))
6183 (let* ((category (or category
6184 (if (stringp org-category)
6185 org-category
6186 (and org-category (symbol-name org-category)))
6187 (if buffer-file-name
6188 (file-name-sans-extension
6189 (file-name-nondirectory buffer-file-name))
6190 "")))
6191 (category-icon (org-agenda-get-category-icon category))
6192 (category-icon (if category-icon
6193 (propertize " " 'display category-icon)
6194 ""))
6195 ;; time, tag, effort are needed for the eval of the prefix format
6196 (tag (if tags (nth (1- (length tags)) tags) ""))
6197 time effort neffort
6198 (ts (if dotime (concat
6199 (if (stringp dotime) dotime "")
6200 (and org-agenda-search-headline-for-time txt))))
6201 (time-of-day (and dotime (org-get-time-of-day ts)))
6202 stamp plain s0 s1 s2 rtn srp l
6203 duration thecategory)
6204 (and (derived-mode-p 'org-mode) buffer-file-name
6205 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6206 (when (and dotime time-of-day)
6207 ;; Extract starting and ending time and move them to prefix
6208 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6209 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6210 (setq s0 (match-string 0 ts)
6211 srp (and stamp (match-end 3))
6212 s1 (match-string (if plain 1 2) ts)
6213 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6215 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6216 ;; them, we might want to remove them there to avoid duplication.
6217 ;; The user can turn this off with a variable.
6218 (if (and org-prefix-has-time
6219 org-agenda-remove-times-when-in-prefix (or stamp plain)
6220 (string-match (concat (regexp-quote s0) " *") txt)
6221 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6222 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6223 (= (match-beginning 0) 0)
6225 (setq txt (replace-match "" nil nil txt))))
6226 ;; Normalize the time(s) to 24 hour
6227 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6228 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6230 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6231 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6232 (setq s2
6233 (org-minutes-to-hh:mm-string
6234 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6236 ;; Compute the duration
6237 (when s2
6238 (setq duration (- (org-hh:mm-string-to-minutes s2)
6239 (org-hh:mm-string-to-minutes s1)))))
6241 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6242 txt)
6243 ;; Tags are in the string
6244 (if (or (eq org-agenda-remove-tags t)
6245 (and org-agenda-remove-tags
6246 org-prefix-has-tag))
6247 (setq txt (replace-match "" t t txt))
6248 (setq txt (replace-match
6249 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6250 (match-string 2 txt))
6251 t t txt))))
6252 (when (derived-mode-p 'org-mode)
6253 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6254 (when effort
6255 (setq neffort (org-duration-string-to-minutes effort)
6256 effort (setq effort (concat "[" effort "]")))))
6257 ;; prevent erroring out with %e format when there is no effort
6258 (or effort (setq effort ""))
6260 (when remove-re
6261 (while (string-match remove-re txt)
6262 (setq txt (replace-match "" t t txt))))
6264 ;; Set org-heading property on `txt' to mark the start of the
6265 ;; heading.
6266 (add-text-properties 0 (length txt) '(org-heading t) txt)
6268 ;; Prepare the variables needed in the eval of the compiled format
6269 (setq time (cond (s2 (concat
6270 (org-agenda-time-of-day-to-ampm-maybe s1)
6271 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6272 (if org-agenda-timegrid-use-ampm " ")))
6273 (s1 (concat
6274 (org-agenda-time-of-day-to-ampm-maybe s1)
6275 (if org-agenda-timegrid-use-ampm
6276 "........ "
6277 "......")))
6278 (t ""))
6279 extra (or (and (not habitp) extra) "")
6280 category (if (symbolp category) (symbol-name category) category)
6281 thecategory (copy-sequence category))
6282 (if (string-match org-bracket-link-regexp category)
6283 (progn
6284 (setq l (if (match-end 3)
6285 (- (match-end 3) (match-beginning 3))
6286 (- (match-end 1) (match-beginning 1))))
6287 (when (< l (or org-prefix-category-length 0))
6288 (setq category (copy-sequence category))
6289 (org-add-props category nil
6290 'extra-space (make-string
6291 (- org-prefix-category-length l 1) ?\ ))))
6292 (if (and org-prefix-category-max-length
6293 (>= (length category) org-prefix-category-max-length))
6294 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6295 ;; Evaluate the compiled format
6296 (setq rtn (concat (eval formatter) txt))
6298 ;; And finally add the text properties
6299 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6300 (org-add-props rtn nil
6301 'org-category (if thecategory (downcase thecategory) category)
6302 'tags (mapcar 'org-downcase-keep-props tags)
6303 'org-highest-priority org-highest-priority
6304 'org-lowest-priority org-lowest-priority
6305 'time-of-day time-of-day
6306 'duration duration
6307 'effort effort
6308 'effort-minutes neffort
6309 'txt txt
6310 'time time
6311 'extra extra
6312 'format org-prefix-format-compiled
6313 'dotime dotime)))))
6315 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6316 "Remove tags string from TXT, and add a modified list of tags.
6317 The modified list may contain inherited tags, and tags matched by
6318 `org-agenda-hide-tags-regexp' will be removed."
6319 (when (or add-inherited hide-re)
6320 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6321 (setq txt (substring txt 0 (match-beginning 0))))
6322 (setq tags
6323 (delq nil
6324 (mapcar (lambda (tg)
6325 (if (or (and hide-re (string-match hide-re tg))
6326 (and (not add-inherited)
6327 (get-text-property 0 'inherited tg)))
6329 tg))
6330 tags)))
6331 (when tags
6332 (let ((have-i (get-text-property 0 'inherited (car tags)))
6334 (setq txt (concat txt " :"
6335 (mapconcat
6336 (lambda (x)
6337 (setq i (get-text-property 0 'inherited x))
6338 (if (and have-i (not i))
6339 (progn
6340 (setq have-i nil)
6341 (concat ":" x))
6343 tags ":")
6344 (if have-i "::" ":"))))))
6345 txt)
6347 (defun org-downcase-keep-props (s)
6348 (let ((props (text-properties-at 0 s)))
6349 (setq s (downcase s))
6350 (add-text-properties 0 (length s) props s)
6353 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6354 (defvar org-agenda-sorting-strategy-selected nil)
6356 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6357 (catch 'exit
6358 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6359 ((and todayp (member 'today (car org-agenda-time-grid))))
6360 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6361 ((member 'weekly (car org-agenda-time-grid)))
6362 (t (throw 'exit list)))
6363 (let* ((have (delq nil (mapcar
6364 (lambda (x) (get-text-property 1 'time-of-day x))
6365 list)))
6366 (string (nth 1 org-agenda-time-grid))
6367 (gridtimes (nth 2 org-agenda-time-grid))
6368 (req (car org-agenda-time-grid))
6369 (remove (member 'remove-match req))
6370 new time)
6371 (if (and (member 'require-timed req) (not have))
6372 ;; don't show empty grid
6373 (throw 'exit list))
6374 (while (setq time (pop gridtimes))
6375 (unless (and remove (member time have))
6376 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6377 (push (org-agenda-format-item
6378 nil string "" nil
6379 (concat (substring time 0 -2) ":" (substring time -2)))
6380 new)
6381 (put-text-property
6382 2 (length (car new)) 'face 'org-time-grid (car new))))
6383 (when (and todayp org-agenda-show-current-time-in-grid)
6384 (push (org-agenda-format-item
6386 org-agenda-current-time-string
6387 "" nil
6388 (format-time-string "%H:%M "))
6389 new)
6390 (put-text-property
6391 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6393 (if (member 'time-up org-agenda-sorting-strategy-selected)
6394 (append new list)
6395 (append list new)))))
6397 (defun org-compile-prefix-format (key)
6398 "Compile the prefix format into a Lisp form that can be evaluated.
6399 The resulting form and associated variable bindings is returned
6400 and stored in the variable `org-prefix-format-compiled'."
6401 (setq org-prefix-has-time nil org-prefix-has-tag nil
6402 org-prefix-category-length nil
6403 org-prefix-has-effort nil)
6404 (let ((s (cond
6405 ((stringp org-agenda-prefix-format)
6406 org-agenda-prefix-format)
6407 ((assq key org-agenda-prefix-format)
6408 (cdr (assq key org-agenda-prefix-format)))
6409 (t " %-12:c%?-12t% s")))
6410 (start 0)
6411 varform vars var e c f opt)
6412 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6413 s start)
6414 (setq var (or (cdr (assoc (match-string 4 s)
6415 '(("c" . category) ("t" . time) ("s" . extra)
6416 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6417 'eval)
6418 c (or (match-string 3 s) "")
6419 opt (match-beginning 1)
6420 start (1+ (match-beginning 0)))
6421 (if (equal var 'time) (setq org-prefix-has-time t))
6422 (if (equal var 'tag) (setq org-prefix-has-tag t))
6423 (if (equal var 'effort) (setq org-prefix-has-effort t))
6424 (setq f (concat "%" (match-string 2 s) "s"))
6425 (when (equal var 'category)
6426 (setq org-prefix-category-length
6427 (floor (abs (string-to-number (match-string 2 s)))))
6428 (setq org-prefix-category-max-length
6429 (let ((x (match-string 2 s)))
6430 (save-match-data
6431 (if (string-match "\\.[0-9]+" x)
6432 (string-to-number (substring (match-string 0 x) 1)))))))
6433 (if (eq var 'eval)
6434 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6435 (if opt
6436 (setq varform
6437 `(if (equal "" ,var)
6439 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6440 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6441 (setq s (replace-match "%s" t nil s))
6442 (push varform vars))
6443 (setq vars (nreverse vars))
6444 (with-current-buffer (or org-agenda-buffer (current-buffer))
6445 (setq org-prefix-format-compiled
6446 (list
6447 `((org-prefix-has-time ,org-prefix-has-time)
6448 (org-prefix-has-tag ,org-prefix-has-tag)
6449 (org-prefix-category-length ,org-prefix-category-length)
6450 (org-prefix-has-effort ,org-prefix-has-effort))
6451 `(format ,s ,@vars))))))
6453 (defun org-set-sorting-strategy (key)
6454 (if (symbolp (car org-agenda-sorting-strategy))
6455 ;; the old format
6456 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6457 (setq org-agenda-sorting-strategy-selected
6458 (or (cdr (assq key org-agenda-sorting-strategy))
6459 (cdr (assq 'agenda org-agenda-sorting-strategy))
6460 '(time-up category-keep priority-down)))))
6462 (defun org-get-time-of-day (s &optional string mod24)
6463 "Check string S for a time of day.
6464 If found, return it as a military time number between 0 and 2400.
6465 If not found, return nil.
6466 The optional STRING argument forces conversion into a 5 character wide string
6467 HH:MM."
6468 (save-match-data
6469 (when
6470 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6471 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6472 (let* ((h (string-to-number (match-string 1 s)))
6473 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6474 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6475 (am-p (equal ampm "am"))
6476 (h1 (cond ((not ampm) h)
6477 ((= h 12) (if am-p 0 12))
6478 (t (+ h (if am-p 0 12)))))
6479 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6480 (mod h1 24) h1))
6481 (t0 (+ (* 100 h2) m))
6482 (t1 (concat (if (>= h1 24) "+" " ")
6483 (if (and org-agenda-time-leading-zero
6484 (< t0 1000)) "0" "")
6485 (if (< t0 100) "0" "")
6486 (if (< t0 10) "0" "")
6487 (int-to-string t0))))
6488 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6490 (defvar org-agenda-before-sorting-filter-function nil
6491 "Function to be applied to agenda items prior to sorting.
6492 Prior to sorting also means just before they are inserted into the agenda.
6494 To aid sorting, you may revisit the original entries and add more text
6495 properties which will later be used by the sorting functions.
6497 The function should take a string argument, an agenda line.
6498 It has access to the text properties in that line, which contain among
6499 other things, the property `org-hd-marker' that points to the entry
6500 where the line comes from. Note that not all lines going into the agenda
6501 have this property, only most.
6503 The function should return the modified string. It is probably best
6504 to ONLY change text properties.
6506 You can also use this function as a filter, by returning nil for lines
6507 you don't want to have in the agenda at all. For this application, you
6508 could bind the variable in the options section of a custom command.")
6510 (defun org-agenda-finalize-entries (list &optional nosort)
6511 "Sort and concatenate the agenda items."
6512 (setq list (mapcar 'org-agenda-highlight-todo list))
6513 (if nosort
6514 list
6515 (when org-agenda-before-sorting-filter-function
6516 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6517 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6519 (defun org-agenda-highlight-todo (x)
6520 (let ((org-done-keywords org-done-keywords-for-agenda)
6521 (case-fold-search nil)
6523 (if (eq x 'line)
6524 (save-excursion
6525 (beginning-of-line 1)
6526 (setq re (org-get-at-bol 'org-todo-regexp))
6527 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6528 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6529 (add-text-properties (match-beginning 0) (match-end 1)
6530 (list 'face (org-get-todo-face 1)))
6531 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6532 (delete-region (match-beginning 1) (1- (match-end 0)))
6533 (goto-char (match-beginning 1))
6534 (insert (format org-agenda-todo-keyword-format s)))))
6535 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6536 (setq re (get-text-property 0 'org-todo-regexp x))
6537 (when (and re
6538 ;; Test `pl' because if there's no heading content,
6539 ;; there's no point matching to highlight. Note
6540 ;; that if we didn't test `pl' first, and there
6541 ;; happened to be no keyword from `org-todo-regexp'
6542 ;; on this heading line, then the `equal' comparison
6543 ;; afterwards would spuriously succeed in the case
6544 ;; where `pl' is nil -- causing an args-out-of-range
6545 ;; error when we try to add text properties to text
6546 ;; that isn't there.
6548 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6549 x pl) pl))
6550 (add-text-properties
6551 (or (match-end 1) (match-end 0)) (match-end 0)
6552 (list 'face (org-get-todo-face (match-string 2 x)))
6554 (when (match-end 1)
6555 (setq x (concat (substring x 0 (match-end 1))
6556 (format org-agenda-todo-keyword-format
6557 (match-string 2 x))
6558 (org-add-props " " (text-properties-at 0 x))
6559 (substring x (match-end 3)))))))
6560 x)))
6562 (defsubst org-cmp-priority (a b)
6563 "Compare the priorities of string A and B."
6564 (let ((pa (or (get-text-property 1 'priority a) 0))
6565 (pb (or (get-text-property 1 'priority b) 0)))
6566 (cond ((> pa pb) +1)
6567 ((< pa pb) -1))))
6569 (defsubst org-cmp-effort (a b)
6570 "Compare the effort values of string A and B."
6571 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6572 (ea (or (get-text-property 1 'effort-minutes a) def))
6573 (eb (or (get-text-property 1 'effort-minutes b) def)))
6574 (cond ((> ea eb) +1)
6575 ((< ea eb) -1))))
6577 (defsubst org-cmp-category (a b)
6578 "Compare the string values of categories of strings A and B."
6579 (let ((ca (or (get-text-property 1 'org-category a) ""))
6580 (cb (or (get-text-property 1 'org-category b) "")))
6581 (cond ((string-lessp ca cb) -1)
6582 ((string-lessp cb ca) +1))))
6584 (defsubst org-cmp-todo-state (a b)
6585 "Compare the todo states of strings A and B."
6586 (let* ((ma (or (get-text-property 1 'org-marker a)
6587 (get-text-property 1 'org-hd-marker a)))
6588 (mb (or (get-text-property 1 'org-marker b)
6589 (get-text-property 1 'org-hd-marker b)))
6590 (fa (and ma (marker-buffer ma)))
6591 (fb (and mb (marker-buffer mb)))
6592 (todo-kwds
6593 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6594 (and fb (with-current-buffer fb org-todo-keywords-1))))
6595 (ta (or (get-text-property 1 'todo-state a) ""))
6596 (tb (or (get-text-property 1 'todo-state b) ""))
6597 (la (- (length (member ta todo-kwds))))
6598 (lb (- (length (member tb todo-kwds))))
6599 (donepa (member ta org-done-keywords-for-agenda))
6600 (donepb (member tb org-done-keywords-for-agenda)))
6601 (cond ((and donepa (not donepb)) -1)
6602 ((and (not donepa) donepb) +1)
6603 ((< la lb) -1)
6604 ((< lb la) +1))))
6606 (defsubst org-cmp-alpha (a b)
6607 "Compare the headlines, alphabetically."
6608 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6609 (plb (text-property-any 0 (length b) 'org-heading t b))
6610 (ta (and pla (substring a pla)))
6611 (tb (and plb (substring b plb))))
6612 (when pla
6613 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6614 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6615 (setq ta (substring ta (match-end 0))))
6616 (setq ta (downcase ta)))
6617 (when plb
6618 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6619 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6620 (setq tb (substring tb (match-end 0))))
6621 (setq tb (downcase tb)))
6622 (cond ((not ta) +1)
6623 ((not tb) -1)
6624 ((string-lessp ta tb) -1)
6625 ((string-lessp tb ta) +1))))
6627 (defsubst org-cmp-tag (a b)
6628 "Compare the string values of the first tags of A and B."
6629 (let ((ta (car (last (get-text-property 1 'tags a))))
6630 (tb (car (last (get-text-property 1 'tags b)))))
6631 (cond ((not ta) +1)
6632 ((not tb) -1)
6633 ((string-lessp ta tb) -1)
6634 ((string-lessp tb ta) +1))))
6636 (defsubst org-cmp-time (a b)
6637 "Compare the time-of-day values of strings A and B."
6638 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6639 (ta (or (get-text-property 1 'time-of-day a) def))
6640 (tb (or (get-text-property 1 'time-of-day b) def)))
6641 (cond ((< ta tb) -1)
6642 ((< tb ta) +1))))
6644 (defsubst org-cmp-habit-p (a b)
6645 "Compare the todo states of strings A and B."
6646 (let ((ha (get-text-property 1 'org-habit-p a))
6647 (hb (get-text-property 1 'org-habit-p b)))
6648 (cond ((and ha (not hb)) -1)
6649 ((and (not ha) hb) +1))))
6651 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6653 (defun org-entries-lessp (a b)
6654 "Predicate for sorting agenda entries."
6655 ;; The following variables will be used when the form is evaluated.
6656 ;; So even though the compiler complains, keep them.
6657 (let* ((ss org-agenda-sorting-strategy-selected)
6658 (time-up (and (org-em 'time-up 'time-down ss)
6659 (org-cmp-time a b)))
6660 (time-down (if time-up (- time-up) nil))
6661 (priority-up (and (org-em 'priority-up 'priority-down ss)
6662 (org-cmp-priority a b)))
6663 (priority-down (if priority-up (- priority-up) nil))
6664 (effort-up (and (org-em 'effort-up 'effort-down ss)
6665 (org-cmp-effort a b)))
6666 (effort-down (if effort-up (- effort-up) nil))
6667 (category-up (and (or (org-em 'category-up 'category-down ss)
6668 (memq 'category-keep ss))
6669 (org-cmp-category a b)))
6670 (category-down (if category-up (- category-up) nil))
6671 (category-keep (if category-up +1 nil))
6672 (tag-up (and (org-em 'tag-up 'tag-down ss)
6673 (org-cmp-tag a b)))
6674 (tag-down (if tag-up (- tag-up) nil))
6675 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6676 (org-cmp-todo-state a b)))
6677 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6678 (habit-up (and (org-em 'habit-up 'habit-down ss)
6679 (org-cmp-habit-p a b)))
6680 (habit-down (if habit-up (- habit-up) nil))
6681 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6682 (org-cmp-alpha a b)))
6683 (alpha-down (if alpha-up (- alpha-up) nil))
6684 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6685 user-defined-up user-defined-down)
6686 (if (and need-user-cmp org-agenda-cmp-user-defined
6687 (functionp org-agenda-cmp-user-defined))
6688 (setq user-defined-up
6689 (funcall org-agenda-cmp-user-defined a b)
6690 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6691 (cdr (assoc
6692 (eval (cons 'or org-agenda-sorting-strategy-selected))
6693 '((-1 . t) (1 . nil) (nil . nil))))))
6695 ;;; Agenda restriction lock
6697 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6698 "Overlay to mark the headline to which agenda commands are restricted.")
6699 (overlay-put org-agenda-restriction-lock-overlay
6700 'face 'org-agenda-restriction-lock)
6701 (overlay-put org-agenda-restriction-lock-overlay
6702 'help-echo "Agendas are currently limited to this subtree.")
6703 (org-detach-overlay org-agenda-restriction-lock-overlay)
6705 (defun org-agenda-set-restriction-lock (&optional type)
6706 "Set restriction lock for agenda, to current subtree or file.
6707 Restriction will be the file if TYPE is `file', or if type is the
6708 universal prefix '(4), or if the cursor is before the first headline
6709 in the file. Otherwise, restriction will be to the current subtree."
6710 (interactive "P")
6711 (and (equal type '(4)) (setq type 'file))
6712 (setq type (cond
6713 (type type)
6714 ((org-at-heading-p) 'subtree)
6715 ((condition-case nil (org-back-to-heading t) (error nil))
6716 'subtree)
6717 (t 'file)))
6718 (if (eq type 'subtree)
6719 (progn
6720 (setq org-agenda-restrict t)
6721 (setq org-agenda-overriding-restriction 'subtree)
6722 (put 'org-agenda-files 'org-restrict
6723 (list (buffer-file-name (buffer-base-buffer))))
6724 (org-back-to-heading t)
6725 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6726 (move-marker org-agenda-restrict-begin (point))
6727 (move-marker org-agenda-restrict-end
6728 (save-excursion (org-end-of-subtree t)))
6729 (message "Locking agenda restriction to subtree"))
6730 (put 'org-agenda-files 'org-restrict
6731 (list (buffer-file-name (buffer-base-buffer))))
6732 (setq org-agenda-restrict nil)
6733 (setq org-agenda-overriding-restriction 'file)
6734 (move-marker org-agenda-restrict-begin nil)
6735 (move-marker org-agenda-restrict-end nil)
6736 (message "Locking agenda restriction to file"))
6737 (setq current-prefix-arg nil)
6738 (org-agenda-maybe-redo))
6740 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6741 "Remove the agenda restriction lock."
6742 (interactive "P")
6743 (org-detach-overlay org-agenda-restriction-lock-overlay)
6744 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6745 (setq org-agenda-overriding-restriction nil)
6746 (setq org-agenda-restrict nil)
6747 (put 'org-agenda-files 'org-restrict nil)
6748 (move-marker org-agenda-restrict-begin nil)
6749 (move-marker org-agenda-restrict-end nil)
6750 (setq current-prefix-arg nil)
6751 (message "Agenda restriction lock removed")
6752 (or noupdate (org-agenda-maybe-redo)))
6754 (defun org-agenda-maybe-redo ()
6755 "If there is any window showing the agenda view, update it."
6756 (let ((w (get-buffer-window org-agenda-buffer-name t))
6757 (w0 (selected-window)))
6758 (when w
6759 (select-window w)
6760 (org-agenda-redo)
6761 (select-window w0)
6762 (if org-agenda-overriding-restriction
6763 (message "Agenda view shifted to new %s restriction"
6764 org-agenda-overriding-restriction)
6765 (message "Agenda restriction lock removed")))))
6767 ;;; Agenda commands
6769 (defun org-agenda-check-type (error &rest types)
6770 "Check if agenda buffer is of allowed type.
6771 If ERROR is non-nil, throw an error, otherwise just return nil.
6772 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6773 (if (not org-agenda-type)
6774 (error "No Org agenda currently displayed")
6775 (if (memq org-agenda-type types)
6777 (if error
6778 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6779 nil))))
6781 (defun org-agenda-Quit (&optional arg)
6782 "Exit agenda by removing the window or the buffer."
6783 (interactive)
6784 (if org-agenda-columns-active
6785 (org-columns-quit)
6786 (let ((buf (current-buffer)))
6787 (if (eq org-agenda-window-setup 'other-frame)
6788 (progn
6789 (org-agenda-reset-markers)
6790 (kill-buffer buf)
6791 (org-columns-remove-overlays)
6792 (setq org-agenda-archives-mode nil)
6793 (delete-frame))
6794 (and (not (eq org-agenda-window-setup 'current-window))
6795 (not (one-window-p))
6796 (delete-window))
6797 (org-agenda-reset-markers)
6798 (kill-buffer buf)
6799 (org-columns-remove-overlays)
6800 (setq org-agenda-archives-mode nil)))
6801 ;; Maybe restore the pre-agenda window configuration.
6802 (and org-agenda-restore-windows-after-quit
6803 (not (eq org-agenda-window-setup 'other-frame))
6804 org-agenda-pre-window-conf
6805 (set-window-configuration org-agenda-pre-window-conf)
6806 (setq org-agenda-pre-window-conf nil))))
6808 (defun org-agenda-quit ()
6809 "Exit agenda by killing agenda buffer or burying it when
6810 `org-agenda-sticky' is non-NIL"
6811 (interactive)
6812 (if (and (eq org-indirect-buffer-display 'other-window)
6813 org-last-indirect-buffer)
6814 (delete-window (get-buffer-window org-last-indirect-buffer)))
6815 (if org-agenda-columns-active
6816 (org-columns-quit)
6817 (if org-agenda-sticky
6818 (let ((buf (current-buffer)))
6819 (if (eq org-agenda-window-setup 'other-frame)
6820 (progn
6821 (delete-frame))
6822 (and (not (eq org-agenda-window-setup 'current-window))
6823 (not (one-window-p))
6824 (delete-window)))
6825 (with-current-buffer buf
6826 (bury-buffer)
6827 ;; Maybe restore the pre-agenda window configuration.
6828 (and org-agenda-restore-windows-after-quit
6829 (not (eq org-agenda-window-setup 'other-frame))
6830 org-agenda-pre-window-conf
6831 (set-window-configuration org-agenda-pre-window-conf)
6832 (setq org-agenda-pre-window-conf nil))))
6833 (org-agenda-Quit))))
6835 (defun org-agenda-exit ()
6836 "Exit agenda by removing the window or the buffer.
6837 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6838 Org-mode buffers visited directly by the user will not be touched."
6839 (interactive)
6840 (org-release-buffers org-agenda-new-buffers)
6841 (setq org-agenda-new-buffers nil)
6842 (org-agenda-Quit))
6844 (defun org-agenda-kill-all-agenda-buffers ()
6845 "Kill all buffers in `org-agenda-mode'.
6846 This is used when toggling sticky agendas. You can also explicitly invoke it
6847 with `C-c a C-k'."
6848 (interactive)
6849 (let (blist)
6850 (dolist (buf (buffer-list))
6851 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6852 (push buf blist)))
6853 (mapc 'kill-buffer blist)))
6855 (defun org-agenda-execute (arg)
6856 "Execute another agenda command, keeping same window.
6857 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6858 in the agenda."
6859 (interactive "P")
6860 (let ((org-agenda-window-setup 'current-window))
6861 (org-agenda arg)))
6863 (defun org-agenda-redo (&optional all)
6864 "Rebuild possibly ALL agenda view(s) in the current buffer."
6865 (interactive "P")
6866 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6867 (cpa (unless (eq all t) current-prefix-arg))
6868 (org-agenda-doing-sticky-redo org-agenda-sticky)
6869 (org-agenda-sticky nil)
6870 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6871 org-agenda-buffer-name))
6872 (org-agenda-keep-modes t)
6873 (tag-filter org-agenda-tag-filter)
6874 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6875 (top-cat-filter org-agenda-top-category-filter)
6876 (cat-filter org-agenda-category-filter)
6877 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6878 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6879 (cols org-agenda-columns-active)
6880 (line (org-current-line))
6881 (window-line (- line (org-current-line (window-start))))
6882 (lprops (get 'org-agenda-redo-command 'org-lprops))
6883 (redo-cmd (get-text-property p 'org-redo-cmd))
6884 (last-args (get-text-property p 'org-last-args))
6885 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6886 (org-agenda-overriding-cmd-arguments
6887 (unless (eq all t)
6888 (cond ((listp last-args)
6889 (cons (or cpa (car last-args)) (cdr last-args)))
6890 ((stringp last-args)
6891 last-args))))
6892 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6893 (put 'org-agenda-tag-filter :preset-filter nil)
6894 (put 'org-agenda-category-filter :preset-filter nil)
6895 (and cols (org-columns-quit))
6896 (message "Rebuilding agenda buffer...")
6897 (if series-redo-cmd
6898 (eval series-redo-cmd)
6899 (org-let lprops '(eval redo-cmd)))
6900 (setq org-agenda-undo-list nil
6901 org-agenda-pending-undo-list nil)
6902 (message "Rebuilding agenda buffer...done")
6903 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6904 (put 'org-agenda-category-filter :preset-filter cat-preset)
6905 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6906 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6907 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6908 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6909 (org-goto-line line)
6910 (recenter window-line)))
6912 (defvar org-global-tags-completion-table nil)
6913 (defvar org-agenda-filter-form nil)
6914 (defvar org-agenda-filtered-by-category nil)
6916 (defun org-agenda-filter-by-category (strip)
6917 "Keep only those lines in the agenda buffer that have a specific category.
6918 The category is that of the current line."
6919 (interactive "P")
6920 (if (and org-agenda-filtered-by-category
6921 org-agenda-category-filter)
6922 (org-agenda-filter-show-all-cat)
6923 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6924 (if cat (org-agenda-filter-apply
6925 (list (concat (if strip "-" "+") cat)) 'category)
6926 (error "No category at point")))))
6928 (defun org-find-top-category (&optional pos)
6929 (save-excursion
6930 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6931 (if pos (goto-char pos))
6932 ;; Skip up to the topmost parent
6933 (while (ignore-errors (outline-up-heading 1) t))
6934 (ignore-errors
6935 (nth 4 (org-heading-components))))))
6937 (defvar org-agenda-filtered-by-top-category nil)
6939 (defun org-agenda-filter-by-top-category (strip)
6940 "Keep only those lines in the agenda buffer that have a specific category.
6941 The category is that of the current line."
6942 (interactive "P")
6943 (if org-agenda-filtered-by-top-category
6944 (progn
6945 (setq org-agenda-filtered-by-top-category nil
6946 org-agenda-top-category-filter nil)
6947 (org-agenda-filter-show-all-cat))
6948 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6949 (if cat (org-agenda-filter-top-category-apply cat strip)
6950 (error "No top-level category at point")))))
6952 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6953 "Keep only those lines in the agenda buffer that have a specific tag.
6954 The tag is selected with its fast selection letter, as configured.
6955 With prefix argument STRIP, remove all lines that do have the tag.
6956 A lisp caller can specify CHAR. NARROW means that the new tag should be
6957 used to narrow the search - the interactive user can also press `-' or `+'
6958 to switch to narrowing."
6959 (interactive "P")
6960 (let* ((alist org-tag-alist-for-agenda)
6961 (tag-chars (mapconcat
6962 (lambda (x) (if (and (not (symbolp (car x)))
6963 (cdr x))
6964 (char-to-string (cdr x))
6965 ""))
6966 alist ""))
6967 (efforts (org-split-string
6968 (or (cdr (assoc (concat org-effort-property "_ALL")
6969 org-global-properties))
6970 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6971 "")))
6972 (effort-op org-agenda-filter-effort-default-operator)
6973 (effort-prompt "")
6974 (inhibit-read-only t)
6975 (current org-agenda-tag-filter)
6976 maybe-refresh a n tag)
6977 (unless char
6978 (message
6979 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6980 (if narrow "Narrow" "Filter") tag-chars
6981 (if org-agenda-auto-exclude-function "[RET], " ""))
6982 (setq char (read-char-exclusive)))
6983 (when (member char '(?+ ?-))
6984 ;; Narrowing down
6985 (cond ((equal char ?-) (setq strip t narrow t))
6986 ((equal char ?+) (setq strip nil narrow t)))
6987 (message
6988 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6989 (setq char (read-char-exclusive)))
6990 (when (member char '(?< ?> ?= ??))
6991 ;; An effort operator
6992 (setq effort-op (char-to-string char))
6993 (setq alist nil) ; to make sure it will be interpreted as effort.
6994 (unless (equal char ??)
6995 (loop for i from 0 to 9 do
6996 (setq effort-prompt
6997 (concat
6998 effort-prompt " ["
6999 (if (= i 9) "0" (int-to-string (1+ i)))
7000 "]" (nth i efforts))))
7001 (message "Effort%s: %s " effort-op effort-prompt)
7002 (setq char (read-char-exclusive))
7003 (when (or (< char ?0) (> char ?9))
7004 (error "Need 1-9,0 to select effort"))))
7005 (when (equal char ?\t)
7006 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7007 (org-set-local 'org-global-tags-completion-table
7008 (org-global-tags-completion-table)))
7009 (let ((completion-ignore-case t))
7010 (setq tag (org-icompleting-read
7011 "Tag: " org-global-tags-completion-table))))
7012 (cond
7013 ((equal char ?\r)
7014 (org-agenda-filter-show-all-tag)
7015 (when org-agenda-auto-exclude-function
7016 (setq org-agenda-tag-filter '())
7017 (dolist (tag (org-agenda-get-represented-tags))
7018 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7019 (if modifier
7020 (push modifier org-agenda-tag-filter))))
7021 (if (not (null org-agenda-tag-filter))
7022 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7023 (setq maybe-refresh t))
7024 ((equal char ?/)
7025 (org-agenda-filter-show-all-tag)
7026 (when (get 'org-agenda-tag-filter :preset-filter)
7027 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7028 (setq maybe-refresh t))
7029 ((equal char ?. )
7030 (setq org-agenda-tag-filter
7031 (mapcar (lambda(tag) (concat "+" tag))
7032 (org-get-at-bol 'tags)))
7033 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7034 (setq maybe-refresh t))
7035 ((or (equal char ?\ )
7036 (setq a (rassoc char alist))
7037 (and (>= char ?0) (<= char ?9)
7038 (setq n (if (= char ?0) 9 (- char ?0 1))
7039 tag (concat effort-op (nth n efforts))
7040 a (cons tag nil)))
7041 (and (= char ??)
7042 (setq tag "?eff")
7043 a (cons tag nil))
7044 (and tag (setq a (cons tag nil))))
7045 (org-agenda-filter-show-all-tag)
7046 (setq tag (car a))
7047 (setq org-agenda-tag-filter
7048 (cons (concat (if strip "-" "+") tag)
7049 (if narrow current nil)))
7050 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7051 (setq maybe-refresh t))
7052 (t (error "Invalid tag selection character %c" char)))
7053 (when (and maybe-refresh
7054 (eq org-agenda-clockreport-mode 'with-filter))
7055 (org-agenda-redo))))
7057 (defun org-agenda-get-represented-tags ()
7058 "Get a list of all tags currently represented in the agenda."
7059 (let (p tags)
7060 (save-excursion
7061 (goto-char (point-min))
7062 (while (setq p (next-single-property-change (point) 'tags))
7063 (goto-char p)
7064 (mapc (lambda (x) (add-to-list 'tags x))
7065 (get-text-property (point) 'tags))))
7066 tags))
7068 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7069 "Refine the current filter. See `org-agenda-filter-by-tag'."
7070 (interactive "P")
7071 (org-agenda-filter-by-tag strip char 'refine))
7073 (defun org-agenda-filter-make-matcher ()
7074 "Create the form that tests a line for agenda filter."
7075 (let (f f1)
7076 ;; first compute the tag-filter matcher
7077 (dolist (x (delete-dups
7078 (append (get 'org-agenda-tag-filter
7079 :preset-filter) org-agenda-tag-filter)))
7080 (if (member x '("-" "+"))
7081 (setq f1 (if (equal x "-") 'tags '(not tags)))
7082 (if (string-match "[<=>?]" x)
7083 (setq f1 (org-agenda-filter-effort-form x))
7084 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7085 (if (equal (string-to-char x) ?-)
7086 (setq f1 (list 'not f1))))
7087 (push f1 f))
7088 ;; then compute the category-filter matcher
7089 (dolist (x (delete-dups
7090 (append (get 'org-agenda-category-filter
7091 :preset-filter) org-agenda-category-filter)))
7092 (if (equal "-" (substring x 0 1))
7093 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7094 (setq f1 (list 'equal (substring x 1) 'cat)))
7095 (push f1 f))
7096 (cons 'and (nreverse f))))
7098 (defun org-agenda-filter-effort-form (e)
7099 "Return the form to compare the effort of the current line with what E says.
7100 E looks like \"+<2:25\"."
7101 (let (op)
7102 (setq e (substring e 1))
7103 (setq op (string-to-char e) e (substring e 1))
7104 (setq op (cond ((equal op ?<) '<=)
7105 ((equal op ?>) '>=)
7106 ((equal op ??) op)
7107 (t '=)))
7108 (list 'org-agenda-compare-effort (list 'quote op)
7109 (org-duration-string-to-minutes e))))
7111 (defun org-agenda-compare-effort (op value)
7112 "Compare the effort of the current line with VALUE, using OP.
7113 If the line does not have an effort defined, return nil."
7114 (let ((eff (org-get-at-bol 'effort-minutes)))
7115 (if (equal op ??)
7116 (not eff)
7117 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7118 value))))
7120 (defun org-agenda-filter-apply (filter type)
7121 "Set FILTER as the new agenda filter and apply it."
7122 (let (tags cat)
7123 (if (eq type 'tag)
7124 (setq org-agenda-tag-filter filter)
7125 (setq org-agenda-category-filter filter))
7126 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7127 (if (and (eq type 'category)
7128 (not (equal (substring (car filter) 0 1) "-")))
7129 ;; Only set `org-agenda-filtered-by-category' to t
7130 ;; when a unique category is used as the filter
7131 (setq org-agenda-filtered-by-category t))
7132 (org-agenda-set-mode-name)
7133 (save-excursion
7134 (goto-char (point-min))
7135 (while (not (eobp))
7136 (if (org-get-at-bol 'org-marker)
7137 (progn
7138 (setq tags (org-get-at-bol 'tags) ; used in eval
7139 cat (get-text-property (point) 'org-category))
7140 (if (not (eval org-agenda-filter-form))
7141 (org-agenda-filter-hide-line type))
7142 (beginning-of-line 2))
7143 (beginning-of-line 2))))
7144 (if (get-char-property (point) 'invisible)
7145 (ignore-errors (org-agenda-previous-line)))))
7147 (defun org-agenda-filter-top-category-apply (category &optional negative)
7148 "Set FILTER as the new agenda filter and apply it."
7149 (org-agenda-set-mode-name)
7150 (save-excursion
7151 (goto-char (point-min))
7152 (while (not (eobp))
7153 (let* ((pos (org-get-at-bol 'org-hd-marker))
7154 (topcat (and pos (org-find-top-category pos))))
7155 (if (and topcat (funcall (if negative 'identity 'not)
7156 (string= category topcat)))
7157 (org-agenda-filter-hide-line 'category)))
7158 (beginning-of-line 2)))
7159 (if (get-char-property (point) 'invisible)
7160 (org-agenda-previous-line))
7161 (setq org-agenda-top-category-filter category
7162 org-agenda-filtered-by-top-category t))
7164 (defun org-agenda-filter-hide-line (type)
7165 (let (ov)
7166 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7167 (point-at-eol)))
7168 (overlay-put ov 'invisible t)
7169 (overlay-put ov 'type type)
7170 (if (eq type 'tag)
7171 (push ov org-agenda-tag-filter-overlays)
7172 (push ov org-agenda-cat-filter-overlays))))
7174 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7175 (setq pos (or pos (point)))
7176 (save-excursion
7177 (dolist (ov (overlays-at pos))
7178 (when (and (overlay-get ov 'invisible)
7179 (eq (overlay-get ov 'type) 'tag))
7180 (goto-char pos)
7181 (if (< (overlay-start ov) (point-at-eol))
7182 (move-overlay ov (point-at-eol)
7183 (overlay-end ov)))))))
7185 (defun org-agenda-filter-show-all-tag nil
7186 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7187 (setq org-agenda-tag-filter-overlays nil
7188 org-agenda-tag-filter nil
7189 org-agenda-filter-form nil)
7190 (org-agenda-set-mode-name))
7192 (defun org-agenda-filter-show-all-cat nil
7193 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7194 (setq org-agenda-cat-filter-overlays nil
7195 org-agenda-filtered-by-category nil
7196 org-agenda-category-filter nil
7197 org-agenda-filter-form nil)
7198 (org-agenda-set-mode-name))
7200 (defun org-agenda-manipulate-query-add ()
7201 "Manipulate the query by adding a search term with positive selection.
7202 Positive selection means the term must be matched for selection of an entry."
7203 (interactive)
7204 (org-agenda-manipulate-query ?\[))
7205 (defun org-agenda-manipulate-query-subtract ()
7206 "Manipulate the query by adding a search term with negative selection.
7207 Negative selection means term must not be matched for selection of an entry."
7208 (interactive)
7209 (org-agenda-manipulate-query ?\]))
7210 (defun org-agenda-manipulate-query-add-re ()
7211 "Manipulate the query by adding a search regexp with positive selection.
7212 Positive selection means the regexp must match for selection of an entry."
7213 (interactive)
7214 (org-agenda-manipulate-query ?\{))
7215 (defun org-agenda-manipulate-query-subtract-re ()
7216 "Manipulate the query by adding a search regexp with negative selection.
7217 Negative selection means regexp must not match for selection of an entry."
7218 (interactive)
7219 (org-agenda-manipulate-query ?\}))
7220 (defun org-agenda-manipulate-query (char)
7221 (cond
7222 ((memq org-agenda-type '(timeline agenda))
7223 (let ((org-agenda-include-inactive-timestamps t))
7224 (org-agenda-redo))
7225 (message "Display now includes inactive timestamps as well"))
7226 ((eq org-agenda-type 'search)
7227 (org-add-to-string
7228 'org-agenda-query-string
7229 (if org-agenda-last-search-view-search-was-boolean
7230 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7231 (?\{ . " +{}") (?\} . " -{}"))))
7232 " "))
7233 (setq org-agenda-redo-command
7234 (list 'org-search-view
7235 (car (get-text-property (min (1- (point-max)) (point))
7236 'org-last-args))
7237 org-agenda-query-string
7238 (+ (length org-agenda-query-string)
7239 (if (member char '(?\{ ?\})) 0 1))))
7240 (set-register org-agenda-query-register org-agenda-query-string)
7241 (let ((org-agenda-overriding-arguments
7242 (cdr org-agenda-redo-command)))
7243 (org-agenda-redo)))
7244 (t (error "Cannot manipulate query for %s-type agenda buffers"
7245 org-agenda-type))))
7247 (defun org-add-to-string (var string)
7248 (set var (concat (symbol-value var) string)))
7250 (defun org-agenda-goto-date (span)
7251 "Jump to DATE in agenda."
7252 (interactive "P")
7253 (let* ((org-read-date-prefer-future
7254 (eval org-agenda-jump-prefer-future))
7255 (date (org-read-date))
7256 (org-agenda-sticky-orig org-agenda-sticky)
7257 (org-agenda-buffer-tmp-name (buffer-name))
7258 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7259 (0-arg (or current-prefix-arg (car args)))
7260 (2-arg (nth 2 args))
7261 (newcmd (list 'org-agenda-list 0-arg date
7262 (org-agenda-span-to-ndays 2-arg)))
7263 (newargs (cdr newcmd))
7264 (inhibit-read-only t)
7265 org-agenda-sticky)
7266 (if (not (org-agenda-check-type t 'agenda))
7267 (error "Not available in non-agenda blocks")
7268 (add-text-properties (point-min) (point-max)
7269 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7270 (org-agenda-redo)
7271 (setq org-agenda-sticky org-agenda-sticky-orig
7272 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7274 (defun org-agenda-goto-today ()
7275 "Go to today."
7276 (interactive)
7277 (org-agenda-check-type t 'timeline 'agenda)
7278 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7279 (curspan (nth 2 args))
7280 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7281 (cond
7282 (tdpos (goto-char tdpos))
7283 ((eq org-agenda-type 'agenda)
7284 (let* ((sd (org-agenda-compute-starting-span
7285 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7286 (org-agenda-overriding-arguments args))
7287 (setf (nth 1 org-agenda-overriding-arguments) sd)
7288 (org-agenda-redo)
7289 (org-agenda-find-same-or-today-or-agenda)))
7290 (t (error "Cannot find today")))))
7292 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7293 (goto-char
7294 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7295 (text-property-any (point-min) (point-max) 'org-today t)
7296 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7297 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7298 (org-agenda-goto-block-beginning))
7299 (point-min))))
7301 (defun org-agenda-goto-block-beginning ()
7302 "Go the agenda block beginning."
7303 (interactive)
7304 (if (not (derived-mode-p 'org-agenda-mode))
7305 (error "Cannot execute this command outside of org-agenda-mode buffers")
7306 (let (dest)
7307 (save-excursion
7308 (unless (looking-at "\\'")
7309 (forward-char))
7310 (let* ((prop 'org-agenda-structural-header)
7311 (p (previous-single-property-change (point) prop))
7312 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7313 (1- (point))) prop)))
7314 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7315 (if (not dest)
7316 (error "Cannot find the beginning of the blog")
7317 (goto-char dest)
7318 (move-beginning-of-line 1)))))
7320 (defun org-agenda-later (arg)
7321 "Go forward in time by the current span.
7322 With prefix ARG, go forward that many times the current span."
7323 (interactive "p")
7324 (org-agenda-check-type t 'agenda)
7325 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7326 (span (or (nth 2 args) org-agenda-current-span))
7327 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7328 (greg (calendar-gregorian-from-absolute sd))
7329 (cnt (org-get-at-bol 'org-day-cnt))
7330 greg2)
7331 (cond
7332 ((numberp span)
7333 (setq sd (+ (* span arg) sd)))
7334 ((eq span 'day)
7335 (setq sd (+ arg sd)))
7336 ((eq span 'week)
7337 (setq sd (+ (* 7 arg) sd)))
7338 ((eq span 'month)
7339 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7340 sd (calendar-absolute-from-gregorian greg2))
7341 (setcar greg2 (1+ (car greg2))))
7342 ((eq span 'year)
7343 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7344 sd (calendar-absolute-from-gregorian greg2))
7345 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7347 (setq sd (+ (* span arg) sd))))
7348 (let ((org-agenda-overriding-cmd
7349 ;; `cmd' may have been set by `org-agenda-run-series' which
7350 ;; uses `org-agenda-overriding-cmd' to decide whether
7351 ;; overriding is allowed for `cmd'
7352 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7353 (org-agenda-overriding-arguments
7354 (list (car args) sd span)))
7355 (org-agenda-redo)
7356 (org-agenda-find-same-or-today-or-agenda cnt))))
7358 (defun org-agenda-earlier (arg)
7359 "Go backward in time by the current span.
7360 With prefix ARG, go backward that many times the current span."
7361 (interactive "p")
7362 (org-agenda-later (- arg)))
7364 (defun org-agenda-view-mode-dispatch ()
7365 "Call one of the view mode commands."
7366 (interactive)
7367 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7368 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7369 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7370 (let ((a (read-char-exclusive)))
7371 (case a
7372 (?\ (call-interactively 'org-agenda-reset-view))
7373 (?d (call-interactively 'org-agenda-day-view))
7374 (?w (call-interactively 'org-agenda-week-view))
7375 (?m (call-interactively 'org-agenda-month-view))
7376 (?y (call-interactively 'org-agenda-year-view))
7377 (?l (call-interactively 'org-agenda-log-mode))
7378 (?L (org-agenda-log-mode '(4)))
7379 (?c (org-agenda-log-mode 'clockcheck))
7380 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7381 (?a (call-interactively 'org-agenda-archives-mode))
7382 (?A (org-agenda-archives-mode 'files))
7383 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7384 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7385 (?G (call-interactively 'org-agenda-toggle-time-grid))
7386 (?D (call-interactively 'org-agenda-toggle-diary))
7387 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7388 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7389 (org-agenda-check-type t 'timeline 'agenda)
7390 (org-agenda-redo))
7391 (message "Display now includes inactive timestamps as well"))
7392 (?q (message "Abort"))
7393 (otherwise (error "Invalid key" )))))
7395 (defun org-agenda-reset-view ()
7396 "Switch to default view for agenda."
7397 (interactive)
7398 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7399 (defun org-agenda-day-view (&optional day-of-year)
7400 "Switch to daily view for agenda.
7401 With argument DAY-OF-YEAR, switch to that day of the year."
7402 (interactive "P")
7403 (org-agenda-change-time-span 'day day-of-year))
7404 (defun org-agenda-week-view (&optional iso-week)
7405 "Switch to daily view for agenda.
7406 With argument ISO-WEEK, switch to the corresponding ISO week.
7407 If ISO-WEEK has more then 2 digits, only the last two encode the
7408 week. Any digits before this encode a year. So 200712 means
7409 week 12 of year 2007. Years in the range 1938-2037 can also be
7410 written as 2-digit years."
7411 (interactive "P")
7412 (org-agenda-change-time-span 'week iso-week))
7413 (defun org-agenda-month-view (&optional month)
7414 "Switch to monthly view for agenda.
7415 With argument MONTH, switch to that month."
7416 (interactive "P")
7417 (org-agenda-change-time-span 'month month))
7418 (defun org-agenda-year-view (&optional year)
7419 "Switch to yearly view for agenda.
7420 With argument YEAR, switch to that year.
7421 If MONTH has more then 2 digits, only the last two encode the
7422 month. Any digits before this encode a year. So 200712 means
7423 December year 2007. Years in the range 1938-2037 can also be
7424 written as 2-digit years."
7425 (interactive "P")
7426 (when year
7427 (setq year (org-small-year-to-year year)))
7428 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7429 (org-agenda-change-time-span 'year year)
7430 (error "Abort")))
7432 (defun org-agenda-change-time-span (span &optional n)
7433 "Change the agenda view to SPAN.
7434 SPAN may be `day', `week', `month', `year'."
7435 (org-agenda-check-type t 'agenda)
7436 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7437 (curspan (nth 2 args)))
7438 (if (and (not n) (equal curspan span))
7439 (error "Viewing span is already \"%s\"" span))
7440 (let* ((sd (or (org-get-at-bol 'day)
7441 (nth 1 args)
7442 org-starting-day))
7443 (sd (org-agenda-compute-starting-span sd span n))
7444 (org-agenda-overriding-cmd
7445 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7446 (org-agenda-overriding-arguments
7447 (list (car args) sd span)))
7448 (org-agenda-redo)
7449 (org-agenda-find-same-or-today-or-agenda))
7450 (org-agenda-set-mode-name)
7451 (message "Switched to %s view" span)))
7453 (defun org-agenda-compute-starting-span (sd span &optional n)
7454 "Compute starting date for agenda.
7455 SPAN may be `day', `week', `month', `year'. The return value
7456 is a cons cell with the starting date and the number of days,
7457 so that the date SD will be in that range."
7458 (let* ((greg (calendar-gregorian-from-absolute sd))
7459 (dg (nth 1 greg))
7460 (mg (car greg))
7461 (yg (nth 2 greg)))
7462 (cond
7463 ((eq span 'day)
7464 (when n
7465 (setq sd (+ (calendar-absolute-from-gregorian
7466 (list mg 1 yg))
7467 n -1))))
7468 ((eq span 'week)
7469 (let* ((nt (calendar-day-of-week
7470 (calendar-gregorian-from-absolute sd)))
7471 (d (if org-agenda-start-on-weekday
7472 (- nt org-agenda-start-on-weekday)
7475 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7476 (when n
7477 (require 'cal-iso)
7478 (when (> n 99)
7479 (setq y1 (org-small-year-to-year (/ n 100))
7480 n (mod n 100)))
7481 (setq sd
7482 (calendar-absolute-from-iso
7483 (list n 1
7484 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7485 ((eq span 'month)
7486 (let (y1)
7487 (when (and n (> n 99))
7488 (setq y1 (org-small-year-to-year (/ n 100))
7489 n (mod n 100)))
7490 (setq sd (calendar-absolute-from-gregorian
7491 (list (or n mg) 1 (or y1 yg))))))
7492 ((eq span 'year)
7493 (setq sd (calendar-absolute-from-gregorian
7494 (list 1 1 (or n yg))))))
7495 sd))
7497 (defun org-agenda-next-date-line (&optional arg)
7498 "Jump to the next line indicating a date in agenda buffer."
7499 (interactive "p")
7500 (org-agenda-check-type t 'agenda 'timeline)
7501 (beginning-of-line 1)
7502 ;; This does not work if user makes date format that starts with a blank
7503 (if (looking-at "^\\S-") (forward-char 1))
7504 (if (not (re-search-forward "^\\S-" nil t arg))
7505 (progn
7506 (backward-char 1)
7507 (error "No next date after this line in this buffer")))
7508 (goto-char (match-beginning 0)))
7510 (defun org-agenda-previous-date-line (&optional arg)
7511 "Jump to the previous line indicating a date in agenda buffer."
7512 (interactive "p")
7513 (org-agenda-check-type t 'agenda 'timeline)
7514 (beginning-of-line 1)
7515 (if (not (re-search-backward "^\\S-" nil t arg))
7516 (error "No previous date before this line in this buffer")))
7518 ;; Initialize the highlight
7519 (defvar org-hl (make-overlay 1 1))
7520 (overlay-put org-hl 'face 'highlight)
7522 (defun org-highlight (begin end &optional buffer)
7523 "Highlight a region with overlay."
7524 (move-overlay org-hl begin end (or buffer (current-buffer))))
7526 (defun org-unhighlight ()
7527 "Detach overlay INDEX."
7528 (org-detach-overlay org-hl))
7530 (defun org-unhighlight-once ()
7531 "Remove the highlight from its position, and this function from the hook."
7532 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7533 (org-unhighlight))
7535 (defvar org-agenda-pre-follow-window-conf nil)
7536 (defun org-agenda-follow-mode ()
7537 "Toggle follow mode in an agenda buffer."
7538 (interactive)
7539 (unless org-agenda-follow-mode
7540 (setq org-agenda-pre-follow-window-conf
7541 (current-window-configuration)))
7542 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7543 (unless org-agenda-follow-mode
7544 (set-window-configuration org-agenda-pre-follow-window-conf))
7545 (org-agenda-set-mode-name)
7546 (org-agenda-do-context-action)
7547 (message "Follow mode is %s"
7548 (if org-agenda-follow-mode "on" "off")))
7550 (defun org-agenda-entry-text-mode (&optional arg)
7551 "Toggle entry text mode in an agenda buffer."
7552 (interactive "P")
7553 (setq org-agenda-entry-text-mode (or (integerp arg)
7554 (not org-agenda-entry-text-mode)))
7555 (org-agenda-entry-text-hide)
7556 (and org-agenda-entry-text-mode
7557 (let ((org-agenda-entry-text-maxlines
7558 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7559 (org-agenda-entry-text-show)))
7560 (org-agenda-set-mode-name)
7561 (message "Entry text mode is %s. Maximum number of lines is %d"
7562 (if org-agenda-entry-text-mode "on" "off")
7563 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7565 (defun org-agenda-clockreport-mode (&optional with-filter)
7566 "Toggle clocktable mode in an agenda buffer.
7567 With prefix arg WITH-FILTER, make the clocktable respect the current
7568 agenda filter."
7569 (interactive "P")
7570 (org-agenda-check-type t 'agenda)
7571 (if with-filter
7572 (setq org-agenda-clockreport-mode 'with-filter)
7573 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7574 (org-agenda-set-mode-name)
7575 (org-agenda-redo)
7576 (message "Clocktable mode is %s"
7577 (if org-agenda-clockreport-mode "on" "off")))
7579 (defun org-agenda-log-mode (&optional special)
7580 "Toggle log mode in an agenda buffer.
7581 With argument SPECIAL, show all possible log items, not only the ones
7582 configured in `org-agenda-log-mode-items'.
7583 With a double `C-u' prefix arg, show *only* log items, nothing else."
7584 (interactive "P")
7585 (org-agenda-check-type t 'agenda 'timeline)
7586 (setq org-agenda-show-log
7587 (cond
7588 ((equal special '(16)) 'only)
7589 ((eq special 'clockcheck)
7590 (if (eq org-agenda-show-log 'clockcheck)
7591 nil 'clockcheck))
7592 (special '(closed clock state))
7593 (t (not org-agenda-show-log))))
7594 (org-agenda-set-mode-name)
7595 (org-agenda-redo)
7596 (message "Log mode is %s"
7597 (if org-agenda-show-log "on" "off")))
7599 (defun org-agenda-archives-mode (&optional with-files)
7600 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7601 When called with a prefix argument, include all archive files as well."
7602 (interactive "P")
7603 (setq org-agenda-archives-mode
7604 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7605 (org-agenda-set-mode-name)
7606 (org-agenda-redo)
7607 (message
7608 "%s"
7609 (cond
7610 ((eq org-agenda-archives-mode nil)
7611 "No archives are included")
7612 ((eq org-agenda-archives-mode 'trees)
7613 (format "Trees with :%s: tag are included" org-archive-tag))
7614 ((eq org-agenda-archives-mode t)
7615 (format "Trees with :%s: tag and all active archive files are included"
7616 org-archive-tag)))))
7618 (defun org-agenda-toggle-diary ()
7619 "Toggle diary inclusion in an agenda buffer."
7620 (interactive)
7621 (org-agenda-check-type t 'agenda)
7622 (setq org-agenda-include-diary (not org-agenda-include-diary))
7623 (org-agenda-redo)
7624 (org-agenda-set-mode-name)
7625 (message "Diary inclusion turned %s"
7626 (if org-agenda-include-diary "on" "off")))
7628 (defun org-agenda-toggle-deadlines ()
7629 "Toggle inclusion of entries with a deadline in an agenda buffer."
7630 (interactive)
7631 (org-agenda-check-type t 'agenda)
7632 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7633 (org-agenda-redo)
7634 (org-agenda-set-mode-name)
7635 (message "Deadlines inclusion turned %s"
7636 (if org-agenda-include-deadlines "on" "off")))
7638 (defun org-agenda-toggle-time-grid ()
7639 "Toggle time grid in an agenda buffer."
7640 (interactive)
7641 (org-agenda-check-type t 'agenda)
7642 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7643 (org-agenda-redo)
7644 (org-agenda-set-mode-name)
7645 (message "Time-grid turned %s"
7646 (if org-agenda-use-time-grid "on" "off")))
7648 (defun org-agenda-set-mode-name ()
7649 "Set the mode name to indicate all the small mode settings."
7650 (setq mode-name
7651 (list "Org-Agenda"
7652 (if (get 'org-agenda-files 'org-restrict) " []" "")
7654 '(:eval (org-agenda-span-name org-agenda-current-span))
7655 (if org-agenda-follow-mode " Follow" "")
7656 (if org-agenda-entry-text-mode " ETxt" "")
7657 (if org-agenda-include-diary " Diary" "")
7658 (if org-agenda-include-deadlines " Ddl" "")
7659 (if org-agenda-use-time-grid " Grid" "")
7660 (if (and (boundp 'org-habit-show-habits)
7661 org-habit-show-habits) " Habit" "")
7662 (cond
7663 ((consp org-agenda-show-log) " LogAll")
7664 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7665 (org-agenda-show-log " Log")
7666 (t ""))
7667 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7668 :preset-filter))
7669 '(:eval (org-propertize
7670 (concat " <"
7671 (mapconcat
7672 'identity
7673 (append
7674 (get 'org-agenda-category-filter :preset-filter)
7675 org-agenda-category-filter)
7677 ">")
7678 'face 'org-agenda-filter-category
7679 'help-echo "Category used in filtering"))
7681 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7682 :preset-filter))
7683 '(:eval (org-propertize
7684 (concat " {"
7685 (mapconcat
7686 'identity
7687 (append
7688 (get 'org-agenda-tag-filter :preset-filter)
7689 org-agenda-tag-filter)
7691 "}")
7692 'face 'org-agenda-filter-tags
7693 'help-echo "Tags used in filtering"))
7695 (if org-agenda-archives-mode
7696 (if (eq org-agenda-archives-mode t)
7697 " Archives"
7698 (format " :%s:" org-archive-tag))
7700 (if org-agenda-clockreport-mode
7701 (if (eq org-agenda-clockreport-mode 'with-filter)
7702 " Clock{}" " Clock")
7703 "")))
7704 (force-mode-line-update))
7706 (org-define-obsolete-function-alias
7707 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7709 (defun org-agenda-update-agenda-type ()
7710 "Update the agenda type after each command."
7711 (setq org-agenda-type
7712 (or (get-text-property (point) 'org-agenda-type)
7713 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7715 (defun org-agenda-next-line ()
7716 "Move cursor to the next line, and show if follow mode is active."
7717 (interactive)
7718 (call-interactively 'next-line)
7719 (org-agenda-do-context-action))
7721 (defun org-agenda-previous-line ()
7722 "Move cursor to the previous line, and show if follow-mode is active."
7723 (interactive)
7724 (call-interactively 'previous-line)
7725 (org-agenda-do-context-action))
7727 (defun org-agenda-next-item (n)
7728 "Move cursor to next agenda item."
7729 (interactive "p")
7730 (let ((col (current-column)))
7731 (dotimes (c n)
7732 (when (next-single-property-change (point-at-eol) 'org-marker)
7733 (move-end-of-line 1)
7734 (goto-char (next-single-property-change (point) 'org-marker))))
7735 (org-move-to-column col))
7736 (org-agenda-do-context-action))
7738 (defun org-agenda-previous-item (n)
7739 "Move cursor to next agenda item."
7740 (interactive "p")
7741 (dotimes (c n)
7742 (let ((col (current-column))
7743 (goto (save-excursion
7744 (move-end-of-line 0)
7745 (previous-single-property-change (point) 'org-marker))))
7746 (if goto (goto-char goto))
7747 (org-move-to-column col)))
7748 (org-agenda-do-context-action))
7750 (defun org-agenda-do-context-action ()
7751 "Show outline path and, maybe, follow mode window."
7752 (let ((m (org-get-at-bol 'org-marker)))
7753 (when (and (markerp m) (marker-buffer m))
7754 (and org-agenda-follow-mode
7755 (if org-agenda-follow-indirect
7756 (org-agenda-tree-to-indirect-buffer nil)
7757 (org-agenda-show)))
7758 (and org-agenda-show-outline-path
7759 (org-with-point-at m (org-display-outline-path t))))))
7761 (defun org-agenda-show-tags ()
7762 "Show the tags applicable to the current item."
7763 (interactive)
7764 (let* ((tags (org-get-at-bol 'tags)))
7765 (if tags
7766 (message "Tags are :%s:"
7767 (org-no-properties (mapconcat 'identity tags ":")))
7768 (message "No tags associated with this line"))))
7770 (defun org-agenda-goto (&optional highlight)
7771 "Go to the Org-mode file which contains the item at point."
7772 (interactive)
7773 (let* ((marker (or (org-get-at-bol 'org-marker)
7774 (org-agenda-error)))
7775 (buffer (marker-buffer marker))
7776 (pos (marker-position marker)))
7777 (switch-to-buffer-other-window buffer)
7778 (widen)
7779 (push-mark)
7780 (goto-char pos)
7781 (when (derived-mode-p 'org-mode)
7782 (org-show-context 'agenda)
7783 (save-excursion
7784 (and (outline-next-heading)
7785 (org-flag-heading nil)))) ; show the next heading
7786 (when (outline-invisible-p)
7787 (show-entry)) ; display invisible text
7788 (recenter (/ (window-height) 2))
7789 (run-hooks 'org-agenda-after-show-hook)
7790 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7792 (defvar org-agenda-after-show-hook nil
7793 "Normal hook run after an item has been shown from the agenda.
7794 Point is in the buffer where the item originated.")
7796 (defun org-agenda-kill ()
7797 "Kill the entry or subtree belonging to the current agenda entry."
7798 (interactive)
7799 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7800 (let* ((bufname-orig (buffer-name))
7801 (marker (or (org-get-at-bol 'org-marker)
7802 (org-agenda-error)))
7803 (buffer (marker-buffer marker))
7804 (pos (marker-position marker))
7805 (type (org-get-at-bol 'type))
7806 dbeg dend (n 0) conf)
7807 (org-with-remote-undo buffer
7808 (with-current-buffer buffer
7809 (save-excursion
7810 (goto-char pos)
7811 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7812 (setq dbeg (progn (org-back-to-heading t) (point))
7813 dend (org-end-of-subtree t t))
7814 (setq dbeg (point-at-bol)
7815 dend (min (point-max) (1+ (point-at-eol)))))
7816 (goto-char dbeg)
7817 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7818 (setq conf (or (eq t org-agenda-confirm-kill)
7819 (and (numberp org-agenda-confirm-kill)
7820 (> n org-agenda-confirm-kill))))
7821 (and conf
7822 (not (y-or-n-p
7823 (format "Delete entry with %d lines in buffer \"%s\"? "
7824 n (buffer-name buffer))))
7825 (error "Abort"))
7826 (let ((org-agenda-buffer-name bufname-orig))
7827 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7828 (with-current-buffer buffer (delete-region dbeg dend))
7829 (message "Agenda item and source killed"))))
7831 (defvar org-archive-default-command) ; defined in org-archive.el
7832 (defun org-agenda-archive-default ()
7833 "Archive the entry or subtree belonging to the current agenda entry."
7834 (interactive)
7835 (require 'org-archive)
7836 (org-agenda-archive-with org-archive-default-command))
7838 (defun org-agenda-archive-default-with-confirmation ()
7839 "Archive the entry or subtree belonging to the current agenda entry."
7840 (interactive)
7841 (require 'org-archive)
7842 (org-agenda-archive-with org-archive-default-command 'confirm))
7844 (defun org-agenda-archive ()
7845 "Archive the entry or subtree belonging to the current agenda entry."
7846 (interactive)
7847 (org-agenda-archive-with 'org-archive-subtree))
7849 (defun org-agenda-archive-to-archive-sibling ()
7850 "Move the entry to the archive sibling."
7851 (interactive)
7852 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7854 (defun org-agenda-archive-with (cmd &optional confirm)
7855 "Move the entry to the archive sibling."
7856 (interactive)
7857 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7858 (let* ((bufname-orig (buffer-name))
7859 (marker (or (org-get-at-bol 'org-marker)
7860 (org-agenda-error)))
7861 (buffer (marker-buffer marker))
7862 (pos (marker-position marker)))
7863 (org-with-remote-undo buffer
7864 (with-current-buffer buffer
7865 (if (derived-mode-p 'org-mode)
7866 (if (and confirm
7867 (not (y-or-n-p "Archive this subtree or entry? ")))
7868 (error "Abort")
7869 (save-excursion
7870 (goto-char pos)
7871 (let ((org-agenda-buffer-name bufname-orig))
7872 (org-remove-subtree-entries-from-agenda))
7873 (org-back-to-heading t)
7874 (funcall cmd)))
7875 (error "Archiving works only in Org-mode files"))))))
7877 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7878 "Remove all lines in the agenda that correspond to a given subtree.
7879 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7880 If this information is not given, the function uses the tree at point."
7881 (let ((buf (or buf (current-buffer))) m p)
7882 (save-excursion
7883 (unless (and beg end)
7884 (org-back-to-heading t)
7885 (setq beg (point))
7886 (org-end-of-subtree t)
7887 (setq end (point)))
7888 (set-buffer (get-buffer org-agenda-buffer-name))
7889 (save-excursion
7890 (goto-char (point-max))
7891 (beginning-of-line 1)
7892 (while (not (bobp))
7893 (when (and (setq m (org-get-at-bol 'org-marker))
7894 (equal buf (marker-buffer m))
7895 (setq p (marker-position m))
7896 (>= p beg)
7897 (< p end))
7898 (let ((inhibit-read-only t))
7899 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7900 (beginning-of-line 0))))))
7902 (defun org-agenda-refile (&optional goto rfloc no-update)
7903 "Refile the item at point."
7904 (interactive "P")
7905 (if (equal goto '(16))
7906 (org-refile-goto-last-stored)
7907 (let* ((buffer-orig (buffer-name))
7908 (marker (or (org-get-at-bol 'org-hd-marker)
7909 (org-agenda-error)))
7910 (buffer (marker-buffer marker))
7911 (pos (marker-position marker))
7912 (rfloc (or rfloc
7913 (org-refile-get-location
7914 (if goto "Goto" "Refile to") buffer
7915 org-refile-allow-creating-parent-nodes))))
7916 (with-current-buffer buffer
7917 (save-excursion
7918 (save-restriction
7919 (widen)
7920 (goto-char marker)
7921 (let ((org-agenda-buffer-name buffer-orig))
7922 (org-remove-subtree-entries-from-agenda))
7923 (org-refile goto buffer rfloc)))))
7924 (unless no-update (org-agenda-redo))))
7926 (defun org-agenda-open-link (&optional arg)
7927 "Open the link(s) in the current entry, if any.
7928 This looks for a link in the displayed line in the agenda.
7929 It also looks at the text of the entry itself."
7930 (interactive "P")
7931 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7932 (org-get-at-bol 'org-marker)))
7933 (buffer (and marker (marker-buffer marker)))
7934 (prefix (buffer-substring
7935 (point-at-bol) (point-at-eol)))
7936 (lkall (org-offer-links-in-entry buffer marker arg prefix))
7937 (lk (car lkall))
7938 (lkend (cdr lkall))
7939 trg)
7940 (cond
7941 ((and buffer (stringp lk))
7942 (with-current-buffer buffer
7943 (setq trg (and (string-match org-bracket-link-regexp lk)
7944 (match-string 1 lk)))
7945 (if (or (not trg) (string-match org-any-link-re trg))
7946 (save-excursion
7947 (save-restriction
7948 (widen)
7949 (goto-char marker)
7950 (when (search-forward lk nil lkend)
7951 (goto-char (match-beginning 0))
7952 (org-open-at-point))))
7953 ;; This is an internal link, widen the buffer
7954 (switch-to-buffer-other-window buffer)
7955 (widen)
7956 (goto-char marker)
7957 (when (search-forward lk nil lkend)
7958 (goto-char (match-beginning 0))
7959 (org-open-at-point)))))
7960 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7961 (save-excursion
7962 (beginning-of-line 1)
7963 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7964 (org-open-link-from-string (match-string 1)))
7965 (t (message "No link to open here")))))
7967 (defun org-agenda-copy-local-variable (var)
7968 "Get a variable from a referenced buffer and install it here."
7969 (let ((m (org-get-at-bol 'org-marker)))
7970 (when (and m (buffer-live-p (marker-buffer m)))
7971 (org-set-local var (with-current-buffer (marker-buffer m)
7972 (symbol-value var))))))
7974 (defun org-agenda-switch-to (&optional delete-other-windows)
7975 "Go to the Org-mode file which contains the item at point."
7976 (interactive)
7977 (if (and org-return-follows-link
7978 (not (org-get-at-bol 'org-marker))
7979 (org-in-regexp org-bracket-link-regexp))
7980 (org-open-link-from-string (match-string 0))
7981 (let* ((marker (or (org-get-at-bol 'org-marker)
7982 (org-agenda-error)))
7983 (buffer (marker-buffer marker))
7984 (pos (marker-position marker)))
7985 (org-pop-to-buffer-same-window buffer)
7986 (and delete-other-windows (delete-other-windows))
7987 (widen)
7988 (goto-char pos)
7989 (when (derived-mode-p 'org-mode)
7990 (org-show-context 'agenda)
7991 (save-excursion
7992 (and (outline-next-heading)
7993 (org-flag-heading nil))) ; show the next heading
7994 (when (outline-invisible-p)
7995 (show-entry)) ; display invisible text
7996 (run-hooks 'org-agenda-after-show-hook)))))
7998 (defun org-agenda-goto-mouse (ev)
7999 "Go to the Org-mode file which contains the item at the mouse click."
8000 (interactive "e")
8001 (mouse-set-point ev)
8002 (org-agenda-goto))
8004 (defun org-agenda-show (&optional full-entry)
8005 "Display the Org-mode file which contains the item at point.
8006 With prefix argument FULL-ENTRY, make the entire entry visible
8007 if it was hidden in the outline."
8008 (interactive "P")
8009 (let ((win (selected-window)))
8010 (if full-entry
8011 (let ((org-show-entry-below t))
8012 (org-agenda-goto t))
8013 (org-agenda-goto t))
8014 (select-window win)))
8016 (defvar org-agenda-show-window nil)
8017 (defun org-agenda-show-and-scroll-up (&optional arg)
8018 "Display the Org-mode file which contains the item at point.
8019 When called repeatedly, scroll the window that is displaying the buffer.
8020 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8021 `show-subtree' to display the item, so that drawers and logbooks stay
8022 folded."
8023 (interactive "P")
8024 (let ((win (selected-window)))
8025 (if (and (window-live-p org-agenda-show-window)
8026 (eq this-command last-command))
8027 (progn
8028 (select-window org-agenda-show-window)
8029 (ignore-errors (scroll-up)))
8030 (org-agenda-goto t)
8031 (if arg (org-show-entry) (show-subtree))
8032 (setq org-agenda-show-window (selected-window)))
8033 (select-window win)))
8035 (defun org-agenda-show-scroll-down ()
8036 "Scroll down the window showing the agenda."
8037 (interactive)
8038 (let ((win (selected-window)))
8039 (when (window-live-p org-agenda-show-window)
8040 (select-window org-agenda-show-window)
8041 (ignore-errors (scroll-down))
8042 (select-window win))))
8044 (defun org-agenda-show-1 (&optional more)
8045 "Display the Org-mode file which contains the item at point.
8046 The prefix arg selects the amount of information to display:
8048 0 hide the subtree
8049 1 just show the entry according to defaults.
8050 2 show the children view
8051 3 show the subtree view
8052 4 show the entire subtree and any LOGBOOK drawers
8053 5 show the entire subtree and any drawers
8054 With prefix argument FULL-ENTRY, make the entire entry visible
8055 if it was hidden in the outline."
8056 (interactive "p")
8057 (let ((win (selected-window)))
8058 (org-agenda-goto t)
8059 (org-recenter-heading 1)
8060 (cond
8061 ((= more 0)
8062 (hide-subtree)
8063 (save-excursion
8064 (org-back-to-heading)
8065 (run-hook-with-args 'org-cycle-hook 'folded))
8066 (message "Remote: FOLDED"))
8067 ((and (org-called-interactively-p 'any) (= more 1))
8068 (message "Remote: show with default settings"))
8069 ((= more 2)
8070 (show-entry)
8071 (show-children)
8072 (save-excursion
8073 (org-back-to-heading)
8074 (run-hook-with-args 'org-cycle-hook 'children))
8075 (message "Remote: CHILDREN"))
8076 ((= more 3)
8077 (show-subtree)
8078 (save-excursion
8079 (org-back-to-heading)
8080 (run-hook-with-args 'org-cycle-hook 'subtree))
8081 (message "Remote: SUBTREE"))
8082 ((= more 4)
8083 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8084 (org-drawer-regexp
8085 (concat "^[ \t]*:\\("
8086 (mapconcat 'regexp-quote org-drawers "\\|")
8087 "\\):[ \t]*$")))
8088 (show-subtree)
8089 (save-excursion
8090 (org-back-to-heading)
8091 (org-cycle-hide-drawers 'subtree)))
8092 (message "Remote: SUBTREE AND LOGBOOK"))
8093 ((> more 4)
8094 (show-subtree)
8095 (message "Remote: SUBTREE AND ALL DRAWERS")))
8096 (select-window win)))
8098 (defun org-recenter-heading (n)
8099 (save-excursion
8100 (org-back-to-heading)
8101 (recenter n)))
8103 (defvar org-agenda-cycle-counter nil)
8104 (defun org-agenda-cycle-show (&optional n)
8105 "Show the current entry in another window, with default settings.
8106 Default settings are taken from `org-show-hierarchy-above' and siblings.
8107 When use repeatedly in immediate succession, the remote entry will cycle
8108 through visibility
8110 children -> subtree -> folded
8112 When called with a numeric prefix arg, that arg will be passed through to
8113 `org-agenda-show-1'. For the interpretation of that argument, see the
8114 docstring of `org-agenda-show-1'."
8115 (interactive "P")
8116 (if (integerp n)
8117 (setq org-agenda-cycle-counter n)
8118 (if (not (eq last-command this-command))
8119 (setq org-agenda-cycle-counter 1)
8120 (if (equal org-agenda-cycle-counter 0)
8121 (setq org-agenda-cycle-counter 2)
8122 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8123 (if (> org-agenda-cycle-counter 3)
8124 (setq org-agenda-cycle-counter 0)))))
8125 (org-agenda-show-1 org-agenda-cycle-counter))
8127 (defun org-agenda-recenter (arg)
8128 "Display the Org-mode file which contains the item at point and recenter."
8129 (interactive "P")
8130 (let ((win (selected-window)))
8131 (org-agenda-goto t)
8132 (recenter arg)
8133 (select-window win)))
8135 (defun org-agenda-show-mouse (ev)
8136 "Display the Org-mode file which contains the item at the mouse click."
8137 (interactive "e")
8138 (mouse-set-point ev)
8139 (org-agenda-show))
8141 (defun org-agenda-check-no-diary ()
8142 "Check if the entry is a diary link and abort if yes."
8143 (if (org-get-at-bol 'org-agenda-diary-link)
8144 (org-agenda-error)))
8146 (defun org-agenda-error ()
8147 (error "Command not allowed in this line"))
8149 (defun org-agenda-tree-to-indirect-buffer (arg)
8150 "Show the subtree corresponding to the current entry in an indirect buffer.
8151 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8153 With a numerical prefix ARG, go up to this level and then take that tree.
8154 With a negative numeric ARG, go up by this number of levels.
8155 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8156 use the dedicated frame)."
8157 (interactive "P")
8158 (if current-prefix-arg
8159 (org-agenda-do-tree-to-indirect-buffer arg)
8160 (let ((agenda-buffer (buffer-name))
8161 (agenda-window (selected-window))
8162 (indirect-window
8163 (and org-last-indirect-buffer
8164 (get-buffer-window org-last-indirect-buffer))))
8165 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8166 (unless (or (eq org-indirect-buffer-display 'new-frame)
8167 (eq org-indirect-buffer-display 'dedicated-frame))
8168 (unwind-protect
8169 (unless (and indirect-window (window-live-p indirect-window))
8170 (setq indirect-window (split-window agenda-window)))
8171 (and indirect-window (select-window indirect-window))
8172 (switch-to-buffer org-last-indirect-buffer :norecord)
8173 (fit-window-to-buffer indirect-window)))
8174 (select-window (get-buffer-window agenda-buffer)))))
8176 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8177 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8178 (org-agenda-check-no-diary)
8179 (let* ((marker (or (org-get-at-bol 'org-marker)
8180 (org-agenda-error)))
8181 (buffer (marker-buffer marker))
8182 (pos (marker-position marker)))
8183 (with-current-buffer buffer
8184 (save-excursion
8185 (goto-char pos)
8186 (funcall 'org-tree-to-indirect-buffer arg)))))
8188 (defvar org-last-heading-marker (make-marker)
8189 "Marker pointing to the headline that last changed its TODO state
8190 by a remote command from the agenda.")
8192 (defun org-agenda-todo-nextset ()
8193 "Switch TODO entry to next sequence."
8194 (interactive)
8195 (org-agenda-todo 'nextset))
8197 (defun org-agenda-todo-previousset ()
8198 "Switch TODO entry to previous sequence."
8199 (interactive)
8200 (org-agenda-todo 'previousset))
8202 (defun org-agenda-todo (&optional arg)
8203 "Cycle TODO state of line at point, also in Org-mode file.
8204 This changes the line at point, all other lines in the agenda referring to
8205 the same tree node, and the headline of the tree node in the Org-mode file."
8206 (interactive "P")
8207 (org-agenda-check-no-diary)
8208 (let* ((col (current-column))
8209 (marker (or (org-get-at-bol 'org-marker)
8210 (org-agenda-error)))
8211 (buffer (marker-buffer marker))
8212 (pos (marker-position marker))
8213 (hdmarker (org-get-at-bol 'org-hd-marker))
8214 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8215 (inhibit-read-only t)
8216 org-agenda-headline-snapshot-before-repeat newhead just-one)
8217 (org-with-remote-undo buffer
8218 (with-current-buffer buffer
8219 (widen)
8220 (goto-char pos)
8221 (org-show-context 'agenda)
8222 (save-excursion
8223 (and (outline-next-heading)
8224 (org-flag-heading nil))) ; show the next heading
8225 (let ((current-prefix-arg arg))
8226 (call-interactively 'org-todo))
8227 (and (bolp) (forward-char 1))
8228 (setq newhead (org-get-heading))
8229 (when (and (org-bound-and-true-p
8230 org-agenda-headline-snapshot-before-repeat)
8231 (not (equal org-agenda-headline-snapshot-before-repeat
8232 newhead))
8233 todayp)
8234 (setq newhead org-agenda-headline-snapshot-before-repeat
8235 just-one t))
8236 (save-excursion
8237 (org-back-to-heading)
8238 (move-marker org-last-heading-marker (point))))
8239 (beginning-of-line 1)
8240 (save-excursion
8241 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8242 (org-move-to-column col))))
8244 (defun org-agenda-add-note (&optional arg)
8245 "Add a time-stamped note to the entry at point."
8246 (interactive "P")
8247 (org-agenda-check-no-diary)
8248 (let* ((marker (or (org-get-at-bol 'org-marker)
8249 (org-agenda-error)))
8250 (buffer (marker-buffer marker))
8251 (pos (marker-position marker))
8252 (hdmarker (org-get-at-bol 'org-hd-marker))
8253 (inhibit-read-only t))
8254 (with-current-buffer buffer
8255 (widen)
8256 (goto-char pos)
8257 (org-show-context 'agenda)
8258 (save-excursion
8259 (and (outline-next-heading)
8260 (org-flag-heading nil))) ; show the next heading
8261 (org-add-note))))
8263 (defun org-agenda-change-all-lines (newhead hdmarker
8264 &optional fixface just-this)
8265 "Change all lines in the agenda buffer which match HDMARKER.
8266 The new content of the line will be NEWHEAD (as modified by
8267 `org-agenda-format-item'). HDMARKER is checked with
8268 `equal' against all `org-hd-marker' text properties in the file.
8269 If FIXFACE is non-nil, the face of each item is modified according to
8270 the new TODO state.
8271 If JUST-THIS is non-nil, change just the current line, not all.
8272 If FORCE-TAGS is non nil, the car of it returns the new tags."
8273 (let* ((inhibit-read-only t)
8274 (line (org-current-line))
8275 (org-agenda-buffer (current-buffer))
8276 (thetags (with-current-buffer (marker-buffer hdmarker)
8277 (save-excursion (save-restriction (widen)
8278 (goto-char hdmarker)
8279 (org-get-tags-at)))))
8280 props m pl undone-face done-face finish new dotime cat tags)
8281 (save-excursion
8282 (goto-char (point-max))
8283 (beginning-of-line 1)
8284 (while (not finish)
8285 (setq finish (bobp))
8286 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8287 (or (not just-this) (= (org-current-line) line))
8288 (equal m hdmarker))
8289 (setq props (text-properties-at (point))
8290 dotime (org-get-at-bol 'dotime)
8291 cat (org-get-at-bol 'org-category)
8292 tags thetags
8294 (let ((org-prefix-format-compiled
8295 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8296 org-prefix-format-compiled))
8297 (extra (org-get-at-bol 'extra)))
8298 (with-current-buffer (marker-buffer hdmarker)
8299 (save-excursion
8300 (save-restriction
8301 (widen)
8302 (org-agenda-format-item extra newhead cat tags dotime)))))
8303 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8304 undone-face (org-get-at-bol 'undone-face)
8305 done-face (org-get-at-bol 'done-face))
8306 (beginning-of-line 1)
8307 (cond
8308 ((equal new "")
8309 (and (looking-at ".*\n?") (replace-match "")))
8310 ((looking-at ".*")
8311 (replace-match new t t)
8312 (beginning-of-line 1)
8313 (add-text-properties (point-at-bol) (point-at-eol) props)
8314 (when fixface
8315 (add-text-properties
8316 (point-at-bol) (point-at-eol)
8317 (list 'face
8318 (if org-last-todo-state-is-todo
8319 undone-face done-face))))
8320 (org-agenda-highlight-todo 'line)
8321 (beginning-of-line 1))
8322 (t (error "Line update did not work")))
8323 (save-restriction
8324 (narrow-to-region (point-at-bol) (point-at-eol))
8325 (org-agenda-finalize)))
8326 (beginning-of-line 0)))))
8328 (defun org-agenda-align-tags (&optional line)
8329 "Align all tags in agenda items to `org-agenda-tags-column'."
8330 (let ((inhibit-read-only t) l c)
8331 (save-excursion
8332 (goto-char (if line (point-at-bol) (point-min)))
8333 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8334 (if line (point-at-eol) nil) t)
8335 (add-text-properties
8336 (match-beginning 2) (match-end 2)
8337 (list 'face (delq nil (let ((prop (get-text-property
8338 (match-beginning 2) 'face)))
8339 (or (listp prop) (setq prop (list prop)))
8340 (if (memq 'org-tag prop)
8341 prop
8342 (cons 'org-tag prop))))))
8343 (setq l (- (match-end 2) (match-beginning 2))
8344 c (if (< org-agenda-tags-column 0)
8345 (- (abs org-agenda-tags-column) l)
8346 org-agenda-tags-column))
8347 (delete-region (match-beginning 1) (match-end 1))
8348 (goto-char (match-beginning 1))
8349 (insert (org-add-props
8350 (make-string (max 1 (- c (current-column))) ?\ )
8351 (plist-put (copy-sequence (text-properties-at (point)))
8352 'face nil))))
8353 (goto-char (point-min))
8354 (org-font-lock-add-tag-faces (point-max)))))
8356 (defun org-agenda-priority-up ()
8357 "Increase the priority of line at point, also in Org-mode file."
8358 (interactive)
8359 (org-agenda-priority 'up))
8361 (defun org-agenda-priority-down ()
8362 "Decrease the priority of line at point, also in Org-mode file."
8363 (interactive)
8364 (org-agenda-priority 'down))
8366 (defun org-agenda-priority (&optional force-direction)
8367 "Set the priority of line at point, also in Org-mode file.
8368 This changes the line at point, all other lines in the agenda referring to
8369 the same tree node, and the headline of the tree node in the Org-mode file.
8370 Called with a universal prefix arg, show the priority instead of setting it."
8371 (interactive "P")
8372 (if (equal force-direction '(4))
8373 (org-show-priority)
8374 (unless org-enable-priority-commands
8375 (error "Priority commands are disabled"))
8376 (org-agenda-check-no-diary)
8377 (let* ((marker (or (org-get-at-bol 'org-marker)
8378 (org-agenda-error)))
8379 (hdmarker (org-get-at-bol 'org-hd-marker))
8380 (buffer (marker-buffer hdmarker))
8381 (pos (marker-position hdmarker))
8382 (inhibit-read-only t)
8383 newhead)
8384 (org-with-remote-undo buffer
8385 (with-current-buffer buffer
8386 (widen)
8387 (goto-char pos)
8388 (org-show-context 'agenda)
8389 (save-excursion
8390 (and (outline-next-heading)
8391 (org-flag-heading nil))) ; show the next heading
8392 (funcall 'org-priority force-direction)
8393 (end-of-line 1)
8394 (setq newhead (org-get-heading)))
8395 (org-agenda-change-all-lines newhead hdmarker)
8396 (beginning-of-line 1)))))
8398 ;; FIXME: should fix the tags property of the agenda line.
8399 (defun org-agenda-set-tags (&optional tag onoff)
8400 "Set tags for the current headline."
8401 (interactive)
8402 (org-agenda-check-no-diary)
8403 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8404 (call-interactively 'org-change-tag-in-region)
8405 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8406 (org-agenda-error)))
8407 (buffer (marker-buffer hdmarker))
8408 (pos (marker-position hdmarker))
8409 (inhibit-read-only t)
8410 newhead)
8411 (org-with-remote-undo buffer
8412 (with-current-buffer buffer
8413 (widen)
8414 (goto-char pos)
8415 (save-excursion
8416 (org-show-context 'agenda))
8417 (save-excursion
8418 (and (outline-next-heading)
8419 (org-flag-heading nil))) ; show the next heading
8420 (goto-char pos)
8421 (if tag
8422 (org-toggle-tag tag onoff)
8423 (call-interactively 'org-set-tags))
8424 (end-of-line 1)
8425 (setq newhead (org-get-heading)))
8426 (org-agenda-change-all-lines newhead hdmarker)
8427 (beginning-of-line 1)))))
8429 (defun org-agenda-set-property ()
8430 "Set a property for the current headline."
8431 (interactive)
8432 (org-agenda-check-no-diary)
8433 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8434 (org-agenda-error)))
8435 (buffer (marker-buffer hdmarker))
8436 (pos (marker-position hdmarker))
8437 (inhibit-read-only t)
8438 newhead)
8439 (org-with-remote-undo buffer
8440 (with-current-buffer buffer
8441 (widen)
8442 (goto-char pos)
8443 (save-excursion
8444 (org-show-context 'agenda))
8445 (save-excursion
8446 (and (outline-next-heading)
8447 (org-flag-heading nil))) ; show the next heading
8448 (goto-char pos)
8449 (call-interactively 'org-set-property)))))
8451 (defun org-agenda-set-effort ()
8452 "Set the effort property for the current headline."
8453 (interactive)
8454 (org-agenda-check-no-diary)
8455 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8456 (org-agenda-error)))
8457 (buffer (marker-buffer hdmarker))
8458 (pos (marker-position hdmarker))
8459 (inhibit-read-only t)
8460 newhead)
8461 (org-with-remote-undo buffer
8462 (with-current-buffer buffer
8463 (widen)
8464 (goto-char pos)
8465 (save-excursion
8466 (org-show-context 'agenda))
8467 (save-excursion
8468 (and (outline-next-heading)
8469 (org-flag-heading nil))) ; show the next heading
8470 (goto-char pos)
8471 (call-interactively 'org-set-effort)
8472 (end-of-line 1)
8473 (setq newhead (org-get-heading)))
8474 (org-agenda-change-all-lines newhead hdmarker))))
8476 (defun org-agenda-toggle-archive-tag ()
8477 "Toggle the archive tag for the current entry."
8478 (interactive)
8479 (org-agenda-check-no-diary)
8480 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8481 (org-agenda-error)))
8482 (buffer (marker-buffer hdmarker))
8483 (pos (marker-position hdmarker))
8484 (inhibit-read-only t)
8485 newhead)
8486 (org-with-remote-undo buffer
8487 (with-current-buffer buffer
8488 (widen)
8489 (goto-char pos)
8490 (org-show-context 'agenda)
8491 (save-excursion
8492 (and (outline-next-heading)
8493 (org-flag-heading nil))) ; show the next heading
8494 (call-interactively 'org-toggle-archive-tag)
8495 (end-of-line 1)
8496 (setq newhead (org-get-heading)))
8497 (org-agenda-change-all-lines newhead hdmarker)
8498 (beginning-of-line 1))))
8500 (defun org-agenda-do-date-later (arg)
8501 (interactive "P")
8502 (cond
8503 ((or (equal arg '(16))
8504 (memq last-command
8505 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8506 (setq this-command 'org-agenda-date-later-minutes)
8507 (org-agenda-date-later-minutes 1))
8508 ((or (equal arg '(4))
8509 (memq last-command
8510 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8511 (setq this-command 'org-agenda-date-later-hours)
8512 (org-agenda-date-later-hours 1))
8514 (org-agenda-date-later (prefix-numeric-value arg)))))
8516 (defun org-agenda-do-date-earlier (arg)
8517 (interactive "P")
8518 (cond
8519 ((or (equal arg '(16))
8520 (memq last-command
8521 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8522 (setq this-command 'org-agenda-date-earlier-minutes)
8523 (org-agenda-date-earlier-minutes 1))
8524 ((or (equal arg '(4))
8525 (memq last-command
8526 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8527 (setq this-command 'org-agenda-date-earlier-hours)
8528 (org-agenda-date-earlier-hours 1))
8530 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8532 (defun org-agenda-date-later (arg &optional what)
8533 "Change the date of this item to ARG day(s) later."
8534 (interactive "p")
8535 (org-agenda-check-type t 'agenda 'timeline)
8536 (org-agenda-check-no-diary)
8537 (let* ((marker (or (org-get-at-bol 'org-marker)
8538 (org-agenda-error)))
8539 (buffer (marker-buffer marker))
8540 (pos (marker-position marker))
8541 cdate today)
8542 (org-with-remote-undo buffer
8543 (with-current-buffer buffer
8544 (widen)
8545 (goto-char pos)
8546 (if (not (org-at-timestamp-p))
8547 (error "Cannot find time stamp"))
8548 (when (and org-agenda-move-date-from-past-immediately-to-today
8549 (equal arg 1)
8550 (or (not what) (eq what 'day))
8551 (not (save-match-data (org-at-date-range-p))))
8552 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8553 cdate (calendar-absolute-from-gregorian
8554 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8555 today (org-today))
8556 (if (> today cdate)
8557 ;; immediately shift to today
8558 (setq arg (- today cdate))))
8559 (org-timestamp-change arg (or what 'day))
8560 (when (and (org-at-date-range-p)
8561 (re-search-backward org-tr-regexp-both (point-at-bol)))
8562 (let ((end org-last-changed-timestamp))
8563 (org-timestamp-change arg (or what 'day))
8564 (setq org-last-changed-timestamp
8565 (concat org-last-changed-timestamp "--" end)))))
8566 (org-agenda-show-new-time marker org-last-changed-timestamp))
8567 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8569 (defun org-agenda-date-earlier (arg &optional what)
8570 "Change the date of this item to ARG day(s) earlier."
8571 (interactive "p")
8572 (org-agenda-date-later (- arg) what))
8574 (defun org-agenda-date-later-minutes (arg)
8575 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8576 (interactive "p")
8577 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8578 (org-agenda-date-later arg 'minute))
8580 (defun org-agenda-date-earlier-minutes (arg)
8581 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8582 (interactive "p")
8583 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8584 (org-agenda-date-earlier arg 'minute))
8586 (defun org-agenda-date-later-hours (arg)
8587 "Change the time of this item, in hour steps."
8588 (interactive "p")
8589 (org-agenda-date-later arg 'hour))
8591 (defun org-agenda-date-earlier-hours (arg)
8592 "Change the time of this item, in hour steps."
8593 (interactive "p")
8594 (org-agenda-date-earlier arg 'hour))
8596 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8597 "Show new date stamp via text properties."
8598 ;; We use text properties to make this undoable
8599 (let ((inhibit-read-only t)
8600 (buffer-invisibility-spec))
8601 (setq stamp (concat " " prefix " => " stamp))
8602 (save-excursion
8603 (goto-char (point-max))
8604 (while (not (bobp))
8605 (when (equal marker (org-get-at-bol 'org-marker))
8606 (org-move-to-column (- (window-width) (length stamp)) t)
8607 (org-agenda-fix-tags-filter-overlays-at (point))
8608 (if (featurep 'xemacs)
8609 ;; Use `duplicable' property to trigger undo recording
8610 (let ((ex (make-extent nil nil))
8611 (gl (make-glyph stamp)))
8612 (set-glyph-face gl 'secondary-selection)
8613 (set-extent-properties
8614 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8615 (insert-extent ex (1- (point)) (point-at-eol)))
8616 (add-text-properties
8617 (1- (point)) (point-at-eol)
8618 (list 'display (org-add-props stamp nil
8619 'face 'secondary-selection))))
8620 (beginning-of-line 1))
8621 (beginning-of-line 0)))))
8623 (defun org-agenda-date-prompt (arg)
8624 "Change the date of this item. Date is prompted for, with default today.
8625 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8626 be used to request time specification in the time stamp."
8627 (interactive "P")
8628 (org-agenda-check-type t 'agenda 'timeline)
8629 (org-agenda-check-no-diary)
8630 (let* ((marker (or (org-get-at-bol 'org-marker)
8631 (org-agenda-error)))
8632 (buffer (marker-buffer marker))
8633 (pos (marker-position marker)))
8634 (org-with-remote-undo buffer
8635 (with-current-buffer buffer
8636 (widen)
8637 (goto-char pos)
8638 (if (not (org-at-timestamp-p t))
8639 (error "Cannot find time stamp"))
8640 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8641 (org-agenda-show-new-time marker org-last-changed-timestamp))
8642 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8644 (defun org-agenda-schedule (arg &optional time)
8645 "Schedule the item at point.
8646 ARG is passed through to `org-schedule'."
8647 (interactive "P")
8648 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8649 (org-agenda-check-no-diary)
8650 (let* ((marker (or (org-get-at-bol 'org-marker)
8651 (org-agenda-error)))
8652 (type (marker-insertion-type marker))
8653 (buffer (marker-buffer marker))
8654 (pos (marker-position marker))
8655 (org-insert-labeled-timestamps-at-point nil)
8657 (set-marker-insertion-type marker t)
8658 (org-with-remote-undo buffer
8659 (with-current-buffer buffer
8660 (widen)
8661 (goto-char pos)
8662 (setq ts (org-schedule arg time)))
8663 (org-agenda-show-new-time marker ts "S"))
8664 (message "%s" ts)))
8666 (defun org-agenda-deadline (arg &optional time)
8667 "Schedule the item at point.
8668 ARG is passed through to `org-deadline'."
8669 (interactive "P")
8670 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8671 (org-agenda-check-no-diary)
8672 (let* ((marker (or (org-get-at-bol 'org-marker)
8673 (org-agenda-error)))
8674 (buffer (marker-buffer marker))
8675 (pos (marker-position marker))
8676 (org-insert-labeled-timestamps-at-point nil)
8678 (org-with-remote-undo buffer
8679 (with-current-buffer buffer
8680 (widen)
8681 (goto-char pos)
8682 (setq ts (org-deadline arg time)))
8683 (org-agenda-show-new-time marker ts "D"))
8684 (message "%s" ts)))
8686 (defun org-agenda-clock-in (&optional arg)
8687 "Start the clock on the currently selected item."
8688 (interactive "P")
8689 (org-agenda-check-no-diary)
8690 (if (equal arg '(4))
8691 (org-clock-in arg)
8692 (let* ((marker (or (org-get-at-bol 'org-marker)
8693 (org-agenda-error)))
8694 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8695 marker))
8696 (pos (marker-position marker))
8697 newhead)
8698 (org-with-remote-undo (marker-buffer marker)
8699 (with-current-buffer (marker-buffer marker)
8700 (widen)
8701 (goto-char pos)
8702 (org-show-context 'agenda)
8703 (org-show-entry)
8704 (org-cycle-hide-drawers 'children)
8705 (org-clock-in arg)
8706 (setq newhead (org-get-heading)))
8707 (org-agenda-change-all-lines newhead hdmarker)))))
8709 (defun org-agenda-clock-out ()
8710 "Stop the currently running clock."
8711 (interactive)
8712 (unless (marker-buffer org-clock-marker)
8713 (error "No running clock"))
8714 (let ((marker (make-marker)) newhead)
8715 (org-with-remote-undo (marker-buffer org-clock-marker)
8716 (with-current-buffer (marker-buffer org-clock-marker)
8717 (save-excursion
8718 (save-restriction
8719 (widen)
8720 (goto-char org-clock-marker)
8721 (org-back-to-heading t)
8722 (move-marker marker (point))
8723 (org-clock-out)
8724 (setq newhead (org-get-heading))))))
8725 (org-agenda-change-all-lines newhead marker)
8726 (move-marker marker nil)))
8728 (defun org-agenda-clock-cancel (&optional arg)
8729 "Cancel the currently running clock."
8730 (interactive "P")
8731 (unless (marker-buffer org-clock-marker)
8732 (error "No running clock"))
8733 (org-with-remote-undo (marker-buffer org-clock-marker)
8734 (org-clock-cancel)))
8736 (defun org-agenda-clock-goto ()
8737 "Jump to the currently clocked in task within the agenda.
8738 If the currently clocked in task is not listed in the agenda
8739 buffer, display it in another window."
8740 (interactive)
8741 (let (pos)
8742 (mapc (lambda (o)
8743 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8744 (setq pos (overlay-start o))))
8745 (overlays-in (point-min) (point-max)))
8746 (cond (pos (goto-char pos))
8747 ;; If the currently clocked entry is not in the agenda
8748 ;; buffer, we visit it in another window:
8749 (org-clock-current-task
8750 (org-switch-to-buffer-other-window (org-clock-goto)))
8751 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8753 (defun org-agenda-diary-entry-in-org-file ()
8754 "Make a diary entry in the file `org-agenda-diary-file'."
8755 (let (d1 d2 char (text "") dp1 dp2)
8756 (if (equal (buffer-name) "*Calendar*")
8757 (setq d1 (calendar-cursor-to-date t)
8758 d2 (car calendar-mark-ring))
8759 (setq dp1 (get-text-property (point-at-bol) 'day))
8760 (unless dp1 (error "No date defined in current line"))
8761 (setq d1 (calendar-gregorian-from-absolute dp1)
8762 d2 (and (ignore-errors (mark))
8763 (save-excursion
8764 (goto-char (mark))
8765 (setq dp2 (get-text-property (point-at-bol) 'day)))
8766 (calendar-gregorian-from-absolute dp2))))
8767 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8768 (setq char (read-char-exclusive))
8769 (cond
8770 ((equal char ?d)
8771 (setq text (read-string "Day entry: "))
8772 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8773 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8774 ((equal char ?a)
8775 (setq d1 (list (car d1) (nth 1 d1)
8776 (read-number (format "Reference year [%d]: " (nth 2 d1))
8777 (nth 2 d1))))
8778 (setq text (read-string "Anniversary (use %d to show years): "))
8779 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8780 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8781 ((equal char ?b)
8782 (setq text (read-string "Block entry: "))
8783 (unless (and d1 d2 (not (equal d1 d2)))
8784 (error "No block of days selected"))
8785 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8786 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8787 ((equal char ?j)
8788 (org-switch-to-buffer-other-window
8789 (find-file-noselect org-agenda-diary-file))
8790 (require 'org-datetree)
8791 (org-datetree-find-date-create d1)
8792 (org-reveal t))
8793 (t (error "Invalid selection character `%c'" char)))))
8795 (defcustom org-agenda-insert-diary-strategy 'date-tree
8796 "Where in `org-agenda-diary-file' should new entries be added?
8797 Valid values:
8799 date-tree in the date tree, as child of the date
8800 top-level as top-level entries at the end of the file."
8801 :group 'org-agenda
8802 :type '(choice
8803 (const :tag "in a date tree" date-tree)
8804 (const :tag "as top level at end of file" top-level)))
8806 (defcustom org-agenda-insert-diary-extract-time nil
8807 "Non-nil means extract any time specification from the diary entry."
8808 :group 'org-agenda
8809 :version "24.1"
8810 :type 'boolean)
8812 (defcustom org-agenda-bulk-mark-char ">"
8813 "A single-character string to be used as the bulk mark."
8814 :group 'org-agenda
8815 :version "24.1"
8816 :type 'string)
8818 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8819 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8820 If TEXT is not empty, it will become the headline of the new entry, and
8821 the resulting entry will not be shown. When TEXT is empty, switch to
8822 `org-agenda-diary-file' and let the user finish the entry there."
8823 (let ((cw (current-window-configuration)))
8824 (org-switch-to-buffer-other-window
8825 (find-file-noselect org-agenda-diary-file))
8826 (widen)
8827 (goto-char (point-min))
8828 (cond
8829 ((eq type 'anniversary)
8830 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8831 (progn
8832 (or (org-at-heading-p t)
8833 (progn
8834 (outline-next-heading)
8835 (insert "* Anniversaries\n\n")
8836 (beginning-of-line -1)))))
8837 (outline-next-heading)
8838 (org-back-over-empty-lines)
8839 (backward-char 1)
8840 (insert "\n")
8841 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8842 (nth 2 d1) (car d1) (nth 1 d1) text)))
8843 ((eq type 'day)
8844 (let ((org-prefix-has-time t)
8845 (org-agenda-time-leading-zero t)
8846 fmt time time2)
8847 (if org-agenda-insert-diary-extract-time
8848 ;; Use org-agenda-format-item to parse text for a time-range and
8849 ;; remove it. FIXME: This is a hack, we should refactor
8850 ;; that function to make time extraction available separately
8851 (setq fmt (org-agenda-format-item nil text nil nil t)
8852 time (get-text-property 0 'time fmt)
8853 time2 (if (> (length time) 0)
8854 ;; split-string removes trailing ...... if
8855 ;; no end time given. First space
8856 ;; separates time from date.
8857 (concat " " (car (split-string time "\\.")))
8858 nil)
8859 text (get-text-property 0 'txt fmt)))
8860 (if (eq org-agenda-insert-diary-strategy 'top-level)
8861 (org-agenda-insert-diary-as-top-level text)
8862 (require 'org-datetree)
8863 (org-datetree-find-date-create d1)
8864 (org-agenda-insert-diary-make-new-entry text))
8865 (org-insert-time-stamp (org-time-from-absolute
8866 (calendar-absolute-from-gregorian d1))
8867 nil nil nil nil time2))
8868 (end-of-line 0))
8869 ((eq type 'block)
8870 (if (> (calendar-absolute-from-gregorian d1)
8871 (calendar-absolute-from-gregorian d2))
8872 (setq d1 (prog1 d2 (setq d2 d1))))
8873 (if (eq org-agenda-insert-diary-strategy 'top-level)
8874 (org-agenda-insert-diary-as-top-level text)
8875 (require 'org-datetree)
8876 (org-datetree-find-date-create d1)
8877 (org-agenda-insert-diary-make-new-entry text))
8878 (org-insert-time-stamp (org-time-from-absolute
8879 (calendar-absolute-from-gregorian d1)))
8880 (insert "--")
8881 (org-insert-time-stamp (org-time-from-absolute
8882 (calendar-absolute-from-gregorian d2)))
8883 (end-of-line 0)))
8884 (if (string-match "\\S-" text)
8885 (progn
8886 (set-window-configuration cw)
8887 (message "%s entry added to %s"
8888 (capitalize (symbol-name type))
8889 (abbreviate-file-name org-agenda-diary-file)))
8890 (org-reveal t)
8891 (message "Please finish entry here"))))
8893 (defun org-agenda-insert-diary-as-top-level (text)
8894 "Make new entry as a top-level entry at the end of the file.
8895 Add TEXT as headline, and position the cursor in the second line so that
8896 a timestamp can be added there."
8897 (widen)
8898 (goto-char (point-max))
8899 (or (bolp) (insert "\n"))
8900 (insert "* " text "\n")
8901 (if org-adapt-indentation (org-indent-to-column 2)))
8903 (defun org-agenda-insert-diary-make-new-entry (text)
8904 "Make new entry as last child of current entry.
8905 Add TEXT as headline, and position the cursor in the second line so that
8906 a timestamp can be added there."
8907 (let ((org-show-following-heading t)
8908 (org-show-siblings t)
8909 (org-show-hierarchy-above t)
8910 (org-show-entry-below t)
8911 col)
8912 (outline-next-heading)
8913 (org-back-over-empty-lines)
8914 (or (looking-at "[ \t]*$")
8915 (progn (insert "\n") (backward-char 1)))
8916 (org-insert-heading nil t)
8917 (org-do-demote)
8918 (setq col (current-column))
8919 (insert text "\n")
8920 (if org-adapt-indentation (org-indent-to-column col))
8921 (let ((org-show-following-heading t)
8922 (org-show-siblings t)
8923 (org-show-hierarchy-above t)
8924 (org-show-entry-below t))
8925 (org-show-context))))
8927 (defun org-agenda-diary-entry ()
8928 "Make a diary entry, like the `i' command from the calendar.
8929 All the standard commands work: block, weekly etc.
8930 When `org-agenda-diary-file' points to a file,
8931 `org-agenda-diary-entry-in-org-file' is called instead to create
8932 entries in that Org-mode file."
8933 (interactive)
8934 (if (not (eq org-agenda-diary-file 'diary-file))
8935 (org-agenda-diary-entry-in-org-file)
8936 (require 'diary-lib)
8937 (let* ((char (progn
8938 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8939 (read-char-exclusive)))
8940 (cmd (cdr (assoc char
8941 '((?d . insert-diary-entry)
8942 (?w . insert-weekly-diary-entry)
8943 (?m . insert-monthly-diary-entry)
8944 (?y . insert-yearly-diary-entry)
8945 (?a . insert-anniversary-diary-entry)
8946 (?b . insert-block-diary-entry)
8947 (?c . insert-cyclic-diary-entry)))))
8948 (oldf (symbol-function 'calendar-cursor-to-date))
8949 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8950 (point (point))
8951 (mark (or (mark t) (point))))
8952 (unless cmd
8953 (error "No command associated with <%c>" char))
8954 (unless (and (get-text-property point 'day)
8955 (or (not (equal ?b char))
8956 (get-text-property mark 'day)))
8957 (error "Don't know which date to use for diary entry"))
8958 ;; We implement this by hacking the `calendar-cursor-to-date' function
8959 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8960 (let ((calendar-mark-ring
8961 (list (calendar-gregorian-from-absolute
8962 (or (get-text-property mark 'day)
8963 (get-text-property point 'day))))))
8964 (unwind-protect
8965 (progn
8966 (fset 'calendar-cursor-to-date
8967 (lambda (&optional error dummy)
8968 (calendar-gregorian-from-absolute
8969 (get-text-property point 'day))))
8970 (call-interactively cmd))
8971 (fset 'calendar-cursor-to-date oldf))))))
8973 (defun org-agenda-execute-calendar-command (cmd)
8974 "Execute a calendar command from the agenda with date from cursor."
8975 (org-agenda-check-type t 'agenda 'timeline)
8976 (require 'diary-lib)
8977 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
8978 (error "Don't know which date to use for the calendar command"))
8979 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8980 (point (point))
8981 (date (calendar-gregorian-from-absolute
8982 (get-text-property point 'day)))
8983 ;; the following 2 vars are needed in the calendar
8984 (displayed-month (car date))
8985 (displayed-year (nth 2 date)))
8986 (unwind-protect
8987 (progn
8988 (fset 'calendar-cursor-to-date
8989 (lambda (&optional error dummy)
8990 (calendar-gregorian-from-absolute
8991 (get-text-property point 'day))))
8992 (call-interactively cmd))
8993 (fset 'calendar-cursor-to-date oldf))))
8995 (defun org-agenda-phases-of-moon ()
8996 "Display the phases of the moon for the 3 months around the cursor date."
8997 (interactive)
8998 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9000 (defun org-agenda-holidays ()
9001 "Display the holidays for the 3 months around the cursor date."
9002 (interactive)
9003 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9005 (defvar calendar-longitude) ; defined in calendar.el
9006 (defvar calendar-latitude) ; defined in calendar.el
9007 (defvar calendar-location-name) ; defined in calendar.el
9009 (defun org-agenda-sunrise-sunset (arg)
9010 "Display sunrise and sunset for the cursor date.
9011 Latitude and longitude can be specified with the variables
9012 `calendar-latitude' and `calendar-longitude'. When called with prefix
9013 argument, latitude and longitude will be prompted for."
9014 (interactive "P")
9015 (require 'solar)
9016 (let ((calendar-longitude (if arg nil calendar-longitude))
9017 (calendar-latitude (if arg nil calendar-latitude))
9018 (calendar-location-name
9019 (if arg "the given coordinates" calendar-location-name)))
9020 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9022 (defun org-agenda-goto-calendar ()
9023 "Open the Emacs calendar with the date at the cursor."
9024 (interactive)
9025 (org-agenda-check-type t 'agenda 'timeline)
9026 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9027 (error "Don't know which date to open in calendar")))
9028 (date (calendar-gregorian-from-absolute day))
9029 (calendar-move-hook nil)
9030 (calendar-view-holidays-initially-flag nil)
9031 (calendar-view-diary-initially-flag nil))
9032 (calendar)
9033 (calendar-goto-date date)))
9035 ;;;###autoload
9036 (defun org-calendar-goto-agenda ()
9037 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9038 This is a command that has to be installed in `calendar-mode-map'."
9039 (interactive)
9040 (org-agenda-list nil (calendar-absolute-from-gregorian
9041 (calendar-cursor-to-date))
9042 nil))
9044 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9045 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9046 This is a command that has to be installed in `calendar-mode-map'.
9048 \(fn)" t nil)
9050 (defun org-agenda-convert-date ()
9051 (interactive)
9052 (org-agenda-check-type t 'agenda 'timeline)
9053 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9054 date s)
9055 (unless day
9056 (error "Don't know which date to convert"))
9057 (setq date (calendar-gregorian-from-absolute day))
9058 (setq s (concat
9059 "Gregorian: " (calendar-date-string date) "\n"
9060 "ISO: " (calendar-iso-date-string date) "\n"
9061 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9062 "Julian: " (calendar-julian-date-string date) "\n"
9063 "Astron. JD: " (calendar-astro-date-string date)
9064 " (Julian date number at noon UTC)\n"
9065 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9066 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9067 "French: " (calendar-french-date-string date) "\n"
9068 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9069 "Mayan: " (calendar-mayan-date-string date) "\n"
9070 "Coptic: " (calendar-coptic-date-string date) "\n"
9071 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9072 "Persian: " (calendar-persian-date-string date) "\n"
9073 "Chinese: " (calendar-chinese-date-string date) "\n"))
9074 (with-output-to-temp-buffer "*Dates*"
9075 (princ s))
9076 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9078 ;;; Bulk commands
9080 (defun org-agenda-bulk-marked-p ()
9081 (eq (get-char-property (point-at-bol) 'type)
9082 'org-marked-entry-overlay))
9084 (defun org-agenda-bulk-mark (&optional arg)
9085 "Mark the entry at point for future bulk action."
9086 (interactive "p")
9087 (dotimes (i (or arg 1))
9088 (unless (org-get-at-bol 'org-agenda-diary-link)
9089 (let* ((m (org-get-at-bol 'org-hd-marker))
9091 (unless (org-agenda-bulk-marked-p)
9092 (unless m (error "Nothing to mark at point"))
9093 (push m org-agenda-bulk-marked-entries)
9094 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9095 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9096 (org-get-todo-face "TODO")
9097 'evaporate)
9098 (overlay-put ov 'type 'org-marked-entry-overlay))
9099 (beginning-of-line 2)
9100 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9101 (beginning-of-line 2))
9102 (message "%d entries marked for bulk action"
9103 (length org-agenda-bulk-marked-entries))))))
9105 (defun org-agenda-bulk-mark-all ()
9106 "Mark all entries for future agenda bulk action."
9107 (interactive)
9108 (org-agenda-bulk-mark-regexp "."))
9110 (defun org-agenda-bulk-mark-regexp (regexp)
9111 "Mark entries matching REGEXP for future agenda bulk action."
9112 (interactive "sMark entries matching regexp: ")
9113 (let ((entries-marked 0))
9114 (save-excursion
9115 (goto-char (point-min))
9116 (goto-char (next-single-property-change (point) 'txt))
9117 (while (re-search-forward regexp nil t)
9118 (when (string-match regexp (get-text-property (point) 'txt))
9119 (setq entries-marked (1+ entries-marked))
9120 (call-interactively 'org-agenda-bulk-mark))))
9121 (if (not entries-marked)
9122 (message "No entry matching this regexp."))))
9124 (defun org-agenda-bulk-unmark (&optional arg)
9125 "Unmark the entry at point for future bulk action."
9126 (interactive "P")
9127 (if arg
9128 (org-agenda-bulk-unmark-all)
9129 (cond ((org-agenda-bulk-marked-p)
9130 (org-agenda-bulk-remove-overlays
9131 (point-at-bol) (+ 2 (point-at-bol)))
9132 (setq org-agenda-bulk-marked-entries
9133 (delete (org-get-at-bol 'org-hd-marker)
9134 org-agenda-bulk-marked-entries))
9135 (beginning-of-line 2)
9136 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9137 (beginning-of-line 2))
9138 (message "%d entries left marked for bulk action"
9139 (length org-agenda-bulk-marked-entries)))
9140 (t (message "No entry to unmark here")))))
9142 (defun org-agenda-bulk-toggle ()
9143 "Toggle marking the entry at point for bulk action."
9144 (interactive)
9145 (if (org-agenda-bulk-marked-p)
9146 (org-agenda-bulk-unmark)
9147 (org-agenda-bulk-mark)))
9149 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9150 "Remove the mark overlays between BEG and END in the agenda buffer.
9151 BEG and END default to the buffer limits.
9153 This only removes the overlays, it does not remove the markers
9154 from the list in `org-agenda-bulk-marked-entries'."
9155 (interactive)
9156 (mapc (lambda (ov)
9157 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9158 (delete-overlay ov)))
9159 (overlays-in (or beg (point-min)) (or end (point-max)))))
9161 (defun org-agenda-bulk-unmark-all ()
9162 "Remove all marks in the agenda buffer.
9163 This will remove the markers and the overlays."
9164 (interactive)
9165 (if (null org-agenda-bulk-marked-entries)
9166 (message "No entry to unmark")
9167 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9168 (setq org-agenda-bulk-marked-entries nil)
9169 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9171 (defcustom org-agenda-persistent-marks nil
9172 "Non-nil means marked items will stay marked after a bulk action.
9173 You can toggle this interactively by typing `p' when prompted for a
9174 bulk action."
9175 :group 'org-agenda
9176 :version "24.1"
9177 :type 'boolean)
9179 (defun org-agenda-bulk-action (&optional arg)
9180 "Execute an remote-editing action on all marked entries.
9181 The prefix arg is passed through to the command if possible."
9182 (interactive "P")
9183 ;; Make sure we have markers, and only valid ones
9184 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9185 (mapc
9186 (lambda (m)
9187 (unless (and (markerp m)
9188 (marker-buffer m)
9189 (buffer-live-p (marker-buffer m))
9190 (marker-position m))
9191 (error "Marker %s for bulk command is invalid" m)))
9192 org-agenda-bulk-marked-entries)
9194 ;; Prompt for the bulk command
9195 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9196 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9197 "[S]catter [f]unction "
9198 (when org-agenda-bulk-custom-functions
9199 (concat " Custom: ["
9200 (mapconcat (lambda(f) (char-to-string (car f)))
9201 org-agenda-bulk-custom-functions "")
9202 "]"))))
9203 (catch 'exit
9204 (let* ((action (read-char-exclusive))
9205 (org-log-refile (if org-log-refile 'time nil))
9206 (entries (reverse org-agenda-bulk-marked-entries))
9207 (org-overriding-default-time
9208 (if (get-text-property (point) 'org-agenda-date-header)
9209 (org-get-cursor-date)))
9210 redo-at-end
9211 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9212 (cond
9213 ((equal action ?p)
9214 (let ((org-agenda-persistent-marks
9215 (not org-agenda-persistent-marks)))
9216 (org-agenda-bulk-action)
9217 (throw 'exit nil)))
9219 ((equal action ?$)
9220 (setq cmd '(org-agenda-archive)))
9222 ((equal action ?A)
9223 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9225 ((member action '(?r ?w))
9226 (setq rfloc (org-refile-get-location
9227 "Refile to"
9228 (marker-buffer (car entries))
9229 org-refile-allow-creating-parent-nodes))
9230 (if (nth 3 rfloc)
9231 (setcar (nthcdr 3 rfloc)
9232 (move-marker (make-marker) (nth 3 rfloc)
9233 (or (get-file-buffer (nth 1 rfloc))
9234 (find-buffer-visiting (nth 1 rfloc))
9235 (error "This should not happen")))))
9237 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9238 redo-at-end t))
9240 ((equal action ?t)
9241 (setq state (org-icompleting-read
9242 "Todo state: "
9243 (with-current-buffer (marker-buffer (car entries))
9244 (mapcar 'list org-todo-keywords-1))))
9245 (setq cmd `(let ((org-inhibit-blocking t)
9246 (org-inhibit-logging 'note))
9247 (org-agenda-todo ,state))))
9249 ((memq action '(?- ?+))
9250 (setq tag (org-icompleting-read
9251 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9252 (with-current-buffer (marker-buffer (car entries))
9253 (delq nil
9254 (mapcar (lambda (x)
9255 (if (stringp (car x)) x)) org-tag-alist)))))
9256 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9258 ((memq action '(?s ?d))
9259 (let* ((time
9260 (unless arg
9261 (org-read-date
9262 nil nil nil
9263 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9264 org-overriding-default-time)))
9265 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9266 (setq cmd `(eval '(,c1 arg ,time)))))
9268 ((equal action ?S)
9269 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9270 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9271 (let ((days (read-number
9272 (format "Scatter tasks across how many %sdays: "
9273 (if arg "week" "")) 7)))
9274 (setq cmd
9275 `(let ((distance (1+ (random ,days))))
9276 (if arg
9277 (let ((dist distance)
9278 (day-of-week
9279 (calendar-day-of-week
9280 (calendar-gregorian-from-absolute (org-today)))))
9281 (dotimes (i (1+ dist))
9282 (while (member day-of-week org-agenda-weekend-days)
9283 (incf distance)
9284 (incf day-of-week)
9285 (if (= day-of-week 7)
9286 (setq day-of-week 0)))
9287 (incf day-of-week)
9288 (if (= day-of-week 7)
9289 (setq day-of-week 0)))))
9290 ;; silently fail when try to replan a sexp entry
9291 (condition-case nil
9292 (let* ((date (calendar-gregorian-from-absolute
9293 (+ (org-today) distance)))
9294 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9295 (nth 2 date))))
9296 (org-agenda-schedule nil time))
9297 (error nil)))))))
9299 ((assoc action org-agenda-bulk-custom-functions)
9300 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9301 redo-at-end t))
9303 ((equal action ?f)
9304 (setq cmd (list (intern
9305 (org-icompleting-read "Function: "
9306 obarray 'fboundp t nil nil)))))
9308 (t (error "Invalid bulk action")))
9310 ;; Sort the markers, to make sure that parents are handled before children
9311 (setq entries (sort entries
9312 (lambda (a b)
9313 (cond
9314 ((equal (marker-buffer a) (marker-buffer b))
9315 (< (marker-position a) (marker-position b)))
9317 (string< (buffer-name (marker-buffer a))
9318 (buffer-name (marker-buffer b))))))))
9320 ;; Now loop over all markers and apply cmd
9321 (while (setq e (pop entries))
9322 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9323 (if (not pos)
9324 (progn (message "Skipping removed entry at %s" e)
9325 (setq cntskip (1+ cntskip)))
9326 (goto-char pos)
9327 (let (org-loop-over-headlines-in-active-region)
9328 (eval cmd))
9329 (setq cnt (1+ cnt))))
9330 (when redo-at-end (org-agenda-redo))
9331 (unless org-agenda-persistent-marks
9332 (org-agenda-bulk-unmark-all))
9333 (message "Acted on %d entries%s%s"
9335 (if (= cntskip 0)
9337 (format ", skipped %d (disappeared before their turn)"
9338 cntskip))
9339 (if (not org-agenda-persistent-marks)
9340 "" " (kept marked)"))))))
9342 (defun org-agenda-capture ()
9343 "Call `org-capture' with the date at point."
9344 (interactive)
9345 (if (not (eq major-mode 'org-agenda-mode))
9346 (error "You cannot do this outside of agenda buffers")
9347 (let ((org-overriding-default-time
9348 (org-get-cursor-date)))
9349 (call-interactively 'org-capture))))
9351 ;;; Flagging notes
9353 (defun org-agenda-show-the-flagging-note ()
9354 "Display the flagging note in the other window.
9355 When called a second time in direct sequence, offer to remove the FLAGGING
9356 tag and (if present) the flagging note."
9357 (interactive)
9358 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9359 (win (selected-window))
9360 note heading newhead)
9361 (unless hdmarker
9362 (error "No linked entry at point"))
9363 (if (and (eq this-command last-command)
9364 (y-or-n-p "Unflag and remove any flagging note? "))
9365 (progn
9366 (org-agenda-remove-flag hdmarker)
9367 (let ((win (get-buffer-window "*Flagging Note*")))
9368 (and win (delete-window win)))
9369 (message "Entry unflagged"))
9370 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9371 (unless note
9372 (error "No flagging note"))
9373 (org-kill-new note)
9374 (org-switch-to-buffer-other-window "*Flagging Note*")
9375 (erase-buffer)
9376 (insert note)
9377 (goto-char (point-min))
9378 (while (re-search-forward "\\\\n" nil t)
9379 (replace-match "\n" t t))
9380 (goto-char (point-min))
9381 (select-window win)
9382 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9384 (defun org-agenda-remove-flag (marker)
9385 "Remove the FLAGGED tag and any flagging note in the entry."
9386 (let (newhead)
9387 (org-with-point-at marker
9388 (org-toggle-tag "FLAGGED" 'off)
9389 (org-entry-delete nil "THEFLAGGINGNOTE")
9390 (setq newhead (org-get-heading)))
9391 (org-agenda-change-all-lines newhead marker)
9392 (message "Entry unflagged")))
9394 (defun org-agenda-get-any-marker (&optional pos)
9395 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9396 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9398 ;;; Appointment reminders
9400 (defvar appt-time-msg-list) ; defined in appt.el
9402 ;;;###autoload
9403 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9404 "Activate appointments found in `org-agenda-files'.
9405 With a \\[universal-argument] prefix, refresh the list of
9406 appointments.
9408 If FILTER is t, interactively prompt the user for a regular
9409 expression, and filter out entries that don't match it.
9411 If FILTER is a string, use this string as a regular expression
9412 for filtering entries out.
9414 If FILTER is a function, filter out entries against which
9415 calling the function returns nil. This function takes one
9416 argument: an entry from `org-agenda-get-day-entries'.
9418 FILTER can also be an alist with the car of each cell being
9419 either 'headline or 'category. For example:
9421 '((headline \"IMPORTANT\")
9422 (category \"Work\"))
9424 will only add headlines containing IMPORTANT or headlines
9425 belonging to the \"Work\" category.
9427 ARGS are symbols indicating what kind of entries to consider.
9428 By default `org-agenda-to-appt' will use :deadline, :scheduled
9429 and :timestamp entries. See the docstring of `org-diary' for
9430 details and examples.
9432 If an entry as a APPT_WARNTIME property, its value will be used
9433 to override `appt-message-warning-time'."
9434 (interactive "P")
9435 (if refresh (setq appt-time-msg-list nil))
9436 (if (eq filter t)
9437 (setq filter (read-from-minibuffer "Regexp filter: ")))
9438 (let* ((cnt 0) ; count added events
9439 (scope (or args '(:deadline :scheduled :timestamp)))
9440 (org-agenda-new-buffers nil)
9441 (org-deadline-warning-days 0)
9442 ;; Do not use `org-today' here because appt only takes
9443 ;; time and without date as argument, so it may pass wrong
9444 ;; information otherwise
9445 (today (org-date-to-gregorian
9446 (time-to-days (current-time))))
9447 (org-agenda-restrict nil)
9448 (files (org-agenda-files 'unrestricted)) entries file
9449 (org-agenda-buffer nil))
9450 ;; Get all entries which may contain an appt
9451 (org-agenda-prepare-buffers files)
9452 (while (setq file (pop files))
9453 (setq entries
9454 (delq nil
9455 (append entries
9456 (apply 'org-agenda-get-day-entries
9457 file today scope)))))
9458 ;; Map thru entries and find if we should filter them out
9459 (mapc
9460 (lambda(x)
9461 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9462 (cat (get-text-property 1 'org-category x))
9463 (tod (get-text-property 1 'time-of-day x))
9464 (ok (or (null filter)
9465 (and (stringp filter) (string-match filter evt))
9466 (and (functionp filter) (funcall filter x))
9467 (and (listp filter)
9468 (let ((cat-filter (cadr (assoc 'category filter)))
9469 (evt-filter (cadr (assoc 'headline filter))))
9470 (or (and (stringp cat-filter)
9471 (string-match cat-filter cat))
9472 (and (stringp evt-filter)
9473 (string-match evt-filter evt)))))))
9474 (wrn (get-text-property 1 'warntime x)))
9475 ;; FIXME: Shall we remove text-properties for the appt text?
9476 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9477 (when (and ok tod)
9478 (setq tod (concat "00" (number-to-string tod))
9479 tod (when (string-match
9480 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9481 (concat (match-string 1 tod) ":"
9482 (match-string 2 tod))))
9483 (if (version< emacs-version "23.3")
9484 (appt-add tod evt)
9485 (appt-add tod evt wrn))
9486 (setq cnt (1+ cnt))))) entries)
9487 (org-release-buffers org-agenda-new-buffers)
9488 (if (eq cnt 0)
9489 (message "No event to add")
9490 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9492 (autoload 'org-agenda-to-appt "org-agenda" "\
9493 Activate appointments found in `org-agenda-files'.
9494 With a \\[universal-argument] prefix, refresh the list of
9495 appointments.
9497 If FILTER is t, interactively prompt the user for a regular
9498 expression, and filter out entries that don't match it.
9500 If FILTER is a string, use this string as a regular expression
9501 for filtering entries out.
9503 If FILTER is a function, filter out entries against which
9504 calling the function returns nil. This function takes one
9505 argument: an entry from `org-agenda-get-day-entries'.
9507 FILTER can also be an alist with the car of each cell being
9508 either 'headline or 'category. For example:
9510 '((headline \"IMPORTANT\")
9511 (category \"Work\"))
9513 will only add headlines containing IMPORTANT or headlines
9514 belonging to the \"Work\" category.
9516 ARGS are symbols indicating what kind of entries to consider.
9517 By default `org-agenda-to-appt' will use :deadline, :scheduled
9518 and :timestamp entries. See the docstring of `org-diary' for
9519 details and examples.
9521 If an entry as a APPT_WARNTIME property, its value will be used
9522 to override `appt-message-warning-time'.
9524 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9526 (defun org-agenda-todayp (date)
9527 "Does DATE mean today, when considering `org-extend-today-until'?"
9528 (let ((today (org-today))
9529 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9530 date)))
9531 (eq date today)))
9533 (defun org-agenda-todo-yesterday (&optional arg)
9534 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9535 (interactive "P")
9536 (let* ((hour (third (decode-time
9537 (org-current-time))))
9538 (org-extend-today-until (1+ hour)))
9539 (org-agenda-todo arg)))
9541 (provide 'org-agenda)
9543 ;;; org-agenda.el ends here