New option `org-time-clocksum-use-effort-durations'
[org-mode.git] / lisp / org-agenda.el
blob75bb06de5b565da6b40dea4c6793a3ecb24b5625
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, the symbol `pre-scheduled',
831 or a number which will then give the number of days before the actual
832 deadline when the prewarnings should resume. The symbol `pre-scheduled'
833 eliminates the deadline prewarning only prior to the scheduled date.
834 This can be used in a workflow where the first showing of the deadline will
835 trigger you to schedule it, and then you don't want to be reminded of it
836 because you will take care of it on the day when scheduled."
837 :group 'org-agenda-skip
838 :group 'org-agenda-daily/weekly
839 :version "24.1"
840 :type '(choice
841 (const :tag "Always show prewarning" nil)
842 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
843 (const :tag "Remove prewarning if entry is scheduled" t)
844 (integer :tag "Restart prewarning N days before deadline")))
846 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
847 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
848 When non-nil, after the search for timestamps has matched once in an
849 entry, the rest of the entry will not be searched."
850 :group 'org-agenda-skip
851 :type 'boolean)
853 (defcustom org-agenda-skip-timestamp-if-done nil
854 "Non-nil means don't select item by timestamp or -range if it is DONE."
855 :group 'org-agenda-skip
856 :group 'org-agenda-daily/weekly
857 :type 'boolean)
859 (defcustom org-agenda-dim-blocked-tasks nil
860 "Non-nil means dim blocked tasks in the agenda display.
861 This causes some overhead during agenda construction, but if you
862 have turned on `org-enforce-todo-dependencies',
863 `org-enforce-todo-checkbox-dependencies', or any other blocking
864 mechanism, this will create useful feedback in the agenda.
866 Instead of t, this variable can also have the value `invisible'.
867 Then blocked tasks will be invisible and only become visible when
868 they become unblocked. An exemption to this behavior is when a task is
869 blocked because of unchecked checkboxes below it. Since checkboxes do
870 not show up in the agenda views, making this task invisible you remove any
871 trace from agenda views that there is something to do. Therefore, a task
872 that is blocked because of checkboxes will never be made invisible, it
873 will only be dimmed."
874 :group 'org-agenda-daily/weekly
875 :group 'org-agenda-todo-list
876 :version "24.3"
877 :type '(choice
878 (const :tag "Do not dim" nil)
879 (const :tag "Dim to a gray face" t)
880 (const :tag "Make invisible" invisible)))
882 (defcustom org-timeline-show-empty-dates 3
883 "Non-nil means `org-timeline' also shows dates without an entry.
884 When nil, only the days which actually have entries are shown.
885 When t, all days between the first and the last date are shown.
886 When an integer, show also empty dates, but if there is a gap of more than
887 N days, just insert a special line indicating the size of the gap."
888 :group 'org-agenda-skip
889 :type '(choice
890 (const :tag "None" nil)
891 (const :tag "All" t)
892 (integer :tag "at most")))
894 (defgroup org-agenda-startup nil
895 "Options concerning initial settings in the Agenda in Org Mode."
896 :tag "Org Agenda Startup"
897 :group 'org-agenda)
899 (defcustom org-agenda-menu-show-matcher t
900 "Non-nil means show the match string in the agenda dispatcher menu.
901 When nil, the matcher string is not shown, but is put into the help-echo
902 property so than moving the mouse over the command shows it.
903 Setting it to nil is good if matcher strings are very long and/or if
904 you want to use two-columns display (see `org-agenda-menu-two-columns')."
905 :group 'org-agenda
906 :version "24.1"
907 :type 'boolean)
909 (org-define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
911 (defcustom org-agenda-menu-two-columns nil
912 "Non-nil means, use two columns to show custom commands in the dispatcher.
913 If you use this, you probably want to set `org-agenda-menu-show-matcher'
914 to nil."
915 :group 'org-agenda
916 :version "24.1"
917 :type 'boolean)
919 (org-define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
920 (defcustom org-agenda-finalize-hook nil
921 "Hook run just before displaying an agenda buffer.
922 The buffer is still writable when the hook is called.
924 You can modify some of the buffer substrings but you should be
925 extra careful not to modify the text properties of the agenda
926 headlines as the agenda display heavily relies on them."
927 :group 'org-agenda-startup
928 :type 'hook)
930 (defcustom org-agenda-mouse-1-follows-link nil
931 "Non-nil means mouse-1 on a link will follow the link in the agenda.
932 A longer mouse click will still set point. Does not work on XEmacs.
933 Needs to be set before org.el is loaded."
934 :group 'org-agenda-startup
935 :type 'boolean)
937 (defcustom org-agenda-start-with-follow-mode nil
938 "The initial value of follow mode in a newly created agenda window."
939 :group 'org-agenda-startup
940 :type 'boolean)
942 (defcustom org-agenda-follow-indirect nil
943 "Non-nil means `org-agenda-follow-mode' displays only the
944 current item's tree, in an indirect buffer."
945 :group 'org-agenda
946 :version "24.1"
947 :type 'boolean)
949 (defcustom org-agenda-show-outline-path t
950 "Non-nil means show outline path in echo area after line motion."
951 :group 'org-agenda-startup
952 :type 'boolean)
954 (defcustom org-agenda-start-with-entry-text-mode nil
955 "The initial value of entry-text-mode in a newly created agenda window."
956 :group 'org-agenda-startup
957 :type 'boolean)
959 (defcustom org-agenda-entry-text-maxlines 5
960 "Number of text lines to be added when `E' is pressed in the agenda.
962 Note that this variable only used during agenda display. Add add entry text
963 when exporting the agenda, configure the variable
964 `org-agenda-add-entry-ext-maxlines'."
965 :group 'org-agenda
966 :type 'integer)
968 (defcustom org-agenda-entry-text-exclude-regexps nil
969 "List of regular expressions to clean up entry text.
970 The complete matches of all regular expressions in this list will be
971 removed from entry text before it is shown in the agenda."
972 :group 'org-agenda
973 :type '(repeat (regexp)))
975 (defvar org-agenda-entry-text-cleanup-hook nil
976 "Hook that is run after basic cleanup of entry text to be shown in agenda.
977 This cleanup is done in a temporary buffer, so the function may inspect and
978 change the entire buffer.
979 Some default stuff like drawers and scheduling/deadline dates will already
980 have been removed when this is called, as will any matches for regular
981 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
983 (defvar org-agenda-include-inactive-timestamps nil
984 "Non-nil means include inactive time stamps in agenda and timeline.
985 Dynamically scoped.")
987 (defgroup org-agenda-windows nil
988 "Options concerning the windows used by the Agenda in Org Mode."
989 :tag "Org Agenda Windows"
990 :group 'org-agenda)
992 (defcustom org-agenda-window-setup 'reorganize-frame
993 "How the agenda buffer should be displayed.
994 Possible values for this option are:
996 current-window Show agenda in the current window, keeping all other windows.
997 other-window Use `switch-to-buffer-other-window' to display agenda.
998 reorganize-frame Show only two windows on the current frame, the current
999 window and the agenda.
1000 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1001 Also, when exiting the agenda, kill that frame.
1002 See also the variable `org-agenda-restore-windows-after-quit'."
1003 :group 'org-agenda-windows
1004 :type '(choice
1005 (const current-window)
1006 (const other-frame)
1007 (const other-window)
1008 (const reorganize-frame)))
1010 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1011 "The min and max height of the agenda window as a fraction of frame height.
1012 The value of the variable is a cons cell with two numbers between 0 and 1.
1013 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1014 :group 'org-agenda-windows
1015 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1017 (defcustom org-agenda-restore-windows-after-quit nil
1018 "Non-nil means restore window configuration upon exiting agenda.
1019 Before the window configuration is changed for displaying the agenda,
1020 the current status is recorded. When the agenda is exited with
1021 `q' or `x' and this option is set, the old state is restored. If
1022 `org-agenda-window-setup' is `other-frame', the value of this
1023 option will be ignored."
1024 :group 'org-agenda-windows
1025 :type 'boolean)
1027 (defcustom org-agenda-ndays nil
1028 "Number of days to include in overview display.
1029 Should be 1 or 7.
1030 Obsolete, see `org-agenda-span'."
1031 :group 'org-agenda-daily/weekly
1032 :type 'integer)
1034 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1036 (defcustom org-agenda-span 'week
1037 "Number of days to include in overview display.
1038 Can be day, week, month, year, or any number of days.
1039 Custom commands can set this variable in the options section."
1040 :group 'org-agenda-daily/weekly
1041 :type '(choice (const :tag "Day" day)
1042 (const :tag "Week" week)
1043 (const :tag "Month" month)
1044 (const :tag "Year" year)
1045 (integer :tag "Custom")))
1047 (defcustom org-agenda-start-on-weekday 1
1048 "Non-nil means start the overview always on the specified weekday.
1049 0 denotes Sunday, 1 denotes Monday etc.
1050 When nil, always start on the current day.
1051 Custom commands can set this variable in the options section."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice (const :tag "Today" nil)
1054 (integer :tag "Weekday No.")))
1056 (defcustom org-agenda-show-all-dates t
1057 "Non-nil means `org-agenda' shows every day in the selected range.
1058 When nil, only the days which actually have entries are shown."
1059 :group 'org-agenda-daily/weekly
1060 :type 'boolean)
1062 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1063 "Format string for displaying dates in the agenda.
1064 Used by the daily/weekly agenda and by the timeline. This should be
1065 a format string understood by `format-time-string', or a function returning
1066 the formatted date as a string. The function must take a single argument,
1067 a calendar-style date list like (month day year)."
1068 :group 'org-agenda-daily/weekly
1069 :type '(choice
1070 (string :tag "Format string")
1071 (function :tag "Function")))
1073 (defun org-agenda-format-date-aligned (date)
1074 "Format a date string for display in the daily/weekly agenda, or timeline.
1075 This function makes sure that dates are aligned for easy reading."
1076 (require 'cal-iso)
1077 (let* ((dayname (calendar-day-name date))
1078 (day (cadr date))
1079 (day-of-week (calendar-day-of-week date))
1080 (month (car date))
1081 (monthname (calendar-month-name month))
1082 (year (nth 2 date))
1083 (iso-week (org-days-to-iso-week
1084 (calendar-absolute-from-gregorian date)))
1085 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1086 (1- year))
1087 ((and (= month 12) (<= iso-week 1))
1088 (1+ year))
1089 (t year)))
1090 (weekstring (if (= day-of-week 1)
1091 (format " W%02d" iso-week)
1092 "")))
1093 (format "%-10s %2d %s %4d%s"
1094 dayname day monthname year weekstring)))
1096 (defcustom org-agenda-time-leading-zero nil
1097 "Non-nil means use leading zero for military times in agenda.
1098 For example, 9:30am would become 09:30 rather than 9:30."
1099 :group 'org-agenda-daily/weekly
1100 :version "24.1"
1101 :type 'boolean)
1103 (defcustom org-agenda-timegrid-use-ampm nil
1104 "When set, show AM/PM style timestamps on the timegrid."
1105 :group 'org-agenda
1106 :version "24.1"
1107 :type 'boolean)
1109 (defun org-agenda-time-of-day-to-ampm (time)
1110 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1111 (let* ((hour-number (string-to-number (substring time 0 -3)))
1112 (minute (substring time -2))
1113 (ampm "am"))
1114 (cond
1115 ((equal hour-number 12)
1116 (setq ampm "pm"))
1117 ((> hour-number 12)
1118 (setq ampm "pm")
1119 (setq hour-number (- hour-number 12))))
1120 (concat
1121 (if org-agenda-time-leading-zero
1122 (format "%02d" hour-number)
1123 (format "%02s" (number-to-string hour-number)))
1124 ":" minute ampm)))
1126 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1127 "Conditionally convert TIME to AM/PM format
1128 based on `org-agenda-timegrid-use-ampm'"
1129 (if org-agenda-timegrid-use-ampm
1130 (org-agenda-time-of-day-to-ampm time)
1131 time))
1133 (defcustom org-agenda-weekend-days '(6 0)
1134 "Which days are weekend?
1135 These days get the special face `org-agenda-date-weekend' in the agenda
1136 and timeline buffers."
1137 :group 'org-agenda-daily/weekly
1138 :type '(set :greedy t
1139 (const :tag "Monday" 1)
1140 (const :tag "Tuesday" 2)
1141 (const :tag "Wednesday" 3)
1142 (const :tag "Thursday" 4)
1143 (const :tag "Friday" 5)
1144 (const :tag "Saturday" 6)
1145 (const :tag "Sunday" 0)))
1147 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1148 "Non-nil means jump to today when moving a past date forward in time.
1149 When using S-right in the agenda to move a a date forward, and the date
1150 stamp currently points to the past, the first key press will move it
1151 to today. WHen nil, just move one day forward even if the date stays
1152 in the past."
1153 :group 'org-agenda-daily/weekly
1154 :version "24.1"
1155 :type 'boolean)
1157 (defcustom org-agenda-include-diary nil
1158 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1159 Custom commands can set this variable in the options section."
1160 :group 'org-agenda-daily/weekly
1161 :type 'boolean)
1163 (defcustom org-agenda-include-deadlines t
1164 "If non-nil, include entries within their deadline warning period.
1165 Custom commands can set this variable in the options section."
1166 :group 'org-agenda-daily/weekly
1167 :version "24.1"
1168 :type 'boolean)
1170 (defcustom org-agenda-repeating-timestamp-show-all t
1171 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1172 When set to a list of strings, only show occurrences of repeating
1173 stamps for these TODO keywords. When nil, only one occurrence is
1174 shown, either today or the nearest into the future."
1175 :group 'org-agenda-daily/weekly
1176 :type '(choice
1177 (const :tag "Show repeating stamps" t)
1178 (repeat :tag "Show repeating stamps for these TODO keywords"
1179 (string :tag "TODO Keyword"))
1180 (const :tag "Don't show repeating stamps" nil)))
1182 (defcustom org-scheduled-past-days 10000
1183 "No. of days to continue listing scheduled items that are not marked DONE.
1184 When an item is scheduled on a date, it shows up in the agenda on this
1185 day and will be listed until it is marked done for the number of days
1186 given here."
1187 :group 'org-agenda-daily/weekly
1188 :type 'integer)
1190 (defcustom org-agenda-log-mode-items '(closed clock)
1191 "List of items that should be shown in agenda log mode.
1192 This list may contain the following symbols:
1194 closed Show entries that have been closed on that day.
1195 clock Show entries that have received clocked time on that day.
1196 state Show all logged state changes.
1197 Note that instead of changing this variable, you can also press `C-u l' in
1198 the agenda to display all available LOG items temporarily."
1199 :group 'org-agenda-daily/weekly
1200 :type '(set :greedy t (const closed) (const clock) (const state)))
1202 (defcustom org-agenda-clock-consistency-checks
1203 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1204 :gap-ok-around ("4:00")
1205 :default-face ((:background "DarkRed") (:foreground "white"))
1206 :overlap-face nil :gap-face nil :no-end-time-face nil
1207 :long-face nil :short-face nil)
1208 "This is a property list, with the following keys:
1210 :max-duration Mark clocking chunks that are longer than this time.
1211 This is a time string like \"HH:MM\", or the number
1212 of minutes as an integer.
1214 :min-duration Mark clocking chunks that are shorter that this.
1215 This is a time string like \"HH:MM\", or the number
1216 of minutes as an integer.
1218 :max-gap Mark gaps between clocking chunks that are longer than
1219 this duration. A number of minutes, or a string
1220 like \"HH:MM\".
1222 :gap-ok-around List of times during the day which are usually not working
1223 times. When a gap is detected, but the gap contains any
1224 of these times, the gap is *not* reported. For example,
1225 if this is (\"4:00\" \"13:00\") then gaps that contain
1226 4:00 in the morning (i.e. the night) and 13:00
1227 (i.e. a typical lunch time) do not cause a warning.
1228 You should have at least one time during the night in this
1229 list, or otherwise the first task each morning will trigger
1230 a warning because it follows a long gap.
1232 Furthermore, the following properties can be used to define faces for
1233 issue display.
1235 :default-face the default face, if the specific face is undefined
1236 :overlap-face face for overlapping clocks
1237 :gap-face face for gaps between clocks
1238 :no-end-time-face face for incomplete clocks
1239 :long-face face for clock intervals that are too long
1240 :short-face face for clock intervals that are too short"
1241 :group 'org-agenda-daily/weekly
1242 :group 'org-clock
1243 :version "24.1"
1244 :type 'plist)
1246 (defcustom org-agenda-log-mode-add-notes t
1247 "Non-nil means add first line of notes to log entries in agenda views.
1248 If a log item like a state change or a clock entry is associated with
1249 notes, the first line of these notes will be added to the entry in the
1250 agenda display."
1251 :group 'org-agenda-daily/weekly
1252 :type 'boolean)
1254 (defcustom org-agenda-start-with-log-mode nil
1255 "The initial value of log-mode in a newly created agenda window.
1256 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1257 explanations on the possible values."
1258 :group 'org-agenda-startup
1259 :group 'org-agenda-daily/weekly
1260 :type '(choice (const :tag "Don't show log items" nil)
1261 (const :tag "Show only log items" 'only)
1262 (const :tag "Show all possible log items" 'clockcheck)
1263 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1264 (choice (const :tag "Show closed log items" 'closed)
1265 (const :tag "Show clocked log items" 'clock)
1266 (const :tag "Show all logged state changes" 'state)))))
1268 (defcustom org-agenda-start-with-clockreport-mode nil
1269 "The initial value of clockreport-mode in a newly created agenda window."
1270 :group 'org-agenda-startup
1271 :group 'org-agenda-daily/weekly
1272 :type 'boolean)
1274 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1275 "Property list with parameters for the clocktable in clockreport mode.
1276 This is the display mode that shows a clock table in the daily/weekly
1277 agenda, the properties for this dynamic block can be set here.
1278 The usual clocktable parameters are allowed here, but you cannot set
1279 the properties :name, :tstart, :tend, :block, and :scope - these will
1280 be overwritten to make sure the content accurately reflects the
1281 current display in the agenda."
1282 :group 'org-agenda-daily/weekly
1283 :type 'plist)
1285 (defcustom org-agenda-search-view-always-boolean nil
1286 "Non-nil means the search string is interpreted as individual parts.
1288 The search string for search view can either be interpreted as a phrase,
1289 or as a list of snippets that define a boolean search for a number of
1290 strings.
1292 When this is non-nil, the string will be split on whitespace, and each
1293 snippet will be searched individually, and all must match in order to
1294 select an entry. A snippet is then a single string of non-white
1295 characters, or a string in double quotes, or a regexp in {} braces.
1296 If a snippet is preceded by \"-\", the snippet must *not* match.
1297 \"+\" is syntactic sugar for positive selection. Each snippet may
1298 be found as a full word or a partial word, but see the variable
1299 `org-agenda-search-view-force-full-words'.
1301 When this is nil, search will look for the entire search phrase as one,
1302 with each space character matching any amount of whitespace, including
1303 line breaks.
1305 Even when this is nil, you can still switch to Boolean search dynamically
1306 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1307 is a regexp marked with braces like \"{abc}\", this will also switch to
1308 boolean search."
1309 :group 'org-agenda-search-view
1310 :version "24.1"
1311 :type 'boolean)
1313 (if (fboundp 'defvaralias)
1314 (defvaralias 'org-agenda-search-view-search-words-only
1315 'org-agenda-search-view-always-boolean))
1317 (defcustom org-agenda-search-view-force-full-words nil
1318 "Non-nil means, search words must be matches as complete words.
1319 When nil, they may also match part of a word."
1320 :group 'org-agenda-search-view
1321 :version "24.1"
1322 :type 'boolean)
1324 (defcustom org-agenda-search-view-max-outline-level nil
1325 "Maximum outline level to display in search view.
1326 E.g. when this is set to 1, the search view will only
1327 show headlines of level 1."
1328 :group 'org-agenda-search-view
1329 :version "24.3"
1330 :type 'integer)
1332 (defgroup org-agenda-time-grid nil
1333 "Options concerning the time grid in the Org-mode Agenda."
1334 :tag "Org Agenda Time Grid"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-search-headline-for-time t
1338 "Non-nil means search headline for a time-of-day.
1339 If the headline contains a time-of-day in one format or another, it will
1340 be used to sort the entry into the time sequence of items for a day.
1341 Some people have time stamps in the headline that refer to the creation
1342 time or so, and then this produces an unwanted side effect. If this is
1343 the case for your, use this variable to turn off searching the headline
1344 for a time."
1345 :group 'org-agenda-time-grid
1346 :type 'boolean)
1348 (defcustom org-agenda-use-time-grid t
1349 "Non-nil means show a time grid in the agenda schedule.
1350 A time grid is a set of lines for specific times (like every two hours between
1351 8:00 and 20:00). The items scheduled for a day at specific times are
1352 sorted in between these lines.
1353 For details about when the grid will be shown, and what it will look like, see
1354 the variable `org-agenda-time-grid'."
1355 :group 'org-agenda-time-grid
1356 :type 'boolean)
1358 (defcustom org-agenda-time-grid
1359 '((daily today require-timed)
1360 "----------------"
1361 (800 1000 1200 1400 1600 1800 2000))
1363 "The settings for time grid for agenda display.
1364 This is a list of three items. The first item is again a list. It contains
1365 symbols specifying conditions when the grid should be displayed:
1367 daily if the agenda shows a single day
1368 weekly if the agenda shows an entire week
1369 today show grid on current date, independent of daily/weekly display
1370 require-timed show grid only if at least one item has a time specification
1372 The second item is a string which will be placed behind the grid time.
1374 The third item is a list of integers, indicating the times that should have
1375 a grid line."
1376 :group 'org-agenda-time-grid
1377 :type
1378 '(list
1379 (set :greedy t :tag "Grid Display Options"
1380 (const :tag "Show grid in single day agenda display" daily)
1381 (const :tag "Show grid in weekly agenda display" weekly)
1382 (const :tag "Always show grid for today" today)
1383 (const :tag "Show grid only if any timed entries are present"
1384 require-timed)
1385 (const :tag "Skip grid times already present in an entry"
1386 remove-match))
1387 (string :tag "Grid String")
1388 (repeat :tag "Grid Times" (integer :tag "Time"))))
1390 (defcustom org-agenda-show-current-time-in-grid t
1391 "Non-nil means show the current time in the time grid."
1392 :group 'org-agenda-time-grid
1393 :version "24.1"
1394 :type 'boolean)
1396 (defcustom org-agenda-current-time-string
1397 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1398 "The string for the current time marker in the agenda."
1399 :group 'org-agenda-time-grid
1400 :version "24.1"
1401 :type 'string)
1403 (defgroup org-agenda-sorting nil
1404 "Options concerning sorting in the Org-mode Agenda."
1405 :tag "Org Agenda Sorting"
1406 :group 'org-agenda)
1408 (defcustom org-agenda-sorting-strategy
1409 '((agenda habit-down time-up priority-down category-keep)
1410 (todo priority-down category-keep)
1411 (tags priority-down category-keep)
1412 (search category-keep))
1413 "Sorting structure for the agenda items of a single day.
1414 This is a list of symbols which will be used in sequence to determine
1415 if an entry should be listed before another entry. The following
1416 symbols are recognized:
1418 time-up Put entries with time-of-day indications first, early first
1419 time-down Put entries with time-of-day indications first, late first
1420 category-keep Keep the default order of categories, corresponding to the
1421 sequence in `org-agenda-files'.
1422 category-up Sort alphabetically by category, A-Z.
1423 category-down Sort alphabetically by category, Z-A.
1424 tag-up Sort alphabetically by last tag, A-Z.
1425 tag-down Sort alphabetically by last tag, Z-A.
1426 priority-up Sort numerically by priority, high priority last.
1427 priority-down Sort numerically by priority, high priority first.
1428 todo-state-up Sort by todo state, tasks that are done last.
1429 todo-state-down Sort by todo state, tasks that are done first.
1430 effort-up Sort numerically by estimated effort, high effort last.
1431 effort-down Sort numerically by estimated effort, high effort first.
1432 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1433 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1434 habit-up Put entries that are habits first
1435 habit-down Put entries that are habits last
1436 alpha-up Sort headlines alphabetically
1437 alpha-down Sort headlines alphabetically, reversed
1439 The different possibilities will be tried in sequence, and testing stops
1440 if one comparison returns a \"not-equal\". For example, the default
1441 '(time-up category-keep priority-down)
1442 means: Pull out all entries having a specified time of day and sort them,
1443 in order to make a time schedule for the current day the first thing in the
1444 agenda listing for the day. Of the entries without a time indication, keep
1445 the grouped in categories, don't sort the categories, but keep them in
1446 the sequence given in `org-agenda-files'. Within each category sort by
1447 priority.
1449 Leaving out `category-keep' would mean that items will be sorted across
1450 categories by priority.
1452 Instead of a single list, this can also be a set of list for specific
1453 contents, with a context symbol in the car of the list, any of
1454 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1456 Custom commands can bind this variable in the options section."
1457 :group 'org-agenda-sorting
1458 :type `(choice
1459 (repeat :tag "General" ,org-sorting-choice)
1460 (list :tag "Individually"
1461 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1462 (repeat ,org-sorting-choice))
1463 (cons (const :tag "Strategy for TODO lists" todo)
1464 (repeat ,org-sorting-choice))
1465 (cons (const :tag "Strategy for Tags matches" tags)
1466 (repeat ,org-sorting-choice))
1467 (cons (const :tag "Strategy for search matches" search)
1468 (repeat ,org-sorting-choice)))))
1470 (defcustom org-agenda-cmp-user-defined nil
1471 "A function to define the comparison `user-defined'.
1472 This function must receive two arguments, agenda entry a and b.
1473 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1474 the user comparison, return nil.
1475 When this is defined, you can make `user-defined-up' and `user-defined-down'
1476 part of an agenda sorting strategy."
1477 :group 'org-agenda-sorting
1478 :type 'symbol)
1480 (defcustom org-sort-agenda-notime-is-late t
1481 "Non-nil means items without time are considered late.
1482 This is only relevant for sorting. When t, items which have no explicit
1483 time like 15:30 will be considered as 99:01, i.e. later than any items which
1484 do have a time. When nil, the default time is before 0:00. You can use this
1485 option to decide if the schedule for today should come before or after timeless
1486 agenda entries."
1487 :group 'org-agenda-sorting
1488 :type 'boolean)
1490 (defcustom org-sort-agenda-noeffort-is-high t
1491 "Non-nil means items without effort estimate are sorted as high effort.
1492 This also applies when filtering an agenda view with respect to the
1493 < or > effort operator. Then, tasks with no effort defined will be treated
1494 as tasks with high effort.
1495 When nil, such items are sorted as 0 minutes effort."
1496 :group 'org-agenda-sorting
1497 :type 'boolean)
1499 (defgroup org-agenda-line-format nil
1500 "Options concerning the entry prefix in the Org-mode agenda display."
1501 :tag "Org Agenda Line Format"
1502 :group 'org-agenda)
1504 (defcustom org-agenda-prefix-format
1505 '((agenda . " %i %-12:c%?-12t% s")
1506 (timeline . " % s")
1507 (todo . " %i %-12:c")
1508 (tags . " %i %-12:c")
1509 (search . " %i %-12:c"))
1510 "Format specifications for the prefix of items in the agenda views.
1511 An alist with five entries, each for the different agenda types. The
1512 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1513 The values are format strings.
1515 This format works similar to a printf format, with the following meaning:
1517 %c the category of the item, \"Diary\" for entries from the diary,
1518 or as given by the CATEGORY keyword or derived from the file name
1519 %e the effort required by the item
1520 %l the level of the item (insert X space(s) if item is of level X)
1521 %i the icon category of the item, see `org-agenda-category-icon-alist'
1522 %T the last tag of the item (ignore inherited tags, which come first)
1523 %t the HH:MM time-of-day specification if one applies to the entry
1524 %s Scheduling/Deadline information, a short string
1525 %(expression) Eval EXPRESSION and replace the control string
1526 by the result
1528 All specifiers work basically like the standard `%s' of printf, but may
1529 contain two additional characters: a question mark just after the `%'
1530 and a whitespace/punctuation character just before the final letter.
1532 If the first character after `%' is a question mark, the entire field
1533 will only be included if the corresponding value applies to the current
1534 entry. This is useful for fields which should have fixed width when
1535 present, but zero width when absent. For example, \"%?-12t\" will
1536 result in a 12 character time field if a time of the day is specified,
1537 but will completely disappear in entries which do not contain a time.
1539 If there is punctuation or whitespace character just before the final
1540 format letter, this character will be appended to the field value if
1541 the value is not empty. For example, the format \"%-12:c\" leads to
1542 \"Diary: \" if the category is \"Diary\". If the category were be
1543 empty, no additional colon would be inserted.
1545 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1546 which means:
1548 - Indent the line with two space characters
1549 - Give the category a 12 chars wide field, padded with whitespace on
1550 the right (because of `-'). Append a colon if there is a category
1551 (because of `:').
1552 - If there is a time-of-day, put it into a 12 chars wide field. If no
1553 time, don't put in an empty field, just skip it (because of '?').
1554 - Finally, put the scheduling information.
1556 See also the variables `org-agenda-remove-times-when-in-prefix' and
1557 `org-agenda-remove-tags'.
1559 Custom commands can set this variable in the options section."
1560 :type '(choice
1561 (string :tag "General format")
1562 (list :greedy t :tag "View dependent"
1563 (cons (const agenda) (string :tag "Format"))
1564 (cons (const timeline) (string :tag "Format"))
1565 (cons (const todo) (string :tag "Format"))
1566 (cons (const tags) (string :tag "Format"))
1567 (cons (const search) (string :tag "Format"))))
1568 :group 'org-agenda-line-format)
1570 (defvar org-prefix-format-compiled nil
1571 "The compiled prefix format and associated variables.
1572 This is a list where first element is a list of variable bindings, and second
1573 element is the compiled format expression. See the variable
1574 `org-agenda-prefix-format'.")
1576 (defcustom org-agenda-todo-keyword-format "%-1s"
1577 "Format for the TODO keyword in agenda lines.
1578 Set this to something like \"%-12s\" if you want all TODO keywords
1579 to occupy a fixed space in the agenda display."
1580 :group 'org-agenda-line-format
1581 :type 'string)
1583 (defcustom org-agenda-diary-sexp-prefix nil
1584 "A regexp that matches part of a diary sexp entry
1585 which should be treated as scheduling/deadline information in
1586 `org-agenda'.
1588 For example, you can use this to extract the `diary-remind-message' from
1589 `diary-remind' entries."
1590 :group 'org-agenda-line-format
1591 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1593 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1594 "Text preceding timerange entries in the agenda view.
1595 This is a list with two strings. The first applies when the range
1596 is entirely on one day. The second applies if the range spans several days.
1597 The strings may have two \"%d\" format specifiers which will be filled
1598 with the sequence number of the days, and the total number of days in the
1599 range, respectively."
1600 :group 'org-agenda-line-format
1601 :type '(list
1602 (string :tag "Deadline today ")
1603 (choice :tag "Deadline relative"
1604 (string :tag "Format string")
1605 (function))))
1607 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1608 "Text preceding scheduled items in the agenda view.
1609 This is a list with two strings. The first applies when the item is
1610 scheduled on the current day. The second applies when it has been scheduled
1611 previously, it may contain a %d indicating that this is the nth time that
1612 this item is scheduled, due to automatic rescheduling of unfinished items
1613 for the following day. So this number is one larger than the number of days
1614 that passed since this item was scheduled first."
1615 :group 'org-agenda-line-format
1616 :type '(list
1617 (string :tag "Scheduled today ")
1618 (string :tag "Scheduled previously")))
1620 (defcustom org-agenda-inactive-leader "["
1621 "Text preceding item pulled into the agenda by inactive time stamps.
1622 These entries are added to the agenda when pressing \"[\"."
1623 :group 'org-agenda-line-format
1624 :version "24.1"
1625 :type '(list
1626 (string :tag "Scheduled today ")
1627 (string :tag "Scheduled previously")))
1629 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1630 "Text preceding deadline items in the agenda view.
1631 This is a list with two strings. The first applies when the item has its
1632 deadline on the current day. The second applies when it is in the past or
1633 in the future, it may contain %d to capture how many days away the deadline
1634 is (was)."
1635 :group 'org-agenda-line-format
1636 :type '(list
1637 (string :tag "Deadline today ")
1638 (choice :tag "Deadline relative"
1639 (string :tag "Format string")
1640 (function))))
1642 (defcustom org-agenda-remove-times-when-in-prefix t
1643 "Non-nil means remove duplicate time specifications in agenda items.
1644 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1645 time-of-day specification in a headline or diary entry is extracted and
1646 placed into the prefix. If this option is non-nil, the original specification
1647 \(a timestamp or -range, or just a plain time(range) specification like
1648 11:30-4pm) will be removed for agenda display. This makes the agenda less
1649 cluttered.
1650 The option can be t or nil. It may also be the symbol `beg', indicating
1651 that the time should only be removed when it is located at the beginning of
1652 the headline/diary entry."
1653 :group 'org-agenda-line-format
1654 :type '(choice
1655 (const :tag "Always" t)
1656 (const :tag "Never" nil)
1657 (const :tag "When at beginning of entry" beg)))
1659 (defcustom org-agenda-remove-timeranges-from-blocks nil
1660 "Non-nil means remove time ranges specifications in agenda
1661 items that span on several days."
1662 :group 'org-agenda-line-format
1663 :version "24.1"
1664 :type 'boolean)
1666 (defcustom org-agenda-default-appointment-duration nil
1667 "Default duration for appointments that only have a starting time.
1668 When nil, no duration is specified in such cases.
1669 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1670 :group 'org-agenda-line-format
1671 :type '(choice
1672 (integer :tag "Minutes")
1673 (const :tag "No default duration")))
1675 (defcustom org-agenda-show-inherited-tags t
1676 "Non-nil means show inherited tags in each agenda line."
1677 :group 'org-agenda-line-format
1678 :type 'boolean)
1680 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1681 "List of agenda view types where to use tag inheritance.
1683 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1684 controlled by `org-use-tag-inheritance'. In other agenda types,
1685 `org-use-tag-inheritance' is not used when selecting the agenda
1686 entries, but you may want the agenda to use the inherited tags
1687 anyway, e.g. for later tag filtering.
1689 Setting this to nil will speed up non-tags agenda view a lot."
1690 :version "24.3")
1692 (defcustom org-agenda-hide-tags-regexp nil
1693 "Regular expression used to filter away specific tags in agenda views.
1694 This means that these tags will be present, but not be shown in the agenda
1695 line. Secondary filtering will still work on the hidden tags.
1696 Nil means don't hide any tags."
1697 :group 'org-agenda-line-format
1698 :type '(choice
1699 (const :tag "Hide none" nil)
1700 (string :tag "Regexp ")))
1702 (defcustom org-agenda-remove-tags nil
1703 "Non-nil means remove the tags from the headline copy in the agenda.
1704 When this is the symbol `prefix', only remove tags when
1705 `org-agenda-prefix-format' contains a `%T' specifier."
1706 :group 'org-agenda-line-format
1707 :type '(choice
1708 (const :tag "Always" t)
1709 (const :tag "Never" nil)
1710 (const :tag "When prefix format contains %T" prefix)))
1712 (if (fboundp 'defvaralias)
1713 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1714 'org-agenda-remove-tags))
1716 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1717 "Shift tags in agenda items to this column.
1718 If this number is positive, it specifies the column. If it is negative,
1719 it means that the tags should be flushright to that column. For example,
1720 -80 works well for a normal 80 character screen."
1721 :group 'org-agenda-line-format
1722 :type 'integer)
1724 (if (fboundp 'defvaralias)
1725 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1727 (defcustom org-agenda-fontify-priorities 'cookies
1728 "Non-nil means highlight low and high priorities in agenda.
1729 When t, the highest priority entries are bold, lowest priority italic.
1730 However, settings in `org-priority-faces' will overrule these faces.
1731 When this variable is the symbol `cookies', only fontify the
1732 cookies, not the entire task.
1733 This may also be an association list of priority faces, whose
1734 keys are the character values of `org-highest-priority',
1735 `org-default-priority', and `org-lowest-priority' (the default values
1736 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1737 color as a string, or a list like `(:background \"Red\")'.
1738 If it is a color, the variable `org-faces-easy-properties'
1739 determines if it is a foreground or a background color."
1740 :group 'org-agenda-line-format
1741 :type '(choice
1742 (const :tag "Never" nil)
1743 (const :tag "Defaults" t)
1744 (const :tag "Cookies only" cookies)
1745 (repeat :tag "Specify"
1746 (list (character :tag "Priority" :value ?A)
1747 (choice :tag "Face "
1748 (string :tag "Color")
1749 (sexp :tag "Face"))))))
1751 (defcustom org-agenda-day-face-function nil
1752 "Function called to determine what face should be used to display a day.
1753 The only argument passed to that function is the day. It should
1754 returns a face, or nil if does not want to specify a face and let
1755 the normal rules apply."
1756 :group 'org-agenda-line-format
1757 :version "24.1"
1758 :type 'function)
1760 (defcustom org-agenda-category-icon-alist nil
1761 "Alist of category icon to be displayed in agenda views.
1763 Each entry should have the following format:
1765 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1767 Where CATEGORY-REGEXP is a regexp matching the categories where
1768 the icon should be displayed.
1769 FILE-OR-DATA either a file path or a string containing image data.
1771 The other fields can be omitted safely if not needed:
1772 TYPE indicates the image type.
1773 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1774 image data.
1775 PROPS are additional image attributes to assign to the image,
1776 like, e.g. `:ascent center'.
1778 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1780 If you want to set the display properties yourself, just put a
1781 list as second element:
1783 (CATEGORY-REGEXP (MY PROPERTY LIST))
1785 For example, to display a 16px horizontal space for Emacs
1786 category, you can use:
1788 (\"Emacs\" '(space . (:width (16))))"
1789 :group 'org-agenda-line-format
1790 :version "24.1"
1791 :type '(alist :key-type (string :tag "Regexp matching category")
1792 :value-type (choice (list :tag "Icon"
1793 (string :tag "File or data")
1794 (symbol :tag "Type")
1795 (boolean :tag "Data?")
1796 (repeat :tag "Extra image properties" :inline t symbol))
1797 (list :tag "Display properties" sexp))))
1799 (defgroup org-agenda-column-view nil
1800 "Options concerning column view in the agenda."
1801 :tag "Org Agenda Column View"
1802 :group 'org-agenda)
1804 (defcustom org-agenda-columns-show-summaries t
1805 "Non-nil means show summaries for columns displayed in the agenda view."
1806 :group 'org-agenda-column-view
1807 :type 'boolean)
1809 (defcustom org-agenda-columns-compute-summary-properties t
1810 "Non-nil means recompute all summary properties before column view.
1811 When column view in the agenda is listing properties that have a summary
1812 operator, it can go to all relevant buffers and recompute the summaries
1813 there. This can mean overhead for the agenda column view, but is necessary
1814 to have thing up to date.
1815 As a special case, a CLOCKSUM property also makes sure that the clock
1816 computations are current."
1817 :group 'org-agenda-column-view
1818 :type 'boolean)
1820 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1821 "Non-nil means the duration of an appointment will add to day effort.
1822 The property to which appointment durations will be added is the one given
1823 in the option `org-effort-property'. If an appointment does not have
1824 an end time, `org-agenda-default-appointment-duration' will be used. If that
1825 is not set, an appointment without end time will not contribute to the time
1826 estimate."
1827 :group 'org-agenda-column-view
1828 :type 'boolean)
1830 (defcustom org-agenda-auto-exclude-function nil
1831 "A function called with a tag to decide if it is filtered on '/ RET'.
1832 The sole argument to the function, which is called once for each
1833 possible tag, is a string giving the name of the tag. The
1834 function should return either nil if the tag should be included
1835 as normal, or \"-<TAG>\" to exclude the tag.
1836 Note that for the purpose of tag filtering, only the lower-case version of
1837 all tags will be considered, so that this function will only ever see
1838 the lower-case version of all tags."
1839 :group 'org-agenda
1840 :type 'function)
1842 (defcustom org-agenda-bulk-custom-functions nil
1843 "Alist of characters and custom functions for bulk actions.
1844 For example, this value makes those two functions available:
1846 '((?R set-category)
1847 (?C bulk-cut))
1849 With selected entries in an agenda buffer, `B R' will call
1850 the custom function `set-category' on the selected entries.
1851 Note that functions in this alist don't need to be quoted."
1852 :type 'alist
1853 :version "24.1"
1854 :group 'org-agenda)
1856 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1857 "Execute BODY with point at location given by `org-hd-marker' property.
1858 If STRING is non-nil, the text property will be fetched from position 0
1859 in that string. If STRING is nil, it will be fetched from the beginning
1860 of the current line."
1861 (org-with-gensyms (marker)
1862 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1863 'org-hd-marker ,string)))
1864 (with-current-buffer (marker-buffer ,marker)
1865 (save-excursion
1866 (goto-char ,marker)
1867 ,@body)))))
1868 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1870 (defun org-add-agenda-custom-command (entry)
1871 "Replace or add a command in `org-agenda-custom-commands'.
1872 This is mostly for hacking and trying a new command - once the command
1873 works you probably want to add it to `org-agenda-custom-commands' for good."
1874 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1875 (if ass
1876 (setcdr ass (cdr entry))
1877 (push entry org-agenda-custom-commands))))
1879 ;;; Define the org-agenda-mode
1881 (defvar org-agenda-mode-map (make-sparse-keymap)
1882 "Keymap for `org-agenda-mode'.")
1883 (if (fboundp 'defvaralias)
1884 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1886 (defvar org-agenda-menu) ; defined later in this file.
1887 (defvar org-agenda-restrict nil) ; defined later in this file.
1888 (defvar org-agenda-follow-mode nil)
1889 (defvar org-agenda-entry-text-mode nil)
1890 (defvar org-agenda-clockreport-mode nil)
1891 (defvar org-agenda-show-log nil)
1892 (defvar org-agenda-redo-command nil)
1893 (defvar org-agenda-query-string nil)
1894 (defvar org-agenda-mode-hook nil
1895 "Hook run after `org-agenda-mode' is turned on.
1896 The buffer is still writable when this hook is called.")
1897 (defvar org-agenda-type nil)
1898 (defvar org-agenda-force-single-file nil)
1899 (defvar org-agenda-bulk-marked-entries nil
1900 "List of markers that refer to marked entries in the agenda.")
1902 ;;; Multiple agenda buffers support
1904 (defcustom org-agenda-sticky nil
1905 "Non-nil means agenda q key will bury agenda buffers.
1906 Agenda commands will then show existing buffer instead of generating new ones.
1907 When nil, `q' will kill the single agenda buffer."
1908 :group 'org-agenda
1909 :version "24.3"
1910 :type 'boolean)
1913 ;;;###autoload
1914 (defun org-toggle-sticky-agenda (&optional arg)
1915 "Toggle `org-agenda-sticky'."
1916 (interactive "P")
1917 (let ((new-value (if arg
1918 (> (prefix-numeric-value arg) 0)
1919 (not org-agenda-sticky))))
1920 (if (equal new-value org-agenda-sticky)
1921 (and (org-called-interactively-p 'interactive)
1922 (message "Sticky agenda was already %s"
1923 (if org-agenda-sticky "enabled" "disabled")))
1924 (setq org-agenda-sticky new-value)
1925 (org-agenda-kill-all-agenda-buffers)
1926 (and (org-called-interactively-p 'interactive)
1927 (message "Sticky agenda was %s"
1928 (if org-agenda-sticky "enabled" "disabled"))))))
1930 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1931 Toggle `org-agenda-sticky'.
1933 \(fn &optional ARG)" t nil)
1935 (defvar org-agenda-buffer nil
1936 "Agenda buffer currently being generated.")
1938 (defvar org-agenda-last-prefix-arg nil)
1939 (defvar org-agenda-this-buffer-name nil)
1940 (defvar org-agenda-doing-sticky-redo nil)
1941 (defvar org-agenda-this-buffer-is-sticky nil)
1943 (defconst org-agenda-local-vars
1944 '(org-agenda-this-buffer-name
1945 org-agenda-undo-list
1946 org-agenda-pending-undo-list
1947 org-agenda-follow-mode
1948 org-agenda-entry-text-mode
1949 org-agenda-clockreport-mode
1950 org-agenda-show-log
1951 org-agenda-redo-command
1952 org-agenda-query-string
1953 org-agenda-type
1954 org-agenda-bulk-marked-entries
1955 org-agenda-undo-has-started-in
1956 org-agenda-info
1957 org-agenda-tag-filter-overlays
1958 org-agenda-cat-filter-overlays
1959 org-agenda-pre-window-conf
1960 org-agenda-columns-active
1961 org-agenda-tag-filter
1962 org-agenda-category-filter
1963 org-agenda-markers
1964 org-agenda-last-search-view-search-was-boolean
1965 org-agenda-filtered-by-category
1966 org-agenda-filter-form
1967 org-agenda-show-window
1968 org-agenda-cycle-counter
1969 org-agenda-last-prefix-arg)
1970 "Variables that must be local in agenda buffers to allow multiple buffers.")
1972 (defun org-agenda-mode ()
1973 "Mode for time-sorted view on action items in Org-mode files.
1975 The following commands are available:
1977 \\{org-agenda-mode-map}"
1978 (interactive)
1979 (cond (org-agenda-doing-sticky-redo
1980 ;; Refreshing sticky agenda-buffer
1982 ;; Preserve the value of `org-agenda-local-vars' variables,
1983 ;; while letting `kill-all-local-variables' kill the rest
1984 (let ((save (buffer-local-variables)))
1985 (kill-all-local-variables)
1986 (mapc 'make-local-variable org-agenda-local-vars)
1987 (dolist (elem save)
1988 (let ((var (car elem))
1989 (val (cdr elem)))
1990 (when (and val
1991 (member var org-agenda-local-vars))
1992 (set var val)))))
1993 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1994 (org-agenda-sticky
1995 ;; Creating a sticky Agenda buffer for the first time
1996 (kill-all-local-variables)
1997 (mapc 'make-local-variable org-agenda-local-vars)
1998 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2000 ;; Creating a non-sticky agenda buffer
2001 (kill-all-local-variables)
2002 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2003 (setq org-agenda-undo-list nil
2004 org-agenda-pending-undo-list nil
2005 org-agenda-bulk-marked-entries nil)
2006 (setq major-mode 'org-agenda-mode)
2007 ;; Keep global-font-lock-mode from turning on font-lock-mode
2008 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2009 (setq mode-name "Org-Agenda")
2010 (use-local-map org-agenda-mode-map)
2011 (easy-menu-add org-agenda-menu)
2012 (if org-startup-truncated (setq truncate-lines t))
2013 (org-set-local 'line-move-visual nil)
2014 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2015 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2016 ;; Make sure properties are removed when copying text
2017 (make-local-variable 'filter-buffer-substring-functions)
2018 (add-hook 'filter-buffer-substring-functions
2019 (lambda (fun start end delete)
2020 (substring-no-properties (funcall fun start end delete))))
2021 (unless org-agenda-keep-modes
2022 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2023 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2024 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2025 org-agenda-show-log org-agenda-start-with-log-mode))
2027 (easy-menu-change
2028 '("Agenda") "Agenda Files"
2029 (append
2030 (list
2031 (vector
2032 (if (get 'org-agenda-files 'org-restrict)
2033 "Restricted to single file"
2034 "Edit File List")
2035 '(org-edit-agenda-file-list)
2036 (not (get 'org-agenda-files 'org-restrict)))
2037 "--")
2038 (mapcar 'org-file-menu-entry (org-agenda-files))))
2039 (org-agenda-set-mode-name)
2040 (apply
2041 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2042 (list 'org-agenda-mode-hook)))
2044 (substitute-key-definition 'undo 'org-agenda-undo
2045 org-agenda-mode-map global-map)
2046 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2047 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2048 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2049 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2050 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2051 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2052 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2053 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2054 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2055 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2056 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2057 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2058 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2059 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2060 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2061 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2062 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2063 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2064 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2065 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2066 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2067 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2068 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2069 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2070 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2071 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2072 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2073 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2074 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2075 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2076 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2077 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2078 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2079 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2080 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2081 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2082 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2083 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2084 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2085 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2086 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2087 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2088 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2089 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2090 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2091 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2093 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2094 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2095 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2096 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2097 (while l (org-defkey org-agenda-mode-map
2098 (int-to-string (pop l)) 'digit-argument)))
2100 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2101 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2102 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2103 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2104 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2105 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2106 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2107 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2108 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2109 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2110 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2111 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2112 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2113 'org-clock-modify-effort-estimate)
2114 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2115 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2116 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2117 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2118 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2119 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2120 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2121 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2122 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2123 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2124 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2125 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2126 (substitute-key-definition 'next-line 'org-agenda-next-line
2127 org-agenda-mode-map global-map)
2128 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2129 org-agenda-mode-map global-map)
2130 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2131 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2132 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2133 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2134 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2135 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2136 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2137 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2138 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2139 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2140 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2141 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2142 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2143 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2144 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2145 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2146 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2147 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2148 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2149 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2150 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2151 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2152 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2153 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2154 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2155 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2156 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2157 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2158 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2159 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2161 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2162 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2163 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2164 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2165 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2166 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2167 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2168 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2169 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2170 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2171 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2172 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2174 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2175 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2176 (when org-agenda-mouse-1-follows-link
2177 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2178 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2179 '("Agenda"
2180 ("Agenda Files")
2181 "--"
2182 ("Agenda Dates"
2183 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2184 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2185 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2186 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2187 "--"
2188 ("View"
2189 ["Day View" org-agenda-day-view
2190 :active (org-agenda-check-type nil 'agenda)
2191 :style radio :selected (eq org-agenda-current-span 'day)
2192 :keys "v d (or just d)"]
2193 ["Week View" org-agenda-week-view
2194 :active (org-agenda-check-type nil 'agenda)
2195 :style radio :selected (eq org-agenda-current-span 'week)
2196 :keys "v w (or just w)"]
2197 ["Month View" org-agenda-month-view
2198 :active (org-agenda-check-type nil 'agenda)
2199 :style radio :selected (eq org-agenda-current-span 'month)
2200 :keys "v m"]
2201 ["Year View" org-agenda-year-view
2202 :active (org-agenda-check-type nil 'agenda)
2203 :style radio :selected (eq org-agenda-current-span 'year)
2204 :keys "v y"]
2205 "--"
2206 ["Include Diary" org-agenda-toggle-diary
2207 :style toggle :selected org-agenda-include-diary
2208 :active (org-agenda-check-type nil 'agenda)]
2209 ["Include Deadlines" org-agenda-toggle-deadlines
2210 :style toggle :selected org-agenda-include-deadlines
2211 :active (org-agenda-check-type nil 'agenda)]
2212 ["Use Time Grid" org-agenda-toggle-time-grid
2213 :style toggle :selected org-agenda-use-time-grid
2214 :active (org-agenda-check-type nil 'agenda)]
2215 "--"
2216 ["Show clock report" org-agenda-clockreport-mode
2217 :style toggle :selected org-agenda-clockreport-mode
2218 :active (org-agenda-check-type nil 'agenda)]
2219 ["Show some entry text" org-agenda-entry-text-mode
2220 :style toggle :selected org-agenda-entry-text-mode
2221 :active t]
2222 "--"
2223 ["Show Logbook entries" org-agenda-log-mode
2224 :style toggle :selected org-agenda-show-log
2225 :active (org-agenda-check-type nil 'agenda 'timeline)
2226 :keys "v l (or just l)"]
2227 ["Include archived trees" org-agenda-archives-mode
2228 :style toggle :selected org-agenda-archives-mode :active t
2229 :keys "v a"]
2230 ["Include archive files" (org-agenda-archives-mode t)
2231 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2232 :keys "v A"]
2233 "--"
2234 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2235 ["Write view to file" org-agenda-write t]
2236 ["Rebuild buffer" org-agenda-redo t]
2237 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2238 "--"
2239 ["Show original entry" org-agenda-show t]
2240 ["Go To (other window)" org-agenda-goto t]
2241 ["Go To (this window)" org-agenda-switch-to t]
2242 ["Capture with cursor date" org-agenda-capture t]
2243 ["Follow Mode" org-agenda-follow-mode
2244 :style toggle :selected org-agenda-follow-mode :active t]
2245 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2246 "--"
2247 ("TODO"
2248 ["Cycle TODO" org-agenda-todo t]
2249 ["Next TODO set" org-agenda-todo-nextset t]
2250 ["Previous TODO set" org-agenda-todo-previousset t]
2251 ["Add note" org-agenda-add-note t])
2252 ("Archive/Refile/Delete"
2253 ["Archive default" org-agenda-archive-default t]
2254 ["Archive default" org-agenda-archive-default-with-confirmation t]
2255 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2256 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2257 ["Archive subtree" org-agenda-archive t]
2258 "--"
2259 ["Refile" org-agenda-refile t]
2260 "--"
2261 ["Delete subtree" org-agenda-kill t])
2262 ("Bulk action"
2263 ["Mark entry" org-agenda-bulk-mark t]
2264 ["Mark all" org-agenda-bulk-mark-all t]
2265 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2266 ["Unmark entry" org-agenda-bulk-unmark t]
2267 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2268 ["Act on all marked" org-agenda-bulk-action t]
2269 "--"
2270 ("Tags and Properties"
2271 ["Show all Tags" org-agenda-show-tags t]
2272 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2273 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2274 "--"
2275 ["Column View" org-columns t])
2276 ("Deadline/Schedule"
2277 ["Schedule" org-agenda-schedule t]
2278 ["Set Deadline" org-agenda-deadline t]
2279 "--"
2280 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2281 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2282 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2283 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2284 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2285 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2286 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2287 ("Clock and Effort"
2288 ["Clock in" org-agenda-clock-in t]
2289 ["Clock out" org-agenda-clock-out t]
2290 ["Clock cancel" org-agenda-clock-cancel t]
2291 ["Goto running clock" org-clock-goto t]
2292 "--"
2293 ["Set Effort" org-agenda-set-effort t]
2294 ["Change clocked effort" org-clock-modify-effort-estimate
2295 (org-clock-is-active)])
2296 ("Priority"
2297 ["Set Priority" org-agenda-priority t]
2298 ["Increase Priority" org-agenda-priority-up t]
2299 ["Decrease Priority" org-agenda-priority-down t]
2300 ["Show Priority" org-show-priority t])
2301 ("Calendar/Diary"
2302 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2303 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2304 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2305 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2306 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2307 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2308 "--"
2309 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2310 "--"
2311 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2312 "--"
2313 ("MobileOrg"
2314 ["Push Files and Views" org-mobile-push t]
2315 ["Get Captured and Flagged" org-mobile-pull t]
2316 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2317 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2318 "--"
2319 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2320 "--"
2321 ["Quit" org-agenda-quit t]
2322 ["Exit and Release Buffers" org-agenda-exit t]
2325 ;;; Agenda undo
2327 (defvar org-agenda-allow-remote-undo t
2328 "Non-nil means allow remote undo from the agenda buffer.")
2329 (defvar org-agenda-undo-has-started-in nil
2330 "Buffers that have already seen `undo-start' in the current undo sequence.")
2332 (defun org-agenda-undo ()
2333 "Undo a remote editing step in the agenda.
2334 This undoes changes both in the agenda buffer and in the remote buffer
2335 that have been changed along."
2336 (interactive)
2337 (or org-agenda-allow-remote-undo
2338 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2339 (if (not (eq this-command last-command))
2340 (setq org-agenda-undo-has-started-in nil
2341 org-agenda-pending-undo-list org-agenda-undo-list))
2342 (if (not org-agenda-pending-undo-list)
2343 (error "No further undo information"))
2344 (let* ((entry (pop org-agenda-pending-undo-list))
2345 buf line cmd rembuf)
2346 (setq cmd (pop entry) line (pop entry))
2347 (setq rembuf (nth 2 entry))
2348 (org-with-remote-undo rembuf
2349 (while (bufferp (setq buf (pop entry)))
2350 (if (pop entry)
2351 (with-current-buffer buf
2352 (let ((last-undo-buffer buf)
2353 (inhibit-read-only t))
2354 (unless (memq buf org-agenda-undo-has-started-in)
2355 (push buf org-agenda-undo-has-started-in)
2356 (make-local-variable 'pending-undo-list)
2357 (undo-start))
2358 (while (and pending-undo-list
2359 (listp pending-undo-list)
2360 (not (car pending-undo-list)))
2361 (pop pending-undo-list))
2362 (undo-more 1))))))
2363 (org-goto-line line)
2364 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2366 (defun org-verify-change-for-undo (l1 l2)
2367 "Verify that a real change occurred between the undo lists L1 and L2."
2368 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2369 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2370 (not (eq l1 l2)))
2372 ;;; Agenda dispatch
2374 (defvar org-agenda-restrict-begin (make-marker))
2375 (defvar org-agenda-restrict-end (make-marker))
2376 (defvar org-agenda-last-dispatch-buffer nil)
2377 (defvar org-agenda-overriding-restriction nil)
2379 (defcustom org-agenda-custom-commands-contexts nil
2380 "Alist of custom agenda keys and contextual rules.
2382 For example, if you have a custom agenda command \"p\" and you
2383 want this command to be accessible only from plain text files,
2384 use this:
2386 '((\"p\" (in-file . \"\\.txt\")))
2388 Here are the available contexts definitions:
2390 in-file: command displayed only in matching files
2391 in-mode: command displayed only in matching modes
2392 not-in-file: command not displayed in matching files
2393 not-in-mode: command not displayed in matching modes
2394 [function]: a custom function taking no argument
2396 If you define several checks, the agenda command will be
2397 accessible if there is at least one valid check.
2399 You can also bind a key to another agenda custom command
2400 depending on contextual rules.
2402 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2404 Here it means: in .txt files, use \"p\" as the key for the
2405 agenda command otherwise associated with \"q\". (The command
2406 originally associated with \"q\" is not displayed to avoid
2407 duplicates.)"
2408 :version "24.3"
2409 :group 'org-agenda-custom-commands
2410 :type '(repeat (list :tag "Rule"
2411 (string :tag " Agenda key")
2412 (string :tag "Replace by command")
2413 (repeat :tag "Available when"
2414 (choice
2415 (cons :tag "Condition"
2416 (choice
2417 (const :tag "In file" in-file)
2418 (const :tag "Not in file" not-in-file)
2419 (const :tag "In mode" in-mode)
2420 (const :tag "Not in mode" not-in-mode))
2421 (regexp))
2422 (function :tag "Custom function"))))))
2424 (defvar org-keys nil)
2425 (defvar org-match nil)
2426 ;;;###autoload
2427 (defun org-agenda (&optional arg org-keys restriction)
2428 "Dispatch agenda commands to collect entries to the agenda buffer.
2429 Prompts for a command to execute. Any prefix arg will be passed
2430 on to the selected command. The default selections are:
2432 a Call `org-agenda-list' to display the agenda for current day or week.
2433 t Call `org-todo-list' to display the global todo list.
2434 T Call `org-todo-list' to display the global todo list, select only
2435 entries with a specific TODO keyword (the user gets a prompt).
2436 m Call `org-tags-view' to display headlines with tags matching
2437 a condition (the user is prompted for the condition).
2438 M Like `m', but select only TODO entries, no ordinary headlines.
2439 L Create a timeline for the current buffer.
2440 e Export views to associated files.
2441 s Search entries for keywords.
2442 S Search entries for keywords, only with TODO keywords.
2443 / Multi occur across all agenda files and also files listed
2444 in `org-agenda-text-search-extra-files'.
2445 < Restrict agenda commands to buffer, subtree, or region.
2446 Press several times to get the desired effect.
2447 > Remove a previous restriction.
2448 # List \"stuck\" projects.
2449 ! Configure what \"stuck\" means.
2450 C Configure custom agenda commands.
2452 More commands can be added by configuring the variable
2453 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2454 searches can be pre-defined in this way.
2456 If the current buffer is in Org-mode and visiting a file, you can also
2457 first press `<' once to indicate that the agenda should be temporarily
2458 \(until the next use of \\[org-agenda]) restricted to the current file.
2459 Pressing `<' twice means to restrict to the current subtree or region
2460 \(if active)."
2461 (interactive "P")
2462 (catch 'exit
2463 (let* ((prefix-descriptions nil)
2464 (org-agenda-buffer-name org-agenda-buffer-name)
2465 (org-agenda-window-setup (if (equal (buffer-name)
2466 org-agenda-buffer-name)
2467 'current-window
2468 org-agenda-window-setup))
2469 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2470 (org-agenda-custom-commands
2471 ;; normalize different versions
2472 (delq nil
2473 (mapcar
2474 (lambda (x)
2475 (cond ((stringp (cdr x))
2476 (push x prefix-descriptions)
2477 nil)
2478 ((stringp (nth 1 x)) x)
2479 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2480 (t (cons (car x) (cons "" (cdr x))))))
2481 org-agenda-custom-commands)))
2482 (org-agenda-custom-commands
2483 (org-contextualize-keys
2484 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2485 (buf (current-buffer))
2486 (bfn (buffer-file-name (buffer-base-buffer)))
2487 entry key type org-match lprops ans)
2488 ;; Turn off restriction unless there is an overriding one,
2489 (unless org-agenda-overriding-restriction
2490 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2491 ;; There is a request to keep the file list in place
2492 (put 'org-agenda-files 'org-restrict nil))
2493 (setq org-agenda-restrict nil)
2494 (move-marker org-agenda-restrict-begin nil)
2495 (move-marker org-agenda-restrict-end nil))
2496 ;; Delete old local properties
2497 (put 'org-agenda-redo-command 'org-lprops nil)
2498 ;; Delete previously set last-arguments
2499 (put 'org-agenda-redo-command 'last-args nil)
2500 ;; Remember where this call originated
2501 (setq org-agenda-last-dispatch-buffer (current-buffer))
2502 (unless org-keys
2503 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2504 org-keys (car ans)
2505 restriction (cdr ans)))
2506 ;; If we have sticky agenda buffers, set a name for the buffer,
2507 ;; depending on the invoking keys. The user may still set this
2508 ;; as a command option, which will overwrite what we do here.
2509 (if org-agenda-sticky
2510 (setq org-agenda-buffer-name
2511 (format "*Org Agenda(%s)*" org-keys)))
2512 ;; Establish the restriction, if any
2513 (when (and (not org-agenda-overriding-restriction) restriction)
2514 (put 'org-agenda-files 'org-restrict (list bfn))
2515 (cond
2516 ((eq restriction 'region)
2517 (setq org-agenda-restrict t)
2518 (move-marker org-agenda-restrict-begin (region-beginning))
2519 (move-marker org-agenda-restrict-end (region-end)))
2520 ((eq restriction 'subtree)
2521 (save-excursion
2522 (setq org-agenda-restrict t)
2523 (org-back-to-heading t)
2524 (move-marker org-agenda-restrict-begin (point))
2525 (move-marker org-agenda-restrict-end
2526 (progn (org-end-of-subtree t)))))))
2528 ;; For example the todo list should not need it (but does...)
2529 (cond
2530 ((setq entry (assoc org-keys org-agenda-custom-commands))
2531 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2532 (progn
2533 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2534 lprops (nth 4 entry))
2535 (if org-agenda-sticky
2536 (setq org-agenda-buffer-name
2537 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2538 (format "*Org Agenda(%s)*" org-keys))))
2539 (put 'org-agenda-redo-command 'org-lprops lprops)
2540 (cond
2541 ((eq type 'agenda)
2542 (org-let lprops '(org-agenda-list current-prefix-arg)))
2543 ((eq type 'alltodo)
2544 (org-let lprops '(org-todo-list current-prefix-arg)))
2545 ((eq type 'search)
2546 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2547 ((eq type 'stuck)
2548 (org-let lprops '(org-agenda-list-stuck-projects
2549 current-prefix-arg)))
2550 ((eq type 'tags)
2551 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2552 ((eq type 'tags-todo)
2553 (org-let lprops '(org-tags-view '(4) org-match)))
2554 ((eq type 'todo)
2555 (org-let lprops '(org-todo-list org-match)))
2556 ((eq type 'tags-tree)
2557 (org-check-for-org-mode)
2558 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2559 ((eq type 'todo-tree)
2560 (org-check-for-org-mode)
2561 (org-let lprops
2562 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2563 (regexp-quote org-match) "\\>"))))
2564 ((eq type 'occur-tree)
2565 (org-check-for-org-mode)
2566 (org-let lprops '(org-occur org-match)))
2567 ((functionp type)
2568 (org-let lprops '(funcall type org-match)))
2569 ((fboundp type)
2570 (org-let lprops '(funcall type org-match)))
2571 (t (error "Invalid custom agenda command type %s" type))))
2572 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2573 ((equal org-keys "C")
2574 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2575 (customize-variable 'org-agenda-custom-commands))
2576 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2577 ((equal org-keys "s") (call-interactively 'org-search-view))
2578 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2579 ((equal org-keys "t") (call-interactively 'org-todo-list))
2580 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2581 ((equal org-keys "m") (call-interactively 'org-tags-view))
2582 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2583 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2584 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2585 (org-add-hook
2586 'post-command-hook
2587 (lambda ()
2588 (unless (current-message)
2589 (let* ((m (org-agenda-get-any-marker))
2590 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2591 (when note
2592 (message (concat
2593 "FLAGGING-NOTE ([?] for more info): "
2594 (org-add-props
2595 (replace-regexp-in-string
2596 "\\\\n" "//"
2597 (copy-sequence note))
2598 nil 'face 'org-warning)))))))
2599 t t))
2600 ((equal org-keys "L")
2601 (unless (derived-mode-p 'org-mode)
2602 (error "This is not an Org-mode file"))
2603 (unless restriction
2604 (put 'org-agenda-files 'org-restrict (list bfn))
2605 (org-call-with-arg 'org-timeline arg)))
2606 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2607 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2608 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2609 (t (error "Invalid agenda key"))))))
2611 (autoload 'org-agenda "org-agenda" "\
2612 Dispatch agenda commands to collect entries to the agenda buffer.
2613 Prompts for a command to execute. Any prefix arg will be passed
2614 on to the selected command. The default selections are:
2616 a Call `org-agenda-list' to display the agenda for current day or week.
2617 t Call `org-todo-list' to display the global todo list.
2618 T Call `org-todo-list' to display the global todo list, select only
2619 entries with a specific TODO keyword (the user gets a prompt).
2620 m Call `org-tags-view' to display headlines with tags matching
2621 a condition (the user is prompted for the condition).
2622 M Like `m', but select only TODO entries, no ordinary headlines.
2623 L Create a timeline for the current buffer.
2624 e Export views to associated files.
2625 s Search entries for keywords.
2626 S Search entries for keywords, only with TODO keywords.
2627 / Multi occur across all agenda files and also files listed
2628 in `org-agenda-text-search-extra-files'.
2629 < Restrict agenda commands to buffer, subtree, or region.
2630 Press several times to get the desired effect.
2631 > Remove a previous restriction.
2632 # List \"stuck\" projects.
2633 ! Configure what \"stuck\" means.
2634 C Configure custom agenda commands.
2636 More commands can be added by configuring the variable
2637 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2638 searches can be pre-defined in this way.
2640 If the current buffer is in Org-mode and visiting a file, you can also
2641 first press `<' once to indicate that the agenda should be temporarily
2642 \(until the next use of \\[org-agenda]) restricted to the current file.
2643 Pressing `<' twice means to restrict to the current subtree or region
2644 \(if active).
2646 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2648 (defun org-agenda-append-agenda ()
2649 "Append another agenda view to the current one.
2650 This function allows interactive building of block agendas.
2651 Agenda views are separated by `org-agenda-block-separator'."
2652 (interactive)
2653 (unless (derived-mode-p 'org-agenda-mode)
2654 (error "Can only append from within agenda buffer"))
2655 (let ((org-agenda-multi t))
2656 (org-agenda)
2657 (widen)
2658 (org-agenda-finalize)
2659 (org-agenda-fit-window-to-buffer)))
2661 (defun org-agenda-normalize-custom-commands (cmds)
2662 (delq nil
2663 (mapcar
2664 (lambda (x)
2665 (cond ((stringp (cdr x)) nil)
2666 ((stringp (nth 1 x)) x)
2667 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2668 (t (cons (car x) (cons "" (cdr x))))))
2669 cmds)))
2671 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2672 "The user interface for selecting an agenda command."
2673 (catch 'exit
2674 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2675 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2676 (region-p (org-region-active-p))
2677 (custom org-agenda-custom-commands)
2678 (selstring "")
2679 restriction second-time
2680 c entry key type match prefixes rmheader header-end custom1 desc
2681 line lines left right n n1)
2682 (save-window-excursion
2683 (delete-other-windows)
2684 (org-switch-to-buffer-other-window " *Agenda Commands*")
2685 (erase-buffer)
2686 (insert (eval-when-compile
2687 (let ((header
2688 "Press key for an agenda command: < Buffer, subtree/region restriction
2689 -------------------------------- > Remove restriction
2690 a Agenda for current week or day e Export agenda views
2691 t List of all TODO entries T Entries with special TODO kwd
2692 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2693 s Search for keywords S Like s, but only TODO entries
2694 L Timeline for current buffer # List stuck projects (!=configure)
2695 / Multi-occur C Configure custom agenda commands
2696 ? Find :FLAGGED: entries * Toggle sticky agenda views
2698 (start 0))
2699 (while (string-match
2700 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2701 header start)
2702 (setq start (match-end 0))
2703 (add-text-properties (match-beginning 2) (match-end 2)
2704 '(face bold) header))
2705 header)))
2706 (setq header-end (point-marker))
2707 (while t
2708 (setq custom1 custom)
2709 (when (eq rmheader t)
2710 (org-goto-line 1)
2711 (re-search-forward ":" nil t)
2712 (delete-region (match-end 0) (point-at-eol))
2713 (forward-char 1)
2714 (looking-at "-+")
2715 (delete-region (match-end 0) (point-at-eol))
2716 (move-marker header-end (match-end 0)))
2717 (goto-char header-end)
2718 (delete-region (point) (point-max))
2720 ;; Produce all the lines that describe custom commands and prefixes
2721 (setq lines nil)
2722 (while (setq entry (pop custom1))
2723 (setq key (car entry) desc (nth 1 entry)
2724 type (nth 2 entry)
2725 match (nth 3 entry))
2726 (if (> (length key) 1)
2727 (add-to-list 'prefixes (string-to-char key))
2728 (setq line
2729 (format
2730 "%-4s%-14s"
2731 (org-add-props (copy-sequence key)
2732 '(face bold))
2733 (cond
2734 ((string-match "\\S-" desc) desc)
2735 ((eq type 'agenda) "Agenda for current week or day")
2736 ((eq type 'alltodo) "List of all TODO entries")
2737 ((eq type 'search) "Word search")
2738 ((eq type 'stuck) "List of stuck projects")
2739 ((eq type 'todo) "TODO keyword")
2740 ((eq type 'tags) "Tags query")
2741 ((eq type 'tags-todo) "Tags (TODO)")
2742 ((eq type 'tags-tree) "Tags tree")
2743 ((eq type 'todo-tree) "TODO kwd tree")
2744 ((eq type 'occur-tree) "Occur tree")
2745 ((functionp type) (if (symbolp type)
2746 (symbol-name type)
2747 "Lambda expression"))
2748 (t "???"))))
2749 (if org-agenda-menu-show-matcher
2750 (setq line
2751 (concat line ": "
2752 (cond
2753 ((stringp match)
2754 (setq match (copy-sequence match))
2755 (org-add-props match nil 'face 'org-warning))
2756 ((listp type)
2757 (format "set of %d commands" (length type))))))
2758 (if (org-string-nw-p match)
2759 (add-text-properties
2760 0 (length line) (list 'help-echo
2761 (concat "Matcher: " match)) line)))
2762 (push line lines)))
2763 (setq lines (nreverse lines))
2764 (when prefixes
2765 (mapc (lambda (x)
2766 (push
2767 (format "%s %s"
2768 (org-add-props (char-to-string x)
2769 nil 'face 'bold)
2770 (or (cdr (assoc (concat selstring
2771 (char-to-string x))
2772 prefix-descriptions))
2773 "Prefix key"))
2774 lines))
2775 prefixes))
2777 ;; Check if we should display in two columns
2778 (if org-agenda-menu-two-columns
2779 (progn
2780 (setq n (length lines)
2781 n1 (+ (/ n 2) (mod n 2))
2782 right (nthcdr n1 lines)
2783 left (copy-sequence lines))
2784 (setcdr (nthcdr (1- n1) left) nil))
2785 (setq left lines right nil))
2786 (while left
2787 (insert "\n" (pop left))
2788 (when right
2789 (if (< (current-column) 40)
2790 (move-to-column 40 t)
2791 (insert " "))
2792 (insert (pop right))))
2794 ;; Make the window the right size
2795 (goto-char (point-min))
2796 (if second-time
2797 (if (not (pos-visible-in-window-p (point-max)))
2798 (org-fit-window-to-buffer))
2799 (setq second-time t)
2800 (org-fit-window-to-buffer))
2802 ;; Ask for selection
2803 (message "Press key for agenda command%s:"
2804 (if (or restrict-ok org-agenda-overriding-restriction)
2805 (if org-agenda-overriding-restriction
2806 " (restriction lock active)"
2807 (if restriction
2808 (format " (restricted to %s)" restriction)
2809 " (unrestricted)"))
2810 ""))
2811 (setq c (read-char-exclusive))
2812 (message "")
2813 (cond
2814 ((assoc (char-to-string c) custom)
2815 (setq selstring (concat selstring (char-to-string c)))
2816 (throw 'exit (cons selstring restriction)))
2817 ((memq c prefixes)
2818 (setq selstring (concat selstring (char-to-string c))
2819 prefixes nil
2820 rmheader (or rmheader t)
2821 custom (delq nil (mapcar
2822 (lambda (x)
2823 (if (or (= (length (car x)) 1)
2824 (/= (string-to-char (car x)) c))
2826 (cons (substring (car x) 1) (cdr x))))
2827 custom))))
2828 ((eq c ?*)
2829 (call-interactively 'org-toggle-sticky-agenda)
2830 (sit-for 2))
2831 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2832 (message "Restriction is only possible in Org-mode buffers")
2833 (ding) (sit-for 1))
2834 ((eq c ?1)
2835 (org-agenda-remove-restriction-lock 'noupdate)
2836 (setq restriction 'buffer))
2837 ((eq c ?0)
2838 (org-agenda-remove-restriction-lock 'noupdate)
2839 (setq restriction (if region-p 'region 'subtree)))
2840 ((eq c ?<)
2841 (org-agenda-remove-restriction-lock 'noupdate)
2842 (setq restriction
2843 (cond
2844 ((eq restriction 'buffer)
2845 (if region-p 'region 'subtree))
2846 ((memq restriction '(subtree region))
2847 nil)
2848 (t 'buffer))))
2849 ((eq c ?>)
2850 (org-agenda-remove-restriction-lock 'noupdate)
2851 (setq restriction nil))
2852 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2853 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2854 ((and (> (length selstring) 0) (eq c ?\d))
2855 (delete-window)
2856 (org-agenda-get-restriction-and-command prefix-descriptions))
2858 ((equal c ?q) (error "Abort"))
2859 (t (error "Invalid key %c" c))))))))
2861 (defun org-agenda-fit-window-to-buffer ()
2862 "Fit the window to the buffer size."
2863 (and (memq org-agenda-window-setup '(reorganize-frame))
2864 (fboundp 'fit-window-to-buffer)
2865 (org-fit-window-to-buffer
2867 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2868 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2870 (defvar org-cmd nil)
2871 (defvar org-agenda-overriding-cmd nil)
2872 (defvar org-agenda-overriding-arguments nil)
2873 (defvar org-agenda-overriding-cmd-arguments nil)
2874 (defun org-agenda-run-series (name series)
2875 (org-let (nth 1 series) '(org-agenda-prepare name))
2876 ;; We need to reset agenda markers here, because when constructing a
2877 ;; block agenda, the individual blocks do not do that.
2878 (org-agenda-reset-markers)
2879 (let* ((org-agenda-multi t)
2880 (redo (list 'org-agenda-run-series name (list 'quote series)))
2881 (cmds (car series))
2882 (gprops (nth 1 series))
2883 match ;; The byte compiler incorrectly complains about this. Keep it!
2884 org-cmd type lprops)
2885 (while (setq org-cmd (pop cmds))
2886 (setq type (car org-cmd)
2887 match (eval (nth 1 org-cmd))
2888 lprops (nth 2 org-cmd))
2889 (let ((org-agenda-overriding-arguments
2890 (if (eq org-agenda-overriding-cmd org-cmd)
2891 (or org-agenda-overriding-arguments
2892 org-agenda-overriding-cmd-arguments))))
2893 (cond
2894 ((eq type 'agenda)
2895 (org-let2 gprops lprops
2896 '(call-interactively 'org-agenda-list)))
2897 ((eq type 'alltodo)
2898 (org-let2 gprops lprops
2899 '(call-interactively 'org-todo-list)))
2900 ((eq type 'search)
2901 (org-let2 gprops lprops
2902 '(org-search-view current-prefix-arg match nil)))
2903 ((eq type 'stuck)
2904 (org-let2 gprops lprops
2905 '(call-interactively 'org-agenda-list-stuck-projects)))
2906 ((eq type 'tags)
2907 (org-let2 gprops lprops
2908 '(org-tags-view current-prefix-arg match)))
2909 ((eq type 'tags-todo)
2910 (org-let2 gprops lprops
2911 '(org-tags-view '(4) match)))
2912 ((eq type 'todo)
2913 (org-let2 gprops lprops
2914 '(org-todo-list match)))
2915 ((fboundp type)
2916 (org-let2 gprops lprops
2917 '(funcall type match)))
2918 (t (error "Invalid type in command series")))))
2919 (widen)
2920 (let ((inhibit-read-only t))
2921 (add-text-properties (point-min) (point-max)
2922 `(org-series t org-series-redo-cmd ,redo)))
2923 (setq org-agenda-redo-command redo)
2924 (goto-char (point-min)))
2925 (org-agenda-fit-window-to-buffer)
2926 (org-let (nth 1 series) '(org-agenda-finalize)))
2928 ;;;###autoload
2929 (defmacro org-batch-agenda (cmd-key &rest parameters)
2930 "Run an agenda command in batch mode and send the result to STDOUT.
2931 If CMD-KEY is a string of length 1, it is used as a key in
2932 `org-agenda-custom-commands' and triggers this command. If it is a
2933 longer string it is used as a tags/todo match string.
2934 Parameters are alternating variable names and values that will be bound
2935 before running the agenda command."
2936 (org-eval-in-environment (org-make-parameter-alist parameters)
2937 (if (> (length cmd-key) 2)
2938 (org-tags-view nil cmd-key)
2939 (org-agenda nil cmd-key)))
2940 (set-buffer org-agenda-buffer-name)
2941 (princ (buffer-string)))
2943 (autoload 'org-batch-agenda "org-agenda" "\
2944 Run an agenda command in batch mode and send the result to STDOUT.
2945 If CMD-KEY is a string of length 1, it is used as a key in
2946 `org-agenda-custom-commands' and triggers this command. If it is a
2947 longer string it is used as a tags/todo match string.
2948 Parameters are alternating variable names and values that will be bound
2949 before running the agenda command.
2951 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2952 (def-edebug-spec org-batch-agenda (form &rest sexp))
2954 (defvar org-agenda-info nil)
2956 ;;;###autoload
2957 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2958 "Run an agenda command in batch mode and send the result to STDOUT.
2959 If CMD-KEY is a string of length 1, it is used as a key in
2960 `org-agenda-custom-commands' and triggers this command. If it is a
2961 longer string it is used as a tags/todo match string.
2962 Parameters are alternating variable names and values that will be bound
2963 before running the agenda command.
2965 The output gives a line for each selected agenda item. Each
2966 item is a list of comma-separated values, like this:
2968 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2970 category The category of the item
2971 head The headline, without TODO kwd, TAGS and PRIORITY
2972 type The type of the agenda entry, can be
2973 todo selected in TODO match
2974 tagsmatch selected in tags match
2975 diary imported from diary
2976 deadline a deadline on given date
2977 scheduled scheduled on given date
2978 timestamp entry has timestamp on given date
2979 closed entry was closed on given date
2980 upcoming-deadline warning about deadline
2981 past-scheduled forwarded scheduled item
2982 block entry has date block including g. date
2983 todo The todo keyword, if any
2984 tags All tags including inherited ones, separated by colons
2985 date The relevant date, like 2007-2-14
2986 time The time, like 15:00-16:50
2987 extra Sting with extra planning info
2988 priority-l The priority letter if any was given
2989 priority-n The computed numerical priority
2990 agenda-day The day in the agenda where this is listed"
2991 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2992 (org-make-parameter-alist parameters))
2993 (if (> (length cmd-key) 2)
2994 (org-tags-view nil cmd-key)
2995 (org-agenda nil cmd-key)))
2996 (set-buffer org-agenda-buffer-name)
2997 (let* ((lines (org-split-string (buffer-string) "\n"))
2998 line)
2999 (while (setq line (pop lines))
3000 (catch 'next
3001 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3002 (setq org-agenda-info
3003 (org-fix-agenda-info (text-properties-at 0 line)))
3004 (princ
3005 (mapconcat 'org-agenda-export-csv-mapper
3006 '(org-category txt type todo tags date time extra
3007 priority-letter priority agenda-day)
3008 ","))
3009 (princ "\n")))))
3011 (autoload 'org-batch-agenda-csv "org-agenda" "\
3012 Run an agenda command in batch mode and send the result to STDOUT.
3013 If CMD-KEY is a string of length 1, it is used as a key in
3014 `org-agenda-custom-commands' and triggers this command. If it is a
3015 longer string it is used as a tags/todo match string.
3016 Parameters are alternating variable names and values that will be bound
3017 before running the agenda command.
3019 The output gives a line for each selected agenda item. Each
3020 item is a list of comma-separated values, like this:
3022 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3024 category The category of the item
3025 head The headline, without TODO kwd, TAGS and PRIORITY
3026 type The type of the agenda entry, can be
3027 todo selected in TODO match
3028 tagsmatch selected in tags match
3029 diary imported from diary
3030 deadline a deadline on given date
3031 scheduled scheduled on given date
3032 timestamp entry has timestamp on given date
3033 closed entry was closed on given date
3034 upcoming-deadline warning about deadline
3035 past-scheduled forwarded scheduled item
3036 block entry has date block including g. date
3037 todo The todo keyword, if any
3038 tags All tags including inherited ones, separated by colons
3039 date The relevant date, like 2007-2-14
3040 time The time, like 15:00-16:50
3041 extra Sting with extra planning info
3042 priority-l The priority letter if any was given
3043 priority-n The computed numerical priority
3044 agenda-day The day in the agenda where this is listed
3046 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3047 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3049 (defun org-fix-agenda-info (props)
3050 "Make sure all properties on an agenda item have a canonical form.
3051 This ensures the export commands can easily use it."
3052 (let (tmp re)
3053 (when (setq tmp (plist-get props 'tags))
3054 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3055 (when (setq tmp (plist-get props 'date))
3056 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3057 (let ((calendar-date-display-form '(year "-" month "-" day)))
3058 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3060 (setq tmp (calendar-date-string tmp)))
3061 (setq props (plist-put props 'date tmp)))
3062 (when (setq tmp (plist-get props 'day))
3063 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3064 (let ((calendar-date-display-form '(year "-" month "-" day)))
3065 (setq tmp (calendar-date-string tmp)))
3066 (setq props (plist-put props 'day tmp))
3067 (setq props (plist-put props 'agenda-day tmp)))
3068 (when (setq tmp (plist-get props 'txt))
3069 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3070 (plist-put props 'priority-letter (match-string 1 tmp))
3071 (setq tmp (replace-match "" t t tmp)))
3072 (when (and (setq re (plist-get props 'org-todo-regexp))
3073 (setq re (concat "\\`\\.*" re " ?"))
3074 (string-match re tmp))
3075 (plist-put props 'todo (match-string 1 tmp))
3076 (setq tmp (replace-match "" t t tmp)))
3077 (plist-put props 'txt tmp)))
3078 props)
3080 (defun org-agenda-export-csv-mapper (prop)
3081 (let ((res (plist-get org-agenda-info prop)))
3082 (setq res
3083 (cond
3084 ((not res) "")
3085 ((stringp res) res)
3086 (t (prin1-to-string res))))
3087 (while (string-match "," res)
3088 (setq res (replace-match ";" t t res)))
3089 (org-trim res)))
3091 ;;;###autoload
3092 (defun org-store-agenda-views (&rest parameters)
3093 (interactive)
3094 (eval (list 'org-batch-store-agenda-views)))
3096 (autoload 'org-store-agenda-views "org-agenda" "\
3099 \(fn &rest PARAMETERS)" t nil)
3101 ;;;###autoload
3102 (defmacro org-batch-store-agenda-views (&rest parameters)
3103 "Run all custom agenda commands that have a file argument."
3104 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3105 (pop-up-frames nil)
3106 (dir default-directory)
3107 (pars (org-make-parameter-alist parameters))
3108 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3109 (save-window-excursion
3110 (while cmds
3111 (setq cmd (pop cmds)
3112 thiscmdkey (car cmd)
3113 thiscmdcmd (cdr cmd)
3114 match (nth 2 thiscmdcmd)
3115 bufname (if org-agenda-sticky
3116 (or (and (stringp match)
3117 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3118 (format "*Org Agenda(%s)*" thiscmdkey))
3119 org-agenda-buffer-name)
3120 cmd-or-set (nth 2 cmd)
3121 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3122 files (nth (if (listp cmd-or-set) 4 5) cmd))
3123 (if (stringp files) (setq files (list files)))
3124 (when files
3125 (org-eval-in-environment (append org-agenda-exporter-settings
3126 opts pars)
3127 (org-agenda nil thiscmdkey))
3128 (set-buffer bufname)
3129 (while files
3130 (org-eval-in-environment (append org-agenda-exporter-settings
3131 opts pars)
3132 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3133 (and (get-buffer bufname)
3134 (kill-buffer bufname)))))))
3136 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3137 Run all custom agenda commands that have a file argument.
3139 \(fn &rest PARAMETERS)" nil t)
3140 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3142 (defvar org-agenda-current-span nil
3143 "The current span used in the agenda view.") ; local variable in the agenda buffer
3144 (defun org-agenda-mark-header-line (pos)
3145 "Mark the line at POS as an agenda structure header."
3146 (save-excursion
3147 (goto-char pos)
3148 (put-text-property (point-at-bol) (point-at-eol)
3149 'org-agenda-structural-header t)
3150 (when org-agenda-title-append
3151 (put-text-property (point-at-bol) (point-at-eol)
3152 'org-agenda-title-append org-agenda-title-append))))
3154 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3155 (defvar org-agenda-write-buffer-name "Agenda View")
3156 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3157 "Write the current buffer (an agenda view) as a file.
3158 Depending on the extension of the file name, plain text (.txt),
3159 HTML (.html or .htm) or Postscript (.ps) is produced.
3160 If the extension is .ics, run icalendar export over all files used
3161 to construct the agenda and limit the export to entries listed in the
3162 agenda now.
3163 With prefix argument OPEN, open the new file immediately.
3164 If NOSETTINGS is given, do not scope the settings of
3165 `org-agenda-exporter-settings' into the export commands. This is used when
3166 the settings have already been scoped and we do not wish to overrule other,
3167 higher priority settings.
3168 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3169 (interactive "FWrite agenda to file: \nP")
3170 (if (not (file-writable-p file))
3171 (error "Cannot write agenda to file %s" file))
3172 (org-let (if nosettings nil org-agenda-exporter-settings)
3173 '(save-excursion
3174 (save-window-excursion
3175 (org-agenda-mark-filtered-text)
3176 (let ((bs (copy-sequence (buffer-string))) beg)
3177 (org-agenda-unmark-filtered-text)
3178 (with-temp-buffer
3179 (rename-buffer org-agenda-write-buffer-name t)
3180 (set-buffer-modified-p nil)
3181 (insert bs)
3182 (org-agenda-remove-marked-text 'org-filtered)
3183 (while (setq beg (text-property-any (point-min) (point-max)
3184 'org-filtered t))
3185 (delete-region
3186 beg (or (next-single-property-change beg 'org-filtered)
3187 (point-max))))
3188 (run-hooks 'org-agenda-before-write-hook)
3189 (cond
3190 ((org-bound-and-true-p org-mobile-creating-agendas)
3191 (org-mobile-write-agenda-for-mobile file))
3192 ((string-match "\\.html?\\'" file)
3193 (require 'htmlize)
3194 (set-buffer (htmlize-buffer (current-buffer)))
3195 (when org-agenda-export-html-style
3196 ;; replace <style> section with org-agenda-export-html-style
3197 (goto-char (point-min))
3198 (kill-region (- (search-forward "<style") 6)
3199 (search-forward "</style>"))
3200 (insert org-agenda-export-html-style))
3201 (write-file file)
3202 (kill-buffer (current-buffer))
3203 (message "HTML written to %s" file))
3204 ((string-match "\\.ps\\'" file)
3205 (require 'ps-print)
3206 (ps-print-buffer-with-faces file)
3207 (message "Postscript written to %s" file))
3208 ((string-match "\\.pdf\\'" file)
3209 (require 'ps-print)
3210 (ps-print-buffer-with-faces
3211 (concat (file-name-sans-extension file) ".ps"))
3212 (call-process "ps2pdf" nil nil nil
3213 (expand-file-name
3214 (concat (file-name-sans-extension file) ".ps"))
3215 (expand-file-name file))
3216 (delete-file (concat (file-name-sans-extension file) ".ps"))
3217 (message "PDF written to %s" file))
3218 ((string-match "\\.ics\\'" file)
3219 (require 'org-icalendar)
3220 (let ((org-agenda-marker-table
3221 (org-create-marker-find-array
3222 (org-agenda-collect-markers)))
3223 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3224 (org-combined-agenda-icalendar-file file))
3225 (apply 'org-export-icalendar 'combine
3226 (org-agenda-files nil 'ifmode))))
3228 (let ((bs (buffer-string)))
3229 (find-file file)
3230 (erase-buffer)
3231 (insert bs)
3232 (save-buffer 0)
3233 (kill-buffer (current-buffer))
3234 (message "Plain text written to %s" file))))))))
3235 (set-buffer (or agenda-bufname
3236 (and (org-called-interactively-p 'any) (buffer-name))
3237 org-agenda-buffer-name)))
3238 (when open (org-open-file file)))
3240 (defvar org-agenda-tag-filter-overlays nil)
3241 (defvar org-agenda-cat-filter-overlays nil)
3243 (defun org-agenda-mark-filtered-text ()
3244 "Mark all text hidden by filtering with a text property."
3245 (let ((inhibit-read-only t))
3246 (mapc
3247 (lambda (o)
3248 (when (equal (overlay-buffer o) (current-buffer))
3249 (put-text-property
3250 (overlay-start o) (overlay-end o)
3251 'org-filtered t)))
3252 (append org-agenda-tag-filter-overlays
3253 org-agenda-cat-filter-overlays))))
3255 (defun org-agenda-unmark-filtered-text ()
3256 "Remove the filtering text property."
3257 (let ((inhibit-read-only t))
3258 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3260 (defun org-agenda-remove-marked-text (property &optional value)
3261 "Delete all text marked with VALUE of PROPERTY.
3262 VALUE defaults to t."
3263 (let (beg)
3264 (setq value (or value t))
3265 (while (setq beg (text-property-any (point-min) (point-max)
3266 property value))
3267 (delete-region
3268 beg (or (next-single-property-change beg 'org-filtered)
3269 (point-max))))))
3271 (defun org-agenda-add-entry-text ()
3272 "Add entry text to agenda lines.
3273 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3274 entry text following headings shown in the agenda.
3275 Drawers will be excluded, also the line with scheduling/deadline info."
3276 (when (and (> org-agenda-add-entry-text-maxlines 0)
3277 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3278 (let (m txt)
3279 (goto-char (point-min))
3280 (while (not (eobp))
3281 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3282 (beginning-of-line 2)
3283 (setq txt (org-agenda-get-some-entry-text
3284 m org-agenda-add-entry-text-maxlines " > "))
3285 (end-of-line 1)
3286 (if (string-match "\\S-" txt)
3287 (insert "\n" txt)
3288 (or (eobp) (forward-char 1))))))))
3290 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3291 &rest keep)
3292 "Extract entry text from MARKER, at most N-LINES lines.
3293 This will ignore drawers etc, just get the text.
3294 If INDENT is given, prefix every line with this string. If KEEP is
3295 given, it is a list of symbols, defining stuff that should not be
3296 removed from the entry content. Currently only `planning' is allowed here."
3297 (let (txt drawer-re kwd-time-re ind)
3298 (save-excursion
3299 (with-current-buffer (marker-buffer marker)
3300 (if (not (derived-mode-p 'org-mode))
3301 (setq txt "")
3302 (save-excursion
3303 (save-restriction
3304 (widen)
3305 (goto-char marker)
3306 (end-of-line 1)
3307 (setq txt (buffer-substring
3308 (min (1+ (point)) (point-max))
3309 (progn (outline-next-heading) (point)))
3310 drawer-re org-drawer-regexp
3311 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3312 ".*\n?"))
3313 (with-temp-buffer
3314 (insert txt)
3315 (when org-agenda-add-entry-text-descriptive-links
3316 (goto-char (point-min))
3317 (while (org-activate-bracket-links (point-max))
3318 (add-text-properties (match-beginning 0) (match-end 0)
3319 '(face org-link))))
3320 (goto-char (point-min))
3321 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3322 (set-text-properties (match-beginning 0) (match-end 0)
3323 nil))
3324 (goto-char (point-min))
3325 (while (re-search-forward drawer-re nil t)
3326 (delete-region
3327 (match-beginning 0)
3328 (progn (re-search-forward
3329 "^[ \t]*:END:.*\n?" nil 'move)
3330 (point))))
3331 (unless (member 'planning keep)
3332 (goto-char (point-min))
3333 (while (re-search-forward kwd-time-re nil t)
3334 (replace-match "")))
3335 (goto-char (point-min))
3336 (when org-agenda-entry-text-exclude-regexps
3337 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3338 (while (setq re (pop re-list))
3339 (goto-char (point-min))
3340 (while (re-search-forward re nil t)
3341 (replace-match "")))))
3342 (goto-char (point-max))
3343 (skip-chars-backward " \t\n")
3344 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3346 ;; find and remove min common indentation
3347 (goto-char (point-min))
3348 (untabify (point-min) (point-max))
3349 (setq ind (org-get-indentation))
3350 (while (not (eobp))
3351 (unless (looking-at "[ \t]*$")
3352 (setq ind (min ind (org-get-indentation))))
3353 (beginning-of-line 2))
3354 (goto-char (point-min))
3355 (while (not (eobp))
3356 (unless (looking-at "[ \t]*$")
3357 (move-to-column ind)
3358 (delete-region (point-at-bol) (point)))
3359 (beginning-of-line 2))
3361 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3363 (goto-char (point-min))
3364 (when indent
3365 (while (and (not (eobp)) (re-search-forward "^" nil t))
3366 (replace-match indent t t)))
3367 (goto-char (point-min))
3368 (while (looking-at "[ \t]*\n") (replace-match ""))
3369 (goto-char (point-max))
3370 (when (> (org-current-line)
3371 n-lines)
3372 (org-goto-line (1+ n-lines))
3373 (backward-char 1))
3374 (setq txt (buffer-substring (point-min) (point)))))))))
3375 txt))
3377 (defun org-agenda-collect-markers ()
3378 "Collect the markers pointing to entries in the agenda buffer."
3379 (let (m markers)
3380 (save-excursion
3381 (goto-char (point-min))
3382 (while (not (eobp))
3383 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3384 (org-get-at-bol 'org-marker)))
3385 (push m markers))
3386 (beginning-of-line 2)))
3387 (nreverse markers)))
3389 (defun org-create-marker-find-array (marker-list)
3390 "Create a alist of files names with all marker positions in that file."
3391 (let (f tbl m a p)
3392 (while (setq m (pop marker-list))
3393 (setq p (marker-position m)
3394 f (buffer-file-name (or (buffer-base-buffer
3395 (marker-buffer m))
3396 (marker-buffer m))))
3397 (if (setq a (assoc f tbl))
3398 (push (marker-position m) (cdr a))
3399 (push (list f p) tbl)))
3400 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3401 tbl)))
3403 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3404 (defun org-check-agenda-marker-table ()
3405 "Check of the current entry is on the marker list."
3406 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3408 (and (setq a (assoc file org-agenda-marker-table))
3409 (save-match-data
3410 (save-excursion
3411 (org-back-to-heading t)
3412 (member (point) (cdr a)))))))
3414 (defun org-check-for-org-mode ()
3415 "Make sure current buffer is in org-mode. Error if not."
3416 (or (derived-mode-p 'org-mode)
3417 (error "Cannot execute org-mode agenda command on buffer in %s"
3418 major-mode)))
3420 ;;; Agenda prepare and finalize
3422 (defvar org-agenda-multi nil) ; dynamically scoped
3423 (defvar org-agenda-pre-window-conf nil)
3424 (defvar org-agenda-columns-active nil)
3425 (defvar org-agenda-name nil)
3426 (defvar org-agenda-tag-filter nil)
3427 (defvar org-agenda-category-filter nil)
3428 (defvar org-agenda-top-category-filter nil)
3429 (defvar org-agenda-tag-filter-while-redo nil)
3430 (defvar org-agenda-tag-filter-preset nil
3431 "A preset of the tags filter used for secondary agenda filtering.
3432 This must be a list of strings, each string must be a single tag preceded
3433 by \"+\" or \"-\".
3434 This variable should not be set directly, but agenda custom commands can
3435 bind it in the options section. The preset filter is a global property of
3436 the entire agenda view. In a block agenda, it will not work reliably to
3437 define a filter for one of the individual blocks. You need to set it in
3438 the global options and expect it to be applied to the entire view.")
3440 (defvar org-agenda-category-filter-preset nil
3441 "A preset of the category filter used for secondary agenda filtering.
3442 This must be a list of strings, each string must be a single category
3443 preceded by \"+\" or \"-\".
3444 This variable should not be set directly, but agenda custom commands can
3445 bind it in the options section. The preset filter is a global property of
3446 the entire agenda view. In a block agenda, it will not work reliably to
3447 define a filter for one of the individual blocks. You need to set it in
3448 the global options and expect it to be applied to the entire view.")
3451 (defun org-agenda-use-sticky-p ()
3452 "Return non-nil if an agenda buffer named
3453 `org-agenda-buffer-name' exists and should be shown instead of
3454 generating a new one."
3455 (and
3456 ;; turned off by user
3457 org-agenda-sticky
3458 ;; For multi-agenda buffer already exists
3459 (not org-agenda-multi)
3460 ;; buffer found
3461 (get-buffer org-agenda-buffer-name)
3462 ;; C-u parameter is same as last call
3463 (with-current-buffer (get-buffer org-agenda-buffer-name)
3464 (and
3465 (equal current-prefix-arg
3466 org-agenda-last-prefix-arg)
3467 ;; In case user turned stickiness on, while having existing
3468 ;; Agenda buffer active, don't reuse that buffer, because it
3469 ;; does not have org variables local
3470 org-agenda-this-buffer-is-sticky))))
3472 (defun org-agenda-prepare-window (abuf)
3473 "Setup agenda buffer in the window."
3474 (let* ((awin (get-buffer-window abuf))
3475 wconf)
3476 (cond
3477 ((equal (current-buffer) abuf) nil)
3478 (awin (select-window awin))
3479 ((not (setq wconf (current-window-configuration))))
3480 ((equal org-agenda-window-setup 'current-window)
3481 (org-pop-to-buffer-same-window abuf))
3482 ((equal org-agenda-window-setup 'other-window)
3483 (org-switch-to-buffer-other-window abuf))
3484 ((equal org-agenda-window-setup 'other-frame)
3485 (switch-to-buffer-other-frame abuf))
3486 ((equal org-agenda-window-setup 'reorganize-frame)
3487 (delete-other-windows)
3488 (org-switch-to-buffer-other-window abuf)))
3489 ;; additional test in case agenda is invoked from within agenda
3490 ;; buffer via elisp link
3491 (unless (equal (current-buffer) abuf)
3492 (org-pop-to-buffer-same-window abuf))
3493 (setq org-agenda-pre-window-conf
3494 (or org-agenda-pre-window-conf wconf))))
3496 (defun org-agenda-prepare (&optional name)
3497 (if (org-agenda-use-sticky-p)
3498 (progn
3499 ;; Popup existing buffer
3500 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3501 (message "Sticky Agenda buffer, use `r' to refresh")
3502 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3503 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3504 (setq org-todo-keywords-for-agenda nil)
3505 (setq org-drawers-for-agenda nil)
3506 (unless org-agenda-persistent-filter
3507 (setq org-agenda-tag-filter nil
3508 org-agenda-category-filter nil))
3509 (put 'org-agenda-tag-filter :preset-filter
3510 org-agenda-tag-filter-preset)
3511 (put 'org-agenda-category-filter :preset-filter
3512 org-agenda-category-filter-preset)
3513 (if org-agenda-multi
3514 (progn
3515 (setq buffer-read-only nil)
3516 (goto-char (point-max))
3517 (unless (or (bobp) org-agenda-compact-blocks
3518 (not org-agenda-block-separator))
3519 (insert "\n"
3520 (if (stringp org-agenda-block-separator)
3521 org-agenda-block-separator
3522 (make-string (window-width) org-agenda-block-separator))
3523 "\n"))
3524 (narrow-to-region (point) (point-max)))
3525 (setq org-done-keywords-for-agenda nil)
3527 ;; Setting any org variables that are in org-agenda-local-vars
3528 ;; list need to be done after the prepare call
3529 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3530 (setq buffer-read-only nil)
3531 (org-agenda-reset-markers)
3532 (let ((inhibit-read-only t)) (erase-buffer))
3533 (org-agenda-mode)
3534 (setq org-agenda-buffer (current-buffer))
3535 (setq org-agenda-contributing-files nil)
3536 (setq org-agenda-columns-active nil)
3537 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3538 (setq org-todo-keywords-for-agenda
3539 (org-uniquify org-todo-keywords-for-agenda))
3540 (setq org-done-keywords-for-agenda
3541 (org-uniquify org-done-keywords-for-agenda))
3542 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3543 (setq org-agenda-last-prefix-arg current-prefix-arg)
3544 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3545 (and name (not org-agenda-name)
3546 (org-set-local 'org-agenda-name name)))
3547 (setq buffer-read-only nil)))
3549 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3550 (defun org-agenda-finalize ()
3551 "Finishing touch for the agenda buffer, called just before displaying it."
3552 (unless org-agenda-multi
3553 (save-excursion
3554 (let ((inhibit-read-only t))
3555 (goto-char (point-min))
3556 (save-excursion
3557 (while (org-activate-bracket-links (point-max))
3558 (add-text-properties (match-beginning 0) (match-end 0)
3559 '(face org-link))))
3560 (save-excursion
3561 (while (org-activate-plain-links (point-max))
3562 (add-text-properties (match-beginning 0) (match-end 0)
3563 '(face org-link))))
3564 (when (cadr (assoc 'org-prefix-has-tag
3565 (car org-prefix-format-compiled)))
3566 (org-agenda-align-tags))
3567 (unless org-agenda-with-colors
3568 (remove-text-properties (point-min) (point-max) '(face nil))))
3569 (if (and (boundp 'org-agenda-overriding-columns-format)
3570 org-agenda-overriding-columns-format)
3571 (org-set-local 'org-agenda-overriding-columns-format
3572 org-agenda-overriding-columns-format))
3573 (if (and (boundp 'org-agenda-view-columns-initially)
3574 org-agenda-view-columns-initially)
3575 (org-agenda-columns))
3576 (when org-agenda-fontify-priorities
3577 (org-agenda-fontify-priorities))
3578 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3579 (org-agenda-dim-blocked-tasks))
3580 ;; We need to widen when `org-agenda-finalize' is called from
3581 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3582 (when org-clock-current-task
3583 (save-restriction
3584 (widen)
3585 (org-agenda-mark-clocking-task)))
3586 (when org-agenda-entry-text-mode
3587 (org-agenda-entry-text-hide)
3588 (org-agenda-entry-text-show))
3589 (if (and (functionp 'org-habit-insert-consistency-graphs)
3590 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3591 (org-habit-insert-consistency-graphs))
3592 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3593 (when (delq nil (mapcar (lambda (tp) (org-agenda-check-type nil tp))
3594 org-agenda-use-tag-inheritance))
3595 (let (mrk)
3596 (save-excursion
3597 (goto-char (point-min))
3598 (while (equal (forward-line) 0)
3599 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3600 (get-text-property (point) 'org-hd-marker)))
3601 (put-text-property (point-at-bol) (point-at-eol)
3602 'tags (org-with-point-at mrk
3603 (delete-dups (org-get-tags-at)))))))))
3604 (let ((inhibit-read-only t))
3605 (run-hooks 'org-agenda-finalize-hook))
3606 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3607 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3608 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3609 (org-agenda-filter-apply org-agenda-category-filter 'category))
3610 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3612 (defun org-agenda-mark-clocking-task ()
3613 "Mark the current clock entry in the agenda if it is present."
3614 (mapc (lambda (o)
3615 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3616 (delete-overlay o)))
3617 (overlays-in (point-min) (point-max)))
3618 (when (marker-buffer org-clock-hd-marker)
3619 (save-excursion
3620 (goto-char (point-min))
3621 (let (s ov)
3622 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3623 (goto-char s)
3624 (when (equal (org-get-at-bol 'org-hd-marker)
3625 org-clock-hd-marker)
3626 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3627 (overlay-put ov 'type 'org-agenda-clocking)
3628 (overlay-put ov 'face 'org-agenda-clocking)
3629 (overlay-put ov 'help-echo
3630 "The clock is running in this item")))))))
3632 (defun org-agenda-fontify-priorities ()
3633 "Make highest priority lines bold, and lowest italic."
3634 (interactive)
3635 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3636 (delete-overlay o)))
3637 (overlays-in (point-min) (point-max)))
3638 (save-excursion
3639 (let ((inhibit-read-only t)
3640 b e p ov h l)
3641 (goto-char (point-min))
3642 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3643 (setq h (or (get-char-property (point) 'org-highest-priority)
3644 org-highest-priority)
3645 l (or (get-char-property (point) 'org-lowest-priority)
3646 org-lowest-priority)
3647 p (string-to-char (match-string 1))
3648 b (match-beginning 0)
3649 e (if (eq org-agenda-fontify-priorities 'cookies)
3650 (match-end 0)
3651 (point-at-eol))
3652 ov (make-overlay b e))
3653 (overlay-put
3654 ov 'face
3655 (cond ((org-face-from-face-or-color
3656 'priority nil
3657 (cdr (assoc p org-priority-faces))))
3658 ((and (listp org-agenda-fontify-priorities)
3659 (org-face-from-face-or-color
3660 'priority nil
3661 (cdr (assoc p org-agenda-fontify-priorities)))))
3662 ((equal p l) 'italic)
3663 ((equal p h) 'bold)))
3664 (overlay-put ov 'org-type 'org-priority)))))
3666 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3667 (interactive "P")
3668 "Dim currently blocked TODO's in the agenda display."
3669 (message "Dim or hide blocked tasks...")
3670 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3671 (delete-overlay o)))
3672 (overlays-in (point-min) (point-max)))
3673 (save-excursion
3674 (let ((inhibit-read-only t)
3675 (org-depend-tag-blocked nil)
3676 (invis (or (not (null invisible))
3677 (eq org-agenda-dim-blocked-tasks 'invisible)))
3678 org-blocked-by-checkboxes
3679 invis1 b e p ov h l)
3680 (goto-char (point-min))
3681 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3682 (and pos (goto-char (1+ pos))))
3683 (setq org-blocked-by-checkboxes nil invis1 invis)
3684 (let ((marker (org-get-at-bol 'org-hd-marker)))
3685 (when (and marker
3686 (with-current-buffer (marker-buffer marker)
3687 (save-excursion (goto-char marker)
3688 (org-entry-blocked-p))))
3689 (if org-blocked-by-checkboxes (setq invis1 nil))
3690 (setq b (if invis1
3691 (max (point-min) (1- (point-at-bol)))
3692 (point-at-bol))
3693 e (point-at-eol)
3694 ov (make-overlay b e))
3695 (if invis1
3696 (overlay-put ov 'invisible t)
3697 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3698 (overlay-put ov 'org-type 'org-blocked-todo))))))
3699 (message "Dim or hide blocked tasks...done"))
3701 (defvar org-agenda-skip-function nil
3702 "Function to be called at each match during agenda construction.
3703 If this function returns nil, the current match should not be skipped.
3704 Otherwise, the function must return a position from where the search
3705 should be continued.
3706 This may also be a Lisp form, it will be evaluated.
3707 Never set this variable using `setq' or so, because then it will apply
3708 to all future agenda commands. If you do want a global skipping condition,
3709 use the option `org-agenda-skip-function-global' instead.
3710 The correct usage for `org-agenda-skip-function' is to bind it with
3711 `let' to scope it dynamically into the agenda-constructing command.
3712 A good way to set it is through options in `org-agenda-custom-commands'.")
3714 (defun org-agenda-skip ()
3715 "Throw to `:skip' in places that should be skipped.
3716 Also moves point to the end of the skipped region, so that search can
3717 continue from there."
3718 (let ((p (point-at-bol)) to)
3719 (when (org-in-src-block-p t) (throw :skip t))
3720 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3721 (get-text-property p :org-archived)
3722 (org-end-of-subtree t)
3723 (throw :skip t))
3724 (and org-agenda-skip-comment-trees
3725 (get-text-property p :org-comment)
3726 (org-end-of-subtree t)
3727 (throw :skip t))
3728 (if (equal (char-after p) ?#) (throw :skip t))
3729 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3730 (org-agenda-skip-eval org-agenda-skip-function)))
3731 (goto-char to)
3732 (throw :skip t))))
3734 (defun org-agenda-skip-eval (form)
3735 "If FORM is a function or a list, call (or eval) is and return result.
3736 `save-excursion' and `save-match-data' are wrapped around the call, so point
3737 and match data are returned to the previous state no matter what these
3738 functions do."
3739 (let (fp)
3740 (and form
3741 (or (setq fp (functionp form))
3742 (consp form))
3743 (save-excursion
3744 (save-match-data
3745 (if fp
3746 (funcall form)
3747 (eval form)))))))
3749 (defvar org-agenda-markers nil
3750 "List of all currently active markers created by `org-agenda'.")
3751 (defvar org-agenda-last-marker-time (org-float-time)
3752 "Creation time of the last agenda marker.")
3754 (defun org-agenda-new-marker (&optional pos)
3755 "Return a new agenda marker.
3756 Org-mode keeps a list of these markers and resets them when they are
3757 no longer in use."
3758 (let ((m (copy-marker (or pos (point)))))
3759 (setq org-agenda-last-marker-time (org-float-time))
3760 (if org-agenda-buffer
3761 (with-current-buffer org-agenda-buffer
3762 (push m org-agenda-markers))
3763 (push m org-agenda-markers))
3766 (defun org-agenda-reset-markers ()
3767 "Reset markers created by `org-agenda'."
3768 (while org-agenda-markers
3769 (move-marker (pop org-agenda-markers) nil)))
3771 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3772 "Save relative positions of markers in region.
3773 This check for agenda markers in all agenda buffers currently active."
3774 (dolist (buf (buffer-list))
3775 (with-current-buffer buf
3776 (when (eq major-mode 'org-agenda-mode)
3777 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3778 org-agenda-markers)))))
3780 ;;; Entry text mode
3782 (defun org-agenda-entry-text-show-here ()
3783 "Add some text from the entry as context to the current line."
3784 (let (m txt o)
3785 (setq m (org-get-at-bol 'org-hd-marker))
3786 (unless (marker-buffer m)
3787 (error "No marker points to an entry here"))
3788 (setq txt (concat "\n" (org-no-properties
3789 (org-agenda-get-some-entry-text
3790 m org-agenda-entry-text-maxlines " > "))))
3791 (when (string-match "\\S-" txt)
3792 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3793 (overlay-put o 'evaporate t)
3794 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3795 (overlay-put o 'after-string txt))))
3797 (defun org-agenda-entry-text-show ()
3798 "Add entry context for all agenda lines."
3799 (interactive)
3800 (save-excursion
3801 (goto-char (point-max))
3802 (beginning-of-line 1)
3803 (while (not (bobp))
3804 (when (org-get-at-bol 'org-hd-marker)
3805 (org-agenda-entry-text-show-here))
3806 (beginning-of-line 0))))
3808 (defun org-agenda-entry-text-hide ()
3809 "Remove any shown entry context."
3810 (delq nil
3811 (mapcar (lambda (o)
3812 (if (eq (overlay-get o 'org-overlay-type)
3813 'agenda-entry-content)
3814 (progn (delete-overlay o) t)))
3815 (overlays-in (point-min) (point-max)))))
3817 (defun org-agenda-get-day-face (date)
3818 "Return the face DATE should be displayed with."
3819 (or (and (functionp org-agenda-day-face-function)
3820 (funcall org-agenda-day-face-function date))
3821 (cond ((org-agenda-todayp date)
3822 'org-agenda-date-today)
3823 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3824 'org-agenda-date-weekend)
3825 (t 'org-agenda-date))))
3827 ;;; Agenda timeline
3829 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3831 (defun org-timeline (&optional dotodo)
3832 "Show a time-sorted view of the entries in the current org file.
3833 Only entries with a time stamp of today or later will be listed. With
3834 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3835 under the current date.
3836 If the buffer contains an active region, only check the region for
3837 dates."
3838 (interactive "P")
3839 (let* ((dopast t)
3840 (org-agenda-show-log-scoped org-agenda-show-log)
3841 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3842 (current-buffer))))
3843 (date (calendar-current-date))
3844 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3845 (end (if (org-region-active-p) (region-end) (point-max)))
3846 (day-numbers (org-get-all-dates
3847 beg end 'no-ranges
3848 t org-agenda-show-log-scoped ; always include today
3849 org-timeline-show-empty-dates))
3850 (org-deadline-warning-days 0)
3851 (org-agenda-only-exact-dates t)
3852 (today (org-today))
3853 (past t)
3854 args
3855 s e rtn d emptyp)
3856 (setq org-agenda-redo-command
3857 (list 'progn
3858 (list 'org-switch-to-buffer-other-window (current-buffer))
3859 (list 'org-timeline (list 'quote dotodo))))
3860 (if (not dopast)
3861 ;; Remove past dates from the list of dates.
3862 (setq day-numbers (delq nil (mapcar (lambda(x)
3863 (if (>= x today) x nil))
3864 day-numbers))))
3865 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3866 (org-compile-prefix-format 'timeline)
3867 (org-set-sorting-strategy 'timeline)
3868 (if org-agenda-show-log-scoped (push :closed args))
3869 (push :timestamp args)
3870 (push :deadline args)
3871 (push :scheduled args)
3872 (push :sexp args)
3873 (if dotodo (push :todo args))
3874 (insert "Timeline of file " entry "\n")
3875 (add-text-properties (point-min) (point)
3876 (list 'face 'org-agenda-structure))
3877 (org-agenda-mark-header-line (point-min))
3878 (while (setq d (pop day-numbers))
3879 (if (and (listp d) (eq (car d) :omitted))
3880 (progn
3881 (setq s (point))
3882 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3883 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3884 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3885 (if (and (>= d today)
3886 dopast
3887 past)
3888 (progn
3889 (setq past nil)
3890 (insert (make-string 79 ?-) "\n")))
3891 (setq date (calendar-gregorian-from-absolute d))
3892 (setq s (point))
3893 (setq rtn (and (not emptyp)
3894 (apply 'org-agenda-get-day-entries entry
3895 date args)))
3896 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3897 (progn
3898 (insert
3899 (if (stringp org-agenda-format-date)
3900 (format-time-string org-agenda-format-date
3901 (org-time-from-absolute date))
3902 (funcall org-agenda-format-date date))
3903 "\n")
3904 (put-text-property s (1- (point)) 'face
3905 (org-agenda-get-day-face date))
3906 (put-text-property s (1- (point)) 'org-date-line t)
3907 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3908 (if (equal d today)
3909 (put-text-property s (1- (point)) 'org-today t))
3910 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3911 (put-text-property s (1- (point)) 'day d)))))
3912 (goto-char (point-min))
3913 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3914 (point-min)))
3915 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3916 (org-agenda-finalize)
3917 (setq buffer-read-only t)))
3919 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3920 "Return a list of all relevant day numbers from BEG to END buffer positions.
3921 If NO-RANGES is non-nil, include only the start and end dates of a range,
3922 not every single day in the range. If FORCE-TODAY is non-nil, make
3923 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3924 inactive time stamps (those in square brackets) are included.
3925 When EMPTY is non-nil, also include days without any entries."
3926 (let ((re (concat
3927 (if pre-re pre-re "")
3928 (if inactive org-ts-regexp-both org-ts-regexp)))
3929 dates dates1 date day day1 day2 ts1 ts2 pos)
3930 (if force-today
3931 (setq dates (list (org-today))))
3932 (save-excursion
3933 (goto-char beg)
3934 (while (re-search-forward re end t)
3935 (setq day (time-to-days (org-time-string-to-time
3936 (substring (match-string 1) 0 10)
3937 (current-buffer) (match-beginning 0))))
3938 (or (memq day dates) (push day dates)))
3939 (unless no-ranges
3940 (goto-char beg)
3941 (while (re-search-forward org-tr-regexp end t)
3942 (setq pos (match-beginning 0))
3943 (setq ts1 (substring (match-string 1) 0 10)
3944 ts2 (substring (match-string 2) 0 10)
3945 day1 (time-to-days (org-time-string-to-time
3946 ts1 (current-buffer) pos))
3947 day2 (time-to-days (org-time-string-to-time
3948 ts2 (current-buffer) pos)))
3949 (while (< (setq day1 (1+ day1)) day2)
3950 (or (memq day1 dates) (push day1 dates)))))
3951 (setq dates (sort dates '<))
3952 (when empty
3953 (while (setq day (pop dates))
3954 (setq day2 (car dates))
3955 (push day dates1)
3956 (when (and day2 empty)
3957 (if (or (eq empty t)
3958 (and (numberp empty) (<= (- day2 day) empty)))
3959 (while (< (setq day (1+ day)) day2)
3960 (push (list day) dates1))
3961 (push (cons :omitted (- day2 day)) dates1))))
3962 (setq dates (nreverse dates1)))
3963 dates)))
3965 ;;; Agenda Daily/Weekly
3967 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3968 "Start day for the agenda view.
3969 Custom commands can set this variable in the options section.")
3970 (defvar org-starting-day nil) ; local variable in the agenda buffer
3971 (defvar org-arg-loc nil) ; local variable
3973 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3974 "List of types searched for when creating the daily/weekly agenda.
3975 This variable is a list of symbols that controls the types of
3976 items that appear in the daily/weekly agenda. Allowed symbols in this
3977 list are are
3979 :timestamp List items containing a date stamp or date range matching
3980 the selected date. This includes sexp entries in
3981 angular brackets.
3983 :sexp List entries resulting from plain diary-like sexps.
3985 :deadline List deadline due on that date. When the date is today,
3986 also list any deadlines past due, or due within
3987 `org-deadline-warning-days'. `:deadline' must appear before
3988 `:scheduled' if the setting of
3989 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3990 any effect.
3992 :scheduled List all items which are scheduled for the given date.
3993 The diary for *today* also contains items which were
3994 scheduled earlier and are not yet marked DONE.
3996 By default, all four types are turned on.
3998 Never set this variable globally using `setq', because then it
3999 will apply to all future agenda commands. Instead, bind it with
4000 `let' to scope it dynamically into the agenda-constructing
4001 command. A good way to set it is through options in
4002 `org-agenda-custom-commands'. For a more flexible (though
4003 somewhat less efficient) way of determining what is included in
4004 the daily/weekly agenda, see `org-agenda-skip-function'.")
4006 (defvar org-agenda-buffer-tmp-name nil)
4007 ;;;###autoload
4008 (defun org-agenda-list (&optional arg start-day span)
4009 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4010 The view will be for the current day or week, but from the overview buffer
4011 you will be able to go to other days/weeks.
4013 With a numeric prefix argument in an interactive call, the agenda will
4014 span ARG days. Lisp programs should instead specify SPAN to change
4015 the number of days. SPAN defaults to `org-agenda-span'.
4017 START-DAY defaults to TODAY, or to the most recent match for the weekday
4018 given in `org-agenda-start-on-weekday'."
4019 (interactive "P")
4020 (if org-agenda-overriding-arguments
4021 (setq arg (car org-agenda-overriding-arguments)
4022 start-day (nth 1 org-agenda-overriding-arguments)
4023 span (nth 2 org-agenda-overriding-arguments)))
4024 (if (and (integerp arg) (> arg 0))
4025 (setq span arg arg nil))
4026 (catch 'exit
4027 (setq org-agenda-buffer-name
4028 (or org-agenda-buffer-tmp-name
4029 (if org-agenda-sticky
4030 (cond ((and org-keys (stringp org-match))
4031 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4032 (org-keys
4033 (format "*Org Agenda(%s)*" org-keys))
4034 (t "*Org Agenda(a)*")))
4035 org-agenda-buffer-name))
4036 (org-agenda-prepare "Day/Week")
4037 (setq start-day (or start-day org-agenda-start-day))
4038 (if (stringp start-day)
4039 ;; Convert to an absolute day number
4040 (setq start-day (time-to-days (org-read-date nil t start-day))))
4041 (org-compile-prefix-format 'agenda)
4042 (org-set-sorting-strategy 'agenda)
4043 (let* ((span (org-agenda-ndays-to-span
4044 (or span org-agenda-ndays org-agenda-span)))
4045 (today (org-today))
4046 (sd (or start-day today))
4047 (ndays (org-agenda-span-to-ndays span sd))
4048 (org-agenda-start-on-weekday
4049 (if (eq ndays 7)
4050 org-agenda-start-on-weekday))
4051 (thefiles (org-agenda-files nil 'ifmode))
4052 (files thefiles)
4053 (start (if (or (null org-agenda-start-on-weekday)
4054 (< ndays 7))
4056 (let* ((nt (calendar-day-of-week
4057 (calendar-gregorian-from-absolute sd)))
4058 (n1 org-agenda-start-on-weekday)
4059 (d (- nt n1)))
4060 (- sd (+ (if (< d 0) 7 0) d)))))
4061 (day-numbers (list start))
4062 (day-cnt 0)
4063 (inhibit-redisplay (not debug-on-error))
4064 (org-agenda-show-log-scoped org-agenda-show-log)
4065 s e rtn rtnall file date d start-pos end-pos todayp
4066 clocktable-start clocktable-end filter)
4067 (setq org-agenda-redo-command
4068 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4069 (dotimes (n (1- ndays))
4070 (push (1+ (car day-numbers)) day-numbers))
4071 (setq day-numbers (nreverse day-numbers))
4072 (setq clocktable-start (car day-numbers)
4073 clocktable-end (1+ (or (org-last day-numbers) 0)))
4074 (org-set-local 'org-starting-day (car day-numbers))
4075 (org-set-local 'org-arg-loc arg)
4076 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4077 (unless org-agenda-compact-blocks
4078 (let* ((d1 (car day-numbers))
4079 (d2 (org-last day-numbers))
4080 (w1 (org-days-to-iso-week d1))
4081 (w2 (org-days-to-iso-week d2)))
4082 (setq s (point))
4083 (if org-agenda-overriding-header
4084 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4085 nil 'face 'org-agenda-structure) "\n")
4086 (insert (org-agenda-span-name span)
4087 "-agenda"
4088 (if (< (- d2 d1) 350)
4089 (if (= w1 w2)
4090 (format " (W%02d)" w1)
4091 (format " (W%02d-W%02d)" w1 w2))
4093 ":\n")))
4094 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4095 'org-date-line t))
4096 (org-agenda-mark-header-line s))
4097 (while (setq d (pop day-numbers))
4098 (setq date (calendar-gregorian-from-absolute d)
4099 s (point))
4100 (if (or (setq todayp (= d today))
4101 (and (not start-pos) (= d sd)))
4102 (setq start-pos (point))
4103 (if (and start-pos (not end-pos))
4104 (setq end-pos (point))))
4105 (setq files thefiles
4106 rtnall nil)
4107 (while (setq file (pop files))
4108 (catch 'nextfile
4109 (org-check-agenda-file file)
4110 (let ((org-agenda-entry-types org-agenda-entry-types))
4111 (unless org-agenda-include-deadlines
4112 (setq org-agenda-entry-types
4113 (delq :deadline org-agenda-entry-types)))
4114 (cond
4115 ((memq org-agenda-show-log-scoped '(only clockcheck))
4116 (setq rtn (org-agenda-get-day-entries
4117 file date :closed)))
4118 (org-agenda-show-log-scoped
4119 (setq rtn (apply 'org-agenda-get-day-entries
4120 file date
4121 (append '(:closed) org-agenda-entry-types))))
4123 (setq rtn (apply 'org-agenda-get-day-entries
4124 file date
4125 org-agenda-entry-types)))))
4126 (setq rtnall (append rtnall rtn)))) ;; all entries
4127 (if org-agenda-include-diary
4128 (let ((org-agenda-search-headline-for-time t))
4129 (require 'diary-lib)
4130 (setq rtn (org-get-entries-from-diary date))
4131 (setq rtnall (append rtnall rtn))))
4132 (if (or rtnall org-agenda-show-all-dates)
4133 (progn
4134 (setq day-cnt (1+ day-cnt))
4135 (insert
4136 (if (stringp org-agenda-format-date)
4137 (format-time-string org-agenda-format-date
4138 (org-time-from-absolute date))
4139 (funcall org-agenda-format-date date))
4140 "\n")
4141 (put-text-property s (1- (point)) 'face
4142 (org-agenda-get-day-face date))
4143 (put-text-property s (1- (point)) 'org-date-line t)
4144 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4145 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4146 (when todayp
4147 (put-text-property s (1- (point)) 'org-today t))
4148 (setq rtnall
4149 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4150 (if rtnall (insert ;; all entries
4151 (org-agenda-finalize-entries rtnall)
4152 "\n"))
4153 (put-text-property s (1- (point)) 'day d)
4154 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4155 (when (and org-agenda-clockreport-mode clocktable-start)
4156 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4157 ;; the above line is to ensure the restricted range!
4158 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4159 tbl)
4160 (setq p (org-plist-delete p :block))
4161 (setq p (plist-put p :tstart clocktable-start))
4162 (setq p (plist-put p :tend clocktable-end))
4163 (setq p (plist-put p :scope 'agenda))
4164 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4165 (setq filter (or org-agenda-tag-filter-while-redo
4166 (get 'org-agenda-tag-filter :preset-filter))))
4167 (setq p (plist-put p :tags (mapconcat (lambda (x)
4168 (if (string-match "[<>=]" x)
4171 filter ""))))
4172 (setq tbl (apply 'org-clock-get-clocktable p))
4173 (insert tbl)))
4174 (goto-char (point-min))
4175 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4176 (unless (and (pos-visible-in-window-p (point-min))
4177 (pos-visible-in-window-p (point-max)))
4178 (goto-char (1- (point-max)))
4179 (recenter -1)
4180 (if (not (pos-visible-in-window-p (or start-pos 1)))
4181 (progn
4182 (goto-char (or start-pos 1))
4183 (recenter 1))))
4184 (goto-char (or start-pos 1))
4185 (add-text-properties (point-min) (point-max)
4186 `(org-agenda-type agenda
4187 org-last-args (,arg ,start-day ,span)
4188 org-redo-cmd ,org-agenda-redo-command
4189 org-series-cmd ,org-cmd))
4190 (if (eq org-agenda-show-log-scoped 'clockcheck)
4191 (org-agenda-show-clocking-issues))
4192 (org-agenda-finalize)
4193 (setq buffer-read-only t)
4194 (message ""))))
4196 (autoload 'org-agenda-list "org-agenda" "\
4197 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4198 The view will be for the current day or week, but from the overview buffer
4199 you will be able to go to other days/weeks.
4201 With a numeric prefix argument in an interactive call, the agenda will
4202 span ARG days. Lisp programs should instead specify SPAN to change
4203 the number of days. SPAN defaults to `org-agenda-span'.
4205 START-DAY defaults to TODAY, or to the most recent match for the weekday
4206 given in `org-agenda-start-on-weekday'.
4208 \(fn &optional ARG START-DAY SPAN)" t nil)
4210 (defun org-agenda-ndays-to-span (n)
4211 "Return a span symbol for a span of N days, or N if none matches."
4212 (cond ((symbolp n) n)
4213 ((= n 1) 'day)
4214 ((= n 7) 'week)
4215 (t n)))
4217 (defun org-agenda-span-to-ndays (span &optional start-day)
4218 "Return ndays from SPAN, possibly starting at START-DAY."
4219 (cond ((numberp span) span)
4220 ((eq span 'day) 1)
4221 ((eq span 'week) 7)
4222 ((eq span 'month)
4223 (let ((date (calendar-gregorian-from-absolute start-day)))
4224 (calendar-last-day-of-month (car date) (caddr date))))
4225 ((eq span 'year)
4226 (let ((date (calendar-gregorian-from-absolute start-day)))
4227 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4229 (defun org-agenda-span-name (span)
4230 "Return a SPAN name."
4231 (if (null span)
4233 (if (symbolp span)
4234 (capitalize (symbol-name span))
4235 (format "%d days" span))))
4237 ;;; Agenda word search
4239 (defvar org-agenda-search-history nil)
4241 (defvar org-search-syntax-table nil
4242 "Special syntax table for org-mode search.
4243 In this table, we have single quotes not as word constituents, to
4244 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4246 (defvar org-mode-syntax-table) ; From org.el
4247 (defun org-search-syntax-table ()
4248 (unless org-search-syntax-table
4249 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4250 (modify-syntax-entry ?' "." org-search-syntax-table)
4251 (modify-syntax-entry ?` "." org-search-syntax-table))
4252 org-search-syntax-table)
4254 (defvar org-agenda-last-search-view-search-was-boolean nil)
4256 ;;;###autoload
4257 (defun org-search-view (&optional todo-only string edit-at)
4258 "Show all entries that contain a phrase or words or regular expressions.
4260 With optional prefix argument TODO-ONLY, only consider entries that are
4261 TODO entries. The argument STRING can be used to pass a default search
4262 string into this function. If EDIT-AT is non-nil, it means that the
4263 user should get a chance to edit this string, with cursor at position
4264 EDIT-AT.
4266 The search string can be viewed either as a phrase that should be found as
4267 is, or it can be broken into a number of snippets, each of which must match
4268 in a Boolean way to select an entry. The default depends on the variable
4269 `org-agenda-search-view-always-boolean'.
4270 Even if this is turned off (the default) you can always switch to
4271 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4273 The default is a direct search of the whole phrase, where each space in
4274 the search string can expand to an arbitrary amount of whitespace,
4275 including newlines.
4277 If using a Boolean search, the search string is split on whitespace and
4278 each snippet is searched separately, with logical AND to select an entry.
4279 Words prefixed with a minus must *not* occur in the entry. Words without
4280 a prefix or prefixed with a plus must occur in the entry. Matching is
4281 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4282 match whole words, not parts of a word) if
4283 `org-agenda-search-view-force-full-words' is set (default is nil).
4285 Boolean search snippets enclosed by curly braces are interpreted as
4286 regular expressions that must or (when preceded with \"-\") must not
4287 match in the entry. Snippets enclosed into double quotes will be taken
4288 as a whole, to include whitespace.
4290 - If the search string starts with an asterisk, search only in headlines.
4291 - If (possibly after the leading star) the search string starts with an
4292 exclamation mark, this also means to look at TODO entries only, an effect
4293 that can also be achieved with a prefix argument.
4294 - If (possibly after star and exclamation mark) the search string starts
4295 with a colon, this will mean that the (non-regexp) snippets of the
4296 Boolean search must match as full words.
4298 This command searches the agenda files, and in addition the files listed
4299 in `org-agenda-text-search-extra-files'."
4300 (interactive "P")
4301 (if org-agenda-overriding-arguments
4302 (setq todo-only (car org-agenda-overriding-arguments)
4303 string (nth 1 org-agenda-overriding-arguments)
4304 edit-at (nth 2 org-agenda-overriding-arguments)))
4305 (let* ((props (list 'face nil
4306 'done-face 'org-agenda-done
4307 'org-not-done-regexp org-not-done-regexp
4308 'org-todo-regexp org-todo-regexp
4309 'org-complex-heading-regexp org-complex-heading-regexp
4310 'mouse-face 'highlight
4311 'help-echo (format "mouse-2 or RET jump to location")))
4312 (full-words org-agenda-search-view-force-full-words)
4313 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4314 regexp rtn rtnall files file pos
4315 marker category category-pos level tags c neg re boolean
4316 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4317 (unless (and (not edit-at)
4318 (stringp string)
4319 (string-match "\\S-" string))
4320 (setq string (read-string
4321 (if org-agenda-search-view-always-boolean
4322 "[+-]Word/{Regexp} ...: "
4323 "Phrase or [+-]Word/{Regexp} ...: ")
4324 (cond
4325 ((integerp edit-at) (cons string edit-at))
4326 (edit-at string))
4327 'org-agenda-search-history)))
4328 (catch 'exit
4329 (if org-agenda-sticky
4330 (setq org-agenda-buffer-name
4331 (if (stringp string)
4332 (format "*Org Agenda(%s:%s)*"
4333 (or org-keys (or (and todo-only "S") "s")) string)
4334 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4335 (org-agenda-prepare "SEARCH")
4336 (org-compile-prefix-format 'search)
4337 (org-set-sorting-strategy 'search)
4338 (setq org-agenda-redo-command
4339 (list 'org-search-view (if todo-only t nil)
4340 (list 'if 'current-prefix-arg nil string)))
4341 (setq org-agenda-query-string string)
4342 (if (equal (string-to-char string) ?*)
4343 (setq hdl-only t
4344 words (substring string 1))
4345 (setq words string))
4346 (when (equal (string-to-char words) ?!)
4347 (setq todo-only t
4348 words (substring words 1)))
4349 (when (equal (string-to-char words) ?:)
4350 (setq full-words t
4351 words (substring words 1)))
4352 (if (or org-agenda-search-view-always-boolean
4353 (member (string-to-char words) '(?- ?+ ?\{)))
4354 (setq boolean t))
4355 (setq words (org-split-string words))
4356 (let (www w)
4357 (while (setq w (pop words))
4358 (while (and (string-match "\\\\\\'" w) words)
4359 (setq w (concat (substring w 0 -1) " " (pop words))))
4360 (push w www))
4361 (setq words (nreverse www) www nil)
4362 (while (setq w (pop words))
4363 (when (and (string-match "\\`[-+]?{" w)
4364 (not (string-match "}\\'" w)))
4365 (while (and words (not (string-match "}\\'" (car words))))
4366 (setq w (concat w " " (pop words))))
4367 (setq w (concat w " " (pop words))))
4368 (push w www))
4369 (setq words (nreverse www)))
4370 (setq org-agenda-last-search-view-search-was-boolean boolean)
4371 (when boolean
4372 (let (wds w)
4373 (while (setq w (pop words))
4374 (if (or (equal (substring w 0 1) "\"")
4375 (and (> (length w) 1)
4376 (member (substring w 0 1) '("+" "-"))
4377 (equal (substring w 1 2) "\"")))
4378 (while (and words (not (equal (substring w -1) "\"")))
4379 (setq w (concat w " " (pop words)))))
4380 (and (string-match "\\`\\([-+]?\\)\"" w)
4381 (setq w (replace-match "\\1" nil nil w)))
4382 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4383 (push w wds))
4384 (setq words (nreverse wds))))
4385 (if boolean
4386 (mapc (lambda (w)
4387 (setq c (string-to-char w))
4388 (if (equal c ?-)
4389 (setq neg t w (substring w 1))
4390 (if (equal c ?+)
4391 (setq neg nil w (substring w 1))
4392 (setq neg nil)))
4393 (if (string-match "\\`{.*}\\'" w)
4394 (setq re (substring w 1 -1))
4395 (if full-words
4396 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4397 (setq re (regexp-quote (downcase w)))))
4398 (if neg (push re regexps-) (push re regexps+)))
4399 words)
4400 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4401 regexps+))
4402 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4403 (if (not regexps+)
4404 (setq regexp org-outline-regexp-bol)
4405 (setq regexp (pop regexps+))
4406 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4407 regexp))))
4408 (setq files (org-agenda-files nil 'ifmode))
4409 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4410 (pop org-agenda-text-search-extra-files)
4411 (setq files (org-add-archive-files files)))
4412 (setq files (append files org-agenda-text-search-extra-files)
4413 rtnall nil)
4414 (while (setq file (pop files))
4415 (setq ee nil)
4416 (catch 'nextfile
4417 (org-check-agenda-file file)
4418 (setq buffer (if (file-exists-p file)
4419 (org-get-agenda-file-buffer file)
4420 (error "No such file %s" file)))
4421 (if (not buffer)
4422 ;; If file does not exist, make sure an error message is sent
4423 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4424 file))))
4425 (with-current-buffer buffer
4426 (with-syntax-table (org-search-syntax-table)
4427 (unless (derived-mode-p 'org-mode)
4428 (error "Agenda file %s is not in `org-mode'" file))
4429 (let ((case-fold-search t))
4430 (save-excursion
4431 (save-restriction
4432 (if org-agenda-restrict
4433 (narrow-to-region org-agenda-restrict-begin
4434 org-agenda-restrict-end)
4435 (widen))
4436 (goto-char (point-min))
4437 (unless (or (org-at-heading-p)
4438 (outline-next-heading))
4439 (throw 'nextfile t))
4440 (goto-char (max (point-min) (1- (point))))
4441 (while (re-search-forward regexp nil t)
4442 (org-back-to-heading t)
4443 (while (and org-agenda-search-view-max-outline-level
4444 (> (org-reduced-level (org-outline-level))
4445 org-agenda-search-view-max-outline-level)
4446 (forward-line -1)
4447 (outline-back-to-heading t)))
4448 (skip-chars-forward "* ")
4449 (setq beg (point-at-bol)
4450 beg1 (point)
4451 end (progn
4452 (outline-next-heading)
4453 (while (and org-agenda-search-view-max-outline-level
4454 (> (org-reduced-level (org-outline-level))
4455 org-agenda-search-view-max-outline-level)
4456 (forward-line 1)
4457 (outline-next-heading)))
4458 (point)))
4460 (catch :skip
4461 (goto-char beg)
4462 (org-agenda-skip)
4463 (setq str (buffer-substring-no-properties
4464 (point-at-bol)
4465 (if hdl-only (point-at-eol) end)))
4466 (mapc (lambda (wr) (when (string-match wr str)
4467 (goto-char (1- end))
4468 (throw :skip t)))
4469 regexps-)
4470 (mapc (lambda (wr) (unless (string-match wr str)
4471 (goto-char (1- end))
4472 (throw :skip t)))
4473 (if todo-only
4474 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4475 regexps+)
4476 regexps+))
4477 (goto-char beg)
4478 (setq marker (org-agenda-new-marker (point))
4479 category (org-get-category)
4480 level (make-string (org-reduced-level (org-outline-level)) ? )
4481 category-pos (get-text-property (point) 'org-category-position)
4482 tags (org-get-tags-at nil t)
4483 txt (org-agenda-format-item
4485 (buffer-substring-no-properties
4486 beg1 (point-at-eol))
4487 level category tags t))
4488 (org-add-props txt props
4489 'org-marker marker 'org-hd-marker marker
4490 'org-todo-regexp org-todo-regexp
4491 'level level
4492 'org-complex-heading-regexp org-complex-heading-regexp
4493 'priority 1000 'org-category category
4494 'org-category-position category-pos
4495 'type "search")
4496 (push txt ee)
4497 (goto-char (1- end))))))))))
4498 (setq rtn (nreverse ee))
4499 (setq rtnall (append rtnall rtn)))
4500 (if org-agenda-overriding-header
4501 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4502 nil 'face 'org-agenda-structure) "\n")
4503 (insert "Search words: ")
4504 (add-text-properties (point-min) (1- (point))
4505 (list 'face 'org-agenda-structure))
4506 (setq pos (point))
4507 (insert string "\n")
4508 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4509 (setq pos (point))
4510 (unless org-agenda-multi
4511 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4512 (add-text-properties pos (1- (point))
4513 (list 'face 'org-agenda-structure))))
4514 (org-agenda-mark-header-line (point-min))
4515 (when rtnall
4516 (insert (org-agenda-finalize-entries rtnall) "\n"))
4517 (goto-char (point-min))
4518 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4519 (add-text-properties (point-min) (point-max)
4520 `(org-agenda-type search
4521 org-last-args (,todo-only ,string ,edit-at)
4522 org-redo-cmd ,org-agenda-redo-command
4523 org-series-cmd ,org-cmd))
4524 (org-agenda-finalize)
4525 (setq buffer-read-only t))))
4527 (autoload 'org-search-view "org-agenda" "\
4528 Show all entries that contain a phrase or words or regular expressions.
4530 With optional prefix argument TODO-ONLY, only consider entries that are
4531 TODO entries. The argument STRING can be used to pass a default search
4532 string into this function. If EDIT-AT is non-nil, it means that the
4533 user should get a chance to edit this string, with cursor at position
4534 EDIT-AT.
4536 The search string can be viewed either as a phrase that should be found as
4537 is, or it can be broken into a number of snippets, each of which must match
4538 in a Boolean way to select an entry. The default depends on the variable
4539 `org-agenda-search-view-always-boolean'.
4540 Even if this is turned off (the default) you can always switch to
4541 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4543 The default is a direct search of the whole phrase, where each space in
4544 the search string can expand to an arbitrary amount of whitespace,
4545 including newlines.
4547 If using a Boolean search, the search string is split on whitespace and
4548 each snippet is searched separately, with logical AND to select an entry.
4549 Words prefixed with a minus must *not* occur in the entry. Words without
4550 a prefix or prefixed with a plus must occur in the entry. Matching is
4551 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4552 match whole words, not parts of a word) if
4553 `org-agenda-search-view-force-full-words' is set (default is nil).
4555 Boolean search snippets enclosed by curly braces are interpreted as
4556 regular expressions that must or (when preceded with \"-\") must not
4557 match in the entry. Snippets enclosed into double quotes will be taken
4558 as a whole, to include whitespace.
4560 - If the search string starts with an asterisk, search only in headlines.
4561 - If (possibly after the leading star) the search string starts with an
4562 exclamation mark, this also means to look at TODO entries only, an effect
4563 that can also be achieved with a prefix argument.
4564 - If (possibly after star and exclamation mark) the search string starts
4565 with a colon, this will mean that the (non-regexp) snippets of the
4566 Boolean search must match as full words.
4568 This command searches the agenda files, and in addition the files listed
4569 in `org-agenda-text-search-extra-files'.
4571 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4573 ;;; Agenda TODO list
4575 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4576 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4577 (concat
4578 (if (or (equal keywords "ALL") (not keywords))
4579 (propertize "ALL" 'face 'warning)
4580 (mapconcat
4581 (lambda (kw)
4582 (propertize kw 'face (org-get-todo-face kw)))
4583 (org-split-string keywords "|")
4584 "|"))
4585 "\n"))
4587 (defvar org-select-this-todo-keyword nil)
4588 (defvar org-last-arg nil)
4590 ;;;###autoload
4591 (defun org-todo-list (&optional arg)
4592 "Show all (not done) TODO entries from all agenda file in a single list.
4593 The prefix arg can be used to select a specific TODO keyword and limit
4594 the list to these. When using \\[universal-argument], you will be prompted
4595 for a keyword. A numeric prefix directly selects the Nth keyword in
4596 `org-todo-keywords-1'."
4597 (interactive "P")
4598 (if org-agenda-overriding-arguments
4599 (setq arg org-agenda-overriding-arguments))
4600 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4601 (let* ((today (org-today))
4602 (date (calendar-gregorian-from-absolute today))
4603 (kwds org-todo-keywords-for-agenda)
4604 (completion-ignore-case t)
4605 (org-select-this-todo-keyword
4606 (if (stringp arg) arg
4607 (and arg (integerp arg) (> arg 0)
4608 (nth (1- arg) kwds))))
4609 rtn rtnall files file pos)
4610 (when (equal arg '(4))
4611 (setq org-select-this-todo-keyword
4612 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4613 (mapcar 'list kwds) nil nil)))
4614 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4615 (catch 'exit
4616 (if org-agenda-sticky
4617 (setq org-agenda-buffer-name
4618 (if (stringp org-select-this-todo-keyword)
4619 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4620 org-select-this-todo-keyword)
4621 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4622 (org-agenda-prepare "TODO")
4623 (org-compile-prefix-format 'todo)
4624 (org-set-sorting-strategy 'todo)
4625 (setq org-agenda-redo-command
4626 `(org-todo-list (or (and (numberp current-prefix-arg)
4627 current-prefix-arg)
4628 ,org-select-this-todo-keyword
4629 current-prefix-arg ,arg)))
4630 (setq files (org-agenda-files nil 'ifmode)
4631 rtnall nil)
4632 (while (setq file (pop files))
4633 (catch 'nextfile
4634 (org-check-agenda-file file)
4635 (setq rtn (org-agenda-get-day-entries file date :todo))
4636 (setq rtnall (append rtnall rtn))))
4637 (if org-agenda-overriding-header
4638 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4639 nil 'face 'org-agenda-structure) "\n")
4640 (insert "Global list of TODO items of type: ")
4641 (add-text-properties (point-min) (1- (point))
4642 (list 'face 'org-agenda-structure
4643 'short-heading
4644 (concat "ToDo: "
4645 (or org-select-this-todo-keyword "ALL"))))
4646 (org-agenda-mark-header-line (point-min))
4647 (insert (org-agenda-propertize-selected-todo-keywords
4648 org-select-this-todo-keyword))
4649 (setq pos (point))
4650 (unless org-agenda-multi
4651 (insert "Available with `N r': (0)[ALL]")
4652 (let ((n 0) s)
4653 (mapc (lambda (x)
4654 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4655 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4656 (insert "\n "))
4657 (insert " " s))
4658 kwds))
4659 (insert "\n"))
4660 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4661 (org-agenda-mark-header-line (point-min))
4662 (when rtnall
4663 (insert (org-agenda-finalize-entries rtnall) "\n"))
4664 (goto-char (point-min))
4665 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4666 (add-text-properties (point-min) (point-max)
4667 `(org-agenda-type todo
4668 org-last-args ,arg
4669 org-redo-cmd ,org-agenda-redo-command
4670 org-series-cmd ,org-cmd))
4671 (org-agenda-finalize)
4672 (setq buffer-read-only t))))
4674 (autoload 'org-todo-list "org-agenda" "\
4675 Show all (not done) TODO entries from all agenda file in a single list.
4676 The prefix arg can be used to select a specific TODO keyword and limit
4677 the list to these. When using \\[universal-argument], you will be prompted
4678 for a keyword. A numeric prefix directly selects the Nth keyword in
4679 `org-todo-keywords-1'.
4681 \(fn &optional ARG)" t nil)
4683 ;;; Agenda tags match
4685 ;;;###autoload
4686 (defun org-tags-view (&optional todo-only match)
4687 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4688 The prefix arg TODO-ONLY limits the search to TODO entries."
4689 (interactive "P")
4690 (if org-agenda-overriding-arguments
4691 (setq todo-only (car org-agenda-overriding-arguments)
4692 match (nth 1 org-agenda-overriding-arguments)))
4693 (let* ((org-tags-match-list-sublevels
4694 org-tags-match-list-sublevels)
4695 (completion-ignore-case t)
4696 rtn rtnall files file pos matcher
4697 buffer)
4698 (when (and (stringp match) (not (string-match "\\S-" match)))
4699 (setq match nil))
4700 (setq matcher (org-make-tags-matcher match)
4701 match (car matcher) matcher (cdr matcher))
4702 (catch 'exit
4703 (if org-agenda-sticky
4704 (setq org-agenda-buffer-name
4705 (if (stringp match)
4706 (format "*Org Agenda(%s:%s)*"
4707 (or org-keys (or (and todo-only "M") "m")) match)
4708 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4709 (org-agenda-prepare (concat "TAGS " match))
4710 (org-compile-prefix-format 'tags)
4711 (org-set-sorting-strategy 'tags)
4712 (setq org-agenda-query-string match)
4713 (setq org-agenda-redo-command
4714 (list 'org-tags-view `(quote ,todo-only)
4715 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4716 (setq files (org-agenda-files nil 'ifmode)
4717 rtnall nil)
4718 (while (setq file (pop files))
4719 (catch 'nextfile
4720 (org-check-agenda-file file)
4721 (setq buffer (if (file-exists-p file)
4722 (org-get-agenda-file-buffer file)
4723 (error "No such file %s" file)))
4724 (if (not buffer)
4725 ;; If file does not exist, error message to agenda
4726 (setq rtn (list
4727 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4728 rtnall (append rtnall rtn))
4729 (with-current-buffer buffer
4730 (unless (derived-mode-p 'org-mode)
4731 (error "Agenda file %s is not in `org-mode'" file))
4732 (save-excursion
4733 (save-restriction
4734 (if org-agenda-restrict
4735 (narrow-to-region org-agenda-restrict-begin
4736 org-agenda-restrict-end)
4737 (widen))
4738 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4739 (setq rtnall (append rtnall rtn))))))))
4740 (if org-agenda-overriding-header
4741 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4742 nil 'face 'org-agenda-structure) "\n")
4743 (insert "Headlines with TAGS match: ")
4744 (add-text-properties (point-min) (1- (point))
4745 (list 'face 'org-agenda-structure
4746 'short-heading
4747 (concat "Match: " match)))
4748 (setq pos (point))
4749 (insert match "\n")
4750 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4751 (setq pos (point))
4752 (unless org-agenda-multi
4753 (insert "Press `C-u r' to search again with new search string\n"))
4754 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4755 (org-agenda-mark-header-line (point-min))
4756 (when rtnall
4757 (insert (org-agenda-finalize-entries rtnall) "\n"))
4758 (goto-char (point-min))
4759 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4760 (add-text-properties (point-min) (point-max)
4761 `(org-agenda-type tags
4762 org-last-args (,todo-only ,match)
4763 org-redo-cmd ,org-agenda-redo-command
4764 org-series-cmd ,org-cmd))
4765 (org-agenda-finalize)
4766 (setq buffer-read-only t))))
4768 (autoload 'org-tags-view "org-agenda" "\
4769 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4770 The prefix arg TODO-ONLY limits the search to TODO entries.
4772 \(fn &optional TODO-ONLY MATCH)" t nil)
4774 ;;; Agenda Finding stuck projects
4776 (defvar org-agenda-skip-regexp nil
4777 "Regular expression used in skipping subtrees for the agenda.
4778 This is basically a temporary global variable that can be set and then
4779 used by user-defined selections using `org-agenda-skip-function'.")
4781 (defvar org-agenda-overriding-header nil
4782 "When set during agenda, todo and tags searches it replaces the header.
4783 This variable should not be set directly, but custom commands can bind it
4784 in the options section.")
4786 (defun org-agenda-skip-entry-when-regexp-matches ()
4787 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4788 If yes, it returns the end position of this entry, causing agenda commands
4789 to skip the entry but continuing the search in the subtree. This is a
4790 function that can be put into `org-agenda-skip-function' for the duration
4791 of a command."
4792 (let ((end (save-excursion (org-end-of-subtree t)))
4793 skip)
4794 (save-excursion
4795 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4796 (and skip end)))
4798 (defun org-agenda-skip-subtree-when-regexp-matches ()
4799 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4800 If yes, it returns the end position of this tree, causing agenda commands
4801 to skip this subtree. This is a function that can be put into
4802 `org-agenda-skip-function' for the duration of a command."
4803 (let ((end (save-excursion (org-end-of-subtree t)))
4804 skip)
4805 (save-excursion
4806 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4807 (and skip end)))
4809 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4810 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4811 If yes, it returns the end position of the current entry (NOT the tree),
4812 causing agenda commands to skip the entry but continuing the search in
4813 the subtree. This is a function that can be put into
4814 `org-agenda-skip-function' for the duration of a command. An important
4815 use of this function is for the stuck project list."
4816 (let ((end (save-excursion (org-end-of-subtree t)))
4817 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4818 skip)
4819 (save-excursion
4820 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4821 (and skip entry-end)))
4823 (defun org-agenda-skip-entry-if (&rest conditions)
4824 "Skip entry if any of CONDITIONS is true.
4825 See `org-agenda-skip-if' for details."
4826 (org-agenda-skip-if nil conditions))
4828 (defun org-agenda-skip-subtree-if (&rest conditions)
4829 "Skip entry if any of CONDITIONS is true.
4830 See `org-agenda-skip-if' for details."
4831 (org-agenda-skip-if t conditions))
4833 (defun org-agenda-skip-if (subtree conditions)
4834 "Checks current entity for CONDITIONS.
4835 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4836 the entry (i.e. the text before the next heading) is checked.
4838 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4839 from different tests. Valid conditions are:
4841 scheduled Check if there is a scheduled cookie
4842 notscheduled Check if there is no scheduled cookie
4843 deadline Check if there is a deadline
4844 notdeadline Check if there is no deadline
4845 timestamp Check if there is a timestamp (also deadline or scheduled)
4846 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4847 regexp Check if regexp matches
4848 notregexp Check if regexp does not match.
4849 todo Check if TODO keyword matches
4850 nottodo Check if TODO keyword does not match
4852 The regexp is taken from the conditions list, it must come right after
4853 the `regexp' or `notregexp' element.
4855 `todo' and `nottodo' accept as an argument a list of todo
4856 keywords, which may include \"*\" to match any todo keyword.
4858 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4860 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4862 Instead of a list, a keyword class may be given. For example:
4864 (org-agenda-skip-entry-if 'nottodo 'done)
4866 would skip entries that haven't been marked with any of \"DONE\"
4867 keywords. Possible classes are: `todo', `done', `any'.
4869 If any of these conditions is met, this function returns the end point of
4870 the entity, causing the search to continue from there. This is a function
4871 that can be put into `org-agenda-skip-function' for the duration of a command."
4872 (let (beg end m)
4873 (org-back-to-heading t)
4874 (setq beg (point)
4875 end (if subtree
4876 (progn (org-end-of-subtree t) (point))
4877 (progn (outline-next-heading) (1- (point)))))
4878 (goto-char beg)
4879 (and
4881 (and (memq 'scheduled conditions)
4882 (re-search-forward org-scheduled-time-regexp end t))
4883 (and (memq 'notscheduled conditions)
4884 (not (re-search-forward org-scheduled-time-regexp end t)))
4885 (and (memq 'deadline conditions)
4886 (re-search-forward org-deadline-time-regexp end t))
4887 (and (memq 'notdeadline conditions)
4888 (not (re-search-forward org-deadline-time-regexp end t)))
4889 (and (memq 'timestamp conditions)
4890 (re-search-forward org-ts-regexp end t))
4891 (and (memq 'nottimestamp conditions)
4892 (not (re-search-forward org-ts-regexp end t)))
4893 (and (setq m (memq 'regexp conditions))
4894 (stringp (nth 1 m))
4895 (re-search-forward (nth 1 m) end t))
4896 (and (setq m (memq 'notregexp conditions))
4897 (stringp (nth 1 m))
4898 (not (re-search-forward (nth 1 m) end t)))
4899 (and (or
4900 (setq m (memq 'nottodo conditions))
4901 (setq m (memq 'todo-unblocked conditions))
4902 (setq m (memq 'nottodo-unblocked conditions))
4903 (setq m (memq 'todo conditions)))
4904 (org-agenda-skip-if-todo m end)))
4905 end)))
4907 (defun org-agenda-skip-if-todo (args end)
4908 "Helper function for `org-agenda-skip-if', do not use it directly.
4909 ARGS is a list with first element either `todo', `nottodo',
4910 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4911 a list of TODO keywords, or a state symbol `todo' or `done' or
4912 `any'."
4913 (let ((kw (car args))
4914 (arg (cadr args))
4915 todo-wds todo-re)
4916 (setq todo-wds
4917 (org-uniquify
4918 (cond
4919 ((listp arg) ;; list of keywords
4920 (if (member "*" arg)
4921 (mapcar 'substring-no-properties org-todo-keywords-1)
4922 arg))
4923 ((symbolp arg) ;; keyword class name
4924 (cond
4925 ((eq arg 'todo)
4926 (org-delete-all org-done-keywords
4927 (mapcar 'substring-no-properties
4928 org-todo-keywords-1)))
4929 ((eq arg 'done) org-done-keywords)
4930 ((eq arg 'any)
4931 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4932 (setq todo-re
4933 (concat "^\\*+[ \t]+\\<\\("
4934 (mapconcat 'identity todo-wds "\\|")
4935 "\\)\\>"))
4936 (cond
4937 ((eq kw 'todo) (re-search-forward todo-re end t))
4938 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4939 ((eq kw 'todo-unblocked)
4940 (catch 'unblocked
4941 (while (re-search-forward todo-re end t)
4942 (or (org-entry-blocked-p) (throw 'unblocked t)))
4943 nil))
4944 ((eq kw 'nottodo-unblocked)
4945 (catch 'unblocked
4946 (while (re-search-forward todo-re end t)
4947 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4951 ;;;###autoload
4952 (defun org-agenda-list-stuck-projects (&rest ignore)
4953 "Create agenda view for projects that are stuck.
4954 Stuck projects are project that have no next actions. For the definitions
4955 of what a project is and how to check if it stuck, customize the variable
4956 `org-stuck-projects'."
4957 (interactive)
4958 (let* ((org-agenda-skip-function
4959 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4960 ;; We could have used org-agenda-skip-if here.
4961 (org-agenda-overriding-header
4962 (or org-agenda-overriding-header "List of stuck projects: "))
4963 (matcher (nth 0 org-stuck-projects))
4964 (todo (nth 1 org-stuck-projects))
4965 (todo-wds (if (member "*" todo)
4966 (progn
4967 (org-agenda-prepare-buffers (org-agenda-files
4968 nil 'ifmode))
4969 (org-delete-all
4970 org-done-keywords-for-agenda
4971 (copy-sequence org-todo-keywords-for-agenda)))
4972 todo))
4973 (todo-re (concat "^\\*+[ \t]+\\("
4974 (mapconcat 'identity todo-wds "\\|")
4975 "\\)\\>"))
4976 (tags (nth 2 org-stuck-projects))
4977 (tags-re (if (member "*" tags)
4978 (concat org-outline-regexp-bol
4979 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4980 (if tags
4981 (concat org-outline-regexp-bol
4982 ".*:\\("
4983 (mapconcat 'identity tags "\\|")
4984 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4985 (gen-re (nth 3 org-stuck-projects))
4986 (re-list
4987 (delq nil
4988 (list
4989 (if todo todo-re)
4990 (if tags tags-re)
4991 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4992 gen-re)))))
4993 (setq org-agenda-skip-regexp
4994 (if re-list
4995 (mapconcat 'identity re-list "\\|")
4996 (error "No information how to identify unstuck projects")))
4997 (org-tags-view nil matcher)
4998 (with-current-buffer org-agenda-buffer-name
4999 (setq org-agenda-redo-command
5000 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5002 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
5003 Create agenda view for projects that are stuck.
5004 Stuck projects are project that have no next actions. For the definitions
5005 of what a project is and how to check if it stuck, customize the variable
5006 `org-stuck-projects'.
5008 \(fn &rest IGNORE)" t nil)
5010 ;;; Diary integration
5012 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5013 (defvar diary-list-entries-hook)
5014 (defvar diary-time-regexp)
5015 (defun org-get-entries-from-diary (date)
5016 "Get the (Emacs Calendar) diary entries for DATE."
5017 (require 'diary-lib)
5018 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5019 (diary-display-hook '(fancy-diary-display))
5020 (diary-display-function 'fancy-diary-display)
5021 (pop-up-frames nil)
5022 (diary-list-entries-hook
5023 (cons 'org-diary-default-entry diary-list-entries-hook))
5024 (diary-file-name-prefix-function nil) ; turn this feature off
5025 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5026 entries
5027 (org-disable-agenda-to-diary t))
5028 (save-excursion
5029 (save-window-excursion
5030 (funcall (if (fboundp 'diary-list-entries)
5031 'diary-list-entries 'list-diary-entries)
5032 date 1)))
5033 (if (not (get-buffer diary-fancy-buffer))
5034 (setq entries nil)
5035 (with-current-buffer diary-fancy-buffer
5036 (setq buffer-read-only nil)
5037 (if (zerop (buffer-size))
5038 ;; No entries
5039 (setq entries nil)
5040 ;; Omit the date and other unnecessary stuff
5041 (org-agenda-cleanup-fancy-diary)
5042 ;; Add prefix to each line and extend the text properties
5043 (if (zerop (buffer-size))
5044 (setq entries nil)
5045 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5046 (setq entries
5047 (with-temp-buffer
5048 (insert entries) (goto-char (point-min))
5049 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5050 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5051 (replace-match (concat "; " (match-string 1)))))
5052 (buffer-string)))))
5053 (set-buffer-modified-p nil)
5054 (kill-buffer diary-fancy-buffer)))
5055 (when entries
5056 (setq entries (org-split-string entries "\n"))
5057 (setq entries
5058 (mapcar
5059 (lambda (x)
5060 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5061 ;; Extend the text properties to the beginning of the line
5062 (org-add-props x (text-properties-at (1- (length x)) x)
5063 'type "diary" 'date date 'face 'org-agenda-diary))
5064 entries)))))
5066 (defvar org-agenda-cleanup-fancy-diary-hook nil
5067 "Hook run when the fancy diary buffer is cleaned up.")
5069 (defun org-agenda-cleanup-fancy-diary ()
5070 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5071 This gets rid of the date, the underline under the date, and
5072 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5073 date. It also removes lines that contain only whitespace."
5074 (goto-char (point-min))
5075 (if (looking-at ".*?:[ \t]*")
5076 (progn
5077 (replace-match "")
5078 (re-search-forward "\n=+$" nil t)
5079 (replace-match "")
5080 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5081 (re-search-forward "\n=+$" nil t)
5082 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5083 (goto-char (point-min))
5084 (while (re-search-forward "^ +\n" nil t)
5085 (replace-match ""))
5086 (goto-char (point-min))
5087 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5088 (replace-match ""))
5089 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5091 ;; Make sure entries from the diary have the right text properties.
5092 (eval-after-load "diary-lib"
5093 '(if (boundp 'diary-modify-entry-list-string-function)
5094 ;; We can rely on the hook, nothing to do
5096 ;; Hook not available, must use advice to make this work
5097 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5098 "Make the position visible."
5099 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5100 (stringp string)
5101 buffer-file-name)
5102 (setq string (org-modify-diary-entry-string string))))))
5104 (defun org-modify-diary-entry-string (string)
5105 "Add text properties to string, allowing org-mode to act on it."
5106 (org-add-props string nil
5107 'mouse-face 'highlight
5108 'help-echo (if buffer-file-name
5109 (format "mouse-2 or RET jump to diary file %s"
5110 (abbreviate-file-name buffer-file-name))
5112 'org-agenda-diary-link t
5113 'org-marker (org-agenda-new-marker (point-at-bol))))
5115 (defun org-diary-default-entry ()
5116 "Add a dummy entry to the diary.
5117 Needed to avoid empty dates which mess up holiday display."
5118 ;; Catch the error if dealing with the new add-to-diary-alist
5119 (when org-disable-agenda-to-diary
5120 (condition-case nil
5121 (org-add-to-diary-list original-date "Org-mode dummy" "")
5122 (error
5123 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5125 (defun org-add-to-diary-list (&rest args)
5126 (if (fboundp 'diary-add-to-list)
5127 (apply 'diary-add-to-list args)
5128 (apply 'add-to-diary-list args)))
5130 (defvar org-diary-last-run-time nil)
5132 ;;;###autoload
5133 (defun org-diary (&rest args)
5134 "Return diary information from org files.
5135 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5136 It accesses org files and extracts information from those files to be
5137 listed in the diary. The function accepts arguments specifying what
5138 items should be listed. For a list of arguments allowed here, see the
5139 variable `org-agenda-entry-types'.
5141 The call in the diary file should look like this:
5143 &%%(org-diary) ~/path/to/some/orgfile.org
5145 Use a separate line for each org file to check. Or, if you omit the file name,
5146 all files listed in `org-agenda-files' will be checked automatically:
5148 &%%(org-diary)
5150 If you don't give any arguments (as in the example above), the default
5151 arguments (:deadline :scheduled :timestamp :sexp) are used.
5152 So the example above may also be written as
5154 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5156 The function expects the lisp variables `entry' and `date' to be provided
5157 by the caller, because this is how the calendar works. Don't use this
5158 function from a program - use `org-agenda-get-day-entries' instead."
5159 (when (> (- (org-float-time)
5160 org-agenda-last-marker-time)
5162 ;; I am not sure if this works with sticky agendas, because the marker
5163 ;; list is then no longer a global variable.
5164 (org-agenda-reset-markers))
5165 (org-compile-prefix-format 'agenda)
5166 (org-set-sorting-strategy 'agenda)
5167 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5168 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5169 (list entry)
5170 (org-agenda-files t)))
5171 (time (org-float-time))
5172 file rtn results)
5173 (when (or (not org-diary-last-run-time)
5174 (> (- time
5175 org-diary-last-run-time)
5177 (org-agenda-prepare-buffers files))
5178 (setq org-diary-last-run-time time)
5179 ;; If this is called during org-agenda, don't return any entries to
5180 ;; the calendar. Org Agenda will list these entries itself.
5181 (if org-disable-agenda-to-diary (setq files nil))
5182 (while (setq file (pop files))
5183 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5184 (setq results (append results rtn)))
5185 (if results
5186 (concat (org-agenda-finalize-entries results) "\n"))))
5188 (autoload 'org-diary "org-agenda" "\
5189 Return diary information from org files.
5190 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5191 It accesses org files and extracts information from those files to be
5192 listed in the diary. The function accepts arguments specifying what
5193 items should be listed. For a list of arguments allowed here, see the
5194 variable `org-agenda-entry-types'.
5196 The call in the diary file should look like this:
5198 &%%(org-diary) ~/path/to/some/orgfile.org
5200 Use a separate line for each org file to check. Or, if you omit the file name,
5201 all files listed in `org-agenda-files' will be checked automatically:
5203 &%%(org-diary)
5205 If you don't give any arguments (as in the example above), the default
5206 arguments (:deadline :scheduled :timestamp :sexp) are used.
5207 So the example above may also be written as
5209 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5211 The function expects the lisp variables `entry' and `date' to be provided
5212 by the caller, because this is how the calendar works. Don't use this
5213 function from a program - use `org-agenda-get-day-entries' instead.
5215 \(fn &rest ARGS)" nil nil)
5217 ;;; Agenda entry finders
5219 (defun org-agenda-get-day-entries (file date &rest args)
5220 "Does the work for `org-diary' and `org-agenda'.
5221 FILE is the path to a file to be checked for entries. DATE is date like
5222 the one returned by `calendar-current-date'. ARGS are symbols indicating
5223 which kind of entries should be extracted. For details about these, see
5224 the documentation of `org-diary'."
5225 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5226 (let* ((org-startup-folded nil)
5227 (org-startup-align-all-tables nil)
5228 (buffer (if (file-exists-p file)
5229 (org-get-agenda-file-buffer file)
5230 (error "No such file %s" file)))
5231 arg results rtn deadline-results)
5232 (if (not buffer)
5233 ;; If file does not exist, make sure an error message ends up in diary
5234 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5235 (with-current-buffer buffer
5236 (unless (derived-mode-p 'org-mode)
5237 (error "Agenda file %s is not in `org-mode'" file))
5238 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5239 (let ((case-fold-search nil))
5240 (save-excursion
5241 (save-restriction
5242 (if org-agenda-restrict
5243 (narrow-to-region org-agenda-restrict-begin
5244 org-agenda-restrict-end)
5245 (widen))
5246 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5247 (while (setq arg (pop args))
5248 (cond
5249 ((and (eq arg :todo)
5250 (equal date (calendar-gregorian-from-absolute
5251 (org-today))))
5252 (setq rtn (org-agenda-get-todos))
5253 (setq results (append results rtn)))
5254 ((eq arg :timestamp)
5255 (setq rtn (org-agenda-get-blocks))
5256 (setq results (append results rtn))
5257 (setq rtn (org-agenda-get-timestamps deadline-results))
5258 (setq results (append results rtn)))
5259 ((eq arg :sexp)
5260 (setq rtn (org-agenda-get-sexps))
5261 (setq results (append results rtn)))
5262 ((eq arg :scheduled)
5263 (setq rtn (org-agenda-get-scheduled deadline-results))
5264 (setq results (append results rtn)))
5265 ((eq arg :closed)
5266 (setq rtn (org-agenda-get-progress))
5267 (setq results (append results rtn)))
5268 ((eq arg :deadline)
5269 (setq rtn (org-agenda-get-deadlines))
5270 (setq deadline-results (copy-sequence rtn))
5271 (setq results (append results rtn))))))))
5272 results))))
5274 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5275 (defun org-agenda-get-todos ()
5276 "Return the TODO information for agenda display."
5277 (let* ((props (list 'face nil
5278 'done-face 'org-agenda-done
5279 'org-not-done-regexp org-not-done-regexp
5280 'org-todo-regexp org-todo-regexp
5281 'org-complex-heading-regexp org-complex-heading-regexp
5282 'mouse-face 'highlight
5283 'help-echo
5284 (format "mouse-2 or RET jump to org file %s"
5285 (abbreviate-file-name buffer-file-name))))
5286 (regexp (format org-heading-keyword-regexp-format
5287 (cond
5288 ((and org-select-this-todo-keyword
5289 (equal org-select-this-todo-keyword "*"))
5290 org-todo-regexp)
5291 (org-select-this-todo-keyword
5292 (concat "\\("
5293 (mapconcat 'identity
5294 (org-split-string
5295 org-select-this-todo-keyword
5296 "|")
5297 "\\|") "\\)"))
5298 (t org-not-done-regexp))))
5299 marker priority category category-pos level tags todo-state
5300 ee txt beg end)
5301 (goto-char (point-min))
5302 (while (re-search-forward regexp nil t)
5303 (catch :skip
5304 (save-match-data
5305 (beginning-of-line)
5306 (org-agenda-skip)
5307 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5308 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5309 (goto-char (1+ beg))
5310 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5311 (throw :skip nil)))
5312 (goto-char (match-beginning 2))
5313 (setq marker (org-agenda-new-marker (match-beginning 0))
5314 category (org-get-category)
5315 category-pos (get-text-property (point) 'org-category-position)
5316 txt (org-trim
5317 (buffer-substring (match-beginning 2) (match-end 0)))
5318 tags (org-get-tags-at nil t)
5319 level (make-string (org-reduced-level (org-outline-level)) ? )
5320 txt (org-agenda-format-item "" txt level category tags t)
5321 priority (1+ (org-get-priority txt))
5322 todo-state (org-get-todo-state))
5323 (org-add-props txt props
5324 'org-marker marker 'org-hd-marker marker
5325 'priority priority 'org-category category
5326 'level level
5327 'org-category-position category-pos
5328 'type "todo" 'todo-state todo-state)
5329 (push txt ee)
5330 (if org-agenda-todo-list-sublevels
5331 (goto-char (match-end 2))
5332 (org-end-of-subtree 'invisible))))
5333 (nreverse ee)))
5335 (defun org-agenda-todo-custom-ignore-p (time n)
5336 "Check whether timestamp is farther away than n number of days.
5337 This function is invoked if `org-agenda-todo-ignore-deadlines',
5338 `org-agenda-todo-ignore-scheduled' or
5339 `org-agenda-todo-ignore-timestamp' is set to an integer."
5340 (let ((days (org-time-stamp-to-now
5341 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5342 (if (>= n 0)
5343 (>= days n)
5344 (<= days n))))
5346 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5347 (&optional end)
5348 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5349 (when (or org-agenda-todo-ignore-with-date
5350 org-agenda-todo-ignore-scheduled
5351 org-agenda-todo-ignore-deadlines
5352 org-agenda-todo-ignore-timestamp)
5353 (setq end (or end (save-excursion (outline-next-heading) (point))))
5354 (save-excursion
5355 (or (and org-agenda-todo-ignore-with-date
5356 (re-search-forward org-ts-regexp end t))
5357 (and org-agenda-todo-ignore-scheduled
5358 (re-search-forward org-scheduled-time-regexp end t)
5359 (cond
5360 ((eq org-agenda-todo-ignore-scheduled 'future)
5361 (> (org-time-stamp-to-now
5362 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5363 ((eq org-agenda-todo-ignore-scheduled 'past)
5364 (<= (org-time-stamp-to-now
5365 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5366 ((numberp org-agenda-todo-ignore-scheduled)
5367 (org-agenda-todo-custom-ignore-p
5368 (match-string 1) org-agenda-todo-ignore-scheduled))
5369 (t)))
5370 (and org-agenda-todo-ignore-deadlines
5371 (re-search-forward org-deadline-time-regexp end t)
5372 (cond
5373 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5374 ((eq org-agenda-todo-ignore-deadlines 'far)
5375 (not (org-deadline-close (match-string 1))))
5376 ((eq org-agenda-todo-ignore-deadlines 'future)
5377 (> (org-time-stamp-to-now
5378 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5379 ((eq org-agenda-todo-ignore-deadlines 'past)
5380 (<= (org-time-stamp-to-now
5381 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5382 ((numberp org-agenda-todo-ignore-deadlines)
5383 (org-agenda-todo-custom-ignore-p
5384 (match-string 1) org-agenda-todo-ignore-deadlines))
5385 (t (org-deadline-close (match-string 1)))))
5386 (and org-agenda-todo-ignore-timestamp
5387 (let ((buffer (current-buffer))
5388 (regexp
5389 (concat
5390 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5391 (start (point)))
5392 ;; Copy current buffer into a temporary one
5393 (with-temp-buffer
5394 (insert-buffer-substring buffer start end)
5395 (goto-char (point-min))
5396 ;; Delete SCHEDULED and DEADLINE items
5397 (while (re-search-forward regexp end t)
5398 (delete-region (match-beginning 0) (match-end 0)))
5399 (goto-char (point-min))
5400 ;; No search for timestamp left
5401 (when (re-search-forward org-ts-regexp nil t)
5402 (cond
5403 ((eq org-agenda-todo-ignore-timestamp 'future)
5404 (> (org-time-stamp-to-now
5405 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5406 ((eq org-agenda-todo-ignore-timestamp 'past)
5407 (<= (org-time-stamp-to-now
5408 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5409 ((numberp org-agenda-todo-ignore-timestamp)
5410 (org-agenda-todo-custom-ignore-p
5411 (match-string 1) org-agenda-todo-ignore-timestamp))
5412 (t))))))))))
5414 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5415 Do we have a reason to ignore this TODO entry because it has a time stamp?
5417 \(fn &optional END)" nil nil)
5419 (defconst org-agenda-no-heading-message
5420 "No heading for this item in buffer or region.")
5422 (defun org-agenda-get-timestamps (&optional deadline-results)
5423 "Return the date stamp information for agenda display."
5424 (let* ((props (list 'face 'org-agenda-calendar-event
5425 'org-not-done-regexp org-not-done-regexp
5426 'org-todo-regexp org-todo-regexp
5427 'org-complex-heading-regexp org-complex-heading-regexp
5428 'mouse-face 'highlight
5429 'help-echo
5430 (format "mouse-2 or RET jump to org file %s"
5431 (abbreviate-file-name buffer-file-name))))
5432 (d1 (calendar-absolute-from-gregorian date))
5434 (deadline-position-alist
5435 (mapcar (lambda (a) (and (setq mm (get-text-property
5436 0 'org-hd-marker a))
5437 (cons (marker-position mm) a)))
5438 deadline-results))
5439 (remove-re org-ts-regexp)
5440 (regexp
5441 (concat
5442 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5443 (regexp-quote
5444 (substring
5445 (format-time-string
5446 (car org-time-stamp-formats)
5447 (apply 'encode-time ; DATE bound by calendar
5448 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5449 1 11))
5450 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5451 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5452 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5453 donep tmp priority category category-pos level ee txt timestr tags
5454 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5455 (goto-char (point-min))
5456 (while (setq end-of-match (re-search-forward regexp nil t))
5457 (setq b0 (match-beginning 0)
5458 b3 (match-beginning 3) e3 (match-end 3)
5459 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5460 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5461 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5462 (member todo-state
5463 org-agenda-repeating-timestamp-show-all)))
5464 (catch :skip
5465 (and (org-at-date-range-p) (throw :skip nil))
5466 (org-agenda-skip)
5467 (if (and (match-end 1)
5468 (not (= d1 (org-time-string-to-absolute
5469 (match-string 1) d1 nil show-all
5470 (current-buffer) b0))))
5471 (throw :skip nil))
5472 (if (and e3
5473 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5474 (throw :skip nil))
5475 (setq tmp (buffer-substring (max (point-min)
5476 (- b0 org-ds-keyword-length))
5478 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5479 inactivep (= (char-after b0) ?\[)
5480 deadlinep (string-match org-deadline-regexp tmp)
5481 scheduledp (string-match org-scheduled-regexp tmp)
5482 closedp (and org-agenda-include-inactive-timestamps
5483 (string-match org-closed-string tmp))
5484 clockp (and org-agenda-include-inactive-timestamps
5485 (or (string-match org-clock-string tmp)
5486 (string-match "]-+\\'" tmp)))
5487 warntime (get-text-property (point) 'org-appt-warntime)
5488 donep (member todo-state org-done-keywords))
5489 (if (or scheduledp deadlinep closedp clockp
5490 (and donep org-agenda-skip-timestamp-if-done))
5491 (throw :skip t))
5492 (if (string-match ">" timestr)
5493 ;; substring should only run to end of time stamp
5494 (setq timestr (substring timestr 0 (match-end 0))))
5495 (setq marker (org-agenda-new-marker b0)
5496 category (org-get-category b0)
5497 category-pos (get-text-property b0 'org-category-position))
5498 (save-excursion
5499 (if (not (re-search-backward org-outline-regexp-bol nil t))
5500 (setq txt org-agenda-no-heading-message)
5501 (goto-char (match-beginning 0))
5502 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5503 (assoc (point) deadline-position-alist))
5504 (throw :skip nil))
5505 (setq hdmarker (org-agenda-new-marker)
5506 tags (org-get-tags-at nil t)
5507 level (make-string (org-reduced-level (org-outline-level)) ? ))
5508 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5509 (setq head (or (match-string 1) ""))
5510 (setq txt (org-agenda-format-item
5511 (if inactivep org-agenda-inactive-leader nil)
5512 head level category tags timestr
5513 remove-re habitp)))
5514 (setq priority (org-get-priority txt))
5515 (org-add-props txt props 'priority priority
5516 'org-marker marker 'org-hd-marker hdmarker
5517 'org-category category 'date date
5518 'level level
5519 'org-category-position category-pos
5520 'todo-state todo-state
5521 'warntime warntime
5522 'type "timestamp")
5523 (push txt ee))
5524 (if org-agenda-skip-additional-timestamps-same-entry
5525 (outline-next-heading)
5526 (goto-char end-of-match))))
5527 (nreverse ee)))
5529 (defun org-agenda-get-sexps ()
5530 "Return the sexp information for agenda display."
5531 (require 'diary-lib)
5532 (let* ((props (list 'face 'org-agenda-calendar-sexp
5533 'mouse-face 'highlight
5534 'help-echo
5535 (format "mouse-2 or RET jump to org file %s"
5536 (abbreviate-file-name buffer-file-name))))
5537 (regexp "^&?%%(")
5538 marker category extra category-pos level ee txt tags entry
5539 result beg b sexp sexp-entry todo-state warntime)
5540 (goto-char (point-min))
5541 (while (re-search-forward regexp nil t)
5542 (catch :skip
5543 (org-agenda-skip)
5544 (setq beg (match-beginning 0))
5545 (goto-char (1- (match-end 0)))
5546 (setq b (point))
5547 (forward-sexp 1)
5548 (setq sexp (buffer-substring b (point)))
5549 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5550 (org-trim (match-string 1))
5551 ""))
5552 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5553 (when result
5554 (setq marker (org-agenda-new-marker beg)
5555 level (make-string (org-reduced-level (org-outline-level)) ? )
5556 category (org-get-category beg)
5557 category-pos (get-text-property beg 'org-category-position)
5558 tags (save-excursion (org-back-to-heading t) (org-get-tags-at nil t))
5559 todo-state (org-get-todo-state)
5560 warntime (get-text-property (point) 'org-appt-warntime)
5561 extra nil)
5563 (dolist (r (if (stringp result)
5564 (list result)
5565 result)) ;; we expect a list here
5566 (when (and org-agenda-diary-sexp-prefix
5567 (string-match org-agenda-diary-sexp-prefix r))
5568 (setq extra (match-string 0 r)
5569 r (replace-match "" nil nil r)))
5570 (if (string-match "\\S-" r)
5571 (setq txt r)
5572 (setq txt "SEXP entry returned empty string"))
5573 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5574 (org-add-props txt props 'org-marker marker
5575 'org-category category 'date date 'todo-state todo-state
5576 'org-category-position category-pos 'tags tags
5577 'level level
5578 'type "sexp" 'warntime warntime)
5579 (push txt ee)))))
5580 (nreverse ee)))
5582 ;; Calendar sanity: define some functions that are independent of
5583 ;; `calendar-date-style'.
5584 ;; Normally I would like to use ISO format when calling the diary functions,
5585 ;; but to make sure we still have Emacs 22 compatibility we bind
5586 ;; also `european-calendar-style' and use european format
5587 (defun org-anniversary (year month day &optional mark)
5588 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5589 (org-no-warnings
5590 (let ((calendar-date-style 'european) (european-calendar-style t))
5591 (diary-anniversary day month year mark))))
5592 (defun org-cyclic (N year month day &optional mark)
5593 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5594 (org-no-warnings
5595 (let ((calendar-date-style 'european) (european-calendar-style t))
5596 (diary-cyclic N day month year mark))))
5597 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5598 "Like `diary-block', but with fixed (ISO) order of arguments."
5599 (org-no-warnings
5600 (let ((calendar-date-style 'european) (european-calendar-style t))
5601 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5602 (defun org-date (year month day &optional mark)
5603 "Like `diary-date', but with fixed (ISO) order of arguments."
5604 (org-no-warnings
5605 (let ((calendar-date-style 'european) (european-calendar-style t))
5606 (diary-date day month year mark))))
5608 ;; Define the` org-class' function
5609 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5610 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5611 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5612 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5613 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5614 `holidays', then any date that is known by the Emacs calendar to be a
5615 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5616 then those holidays will be skipped."
5617 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5618 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5619 (d (calendar-absolute-from-gregorian date))
5620 (h (when skip-weeks (calendar-check-holidays date))))
5621 (and
5622 (<= date1 d)
5623 (<= d date2)
5624 (= (calendar-day-of-week date) dayname)
5625 (or (not skip-weeks)
5626 (progn
5627 (require 'cal-iso)
5628 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5629 (not (or (and h (memq 'holidays skip-weeks))
5630 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5631 entry)))
5633 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5634 "Like `org-class', but honor `calendar-date-style'.
5635 The order of the first 2 times 3 arguments depends on the variable
5636 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5637 So for American calendars, give this as MONTH DAY YEAR, for European as
5638 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5639 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5640 is any number of ISO weeks in the block period for which the item should
5641 be skipped.
5643 This function is here only for backward compatibility and it is deprecated,
5644 please use `org-class' instead."
5645 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5646 (date2 (org-order-calendar-date-args m2 d2 y2)))
5647 (org-class
5648 (nth 2 date1) (car date1) (nth 1 date1)
5649 (nth 2 date2) (car date2) (nth 1 date2)
5650 dayname skip-weeks)))
5651 (make-obsolete 'org-diary-class 'org-class "")
5653 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5654 (defalias 'org-get-closed 'org-agenda-get-progress)
5655 (defun org-agenda-get-progress ()
5656 "Return the logged TODO entries for agenda display."
5657 (let* ((props (list 'mouse-face 'highlight
5658 'org-not-done-regexp org-not-done-regexp
5659 'org-todo-regexp org-todo-regexp
5660 'org-complex-heading-regexp org-complex-heading-regexp
5661 'help-echo
5662 (format "mouse-2 or RET jump to org file %s"
5663 (abbreviate-file-name buffer-file-name))))
5664 (items (if (consp org-agenda-show-log-scoped)
5665 org-agenda-show-log-scoped
5666 (if (eq org-agenda-show-log-scoped 'clockcheck)
5667 '(clock)
5668 org-agenda-log-mode-items)))
5669 (parts
5670 (delq nil
5671 (list
5672 (if (memq 'closed items) (concat "\\<" org-closed-string))
5673 (if (memq 'clock items) (concat "\\<" org-clock-string))
5674 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5675 (parts-re (if parts (mapconcat 'identity parts "\\|")
5676 (error "`org-agenda-log-mode-items' is empty")))
5677 (regexp (concat
5678 "\\(" parts-re "\\)"
5679 " *\\["
5680 (regexp-quote
5681 (substring
5682 (format-time-string
5683 (car org-time-stamp-formats)
5684 (apply 'encode-time ; DATE bound by calendar
5685 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5686 1 11))))
5687 (org-agenda-search-headline-for-time nil)
5688 marker hdmarker priority category category-pos level tags closedp
5689 statep clockp state ee txt extra timestr rest clocked)
5690 (goto-char (point-min))
5691 (while (re-search-forward regexp nil t)
5692 (catch :skip
5693 (org-agenda-skip)
5694 (setq marker (org-agenda-new-marker (match-beginning 0))
5695 closedp (equal (match-string 1) org-closed-string)
5696 statep (equal (string-to-char (match-string 1)) ?-)
5697 clockp (not (or closedp statep))
5698 state (and statep (match-string 2))
5699 category (org-get-category (match-beginning 0))
5700 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5701 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5702 (when (string-match "\\]" timestr)
5703 ;; substring should only run to end of time stamp
5704 (setq rest (substring timestr (match-end 0))
5705 timestr (substring timestr 0 (match-end 0)))
5706 (if (and (not closedp) (not statep)
5707 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5708 rest))
5709 (progn (setq timestr (concat (substring timestr 0 -1)
5710 "-" (match-string 1 rest) "]"))
5711 (setq clocked (match-string 2 rest)))
5712 (setq clocked "-")))
5713 (save-excursion
5714 (setq extra
5715 (cond
5716 ((not org-agenda-log-mode-add-notes) nil)
5717 (statep
5718 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5719 (match-string 1)))
5720 (clockp
5721 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5722 (match-string 1)))))
5723 (if (not (re-search-backward org-outline-regexp-bol nil t))
5724 (setq txt org-agenda-no-heading-message)
5725 (goto-char (match-beginning 0))
5726 (setq hdmarker (org-agenda-new-marker)
5727 tags (org-get-tags-at nil t)
5728 level (make-string (org-reduced-level (org-outline-level)) ? ))
5729 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5730 (setq txt (match-string 1))
5731 (when extra
5732 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5733 (setq txt (concat (substring txt 0 (match-beginning 1))
5734 " - " extra " " (match-string 2 txt)))
5735 (setq txt (concat txt " - " extra))))
5736 (setq txt (org-agenda-format-item
5737 (cond
5738 (closedp "Closed: ")
5739 (statep (concat "State: (" state ")"))
5740 (t (concat "Clocked: (" clocked ")")))
5741 txt level category tags timestr)))
5742 (setq priority 100000)
5743 (org-add-props txt props
5744 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5745 'priority priority 'org-category category
5746 'org-category-position category-pos
5747 'level level
5748 'type "closed" 'date date
5749 'undone-face 'org-warning 'done-face 'org-agenda-done)
5750 (push txt ee))
5751 (goto-char (point-at-eol))))
5752 (nreverse ee)))
5754 (defun org-agenda-show-clocking-issues ()
5755 "Add overlays, showing issues with clocking.
5756 See also the user option `org-agenda-clock-consistency-checks'."
5757 (interactive)
5758 (let* ((pl org-agenda-clock-consistency-checks)
5759 (re (concat "^[ \t]*"
5760 org-clock-string
5761 "[ \t]+"
5762 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5763 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5764 (tlstart 0.)
5765 (tlend 0.)
5766 (maxtime (org-hh:mm-string-to-minutes
5767 (or (plist-get pl :max-duration) "24:00")))
5768 (mintime (org-hh:mm-string-to-minutes
5769 (or (plist-get pl :min-duration) 0)))
5770 (maxgap (org-hh:mm-string-to-minutes
5771 ;; default 30:00 means never complain
5772 (or (plist-get pl :max-gap) "30:00")))
5773 (gapok (mapcar 'org-hh:mm-string-to-minutes
5774 (plist-get pl :gap-ok-around)))
5775 (def-face (or (plist-get pl :default-face)
5776 '((:background "DarkRed") (:foreground "white"))))
5777 issue face m te ts dt ov)
5778 (goto-char (point-min))
5779 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5780 (setq issue nil face def-face)
5781 (catch 'next
5782 (setq m (org-get-at-bol 'org-marker)
5783 te nil ts nil)
5784 (unless (and m (markerp m))
5785 (setq issue "No valid clock line") (throw 'next t))
5786 (org-with-point-at m
5787 (save-excursion
5788 (goto-char (point-at-bol))
5789 (unless (looking-at re)
5790 (error "No valid Clock line")
5791 (throw 'next t))
5792 (unless (match-end 3)
5793 (setq issue "No end time"
5794 face (or (plist-get pl :no-end-time-face) face))
5795 (throw 'next t))
5796 (setq ts (match-string 1)
5797 te (match-string 3)
5798 ts (org-float-time
5799 (apply 'encode-time (org-parse-time-string ts)))
5800 te (org-float-time
5801 (apply 'encode-time (org-parse-time-string te)))
5802 dt (- te ts))))
5803 (cond
5804 ((> dt (* 60 maxtime))
5805 ;; a very long clocking chunk
5806 (setq issue (format "Clocking interval is very long: %s"
5807 (org-minutes-to-clocksum-string
5808 (floor (/ (float dt) 60.))))
5809 face (or (plist-get pl :long-face) face)))
5810 ((< dt (* 60 mintime))
5811 ;; a very short clocking chunk
5812 (setq issue (format "Clocking interval is very short: %s"
5813 (org-minutes-to-clocksum-string
5814 (floor (/ (float dt) 60.))))
5815 face (or (plist-get pl :short-face) face)))
5816 ((and (> tlend 0) (< ts tlend))
5817 ;; Two clock entries are overlapping
5818 (setq issue (format "Clocking overlap: %d minutes"
5819 (/ (- tlend ts) 60))
5820 face (or (plist-get pl :overlap-face) face)))
5821 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5822 ;; There is a gap, lets see if we need to report it
5823 (unless (org-agenda-check-clock-gap tlend ts gapok)
5824 (setq issue (format "Clocking gap: %d minutes"
5825 (/ (- ts tlend) 60))
5826 face (or (plist-get pl :gap-face) face))))
5827 (t nil)))
5828 (setq tlend (or te tlend) tlstart (or ts tlstart))
5829 (when issue
5830 ;; OK, there was some issue, add an overlay to show the issue
5831 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5832 (overlay-put ov 'before-string
5833 (concat
5834 (org-add-props
5835 (format "%-43s" (concat " " issue))
5837 'face face)
5838 "\n"))
5839 (overlay-put ov 'evaporate t)))))
5841 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5842 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5843 (catch 'exit
5844 (unless ok-list
5845 ;; there are no OK times for gaps...
5846 (throw 'exit nil))
5847 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5848 ;; This is more than 24 hours, so it is OK.
5849 ;; because we have at least one OK time, that must be in the
5850 ;; 24 hour interval.
5851 (throw 'exit t))
5852 ;; We have a shorter gap.
5853 ;; Now we have to get the minute of the day when these times are
5854 (let* ((t1dec (decode-time (seconds-to-time t1)))
5855 (t2dec (decode-time (seconds-to-time t2)))
5856 ;; compute the minute on the day
5857 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5858 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5859 (when (< min2 min1)
5860 ;; if min2 is smaller than min1, this means it is on the next day.
5861 ;; Wrap it to after midnight.
5862 (setq min2 (+ min2 1440)))
5863 ;; Now check if any of the OK times is in the gap
5864 (mapc (lambda (x)
5865 ;; Wrap the time to after midnight if necessary
5866 (if (< x min1) (setq x (+ x 1440)))
5867 ;; Check if in interval
5868 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5869 ok-list)
5870 ;; Nope, this gap is not OK
5871 nil)))
5873 (defun org-agenda-get-deadlines ()
5874 "Return the deadline information for agenda display."
5875 (let* ((props (list 'mouse-face 'highlight
5876 'org-not-done-regexp org-not-done-regexp
5877 'org-todo-regexp org-todo-regexp
5878 'org-complex-heading-regexp org-complex-heading-regexp
5879 'help-echo
5880 (format "mouse-2 or RET jump to org file %s"
5881 (abbreviate-file-name buffer-file-name))))
5882 (regexp org-deadline-time-regexp)
5883 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5884 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5885 d2 diff dfrac wdays pos pos1 category category-pos level
5886 tags suppress-prewarning ee txt head face s todo-state
5887 show-all upcomingp donep timestr warntime)
5888 (goto-char (point-min))
5889 (while (re-search-forward regexp nil t)
5890 (catch :skip
5891 (org-agenda-skip)
5892 (setq s (match-string 1)
5893 txt nil
5894 pos (1- (match-beginning 1))
5895 todo-state (save-match-data (org-get-todo-state))
5896 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5897 (member todo-state
5898 org-agenda-repeating-timestamp-show-all))
5899 d2 (org-time-string-to-absolute
5900 (match-string 1) d1 'past show-all
5901 (current-buffer) pos)
5902 diff (- d2 d1))
5903 (setq suppress-prewarning
5904 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5905 (let ((item (buffer-substring (point-at-bol)
5906 (point-at-eol))))
5907 (save-match-data
5908 (and (string-match
5909 org-scheduled-time-regexp item)
5910 (match-string 1 item)))))))
5911 (cond
5912 ((not ds) nil)
5913 ;; The current item has a scheduled date (in ds), so
5914 ;; evaluate its prewarning lead time.
5915 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5916 ;; Use global prewarning-restart lead time.
5917 org-agenda-skip-deadline-prewarning-if-scheduled)
5918 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5919 'pre-scheduled)
5920 ;; Set prewarning to no earlier than scheduled.
5921 (min (- d2 (org-time-string-to-absolute
5922 ds d1 'past show-all (current-buffer) pos))
5923 org-deadline-warning-days))
5924 ;; Set prewarning to deadline.
5925 (t 0))))
5926 (setq wdays (if suppress-prewarning
5927 (let ((org-deadline-warning-days suppress-prewarning))
5928 (org-get-wdays s))
5929 (org-get-wdays s))
5930 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5931 upcomingp (and todayp (> diff 0)))
5932 ;; When to show a deadline in the calendar:
5933 ;; If the expiration is within wdays warning time.
5934 ;; Past-due deadlines are only shown on the current date
5935 (if (and (or (and (<= diff wdays)
5936 (and todayp (not org-agenda-only-exact-dates)))
5937 (= diff 0)))
5938 (save-excursion
5939 ;; (setq todo-state (org-get-todo-state))
5940 (setq donep (member todo-state org-done-keywords))
5941 (if (and donep
5942 (or org-agenda-skip-deadline-if-done
5943 (not (= diff 0))))
5944 (setq txt nil)
5945 (setq category (org-get-category)
5946 warntime (get-text-property (point) 'org-appt-warntime)
5947 category-pos (get-text-property (point) 'org-category-position))
5948 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5949 (setq txt org-agenda-no-heading-message)
5950 (goto-char (match-end 0))
5951 (setq pos1 (match-beginning 0))
5952 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5953 (setq tags (org-get-tags-at pos1 t))
5954 (setq head (buffer-substring-no-properties
5955 (point)
5956 (progn (skip-chars-forward "^\r\n")
5957 (point))))
5958 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5959 (setq timestr
5960 (concat (substring s (match-beginning 1)) " "))
5961 (setq timestr 'time))
5962 (setq txt (org-agenda-format-item
5963 (if (= diff 0)
5964 (car org-agenda-deadline-leaders)
5965 (if (functionp
5966 (nth 1 org-agenda-deadline-leaders))
5967 (funcall
5968 (nth 1 org-agenda-deadline-leaders)
5969 diff date)
5970 (format (nth 1 org-agenda-deadline-leaders)
5971 diff)))
5972 head level category tags
5973 (if (not (= diff 0)) nil timestr)))))
5974 (when txt
5975 (setq face (org-agenda-deadline-face dfrac))
5976 (org-add-props txt props
5977 'org-marker (org-agenda-new-marker pos)
5978 'warntime warntime
5979 'level level
5980 'org-hd-marker (org-agenda-new-marker pos1)
5981 'priority (+ (- diff)
5982 (org-get-priority txt))
5983 'org-category category
5984 'org-category-position category-pos
5985 'todo-state todo-state
5986 'type (if upcomingp "upcoming-deadline" "deadline")
5987 'date (if upcomingp date d2)
5988 'face (if donep 'org-agenda-done face)
5989 'undone-face face 'done-face 'org-agenda-done)
5990 (push txt ee))))))
5991 (nreverse ee)))
5993 (defun org-agenda-deadline-face (fraction)
5994 "Return the face to displaying a deadline item.
5995 FRACTION is what fraction of the head-warning time has passed."
5996 (let ((faces org-agenda-deadline-faces) f)
5997 (catch 'exit
5998 (while (setq f (pop faces))
5999 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6001 (defun org-agenda-get-scheduled (&optional deadline-results)
6002 "Return the scheduled information for agenda display."
6003 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6004 'org-todo-regexp org-todo-regexp
6005 'org-complex-heading-regexp org-complex-heading-regexp
6006 'done-face 'org-agenda-done
6007 'mouse-face 'highlight
6008 'help-echo
6009 (format "mouse-2 or RET jump to org file %s"
6010 (abbreviate-file-name buffer-file-name))))
6011 (regexp org-scheduled-time-regexp)
6012 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6013 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6015 (deadline-position-alist
6016 (mapcar (lambda (a) (and (setq mm (get-text-property
6017 0 'org-hd-marker a))
6018 (cons (marker-position mm) a)))
6019 deadline-results))
6020 d2 diff pos pos1 category category-pos level tags donep
6021 ee txt head pastschedp todo-state face timestr s habitp show-all
6022 did-habit-check-p warntime)
6023 (goto-char (point-min))
6024 (while (re-search-forward regexp nil t)
6025 (catch :skip
6026 (org-agenda-skip)
6027 (setq s (match-string 1)
6028 txt nil
6029 pos (1- (match-beginning 1))
6030 todo-state (save-match-data (org-get-todo-state))
6031 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6032 (member todo-state
6033 org-agenda-repeating-timestamp-show-all))
6034 d2 (org-time-string-to-absolute
6035 (match-string 1) d1 'past show-all
6036 (current-buffer) pos)
6037 diff (- d2 d1)
6038 warntime (get-text-property (point) 'org-appt-warntime))
6039 (setq pastschedp (and todayp (< diff 0)))
6040 (setq did-habit-check-p nil)
6041 ;; When to show a scheduled item in the calendar:
6042 ;; If it is on or past the date.
6043 (when (or (and (< diff 0)
6044 (< (abs diff) org-scheduled-past-days)
6045 (and todayp (not org-agenda-only-exact-dates)))
6046 (= diff 0)
6047 ;; org-is-habit-p uses org-entry-get, which is expansive
6048 ;; so we go extra mile to only call it once
6049 (and todayp
6050 (boundp 'org-habit-show-all-today)
6051 org-habit-show-all-today
6052 (setq did-habit-check-p t)
6053 (setq habitp (and (functionp 'org-is-habit-p)
6054 (org-is-habit-p)))))
6055 (save-excursion
6056 (setq donep (member todo-state org-done-keywords))
6057 (if (and donep
6058 (or org-agenda-skip-scheduled-if-done
6059 (not (= diff 0))
6060 (and (functionp 'org-is-habit-p)
6061 (org-is-habit-p))))
6062 (setq txt nil)
6063 (setq habitp (if did-habit-check-p habitp
6064 (and (functionp 'org-is-habit-p)
6065 (org-is-habit-p))))
6066 (setq category (org-get-category)
6067 category-pos (get-text-property (point) 'org-category-position))
6068 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6069 (setq txt org-agenda-no-heading-message)
6070 (goto-char (match-end 0))
6071 (setq pos1 (match-beginning 0))
6072 (if habitp
6073 (if (or (not org-habit-show-habits)
6074 (and (not todayp)
6075 (boundp 'org-habit-show-habits-only-for-today)
6076 org-habit-show-habits-only-for-today))
6077 (throw :skip nil))
6078 (if (and
6079 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6080 (and org-agenda-skip-scheduled-if-deadline-is-shown
6081 pastschedp))
6082 (setq mm (assoc pos1 deadline-position-alist)))
6083 (throw :skip nil)))
6084 (setq tags (org-get-tags-at nil t))
6085 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6086 (setq head (buffer-substring-no-properties
6087 (point)
6088 (progn (skip-chars-forward "^\r\n") (point))))
6089 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6090 (setq timestr
6091 (concat (substring s (match-beginning 1)) " "))
6092 (setq timestr 'time))
6093 (setq txt (org-agenda-format-item
6094 (if (= diff 0)
6095 (car org-agenda-scheduled-leaders)
6096 (format (nth 1 org-agenda-scheduled-leaders)
6097 (- 1 diff)))
6098 head level category tags
6099 (if (not (= diff 0)) nil timestr)
6100 nil habitp))))
6101 (when txt
6102 (setq face
6103 (cond
6104 ((and (not habitp) pastschedp)
6105 'org-scheduled-previously)
6106 (todayp 'org-scheduled-today)
6107 (t 'org-scheduled))
6108 habitp (and habitp (org-habit-parse-todo)))
6109 (org-add-props txt props
6110 'undone-face face
6111 'face (if donep 'org-agenda-done face)
6112 'org-marker (org-agenda-new-marker pos)
6113 'org-hd-marker (org-agenda-new-marker pos1)
6114 'type (if pastschedp "past-scheduled" "scheduled")
6115 'date (if pastschedp d2 date)
6116 'warntime warntime
6117 'level level
6118 'priority (if habitp
6119 (org-habit-get-priority habitp)
6120 (+ 94 (- 5 diff) (org-get-priority txt)))
6121 'org-category category
6122 'category-position category-pos
6123 'org-habit-p habitp
6124 'todo-state todo-state)
6125 (push txt ee))))))
6126 (nreverse ee)))
6128 (defun org-agenda-get-blocks ()
6129 "Return the date-range information for agenda display."
6130 (let* ((props (list 'face nil
6131 'org-not-done-regexp org-not-done-regexp
6132 'org-todo-regexp org-todo-regexp
6133 'org-complex-heading-regexp org-complex-heading-regexp
6134 'mouse-face 'highlight
6135 'help-echo
6136 (format "mouse-2 or RET jump to org file %s"
6137 (abbreviate-file-name buffer-file-name))))
6138 (regexp org-tr-regexp)
6139 (d0 (calendar-absolute-from-gregorian date))
6140 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6141 level todo-state tags pos head donep)
6142 (goto-char (point-min))
6143 (while (re-search-forward regexp nil t)
6144 (catch :skip
6145 (org-agenda-skip)
6146 (setq pos (point))
6147 (let ((start-time (match-string 1))
6148 (end-time (match-string 2)))
6149 (setq s1 (match-string 1)
6150 s2 (match-string 2)
6151 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6152 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6153 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6154 ;; Only allow days between the limits, because the normal
6155 ;; date stamps will catch the limits.
6156 (save-excursion
6157 (setq todo-state (org-get-todo-state))
6158 (setq donep (member todo-state org-done-keywords))
6159 (if (and donep org-agenda-skip-timestamp-if-done)
6160 (throw :skip t))
6161 (setq marker (org-agenda-new-marker (point)))
6162 (setq category (org-get-category)
6163 category-pos (get-text-property (point) 'org-category-position))
6164 (if (not (re-search-backward org-outline-regexp-bol nil t))
6165 (setq txt org-agenda-no-heading-message)
6166 (goto-char (match-beginning 0))
6167 (setq hdmarker (org-agenda-new-marker (point)))
6168 (setq tags (org-get-tags-at nil t))
6169 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6170 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6171 (setq head (match-string 1))
6172 (let ((remove-re
6173 (if org-agenda-remove-timeranges-from-blocks
6174 (concat
6175 "<" (regexp-quote s1) ".*?>"
6176 "--"
6177 "<" (regexp-quote s2) ".*?>")
6178 nil)))
6179 (setq txt (org-agenda-format-item
6180 (format
6181 (nth (if (= d1 d2) 0 1)
6182 org-agenda-timerange-leaders)
6183 (1+ (- d0 d1)) (1+ (- d2 d1)))
6184 head level category tags
6185 (cond ((and (= d1 d0) (= d2 d0))
6186 (concat "<" start-time ">--<" end-time ">"))
6187 ((= d1 d0)
6188 (concat "<" start-time ">"))
6189 ((= d2 d0)
6190 (concat "<" end-time ">")))
6191 remove-re))))
6192 (org-add-props txt props
6193 'org-marker marker 'org-hd-marker hdmarker
6194 'type "block" 'date date
6195 'level level
6196 'todo-state todo-state
6197 'priority (org-get-priority txt) 'org-category category
6198 'org-category-position category-pos)
6199 (push txt ee))))
6200 (goto-char pos)))
6201 ;; Sort the entries by expiration date.
6202 (nreverse ee)))
6204 ;;; Agenda presentation and sorting
6206 (defvar org-prefix-has-time nil
6207 "A flag, set by `org-compile-prefix-format'.
6208 The flag is set if the currently compiled format contains a `%t'.")
6209 (defvar org-prefix-has-tag nil
6210 "A flag, set by `org-compile-prefix-format'.
6211 The flag is set if the currently compiled format contains a `%T'.")
6212 (defvar org-prefix-has-effort nil
6213 "A flag, set by `org-compile-prefix-format'.
6214 The flag is set if the currently compiled format contains a `%e'.")
6215 (defvar org-prefix-category-length nil
6216 "Used by `org-compile-prefix-format' to remember the category field width.")
6217 (defvar org-prefix-category-max-length nil
6218 "Used by `org-compile-prefix-format' to remember the category field width.")
6220 (defun org-agenda-get-category-icon (category)
6221 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6222 (dolist (entry org-agenda-category-icon-alist)
6223 (when (org-string-match-p (car entry) category)
6224 (if (listp (cadr entry))
6225 (return (cadr entry))
6226 (return (apply 'create-image (cdr entry)))))))
6228 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6229 remove-re habitp)
6230 "Format TXT to be inserted into the agenda buffer.
6231 In particular, add the prefix and corresponding text properties.
6233 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6234 LEVEL may be a string to replace the `%l' specifier.
6235 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6236 category taken from local variable or file name. It will replace the `%c'
6237 specifier in the format.
6238 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6239 TXT for sorting of this entry, and for the `%t' specifier in the format.
6240 When DOTIME is a string, this string is searched for a time before TXT is.
6241 TAGS can be the tags of the headline.
6242 Any match of REMOVE-RE will be removed from TXT."
6243 ;; We keep the org-prefix-* variable values along with a compiled
6244 ;; formatter, so that multiple agendas existing at the same time do
6245 ;; not step on each other toes.
6247 ;; It was inconvenient to make these variables buffer local in
6248 ;; Agenda buffers, because this function expects to be called with
6249 ;; the buffer where item comes from being current, and not agenda
6250 ;; buffer
6251 (let* ((bindings (car org-prefix-format-compiled))
6252 (formatter (cadr org-prefix-format-compiled)))
6253 (loop for (var value) in bindings
6254 do (set var value))
6255 (save-match-data
6256 ;; Diary entries sometimes have extra whitespace at the beginning
6257 (setq txt (org-trim txt))
6259 ;; Fix the tags part in txt
6260 (setq txt (org-agenda-fix-displayed-tags
6261 txt tags
6262 org-agenda-show-inherited-tags
6263 org-agenda-hide-tags-regexp))
6265 (let* ((category (or category
6266 (if (stringp org-category)
6267 org-category
6268 (and org-category (symbol-name org-category)))
6269 (if buffer-file-name
6270 (file-name-sans-extension
6271 (file-name-nondirectory buffer-file-name))
6272 "")))
6273 (category-icon (org-agenda-get-category-icon category))
6274 (category-icon (if category-icon
6275 (propertize " " 'display category-icon)
6276 ""))
6277 ;; time, tag, effort are needed for the eval of the prefix format
6278 (tag (if tags (nth (1- (length tags)) tags) ""))
6279 time effort neffort
6280 (ts (if dotime (concat
6281 (if (stringp dotime) dotime "")
6282 (and org-agenda-search-headline-for-time txt))))
6283 (time-of-day (and dotime (org-get-time-of-day ts)))
6284 stamp plain s0 s1 s2 rtn srp l
6285 duration thecategory)
6286 (and (derived-mode-p 'org-mode) buffer-file-name
6287 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6288 (when (and dotime time-of-day)
6289 ;; Extract starting and ending time and move them to prefix
6290 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6291 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6292 (setq s0 (match-string 0 ts)
6293 srp (and stamp (match-end 3))
6294 s1 (match-string (if plain 1 2) ts)
6295 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6297 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6298 ;; them, we might want to remove them there to avoid duplication.
6299 ;; The user can turn this off with a variable.
6300 (if (and org-prefix-has-time
6301 org-agenda-remove-times-when-in-prefix (or stamp plain)
6302 (string-match (concat (regexp-quote s0) " *") txt)
6303 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6304 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6305 (= (match-beginning 0) 0)
6307 (setq txt (replace-match "" nil nil txt))))
6308 ;; Normalize the time(s) to 24 hour
6309 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6310 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6312 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6313 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6314 (setq s2
6315 (org-minutes-to-clocksum-string
6316 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6318 ;; Compute the duration
6319 (when s2
6320 (setq duration (- (org-hh:mm-string-to-minutes s2)
6321 (org-hh:mm-string-to-minutes s1)))))
6323 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6324 txt)
6325 ;; Tags are in the string
6326 (if (or (eq org-agenda-remove-tags t)
6327 (and org-agenda-remove-tags
6328 org-prefix-has-tag))
6329 (setq txt (replace-match "" t t txt))
6330 (setq txt (replace-match
6331 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6332 (match-string 2 txt))
6333 t t txt))))
6334 (when (derived-mode-p 'org-mode)
6335 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6336 (when effort
6337 (setq neffort (org-duration-string-to-minutes effort)
6338 effort (setq effort (concat "[" effort "]")))))
6339 ;; prevent erroring out with %e format when there is no effort
6340 (or effort (setq effort ""))
6342 (when remove-re
6343 (while (string-match remove-re txt)
6344 (setq txt (replace-match "" t t txt))))
6346 ;; Set org-heading property on `txt' to mark the start of the
6347 ;; heading.
6348 (add-text-properties 0 (length txt) '(org-heading t) txt)
6350 ;; Prepare the variables needed in the eval of the compiled format
6351 (setq time (cond (s2 (concat
6352 (org-agenda-time-of-day-to-ampm-maybe s1)
6353 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6354 (if org-agenda-timegrid-use-ampm " ")))
6355 (s1 (concat
6356 (org-agenda-time-of-day-to-ampm-maybe s1)
6357 (if org-agenda-timegrid-use-ampm
6358 "........ "
6359 "......")))
6360 (t ""))
6361 extra (or (and (not habitp) extra) "")
6362 category (if (symbolp category) (symbol-name category) category)
6363 thecategory (copy-sequence category)
6364 level (or level ""))
6365 (if (string-match org-bracket-link-regexp category)
6366 (progn
6367 (setq l (if (match-end 3)
6368 (- (match-end 3) (match-beginning 3))
6369 (- (match-end 1) (match-beginning 1))))
6370 (when (< l (or org-prefix-category-length 0))
6371 (setq category (copy-sequence category))
6372 (org-add-props category nil
6373 'extra-space (make-string
6374 (- org-prefix-category-length l 1) ?\ ))))
6375 (if (and org-prefix-category-max-length
6376 (>= (length category) org-prefix-category-max-length))
6377 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6378 ;; Evaluate the compiled format
6379 (setq rtn (concat (eval formatter) txt))
6381 ;; And finally add the text properties
6382 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6383 (org-add-props rtn nil
6384 'org-category (if thecategory (downcase thecategory) category)
6385 'tags (mapcar 'org-downcase-keep-props tags)
6386 'org-highest-priority org-highest-priority
6387 'org-lowest-priority org-lowest-priority
6388 'time-of-day time-of-day
6389 'duration duration
6390 'effort effort
6391 'effort-minutes neffort
6392 'txt txt
6393 'level level
6394 'time time
6395 'extra extra
6396 'format org-prefix-format-compiled
6397 'dotime dotime)))))
6399 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6400 "Remove tags string from TXT, and add a modified list of tags.
6401 The modified list may contain inherited tags, and tags matched by
6402 `org-agenda-hide-tags-regexp' will be removed."
6403 (when (or add-inherited hide-re)
6404 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6405 (setq txt (substring txt 0 (match-beginning 0))))
6406 (setq tags
6407 (delq nil
6408 (mapcar (lambda (tg)
6409 (if (or (and hide-re (string-match hide-re tg))
6410 (and (not add-inherited)
6411 (get-text-property 0 'inherited tg)))
6413 tg))
6414 tags)))
6415 (when tags
6416 (let ((have-i (get-text-property 0 'inherited (car tags)))
6418 (setq txt (concat txt " :"
6419 (mapconcat
6420 (lambda (x)
6421 (setq i (get-text-property 0 'inherited x))
6422 (if (and have-i (not i))
6423 (progn
6424 (setq have-i nil)
6425 (concat ":" x))
6427 tags ":")
6428 (if have-i "::" ":"))))))
6429 txt)
6431 (defun org-downcase-keep-props (s)
6432 (let ((props (text-properties-at 0 s)))
6433 (setq s (downcase s))
6434 (add-text-properties 0 (length s) props s)
6437 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6438 (defvar org-agenda-sorting-strategy-selected nil)
6440 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6441 "Add a time-grid for agenda items which need it.
6443 LIST is the list of agenda items formatted by `org-agenda-list'.
6444 NDAYS is the span of the current agenda view.
6445 TODAYP is `t' when the current agenda view is on today."
6446 (catch 'exit
6447 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6448 ((and todayp (member 'today (car org-agenda-time-grid))))
6449 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6450 ((member 'weekly (car org-agenda-time-grid)))
6451 (t (throw 'exit list)))
6452 (let* ((have (delq nil (mapcar
6453 (lambda (x) (get-text-property 1 'time-of-day x))
6454 list)))
6455 (string (nth 1 org-agenda-time-grid))
6456 (gridtimes (nth 2 org-agenda-time-grid))
6457 (req (car org-agenda-time-grid))
6458 (remove (member 'remove-match req))
6459 new time)
6460 (if (and (member 'require-timed req) (not have))
6461 ;; don't show empty grid
6462 (throw 'exit list))
6463 (while (setq time (pop gridtimes))
6464 (unless (and remove (member time have))
6465 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6466 (push (org-agenda-format-item
6467 nil string nil "" nil
6468 (concat (substring time 0 -2) ":" (substring time -2)))
6469 new)
6470 (put-text-property
6471 2 (length (car new)) 'face 'org-time-grid (car new))))
6472 (when (and todayp org-agenda-show-current-time-in-grid)
6473 (push (org-agenda-format-item
6474 nil org-agenda-current-time-string nil "" nil
6475 (format-time-string "%H:%M "))
6476 new)
6477 (put-text-property
6478 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6480 (if (member 'time-up org-agenda-sorting-strategy-selected)
6481 (append new list)
6482 (append list new)))))
6484 (defun org-compile-prefix-format (key)
6485 "Compile the prefix format into a Lisp form that can be evaluated.
6486 The resulting form and associated variable bindings is returned
6487 and stored in the variable `org-prefix-format-compiled'."
6488 (setq org-prefix-has-time nil
6489 org-prefix-has-tag nil
6490 org-prefix-category-length nil
6491 org-prefix-has-effort nil)
6492 (let ((s (cond
6493 ((stringp org-agenda-prefix-format)
6494 org-agenda-prefix-format)
6495 ((assq key org-agenda-prefix-format)
6496 (cdr (assq key org-agenda-prefix-format)))
6497 (t " %-12:c%?-12t% s")))
6498 (start 0)
6499 varform vars var e c f opt)
6500 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6501 s start)
6502 (setq var (or (cdr (assoc (match-string 4 s)
6503 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6504 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6505 'eval)
6506 c (or (match-string 3 s) "")
6507 opt (match-beginning 1)
6508 start (1+ (match-beginning 0)))
6509 (if (equal var 'time) (setq org-prefix-has-time t))
6510 (if (equal var 'tag) (setq org-prefix-has-tag t))
6511 (if (equal var 'effort) (setq org-prefix-has-effort t))
6512 (setq f (concat "%" (match-string 2 s) "s"))
6513 (when (equal var 'category)
6514 (setq org-prefix-category-length
6515 (floor (abs (string-to-number (match-string 2 s)))))
6516 (setq org-prefix-category-max-length
6517 (let ((x (match-string 2 s)))
6518 (save-match-data
6519 (if (string-match "\\.[0-9]+" x)
6520 (string-to-number (substring (match-string 0 x) 1)))))))
6521 (if (eq var 'eval)
6522 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6523 (if opt
6524 (setq varform
6525 `(if (equal "" ,var)
6527 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6528 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6529 (setq s (replace-match "%s" t nil s))
6530 (push varform vars))
6531 (setq vars (nreverse vars))
6532 (with-current-buffer (or org-agenda-buffer (current-buffer))
6533 (setq org-prefix-format-compiled
6534 (list
6535 `((org-prefix-has-time ,org-prefix-has-time)
6536 (org-prefix-has-tag ,org-prefix-has-tag)
6537 (org-prefix-category-length ,org-prefix-category-length)
6538 (org-prefix-has-effort ,org-prefix-has-effort))
6539 `(format ,s ,@vars))))))
6541 (defun org-set-sorting-strategy (key)
6542 (if (symbolp (car org-agenda-sorting-strategy))
6543 ;; the old format
6544 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6545 (setq org-agenda-sorting-strategy-selected
6546 (or (cdr (assq key org-agenda-sorting-strategy))
6547 (cdr (assq 'agenda org-agenda-sorting-strategy))
6548 '(time-up category-keep priority-down)))))
6550 (defun org-get-time-of-day (s &optional string mod24)
6551 "Check string S for a time of day.
6552 If found, return it as a military time number between 0 and 2400.
6553 If not found, return nil.
6554 The optional STRING argument forces conversion into a 5 character wide string
6555 HH:MM."
6556 (save-match-data
6557 (when
6558 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6559 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6560 (let* ((h (string-to-number (match-string 1 s)))
6561 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6562 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6563 (am-p (equal ampm "am"))
6564 (h1 (cond ((not ampm) h)
6565 ((= h 12) (if am-p 0 12))
6566 (t (+ h (if am-p 0 12)))))
6567 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6568 (mod h1 24) h1))
6569 (t0 (+ (* 100 h2) m))
6570 (t1 (concat (if (>= h1 24) "+" " ")
6571 (if (and org-agenda-time-leading-zero
6572 (< t0 1000)) "0" "")
6573 (if (< t0 100) "0" "")
6574 (if (< t0 10) "0" "")
6575 (int-to-string t0))))
6576 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6578 (defvar org-agenda-before-sorting-filter-function nil
6579 "Function to be applied to agenda items prior to sorting.
6580 Prior to sorting also means just before they are inserted into the agenda.
6582 To aid sorting, you may revisit the original entries and add more text
6583 properties which will later be used by the sorting functions.
6585 The function should take a string argument, an agenda line.
6586 It has access to the text properties in that line, which contain among
6587 other things, the property `org-hd-marker' that points to the entry
6588 where the line comes from. Note that not all lines going into the agenda
6589 have this property, only most.
6591 The function should return the modified string. It is probably best
6592 to ONLY change text properties.
6594 You can also use this function as a filter, by returning nil for lines
6595 you don't want to have in the agenda at all. For this application, you
6596 could bind the variable in the options section of a custom command.")
6598 (defun org-agenda-finalize-entries (list &optional nosort)
6599 "Sort and concatenate the agenda items."
6600 (setq list (mapcar 'org-agenda-highlight-todo list))
6601 (if nosort
6602 list
6603 (when org-agenda-before-sorting-filter-function
6604 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6605 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6607 (defun org-agenda-highlight-todo (x)
6608 (let ((org-done-keywords org-done-keywords-for-agenda)
6609 (case-fold-search nil)
6611 (if (eq x 'line)
6612 (save-excursion
6613 (beginning-of-line 1)
6614 (setq re (org-get-at-bol 'org-todo-regexp))
6615 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6616 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6617 (add-text-properties (match-beginning 0) (match-end 1)
6618 (list 'face (org-get-todo-face 1)))
6619 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6620 (delete-region (match-beginning 1) (1- (match-end 0)))
6621 (goto-char (match-beginning 1))
6622 (insert (format org-agenda-todo-keyword-format s)))))
6623 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6624 (setq re (get-text-property 0 'org-todo-regexp x))
6625 (when (and re
6626 ;; Test `pl' because if there's no heading content,
6627 ;; there's no point matching to highlight. Note
6628 ;; that if we didn't test `pl' first, and there
6629 ;; happened to be no keyword from `org-todo-regexp'
6630 ;; on this heading line, then the `equal' comparison
6631 ;; afterwards would spuriously succeed in the case
6632 ;; where `pl' is nil -- causing an args-out-of-range
6633 ;; error when we try to add text properties to text
6634 ;; that isn't there.
6636 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6637 x pl) pl))
6638 (add-text-properties
6639 (or (match-end 1) (match-end 0)) (match-end 0)
6640 (list 'face (org-get-todo-face (match-string 2 x)))
6642 (when (match-end 1)
6643 (setq x (concat (substring x 0 (match-end 1))
6644 (format org-agenda-todo-keyword-format
6645 (match-string 2 x))
6646 (org-add-props " " (text-properties-at 0 x))
6647 (substring x (match-end 3)))))))
6648 x)))
6650 (defsubst org-cmp-priority (a b)
6651 "Compare the priorities of string A and B."
6652 (let ((pa (or (get-text-property 1 'priority a) 0))
6653 (pb (or (get-text-property 1 'priority b) 0)))
6654 (cond ((> pa pb) +1)
6655 ((< pa pb) -1))))
6657 (defsubst org-cmp-effort (a b)
6658 "Compare the effort values of string A and B."
6659 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6660 (ea (or (get-text-property 1 'effort-minutes a) def))
6661 (eb (or (get-text-property 1 'effort-minutes b) def)))
6662 (cond ((> ea eb) +1)
6663 ((< ea eb) -1))))
6665 (defsubst org-cmp-category (a b)
6666 "Compare the string values of categories of strings A and B."
6667 (let ((ca (or (get-text-property 1 'org-category a) ""))
6668 (cb (or (get-text-property 1 'org-category b) "")))
6669 (cond ((string-lessp ca cb) -1)
6670 ((string-lessp cb ca) +1))))
6672 (defsubst org-cmp-todo-state (a b)
6673 "Compare the todo states of strings A and B."
6674 (let* ((ma (or (get-text-property 1 'org-marker a)
6675 (get-text-property 1 'org-hd-marker a)))
6676 (mb (or (get-text-property 1 'org-marker b)
6677 (get-text-property 1 'org-hd-marker b)))
6678 (fa (and ma (marker-buffer ma)))
6679 (fb (and mb (marker-buffer mb)))
6680 (todo-kwds
6681 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6682 (and fb (with-current-buffer fb org-todo-keywords-1))))
6683 (ta (or (get-text-property 1 'todo-state a) ""))
6684 (tb (or (get-text-property 1 'todo-state b) ""))
6685 (la (- (length (member ta todo-kwds))))
6686 (lb (- (length (member tb todo-kwds))))
6687 (donepa (member ta org-done-keywords-for-agenda))
6688 (donepb (member tb org-done-keywords-for-agenda)))
6689 (cond ((and donepa (not donepb)) -1)
6690 ((and (not donepa) donepb) +1)
6691 ((< la lb) -1)
6692 ((< lb la) +1))))
6694 (defsubst org-cmp-alpha (a b)
6695 "Compare the headlines, alphabetically."
6696 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6697 (plb (text-property-any 0 (length b) 'org-heading t b))
6698 (ta (and pla (substring a pla)))
6699 (tb (and plb (substring b plb))))
6700 (when pla
6701 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6702 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6703 (setq ta (substring ta (match-end 0))))
6704 (setq ta (downcase ta)))
6705 (when plb
6706 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6707 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6708 (setq tb (substring tb (match-end 0))))
6709 (setq tb (downcase tb)))
6710 (cond ((not ta) +1)
6711 ((not tb) -1)
6712 ((string-lessp ta tb) -1)
6713 ((string-lessp tb ta) +1))))
6715 (defsubst org-cmp-tag (a b)
6716 "Compare the string values of the first tags of A and B."
6717 (let ((ta (car (last (get-text-property 1 'tags a))))
6718 (tb (car (last (get-text-property 1 'tags b)))))
6719 (cond ((not ta) +1)
6720 ((not tb) -1)
6721 ((string-lessp ta tb) -1)
6722 ((string-lessp tb ta) +1))))
6724 (defsubst org-cmp-time (a b)
6725 "Compare the time-of-day values of strings A and B."
6726 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6727 (ta (or (get-text-property 1 'time-of-day a) def))
6728 (tb (or (get-text-property 1 'time-of-day b) def)))
6729 (cond ((< ta tb) -1)
6730 ((< tb ta) +1))))
6732 (defsubst org-cmp-habit-p (a b)
6733 "Compare the todo states of strings A and B."
6734 (let ((ha (get-text-property 1 'org-habit-p a))
6735 (hb (get-text-property 1 'org-habit-p b)))
6736 (cond ((and ha (not hb)) -1)
6737 ((and (not ha) hb) +1))))
6739 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6741 (defun org-entries-lessp (a b)
6742 "Predicate for sorting agenda entries."
6743 ;; The following variables will be used when the form is evaluated.
6744 ;; So even though the compiler complains, keep them.
6745 (let* ((ss org-agenda-sorting-strategy-selected)
6746 (time-up (and (org-em 'time-up 'time-down ss)
6747 (org-cmp-time a b)))
6748 (time-down (if time-up (- time-up) nil))
6749 (priority-up (and (org-em 'priority-up 'priority-down ss)
6750 (org-cmp-priority a b)))
6751 (priority-down (if priority-up (- priority-up) nil))
6752 (effort-up (and (org-em 'effort-up 'effort-down ss)
6753 (org-cmp-effort a b)))
6754 (effort-down (if effort-up (- effort-up) nil))
6755 (category-up (and (or (org-em 'category-up 'category-down ss)
6756 (memq 'category-keep ss))
6757 (org-cmp-category a b)))
6758 (category-down (if category-up (- category-up) nil))
6759 (category-keep (if category-up +1 nil))
6760 (tag-up (and (org-em 'tag-up 'tag-down ss)
6761 (org-cmp-tag a b)))
6762 (tag-down (if tag-up (- tag-up) nil))
6763 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6764 (org-cmp-todo-state a b)))
6765 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6766 (habit-up (and (org-em 'habit-up 'habit-down ss)
6767 (org-cmp-habit-p a b)))
6768 (habit-down (if habit-up (- habit-up) nil))
6769 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6770 (org-cmp-alpha a b)))
6771 (alpha-down (if alpha-up (- alpha-up) nil))
6772 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6773 user-defined-up user-defined-down)
6774 (if (and need-user-cmp org-agenda-cmp-user-defined
6775 (functionp org-agenda-cmp-user-defined))
6776 (setq user-defined-up
6777 (funcall org-agenda-cmp-user-defined a b)
6778 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6779 (cdr (assoc
6780 (eval (cons 'or org-agenda-sorting-strategy-selected))
6781 '((-1 . t) (1 . nil) (nil . nil))))))
6783 ;;; Agenda restriction lock
6785 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6786 "Overlay to mark the headline to which agenda commands are restricted.")
6787 (overlay-put org-agenda-restriction-lock-overlay
6788 'face 'org-agenda-restriction-lock)
6789 (overlay-put org-agenda-restriction-lock-overlay
6790 'help-echo "Agendas are currently limited to this subtree.")
6791 (org-detach-overlay org-agenda-restriction-lock-overlay)
6793 (defun org-agenda-set-restriction-lock (&optional type)
6794 "Set restriction lock for agenda, to current subtree or file.
6795 Restriction will be the file if TYPE is `file', or if type is the
6796 universal prefix '(4), or if the cursor is before the first headline
6797 in the file. Otherwise, restriction will be to the current subtree."
6798 (interactive "P")
6799 (and (equal type '(4)) (setq type 'file))
6800 (setq type (cond
6801 (type type)
6802 ((org-at-heading-p) 'subtree)
6803 ((condition-case nil (org-back-to-heading t) (error nil))
6804 'subtree)
6805 (t 'file)))
6806 (if (eq type 'subtree)
6807 (progn
6808 (setq org-agenda-restrict t)
6809 (setq org-agenda-overriding-restriction 'subtree)
6810 (put 'org-agenda-files 'org-restrict
6811 (list (buffer-file-name (buffer-base-buffer))))
6812 (org-back-to-heading t)
6813 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6814 (move-marker org-agenda-restrict-begin (point))
6815 (move-marker org-agenda-restrict-end
6816 (save-excursion (org-end-of-subtree t)))
6817 (message "Locking agenda restriction to subtree"))
6818 (put 'org-agenda-files 'org-restrict
6819 (list (buffer-file-name (buffer-base-buffer))))
6820 (setq org-agenda-restrict nil)
6821 (setq org-agenda-overriding-restriction 'file)
6822 (move-marker org-agenda-restrict-begin nil)
6823 (move-marker org-agenda-restrict-end nil)
6824 (message "Locking agenda restriction to file"))
6825 (setq current-prefix-arg nil)
6826 (org-agenda-maybe-redo))
6828 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6829 "Remove the agenda restriction lock."
6830 (interactive "P")
6831 (org-detach-overlay org-agenda-restriction-lock-overlay)
6832 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6833 (setq org-agenda-overriding-restriction nil)
6834 (setq org-agenda-restrict nil)
6835 (put 'org-agenda-files 'org-restrict nil)
6836 (move-marker org-agenda-restrict-begin nil)
6837 (move-marker org-agenda-restrict-end nil)
6838 (setq current-prefix-arg nil)
6839 (message "Agenda restriction lock removed")
6840 (or noupdate (org-agenda-maybe-redo)))
6842 (defun org-agenda-maybe-redo ()
6843 "If there is any window showing the agenda view, update it."
6844 (let ((w (get-buffer-window org-agenda-buffer-name t))
6845 (w0 (selected-window)))
6846 (when w
6847 (select-window w)
6848 (org-agenda-redo)
6849 (select-window w0)
6850 (if org-agenda-overriding-restriction
6851 (message "Agenda view shifted to new %s restriction"
6852 org-agenda-overriding-restriction)
6853 (message "Agenda restriction lock removed")))))
6855 ;;; Agenda commands
6857 (defun org-agenda-check-type (error &rest types)
6858 "Check if agenda buffer is of allowed type.
6859 If ERROR is non-nil, throw an error, otherwise just return nil.
6860 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6861 (if (not org-agenda-type)
6862 (error "No Org agenda currently displayed")
6863 (if (memq org-agenda-type types)
6865 (if error
6866 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6867 nil))))
6869 (defun org-agenda-Quit ()
6870 "Exit the agenda and kill buffers loaded by `org-agenda'.
6871 Also restore the window configuration."
6872 (interactive)
6873 (if org-agenda-columns-active
6874 (org-columns-quit)
6875 (let ((buf (current-buffer)))
6876 (if (eq org-agenda-window-setup 'other-frame)
6877 (progn
6878 (org-agenda-reset-markers)
6879 (kill-buffer buf)
6880 (org-columns-remove-overlays)
6881 (setq org-agenda-archives-mode nil)
6882 (delete-frame))
6883 (and (not (eq org-agenda-window-setup 'current-window))
6884 (not (one-window-p))
6885 (delete-window))
6886 (org-agenda-reset-markers)
6887 (kill-buffer buf)
6888 (org-columns-remove-overlays)
6889 (setq org-agenda-archives-mode nil)))
6890 ;; Maybe restore the pre-agenda window configuration.
6891 (and org-agenda-restore-windows-after-quit
6892 (not (eq org-agenda-window-setup 'other-frame))
6893 org-agenda-pre-window-conf
6894 (set-window-configuration org-agenda-pre-window-conf)
6895 (setq org-agenda-pre-window-conf nil))))
6897 (defun org-agenda-quit ()
6898 "Exit the agenda and restore the window configuration.
6899 When `org-agenda-sticky' is non-nil, only bury the agenda."
6900 (interactive)
6901 (if (and (eq org-indirect-buffer-display 'other-window)
6902 org-last-indirect-buffer)
6903 (delete-window (get-buffer-window org-last-indirect-buffer)))
6904 (if org-agenda-columns-active
6905 (org-columns-quit)
6906 (if org-agenda-sticky
6907 (let ((buf (current-buffer)))
6908 (if (eq org-agenda-window-setup 'other-frame)
6909 (progn
6910 (delete-frame))
6911 (and (not (eq org-agenda-window-setup 'current-window))
6912 (not (one-window-p))
6913 (delete-window)))
6914 (with-current-buffer buf
6915 (bury-buffer)
6916 ;; Maybe restore the pre-agenda window configuration.
6917 (and org-agenda-restore-windows-after-quit
6918 (not (eq org-agenda-window-setup 'other-frame))
6919 org-agenda-pre-window-conf
6920 (set-window-configuration org-agenda-pre-window-conf)
6921 (setq org-agenda-pre-window-conf nil))))
6922 (org-agenda-Quit))))
6924 (defun org-agenda-exit ()
6925 "Exit the agenda and restore the window configuration.
6926 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
6927 buffers visited directly by the user will not be touched."
6928 (interactive)
6929 (org-release-buffers org-agenda-new-buffers)
6930 (setq org-agenda-new-buffers nil)
6931 (org-agenda-Quit))
6933 (defun org-agenda-kill-all-agenda-buffers ()
6934 "Kill all buffers in `org-agenda-mode'.
6935 This is used when toggling sticky agendas.
6936 You can also explicitly invoke it with `C-c a C-k'."
6937 (interactive)
6938 (let (blist)
6939 (dolist (buf (buffer-list))
6940 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6941 (push buf blist)))
6942 (mapc 'kill-buffer blist)))
6944 (defun org-agenda-execute (arg)
6945 "Execute another agenda command, keeping same window.
6946 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6947 in the agenda."
6948 (interactive "P")
6949 (let ((org-agenda-window-setup 'current-window))
6950 (org-agenda arg)))
6952 (defun org-agenda-redo (&optional all)
6953 "Rebuild possibly ALL agenda view(s) in the current buffer."
6954 (interactive "P")
6955 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6956 (cpa (unless (eq all t) current-prefix-arg))
6957 (org-agenda-doing-sticky-redo org-agenda-sticky)
6958 (org-agenda-sticky nil)
6959 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6960 org-agenda-buffer-name))
6961 (org-agenda-keep-modes t)
6962 (tag-filter org-agenda-tag-filter)
6963 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6964 (top-cat-filter org-agenda-top-category-filter)
6965 (cat-filter org-agenda-category-filter)
6966 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6967 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6968 (cols org-agenda-columns-active)
6969 (line (org-current-line))
6970 (window-line (- line (org-current-line (window-start))))
6971 (lprops (get 'org-agenda-redo-command 'org-lprops))
6972 (redo-cmd (get-text-property p 'org-redo-cmd))
6973 (last-args (get-text-property p 'org-last-args))
6974 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6975 (org-agenda-overriding-cmd-arguments
6976 (unless (eq all t)
6977 (cond ((listp last-args)
6978 (cons (or cpa (car last-args)) (cdr last-args)))
6979 ((stringp last-args)
6980 last-args))))
6981 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6982 (put 'org-agenda-tag-filter :preset-filter nil)
6983 (put 'org-agenda-category-filter :preset-filter nil)
6984 (and cols (org-columns-quit))
6985 (message "Rebuilding agenda buffer...")
6986 (if series-redo-cmd
6987 (eval series-redo-cmd)
6988 (org-let lprops '(eval redo-cmd)))
6989 (setq org-agenda-undo-list nil
6990 org-agenda-pending-undo-list nil)
6991 (message "Rebuilding agenda buffer...done")
6992 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6993 (put 'org-agenda-category-filter :preset-filter cat-preset)
6994 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6995 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6996 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6997 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6998 (org-goto-line line)
6999 (recenter window-line)))
7001 (defvar org-global-tags-completion-table nil)
7002 (defvar org-agenda-filter-form nil)
7003 (defvar org-agenda-filtered-by-category nil)
7005 (defun org-agenda-filter-by-category (strip)
7006 "Keep only those lines in the agenda buffer that have a specific category.
7007 The category is that of the current line."
7008 (interactive "P")
7009 (if (and org-agenda-filtered-by-category
7010 org-agenda-category-filter)
7011 (org-agenda-filter-show-all-cat)
7012 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7013 (if cat (org-agenda-filter-apply
7014 (list (concat (if strip "-" "+") cat)) 'category)
7015 (error "No category at point")))))
7017 (defun org-find-top-category (&optional pos)
7018 (save-excursion
7019 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7020 (if pos (goto-char pos))
7021 ;; Skip up to the topmost parent
7022 (while (ignore-errors (outline-up-heading 1) t))
7023 (ignore-errors
7024 (nth 4 (org-heading-components))))))
7026 (defvar org-agenda-filtered-by-top-category nil)
7028 (defun org-agenda-filter-by-top-category (strip)
7029 "Keep only those lines in the agenda buffer that have a specific category.
7030 The category is that of the current line."
7031 (interactive "P")
7032 (if org-agenda-filtered-by-top-category
7033 (progn
7034 (setq org-agenda-filtered-by-top-category nil
7035 org-agenda-top-category-filter nil)
7036 (org-agenda-filter-show-all-cat))
7037 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7038 (if cat (org-agenda-filter-top-category-apply cat strip)
7039 (error "No top-level category at point")))))
7041 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7042 "Keep only those lines in the agenda buffer that have a specific tag.
7043 The tag is selected with its fast selection letter, as configured.
7044 With prefix argument STRIP, remove all lines that do have the tag.
7045 A lisp caller can specify CHAR. NARROW means that the new tag should be
7046 used to narrow the search - the interactive user can also press `-' or `+'
7047 to switch to narrowing."
7048 (interactive "P")
7049 (let* ((alist org-tag-alist-for-agenda)
7050 (tag-chars (mapconcat
7051 (lambda (x) (if (and (not (symbolp (car x)))
7052 (cdr x))
7053 (char-to-string (cdr x))
7054 ""))
7055 alist ""))
7056 (efforts (org-split-string
7057 (or (cdr (assoc (concat org-effort-property "_ALL")
7058 org-global-properties))
7059 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7060 "")))
7061 (effort-op org-agenda-filter-effort-default-operator)
7062 (effort-prompt "")
7063 (inhibit-read-only t)
7064 (current org-agenda-tag-filter)
7065 maybe-refresh a n tag)
7066 (unless char
7067 (message
7068 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7069 (if narrow "Narrow" "Filter") tag-chars
7070 (if org-agenda-auto-exclude-function "[RET], " ""))
7071 (setq char (read-char-exclusive)))
7072 (when (member char '(?+ ?-))
7073 ;; Narrowing down
7074 (cond ((equal char ?-) (setq strip t narrow t))
7075 ((equal char ?+) (setq strip nil narrow t)))
7076 (message
7077 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7078 (setq char (read-char-exclusive)))
7079 (when (member char '(?< ?> ?= ??))
7080 ;; An effort operator
7081 (setq effort-op (char-to-string char))
7082 (setq alist nil) ; to make sure it will be interpreted as effort.
7083 (unless (equal char ??)
7084 (loop for i from 0 to 9 do
7085 (setq effort-prompt
7086 (concat
7087 effort-prompt " ["
7088 (if (= i 9) "0" (int-to-string (1+ i)))
7089 "]" (nth i efforts))))
7090 (message "Effort%s: %s " effort-op effort-prompt)
7091 (setq char (read-char-exclusive))
7092 (when (or (< char ?0) (> char ?9))
7093 (error "Need 1-9,0 to select effort"))))
7094 (when (equal char ?\t)
7095 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7096 (org-set-local 'org-global-tags-completion-table
7097 (org-global-tags-completion-table)))
7098 (let ((completion-ignore-case t))
7099 (setq tag (org-icompleting-read
7100 "Tag: " org-global-tags-completion-table))))
7101 (cond
7102 ((equal char ?\r)
7103 (org-agenda-filter-show-all-tag)
7104 (when org-agenda-auto-exclude-function
7105 (setq org-agenda-tag-filter '())
7106 (dolist (tag (org-agenda-get-represented-tags))
7107 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7108 (if modifier
7109 (push modifier org-agenda-tag-filter))))
7110 (if (not (null org-agenda-tag-filter))
7111 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7112 (setq maybe-refresh t))
7113 ((equal char ?/)
7114 (org-agenda-filter-show-all-tag)
7115 (when (get 'org-agenda-tag-filter :preset-filter)
7116 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7117 (setq maybe-refresh t))
7118 ((equal char ?. )
7119 (setq org-agenda-tag-filter
7120 (mapcar (lambda(tag) (concat "+" tag))
7121 (org-get-at-bol 'tags)))
7122 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7123 (setq maybe-refresh t))
7124 ((or (equal char ?\ )
7125 (setq a (rassoc char alist))
7126 (and (>= char ?0) (<= char ?9)
7127 (setq n (if (= char ?0) 9 (- char ?0 1))
7128 tag (concat effort-op (nth n efforts))
7129 a (cons tag nil)))
7130 (and (= char ??)
7131 (setq tag "?eff")
7132 a (cons tag nil))
7133 (and tag (setq a (cons tag nil))))
7134 (org-agenda-filter-show-all-tag)
7135 (setq tag (car a))
7136 (setq org-agenda-tag-filter
7137 (cons (concat (if strip "-" "+") tag)
7138 (if narrow current nil)))
7139 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7140 (setq maybe-refresh t))
7141 (t (error "Invalid tag selection character %c" char)))
7142 (when (and maybe-refresh
7143 (eq org-agenda-clockreport-mode 'with-filter))
7144 (org-agenda-redo))))
7146 (defun org-agenda-get-represented-tags ()
7147 "Get a list of all tags currently represented in the agenda."
7148 (let (p tags)
7149 (save-excursion
7150 (goto-char (point-min))
7151 (while (setq p (next-single-property-change (point) 'tags))
7152 (goto-char p)
7153 (mapc (lambda (x) (add-to-list 'tags x))
7154 (get-text-property (point) 'tags))))
7155 tags))
7157 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7158 "Refine the current filter. See `org-agenda-filter-by-tag'."
7159 (interactive "P")
7160 (org-agenda-filter-by-tag strip char 'refine))
7162 (defun org-agenda-filter-make-matcher ()
7163 "Create the form that tests a line for agenda filter."
7164 (let (f f1)
7165 ;; first compute the tag-filter matcher
7166 (dolist (x (delete-dups
7167 (append (get 'org-agenda-tag-filter
7168 :preset-filter) org-agenda-tag-filter)))
7169 (if (member x '("-" "+"))
7170 (setq f1 (if (equal x "-") 'tags '(not tags)))
7171 (if (string-match "[<=>?]" x)
7172 (setq f1 (org-agenda-filter-effort-form x))
7173 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7174 (if (equal (string-to-char x) ?-)
7175 (setq f1 (list 'not f1))))
7176 (push f1 f))
7177 ;; then compute the category-filter matcher
7178 (dolist (x (delete-dups
7179 (append (get 'org-agenda-category-filter
7180 :preset-filter) org-agenda-category-filter)))
7181 (if (equal "-" (substring x 0 1))
7182 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7183 (setq f1 (list 'equal (substring x 1) 'cat)))
7184 (push f1 f))
7185 (cons 'and (nreverse f))))
7187 (defun org-agenda-filter-effort-form (e)
7188 "Return the form to compare the effort of the current line with what E says.
7189 E looks like \"+<2:25\"."
7190 (let (op)
7191 (setq e (substring e 1))
7192 (setq op (string-to-char e) e (substring e 1))
7193 (setq op (cond ((equal op ?<) '<=)
7194 ((equal op ?>) '>=)
7195 ((equal op ??) op)
7196 (t '=)))
7197 (list 'org-agenda-compare-effort (list 'quote op)
7198 (org-duration-string-to-minutes e))))
7200 (defun org-agenda-compare-effort (op value)
7201 "Compare the effort of the current line with VALUE, using OP.
7202 If the line does not have an effort defined, return nil."
7203 (let ((eff (org-get-at-bol 'effort-minutes)))
7204 (if (equal op ??)
7205 (not eff)
7206 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7207 value))))
7209 (defun org-agenda-filter-apply (filter type)
7210 "Set FILTER as the new agenda filter and apply it."
7211 (let (tags cat)
7212 (if (eq type 'tag)
7213 (setq org-agenda-tag-filter filter)
7214 (setq org-agenda-category-filter filter))
7215 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7216 (if (and (eq type 'category)
7217 (not (equal (substring (car filter) 0 1) "-")))
7218 ;; Only set `org-agenda-filtered-by-category' to t
7219 ;; when a unique category is used as the filter
7220 (setq org-agenda-filtered-by-category t))
7221 (org-agenda-set-mode-name)
7222 (save-excursion
7223 (goto-char (point-min))
7224 (while (not (eobp))
7225 (if (org-get-at-bol 'org-marker)
7226 (progn
7227 (setq tags (org-get-at-bol 'tags) ; used in eval
7228 cat (get-text-property (point) 'org-category))
7229 (if (not (eval org-agenda-filter-form))
7230 (org-agenda-filter-hide-line type))
7231 (beginning-of-line 2))
7232 (beginning-of-line 2))))
7233 (if (get-char-property (point) 'invisible)
7234 (ignore-errors (org-agenda-previous-line)))))
7236 (defun org-agenda-filter-top-category-apply (category &optional negative)
7237 "Set FILTER as the new agenda filter and apply it."
7238 (org-agenda-set-mode-name)
7239 (save-excursion
7240 (goto-char (point-min))
7241 (while (not (eobp))
7242 (let* ((pos (org-get-at-bol 'org-hd-marker))
7243 (topcat (and pos (org-find-top-category pos))))
7244 (if (and topcat (funcall (if negative 'identity 'not)
7245 (string= category topcat)))
7246 (org-agenda-filter-hide-line 'category)))
7247 (beginning-of-line 2)))
7248 (if (get-char-property (point) 'invisible)
7249 (org-agenda-previous-line))
7250 (setq org-agenda-top-category-filter category
7251 org-agenda-filtered-by-top-category t))
7253 (defun org-agenda-filter-hide-line (type)
7254 (let (ov)
7255 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7256 (point-at-eol)))
7257 (overlay-put ov 'invisible t)
7258 (overlay-put ov 'type type)
7259 (if (eq type 'tag)
7260 (push ov org-agenda-tag-filter-overlays)
7261 (push ov org-agenda-cat-filter-overlays))))
7263 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7264 (setq pos (or pos (point)))
7265 (save-excursion
7266 (dolist (ov (overlays-at pos))
7267 (when (and (overlay-get ov 'invisible)
7268 (eq (overlay-get ov 'type) 'tag))
7269 (goto-char pos)
7270 (if (< (overlay-start ov) (point-at-eol))
7271 (move-overlay ov (point-at-eol)
7272 (overlay-end ov)))))))
7274 (defun org-agenda-filter-show-all-tag nil
7275 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7276 (setq org-agenda-tag-filter-overlays nil
7277 org-agenda-tag-filter nil
7278 org-agenda-filter-form nil)
7279 (org-agenda-set-mode-name))
7281 (defun org-agenda-filter-show-all-cat nil
7282 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7283 (setq org-agenda-cat-filter-overlays nil
7284 org-agenda-filtered-by-category nil
7285 org-agenda-category-filter nil
7286 org-agenda-filter-form nil)
7287 (org-agenda-set-mode-name))
7289 (defun org-agenda-manipulate-query-add ()
7290 "Manipulate the query by adding a search term with positive selection.
7291 Positive selection means the term must be matched for selection of an entry."
7292 (interactive)
7293 (org-agenda-manipulate-query ?\[))
7294 (defun org-agenda-manipulate-query-subtract ()
7295 "Manipulate the query by adding a search term with negative selection.
7296 Negative selection means term must not be matched for selection of an entry."
7297 (interactive)
7298 (org-agenda-manipulate-query ?\]))
7299 (defun org-agenda-manipulate-query-add-re ()
7300 "Manipulate the query by adding a search regexp with positive selection.
7301 Positive selection means the regexp must match for selection of an entry."
7302 (interactive)
7303 (org-agenda-manipulate-query ?\{))
7304 (defun org-agenda-manipulate-query-subtract-re ()
7305 "Manipulate the query by adding a search regexp with negative selection.
7306 Negative selection means regexp must not match for selection of an entry."
7307 (interactive)
7308 (org-agenda-manipulate-query ?\}))
7309 (defun org-agenda-manipulate-query (char)
7310 (cond
7311 ((memq org-agenda-type '(timeline agenda))
7312 (let ((org-agenda-include-inactive-timestamps t))
7313 (org-agenda-redo))
7314 (message "Display now includes inactive timestamps as well"))
7315 ((eq org-agenda-type 'search)
7316 (org-add-to-string
7317 'org-agenda-query-string
7318 (if org-agenda-last-search-view-search-was-boolean
7319 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7320 (?\{ . " +{}") (?\} . " -{}"))))
7321 " "))
7322 (setq org-agenda-redo-command
7323 (list 'org-search-view
7324 (car (get-text-property (min (1- (point-max)) (point))
7325 'org-last-args))
7326 org-agenda-query-string
7327 (+ (length org-agenda-query-string)
7328 (if (member char '(?\{ ?\})) 0 1))))
7329 (set-register org-agenda-query-register org-agenda-query-string)
7330 (let ((org-agenda-overriding-arguments
7331 (cdr org-agenda-redo-command)))
7332 (org-agenda-redo)))
7333 (t (error "Cannot manipulate query for %s-type agenda buffers"
7334 org-agenda-type))))
7336 (defun org-add-to-string (var string)
7337 (set var (concat (symbol-value var) string)))
7339 (defun org-agenda-goto-date (span)
7340 "Jump to DATE in agenda."
7341 (interactive "P")
7342 (let* ((org-read-date-prefer-future
7343 (eval org-agenda-jump-prefer-future))
7344 (date (org-read-date))
7345 (org-agenda-sticky-orig org-agenda-sticky)
7346 (org-agenda-buffer-tmp-name (buffer-name))
7347 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7348 (0-arg (or current-prefix-arg (car args)))
7349 (2-arg (nth 2 args))
7350 (newcmd (list 'org-agenda-list 0-arg date
7351 (org-agenda-span-to-ndays 2-arg)))
7352 (newargs (cdr newcmd))
7353 (inhibit-read-only t)
7354 org-agenda-sticky)
7355 (if (not (org-agenda-check-type t 'agenda))
7356 (error "Not available in non-agenda blocks")
7357 (add-text-properties (point-min) (point-max)
7358 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7359 (org-agenda-redo)
7360 (setq org-agenda-sticky org-agenda-sticky-orig
7361 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7363 (defun org-agenda-goto-today ()
7364 "Go to today."
7365 (interactive)
7366 (org-agenda-check-type t 'timeline 'agenda)
7367 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7368 (curspan (nth 2 args))
7369 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7370 (cond
7371 (tdpos (goto-char tdpos))
7372 ((eq org-agenda-type 'agenda)
7373 (let* ((sd (org-agenda-compute-starting-span
7374 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7375 (org-agenda-overriding-arguments args))
7376 (setf (nth 1 org-agenda-overriding-arguments) sd)
7377 (org-agenda-redo)
7378 (org-agenda-find-same-or-today-or-agenda)))
7379 (t (error "Cannot find today")))))
7381 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7382 (goto-char
7383 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7384 (text-property-any (point-min) (point-max) 'org-today t)
7385 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7386 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7387 (org-agenda-goto-block-beginning))
7388 (point-min))))
7390 (defun org-agenda-goto-block-beginning ()
7391 "Go the agenda block beginning."
7392 (interactive)
7393 (if (not (derived-mode-p 'org-agenda-mode))
7394 (error "Cannot execute this command outside of org-agenda-mode buffers")
7395 (let (dest)
7396 (save-excursion
7397 (unless (looking-at "\\'")
7398 (forward-char))
7399 (let* ((prop 'org-agenda-structural-header)
7400 (p (previous-single-property-change (point) prop))
7401 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7402 (1- (point))) prop)))
7403 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7404 (if (not dest)
7405 (error "Cannot find the beginning of the blog")
7406 (goto-char dest)
7407 (move-beginning-of-line 1)))))
7409 (defun org-agenda-later (arg)
7410 "Go forward in time by the current span.
7411 With prefix ARG, go forward that many times the current span."
7412 (interactive "p")
7413 (org-agenda-check-type t 'agenda)
7414 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7415 (span (or (nth 2 args) org-agenda-current-span))
7416 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7417 (greg (calendar-gregorian-from-absolute sd))
7418 (cnt (org-get-at-bol 'org-day-cnt))
7419 greg2)
7420 (cond
7421 ((numberp span)
7422 (setq sd (+ (* span arg) sd)))
7423 ((eq span 'day)
7424 (setq sd (+ arg sd)))
7425 ((eq span 'week)
7426 (setq sd (+ (* 7 arg) sd)))
7427 ((eq span 'month)
7428 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7429 sd (calendar-absolute-from-gregorian greg2))
7430 (setcar greg2 (1+ (car greg2))))
7431 ((eq span 'year)
7432 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7433 sd (calendar-absolute-from-gregorian greg2))
7434 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7436 (setq sd (+ (* span arg) sd))))
7437 (let ((org-agenda-overriding-cmd
7438 ;; `cmd' may have been set by `org-agenda-run-series' which
7439 ;; uses `org-agenda-overriding-cmd' to decide whether
7440 ;; overriding is allowed for `cmd'
7441 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7442 (org-agenda-overriding-arguments
7443 (list (car args) sd span)))
7444 (org-agenda-redo)
7445 (org-agenda-find-same-or-today-or-agenda cnt))))
7447 (defun org-agenda-earlier (arg)
7448 "Go backward in time by the current span.
7449 With prefix ARG, go backward that many times the current span."
7450 (interactive "p")
7451 (org-agenda-later (- arg)))
7453 (defun org-agenda-view-mode-dispatch ()
7454 "Call one of the view mode commands."
7455 (interactive)
7456 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7457 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7458 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7459 (let ((a (read-char-exclusive)))
7460 (case a
7461 (?\ (call-interactively 'org-agenda-reset-view))
7462 (?d (call-interactively 'org-agenda-day-view))
7463 (?w (call-interactively 'org-agenda-week-view))
7464 (?m (call-interactively 'org-agenda-month-view))
7465 (?y (call-interactively 'org-agenda-year-view))
7466 (?l (call-interactively 'org-agenda-log-mode))
7467 (?L (org-agenda-log-mode '(4)))
7468 (?c (org-agenda-log-mode 'clockcheck))
7469 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7470 (?a (call-interactively 'org-agenda-archives-mode))
7471 (?A (org-agenda-archives-mode 'files))
7472 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7473 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7474 (?G (call-interactively 'org-agenda-toggle-time-grid))
7475 (?D (call-interactively 'org-agenda-toggle-diary))
7476 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7477 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7478 (org-agenda-check-type t 'timeline 'agenda)
7479 (org-agenda-redo))
7480 (message "Display now includes inactive timestamps as well"))
7481 (?q (message "Abort"))
7482 (otherwise (error "Invalid key" )))))
7484 (defun org-agenda-reset-view ()
7485 "Switch to default view for agenda."
7486 (interactive)
7487 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7488 (defun org-agenda-day-view (&optional day-of-year)
7489 "Switch to daily view for agenda.
7490 With argument DAY-OF-YEAR, switch to that day of the year."
7491 (interactive "P")
7492 (org-agenda-change-time-span 'day day-of-year))
7493 (defun org-agenda-week-view (&optional iso-week)
7494 "Switch to daily view for agenda.
7495 With argument ISO-WEEK, switch to the corresponding ISO week.
7496 If ISO-WEEK has more then 2 digits, only the last two encode the
7497 week. Any digits before this encode a year. So 200712 means
7498 week 12 of year 2007. Years in the range 1938-2037 can also be
7499 written as 2-digit years."
7500 (interactive "P")
7501 (org-agenda-change-time-span 'week iso-week))
7502 (defun org-agenda-month-view (&optional month)
7503 "Switch to monthly view for agenda.
7504 With argument MONTH, switch to that month."
7505 (interactive "P")
7506 (org-agenda-change-time-span 'month month))
7507 (defun org-agenda-year-view (&optional year)
7508 "Switch to yearly view for agenda.
7509 With argument YEAR, switch to that year.
7510 If MONTH has more then 2 digits, only the last two encode the
7511 month. Any digits before this encode a year. So 200712 means
7512 December year 2007. Years in the range 1938-2037 can also be
7513 written as 2-digit years."
7514 (interactive "P")
7515 (when year
7516 (setq year (org-small-year-to-year year)))
7517 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7518 (org-agenda-change-time-span 'year year)
7519 (error "Abort")))
7521 (defun org-agenda-change-time-span (span &optional n)
7522 "Change the agenda view to SPAN.
7523 SPAN may be `day', `week', `month', `year'."
7524 (org-agenda-check-type t 'agenda)
7525 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7526 (curspan (nth 2 args)))
7527 (if (and (not n) (equal curspan span))
7528 (error "Viewing span is already \"%s\"" span))
7529 (let* ((sd (or (org-get-at-bol 'day)
7530 (nth 1 args)
7531 org-starting-day))
7532 (sd (org-agenda-compute-starting-span sd span n))
7533 (org-agenda-overriding-cmd
7534 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7535 (org-agenda-overriding-arguments
7536 (list (car args) sd span)))
7537 (org-agenda-redo)
7538 (org-agenda-find-same-or-today-or-agenda))
7539 (org-agenda-set-mode-name)
7540 (message "Switched to %s view" span)))
7542 (defun org-agenda-compute-starting-span (sd span &optional n)
7543 "Compute starting date for agenda.
7544 SPAN may be `day', `week', `month', `year'. The return value
7545 is a cons cell with the starting date and the number of days,
7546 so that the date SD will be in that range."
7547 (let* ((greg (calendar-gregorian-from-absolute sd))
7548 (dg (nth 1 greg))
7549 (mg (car greg))
7550 (yg (nth 2 greg)))
7551 (cond
7552 ((eq span 'day)
7553 (when n
7554 (setq sd (+ (calendar-absolute-from-gregorian
7555 (list mg 1 yg))
7556 n -1))))
7557 ((eq span 'week)
7558 (let* ((nt (calendar-day-of-week
7559 (calendar-gregorian-from-absolute sd)))
7560 (d (if org-agenda-start-on-weekday
7561 (- nt org-agenda-start-on-weekday)
7564 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7565 (when n
7566 (require 'cal-iso)
7567 (when (> n 99)
7568 (setq y1 (org-small-year-to-year (/ n 100))
7569 n (mod n 100)))
7570 (setq sd
7571 (calendar-absolute-from-iso
7572 (list n 1
7573 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7574 ((eq span 'month)
7575 (let (y1)
7576 (when (and n (> n 99))
7577 (setq y1 (org-small-year-to-year (/ n 100))
7578 n (mod n 100)))
7579 (setq sd (calendar-absolute-from-gregorian
7580 (list (or n mg) 1 (or y1 yg))))))
7581 ((eq span 'year)
7582 (setq sd (calendar-absolute-from-gregorian
7583 (list 1 1 (or n yg))))))
7584 sd))
7586 (defun org-agenda-next-date-line (&optional arg)
7587 "Jump to the next line indicating a date in agenda buffer."
7588 (interactive "p")
7589 (org-agenda-check-type t 'agenda 'timeline)
7590 (beginning-of-line 1)
7591 ;; This does not work if user makes date format that starts with a blank
7592 (if (looking-at "^\\S-") (forward-char 1))
7593 (if (not (re-search-forward "^\\S-" nil t arg))
7594 (progn
7595 (backward-char 1)
7596 (error "No next date after this line in this buffer")))
7597 (goto-char (match-beginning 0)))
7599 (defun org-agenda-previous-date-line (&optional arg)
7600 "Jump to the previous line indicating a date in agenda buffer."
7601 (interactive "p")
7602 (org-agenda-check-type t 'agenda 'timeline)
7603 (beginning-of-line 1)
7604 (if (not (re-search-backward "^\\S-" nil t arg))
7605 (error "No previous date before this line in this buffer")))
7607 ;; Initialize the highlight
7608 (defvar org-hl (make-overlay 1 1))
7609 (overlay-put org-hl 'face 'highlight)
7611 (defun org-highlight (begin end &optional buffer)
7612 "Highlight a region with overlay."
7613 (move-overlay org-hl begin end (or buffer (current-buffer))))
7615 (defun org-unhighlight ()
7616 "Detach overlay INDEX."
7617 (org-detach-overlay org-hl))
7619 (defun org-unhighlight-once ()
7620 "Remove the highlight from its position, and this function from the hook."
7621 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7622 (org-unhighlight))
7624 (defvar org-agenda-pre-follow-window-conf nil)
7625 (defun org-agenda-follow-mode ()
7626 "Toggle follow mode in an agenda buffer."
7627 (interactive)
7628 (unless org-agenda-follow-mode
7629 (setq org-agenda-pre-follow-window-conf
7630 (current-window-configuration)))
7631 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7632 (unless org-agenda-follow-mode
7633 (set-window-configuration org-agenda-pre-follow-window-conf))
7634 (org-agenda-set-mode-name)
7635 (org-agenda-do-context-action)
7636 (message "Follow mode is %s"
7637 (if org-agenda-follow-mode "on" "off")))
7639 (defun org-agenda-entry-text-mode (&optional arg)
7640 "Toggle entry text mode in an agenda buffer."
7641 (interactive "P")
7642 (setq org-agenda-entry-text-mode (or (integerp arg)
7643 (not org-agenda-entry-text-mode)))
7644 (org-agenda-entry-text-hide)
7645 (and org-agenda-entry-text-mode
7646 (let ((org-agenda-entry-text-maxlines
7647 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7648 (org-agenda-entry-text-show)))
7649 (org-agenda-set-mode-name)
7650 (message "Entry text mode is %s. Maximum number of lines is %d"
7651 (if org-agenda-entry-text-mode "on" "off")
7652 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7654 (defun org-agenda-clockreport-mode (&optional with-filter)
7655 "Toggle clocktable mode in an agenda buffer.
7656 With prefix arg WITH-FILTER, make the clocktable respect the current
7657 agenda filter."
7658 (interactive "P")
7659 (org-agenda-check-type t 'agenda)
7660 (if with-filter
7661 (setq org-agenda-clockreport-mode 'with-filter)
7662 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7663 (org-agenda-set-mode-name)
7664 (org-agenda-redo)
7665 (message "Clocktable mode is %s"
7666 (if org-agenda-clockreport-mode "on" "off")))
7668 (defun org-agenda-log-mode (&optional special)
7669 "Toggle log mode in an agenda buffer.
7670 With argument SPECIAL, show all possible log items, not only the ones
7671 configured in `org-agenda-log-mode-items'.
7672 With a double `C-u' prefix arg, show *only* log items, nothing else."
7673 (interactive "P")
7674 (org-agenda-check-type t 'agenda 'timeline)
7675 (setq org-agenda-show-log
7676 (cond
7677 ((equal special '(16)) 'only)
7678 ((eq special 'clockcheck)
7679 (if (eq org-agenda-show-log 'clockcheck)
7680 nil 'clockcheck))
7681 (special '(closed clock state))
7682 (t (not org-agenda-show-log))))
7683 (org-agenda-set-mode-name)
7684 (org-agenda-redo)
7685 (message "Log mode is %s"
7686 (if org-agenda-show-log "on" "off")))
7688 (defun org-agenda-archives-mode (&optional with-files)
7689 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7690 When called with a prefix argument, include all archive files as well."
7691 (interactive "P")
7692 (setq org-agenda-archives-mode
7693 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7694 (org-agenda-set-mode-name)
7695 (org-agenda-redo)
7696 (message
7697 "%s"
7698 (cond
7699 ((eq org-agenda-archives-mode nil)
7700 "No archives are included")
7701 ((eq org-agenda-archives-mode 'trees)
7702 (format "Trees with :%s: tag are included" org-archive-tag))
7703 ((eq org-agenda-archives-mode t)
7704 (format "Trees with :%s: tag and all active archive files are included"
7705 org-archive-tag)))))
7707 (defun org-agenda-toggle-diary ()
7708 "Toggle diary inclusion in an agenda buffer."
7709 (interactive)
7710 (org-agenda-check-type t 'agenda)
7711 (setq org-agenda-include-diary (not org-agenda-include-diary))
7712 (org-agenda-redo)
7713 (org-agenda-set-mode-name)
7714 (message "Diary inclusion turned %s"
7715 (if org-agenda-include-diary "on" "off")))
7717 (defun org-agenda-toggle-deadlines ()
7718 "Toggle inclusion of entries with a deadline in an agenda buffer."
7719 (interactive)
7720 (org-agenda-check-type t 'agenda)
7721 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7722 (org-agenda-redo)
7723 (org-agenda-set-mode-name)
7724 (message "Deadlines inclusion turned %s"
7725 (if org-agenda-include-deadlines "on" "off")))
7727 (defun org-agenda-toggle-time-grid ()
7728 "Toggle time grid in an agenda buffer."
7729 (interactive)
7730 (org-agenda-check-type t 'agenda)
7731 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7732 (org-agenda-redo)
7733 (org-agenda-set-mode-name)
7734 (message "Time-grid turned %s"
7735 (if org-agenda-use-time-grid "on" "off")))
7737 (defun org-agenda-set-mode-name ()
7738 "Set the mode name to indicate all the small mode settings."
7739 (setq mode-name
7740 (list "Org-Agenda"
7741 (if (get 'org-agenda-files 'org-restrict) " []" "")
7743 '(:eval (org-agenda-span-name org-agenda-current-span))
7744 (if org-agenda-follow-mode " Follow" "")
7745 (if org-agenda-entry-text-mode " ETxt" "")
7746 (if org-agenda-include-diary " Diary" "")
7747 (if org-agenda-include-deadlines " Ddl" "")
7748 (if org-agenda-use-time-grid " Grid" "")
7749 (if (and (boundp 'org-habit-show-habits)
7750 org-habit-show-habits) " Habit" "")
7751 (cond
7752 ((consp org-agenda-show-log) " LogAll")
7753 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7754 (org-agenda-show-log " Log")
7755 (t ""))
7756 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7757 :preset-filter))
7758 '(:eval (org-propertize
7759 (concat " <"
7760 (mapconcat
7761 'identity
7762 (append
7763 (get 'org-agenda-category-filter :preset-filter)
7764 org-agenda-category-filter)
7766 ">")
7767 'face 'org-agenda-filter-category
7768 'help-echo "Category used in filtering"))
7770 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7771 :preset-filter))
7772 '(:eval (org-propertize
7773 (concat " {"
7774 (mapconcat
7775 'identity
7776 (append
7777 (get 'org-agenda-tag-filter :preset-filter)
7778 org-agenda-tag-filter)
7780 "}")
7781 'face 'org-agenda-filter-tags
7782 'help-echo "Tags used in filtering"))
7784 (if org-agenda-archives-mode
7785 (if (eq org-agenda-archives-mode t)
7786 " Archives"
7787 (format " :%s:" org-archive-tag))
7789 (if org-agenda-clockreport-mode
7790 (if (eq org-agenda-clockreport-mode 'with-filter)
7791 " Clock{}" " Clock")
7792 "")))
7793 (force-mode-line-update))
7795 (org-define-obsolete-function-alias
7796 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7798 (defun org-agenda-update-agenda-type ()
7799 "Update the agenda type after each command."
7800 (setq org-agenda-type
7801 (or (get-text-property (point) 'org-agenda-type)
7802 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7804 (defun org-agenda-next-line ()
7805 "Move cursor to the next line, and show if follow mode is active."
7806 (interactive)
7807 (call-interactively 'next-line)
7808 (org-agenda-do-context-action))
7810 (defun org-agenda-previous-line ()
7811 "Move cursor to the previous line, and show if follow-mode is active."
7812 (interactive)
7813 (call-interactively 'previous-line)
7814 (org-agenda-do-context-action))
7816 (defun org-agenda-next-item (n)
7817 "Move cursor to next agenda item."
7818 (interactive "p")
7819 (let ((col (current-column)))
7820 (dotimes (c n)
7821 (when (next-single-property-change (point-at-eol) 'org-marker)
7822 (move-end-of-line 1)
7823 (goto-char (next-single-property-change (point) 'org-marker))))
7824 (org-move-to-column col))
7825 (org-agenda-do-context-action))
7827 (defun org-agenda-previous-item (n)
7828 "Move cursor to next agenda item."
7829 (interactive "p")
7830 (dotimes (c n)
7831 (let ((col (current-column))
7832 (goto (save-excursion
7833 (move-end-of-line 0)
7834 (previous-single-property-change (point) 'org-marker))))
7835 (if goto (goto-char goto))
7836 (org-move-to-column col)))
7837 (org-agenda-do-context-action))
7839 (defun org-agenda-do-context-action ()
7840 "Show outline path and, maybe, follow mode window."
7841 (let ((m (org-get-at-bol 'org-marker)))
7842 (when (and (markerp m) (marker-buffer m))
7843 (and org-agenda-follow-mode
7844 (if org-agenda-follow-indirect
7845 (org-agenda-tree-to-indirect-buffer nil)
7846 (org-agenda-show)))
7847 (and org-agenda-show-outline-path
7848 (org-with-point-at m (org-display-outline-path t))))))
7850 (defun org-agenda-show-tags ()
7851 "Show the tags applicable to the current item."
7852 (interactive)
7853 (let* ((tags (org-get-at-bol 'tags)))
7854 (if tags
7855 (message "Tags are :%s:"
7856 (org-no-properties (mapconcat 'identity tags ":")))
7857 (message "No tags associated with this line"))))
7859 (defun org-agenda-goto (&optional highlight)
7860 "Go to the Org-mode file which contains the item at point."
7861 (interactive)
7862 (let* ((marker (or (org-get-at-bol 'org-marker)
7863 (org-agenda-error)))
7864 (buffer (marker-buffer marker))
7865 (pos (marker-position marker)))
7866 (switch-to-buffer-other-window buffer)
7867 (widen)
7868 (push-mark)
7869 (goto-char pos)
7870 (when (derived-mode-p 'org-mode)
7871 (org-show-context 'agenda)
7872 (save-excursion
7873 (and (outline-next-heading)
7874 (org-flag-heading nil)))) ; show the next heading
7875 (when (outline-invisible-p)
7876 (show-entry)) ; display invisible text
7877 (recenter (/ (window-height) 2))
7878 (run-hooks 'org-agenda-after-show-hook)
7879 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7881 (defvar org-agenda-after-show-hook nil
7882 "Normal hook run after an item has been shown from the agenda.
7883 Point is in the buffer where the item originated.")
7885 (defun org-agenda-kill ()
7886 "Kill the entry or subtree belonging to the current agenda entry."
7887 (interactive)
7888 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7889 (let* ((bufname-orig (buffer-name))
7890 (marker (or (org-get-at-bol 'org-marker)
7891 (org-agenda-error)))
7892 (buffer (marker-buffer marker))
7893 (pos (marker-position marker))
7894 (type (org-get-at-bol 'type))
7895 dbeg dend (n 0) conf)
7896 (org-with-remote-undo buffer
7897 (with-current-buffer buffer
7898 (save-excursion
7899 (goto-char pos)
7900 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7901 (setq dbeg (progn (org-back-to-heading t) (point))
7902 dend (org-end-of-subtree t t))
7903 (setq dbeg (point-at-bol)
7904 dend (min (point-max) (1+ (point-at-eol)))))
7905 (goto-char dbeg)
7906 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7907 (setq conf (or (eq t org-agenda-confirm-kill)
7908 (and (numberp org-agenda-confirm-kill)
7909 (> n org-agenda-confirm-kill))))
7910 (and conf
7911 (not (y-or-n-p
7912 (format "Delete entry with %d lines in buffer \"%s\"? "
7913 n (buffer-name buffer))))
7914 (error "Abort"))
7915 (let ((org-agenda-buffer-name bufname-orig))
7916 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7917 (with-current-buffer buffer (delete-region dbeg dend))
7918 (message "Agenda item and source killed"))))
7920 (defvar org-archive-default-command) ; defined in org-archive.el
7921 (defun org-agenda-archive-default ()
7922 "Archive the entry or subtree belonging to the current agenda entry."
7923 (interactive)
7924 (require 'org-archive)
7925 (org-agenda-archive-with org-archive-default-command))
7927 (defun org-agenda-archive-default-with-confirmation ()
7928 "Archive the entry or subtree belonging to the current agenda entry."
7929 (interactive)
7930 (require 'org-archive)
7931 (org-agenda-archive-with org-archive-default-command 'confirm))
7933 (defun org-agenda-archive ()
7934 "Archive the entry or subtree belonging to the current agenda entry."
7935 (interactive)
7936 (org-agenda-archive-with 'org-archive-subtree))
7938 (defun org-agenda-archive-to-archive-sibling ()
7939 "Move the entry to the archive sibling."
7940 (interactive)
7941 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7943 (defun org-agenda-archive-with (cmd &optional confirm)
7944 "Move the entry to the archive sibling."
7945 (interactive)
7946 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7947 (let* ((bufname-orig (buffer-name))
7948 (marker (or (org-get-at-bol 'org-marker)
7949 (org-agenda-error)))
7950 (buffer (marker-buffer marker))
7951 (pos (marker-position marker)))
7952 (org-with-remote-undo buffer
7953 (with-current-buffer buffer
7954 (if (derived-mode-p 'org-mode)
7955 (if (and confirm
7956 (not (y-or-n-p "Archive this subtree or entry? ")))
7957 (error "Abort")
7958 (save-excursion
7959 (goto-char pos)
7960 (let ((org-agenda-buffer-name bufname-orig))
7961 (org-remove-subtree-entries-from-agenda))
7962 (org-back-to-heading t)
7963 (funcall cmd)))
7964 (error "Archiving works only in Org-mode files"))))))
7966 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7967 "Remove all lines in the agenda that correspond to a given subtree.
7968 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7969 If this information is not given, the function uses the tree at point."
7970 (let ((buf (or buf (current-buffer))) m p)
7971 (save-excursion
7972 (unless (and beg end)
7973 (org-back-to-heading t)
7974 (setq beg (point))
7975 (org-end-of-subtree t)
7976 (setq end (point)))
7977 (set-buffer (get-buffer org-agenda-buffer-name))
7978 (save-excursion
7979 (goto-char (point-max))
7980 (beginning-of-line 1)
7981 (while (not (bobp))
7982 (when (and (setq m (org-get-at-bol 'org-marker))
7983 (equal buf (marker-buffer m))
7984 (setq p (marker-position m))
7985 (>= p beg)
7986 (< p end))
7987 (let ((inhibit-read-only t))
7988 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7989 (beginning-of-line 0))))))
7991 (defun org-agenda-refile (&optional goto rfloc no-update)
7992 "Refile the item at point."
7993 (interactive "P")
7994 (if (equal goto '(16))
7995 (org-refile-goto-last-stored)
7996 (let* ((buffer-orig (buffer-name))
7997 (marker (or (org-get-at-bol 'org-hd-marker)
7998 (org-agenda-error)))
7999 (buffer (marker-buffer marker))
8000 (pos (marker-position marker))
8001 (rfloc (or rfloc
8002 (org-refile-get-location
8003 (if goto "Goto" "Refile to") buffer
8004 org-refile-allow-creating-parent-nodes))))
8005 (with-current-buffer buffer
8006 (save-excursion
8007 (save-restriction
8008 (widen)
8009 (goto-char marker)
8010 (let ((org-agenda-buffer-name buffer-orig))
8011 (org-remove-subtree-entries-from-agenda))
8012 (org-refile goto buffer rfloc)))))
8013 (unless no-update (org-agenda-redo))))
8015 (defun org-agenda-open-link (&optional arg)
8016 "Open the link(s) in the current entry, if any.
8017 This looks for a link in the displayed line in the agenda.
8018 It also looks at the text of the entry itself."
8019 (interactive "P")
8020 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8021 (org-get-at-bol 'org-marker)))
8022 (buffer (and marker (marker-buffer marker)))
8023 (prefix (buffer-substring
8024 (point-at-bol) (point-at-eol)))
8025 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8026 (lk (car lkall))
8027 (lkend (cdr lkall))
8028 trg)
8029 (cond
8030 ((and buffer (stringp lk))
8031 (with-current-buffer buffer
8032 (setq trg (and (string-match org-bracket-link-regexp lk)
8033 (match-string 1 lk)))
8034 (if (or (not trg) (string-match org-any-link-re trg))
8035 (save-excursion
8036 (save-restriction
8037 (widen)
8038 (goto-char marker)
8039 (when (search-forward lk nil lkend)
8040 (goto-char (match-beginning 0))
8041 (org-open-at-point))))
8042 ;; This is an internal link, widen the buffer
8043 (switch-to-buffer-other-window buffer)
8044 (widen)
8045 (goto-char marker)
8046 (when (search-forward lk nil lkend)
8047 (goto-char (match-beginning 0))
8048 (org-open-at-point)))))
8049 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8050 (save-excursion
8051 (beginning-of-line 1)
8052 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8053 (org-open-link-from-string (match-string 1)))
8054 (t (message "No link to open here")))))
8056 (defun org-agenda-copy-local-variable (var)
8057 "Get a variable from a referenced buffer and install it here."
8058 (let ((m (org-get-at-bol 'org-marker)))
8059 (when (and m (buffer-live-p (marker-buffer m)))
8060 (org-set-local var (with-current-buffer (marker-buffer m)
8061 (symbol-value var))))))
8063 (defun org-agenda-switch-to (&optional delete-other-windows)
8064 "Go to the Org-mode file which contains the item at point."
8065 (interactive)
8066 (if (and org-return-follows-link
8067 (not (org-get-at-bol 'org-marker))
8068 (org-in-regexp org-bracket-link-regexp))
8069 (org-open-link-from-string (match-string 0))
8070 (let* ((marker (or (org-get-at-bol 'org-marker)
8071 (org-agenda-error)))
8072 (buffer (marker-buffer marker))
8073 (pos (marker-position marker)))
8074 (org-pop-to-buffer-same-window buffer)
8075 (and delete-other-windows (delete-other-windows))
8076 (widen)
8077 (goto-char pos)
8078 (when (derived-mode-p 'org-mode)
8079 (org-show-context 'agenda)
8080 (save-excursion
8081 (and (outline-next-heading)
8082 (org-flag-heading nil))) ; show the next heading
8083 (when (outline-invisible-p)
8084 (show-entry)) ; display invisible text
8085 (run-hooks 'org-agenda-after-show-hook)))))
8087 (defun org-agenda-goto-mouse (ev)
8088 "Go to the Org-mode file which contains the item at the mouse click."
8089 (interactive "e")
8090 (mouse-set-point ev)
8091 (org-agenda-goto))
8093 (defun org-agenda-show (&optional full-entry)
8094 "Display the Org-mode file which contains the item at point.
8095 With prefix argument FULL-ENTRY, make the entire entry visible
8096 if it was hidden in the outline."
8097 (interactive "P")
8098 (let ((win (selected-window)))
8099 (if full-entry
8100 (let ((org-show-entry-below t))
8101 (org-agenda-goto t))
8102 (org-agenda-goto t))
8103 (select-window win)))
8105 (defvar org-agenda-show-window nil)
8106 (defun org-agenda-show-and-scroll-up (&optional arg)
8107 "Display the Org-mode file which contains the item at point.
8108 When called repeatedly, scroll the window that is displaying the buffer.
8109 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8110 `show-subtree' to display the item, so that drawers and logbooks stay
8111 folded."
8112 (interactive "P")
8113 (let ((win (selected-window)))
8114 (if (and (window-live-p org-agenda-show-window)
8115 (eq this-command last-command))
8116 (progn
8117 (select-window org-agenda-show-window)
8118 (ignore-errors (scroll-up)))
8119 (org-agenda-goto t)
8120 (if arg (org-show-entry) (show-subtree))
8121 (setq org-agenda-show-window (selected-window)))
8122 (select-window win)))
8124 (defun org-agenda-show-scroll-down ()
8125 "Scroll down the window showing the agenda."
8126 (interactive)
8127 (let ((win (selected-window)))
8128 (when (window-live-p org-agenda-show-window)
8129 (select-window org-agenda-show-window)
8130 (ignore-errors (scroll-down))
8131 (select-window win))))
8133 (defun org-agenda-show-1 (&optional more)
8134 "Display the Org-mode file which contains the item at point.
8135 The prefix arg selects the amount of information to display:
8137 0 hide the subtree
8138 1 just show the entry according to defaults.
8139 2 show the children view
8140 3 show the subtree view
8141 4 show the entire subtree and any LOGBOOK drawers
8142 5 show the entire subtree and any drawers
8143 With prefix argument FULL-ENTRY, make the entire entry visible
8144 if it was hidden in the outline."
8145 (interactive "p")
8146 (let ((win (selected-window)))
8147 (org-agenda-goto t)
8148 (org-recenter-heading 1)
8149 (cond
8150 ((= more 0)
8151 (hide-subtree)
8152 (save-excursion
8153 (org-back-to-heading)
8154 (run-hook-with-args 'org-cycle-hook 'folded))
8155 (message "Remote: FOLDED"))
8156 ((and (org-called-interactively-p 'any) (= more 1))
8157 (message "Remote: show with default settings"))
8158 ((= more 2)
8159 (show-entry)
8160 (show-children)
8161 (save-excursion
8162 (org-back-to-heading)
8163 (run-hook-with-args 'org-cycle-hook 'children))
8164 (message "Remote: CHILDREN"))
8165 ((= more 3)
8166 (show-subtree)
8167 (save-excursion
8168 (org-back-to-heading)
8169 (run-hook-with-args 'org-cycle-hook 'subtree))
8170 (message "Remote: SUBTREE"))
8171 ((= more 4)
8172 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8173 (org-drawer-regexp
8174 (concat "^[ \t]*:\\("
8175 (mapconcat 'regexp-quote org-drawers "\\|")
8176 "\\):[ \t]*$")))
8177 (show-subtree)
8178 (save-excursion
8179 (org-back-to-heading)
8180 (org-cycle-hide-drawers 'subtree)))
8181 (message "Remote: SUBTREE AND LOGBOOK"))
8182 ((> more 4)
8183 (show-subtree)
8184 (message "Remote: SUBTREE AND ALL DRAWERS")))
8185 (select-window win)))
8187 (defun org-recenter-heading (n)
8188 (save-excursion
8189 (org-back-to-heading)
8190 (recenter n)))
8192 (defvar org-agenda-cycle-counter nil)
8193 (defun org-agenda-cycle-show (&optional n)
8194 "Show the current entry in another window, with default settings.
8195 Default settings are taken from `org-show-hierarchy-above' and siblings.
8196 When use repeatedly in immediate succession, the remote entry will cycle
8197 through visibility
8199 children -> subtree -> folded
8201 When called with a numeric prefix arg, that arg will be passed through to
8202 `org-agenda-show-1'. For the interpretation of that argument, see the
8203 docstring of `org-agenda-show-1'."
8204 (interactive "P")
8205 (if (integerp n)
8206 (setq org-agenda-cycle-counter n)
8207 (if (not (eq last-command this-command))
8208 (setq org-agenda-cycle-counter 1)
8209 (if (equal org-agenda-cycle-counter 0)
8210 (setq org-agenda-cycle-counter 2)
8211 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8212 (if (> org-agenda-cycle-counter 3)
8213 (setq org-agenda-cycle-counter 0)))))
8214 (org-agenda-show-1 org-agenda-cycle-counter))
8216 (defun org-agenda-recenter (arg)
8217 "Display the Org-mode file which contains the item at point and recenter."
8218 (interactive "P")
8219 (let ((win (selected-window)))
8220 (org-agenda-goto t)
8221 (recenter arg)
8222 (select-window win)))
8224 (defun org-agenda-show-mouse (ev)
8225 "Display the Org-mode file which contains the item at the mouse click."
8226 (interactive "e")
8227 (mouse-set-point ev)
8228 (org-agenda-show))
8230 (defun org-agenda-check-no-diary ()
8231 "Check if the entry is a diary link and abort if yes."
8232 (if (org-get-at-bol 'org-agenda-diary-link)
8233 (org-agenda-error)))
8235 (defun org-agenda-error ()
8236 (error "Command not allowed in this line"))
8238 (defun org-agenda-tree-to-indirect-buffer (arg)
8239 "Show the subtree corresponding to the current entry in an indirect buffer.
8240 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8242 With a numerical prefix ARG, go up to this level and then take that tree.
8243 With a negative numeric ARG, go up by this number of levels.
8244 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8245 use the dedicated frame)."
8246 (interactive "P")
8247 (if current-prefix-arg
8248 (org-agenda-do-tree-to-indirect-buffer arg)
8249 (let ((agenda-buffer (buffer-name))
8250 (agenda-window (selected-window))
8251 (indirect-window
8252 (and org-last-indirect-buffer
8253 (get-buffer-window org-last-indirect-buffer))))
8254 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8255 (unless (or (eq org-indirect-buffer-display 'new-frame)
8256 (eq org-indirect-buffer-display 'dedicated-frame))
8257 (unwind-protect
8258 (unless (and indirect-window (window-live-p indirect-window))
8259 (setq indirect-window (split-window agenda-window)))
8260 (and indirect-window (select-window indirect-window))
8261 (switch-to-buffer org-last-indirect-buffer :norecord)
8262 (fit-window-to-buffer indirect-window)))
8263 (select-window (get-buffer-window agenda-buffer)))))
8265 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8266 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8267 (org-agenda-check-no-diary)
8268 (let* ((marker (or (org-get-at-bol 'org-marker)
8269 (org-agenda-error)))
8270 (buffer (marker-buffer marker))
8271 (pos (marker-position marker)))
8272 (with-current-buffer buffer
8273 (save-excursion
8274 (goto-char pos)
8275 (funcall 'org-tree-to-indirect-buffer arg)))))
8277 (defvar org-last-heading-marker (make-marker)
8278 "Marker pointing to the headline that last changed its TODO state
8279 by a remote command from the agenda.")
8281 (defun org-agenda-todo-nextset ()
8282 "Switch TODO entry to next sequence."
8283 (interactive)
8284 (org-agenda-todo 'nextset))
8286 (defun org-agenda-todo-previousset ()
8287 "Switch TODO entry to previous sequence."
8288 (interactive)
8289 (org-agenda-todo 'previousset))
8291 (defun org-agenda-todo (&optional arg)
8292 "Cycle TODO state of line at point, also in Org-mode file.
8293 This changes the line at point, all other lines in the agenda referring to
8294 the same tree node, and the headline of the tree node in the Org-mode file."
8295 (interactive "P")
8296 (org-agenda-check-no-diary)
8297 (let* ((col (current-column))
8298 (marker (or (org-get-at-bol 'org-marker)
8299 (org-agenda-error)))
8300 (buffer (marker-buffer marker))
8301 (pos (marker-position marker))
8302 (hdmarker (org-get-at-bol 'org-hd-marker))
8303 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8304 (inhibit-read-only t)
8305 org-agenda-headline-snapshot-before-repeat newhead just-one)
8306 (org-with-remote-undo buffer
8307 (with-current-buffer buffer
8308 (widen)
8309 (goto-char pos)
8310 (org-show-context 'agenda)
8311 (save-excursion
8312 (and (outline-next-heading)
8313 (org-flag-heading nil))) ; show the next heading
8314 (let ((current-prefix-arg arg))
8315 (call-interactively 'org-todo))
8316 (and (bolp) (forward-char 1))
8317 (setq newhead (org-get-heading))
8318 (when (and (org-bound-and-true-p
8319 org-agenda-headline-snapshot-before-repeat)
8320 (not (equal org-agenda-headline-snapshot-before-repeat
8321 newhead))
8322 todayp)
8323 (setq newhead org-agenda-headline-snapshot-before-repeat
8324 just-one t))
8325 (save-excursion
8326 (org-back-to-heading)
8327 (move-marker org-last-heading-marker (point))))
8328 (beginning-of-line 1)
8329 (save-excursion
8330 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8331 (org-move-to-column col))))
8333 (defun org-agenda-add-note (&optional arg)
8334 "Add a time-stamped note to the entry at point."
8335 (interactive "P")
8336 (org-agenda-check-no-diary)
8337 (let* ((marker (or (org-get-at-bol 'org-marker)
8338 (org-agenda-error)))
8339 (buffer (marker-buffer marker))
8340 (pos (marker-position marker))
8341 (hdmarker (org-get-at-bol 'org-hd-marker))
8342 (inhibit-read-only t))
8343 (with-current-buffer buffer
8344 (widen)
8345 (goto-char pos)
8346 (org-show-context 'agenda)
8347 (save-excursion
8348 (and (outline-next-heading)
8349 (org-flag-heading nil))) ; show the next heading
8350 (org-add-note))))
8352 (defun org-agenda-change-all-lines (newhead hdmarker
8353 &optional fixface just-this)
8354 "Change all lines in the agenda buffer which match HDMARKER.
8355 The new content of the line will be NEWHEAD (as modified by
8356 `org-agenda-format-item'). HDMARKER is checked with
8357 `equal' against all `org-hd-marker' text properties in the file.
8358 If FIXFACE is non-nil, the face of each item is modified according to
8359 the new TODO state.
8360 If JUST-THIS is non-nil, change just the current line, not all.
8361 If FORCE-TAGS is non nil, the car of it returns the new tags."
8362 (let* ((inhibit-read-only t)
8363 (line (org-current-line))
8364 (org-agenda-buffer (current-buffer))
8365 (thetags (with-current-buffer (marker-buffer hdmarker)
8366 (save-excursion (save-restriction (widen)
8367 (goto-char hdmarker)
8368 (org-get-tags-at)))))
8369 props m pl undone-face done-face finish new dotime level cat tags)
8370 (save-excursion
8371 (goto-char (point-max))
8372 (beginning-of-line 1)
8373 (while (not finish)
8374 (setq finish (bobp))
8375 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8376 (or (not just-this) (= (org-current-line) line))
8377 (equal m hdmarker))
8378 (setq props (text-properties-at (point))
8379 dotime (org-get-at-bol 'dotime)
8380 cat (org-get-at-bol 'org-category)
8381 level (org-get-at-bol 'level)
8382 tags thetags
8384 (let ((org-prefix-format-compiled
8385 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8386 org-prefix-format-compiled))
8387 (extra (org-get-at-bol 'extra)))
8388 (with-current-buffer (marker-buffer hdmarker)
8389 (save-excursion
8390 (save-restriction
8391 (widen)
8392 (org-agenda-format-item extra newhead level cat tags dotime)))))
8393 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8394 undone-face (org-get-at-bol 'undone-face)
8395 done-face (org-get-at-bol 'done-face))
8396 (beginning-of-line 1)
8397 (cond
8398 ((equal new "")
8399 (and (looking-at ".*\n?") (replace-match "")))
8400 ((looking-at ".*")
8401 (replace-match new t t)
8402 (beginning-of-line 1)
8403 (add-text-properties (point-at-bol) (point-at-eol) props)
8404 (when fixface
8405 (add-text-properties
8406 (point-at-bol) (point-at-eol)
8407 (list 'face
8408 (if org-last-todo-state-is-todo
8409 undone-face done-face))))
8410 (org-agenda-highlight-todo 'line)
8411 (beginning-of-line 1))
8412 (t (error "Line update did not work")))
8413 (save-restriction
8414 (narrow-to-region (point-at-bol) (point-at-eol))
8415 (org-agenda-finalize)))
8416 (beginning-of-line 0)))))
8418 (defun org-agenda-align-tags (&optional line)
8419 "Align all tags in agenda items to `org-agenda-tags-column'."
8420 (let ((inhibit-read-only t) l c)
8421 (save-excursion
8422 (goto-char (if line (point-at-bol) (point-min)))
8423 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8424 (if line (point-at-eol) nil) t)
8425 (add-text-properties
8426 (match-beginning 2) (match-end 2)
8427 (list 'face (delq nil (let ((prop (get-text-property
8428 (match-beginning 2) 'face)))
8429 (or (listp prop) (setq prop (list prop)))
8430 (if (memq 'org-tag prop)
8431 prop
8432 (cons 'org-tag prop))))))
8433 (setq l (- (match-end 2) (match-beginning 2))
8434 c (if (< org-agenda-tags-column 0)
8435 (- (abs org-agenda-tags-column) l)
8436 org-agenda-tags-column))
8437 (delete-region (match-beginning 1) (match-end 1))
8438 (goto-char (match-beginning 1))
8439 (insert (org-add-props
8440 (make-string (max 1 (- c (current-column))) ?\ )
8441 (plist-put (copy-sequence (text-properties-at (point)))
8442 'face nil))))
8443 (goto-char (point-min))
8444 (org-font-lock-add-tag-faces (point-max)))))
8446 (defun org-agenda-priority-up ()
8447 "Increase the priority of line at point, also in Org-mode file."
8448 (interactive)
8449 (org-agenda-priority 'up))
8451 (defun org-agenda-priority-down ()
8452 "Decrease the priority of line at point, also in Org-mode file."
8453 (interactive)
8454 (org-agenda-priority 'down))
8456 (defun org-agenda-priority (&optional force-direction)
8457 "Set the priority of line at point, also in Org-mode file.
8458 This changes the line at point, all other lines in the agenda referring to
8459 the same tree node, and the headline of the tree node in the Org-mode file.
8460 Called with a universal prefix arg, show the priority instead of setting it."
8461 (interactive "P")
8462 (if (equal force-direction '(4))
8463 (org-show-priority)
8464 (unless org-enable-priority-commands
8465 (error "Priority commands are disabled"))
8466 (org-agenda-check-no-diary)
8467 (let* ((marker (or (org-get-at-bol 'org-marker)
8468 (org-agenda-error)))
8469 (hdmarker (org-get-at-bol 'org-hd-marker))
8470 (buffer (marker-buffer hdmarker))
8471 (pos (marker-position hdmarker))
8472 (inhibit-read-only t)
8473 newhead)
8474 (org-with-remote-undo buffer
8475 (with-current-buffer buffer
8476 (widen)
8477 (goto-char pos)
8478 (org-show-context 'agenda)
8479 (save-excursion
8480 (and (outline-next-heading)
8481 (org-flag-heading nil))) ; show the next heading
8482 (funcall 'org-priority force-direction)
8483 (end-of-line 1)
8484 (setq newhead (org-get-heading)))
8485 (org-agenda-change-all-lines newhead hdmarker)
8486 (beginning-of-line 1)))))
8488 ;; FIXME: should fix the tags property of the agenda line.
8489 (defun org-agenda-set-tags (&optional tag onoff)
8490 "Set tags for the current headline."
8491 (interactive)
8492 (org-agenda-check-no-diary)
8493 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8494 (call-interactively 'org-change-tag-in-region)
8495 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8496 (org-agenda-error)))
8497 (buffer (marker-buffer hdmarker))
8498 (pos (marker-position hdmarker))
8499 (inhibit-read-only t)
8500 newhead)
8501 (org-with-remote-undo buffer
8502 (with-current-buffer buffer
8503 (widen)
8504 (goto-char pos)
8505 (save-excursion
8506 (org-show-context 'agenda))
8507 (save-excursion
8508 (and (outline-next-heading)
8509 (org-flag-heading nil))) ; show the next heading
8510 (goto-char pos)
8511 (if tag
8512 (org-toggle-tag tag onoff)
8513 (call-interactively 'org-set-tags))
8514 (end-of-line 1)
8515 (setq newhead (org-get-heading)))
8516 (org-agenda-change-all-lines newhead hdmarker)
8517 (beginning-of-line 1)))))
8519 (defun org-agenda-set-property ()
8520 "Set a property for the current headline."
8521 (interactive)
8522 (org-agenda-check-no-diary)
8523 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8524 (org-agenda-error)))
8525 (buffer (marker-buffer hdmarker))
8526 (pos (marker-position hdmarker))
8527 (inhibit-read-only t)
8528 newhead)
8529 (org-with-remote-undo buffer
8530 (with-current-buffer buffer
8531 (widen)
8532 (goto-char pos)
8533 (save-excursion
8534 (org-show-context 'agenda))
8535 (save-excursion
8536 (and (outline-next-heading)
8537 (org-flag-heading nil))) ; show the next heading
8538 (goto-char pos)
8539 (call-interactively 'org-set-property)))))
8541 (defun org-agenda-set-effort ()
8542 "Set the effort property for the current headline."
8543 (interactive)
8544 (org-agenda-check-no-diary)
8545 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8546 (org-agenda-error)))
8547 (buffer (marker-buffer hdmarker))
8548 (pos (marker-position hdmarker))
8549 (inhibit-read-only t)
8550 newhead)
8551 (org-with-remote-undo buffer
8552 (with-current-buffer buffer
8553 (widen)
8554 (goto-char pos)
8555 (save-excursion
8556 (org-show-context 'agenda))
8557 (save-excursion
8558 (and (outline-next-heading)
8559 (org-flag-heading nil))) ; show the next heading
8560 (goto-char pos)
8561 (call-interactively 'org-set-effort)
8562 (end-of-line 1)
8563 (setq newhead (org-get-heading)))
8564 (org-agenda-change-all-lines newhead hdmarker))))
8566 (defun org-agenda-toggle-archive-tag ()
8567 "Toggle the archive tag for the current entry."
8568 (interactive)
8569 (org-agenda-check-no-diary)
8570 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8571 (org-agenda-error)))
8572 (buffer (marker-buffer hdmarker))
8573 (pos (marker-position hdmarker))
8574 (inhibit-read-only t)
8575 newhead)
8576 (org-with-remote-undo buffer
8577 (with-current-buffer buffer
8578 (widen)
8579 (goto-char pos)
8580 (org-show-context 'agenda)
8581 (save-excursion
8582 (and (outline-next-heading)
8583 (org-flag-heading nil))) ; show the next heading
8584 (call-interactively 'org-toggle-archive-tag)
8585 (end-of-line 1)
8586 (setq newhead (org-get-heading)))
8587 (org-agenda-change-all-lines newhead hdmarker)
8588 (beginning-of-line 1))))
8590 (defun org-agenda-do-date-later (arg)
8591 (interactive "P")
8592 (cond
8593 ((or (equal arg '(16))
8594 (memq last-command
8595 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8596 (setq this-command 'org-agenda-date-later-minutes)
8597 (org-agenda-date-later-minutes 1))
8598 ((or (equal arg '(4))
8599 (memq last-command
8600 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8601 (setq this-command 'org-agenda-date-later-hours)
8602 (org-agenda-date-later-hours 1))
8604 (org-agenda-date-later (prefix-numeric-value arg)))))
8606 (defun org-agenda-do-date-earlier (arg)
8607 (interactive "P")
8608 (cond
8609 ((or (equal arg '(16))
8610 (memq last-command
8611 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8612 (setq this-command 'org-agenda-date-earlier-minutes)
8613 (org-agenda-date-earlier-minutes 1))
8614 ((or (equal arg '(4))
8615 (memq last-command
8616 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8617 (setq this-command 'org-agenda-date-earlier-hours)
8618 (org-agenda-date-earlier-hours 1))
8620 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8622 (defun org-agenda-date-later (arg &optional what)
8623 "Change the date of this item to ARG day(s) later."
8624 (interactive "p")
8625 (org-agenda-check-type t 'agenda 'timeline)
8626 (org-agenda-check-no-diary)
8627 (let* ((marker (or (org-get-at-bol 'org-marker)
8628 (org-agenda-error)))
8629 (buffer (marker-buffer marker))
8630 (pos (marker-position marker))
8631 cdate today)
8632 (org-with-remote-undo buffer
8633 (with-current-buffer buffer
8634 (widen)
8635 (goto-char pos)
8636 (if (not (org-at-timestamp-p))
8637 (error "Cannot find time stamp"))
8638 (when (and org-agenda-move-date-from-past-immediately-to-today
8639 (equal arg 1)
8640 (or (not what) (eq what 'day))
8641 (not (save-match-data (org-at-date-range-p))))
8642 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8643 cdate (calendar-absolute-from-gregorian
8644 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8645 today (org-today))
8646 (if (> today cdate)
8647 ;; immediately shift to today
8648 (setq arg (- today cdate))))
8649 (org-timestamp-change arg (or what 'day))
8650 (when (and (org-at-date-range-p)
8651 (re-search-backward org-tr-regexp-both (point-at-bol)))
8652 (let ((end org-last-changed-timestamp))
8653 (org-timestamp-change arg (or what 'day))
8654 (setq org-last-changed-timestamp
8655 (concat org-last-changed-timestamp "--" end)))))
8656 (org-agenda-show-new-time marker org-last-changed-timestamp))
8657 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8659 (defun org-agenda-date-earlier (arg &optional what)
8660 "Change the date of this item to ARG day(s) earlier."
8661 (interactive "p")
8662 (org-agenda-date-later (- arg) what))
8664 (defun org-agenda-date-later-minutes (arg)
8665 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8666 (interactive "p")
8667 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8668 (org-agenda-date-later arg 'minute))
8670 (defun org-agenda-date-earlier-minutes (arg)
8671 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8672 (interactive "p")
8673 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8674 (org-agenda-date-earlier arg 'minute))
8676 (defun org-agenda-date-later-hours (arg)
8677 "Change the time of this item, in hour steps."
8678 (interactive "p")
8679 (org-agenda-date-later arg 'hour))
8681 (defun org-agenda-date-earlier-hours (arg)
8682 "Change the time of this item, in hour steps."
8683 (interactive "p")
8684 (org-agenda-date-earlier arg 'hour))
8686 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8687 "Show new date stamp via text properties."
8688 ;; We use text properties to make this undoable
8689 (let ((inhibit-read-only t)
8690 (buffer-invisibility-spec))
8691 (setq stamp (concat " " prefix " => " stamp))
8692 (save-excursion
8693 (goto-char (point-max))
8694 (while (not (bobp))
8695 (when (equal marker (org-get-at-bol 'org-marker))
8696 (org-move-to-column (- (window-width) (length stamp)) t)
8697 (org-agenda-fix-tags-filter-overlays-at (point))
8698 (if (featurep 'xemacs)
8699 ;; Use `duplicable' property to trigger undo recording
8700 (let ((ex (make-extent nil nil))
8701 (gl (make-glyph stamp)))
8702 (set-glyph-face gl 'secondary-selection)
8703 (set-extent-properties
8704 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8705 (insert-extent ex (1- (point)) (point-at-eol)))
8706 (add-text-properties
8707 (1- (point)) (point-at-eol)
8708 (list 'display (org-add-props stamp nil
8709 'face 'secondary-selection))))
8710 (beginning-of-line 1))
8711 (beginning-of-line 0)))))
8713 (defun org-agenda-date-prompt (arg)
8714 "Change the date of this item. Date is prompted for, with default today.
8715 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8716 be used to request time specification in the time stamp."
8717 (interactive "P")
8718 (org-agenda-check-type t 'agenda 'timeline)
8719 (org-agenda-check-no-diary)
8720 (let* ((marker (or (org-get-at-bol 'org-marker)
8721 (org-agenda-error)))
8722 (buffer (marker-buffer marker))
8723 (pos (marker-position marker)))
8724 (org-with-remote-undo buffer
8725 (with-current-buffer buffer
8726 (widen)
8727 (goto-char pos)
8728 (if (not (org-at-timestamp-p t))
8729 (error "Cannot find time stamp"))
8730 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8731 (org-agenda-show-new-time marker org-last-changed-timestamp))
8732 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8734 (defun org-agenda-schedule (arg &optional time)
8735 "Schedule the item at point.
8736 ARG is passed through to `org-schedule'."
8737 (interactive "P")
8738 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8739 (org-agenda-check-no-diary)
8740 (let* ((marker (or (org-get-at-bol 'org-marker)
8741 (org-agenda-error)))
8742 (type (marker-insertion-type marker))
8743 (buffer (marker-buffer marker))
8744 (pos (marker-position marker))
8745 (org-insert-labeled-timestamps-at-point nil)
8747 (set-marker-insertion-type marker t)
8748 (org-with-remote-undo buffer
8749 (with-current-buffer buffer
8750 (widen)
8751 (goto-char pos)
8752 (setq ts (org-schedule arg time)))
8753 (org-agenda-show-new-time marker ts "S"))
8754 (message "%s" ts)))
8756 (defun org-agenda-deadline (arg &optional time)
8757 "Schedule the item at point.
8758 ARG is passed through to `org-deadline'."
8759 (interactive "P")
8760 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8761 (org-agenda-check-no-diary)
8762 (let* ((marker (or (org-get-at-bol 'org-marker)
8763 (org-agenda-error)))
8764 (buffer (marker-buffer marker))
8765 (pos (marker-position marker))
8766 (org-insert-labeled-timestamps-at-point nil)
8768 (org-with-remote-undo buffer
8769 (with-current-buffer buffer
8770 (widen)
8771 (goto-char pos)
8772 (setq ts (org-deadline arg time)))
8773 (org-agenda-show-new-time marker ts "D"))
8774 (message "%s" ts)))
8776 (defun org-agenda-clock-in (&optional arg)
8777 "Start the clock on the currently selected item."
8778 (interactive "P")
8779 (org-agenda-check-no-diary)
8780 (if (equal arg '(4))
8781 (org-clock-in arg)
8782 (let* ((marker (or (org-get-at-bol 'org-marker)
8783 (org-agenda-error)))
8784 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8785 marker))
8786 (pos (marker-position marker))
8787 newhead)
8788 (org-with-remote-undo (marker-buffer marker)
8789 (with-current-buffer (marker-buffer marker)
8790 (widen)
8791 (goto-char pos)
8792 (org-show-context 'agenda)
8793 (org-show-entry)
8794 (org-cycle-hide-drawers 'children)
8795 (org-clock-in arg)
8796 (setq newhead (org-get-heading)))
8797 (org-agenda-change-all-lines newhead hdmarker)))))
8799 (defun org-agenda-clock-out ()
8800 "Stop the currently running clock."
8801 (interactive)
8802 (unless (marker-buffer org-clock-marker)
8803 (error "No running clock"))
8804 (let ((marker (make-marker)) newhead)
8805 (org-with-remote-undo (marker-buffer org-clock-marker)
8806 (with-current-buffer (marker-buffer org-clock-marker)
8807 (save-excursion
8808 (save-restriction
8809 (widen)
8810 (goto-char org-clock-marker)
8811 (org-back-to-heading t)
8812 (move-marker marker (point))
8813 (org-clock-out)
8814 (setq newhead (org-get-heading))))))
8815 (org-agenda-change-all-lines newhead marker)
8816 (move-marker marker nil)))
8818 (defun org-agenda-clock-cancel (&optional arg)
8819 "Cancel the currently running clock."
8820 (interactive "P")
8821 (unless (marker-buffer org-clock-marker)
8822 (error "No running clock"))
8823 (org-with-remote-undo (marker-buffer org-clock-marker)
8824 (org-clock-cancel)))
8826 (defun org-agenda-clock-goto ()
8827 "Jump to the currently clocked in task within the agenda.
8828 If the currently clocked in task is not listed in the agenda
8829 buffer, display it in another window."
8830 (interactive)
8831 (let (pos)
8832 (mapc (lambda (o)
8833 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8834 (setq pos (overlay-start o))))
8835 (overlays-in (point-min) (point-max)))
8836 (cond (pos (goto-char pos))
8837 ;; If the currently clocked entry is not in the agenda
8838 ;; buffer, we visit it in another window:
8839 (org-clock-current-task
8840 (org-switch-to-buffer-other-window (org-clock-goto)))
8841 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8843 (defun org-agenda-diary-entry-in-org-file ()
8844 "Make a diary entry in the file `org-agenda-diary-file'."
8845 (let (d1 d2 char (text "") dp1 dp2)
8846 (if (equal (buffer-name) "*Calendar*")
8847 (setq d1 (calendar-cursor-to-date t)
8848 d2 (car calendar-mark-ring))
8849 (setq dp1 (get-text-property (point-at-bol) 'day))
8850 (unless dp1 (error "No date defined in current line"))
8851 (setq d1 (calendar-gregorian-from-absolute dp1)
8852 d2 (and (ignore-errors (mark))
8853 (save-excursion
8854 (goto-char (mark))
8855 (setq dp2 (get-text-property (point-at-bol) 'day)))
8856 (calendar-gregorian-from-absolute dp2))))
8857 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8858 (setq char (read-char-exclusive))
8859 (cond
8860 ((equal char ?d)
8861 (setq text (read-string "Day entry: "))
8862 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8863 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8864 ((equal char ?a)
8865 (setq d1 (list (car d1) (nth 1 d1)
8866 (read-number (format "Reference year [%d]: " (nth 2 d1))
8867 (nth 2 d1))))
8868 (setq text (read-string "Anniversary (use %d to show years): "))
8869 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8870 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8871 ((equal char ?b)
8872 (setq text (read-string "Block entry: "))
8873 (unless (and d1 d2 (not (equal d1 d2)))
8874 (error "No block of days selected"))
8875 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8876 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8877 ((equal char ?j)
8878 (org-switch-to-buffer-other-window
8879 (find-file-noselect org-agenda-diary-file))
8880 (require 'org-datetree)
8881 (org-datetree-find-date-create d1)
8882 (org-reveal t))
8883 (t (error "Invalid selection character `%c'" char)))))
8885 (defcustom org-agenda-insert-diary-strategy 'date-tree
8886 "Where in `org-agenda-diary-file' should new entries be added?
8887 Valid values:
8889 date-tree in the date tree, as child of the date
8890 top-level as top-level entries at the end of the file."
8891 :group 'org-agenda
8892 :type '(choice
8893 (const :tag "in a date tree" date-tree)
8894 (const :tag "as top level at end of file" top-level)))
8896 (defcustom org-agenda-insert-diary-extract-time nil
8897 "Non-nil means extract any time specification from the diary entry."
8898 :group 'org-agenda
8899 :version "24.1"
8900 :type 'boolean)
8902 (defcustom org-agenda-bulk-mark-char ">"
8903 "A single-character string to be used as the bulk mark."
8904 :group 'org-agenda
8905 :version "24.1"
8906 :type 'string)
8908 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8909 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8910 If TEXT is not empty, it will become the headline of the new entry, and
8911 the resulting entry will not be shown. When TEXT is empty, switch to
8912 `org-agenda-diary-file' and let the user finish the entry there."
8913 (let ((cw (current-window-configuration)))
8914 (org-switch-to-buffer-other-window
8915 (find-file-noselect org-agenda-diary-file))
8916 (widen)
8917 (goto-char (point-min))
8918 (cond
8919 ((eq type 'anniversary)
8920 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8921 (progn
8922 (or (org-at-heading-p t)
8923 (progn
8924 (outline-next-heading)
8925 (insert "* Anniversaries\n\n")
8926 (beginning-of-line -1)))))
8927 (outline-next-heading)
8928 (org-back-over-empty-lines)
8929 (backward-char 1)
8930 (insert "\n")
8931 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8932 (nth 2 d1) (car d1) (nth 1 d1) text)))
8933 ((eq type 'day)
8934 (let ((org-prefix-has-time t)
8935 (org-agenda-time-leading-zero t)
8936 fmt time time2)
8937 (if org-agenda-insert-diary-extract-time
8938 ;; Use org-agenda-format-item to parse text for a time-range and
8939 ;; remove it. FIXME: This is a hack, we should refactor
8940 ;; that function to make time extraction available separately
8941 (setq fmt (org-agenda-format-item nil text nil nil nil t)
8942 time (get-text-property 0 'time fmt)
8943 time2 (if (> (length time) 0)
8944 ;; split-string removes trailing ...... if
8945 ;; no end time given. First space
8946 ;; separates time from date.
8947 (concat " " (car (split-string time "\\.")))
8948 nil)
8949 text (get-text-property 0 'txt fmt)))
8950 (if (eq org-agenda-insert-diary-strategy 'top-level)
8951 (org-agenda-insert-diary-as-top-level text)
8952 (require 'org-datetree)
8953 (org-datetree-find-date-create d1)
8954 (org-agenda-insert-diary-make-new-entry text))
8955 (org-insert-time-stamp (org-time-from-absolute
8956 (calendar-absolute-from-gregorian d1))
8957 nil nil nil nil time2))
8958 (end-of-line 0))
8959 ((eq type 'block)
8960 (if (> (calendar-absolute-from-gregorian d1)
8961 (calendar-absolute-from-gregorian d2))
8962 (setq d1 (prog1 d2 (setq d2 d1))))
8963 (if (eq org-agenda-insert-diary-strategy 'top-level)
8964 (org-agenda-insert-diary-as-top-level text)
8965 (require 'org-datetree)
8966 (org-datetree-find-date-create d1)
8967 (org-agenda-insert-diary-make-new-entry text))
8968 (org-insert-time-stamp (org-time-from-absolute
8969 (calendar-absolute-from-gregorian d1)))
8970 (insert "--")
8971 (org-insert-time-stamp (org-time-from-absolute
8972 (calendar-absolute-from-gregorian d2)))
8973 (end-of-line 0)))
8974 (if (string-match "\\S-" text)
8975 (progn
8976 (set-window-configuration cw)
8977 (message "%s entry added to %s"
8978 (capitalize (symbol-name type))
8979 (abbreviate-file-name org-agenda-diary-file)))
8980 (org-reveal t)
8981 (message "Please finish entry here"))))
8983 (defun org-agenda-insert-diary-as-top-level (text)
8984 "Make new entry as a top-level entry at the end of the file.
8985 Add TEXT as headline, and position the cursor in the second line so that
8986 a timestamp can be added there."
8987 (widen)
8988 (goto-char (point-max))
8989 (or (bolp) (insert "\n"))
8990 (insert "* " text "\n")
8991 (if org-adapt-indentation (org-indent-to-column 2)))
8993 (defun org-agenda-insert-diary-make-new-entry (text)
8994 "Make new entry as last child of current entry.
8995 Add TEXT as headline, and position the cursor in the second line so that
8996 a timestamp can be added there."
8997 (let ((org-show-following-heading t)
8998 (org-show-siblings t)
8999 (org-show-hierarchy-above t)
9000 (org-show-entry-below t)
9001 col)
9002 (outline-next-heading)
9003 (org-back-over-empty-lines)
9004 (or (looking-at "[ \t]*$")
9005 (progn (insert "\n") (backward-char 1)))
9006 (org-insert-heading nil t)
9007 (org-do-demote)
9008 (setq col (current-column))
9009 (insert text "\n")
9010 (if org-adapt-indentation (org-indent-to-column col))
9011 (let ((org-show-following-heading t)
9012 (org-show-siblings t)
9013 (org-show-hierarchy-above t)
9014 (org-show-entry-below t))
9015 (org-show-context))))
9017 (defun org-agenda-diary-entry ()
9018 "Make a diary entry, like the `i' command from the calendar.
9019 All the standard commands work: block, weekly etc.
9020 When `org-agenda-diary-file' points to a file,
9021 `org-agenda-diary-entry-in-org-file' is called instead to create
9022 entries in that Org-mode file."
9023 (interactive)
9024 (if (not (eq org-agenda-diary-file 'diary-file))
9025 (org-agenda-diary-entry-in-org-file)
9026 (require 'diary-lib)
9027 (let* ((char (progn
9028 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9029 (read-char-exclusive)))
9030 (cmd (cdr (assoc char
9031 '((?d . insert-diary-entry)
9032 (?w . insert-weekly-diary-entry)
9033 (?m . insert-monthly-diary-entry)
9034 (?y . insert-yearly-diary-entry)
9035 (?a . insert-anniversary-diary-entry)
9036 (?b . insert-block-diary-entry)
9037 (?c . insert-cyclic-diary-entry)))))
9038 (oldf (symbol-function 'calendar-cursor-to-date))
9039 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9040 (point (point))
9041 (mark (or (mark t) (point))))
9042 (unless cmd
9043 (error "No command associated with <%c>" char))
9044 (unless (and (get-text-property point 'day)
9045 (or (not (equal ?b char))
9046 (get-text-property mark 'day)))
9047 (error "Don't know which date to use for diary entry"))
9048 ;; We implement this by hacking the `calendar-cursor-to-date' function
9049 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9050 (let ((calendar-mark-ring
9051 (list (calendar-gregorian-from-absolute
9052 (or (get-text-property mark 'day)
9053 (get-text-property point 'day))))))
9054 (unwind-protect
9055 (progn
9056 (fset 'calendar-cursor-to-date
9057 (lambda (&optional error dummy)
9058 (calendar-gregorian-from-absolute
9059 (get-text-property point 'day))))
9060 (call-interactively cmd))
9061 (fset 'calendar-cursor-to-date oldf))))))
9063 (defun org-agenda-execute-calendar-command (cmd)
9064 "Execute a calendar command from the agenda with date from cursor."
9065 (org-agenda-check-type t 'agenda 'timeline)
9066 (require 'diary-lib)
9067 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9068 (error "Don't know which date to use for the calendar command"))
9069 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9070 (point (point))
9071 (date (calendar-gregorian-from-absolute
9072 (get-text-property point 'day)))
9073 ;; the following 2 vars are needed in the calendar
9074 (displayed-month (car date))
9075 (displayed-year (nth 2 date)))
9076 (unwind-protect
9077 (progn
9078 (fset 'calendar-cursor-to-date
9079 (lambda (&optional error dummy)
9080 (calendar-gregorian-from-absolute
9081 (get-text-property point 'day))))
9082 (call-interactively cmd))
9083 (fset 'calendar-cursor-to-date oldf))))
9085 (defun org-agenda-phases-of-moon ()
9086 "Display the phases of the moon for the 3 months around the cursor date."
9087 (interactive)
9088 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9090 (defun org-agenda-holidays ()
9091 "Display the holidays for the 3 months around the cursor date."
9092 (interactive)
9093 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9095 (defvar calendar-longitude) ; defined in calendar.el
9096 (defvar calendar-latitude) ; defined in calendar.el
9097 (defvar calendar-location-name) ; defined in calendar.el
9099 (defun org-agenda-sunrise-sunset (arg)
9100 "Display sunrise and sunset for the cursor date.
9101 Latitude and longitude can be specified with the variables
9102 `calendar-latitude' and `calendar-longitude'. When called with prefix
9103 argument, latitude and longitude will be prompted for."
9104 (interactive "P")
9105 (require 'solar)
9106 (let ((calendar-longitude (if arg nil calendar-longitude))
9107 (calendar-latitude (if arg nil calendar-latitude))
9108 (calendar-location-name
9109 (if arg "the given coordinates" calendar-location-name)))
9110 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9112 (defun org-agenda-goto-calendar ()
9113 "Open the Emacs calendar with the date at the cursor."
9114 (interactive)
9115 (org-agenda-check-type t 'agenda 'timeline)
9116 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9117 (error "Don't know which date to open in calendar")))
9118 (date (calendar-gregorian-from-absolute day))
9119 (calendar-move-hook nil)
9120 (calendar-view-holidays-initially-flag nil)
9121 (calendar-view-diary-initially-flag nil))
9122 (calendar)
9123 (calendar-goto-date date)))
9125 ;;;###autoload
9126 (defun org-calendar-goto-agenda ()
9127 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9128 This is a command that has to be installed in `calendar-mode-map'."
9129 (interactive)
9130 (org-agenda-list nil (calendar-absolute-from-gregorian
9131 (calendar-cursor-to-date))
9132 nil))
9134 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9135 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9136 This is a command that has to be installed in `calendar-mode-map'.
9138 \(fn)" t nil)
9140 (defun org-agenda-convert-date ()
9141 (interactive)
9142 (org-agenda-check-type t 'agenda 'timeline)
9143 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9144 date s)
9145 (unless day
9146 (error "Don't know which date to convert"))
9147 (setq date (calendar-gregorian-from-absolute day))
9148 (setq s (concat
9149 "Gregorian: " (calendar-date-string date) "\n"
9150 "ISO: " (calendar-iso-date-string date) "\n"
9151 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9152 "Julian: " (calendar-julian-date-string date) "\n"
9153 "Astron. JD: " (calendar-astro-date-string date)
9154 " (Julian date number at noon UTC)\n"
9155 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9156 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9157 "French: " (calendar-french-date-string date) "\n"
9158 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9159 "Mayan: " (calendar-mayan-date-string date) "\n"
9160 "Coptic: " (calendar-coptic-date-string date) "\n"
9161 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9162 "Persian: " (calendar-persian-date-string date) "\n"
9163 "Chinese: " (calendar-chinese-date-string date) "\n"))
9164 (with-output-to-temp-buffer "*Dates*"
9165 (princ s))
9166 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9168 ;;; Bulk commands
9170 (defun org-agenda-bulk-marked-p ()
9171 (eq (get-char-property (point-at-bol) 'type)
9172 'org-marked-entry-overlay))
9174 (defun org-agenda-bulk-mark (&optional arg)
9175 "Mark the entry at point for future bulk action."
9176 (interactive "p")
9177 (dotimes (i (or arg 1))
9178 (unless (org-get-at-bol 'org-agenda-diary-link)
9179 (let* ((m (org-get-at-bol 'org-hd-marker))
9181 (unless (org-agenda-bulk-marked-p)
9182 (unless m (error "Nothing to mark at point"))
9183 (push m org-agenda-bulk-marked-entries)
9184 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9185 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9186 (org-get-todo-face "TODO")
9187 'evaporate)
9188 (overlay-put ov 'type 'org-marked-entry-overlay))
9189 (beginning-of-line 2)
9190 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9191 (beginning-of-line 2))
9192 (message "%d entries marked for bulk action"
9193 (length org-agenda-bulk-marked-entries))))))
9195 (defun org-agenda-bulk-mark-all ()
9196 "Mark all entries for future agenda bulk action."
9197 (interactive)
9198 (org-agenda-bulk-mark-regexp "."))
9200 (defun org-agenda-bulk-mark-regexp (regexp)
9201 "Mark entries matching REGEXP for future agenda bulk action."
9202 (interactive "sMark entries matching regexp: ")
9203 (let ((entries-marked 0))
9204 (save-excursion
9205 (goto-char (point-min))
9206 (goto-char (next-single-property-change (point) 'txt))
9207 (while (re-search-forward regexp nil t)
9208 (when (string-match regexp (get-text-property (point) 'txt))
9209 (setq entries-marked (1+ entries-marked))
9210 (call-interactively 'org-agenda-bulk-mark))))
9211 (if (not entries-marked)
9212 (message "No entry matching this regexp."))))
9214 (defun org-agenda-bulk-unmark (&optional arg)
9215 "Unmark the entry at point for future bulk action."
9216 (interactive "P")
9217 (if arg
9218 (org-agenda-bulk-unmark-all)
9219 (cond ((org-agenda-bulk-marked-p)
9220 (org-agenda-bulk-remove-overlays
9221 (point-at-bol) (+ 2 (point-at-bol)))
9222 (setq org-agenda-bulk-marked-entries
9223 (delete (org-get-at-bol 'org-hd-marker)
9224 org-agenda-bulk-marked-entries))
9225 (beginning-of-line 2)
9226 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9227 (beginning-of-line 2))
9228 (message "%d entries left marked for bulk action"
9229 (length org-agenda-bulk-marked-entries)))
9230 (t (message "No entry to unmark here")))))
9232 (defun org-agenda-bulk-toggle ()
9233 "Toggle marking the entry at point for bulk action."
9234 (interactive)
9235 (if (org-agenda-bulk-marked-p)
9236 (org-agenda-bulk-unmark)
9237 (org-agenda-bulk-mark)))
9239 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9240 "Remove the mark overlays between BEG and END in the agenda buffer.
9241 BEG and END default to the buffer limits.
9243 This only removes the overlays, it does not remove the markers
9244 from the list in `org-agenda-bulk-marked-entries'."
9245 (interactive)
9246 (mapc (lambda (ov)
9247 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9248 (delete-overlay ov)))
9249 (overlays-in (or beg (point-min)) (or end (point-max)))))
9251 (defun org-agenda-bulk-unmark-all ()
9252 "Remove all marks in the agenda buffer.
9253 This will remove the markers and the overlays."
9254 (interactive)
9255 (if (null org-agenda-bulk-marked-entries)
9256 (message "No entry to unmark")
9257 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9258 (setq org-agenda-bulk-marked-entries nil)
9259 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9261 (defcustom org-agenda-persistent-marks nil
9262 "Non-nil means marked items will stay marked after a bulk action.
9263 You can toggle this interactively by typing `p' when prompted for a
9264 bulk action."
9265 :group 'org-agenda
9266 :version "24.1"
9267 :type 'boolean)
9269 (defun org-agenda-bulk-action (&optional arg)
9270 "Execute an remote-editing action on all marked entries.
9271 The prefix arg is passed through to the command if possible."
9272 (interactive "P")
9273 ;; Make sure we have markers, and only valid ones
9274 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9275 (mapc
9276 (lambda (m)
9277 (unless (and (markerp m)
9278 (marker-buffer m)
9279 (buffer-live-p (marker-buffer m))
9280 (marker-position m))
9281 (error "Marker %s for bulk command is invalid" m)))
9282 org-agenda-bulk-marked-entries)
9284 ;; Prompt for the bulk command
9285 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9286 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9287 "[S]catter [f]unction "
9288 (when org-agenda-bulk-custom-functions
9289 (concat " Custom: ["
9290 (mapconcat (lambda(f) (char-to-string (car f)))
9291 org-agenda-bulk-custom-functions "")
9292 "]"))))
9293 (catch 'exit
9294 (let* ((action (read-char-exclusive))
9295 (org-log-refile (if org-log-refile 'time nil))
9296 (entries (reverse org-agenda-bulk-marked-entries))
9297 (org-overriding-default-time
9298 (if (get-text-property (point) 'org-agenda-date-header)
9299 (org-get-cursor-date)))
9300 redo-at-end
9301 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9302 (cond
9303 ((equal action ?p)
9304 (let ((org-agenda-persistent-marks
9305 (not org-agenda-persistent-marks)))
9306 (org-agenda-bulk-action)
9307 (throw 'exit nil)))
9309 ((equal action ?$)
9310 (setq cmd '(org-agenda-archive)))
9312 ((equal action ?A)
9313 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9315 ((member action '(?r ?w))
9316 (setq rfloc (org-refile-get-location
9317 "Refile to"
9318 (marker-buffer (car entries))
9319 org-refile-allow-creating-parent-nodes))
9320 (if (nth 3 rfloc)
9321 (setcar (nthcdr 3 rfloc)
9322 (move-marker (make-marker) (nth 3 rfloc)
9323 (or (get-file-buffer (nth 1 rfloc))
9324 (find-buffer-visiting (nth 1 rfloc))
9325 (error "This should not happen")))))
9327 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9328 redo-at-end t))
9330 ((equal action ?t)
9331 (setq state (org-icompleting-read
9332 "Todo state: "
9333 (with-current-buffer (marker-buffer (car entries))
9334 (mapcar 'list org-todo-keywords-1))))
9335 (setq cmd `(let ((org-inhibit-blocking t)
9336 (org-inhibit-logging 'note))
9337 (org-agenda-todo ,state))))
9339 ((memq action '(?- ?+))
9340 (setq tag (org-icompleting-read
9341 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9342 (with-current-buffer (marker-buffer (car entries))
9343 (delq nil
9344 (mapcar (lambda (x)
9345 (if (stringp (car x)) x)) org-tag-alist)))))
9346 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9348 ((memq action '(?s ?d))
9349 (let* ((time
9350 (unless arg
9351 (org-read-date
9352 nil nil nil
9353 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9354 org-overriding-default-time)))
9355 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9356 (setq cmd `(eval '(,c1 arg ,time)))))
9358 ((equal action ?S)
9359 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9360 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9361 (let ((days (read-number
9362 (format "Scatter tasks across how many %sdays: "
9363 (if arg "week" "")) 7)))
9364 (setq cmd
9365 `(let ((distance (1+ (random ,days))))
9366 (if arg
9367 (let ((dist distance)
9368 (day-of-week
9369 (calendar-day-of-week
9370 (calendar-gregorian-from-absolute (org-today)))))
9371 (dotimes (i (1+ dist))
9372 (while (member day-of-week org-agenda-weekend-days)
9373 (incf distance)
9374 (incf day-of-week)
9375 (if (= day-of-week 7)
9376 (setq day-of-week 0)))
9377 (incf day-of-week)
9378 (if (= day-of-week 7)
9379 (setq day-of-week 0)))))
9380 ;; silently fail when try to replan a sexp entry
9381 (condition-case nil
9382 (let* ((date (calendar-gregorian-from-absolute
9383 (+ (org-today) distance)))
9384 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9385 (nth 2 date))))
9386 (org-agenda-schedule nil time))
9387 (error nil)))))))
9389 ((assoc action org-agenda-bulk-custom-functions)
9390 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9391 redo-at-end t))
9393 ((equal action ?f)
9394 (setq cmd (list (intern
9395 (org-icompleting-read "Function: "
9396 obarray 'fboundp t nil nil)))))
9398 (t (error "Invalid bulk action")))
9400 ;; Sort the markers, to make sure that parents are handled before children
9401 (setq entries (sort entries
9402 (lambda (a b)
9403 (cond
9404 ((equal (marker-buffer a) (marker-buffer b))
9405 (< (marker-position a) (marker-position b)))
9407 (string< (buffer-name (marker-buffer a))
9408 (buffer-name (marker-buffer b))))))))
9410 ;; Now loop over all markers and apply cmd
9411 (while (setq e (pop entries))
9412 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9413 (if (not pos)
9414 (progn (message "Skipping removed entry at %s" e)
9415 (setq cntskip (1+ cntskip)))
9416 (goto-char pos)
9417 (let (org-loop-over-headlines-in-active-region)
9418 (eval cmd))
9419 (setq cnt (1+ cnt))))
9420 (when redo-at-end (org-agenda-redo))
9421 (unless org-agenda-persistent-marks
9422 (org-agenda-bulk-unmark-all))
9423 (message "Acted on %d entries%s%s"
9425 (if (= cntskip 0)
9427 (format ", skipped %d (disappeared before their turn)"
9428 cntskip))
9429 (if (not org-agenda-persistent-marks)
9430 "" " (kept marked)"))))))
9432 (defun org-agenda-capture (&optional with-time)
9433 "Call `org-capture' with the date at point.
9434 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9435 current HH:MM time."
9436 (interactive "P")
9437 (if (not (eq major-mode 'org-agenda-mode))
9438 (user-error "You cannot do this outside of agenda buffers")
9439 (let ((org-overriding-default-time
9440 (org-get-cursor-date (equal with-time 1))))
9441 (call-interactively 'org-capture))))
9443 ;;; Flagging notes
9445 (defun org-agenda-show-the-flagging-note ()
9446 "Display the flagging note in the other window.
9447 When called a second time in direct sequence, offer to remove the FLAGGING
9448 tag and (if present) the flagging note."
9449 (interactive)
9450 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9451 (win (selected-window))
9452 note heading newhead)
9453 (unless hdmarker
9454 (error "No linked entry at point"))
9455 (if (and (eq this-command last-command)
9456 (y-or-n-p "Unflag and remove any flagging note? "))
9457 (progn
9458 (org-agenda-remove-flag hdmarker)
9459 (let ((win (get-buffer-window "*Flagging Note*")))
9460 (and win (delete-window win)))
9461 (message "Entry unflagged"))
9462 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9463 (unless note
9464 (error "No flagging note"))
9465 (org-kill-new note)
9466 (org-switch-to-buffer-other-window "*Flagging Note*")
9467 (erase-buffer)
9468 (insert note)
9469 (goto-char (point-min))
9470 (while (re-search-forward "\\\\n" nil t)
9471 (replace-match "\n" t t))
9472 (goto-char (point-min))
9473 (select-window win)
9474 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9476 (defun org-agenda-remove-flag (marker)
9477 "Remove the FLAGGED tag and any flagging note in the entry."
9478 (let (newhead)
9479 (org-with-point-at marker
9480 (org-toggle-tag "FLAGGED" 'off)
9481 (org-entry-delete nil "THEFLAGGINGNOTE")
9482 (setq newhead (org-get-heading)))
9483 (org-agenda-change-all-lines newhead marker)
9484 (message "Entry unflagged")))
9486 (defun org-agenda-get-any-marker (&optional pos)
9487 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9488 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9490 ;;; Appointment reminders
9492 (defvar appt-time-msg-list) ; defined in appt.el
9494 ;;;###autoload
9495 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9496 "Activate appointments found in `org-agenda-files'.
9497 With a \\[universal-argument] prefix, refresh the list of
9498 appointments.
9500 If FILTER is t, interactively prompt the user for a regular
9501 expression, and filter out entries that don't match it.
9503 If FILTER is a string, use this string as a regular expression
9504 for filtering entries out.
9506 If FILTER is a function, filter out entries against which
9507 calling the function returns nil. This function takes one
9508 argument: an entry from `org-agenda-get-day-entries'.
9510 FILTER can also be an alist with the car of each cell being
9511 either 'headline or 'category. For example:
9513 '((headline \"IMPORTANT\")
9514 (category \"Work\"))
9516 will only add headlines containing IMPORTANT or headlines
9517 belonging to the \"Work\" category.
9519 ARGS are symbols indicating what kind of entries to consider.
9520 By default `org-agenda-to-appt' will use :deadline, :scheduled
9521 and :timestamp entries. See the docstring of `org-diary' for
9522 details and examples.
9524 If an entry as a APPT_WARNTIME property, its value will be used
9525 to override `appt-message-warning-time'."
9526 (interactive "P")
9527 (if refresh (setq appt-time-msg-list nil))
9528 (if (eq filter t)
9529 (setq filter (read-from-minibuffer "Regexp filter: ")))
9530 (let* ((cnt 0) ; count added events
9531 (scope (or args '(:deadline :scheduled :timestamp)))
9532 (org-agenda-new-buffers nil)
9533 (org-deadline-warning-days 0)
9534 ;; Do not use `org-today' here because appt only takes
9535 ;; time and without date as argument, so it may pass wrong
9536 ;; information otherwise
9537 (today (org-date-to-gregorian
9538 (time-to-days (current-time))))
9539 (org-agenda-restrict nil)
9540 (files (org-agenda-files 'unrestricted)) entries file
9541 (org-agenda-buffer nil))
9542 ;; Get all entries which may contain an appt
9543 (org-agenda-prepare-buffers files)
9544 (while (setq file (pop files))
9545 (setq entries
9546 (delq nil
9547 (append entries
9548 (apply 'org-agenda-get-day-entries
9549 file today scope)))))
9550 ;; Map thru entries and find if we should filter them out
9551 (mapc
9552 (lambda(x)
9553 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9554 (cat (get-text-property 1 'org-category x))
9555 (tod (get-text-property 1 'time-of-day x))
9556 (ok (or (null filter)
9557 (and (stringp filter) (string-match filter evt))
9558 (and (functionp filter) (funcall filter x))
9559 (and (listp filter)
9560 (let ((cat-filter (cadr (assoc 'category filter)))
9561 (evt-filter (cadr (assoc 'headline filter))))
9562 (or (and (stringp cat-filter)
9563 (string-match cat-filter cat))
9564 (and (stringp evt-filter)
9565 (string-match evt-filter evt)))))))
9566 (wrn (get-text-property 1 'warntime x)))
9567 ;; FIXME: Shall we remove text-properties for the appt text?
9568 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9569 (when (and ok tod)
9570 (setq tod (concat "00" (number-to-string tod))
9571 tod (when (string-match
9572 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9573 (concat (match-string 1 tod) ":"
9574 (match-string 2 tod))))
9575 (if (version< emacs-version "23.3")
9576 (appt-add tod evt)
9577 (appt-add tod evt wrn))
9578 (setq cnt (1+ cnt))))) entries)
9579 (org-release-buffers org-agenda-new-buffers)
9580 (if (eq cnt 0)
9581 (message "No event to add")
9582 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9584 (autoload 'org-agenda-to-appt "org-agenda" "\
9585 Activate appointments found in `org-agenda-files'.
9586 With a \\[universal-argument] prefix, refresh the list of
9587 appointments.
9589 If FILTER is t, interactively prompt the user for a regular
9590 expression, and filter out entries that don't match it.
9592 If FILTER is a string, use this string as a regular expression
9593 for filtering entries out.
9595 If FILTER is a function, filter out entries against which
9596 calling the function returns nil. This function takes one
9597 argument: an entry from `org-agenda-get-day-entries'.
9599 FILTER can also be an alist with the car of each cell being
9600 either 'headline or 'category. For example:
9602 '((headline \"IMPORTANT\")
9603 (category \"Work\"))
9605 will only add headlines containing IMPORTANT or headlines
9606 belonging to the \"Work\" category.
9608 ARGS are symbols indicating what kind of entries to consider.
9609 By default `org-agenda-to-appt' will use :deadline, :scheduled
9610 and :timestamp entries. See the docstring of `org-diary' for
9611 details and examples.
9613 If an entry as a APPT_WARNTIME property, its value will be used
9614 to override `appt-message-warning-time'.
9616 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9618 (defun org-agenda-todayp (date)
9619 "Does DATE mean today, when considering `org-extend-today-until'?"
9620 (let ((today (org-today))
9621 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9622 date)))
9623 (eq date today)))
9625 (defun org-agenda-todo-yesterday (&optional arg)
9626 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9627 (interactive "P")
9628 (let* ((hour (third (decode-time
9629 (org-current-time))))
9630 (org-extend-today-until (1+ hour)))
9631 (org-agenda-todo arg)))
9633 (provide 'org-agenda)
9635 ;;; org-agenda.el ends here