org.el: Fix bug about filling message headers and citations
[org-mode.git] / lisp / org-agenda.el
blobc29f3508be93050e6b393af83bf2944054e2704a
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
87 (defvar calendar-mode-map)
88 (defvar org-clock-current-task) ; defined in org-clock.el
89 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
90 (defvar org-habit-show-habits)
91 (defvar org-habit-show-habits-only-for-today)
92 (defvar org-habit-show-all-today nil)
94 ;; Defined somewhere in this file, but used before definition.
95 (defvar org-agenda-buffer-name)
96 (defvar org-agenda-overriding-header)
97 (defvar org-agenda-title-append nil)
98 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
99 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
100 (defvar org-agenda-undo-list)
101 (defvar org-agenda-pending-undo-list)
102 (defvar original-date) ; dynamically scoped, calendar.el does scope this
104 (defcustom org-agenda-confirm-kill 1
105 "When set, remote killing from the agenda buffer needs confirmation.
106 When t, a confirmation is always needed. When a number N, confirmation is
107 only needed when the text to be killed contains more than N non-white lines."
108 :group 'org-agenda
109 :type '(choice
110 (const :tag "Never" nil)
111 (const :tag "Always" t)
112 (integer :tag "When more than N lines")))
114 (defcustom org-agenda-compact-blocks nil
115 "Non-nil means make the block agenda more compact.
116 This is done globally by leaving out lines like the agenda span
117 name and week number or the separator lines."
118 :group 'org-agenda
119 :type 'boolean)
121 (defcustom org-agenda-block-separator ?=
122 "The separator between blocks in the agenda.
123 If this is a string, it will be used as the separator, with a newline added.
124 If it is a character, it will be repeated to fill the window width.
125 If nil the separator is disabled. In `org-agenda-custom-commands' this
126 addresses the separator between the current and the previous block."
127 :group 'org-agenda
128 :type '(choice
129 (const :tag "Disabled" nil)
130 (character)
131 (string)))
133 (defgroup org-agenda-export nil
134 "Options concerning exporting agenda views in Org-mode."
135 :tag "Org Agenda Export"
136 :group 'org-agenda)
138 (defcustom org-agenda-with-colors t
139 "Non-nil means use colors in agenda views."
140 :group 'org-agenda-export
141 :type 'boolean)
143 (defcustom org-agenda-exporter-settings nil
144 "Alist of variable/value pairs that should be active during agenda export.
145 This is a good place to set options for ps-print and for htmlize.
146 Note that the way this is implemented, the values will be evaluated
147 before assigned to the variables. So make sure to quote values you do
148 *not* want evaluated, for example
150 (setq org-agenda-exporter-settings
151 '((ps-print-color-p 'black-white)))"
152 :group 'org-agenda-export
153 :type '(repeat
154 (list
155 (variable)
156 (sexp :tag "Value"))))
158 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
159 "Hook run in temporary buffer before writing it to an export file.
160 A useful function is `org-agenda-add-entry-text'."
161 :group 'org-agenda-export
162 :type 'hook
163 :options '(org-agenda-add-entry-text))
165 (defcustom org-agenda-add-entry-text-maxlines 0
166 "Maximum number of entry text lines to be added to agenda.
167 This is only relevant when `org-agenda-add-entry-text' is part of
168 `org-agenda-before-write-hook', which it is by default.
169 When this is 0, nothing will happen. When it is greater than 0, it
170 specifies the maximum number of lines that will be added for each entry
171 that is listed in the agenda view.
173 Note that this variable is not used during display, only when exporting
174 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
175 and `org-agenda-entry-text-maxlines'."
176 :group 'org-agenda
177 :type 'integer)
179 (defcustom org-agenda-add-entry-text-descriptive-links t
180 "Non-nil means export org-links as descriptive links in agenda added text.
181 This variable applies to the text added to the agenda when
182 `org-agenda-add-entry-text-maxlines' is larger than 0.
183 When this variable nil, the URL will (also) be shown."
184 :group 'org-agenda
185 :type 'boolean)
187 (defcustom org-agenda-export-html-style ""
188 "The style specification for exported HTML Agenda files.
189 If this variable contains a string, it will replace the default <style>
190 section as produced by `htmlize'.
191 Since there are different ways of setting style information, this variable
192 needs to contain the full HTML structure to provide a style, including the
193 surrounding HTML tags. The style specifications should include definitions
194 the fonts used by the agenda, here is an example:
196 <style type=\"text/css\">
197 p { font-weight: normal; color: gray; }
198 .org-agenda-structure {
199 font-size: 110%;
200 color: #003399;
201 font-weight: 600;
203 .org-todo {
204 color: #cc6666;
205 font-weight: bold;
207 .org-agenda-done {
208 color: #339933;
210 .org-done {
211 color: #339933;
213 .title { text-align: center; }
214 .todo, .deadline { color: red; }
215 .done { color: green; }
216 </style>
218 or, if you want to keep the style in a file,
220 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
222 As the value of this option simply gets inserted into the HTML <head> header,
223 you can \"misuse\" it to also add other text to the header. However,
224 <style>...</style> is required, if not present the variable will be ignored."
225 :group 'org-agenda-export
226 :group 'org-export-html
227 :type 'string)
229 (defcustom org-agenda-persistent-filter nil
230 "When set, keep filters from one agenda view to the next."
231 :group 'org-agenda
232 :type 'boolean)
234 (defgroup org-agenda-custom-commands nil
235 "Options concerning agenda views in Org-mode."
236 :tag "Org Agenda Custom Commands"
237 :group 'org-agenda)
239 (defconst org-sorting-choice
240 '(choice
241 (const time-up) (const time-down)
242 (const category-keep) (const category-up) (const category-down)
243 (const tag-down) (const tag-up)
244 (const priority-up) (const priority-down)
245 (const todo-state-up) (const todo-state-down)
246 (const effort-up) (const effort-down)
247 (const habit-up) (const habit-down)
248 (const alpha-up) (const alpha-down)
249 (const user-defined-up) (const user-defined-down))
250 "Sorting choices.")
252 ;; Keep custom values for `org-agenda-filter-preset' compatible with
253 ;; the new variable `org-agenda-tag-filter-preset'.
254 (if (fboundp 'defvaralias)
255 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
256 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
258 (defconst org-agenda-custom-commands-local-options
259 `(repeat :tag "Local settings for this command. Remember to quote values"
260 (choice :tag "Setting"
261 (list :tag "Heading for this block"
262 (const org-agenda-overriding-header)
263 (string :tag "Headline"))
264 (list :tag "Files to be searched"
265 (const org-agenda-files)
266 (list
267 (const :format "" quote)
268 (repeat (file))))
269 (list :tag "Sorting strategy"
270 (const org-agenda-sorting-strategy)
271 (list
272 (const :format "" quote)
273 (repeat
274 ,org-sorting-choice)))
275 (list :tag "Prefix format"
276 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
277 (string))
278 (list :tag "Number of days in agenda"
279 (const org-agenda-span)
280 (choice (const :tag "Day" 'day)
281 (const :tag "Week" 'week)
282 (const :tag "Month" 'month)
283 (const :tag "Year" 'year)
284 (integer :tag "Custom")))
285 (list :tag "Fixed starting date"
286 (const org-agenda-start-day)
287 (string :value "2007-11-01"))
288 (list :tag "Start on day of week"
289 (const org-agenda-start-on-weekday)
290 (choice :value 1
291 (const :tag "Today" nil)
292 (integer :tag "Weekday No.")))
293 (list :tag "Include data from diary"
294 (const org-agenda-include-diary)
295 (boolean))
296 (list :tag "Deadline Warning days"
297 (const org-deadline-warning-days)
298 (integer :value 1))
299 (list :tag "Category filter preset"
300 (const org-agenda-category-filter-preset)
301 (list
302 (const :format "" quote)
303 (repeat
304 (string :tag "+category or -category"))))
305 (list :tag "Tags filter preset"
306 (const org-agenda-tag-filter-preset)
307 (list
308 (const :format "" quote)
309 (repeat
310 (string :tag "+tag or -tag"))))
311 (list :tag "Set daily/weekly entry types"
312 (const org-agenda-entry-types)
313 (list
314 (const :format "" quote)
315 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
316 (const :deadline)
317 (const :scheduled)
318 (const :timestamp)
319 (const :sexp))))
320 (list :tag "Standard skipping condition"
321 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
322 (const org-agenda-skip-function)
323 (list
324 (const :format "" quote)
325 (list
326 (choice
327 :tag "Skipping range"
328 (const :tag "Skip entry" org-agenda-skip-entry-if)
329 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
330 (repeat :inline t :tag "Conditions for skipping"
331 (choice
332 :tag "Condition type"
333 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
334 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
335 (list :tag "TODO state is" :inline t
336 (const 'todo)
337 (choice
338 (const :tag "any not-done state" 'todo)
339 (const :tag "any done state" 'done)
340 (const :tag "any state" 'any)
341 (list :tag "Keyword list"
342 (const :format "" quote)
343 (repeat (string :tag "Keyword")))))
344 (list :tag "TODO state is not" :inline t
345 (const 'nottodo)
346 (choice
347 (const :tag "any not-done state" 'todo)
348 (const :tag "any done state" 'done)
349 (const :tag "any state" 'any)
350 (list :tag "Keyword list"
351 (const :format "" quote)
352 (repeat (string :tag "Keyword")))))
353 (const :tag "scheduled" 'scheduled)
354 (const :tag "not scheduled" 'notscheduled)
355 (const :tag "deadline" 'deadline)
356 (const :tag "no deadline" 'notdeadline)
357 (const :tag "timestamp" 'timestamp)
358 (const :tag "no timestamp" 'nottimestamp))))))
359 (list :tag "Non-standard skipping condition"
360 :value (org-agenda-skip-function)
361 (const org-agenda-skip-function)
362 (sexp :tag "Function or form (quoted!)"))
363 (list :tag "Any variable"
364 (variable :tag "Variable")
365 (sexp :tag "Value (sexp)"))))
366 "Selection of examples for agenda command settings.
367 This will be spliced into the custom type of
368 `org-agenda-custom-commands'.")
371 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
372 ((agenda "") (alltodo))))
373 "Custom commands for the agenda.
374 These commands will be offered on the splash screen displayed by the
375 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
377 (key desc type match settings files)
379 key The key (one or more characters as a string) to be associated
380 with the command.
381 desc A description of the command, when omitted or nil, a default
382 description is built using MATCH.
383 type The command type, any of the following symbols:
384 agenda The daily/weekly agenda.
385 todo Entries with a specific TODO keyword, in all agenda files.
386 search Entries containing search words entry or headline.
387 tags Tags/Property/TODO match in all agenda files.
388 tags-todo Tags/P/T match in all agenda files, TODO entries only.
389 todo-tree Sparse tree of specific TODO keyword in *current* file.
390 tags-tree Sparse tree with all tags matches in *current* file.
391 occur-tree Occur sparse tree for *current* file.
392 ... A user-defined function.
393 match What to search for:
394 - a single keyword for TODO keyword searches
395 - a tags match expression for tags searches
396 - a word search expression for text searches.
397 - a regular expression for occur searches
398 For all other commands, this should be the empty string.
399 settings A list of option settings, similar to that in a let form, so like
400 this: ((opt1 val1) (opt2 val2) ...). The values will be
401 evaluated at the moment of execution, so quote them when needed.
402 files A list of files file to write the produced agenda buffer to
403 with the command `org-store-agenda-views'.
404 If a file name ends in \".html\", an HTML version of the buffer
405 is written out. If it ends in \".ps\", a postscript version is
406 produced. Otherwise, only the plain text is written to the file.
408 You can also define a set of commands, to create a composite agenda buffer.
409 In this case, an entry looks like this:
411 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
413 where
415 desc A description string to be displayed in the dispatcher menu.
416 cmd An agenda command, similar to the above. However, tree commands
417 are not allowed, but instead you can get agenda and global todo list.
418 So valid commands for a set are:
419 (agenda \"\" settings)
420 (alltodo \"\" settings)
421 (stuck \"\" settings)
422 (todo \"match\" settings files)
423 (search \"match\" settings files)
424 (tags \"match\" settings files)
425 (tags-todo \"match\" settings files)
427 Each command can carry a list of options, and another set of options can be
428 given for the whole set of commands. Individual command options take
429 precedence over the general options.
431 When using several characters as key to a command, the first characters
432 are prefix commands. For the dispatcher to display useful information, you
433 should provide a description for the prefix, like
435 (setq org-agenda-custom-commands
436 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
437 (\"hl\" tags \"+HOME+Lisa\")
438 (\"hp\" tags \"+HOME+Peter\")
439 (\"hk\" tags \"+HOME+Kim\")))"
440 :group 'org-agenda-custom-commands
441 :type `(repeat
442 (choice :value ("x" "Describe command here" tags "" nil)
443 (list :tag "Single command"
444 (string :tag "Access Key(s) ")
445 (option (string :tag "Description"))
446 (choice
447 (const :tag "Agenda" agenda)
448 (const :tag "TODO list" alltodo)
449 (const :tag "Search words" search)
450 (const :tag "Stuck projects" stuck)
451 (const :tag "Tags/Property match (all agenda files)" tags)
452 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
453 (const :tag "TODO keyword search (all agenda files)" todo)
454 (const :tag "Tags sparse tree (current buffer)" tags-tree)
455 (const :tag "TODO keyword tree (current buffer)" todo-tree)
456 (const :tag "Occur tree (current buffer)" occur-tree)
457 (sexp :tag "Other, user-defined function"))
458 (string :tag "Match (only for some commands)")
459 ,org-agenda-custom-commands-local-options
460 (option (repeat :tag "Export" (file :tag "Export to"))))
461 (list :tag "Command series, all agenda files"
462 (string :tag "Access Key(s)")
463 (string :tag "Description ")
464 (repeat :tag "Component"
465 (choice
466 (list :tag "Agenda"
467 (const :format "" agenda)
468 (const :tag "" :format "" "")
469 ,org-agenda-custom-commands-local-options)
470 (list :tag "TODO list (all keywords)"
471 (const :format "" alltodo)
472 (const :tag "" :format "" "")
473 ,org-agenda-custom-commands-local-options)
474 (list :tag "Search words"
475 (const :format "" search)
476 (string :tag "Match")
477 ,org-agenda-custom-commands-local-options)
478 (list :tag "Stuck projects"
479 (const :format "" stuck)
480 (const :tag "" :format "" "")
481 ,org-agenda-custom-commands-local-options)
482 (list :tag "Tags search"
483 (const :format "" tags)
484 (string :tag "Match")
485 ,org-agenda-custom-commands-local-options)
486 (list :tag "Tags search, TODO entries only"
487 (const :format "" tags-todo)
488 (string :tag "Match")
489 ,org-agenda-custom-commands-local-options)
490 (list :tag "TODO keyword search"
491 (const :format "" todo)
492 (string :tag "Match")
493 ,org-agenda-custom-commands-local-options)
494 (list :tag "Other, user-defined function"
495 (symbol :tag "function")
496 (string :tag "Match")
497 ,org-agenda-custom-commands-local-options)))
499 (repeat :tag "Settings for entire command set"
500 (list (variable :tag "Any variable")
501 (sexp :tag "Value")))
502 (option (repeat :tag "Export" (file :tag "Export to"))))
503 (cons :tag "Prefix key documentation"
504 (string :tag "Access Key(s)")
505 (string :tag "Description ")))))
507 (defcustom org-agenda-query-register ?o
508 "The register holding the current query string.
509 The purpose of this is that if you construct a query string interactively,
510 you can then use it to define a custom command."
511 :group 'org-agenda-custom-commands
512 :type 'character)
514 (defcustom org-stuck-projects
515 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
516 "How to identify stuck projects.
517 This is a list of four items:
518 1. A tags/todo/property matcher string that is used to identify a project.
519 See the manual for a description of tag and property searches.
520 The entire tree below a headline matched by this is considered one project.
521 2. A list of TODO keywords identifying non-stuck projects.
522 If the project subtree contains any headline with one of these todo
523 keywords, the project is considered to be not stuck. If you specify
524 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
525 3. A list of tags identifying non-stuck projects.
526 If the project subtree contains any headline with one of these tags,
527 the project is considered to be not stuck. If you specify \"*\" as
528 a tag, any tag will mark the project unstuck. Note that this is about
529 the explicit presence of a tag somewhere in the subtree, inherited
530 tags to not count here. If inherited tags make a project not stuck,
531 use \"-TAG\" in the tags part of the matcher under (1.) above.
532 4. An arbitrary regular expression matching non-stuck projects.
534 If the project turns out to be not stuck, search continues also in the
535 subtree to see if any of the subtasks have project status.
537 See also the variable `org-tags-match-list-sublevels' which applies
538 to projects matched by this search as well.
540 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
541 or `C-c a #' to produce the list."
542 :group 'org-agenda-custom-commands
543 :type '(list
544 (string :tag "Tags/TODO match to identify a project")
545 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
546 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
547 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
549 (defcustom org-agenda-filter-effort-default-operator "<"
550 "The default operator for effort estimate filtering.
551 If you select an effort estimate limit without first pressing an operator,
552 this one will be used."
553 :group 'org-agenda-custom-commands
554 :type '(choice (const :tag "less or equal" "<")
555 (const :tag "greater or equal"">")
556 (const :tag "equal" "=")))
558 (defgroup org-agenda-skip nil
559 "Options concerning skipping parts of agenda files."
560 :tag "Org Agenda Skip"
561 :group 'org-agenda)
563 (defcustom org-agenda-skip-function-global nil
564 "Function to be called at each match during agenda construction.
565 If this function returns nil, the current match should not be skipped.
566 If the function decided to skip an agenda match, is must return the
567 buffer position from which the search should be continued.
568 This may also be a Lisp form, which will be evaluated.
570 This variable will be applied to every agenda match, including
571 tags/property searches and TODO lists. So try to make the test function
572 do its checking as efficiently as possible. To implement a skipping
573 condition just for specific agenda commands, use the variable
574 `org-agenda-skip-function' which can be set in the options section
575 of custom agenda commands."
576 :group 'org-agenda-skip
577 :type 'sexp)
579 (defgroup org-agenda-daily/weekly nil
580 "Options concerning the daily/weekly agenda."
581 :tag "Org Agenda Daily/Weekly"
582 :group 'org-agenda)
583 (defgroup org-agenda-todo-list nil
584 "Options concerning the global todo list agenda view."
585 :tag "Org Agenda Todo List"
586 :group 'org-agenda)
587 (defgroup org-agenda-match-view nil
588 "Options concerning the general tags/property/todo match agenda view."
589 :tag "Org Agenda Match View"
590 :group 'org-agenda)
591 (defgroup org-agenda-search-view nil
592 "Options concerning the general tags/property/todo match agenda view."
593 :tag "Org Agenda Match View"
594 :group 'org-agenda)
596 (defvar org-agenda-archives-mode nil
597 "Non-nil means the agenda will include archived items.
598 If this is the symbol `trees', trees in the selected agenda scope
599 that are marked with the ARCHIVE tag will be included anyway. When this is
600 t, also all archive files associated with the current selection of agenda
601 files will be included.")
603 (defcustom org-agenda-skip-comment-trees t
604 "Non-nil means skip trees that start with the COMMENT keyword.
605 When nil, these trees are also scanned by agenda commands."
606 :group 'org-agenda-skip
607 :type 'boolean)
609 (defcustom org-agenda-todo-list-sublevels t
610 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
611 When nil, the sublevels of a TODO entry are not checked, resulting in
612 potentially much shorter TODO lists."
613 :group 'org-agenda-skip
614 :group 'org-agenda-todo-list
615 :type 'boolean)
617 (defcustom org-agenda-todo-ignore-with-date nil
618 "Non-nil means don't show entries with a date in the global todo list.
619 You can use this if you prefer to mark mere appointments with a TODO keyword,
620 but don't want them to show up in the TODO list.
621 When this is set, it also covers deadlines and scheduled items, the settings
622 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
623 will be ignored.
624 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
625 :group 'org-agenda-skip
626 :group 'org-agenda-todo-list
627 :type 'boolean)
629 (defcustom org-agenda-todo-ignore-timestamp nil
630 "Non-nil means don't show entries with a timestamp.
631 This applies when creating the global todo list.
632 Valid values are:
634 past Don't show entries for today or in the past.
636 future Don't show entries with a timestamp in the future.
637 The idea behind this is that if it has a future
638 timestamp, you don't want to think about it until the
639 date.
641 all Don't show any entries with a timestamp in the global todo list.
642 The idea behind this is that by setting a timestamp, you
643 have already \"taken care\" of this item.
645 This variable can also have an integer as a value. If positive (N),
646 todos with a timestamp N or more days in the future will be ignored. If
647 negative (-N), todos with a timestamp N or more days in the past will be
648 ignored. If 0, todos with a timestamp either today or in the future will
649 be ignored. For example, a value of -1 will exclude todos with a
650 timestamp in the past (yesterday or earlier), while a value of 7 will
651 exclude todos with a timestamp a week or more in the future.
653 See also `org-agenda-todo-ignore-with-date'.
654 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
655 to make his option also apply to the tags-todo list."
656 :group 'org-agenda-skip
657 :group 'org-agenda-todo-list
658 :version "24.1"
659 :type '(choice
660 (const :tag "Ignore future timestamp todos" future)
661 (const :tag "Ignore past or present timestamp todos" past)
662 (const :tag "Ignore all timestamp todos" all)
663 (const :tag "Show timestamp todos" nil)
664 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
666 (defcustom org-agenda-todo-ignore-scheduled nil
667 "Non-nil means, ignore some scheduled TODO items when making TODO list.
668 This applies when creating the global todo list.
669 Valid values are:
671 past Don't show entries scheduled today or in the past.
673 future Don't show entries scheduled in the future.
674 The idea behind this is that by scheduling it, you don't want to
675 think about it until the scheduled date.
677 all Don't show any scheduled entries in the global todo list.
678 The idea behind this is that by scheduling it, you have already
679 \"taken care\" of this item.
681 t Same as `all', for backward compatibility.
683 This variable can also have an integer as a value. See
684 `org-agenda-todo-ignore-timestamp' for more details.
686 See also `org-agenda-todo-ignore-with-date'.
687 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
688 to make his option also apply to the tags-todo list."
689 :group 'org-agenda-skip
690 :group 'org-agenda-todo-list
691 :type '(choice
692 (const :tag "Ignore future-scheduled todos" future)
693 (const :tag "Ignore past- or present-scheduled todos" past)
694 (const :tag "Ignore all scheduled todos" all)
695 (const :tag "Ignore all scheduled todos (compatibility)" t)
696 (const :tag "Show scheduled todos" nil)
697 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
699 (defcustom org-agenda-todo-ignore-deadlines nil
700 "Non-nil means ignore some deadlined TODO items when making TODO list.
701 There are different motivations for using different values, please think
702 carefully when configuring this variable.
704 This applies when creating the global todo list.
705 Valid values are:
707 near Don't show near deadline entries. A deadline is near when it is
708 closer than `org-deadline-warning-days' days. The idea behind this
709 is that such items will appear in the agenda anyway.
711 far Don't show TODO entries where a deadline has been defined, but
712 the deadline is not near. This is useful if you don't want to
713 use the todo list to figure out what to do now.
715 past Don't show entries with a deadline timestamp for today or in the past.
717 future Don't show entries with a deadline timestamp in the future, not even
718 when they become `near' ones. Use it with caution.
720 all Ignore all TODO entries that do have a deadline.
722 t Same as `near', for backward compatibility.
724 This variable can also have an integer as a value. See
725 `org-agenda-todo-ignore-timestamp' for more details.
727 See also `org-agenda-todo-ignore-with-date'.
728 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
729 to make his option also apply to the tags-todo list."
730 :group 'org-agenda-skip
731 :group 'org-agenda-todo-list
732 :type '(choice
733 (const :tag "Ignore near deadlines" near)
734 (const :tag "Ignore near deadlines (compatibility)" t)
735 (const :tag "Ignore far deadlines" far)
736 (const :tag "Ignore all TODOs with a deadlines" all)
737 (const :tag "Show all TODOs, even if they have a deadline" nil)
738 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
740 (defcustom org-agenda-tags-todo-honor-ignore-options nil
741 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
742 The variables
743 `org-agenda-todo-ignore-with-date',
744 `org-agenda-todo-ignore-timestamp',
745 `org-agenda-todo-ignore-scheduled',
746 `org-agenda-todo-ignore-deadlines'
747 make the global TODO list skip entries that have time stamps of certain
748 kinds. If this option is set, the same options will also apply for the
749 tags-todo search, which is the general tags/property matcher
750 restricted to unfinished TODO entries only."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :group 'org-agenda-match-view
754 :type 'boolean)
756 (defcustom org-agenda-skip-scheduled-if-done nil
757 "Non-nil means don't show scheduled items in agenda when they are done.
758 This is relevant for the daily/weekly agenda, not for the TODO list. And
759 it applies only to the actual date of the scheduling. Warnings about
760 an item with a past scheduling dates are always turned off when the item
761 is DONE."
762 :group 'org-agenda-skip
763 :group 'org-agenda-daily/weekly
764 :type 'boolean)
766 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
767 "Non-nil means skip scheduling line if same entry shows because of deadline.
768 In the agenda of today, an entry can show up multiple times because
769 it is both scheduled and has a nearby deadline, and maybe a plain time
770 stamp as well.
771 When this variable is t, then only the deadline is shown and the fact that
772 the entry is scheduled today or was scheduled previously is not shown.
773 When this variable is nil, the entry will be shown several times. When
774 the variable is the symbol `not-today', then skip scheduled previously,
775 but not scheduled today."
776 :group 'org-agenda-skip
777 :group 'org-agenda-daily/weekly
778 :type '(choice
779 (const :tag "Never" nil)
780 (const :tag "Always" t)
781 (const :tag "Not when scheduled today" not-today)))
783 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
784 "Non-nil means skip timestamp line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times
786 because it has both a plain timestamp and has a nearby deadline.
787 When this variable is t, then only the deadline is shown and the
788 fact that the entry has a timestamp for or including today is not
789 shown. When this variable is nil, the entry will be shown
790 several times."
791 :group 'org-agenda-skip
792 :group 'org-agenda-daily/weekly
793 :version "24.1"
794 :type '(choice
795 (const :tag "Never" nil)
796 (const :tag "Always" t)))
798 (defcustom org-agenda-skip-deadline-if-done nil
799 "Non-nil means don't show deadlines when the corresponding item is done.
800 When nil, the deadline is still shown and should give you a happy feeling.
801 This is relevant for the daily/weekly agenda. And it applied only to the
802 actually date of the deadline. Warnings about approaching and past-due
803 deadlines are always turned off when the item is DONE."
804 :group 'org-agenda-skip
805 :group 'org-agenda-daily/weekly
806 :type 'boolean)
808 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
809 "Non-nil means skip deadline prewarning when entry is also scheduled.
810 This will apply on all days where a prewarning for the deadline would
811 be shown, but not at the day when the entry is actually due. On that day,
812 the deadline will be shown anyway.
813 This variable may be set to nil, t, or a number which will then give
814 the number of days before the actual deadline when the prewarnings
815 should resume.
816 This can be used in a workflow where the first showing of the deadline will
817 trigger you to schedule it, and then you don't want to be reminded of it
818 because you will take care of it on the day when scheduled."
819 :group 'org-agenda-skip
820 :group 'org-agenda-daily/weekly
821 :version "24.1"
822 :type '(choice
823 (const :tag "Alwas show prewarning" nil)
824 (const :tag "Remove prewarning if entry is scheduled" t)
825 (integer :tag "Restart prewarning N days before deadline")))
827 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
828 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
829 When non-nil, after the search for timestamps has matched once in an
830 entry, the rest of the entry will not be searched."
831 :group 'org-agenda-skip
832 :type 'boolean)
834 (defcustom org-agenda-skip-timestamp-if-done nil
835 "Non-nil means don't select item by timestamp or -range if it is DONE."
836 :group 'org-agenda-skip
837 :group 'org-agenda-daily/weekly
838 :type 'boolean)
840 (defcustom org-agenda-dim-blocked-tasks t
841 "Non-nil means dim blocked tasks in the agenda display.
842 This causes some overhead during agenda construction, but if you
843 have turned on `org-enforce-todo-dependencies',
844 `org-enforce-todo-checkbox-dependencies', or any other blocking
845 mechanism, this will create useful feedback in the agenda.
847 Instead of t, this variable can also have the value `invisible'.
848 Then blocked tasks will be invisible and only become visible when
849 they become unblocked. An exemption to this behavior is when a task is
850 blocked because of unchecked checkboxes below it. Since checkboxes do
851 not show up in the agenda views, making this task invisible you remove any
852 trace from agenda views that there is something to do. Therefore, a task
853 that is blocked because of checkboxes will never be made invisible, it
854 will only be dimmed."
855 :group 'org-agenda-daily/weekly
856 :group 'org-agenda-todo-list
857 :type '(choice
858 (const :tag "Do not dim" nil)
859 (const :tag "Dim to a gray face" t)
860 (const :tag "Make invisible" invisible)))
862 (defcustom org-timeline-show-empty-dates 3
863 "Non-nil means `org-timeline' also shows dates without an entry.
864 When nil, only the days which actually have entries are shown.
865 When t, all days between the first and the last date are shown.
866 When an integer, show also empty dates, but if there is a gap of more than
867 N days, just insert a special line indicating the size of the gap."
868 :group 'org-agenda-skip
869 :type '(choice
870 (const :tag "None" nil)
871 (const :tag "All" t)
872 (integer :tag "at most")))
874 (defgroup org-agenda-startup nil
875 "Options concerning initial settings in the Agenda in Org Mode."
876 :tag "Org Agenda Startup"
877 :group 'org-agenda)
879 (defcustom org-agenda-menu-show-matcher t
880 "Non-nil means show the match string in the agenda dispatcher menu.
881 When nil, the matcher string is not shown, but is put into the help-echo
882 property so than moving the mouse over the command shows it.
883 Setting it to nil is good if matcher strings are very long and/or if
884 you want to use two-column display (see `org-agenda-menu-two-column')."
885 :group 'org-agenda
886 :version "24.1"
887 :type 'boolean)
889 (defcustom org-agenda-menu-two-column nil
890 "Non-nil means, use two columns to show custom commands in the dispatcher.
891 If you use this, you probably want to set `org-agenda-menu-show-matcher'
892 to nil."
893 :group 'org-agenda
894 :version "24.1"
895 :type 'boolean)
897 (defcustom org-finalize-agenda-hook nil
898 "Hook run just before displaying an agenda buffer."
899 :group 'org-agenda-startup
900 :type 'hook)
902 (defcustom org-agenda-mouse-1-follows-link nil
903 "Non-nil means mouse-1 on a link will follow the link in the agenda.
904 A longer mouse click will still set point. Does not work on XEmacs.
905 Needs to be set before org.el is loaded."
906 :group 'org-agenda-startup
907 :type 'boolean)
909 (defcustom org-agenda-start-with-follow-mode nil
910 "The initial value of follow mode in a newly created agenda window."
911 :group 'org-agenda-startup
912 :type 'boolean)
914 (defcustom org-agenda-follow-indirect nil
915 "Non-nil means `org-agenda-follow-mode' displays only the
916 current item's tree, in an indirect buffer."
917 :group 'org-agenda
918 :version "24.1"
919 :type 'boolean)
921 (defcustom org-agenda-show-outline-path t
922 "Non-nil means show outline path in echo area after line motion."
923 :group 'org-agenda-startup
924 :type 'boolean)
926 (defcustom org-agenda-start-with-entry-text-mode nil
927 "The initial value of entry-text-mode in a newly created agenda window."
928 :group 'org-agenda-startup
929 :type 'boolean)
931 (defcustom org-agenda-entry-text-maxlines 5
932 "Number of text lines to be added when `E' is pressed in the agenda.
934 Note that this variable only used during agenda display. Add add entry text
935 when exporting the agenda, configure the variable
936 `org-agenda-add-entry-ext-maxlines'."
937 :group 'org-agenda
938 :type 'integer)
940 (defcustom org-agenda-entry-text-exclude-regexps nil
941 "List of regular expressions to clean up entry text.
942 The complete matches of all regular expressions in this list will be
943 removed from entry text before it is shown in the agenda."
944 :group 'org-agenda
945 :type '(repeat (regexp)))
947 (defvar org-agenda-entry-text-cleanup-hook nil
948 "Hook that is run after basic cleanup of entry text to be shown in agenda.
949 This cleanup is done in a temporary buffer, so the function may inspect and
950 change the entire buffer.
951 Some default stuff like drawers and scheduling/deadline dates will already
952 have been removed when this is called, as will any matches for regular
953 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
955 (defvar org-agenda-include-inactive-timestamps nil
956 "Non-nil means include inactive time stamps in agenda and timeline.
957 Dynamically scoped.")
959 (defgroup org-agenda-windows nil
960 "Options concerning the windows used by the Agenda in Org Mode."
961 :tag "Org Agenda Windows"
962 :group 'org-agenda)
964 (defcustom org-agenda-window-setup 'reorganize-frame
965 "How the agenda buffer should be displayed.
966 Possible values for this option are:
968 current-window Show agenda in the current window, keeping all other windows.
969 other-window Use `switch-to-buffer-other-window' to display agenda.
970 reorganize-frame Show only two windows on the current frame, the current
971 window and the agenda.
972 other-frame Use `switch-to-buffer-other-frame' to display agenda.
973 Also, when exiting the agenda, kill that frame.
974 See also the variable `org-agenda-restore-windows-after-quit'."
975 :group 'org-agenda-windows
976 :type '(choice
977 (const current-window)
978 (const other-frame)
979 (const other-window)
980 (const reorganize-frame)))
982 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
983 "The min and max height of the agenda window as a fraction of frame height.
984 The value of the variable is a cons cell with two numbers between 0 and 1.
985 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
986 :group 'org-agenda-windows
987 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
989 (defcustom org-agenda-restore-windows-after-quit nil
990 "Non-nil means restore window configuration upon exiting agenda.
991 Before the window configuration is changed for displaying the agenda,
992 the current status is recorded. When the agenda is exited with
993 `q' or `x' and this option is set, the old state is restored. If
994 `org-agenda-window-setup' is `other-frame', the value of this
995 option will be ignored."
996 :group 'org-agenda-windows
997 :type 'boolean)
999 (defcustom org-agenda-ndays nil
1000 "Number of days to include in overview display.
1001 Should be 1 or 7.
1002 Obsolete, see `org-agenda-span'."
1003 :group 'org-agenda-daily/weekly
1004 :type 'integer)
1006 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1008 (defcustom org-agenda-span 'week
1009 "Number of days to include in overview display.
1010 Can be day, week, month, year, or any number of days.
1011 Custom commands can set this variable in the options section."
1012 :group 'org-agenda-daily/weekly
1013 :type '(choice (const :tag "Day" day)
1014 (const :tag "Week" week)
1015 (const :tag "Month" month)
1016 (const :tag "Year" year)
1017 (integer :tag "Custom")))
1019 (defcustom org-agenda-start-on-weekday 1
1020 "Non-nil means start the overview always on the specified weekday.
1021 0 denotes Sunday, 1 denotes Monday etc.
1022 When nil, always start on the current day.
1023 Custom commands can set this variable in the options section."
1024 :group 'org-agenda-daily/weekly
1025 :type '(choice (const :tag "Today" nil)
1026 (integer :tag "Weekday No.")))
1028 (defcustom org-agenda-show-all-dates t
1029 "Non-nil means `org-agenda' shows every day in the selected range.
1030 When nil, only the days which actually have entries are shown."
1031 :group 'org-agenda-daily/weekly
1032 :type 'boolean)
1034 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1035 "Format string for displaying dates in the agenda.
1036 Used by the daily/weekly agenda and by the timeline. This should be
1037 a format string understood by `format-time-string', or a function returning
1038 the formatted date as a string. The function must take a single argument,
1039 a calendar-style date list like (month day year)."
1040 :group 'org-agenda-daily/weekly
1041 :type '(choice
1042 (string :tag "Format string")
1043 (function :tag "Function")))
1045 (defun org-agenda-format-date-aligned (date)
1046 "Format a date string for display in the daily/weekly agenda, or timeline.
1047 This function makes sure that dates are aligned for easy reading."
1048 (require 'cal-iso)
1049 (let* ((dayname (calendar-day-name date))
1050 (day (cadr date))
1051 (day-of-week (calendar-day-of-week date))
1052 (month (car date))
1053 (monthname (calendar-month-name month))
1054 (year (nth 2 date))
1055 (iso-week (org-days-to-iso-week
1056 (calendar-absolute-from-gregorian date)))
1057 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1058 (1- year))
1059 ((and (= month 12) (<= iso-week 1))
1060 (1+ year))
1061 (t year)))
1062 (weekstring (if (= day-of-week 1)
1063 (format " W%02d" iso-week)
1064 "")))
1065 (format "%-10s %2d %s %4d%s"
1066 dayname day monthname year weekstring)))
1068 (defcustom org-agenda-time-leading-zero nil
1069 "Non-nil means use leading zero for military times in agenda.
1070 For example, 9:30am would become 09:30 rather than 9:30."
1071 :group 'org-agenda-daily/weekly
1072 :version "24.1"
1073 :type 'boolean)
1075 (defcustom org-agenda-timegrid-use-ampm nil
1076 "When set, show AM/PM style timestamps on the timegrid."
1077 :group 'org-agenda
1078 :version "24.1"
1079 :type 'boolean)
1081 (defun org-agenda-time-of-day-to-ampm (time)
1082 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1083 (let* ((hour-number (string-to-number (substring time 0 -3)))
1084 (minute (substring time -2))
1085 (ampm "am"))
1086 (cond
1087 ((equal hour-number 12)
1088 (setq ampm "pm"))
1089 ((> hour-number 12)
1090 (setq ampm "pm")
1091 (setq hour-number (- hour-number 12))))
1092 (concat
1093 (if org-agenda-time-leading-zero
1094 (format "%02d" hour-number)
1095 (format "%02s" (number-to-string hour-number)))
1096 ":" minute ampm)))
1098 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1099 "Conditionally convert TIME to AM/PM format
1100 based on `org-agenda-timegrid-use-ampm'"
1101 (if org-agenda-timegrid-use-ampm
1102 (org-agenda-time-of-day-to-ampm time)
1103 time))
1105 (defcustom org-agenda-weekend-days '(6 0)
1106 "Which days are weekend?
1107 These days get the special face `org-agenda-date-weekend' in the agenda
1108 and timeline buffers."
1109 :group 'org-agenda-daily/weekly
1110 :type '(set :greedy t
1111 (const :tag "Monday" 1)
1112 (const :tag "Tuesday" 2)
1113 (const :tag "Wednesday" 3)
1114 (const :tag "Thursday" 4)
1115 (const :tag "Friday" 5)
1116 (const :tag "Saturday" 6)
1117 (const :tag "Sunday" 0)))
1119 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1120 "Non-nil means jump to today when moving a past date forward in time.
1121 When using S-right in the agenda to move a a date forward, and the date
1122 stamp currently points to the past, the first key press will move it
1123 to today. WHen nil, just move one day forward even if the date stays
1124 in the past."
1125 :group 'org-agenda-daily/weekly
1126 :version "24.1"
1127 :type 'boolean)
1129 (defcustom org-agenda-include-diary nil
1130 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1131 Custom commands can set this variable in the options section."
1132 :group 'org-agenda-daily/weekly
1133 :type 'boolean)
1135 (defcustom org-agenda-include-deadlines t
1136 "If non-nil, include entries within their deadline warning period.
1137 Custom commands can set this variable in the options section."
1138 :group 'org-agenda-daily/weekly
1139 :version "24.1"
1140 :type 'boolean)
1142 (defcustom org-agenda-repeating-timestamp-show-all t
1143 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1144 When set to a list of strings, only show occurrences of repeating
1145 stamps for these TODO keywords. When nil, only one occurrence is
1146 shown, either today or the nearest into the future."
1147 :group 'org-agenda-daily/weekly
1148 :type '(choice
1149 (const :tag "Show repeating stamps" t)
1150 (repeat :tag "Show repeating stamps for these TODO keywords"
1151 (string :tag "TODO Keyword"))
1152 (const :tag "Don't show repeating stamps" nil)))
1154 (defcustom org-scheduled-past-days 10000
1155 "No. of days to continue listing scheduled items that are not marked DONE.
1156 When an item is scheduled on a date, it shows up in the agenda on this
1157 day and will be listed until it is marked done for the number of days
1158 given here."
1159 :group 'org-agenda-daily/weekly
1160 :type 'integer)
1162 (defcustom org-agenda-log-mode-items '(closed clock)
1163 "List of items that should be shown in agenda log mode.
1164 This list may contain the following symbols:
1166 closed Show entries that have been closed on that day.
1167 clock Show entries that have received clocked time on that day.
1168 state Show all logged state changes.
1169 Note that instead of changing this variable, you can also press `C-u l' in
1170 the agenda to display all available LOG items temporarily."
1171 :group 'org-agenda-daily/weekly
1172 :type '(set :greedy t (const closed) (const clock) (const state)))
1174 (defcustom org-agenda-clock-consistency-checks
1175 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1176 :gap-ok-around ("4:00")
1177 :default-face ((:background "DarkRed") (:foreground "white"))
1178 :overlap-face nil :gap-face nil :no-end-time-face nil
1179 :long-face nil :short-face nil)
1180 "This is a property list, with the following keys:
1182 :max-duration Mark clocking chunks that are longer than this time.
1183 This is a time string like \"HH:MM\", or the number
1184 of minutes as an integer.
1186 :min-duration Mark clocking chunks that are shorter that this.
1187 This is a time string like \"HH:MM\", or the number
1188 of minutes as an integer.
1190 :max-gap Mark gaps between clocking chunks that are longer than
1191 this duration. A number of minutes, or a string
1192 like \"HH:MM\".
1194 :gap-ok-around List of times during the day which are usually not working
1195 times. When a gap is detected, but the gap contains any
1196 of these times, the gap is *not* reported. For example,
1197 if this is (\"4:00\" \"13:00\") then gaps that contain
1198 4:00 in the morning (i.e. the night) and 13:00
1199 (i.e. a typical lunch time) do not cause a warning.
1200 You should have at least one time during the night in this
1201 list, or otherwise the first task each morning will trigger
1202 a warning because it follows a long gap.
1204 Furthermore, the following properties can be used to define faces for
1205 issue display.
1207 :default-face the default face, if the specific face is undefined
1208 :overlap-face face for overlapping clocks
1209 :gap-face face for gaps between clocks
1210 :no-end-time-face face for incomplete clocks
1211 :long-face face for clock intervals that are too long
1212 :short-face face for clock intervals that are too short"
1213 :group 'org-agenda-daily/weekly
1214 :group 'org-clock
1215 :version "24.1"
1216 :type 'plist)
1218 (defcustom org-agenda-log-mode-add-notes t
1219 "Non-nil means add first line of notes to log entries in agenda views.
1220 If a log item like a state change or a clock entry is associated with
1221 notes, the first line of these notes will be added to the entry in the
1222 agenda display."
1223 :group 'org-agenda-daily/weekly
1224 :type 'boolean)
1226 (defcustom org-agenda-start-with-log-mode nil
1227 "The initial value of log-mode in a newly created agenda window.
1228 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1229 explanations on the possible values."
1230 :group 'org-agenda-startup
1231 :group 'org-agenda-daily/weekly
1232 :type '(choice (const :tag "Don't show log items" nil)
1233 (const :tag "Show only log items" 'only)
1234 (const :tag "Show all possible log items" 'clockcheck)
1235 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1236 (choice (const :tag "Show closed log items" 'closed)
1237 (const :tag "Show clocked log items" 'clock)
1238 (const :tag "Show all logged state changes" 'state)))))
1240 (defcustom org-agenda-start-with-clockreport-mode nil
1241 "The initial value of clockreport-mode in a newly created agenda window."
1242 :group 'org-agenda-startup
1243 :group 'org-agenda-daily/weekly
1244 :type 'boolean)
1246 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1247 "Property list with parameters for the clocktable in clockreport mode.
1248 This is the display mode that shows a clock table in the daily/weekly
1249 agenda, the properties for this dynamic block can be set here.
1250 The usual clocktable parameters are allowed here, but you cannot set
1251 the properties :name, :tstart, :tend, :block, and :scope - these will
1252 be overwritten to make sure the content accurately reflects the
1253 current display in the agenda."
1254 :group 'org-agenda-daily/weekly
1255 :type 'plist)
1257 (defcustom org-agenda-search-view-always-boolean nil
1258 "Non-nil means the search string is interpreted as individual parts.
1260 The search string for search view can either be interpreted as a phrase,
1261 or as a list of snippets that define a boolean search for a number of
1262 strings.
1264 When this is non-nil, the string will be split on whitespace, and each
1265 snippet will be searched individually, and all must match in order to
1266 select an entry. A snippet is then a single string of non-white
1267 characters, or a string in double quotes, or a regexp in {} braces.
1268 If a snippet is preceded by \"-\", the snippet must *not* match.
1269 \"+\" is syntactic sugar for positive selection. Each snippet may
1270 be found as a full word or a partial word, but see the variable
1271 `org-agenda-search-view-force-full-words'.
1273 When this is nil, search will look for the entire search phrase as one,
1274 with each space character matching any amount of whitespace, including
1275 line breaks.
1277 Even when this is nil, you can still switch to Boolean search dynamically
1278 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1279 is a regexp marked with braces like \"{abc}\", this will also switch to
1280 boolean search."
1281 :group 'org-agenda-search-view
1282 :version "24.1"
1283 :type 'boolean)
1285 (if (fboundp 'defvaralias)
1286 (defvaralias 'org-agenda-search-view-search-words-only
1287 'org-agenda-search-view-always-boolean))
1289 (defcustom org-agenda-search-view-force-full-words nil
1290 "Non-nil means, search words must be matches as complete words.
1291 When nil, they may also match part of a word."
1292 :group 'org-agenda-search-view
1293 :version "24.1"
1294 :type 'boolean)
1296 (defgroup org-agenda-time-grid nil
1297 "Options concerning the time grid in the Org-mode Agenda."
1298 :tag "Org Agenda Time Grid"
1299 :group 'org-agenda)
1301 (defcustom org-agenda-search-headline-for-time t
1302 "Non-nil means search headline for a time-of-day.
1303 If the headline contains a time-of-day in one format or another, it will
1304 be used to sort the entry into the time sequence of items for a day.
1305 Some people have time stamps in the headline that refer to the creation
1306 time or so, and then this produces an unwanted side effect. If this is
1307 the case for your, use this variable to turn off searching the headline
1308 for a time."
1309 :group 'org-agenda-time-grid
1310 :type 'boolean)
1312 (defcustom org-agenda-use-time-grid t
1313 "Non-nil means show a time grid in the agenda schedule.
1314 A time grid is a set of lines for specific times (like every two hours between
1315 8:00 and 20:00). The items scheduled for a day at specific times are
1316 sorted in between these lines.
1317 For details about when the grid will be shown, and what it will look like, see
1318 the variable `org-agenda-time-grid'."
1319 :group 'org-agenda-time-grid
1320 :type 'boolean)
1322 (defcustom org-agenda-time-grid
1323 '((daily today require-timed)
1324 "----------------"
1325 (800 1000 1200 1400 1600 1800 2000))
1327 "The settings for time grid for agenda display.
1328 This is a list of three items. The first item is again a list. It contains
1329 symbols specifying conditions when the grid should be displayed:
1331 daily if the agenda shows a single day
1332 weekly if the agenda shows an entire week
1333 today show grid on current date, independent of daily/weekly display
1334 require-timed show grid only if at least one item has a time specification
1336 The second item is a string which will be placed behind the grid time.
1338 The third item is a list of integers, indicating the times that should have
1339 a grid line."
1340 :group 'org-agenda-time-grid
1341 :type
1342 '(list
1343 (set :greedy t :tag "Grid Display Options"
1344 (const :tag "Show grid in single day agenda display" daily)
1345 (const :tag "Show grid in weekly agenda display" weekly)
1346 (const :tag "Always show grid for today" today)
1347 (const :tag "Show grid only if any timed entries are present"
1348 require-timed)
1349 (const :tag "Skip grid times already present in an entry"
1350 remove-match))
1351 (string :tag "Grid String")
1352 (repeat :tag "Grid Times" (integer :tag "Time"))))
1354 (defcustom org-agenda-show-current-time-in-grid t
1355 "Non-nil means show the current time in the time grid."
1356 :group 'org-agenda-time-grid
1357 :version "24.1"
1358 :type 'boolean)
1360 (defcustom org-agenda-current-time-string
1361 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1362 "The string for the current time marker in the agenda."
1363 :group 'org-agenda-time-grid
1364 :version "24.1"
1365 :type 'string)
1367 (defgroup org-agenda-sorting nil
1368 "Options concerning sorting in the Org-mode Agenda."
1369 :tag "Org Agenda Sorting"
1370 :group 'org-agenda)
1372 (defcustom org-agenda-sorting-strategy
1373 '((agenda habit-down time-up priority-down category-keep)
1374 (todo priority-down category-keep)
1375 (tags priority-down category-keep)
1376 (search category-keep))
1377 "Sorting structure for the agenda items of a single day.
1378 This is a list of symbols which will be used in sequence to determine
1379 if an entry should be listed before another entry. The following
1380 symbols are recognized:
1382 time-up Put entries with time-of-day indications first, early first
1383 time-down Put entries with time-of-day indications first, late first
1384 category-keep Keep the default order of categories, corresponding to the
1385 sequence in `org-agenda-files'.
1386 category-up Sort alphabetically by category, A-Z.
1387 category-down Sort alphabetically by category, Z-A.
1388 tag-up Sort alphabetically by last tag, A-Z.
1389 tag-down Sort alphabetically by last tag, Z-A.
1390 priority-up Sort numerically by priority, high priority last.
1391 priority-down Sort numerically by priority, high priority first.
1392 todo-state-up Sort by todo state, tasks that are done last.
1393 todo-state-down Sort by todo state, tasks that are done first.
1394 effort-up Sort numerically by estimated effort, high effort last.
1395 effort-down Sort numerically by estimated effort, high effort first.
1396 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1397 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1398 habit-up Put entries that are habits first
1399 habit-down Put entries that are habits last
1400 alpha-up Sort headlines alphabetically
1401 alpha-down Sort headlines alphabetically, reversed
1403 The different possibilities will be tried in sequence, and testing stops
1404 if one comparison returns a \"not-equal\". For example, the default
1405 '(time-up category-keep priority-down)
1406 means: Pull out all entries having a specified time of day and sort them,
1407 in order to make a time schedule for the current day the first thing in the
1408 agenda listing for the day. Of the entries without a time indication, keep
1409 the grouped in categories, don't sort the categories, but keep them in
1410 the sequence given in `org-agenda-files'. Within each category sort by
1411 priority.
1413 Leaving out `category-keep' would mean that items will be sorted across
1414 categories by priority.
1416 Instead of a single list, this can also be a set of list for specific
1417 contents, with a context symbol in the car of the list, any of
1418 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1420 Custom commands can bind this variable in the options section."
1421 :group 'org-agenda-sorting
1422 :type `(choice
1423 (repeat :tag "General" ,org-sorting-choice)
1424 (list :tag "Individually"
1425 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1426 (repeat ,org-sorting-choice))
1427 (cons (const :tag "Strategy for TODO lists" todo)
1428 (repeat ,org-sorting-choice))
1429 (cons (const :tag "Strategy for Tags matches" tags)
1430 (repeat ,org-sorting-choice))
1431 (cons (const :tag "Strategy for search matches" search)
1432 (repeat ,org-sorting-choice)))))
1434 (defcustom org-agenda-cmp-user-defined nil
1435 "A function to define the comparison `user-defined'.
1436 This function must receive two arguments, agenda entry a and b.
1437 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1438 the user comparison, return nil.
1439 When this is defined, you can make `user-defined-up' and `user-defined-down'
1440 part of an agenda sorting strategy."
1441 :group 'org-agenda-sorting
1442 :type 'symbol)
1444 (defcustom org-sort-agenda-notime-is-late t
1445 "Non-nil means items without time are considered late.
1446 This is only relevant for sorting. When t, items which have no explicit
1447 time like 15:30 will be considered as 99:01, i.e. later than any items which
1448 do have a time. When nil, the default time is before 0:00. You can use this
1449 option to decide if the schedule for today should come before or after timeless
1450 agenda entries."
1451 :group 'org-agenda-sorting
1452 :type 'boolean)
1454 (defcustom org-sort-agenda-noeffort-is-high t
1455 "Non-nil means items without effort estimate are sorted as high effort.
1456 This also applies when filtering an agenda view with respect to the
1457 < or > effort operator. Then, tasks with no effort defined will be treated
1458 as tasks with high effort.
1459 When nil, such items are sorted as 0 minutes effort."
1460 :group 'org-agenda-sorting
1461 :type 'boolean)
1463 (defgroup org-agenda-line-format nil
1464 "Options concerning the entry prefix in the Org-mode agenda display."
1465 :tag "Org Agenda Line Format"
1466 :group 'org-agenda)
1468 (defcustom org-agenda-prefix-format
1469 '((agenda . " %i %-12:c%?-12t% s")
1470 (timeline . " % s")
1471 (todo . " %i %-12:c")
1472 (tags . " %i %-12:c")
1473 (search . " %i %-12:c"))
1474 "Format specifications for the prefix of items in the agenda views.
1475 An alist with five entries, each for the different agenda types. The
1476 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1477 The values are format strings.
1479 This format works similar to a printf format, with the following meaning:
1481 %c the category of the item, \"Diary\" for entries from the diary,
1482 or as given by the CATEGORY keyword or derived from the file name
1483 %e the effort required by the item
1484 %i the icon category of the item, see `org-agenda-category-icon-alist'
1485 %T the last tag of the item (ignore inherited tags, which come first)
1486 %t the HH:MM time-of-day specification if one applies to the entry
1487 %s Scheduling/Deadline information, a short string
1488 %(expression) Eval EXPRESSION and replace the control string
1489 by the result
1491 All specifiers work basically like the standard `%s' of printf, but may
1492 contain two additional characters: a question mark just after the `%'
1493 and a whitespace/punctuation character just before the final letter.
1495 If the first character after `%' is a question mark, the entire field
1496 will only be included if the corresponding value applies to the current
1497 entry. This is useful for fields which should have fixed width when
1498 present, but zero width when absent. For example, \"%?-12t\" will
1499 result in a 12 character time field if a time of the day is specified,
1500 but will completely disappear in entries which do not contain a time.
1502 If there is punctuation or whitespace character just before the final
1503 format letter, this character will be appended to the field value if
1504 the value is not empty. For example, the format \"%-12:c\" leads to
1505 \"Diary: \" if the category is \"Diary\". If the category were be
1506 empty, no additional colon would be inserted.
1508 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1509 which means:
1511 - Indent the line with two space characters
1512 - Give the category a 12 chars wide field, padded with whitespace on
1513 the right (because of `-'). Append a colon if there is a category
1514 (because of `:').
1515 - If there is a time-of-day, put it into a 12 chars wide field. If no
1516 time, don't put in an empty field, just skip it (because of '?').
1517 - Finally, put the scheduling information.
1519 See also the variables `org-agenda-remove-times-when-in-prefix' and
1520 `org-agenda-remove-tags'.
1522 Custom commands can set this variable in the options section."
1523 :type '(choice
1524 (string :tag "General format")
1525 (list :greedy t :tag "View dependent"
1526 (cons (const agenda) (string :tag "Format"))
1527 (cons (const timeline) (string :tag "Format"))
1528 (cons (const todo) (string :tag "Format"))
1529 (cons (const tags) (string :tag "Format"))
1530 (cons (const search) (string :tag "Format"))))
1531 :group 'org-agenda-line-format)
1533 (defvar org-prefix-format-compiled nil
1534 "The compiled prefix format and associated variables.
1535 This is a list where first element is a list of variable bindings, and second
1536 element is the compiled format expression. See the variable
1537 `org-agenda-prefix-format'.")
1539 (defcustom org-agenda-todo-keyword-format "%-1s"
1540 "Format for the TODO keyword in agenda lines.
1541 Set this to something like \"%-12s\" if you want all TODO keywords
1542 to occupy a fixed space in the agenda display."
1543 :group 'org-agenda-line-format
1544 :type 'string)
1546 (defcustom org-agenda-diary-sexp-prefix nil
1547 "A regexp that matches part of a diary sexp entry
1548 which should be treated as scheduling/deadline information in
1549 `org-agenda'.
1551 For example, you can use this to extract the `diary-remind-message' from
1552 `diary-remind' entries."
1553 :group 'org-agenda-line-format
1554 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1556 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1557 "Text preceding timerange entries in the agenda view.
1558 This is a list with two strings. The first applies when the range
1559 is entirely on one day. The second applies if the range spans several days.
1560 The strings may have two \"%d\" format specifiers which will be filled
1561 with the sequence number of the days, and the total number of days in the
1562 range, respectively."
1563 :group 'org-agenda-line-format
1564 :type '(list
1565 (string :tag "Deadline today ")
1566 (choice :tag "Deadline relative"
1567 (string :tag "Format string")
1568 (function))))
1570 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1571 "Text preceding scheduled items in the agenda view.
1572 This is a list with two strings. The first applies when the item is
1573 scheduled on the current day. The second applies when it has been scheduled
1574 previously, it may contain a %d indicating that this is the nth time that
1575 this item is scheduled, due to automatic rescheduling of unfinished items
1576 for the following day. So this number is one larger than the number of days
1577 that passed since this item was scheduled first."
1578 :group 'org-agenda-line-format
1579 :type '(list
1580 (string :tag "Scheduled today ")
1581 (string :tag "Scheduled previously")))
1583 (defcustom org-agenda-inactive-leader "["
1584 "Text preceding item pulled into the agenda by inactive time stamps.
1585 These entries are added to the agenda when pressing \"[\"."
1586 :group 'org-agenda-line-format
1587 :version "24.1"
1588 :type '(list
1589 (string :tag "Scheduled today ")
1590 (string :tag "Scheduled previously")))
1592 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1593 "Text preceding deadline items in the agenda view.
1594 This is a list with two strings. The first applies when the item has its
1595 deadline on the current day. The second applies when it is in the past or
1596 in the future, it may contain %d to capture how many days away the deadline
1597 is (was)."
1598 :group 'org-agenda-line-format
1599 :type '(list
1600 (string :tag "Deadline today ")
1601 (choice :tag "Deadline relative"
1602 (string :tag "Format string")
1603 (function))))
1605 (defcustom org-agenda-remove-times-when-in-prefix t
1606 "Non-nil means remove duplicate time specifications in agenda items.
1607 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1608 time-of-day specification in a headline or diary entry is extracted and
1609 placed into the prefix. If this option is non-nil, the original specification
1610 \(a timestamp or -range, or just a plain time(range) specification like
1611 11:30-4pm) will be removed for agenda display. This makes the agenda less
1612 cluttered.
1613 The option can be t or nil. It may also be the symbol `beg', indicating
1614 that the time should only be removed when it is located at the beginning of
1615 the headline/diary entry."
1616 :group 'org-agenda-line-format
1617 :type '(choice
1618 (const :tag "Always" t)
1619 (const :tag "Never" nil)
1620 (const :tag "When at beginning of entry" beg)))
1622 (defcustom org-agenda-remove-timeranges-from-blocks nil
1623 "Non-nil means remove time ranges specifications in agenda
1624 items that span on several days."
1625 :group 'org-agenda-line-format
1626 :version "24.1"
1627 :type 'boolean)
1629 (defcustom org-agenda-default-appointment-duration nil
1630 "Default duration for appointments that only have a starting time.
1631 When nil, no duration is specified in such cases.
1632 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1633 :group 'org-agenda-line-format
1634 :type '(choice
1635 (integer :tag "Minutes")
1636 (const :tag "No default duration")))
1638 (defcustom org-agenda-show-inherited-tags t
1639 "Non-nil means show inherited tags in each agenda line."
1640 :group 'org-agenda-line-format
1641 :type 'boolean)
1643 (defcustom org-agenda-hide-tags-regexp nil
1644 "Regular expression used to filter away specific tags in agenda views.
1645 This means that these tags will be present, but not be shown in the agenda
1646 line. Secondary filtering will still work on the hidden tags.
1647 Nil means don't hide any tags."
1648 :group 'org-agenda-line-format
1649 :type '(choice
1650 (const :tag "Hide none" nil)
1651 (string :tag "Regexp ")))
1653 (defcustom org-agenda-remove-tags nil
1654 "Non-nil means remove the tags from the headline copy in the agenda.
1655 When this is the symbol `prefix', only remove tags when
1656 `org-agenda-prefix-format' contains a `%T' specifier."
1657 :group 'org-agenda-line-format
1658 :type '(choice
1659 (const :tag "Always" t)
1660 (const :tag "Never" nil)
1661 (const :tag "When prefix format contains %T" prefix)))
1663 (if (fboundp 'defvaralias)
1664 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1665 'org-agenda-remove-tags))
1667 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1668 "Shift tags in agenda items to this column.
1669 If this number is positive, it specifies the column. If it is negative,
1670 it means that the tags should be flushright to that column. For example,
1671 -80 works well for a normal 80 character screen."
1672 :group 'org-agenda-line-format
1673 :type 'integer)
1675 (if (fboundp 'defvaralias)
1676 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1678 (defcustom org-agenda-fontify-priorities 'cookies
1679 "Non-nil means highlight low and high priorities in agenda.
1680 When t, the highest priority entries are bold, lowest priority italic.
1681 However, settings in `org-priority-faces' will overrule these faces.
1682 When this variable is the symbol `cookies', only fontify the
1683 cookies, not the entire task.
1684 This may also be an association list of priority faces, whose
1685 keys are the character values of `org-highest-priority',
1686 `org-default-priority', and `org-lowest-priority' (the default values
1687 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1688 color as a string, or a list like `(:background \"Red\")'.
1689 If it is a color, the variable `org-faces-easy-properties'
1690 determines if it is a foreground or a background color."
1691 :group 'org-agenda-line-format
1692 :type '(choice
1693 (const :tag "Never" nil)
1694 (const :tag "Defaults" t)
1695 (const :tag "Cookies only" cookies)
1696 (repeat :tag "Specify"
1697 (list (character :tag "Priority" :value ?A)
1698 (choice :tag "Face "
1699 (string :tag "Color")
1700 (sexp :tag "Face"))))))
1702 (defcustom org-agenda-day-face-function nil
1703 "Function called to determine what face should be used to display a day.
1704 The only argument passed to that function is the day. It should
1705 returns a face, or nil if does not want to specify a face and let
1706 the normal rules apply."
1707 :group 'org-agenda-line-format
1708 :version "24.1"
1709 :type 'function)
1711 (defcustom org-agenda-category-icon-alist nil
1712 "Alist of category icon to be displayed in agenda views.
1714 Each entry should have the following format:
1716 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1718 Where CATEGORY-REGEXP is a regexp matching the categories where
1719 the icon should be displayed.
1720 FILE-OR-DATA either a file path or a string containing image data.
1722 The other fields can be omitted safely if not needed:
1723 TYPE indicates the image type.
1724 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1725 image data.
1726 PROPS are additional image attributes to assign to the image,
1727 like, e.g. `:ascent center'.
1729 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1731 If you want to set the display properties yourself, just put a
1732 list as second element:
1734 (CATEGORY-REGEXP (MY PROPERTY LIST))
1736 For example, to display a 16px horizontal space for Emacs
1737 category, you can use:
1739 (\"Emacs\" '(space . (:width (16))))"
1740 :group 'org-agenda-line-format
1741 :version "24.1"
1742 :type '(alist :key-type (string :tag "Regexp matching category")
1743 :value-type (choice (list :tag "Icon"
1744 (string :tag "File or data")
1745 (symbol :tag "Type")
1746 (boolean :tag "Data?")
1747 (repeat :tag "Extra image properties" :inline t symbol))
1748 (list :tag "Display properties" sexp))))
1750 (defgroup org-agenda-column-view nil
1751 "Options concerning column view in the agenda."
1752 :tag "Org Agenda Column View"
1753 :group 'org-agenda)
1755 (defcustom org-agenda-columns-show-summaries t
1756 "Non-nil means show summaries for columns displayed in the agenda view."
1757 :group 'org-agenda-column-view
1758 :type 'boolean)
1760 (defcustom org-agenda-columns-compute-summary-properties t
1761 "Non-nil means recompute all summary properties before column view.
1762 When column view in the agenda is listing properties that have a summary
1763 operator, it can go to all relevant buffers and recompute the summaries
1764 there. This can mean overhead for the agenda column view, but is necessary
1765 to have thing up to date.
1766 As a special case, a CLOCKSUM property also makes sure that the clock
1767 computations are current."
1768 :group 'org-agenda-column-view
1769 :type 'boolean)
1771 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1772 "Non-nil means the duration of an appointment will add to day effort.
1773 The property to which appointment durations will be added is the one given
1774 in the option `org-effort-property'. If an appointment does not have
1775 an end time, `org-agenda-default-appointment-duration' will be used. If that
1776 is not set, an appointment without end time will not contribute to the time
1777 estimate."
1778 :group 'org-agenda-column-view
1779 :type 'boolean)
1781 (defcustom org-agenda-auto-exclude-function nil
1782 "A function called with a tag to decide if it is filtered on '/ RET'.
1783 The sole argument to the function, which is called once for each
1784 possible tag, is a string giving the name of the tag. The
1785 function should return either nil if the tag should be included
1786 as normal, or \"-<TAG>\" to exclude the tag.
1787 Note that for the purpose of tag filtering, only the lower-case version of
1788 all tags will be considered, so that this function will only ever see
1789 the lower-case version of all tags."
1790 :group 'org-agenda
1791 :type 'function)
1793 (defcustom org-agenda-bulk-custom-functions nil
1794 "Alist of characters and custom functions for bulk actions.
1795 For example, this value makes those two functions available:
1797 '((?R set-category)
1798 (?C bulk-cut))
1800 With selected entries in an agenda buffer, `B R' will call
1801 the custom function `set-category' on the selected entries.
1802 Note that functions in this alist don't need to be quoted."
1803 :type 'alist
1804 :version "24.1"
1805 :group 'org-agenda)
1807 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1808 "Execute BODY with point at location given by `org-hd-marker' property.
1809 If STRING is non-nil, the text property will be fetched from position 0
1810 in that string. If STRING is nil, it will be fetched from the beginning
1811 of the current line."
1812 (org-with-gensyms (marker)
1813 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1814 'org-hd-marker ,string)))
1815 (with-current-buffer (marker-buffer ,marker)
1816 (save-excursion
1817 (goto-char ,marker)
1818 ,@body)))))
1819 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1821 (defun org-add-agenda-custom-command (entry)
1822 "Replace or add a command in `org-agenda-custom-commands'.
1823 This is mostly for hacking and trying a new command - once the command
1824 works you probably want to add it to `org-agenda-custom-commands' for good."
1825 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1826 (if ass
1827 (setcdr ass (cdr entry))
1828 (push entry org-agenda-custom-commands))))
1830 ;;; Define the org-agenda-mode
1832 (defvar org-agenda-mode-map (make-sparse-keymap)
1833 "Keymap for `org-agenda-mode'.")
1834 (if (fboundp 'defvaralias)
1835 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1837 (defvar org-agenda-menu) ; defined later in this file.
1838 (defvar org-agenda-restrict) ; defined later in this file.
1839 (defvar org-agenda-follow-mode nil)
1840 (defvar org-agenda-entry-text-mode nil)
1841 (defvar org-agenda-clockreport-mode nil)
1842 (defvar org-agenda-show-log nil)
1843 (defvar org-agenda-redo-command nil)
1844 (defvar org-agenda-query-string nil)
1845 (defvar org-agenda-mode-hook nil
1846 "Hook for `org-agenda-mode', run after the mode is turned on.")
1847 (defvar org-agenda-type nil)
1848 (defvar org-agenda-force-single-file nil)
1849 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1852 ;;; Multiple agenda buffers support
1854 (defcustom org-agenda-sticky nil
1855 "Non-nil means agenda q key will bury agenda buffers.
1856 Agenda commands will then show existing buffer instead of generating new ones.
1857 When nil, `q' will kill the single agenda buffer."
1858 :group 'org-agenda
1859 :type 'boolean
1860 :set (lambda (var val)
1861 (if (boundp var)
1862 (org-toggle-sticky-agenda (if val 1 0))
1863 (set var val))))
1865 (defun org-toggle-sticky-agenda (&optional arg)
1866 "Toggle `org-agenda-sticky'."
1867 (interactive "P")
1868 (let ((new-value (if arg
1869 (> (prefix-numeric-value arg) 0)
1870 (not org-agenda-sticky))))
1871 (if (equal new-value org-agenda-sticky)
1872 (and (org-called-interactively-p 'interactive)
1873 (message "Sticky agenda was already %s"
1874 (if org-agenda-sticky "enabled" "disabled")))
1875 (setq org-agenda-sticky new-value)
1876 (org-agenda-kill-all-agenda-buffers)
1877 (and (org-called-interactively-p 'interactive)
1878 (message "Sticky agenda was %s"
1879 (if org-agenda-sticky "enabled" "disabled"))))))
1881 (defvar org-agenda-buffer nil
1882 "Agenda buffer currently being generated.")
1884 (defvar org-agenda-last-prefix-arg nil)
1885 (defvar org-agenda-this-buffer-name nil)
1886 (defvar org-agenda-doing-sticky-redo nil)
1887 (defvar org-agenda-this-buffer-is-sticky nil)
1889 (defconst org-agenda-local-vars
1890 '(org-agenda-this-buffer-name
1891 org-agenda-undo-list
1892 org-agenda-pending-undo-list
1893 org-agenda-follow-mode
1894 org-agenda-entry-text-mode
1895 org-agenda-clockreport-mode
1896 org-agenda-show-log
1897 org-agenda-redo-command
1898 org-agenda-query-string
1899 org-agenda-type
1900 org-agenda-bulk-marked-entries
1901 org-agenda-undo-has-started-in
1902 org-agenda-last-arguments
1903 org-agenda-info
1904 org-agenda-tag-filter-overlays
1905 org-agenda-cat-filter-overlays
1906 org-pre-agenda-window-conf
1907 org-agenda-columns-active
1908 org-agenda-tag-filter
1909 org-agenda-category-filter
1910 org-agenda-markers
1911 org-agenda-last-search-view-search-was-boolean
1912 org-agenda-filtered-by-category
1913 org-agenda-filter-form
1914 org-agenda-show-window
1915 org-agenda-cycle-counter
1916 org-agenda-last-prefix-arg)
1917 "Variables that must be local in agenda buffers to allow multiple buffers.")
1919 (defun org-agenda-mode ()
1920 "Mode for time-sorted view on action items in Org-mode files.
1922 The following commands are available:
1924 \\{org-agenda-mode-map}"
1925 (interactive)
1926 (cond (org-agenda-doing-sticky-redo
1927 ;; Refreshing sticky agenda-buffer
1929 ;; Preserve the value of `org-agenda-local-vars' variables,
1930 ;; while letting `kill-all-local-variables' kill the rest
1931 (let ((save (buffer-local-variables)))
1932 (kill-all-local-variables)
1933 (mapc 'make-local-variable org-agenda-local-vars)
1934 (dolist (elem save)
1935 (let ((var (car elem))
1936 (val (cdr elem)))
1937 (when (and val
1938 (member var org-agenda-local-vars))
1939 (set var val)))))
1940 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1941 (org-agenda-sticky
1942 ;; Creating a sticky Agenda buffer for the first time
1943 (kill-all-local-variables)
1944 (mapc 'make-local-variable org-agenda-local-vars)
1945 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1947 ;; Creating a non-sticky agenda buffer
1948 (kill-all-local-variables)
1949 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1950 (setq org-agenda-undo-list nil
1951 org-agenda-pending-undo-list nil
1952 org-agenda-bulk-marked-entries nil)
1953 (setq major-mode 'org-agenda-mode)
1954 ;; Keep global-font-lock-mode from turning on font-lock-mode
1955 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1956 (setq mode-name "Org-Agenda")
1957 (use-local-map org-agenda-mode-map)
1958 (easy-menu-add org-agenda-menu)
1959 (if org-startup-truncated (setq truncate-lines t))
1960 (org-set-local 'line-move-visual nil)
1961 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1962 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1963 ;; Make sure properties are removed when copying text
1964 (make-local-variable 'filter-buffer-substring-functions)
1965 (add-hook 'filter-buffer-substring-functions
1966 (lambda (fun start end delete)
1967 (substring-no-properties (funcall fun start end delete))))
1968 (unless org-agenda-keep-modes
1969 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1970 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1971 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1972 org-agenda-show-log org-agenda-start-with-log-mode))
1974 (easy-menu-change
1975 '("Agenda") "Agenda Files"
1976 (append
1977 (list
1978 (vector
1979 (if (get 'org-agenda-files 'org-restrict)
1980 "Restricted to single file"
1981 "Edit File List")
1982 '(org-edit-agenda-file-list)
1983 (not (get 'org-agenda-files 'org-restrict)))
1984 "--")
1985 (mapcar 'org-file-menu-entry (org-agenda-files))))
1986 (org-agenda-set-mode-name)
1987 (apply
1988 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1989 (list 'org-agenda-mode-hook)))
1991 (substitute-key-definition 'undo 'org-agenda-undo
1992 org-agenda-mode-map global-map)
1993 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1994 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1995 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1996 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1997 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1998 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1999 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2000 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2001 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2002 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2003 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2004 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2005 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2006 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2007 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2008 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2009 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2010 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2011 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2012 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2013 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2014 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2015 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2016 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2017 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2018 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2019 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2020 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2021 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2022 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2023 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2024 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2025 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2026 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2027 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2028 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2029 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2030 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2031 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2032 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2033 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2034 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2035 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2036 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2037 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2038 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2040 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2041 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2042 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2043 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2044 (while l (org-defkey org-agenda-mode-map
2045 (int-to-string (pop l)) 'digit-argument)))
2047 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2048 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2049 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2050 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2051 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2052 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2053 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2054 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2055 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2056 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2057 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2058 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2059 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2060 'org-clock-modify-effort-estimate)
2061 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2062 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2063 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2064 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2065 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2066 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2067 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2068 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2069 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2070 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2071 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2072 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2073 (substitute-key-definition 'next-line 'org-agenda-next-line
2074 org-agenda-mode-map global-map)
2075 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2076 org-agenda-mode-map global-map)
2077 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2078 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2079 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2080 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2081 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2082 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2083 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2084 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2085 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2086 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2087 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2088 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2089 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2090 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2091 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2092 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2093 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2094 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2095 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2096 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2097 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2098 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2099 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2100 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2101 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2102 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2103 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2104 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2105 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2106 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2108 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2109 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2110 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2111 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2112 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2113 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2114 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2115 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2116 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2117 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2119 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2121 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2122 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2123 (when org-agenda-mouse-1-follows-link
2124 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2125 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2126 '("Agenda"
2127 ("Agenda Files")
2128 "--"
2129 ("Agenda Dates"
2130 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2131 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2132 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2133 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2134 "--"
2135 ("View"
2136 ["Day View" org-agenda-day-view
2137 :active (org-agenda-check-type nil 'agenda)
2138 :style radio :selected (eq org-agenda-current-span 'day)
2139 :keys "v d (or just d)"]
2140 ["Week View" org-agenda-week-view
2141 :active (org-agenda-check-type nil 'agenda)
2142 :style radio :selected (eq org-agenda-current-span 'week)
2143 :keys "v w (or just w)"]
2144 ["Month View" org-agenda-month-view
2145 :active (org-agenda-check-type nil 'agenda)
2146 :style radio :selected (eq org-agenda-current-span 'month)
2147 :keys "v m"]
2148 ["Year View" org-agenda-year-view
2149 :active (org-agenda-check-type nil 'agenda)
2150 :style radio :selected (eq org-agenda-current-span 'year)
2151 :keys "v y"]
2152 "--"
2153 ["Include Diary" org-agenda-toggle-diary
2154 :style toggle :selected org-agenda-include-diary
2155 :active (org-agenda-check-type nil 'agenda)]
2156 ["Include Deadlines" org-agenda-toggle-deadlines
2157 :style toggle :selected org-agenda-include-deadlines
2158 :active (org-agenda-check-type nil 'agenda)]
2159 ["Use Time Grid" org-agenda-toggle-time-grid
2160 :style toggle :selected org-agenda-use-time-grid
2161 :active (org-agenda-check-type nil 'agenda)]
2162 "--"
2163 ["Show clock report" org-agenda-clockreport-mode
2164 :style toggle :selected org-agenda-clockreport-mode
2165 :active (org-agenda-check-type nil 'agenda)]
2166 ["Show some entry text" org-agenda-entry-text-mode
2167 :style toggle :selected org-agenda-entry-text-mode
2168 :active t]
2169 "--"
2170 ["Show Logbook entries" org-agenda-log-mode
2171 :style toggle :selected org-agenda-show-log
2172 :active (org-agenda-check-type nil 'agenda 'timeline)
2173 :keys "v l (or just l)"]
2174 ["Include archived trees" org-agenda-archives-mode
2175 :style toggle :selected org-agenda-archives-mode :active t
2176 :keys "v a"]
2177 ["Include archive files" (org-agenda-archives-mode t)
2178 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2179 :keys "v A"]
2180 "--"
2181 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2182 ["Write view to file" org-agenda-write t]
2183 ["Rebuild buffer" org-agenda-redo t]
2184 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2185 "--"
2186 ["Show original entry" org-agenda-show t]
2187 ["Go To (other window)" org-agenda-goto t]
2188 ["Go To (this window)" org-agenda-switch-to t]
2189 ["Follow Mode" org-agenda-follow-mode
2190 :style toggle :selected org-agenda-follow-mode :active t]
2191 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2192 "--"
2193 ("TODO"
2194 ["Cycle TODO" org-agenda-todo t]
2195 ["Next TODO set" org-agenda-todo-nextset t]
2196 ["Previous TODO set" org-agenda-todo-previousset t]
2197 ["Add note" org-agenda-add-note t])
2198 ("Archive/Refile/Delete"
2199 ["Archive default" org-agenda-archive-default t]
2200 ["Archive default" org-agenda-archive-default-with-confirmation t]
2201 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2202 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2203 ["Archive subtree" org-agenda-archive t]
2204 "--"
2205 ["Refile" org-agenda-refile t]
2206 "--"
2207 ["Delete subtree" org-agenda-kill t])
2208 ("Bulk action"
2209 ["Mark entry" org-agenda-bulk-mark t]
2210 ["Mark all" org-agenda-bulk-mark-all t]
2211 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2212 ["Unmark entry" org-agenda-bulk-unmark t]
2213 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
2214 ["Act on all marked" org-agenda-bulk-action t]
2215 "--"
2216 ("Tags and Properties"
2217 ["Show all Tags" org-agenda-show-tags t]
2218 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2219 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2220 "--"
2221 ["Column View" org-columns t])
2222 ("Deadline/Schedule"
2223 ["Schedule" org-agenda-schedule t]
2224 ["Set Deadline" org-agenda-deadline t]
2225 "--"
2226 ["Mark item" org-agenda-action :active t :keys "k m"]
2227 ["Show mark item" org-agenda-action :active t :keys "k v"]
2228 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2229 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2230 "--"
2231 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2232 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2233 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2234 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2235 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2236 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2237 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2238 ("Clock and Effort"
2239 ["Clock in" org-agenda-clock-in t]
2240 ["Clock out" org-agenda-clock-out t]
2241 ["Clock cancel" org-agenda-clock-cancel t]
2242 ["Goto running clock" org-clock-goto t]
2243 "--"
2244 ["Set Effort" org-agenda-set-effort t]
2245 ["Change clocked effort" org-clock-modify-effort-estimate
2246 (org-clock-is-active)])
2247 ("Priority"
2248 ["Set Priority" org-agenda-priority t]
2249 ["Increase Priority" org-agenda-priority-up t]
2250 ["Decrease Priority" org-agenda-priority-down t]
2251 ["Show Priority" org-agenda-show-priority t])
2252 ("Calendar/Diary"
2253 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2254 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2255 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2256 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2257 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2258 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2259 "--"
2260 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2261 "--"
2262 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2263 "--"
2264 ("MobileOrg"
2265 ["Push Files and Views" org-mobile-push t]
2266 ["Get Captured and Flagged" org-mobile-pull t]
2267 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2268 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2269 "--"
2270 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2271 "--"
2272 ["Quit" org-agenda-quit t]
2273 ["Exit and Release Buffers" org-agenda-exit t]
2276 ;;; Agenda undo
2278 (defvar org-agenda-allow-remote-undo t
2279 "Non-nil means allow remote undo from the agenda buffer.")
2280 (defvar org-agenda-undo-list nil
2281 "List of undoable operations in the agenda since last refresh.")
2282 (defvar org-agenda-undo-has-started-in nil
2283 "Buffers that have already seen `undo-start' in the current undo sequence.")
2284 (defvar org-agenda-pending-undo-list nil
2285 "In a series of undo commands, this is the list of remaining undo items.")
2287 (defun org-agenda-undo ()
2288 "Undo a remote editing step in the agenda.
2289 This undoes changes both in the agenda buffer and in the remote buffer
2290 that have been changed along."
2291 (interactive)
2292 (or org-agenda-allow-remote-undo
2293 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2294 (if (not (eq this-command last-command))
2295 (setq org-agenda-undo-has-started-in nil
2296 org-agenda-pending-undo-list org-agenda-undo-list))
2297 (if (not org-agenda-pending-undo-list)
2298 (error "No further undo information"))
2299 (let* ((entry (pop org-agenda-pending-undo-list))
2300 buf line cmd rembuf)
2301 (setq cmd (pop entry) line (pop entry))
2302 (setq rembuf (nth 2 entry))
2303 (org-with-remote-undo rembuf
2304 (while (bufferp (setq buf (pop entry)))
2305 (if (pop entry)
2306 (with-current-buffer buf
2307 (let ((last-undo-buffer buf)
2308 (inhibit-read-only t))
2309 (unless (memq buf org-agenda-undo-has-started-in)
2310 (push buf org-agenda-undo-has-started-in)
2311 (make-local-variable 'pending-undo-list)
2312 (undo-start))
2313 (while (and pending-undo-list
2314 (listp pending-undo-list)
2315 (not (car pending-undo-list)))
2316 (pop pending-undo-list))
2317 (undo-more 1))))))
2318 (org-goto-line line)
2319 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2321 (defun org-verify-change-for-undo (l1 l2)
2322 "Verify that a real change occurred between the undo lists L1 and L2."
2323 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2324 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2325 (not (eq l1 l2)))
2327 ;;; Agenda dispatch
2329 (defvar org-agenda-restrict nil)
2330 (defvar org-agenda-restrict-begin (make-marker))
2331 (defvar org-agenda-restrict-end (make-marker))
2332 (defvar org-agenda-last-dispatch-buffer nil)
2333 (defvar org-agenda-overriding-restriction nil)
2335 ;;;###autoload
2336 (defun org-agenda (&optional arg keys restriction)
2337 "Dispatch agenda commands to collect entries to the agenda buffer.
2338 Prompts for a command to execute. Any prefix arg will be passed
2339 on to the selected command. The default selections are:
2341 a Call `org-agenda-list' to display the agenda for current day or week.
2342 t Call `org-todo-list' to display the global todo list.
2343 T Call `org-todo-list' to display the global todo list, select only
2344 entries with a specific TODO keyword (the user gets a prompt).
2345 m Call `org-tags-view' to display headlines with tags matching
2346 a condition (the user is prompted for the condition).
2347 M Like `m', but select only TODO entries, no ordinary headlines.
2348 L Create a timeline for the current buffer.
2349 e Export views to associated files.
2350 s Search entries for keywords.
2351 / Multi occur across all agenda files and also files listed
2352 in `org-agenda-text-search-extra-files'.
2353 < Restrict agenda commands to buffer, subtree, or region.
2354 Press several times to get the desired effect.
2355 > Remove a previous restriction.
2356 # List \"stuck\" projects.
2357 ! Configure what \"stuck\" means.
2358 C Configure custom agenda commands.
2360 More commands can be added by configuring the variable
2361 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2362 searches can be pre-defined in this way.
2364 If the current buffer is in Org-mode and visiting a file, you can also
2365 first press `<' once to indicate that the agenda should be temporarily
2366 \(until the next use of \\[org-agenda]) restricted to the current file.
2367 Pressing `<' twice means to restrict to the current subtree or region
2368 \(if active)."
2369 (interactive "P")
2370 (catch 'exit
2371 (let* ((prefix-descriptions nil)
2372 (org-agenda-buffer-name org-agenda-buffer-name)
2373 (org-agenda-window-setup (if (equal (buffer-name)
2374 org-agenda-buffer-name)
2375 'current-window
2376 org-agenda-window-setup))
2377 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2378 (org-agenda-custom-commands
2379 ;; normalize different versions
2380 (delq nil
2381 (mapcar
2382 (lambda (x)
2383 (cond ((stringp (cdr x))
2384 (push x prefix-descriptions)
2385 nil)
2386 ((stringp (nth 1 x)) x)
2387 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2388 (t (cons (car x) (cons "" (cdr x))))))
2389 org-agenda-custom-commands)))
2390 (buf (current-buffer))
2391 (bfn (buffer-file-name (buffer-base-buffer)))
2392 entry key type match lprops ans)
2393 ;; Turn off restriction unless there is an overriding one,
2394 (unless org-agenda-overriding-restriction
2395 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2396 ;; There is a request to keep the file list in place
2397 (put 'org-agenda-files 'org-restrict nil))
2398 (setq org-agenda-restrict nil)
2399 (move-marker org-agenda-restrict-begin nil)
2400 (move-marker org-agenda-restrict-end nil))
2401 ;; Delete old local properties
2402 (put 'org-agenda-redo-command 'org-lprops nil)
2403 ;; Delete previously set last-arguments
2404 (put 'org-agenda-redo-command 'last-args nil)
2405 ;; Remember where this call originated
2406 (setq org-agenda-last-dispatch-buffer (current-buffer))
2407 (unless keys
2408 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2409 keys (car ans)
2410 restriction (cdr ans)))
2411 ;; If we have sticky agenda buffers, set a name for the buffer,
2412 ;; depending on the invoking keys. The user may still set this
2413 ;; as a command option, which will overwrite what we do here.
2414 (if org-agenda-sticky
2415 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2416 ;; Establish the restriction, if any
2417 (when (and (not org-agenda-overriding-restriction) restriction)
2418 (put 'org-agenda-files 'org-restrict (list bfn))
2419 (cond
2420 ((eq restriction 'region)
2421 (setq org-agenda-restrict t)
2422 (move-marker org-agenda-restrict-begin (region-beginning))
2423 (move-marker org-agenda-restrict-end (region-end)))
2424 ((eq restriction 'subtree)
2425 (save-excursion
2426 (setq org-agenda-restrict t)
2427 (org-back-to-heading t)
2428 (move-marker org-agenda-restrict-begin (point))
2429 (move-marker org-agenda-restrict-end
2430 (progn (org-end-of-subtree t)))))))
2432 ;; For example the todo list should not need it (but does...)
2433 (cond
2434 ((setq entry (assoc keys org-agenda-custom-commands))
2435 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2436 (progn
2437 (setq type (nth 2 entry) match (eval (nth 3 entry))
2438 lprops (nth 4 entry))
2439 (put 'org-agenda-redo-command 'org-lprops lprops)
2440 (cond
2441 ((eq type 'agenda)
2442 (org-let lprops '(org-agenda-list current-prefix-arg)))
2443 ((eq type 'alltodo)
2444 (org-let lprops '(org-todo-list current-prefix-arg)))
2445 ((eq type 'search)
2446 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2447 ((eq type 'stuck)
2448 (org-let lprops '(org-agenda-list-stuck-projects
2449 current-prefix-arg)))
2450 ((eq type 'tags)
2451 (org-let lprops '(org-tags-view current-prefix-arg match)))
2452 ((eq type 'tags-todo)
2453 (org-let lprops '(org-tags-view '(4) match)))
2454 ((eq type 'todo)
2455 (org-let lprops '(org-todo-list match)))
2456 ((eq type 'tags-tree)
2457 (org-check-for-org-mode)
2458 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2459 ((eq type 'todo-tree)
2460 (org-check-for-org-mode)
2461 (org-let lprops
2462 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2463 (regexp-quote match) "\\>"))))
2464 ((eq type 'occur-tree)
2465 (org-check-for-org-mode)
2466 (org-let lprops '(org-occur match)))
2467 ((functionp type)
2468 (org-let lprops '(funcall type match)))
2469 ((fboundp type)
2470 (org-let lprops '(funcall type match)))
2471 (t (error "Invalid custom agenda command type %s" type))))
2472 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2473 ((equal keys "C")
2474 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2475 (customize-variable 'org-agenda-custom-commands))
2476 ((equal keys "a") (call-interactively 'org-agenda-list))
2477 ((equal keys "s") (call-interactively 'org-search-view))
2478 ((equal keys "t") (call-interactively 'org-todo-list))
2479 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2480 ((equal keys "m") (call-interactively 'org-tags-view))
2481 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2482 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2483 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2484 (org-add-hook
2485 'post-command-hook
2486 (lambda ()
2487 (unless (current-message)
2488 (let* ((m (org-agenda-get-any-marker))
2489 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2490 (when note
2491 (message (concat
2492 "FLAGGING-NOTE ([?] for more info): "
2493 (org-add-props
2494 (replace-regexp-in-string
2495 "\\\\n" "//"
2496 (copy-sequence note))
2497 nil 'face 'org-warning)))))))
2498 t t))
2499 ((equal keys "L")
2500 (unless (derived-mode-p 'org-mode)
2501 (error "This is not an Org-mode file"))
2502 (unless restriction
2503 (put 'org-agenda-files 'org-restrict (list bfn))
2504 (org-call-with-arg 'org-timeline arg)))
2505 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2506 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2507 ((equal keys "!") (customize-variable 'org-stuck-projects))
2508 (t (error "Invalid agenda key"))))))
2510 (defun org-agenda-append-agenda ()
2511 "Append another agenda view to the current one.
2512 This function allows interactive building of block agendas.
2513 Agenda views are separated by `org-agenda-block-separator'."
2514 (interactive)
2515 (unless (string= (buffer-name) org-agenda-buffer-name)
2516 (error "Can only append from within agenda buffer"))
2517 (let ((org-agenda-multi t))
2518 (org-agenda)
2519 (widen)))
2521 (defun org-agenda-normalize-custom-commands (cmds)
2522 (delq nil
2523 (mapcar
2524 (lambda (x)
2525 (cond ((stringp (cdr x)) nil)
2526 ((stringp (nth 1 x)) x)
2527 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2528 (t (cons (car x) (cons "" (cdr x))))))
2529 cmds)))
2531 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2532 "The user interface for selecting an agenda command."
2533 (catch 'exit
2534 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2535 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2536 (region-p (org-region-active-p))
2537 (custom org-agenda-custom-commands)
2538 (selstring "")
2539 restriction second-time
2540 c entry key type match prefixes rmheader header-end custom1 desc
2541 line lines left right n n1)
2542 (save-window-excursion
2543 (delete-other-windows)
2544 (org-switch-to-buffer-other-window " *Agenda Commands*")
2545 (erase-buffer)
2546 (insert (eval-when-compile
2547 (let ((header
2548 "Press key for an agenda command: < Buffer, subtree/region restriction
2549 -------------------------------- > Remove restriction
2550 a Agenda for current week or day e Export agenda views
2551 t List of all TODO entries T Entries with special TODO kwd
2552 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2553 L Timeline for current buffer # List stuck projects (!=configure)
2554 s Search for keywords * Toggle sticky agenda views
2555 / Multi-occur ? Find :FLAGGED: entries
2556 C Configure custom agenda commands
2558 (start 0))
2559 (while (string-match
2560 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2561 header start)
2562 (setq start (match-end 0))
2563 (add-text-properties (match-beginning 2) (match-end 2)
2564 '(face bold) header))
2565 header)))
2566 (setq header-end (move-marker (make-marker) (point)))
2567 (while t
2568 (setq custom1 custom)
2569 (when (eq rmheader t)
2570 (org-goto-line 1)
2571 (re-search-forward ":" nil t)
2572 (delete-region (match-end 0) (point-at-eol))
2573 (forward-char 1)
2574 (looking-at "-+")
2575 (delete-region (match-end 0) (point-at-eol))
2576 (move-marker header-end (match-end 0)))
2577 (goto-char header-end)
2578 (delete-region (point) (point-max))
2580 ;; Produce all the lines that describe custom commands and prefixes
2581 (setq lines nil)
2582 (while (setq entry (pop custom1))
2583 (setq key (car entry) desc (nth 1 entry)
2584 type (nth 2 entry)
2585 match (nth 3 entry))
2586 (if (> (length key) 1)
2587 (add-to-list 'prefixes (string-to-char key))
2588 (setq line
2589 (format
2590 "%-4s%-14s"
2591 (org-add-props (copy-sequence key)
2592 '(face bold))
2593 (cond
2594 ((string-match "\\S-" desc) desc)
2595 ((eq type 'agenda) "Agenda for current week or day")
2596 ((eq type 'alltodo) "List of all TODO entries")
2597 ((eq type 'search) "Word search")
2598 ((eq type 'stuck) "List of stuck projects")
2599 ((eq type 'todo) "TODO keyword")
2600 ((eq type 'tags) "Tags query")
2601 ((eq type 'tags-todo) "Tags (TODO)")
2602 ((eq type 'tags-tree) "Tags tree")
2603 ((eq type 'todo-tree) "TODO kwd tree")
2604 ((eq type 'occur-tree) "Occur tree")
2605 ((functionp type) (if (symbolp type)
2606 (symbol-name type)
2607 "Lambda expression"))
2608 (t "???"))))
2609 (if org-agenda-menu-show-matcher
2610 (setq line
2611 (concat line ": "
2612 (cond
2613 ((stringp match)
2614 (setq match (copy-sequence match))
2615 (org-add-props match nil 'face 'org-warning))
2616 (match
2617 (format "set of %d commands" (length match)))
2618 (t ""))))
2619 (if (org-string-nw-p match)
2620 (add-text-properties
2621 0 (length line) (list 'help-echo
2622 (concat "Matcher: "match)) line)))
2623 (push line lines)))
2624 (setq lines (nreverse lines))
2625 (when prefixes
2626 (mapc (lambda (x)
2627 (push
2628 (format "%s %s"
2629 (org-add-props (char-to-string x)
2630 nil 'face 'bold)
2631 (or (cdr (assoc (concat selstring
2632 (char-to-string x))
2633 prefix-descriptions))
2634 "Prefix key"))
2635 lines))
2636 prefixes))
2638 ;; Check if we should display in two columns
2639 (if org-agenda-menu-two-column
2640 (progn
2641 (setq n (length lines)
2642 n1 (+ (/ n 2) (mod n 2))
2643 right (nthcdr n1 lines)
2644 left (copy-sequence lines))
2645 (setcdr (nthcdr (1- n1) left) nil))
2646 (setq left lines right nil))
2647 (while left
2648 (insert "\n" (pop left))
2649 (when right
2650 (if (< (current-column) 40)
2651 (move-to-column 40 t)
2652 (insert " "))
2653 (insert (pop right))))
2655 ;; Make the window the right size
2656 (goto-char (point-min))
2657 (if second-time
2658 (if (not (pos-visible-in-window-p (point-max)))
2659 (org-fit-window-to-buffer))
2660 (setq second-time t)
2661 (org-fit-window-to-buffer))
2663 ;; Ask for selection
2664 (message "Press key for agenda command%s:"
2665 (if (or restrict-ok org-agenda-overriding-restriction)
2666 (if org-agenda-overriding-restriction
2667 " (restriction lock active)"
2668 (if restriction
2669 (format " (restricted to %s)" restriction)
2670 " (unrestricted)"))
2671 ""))
2672 (setq c (read-char-exclusive))
2673 (message "")
2674 (cond
2675 ((assoc (char-to-string c) custom)
2676 (setq selstring (concat selstring (char-to-string c)))
2677 (throw 'exit (cons selstring restriction)))
2678 ((memq c prefixes)
2679 (setq selstring (concat selstring (char-to-string c))
2680 prefixes nil
2681 rmheader (or rmheader t)
2682 custom (delq nil (mapcar
2683 (lambda (x)
2684 (if (or (= (length (car x)) 1)
2685 (/= (string-to-char (car x)) c))
2687 (cons (substring (car x) 1) (cdr x))))
2688 custom))))
2689 ((eq c ?*)
2690 (call-interactively 'org-toggle-sticky-agenda)
2691 (sit-for 2))
2692 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2693 (message "Restriction is only possible in Org-mode buffers")
2694 (ding) (sit-for 1))
2695 ((eq c ?1)
2696 (org-agenda-remove-restriction-lock 'noupdate)
2697 (setq restriction 'buffer))
2698 ((eq c ?0)
2699 (org-agenda-remove-restriction-lock 'noupdate)
2700 (setq restriction (if region-p 'region 'subtree)))
2701 ((eq c ?<)
2702 (org-agenda-remove-restriction-lock 'noupdate)
2703 (setq restriction
2704 (cond
2705 ((eq restriction 'buffer)
2706 (if region-p 'region 'subtree))
2707 ((memq restriction '(subtree region))
2708 nil)
2709 (t 'buffer))))
2710 ((eq c ?>)
2711 (org-agenda-remove-restriction-lock 'noupdate)
2712 (setq restriction nil))
2713 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2714 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2715 ((and (> (length selstring) 0) (eq c ?\d))
2716 (delete-window)
2717 (org-agenda-get-restriction-and-command prefix-descriptions))
2719 ((equal c ?q) (error "Abort"))
2720 (t (error "Invalid key %c" c))))))))
2722 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2723 (defvar org-agenda-last-arguments nil
2724 "The arguments of the previous call to `org-agenda'.")
2725 (defun org-agenda-run-series (name series)
2726 (org-let (nth 1 series) '(org-prepare-agenda name))
2727 ;; We need to reset agenda markers here, because when constructing a
2728 ;; block agenda, the individual blocks do not do that.
2729 (org-agenda-reset-markers)
2730 (let* ((org-agenda-multi t)
2731 (redo (list 'org-agenda-run-series name (list 'quote series)))
2732 (org-agenda-overriding-arguments
2733 (or org-agenda-overriding-arguments
2734 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2735 (get 'org-agenda-redo-command 'last-args))))
2736 (cmds (car series))
2737 (gprops (nth 1 series))
2738 match ;; The byte compiler incorrectly complains about this. Keep it!
2739 cmd type lprops)
2740 (while (setq cmd (pop cmds))
2741 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2742 (cond
2743 ((eq type 'agenda)
2744 (org-let2 gprops lprops
2745 '(call-interactively 'org-agenda-list)))
2746 ((eq type 'alltodo)
2747 (org-let2 gprops lprops
2748 '(call-interactively 'org-todo-list)))
2749 ((eq type 'search)
2750 (org-let2 gprops lprops
2751 '(org-search-view current-prefix-arg match nil)))
2752 ((eq type 'stuck)
2753 (org-let2 gprops lprops
2754 '(call-interactively 'org-agenda-list-stuck-projects)))
2755 ((eq type 'tags)
2756 (org-let2 gprops lprops
2757 '(org-tags-view current-prefix-arg match)))
2758 ((eq type 'tags-todo)
2759 (org-let2 gprops lprops
2760 '(org-tags-view '(4) match)))
2761 ((eq type 'todo)
2762 (org-let2 gprops lprops
2763 '(org-todo-list match)))
2764 ((fboundp type)
2765 (org-let2 gprops lprops
2766 '(funcall type match)))
2767 (t (error "Invalid type in command series"))))
2768 (widen)
2769 (setq org-agenda-redo-command redo)
2770 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2771 (goto-char (point-min)))
2772 (org-fit-agenda-window)
2773 (org-let (nth 1 series) '(org-finalize-agenda)))
2775 ;;;###autoload
2776 (defmacro org-batch-agenda (cmd-key &rest parameters)
2777 "Run an agenda command in batch mode and send the result to STDOUT.
2778 If CMD-KEY is a string of length 1, it is used as a key in
2779 `org-agenda-custom-commands' and triggers this command. If it is a
2780 longer string it is used as a tags/todo match string.
2781 Parameters are alternating variable names and values that will be bound
2782 before running the agenda command."
2783 (org-eval-in-environment (org-make-parameter-alist parameters)
2784 (if (> (length cmd-key) 2)
2785 (org-tags-view nil cmd-key)
2786 (org-agenda nil cmd-key)))
2787 (set-buffer org-agenda-buffer-name)
2788 (princ (buffer-string)))
2789 (def-edebug-spec org-batch-agenda (form &rest sexp))
2791 (defvar org-agenda-info nil)
2793 ;;;###autoload
2794 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2795 "Run an agenda command in batch mode and send the result to STDOUT.
2796 If CMD-KEY is a string of length 1, it is used as a key in
2797 `org-agenda-custom-commands' and triggers this command. If it is a
2798 longer string it is used as a tags/todo match string.
2799 Parameters are alternating variable names and values that will be bound
2800 before running the agenda command.
2802 The output gives a line for each selected agenda item. Each
2803 item is a list of comma-separated values, like this:
2805 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2807 category The category of the item
2808 head The headline, without TODO kwd, TAGS and PRIORITY
2809 type The type of the agenda entry, can be
2810 todo selected in TODO match
2811 tagsmatch selected in tags match
2812 diary imported from diary
2813 deadline a deadline on given date
2814 scheduled scheduled on given date
2815 timestamp entry has timestamp on given date
2816 closed entry was closed on given date
2817 upcoming-deadline warning about deadline
2818 past-scheduled forwarded scheduled item
2819 block entry has date block including g. date
2820 todo The todo keyword, if any
2821 tags All tags including inherited ones, separated by colons
2822 date The relevant date, like 2007-2-14
2823 time The time, like 15:00-16:50
2824 extra Sting with extra planning info
2825 priority-l The priority letter if any was given
2826 priority-n The computed numerical priority
2827 agenda-day The day in the agenda where this is listed"
2828 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2829 (org-make-parameter-alist parameters))
2830 (if (> (length cmd-key) 2)
2831 (org-tags-view nil cmd-key)
2832 (org-agenda nil cmd-key)))
2833 (set-buffer org-agenda-buffer-name)
2834 (let* ((lines (org-split-string (buffer-string) "\n"))
2835 line)
2836 (while (setq line (pop lines))
2837 (catch 'next
2838 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2839 (setq org-agenda-info
2840 (org-fix-agenda-info (text-properties-at 0 line)))
2841 (princ
2842 (mapconcat 'org-agenda-export-csv-mapper
2843 '(org-category txt type todo tags date time extra
2844 priority-letter priority agenda-day)
2845 ","))
2846 (princ "\n")))))
2847 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2849 (defun org-fix-agenda-info (props)
2850 "Make sure all properties on an agenda item have a canonical form.
2851 This ensures the export commands can easily use it."
2852 (let (tmp re)
2853 (when (setq tmp (plist-get props 'tags))
2854 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2855 (when (setq tmp (plist-get props 'date))
2856 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2857 (let ((calendar-date-display-form '(year "-" month "-" day)))
2858 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2860 (setq tmp (calendar-date-string tmp)))
2861 (setq props (plist-put props 'date tmp)))
2862 (when (setq tmp (plist-get props 'day))
2863 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2864 (let ((calendar-date-display-form '(year "-" month "-" day)))
2865 (setq tmp (calendar-date-string tmp)))
2866 (setq props (plist-put props 'day tmp))
2867 (setq props (plist-put props 'agenda-day tmp)))
2868 (when (setq tmp (plist-get props 'txt))
2869 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2870 (plist-put props 'priority-letter (match-string 1 tmp))
2871 (setq tmp (replace-match "" t t tmp)))
2872 (when (and (setq re (plist-get props 'org-todo-regexp))
2873 (setq re (concat "\\`\\.*" re " ?"))
2874 (string-match re tmp))
2875 (plist-put props 'todo (match-string 1 tmp))
2876 (setq tmp (replace-match "" t t tmp)))
2877 (plist-put props 'txt tmp)))
2878 props)
2880 (defun org-agenda-export-csv-mapper (prop)
2881 (let ((res (plist-get org-agenda-info prop)))
2882 (setq res
2883 (cond
2884 ((not res) "")
2885 ((stringp res) res)
2886 (t (prin1-to-string res))))
2887 (while (string-match "," res)
2888 (setq res (replace-match ";" t t res)))
2889 (org-trim res)))
2891 ;;;###autoload
2892 (defun org-store-agenda-views (&rest parameters)
2893 (interactive)
2894 (eval (list 'org-batch-store-agenda-views)))
2896 ;;;###autoload
2897 (defmacro org-batch-store-agenda-views (&rest parameters)
2898 "Run all custom agenda commands that have a file argument."
2899 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2900 (pop-up-frames nil)
2901 (dir default-directory)
2902 (pars (org-make-parameter-alist parameters))
2903 cmd thiscmdkey files opts cmd-or-set bufname)
2904 (save-window-excursion
2905 (while cmds
2906 (setq cmd (pop cmds)
2907 thiscmdkey (car cmd)
2908 bufname (if org-agenda-sticky (format "*Org Agenda(%s)*" thiscmdkey)
2909 org-agenda-buffer-name)
2910 cmd-or-set (nth 2 cmd)
2911 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2912 files (nth (if (listp cmd-or-set) 4 5) cmd))
2913 (if (stringp files) (setq files (list files)))
2914 (when files
2915 (org-eval-in-environment (append org-agenda-exporter-settings
2916 opts pars)
2917 (org-agenda nil thiscmdkey))
2918 (set-buffer bufname)
2919 (while files
2920 (org-eval-in-environment (append org-agenda-exporter-settings
2921 opts pars)
2922 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
2923 (and (get-buffer bufname)
2924 (kill-buffer bufname)))))))
2925 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2927 (defun org-agenda-mark-header-line (pos)
2928 "Mark the line at POS as an agenda structure header."
2929 (save-excursion
2930 (goto-char pos)
2931 (put-text-property (point-at-bol) (point-at-eol)
2932 'org-agenda-structural-header t)
2933 (when org-agenda-title-append
2934 (put-text-property (point-at-bol) (point-at-eol)
2935 'org-agenda-title-append org-agenda-title-append))))
2937 (defvar org-mobile-creating-agendas)
2938 (defvar org-agenda-write-buffer-name "Agenda View")
2939 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
2940 "Write the current buffer (an agenda view) as a file.
2941 Depending on the extension of the file name, plain text (.txt),
2942 HTML (.html or .htm) or Postscript (.ps) is produced.
2943 If the extension is .ics, run icalendar export over all files used
2944 to construct the agenda and limit the export to entries listed in the
2945 agenda now.
2946 With prefix argument OPEN, open the new file immediately.
2947 If NOSETTINGS is given, do not scope the settings of
2948 `org-agenda-exporter-settings' into the export commands. This is used when
2949 the settings have already been scoped and we do not wish to overrule other,
2950 higher priority settings.
2951 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
2952 (interactive "FWrite agenda to file: \nP")
2953 (if (not (file-writable-p file))
2954 (error "Cannot write agenda to file %s" file))
2955 (org-let (if nosettings nil org-agenda-exporter-settings)
2956 '(save-excursion
2957 (save-window-excursion
2958 (org-agenda-mark-filtered-text)
2959 (let ((bs (copy-sequence (buffer-string))) beg)
2960 (org-agenda-unmark-filtered-text)
2961 (with-temp-buffer
2962 (rename-buffer org-agenda-write-buffer-name t)
2963 (set-buffer-modified-p nil)
2964 (insert bs)
2965 (org-agenda-remove-marked-text 'org-filtered)
2966 (while (setq beg (text-property-any (point-min) (point-max)
2967 'org-filtered t))
2968 (delete-region
2969 beg (or (next-single-property-change beg 'org-filtered)
2970 (point-max))))
2971 (run-hooks 'org-agenda-before-write-hook)
2972 (cond
2973 ((org-bound-and-true-p org-mobile-creating-agendas)
2974 (org-mobile-write-agenda-for-mobile file))
2975 ((string-match "\\.html?\\'" file)
2976 (require 'htmlize)
2977 (set-buffer (htmlize-buffer (current-buffer)))
2978 (when (and org-agenda-export-html-style
2979 (string-match "<style>" org-agenda-export-html-style))
2980 ;; replace <style> section with org-agenda-export-html-style
2981 (goto-char (point-min))
2982 (kill-region (- (search-forward "<style") 6)
2983 (search-forward "</style>"))
2984 (insert org-agenda-export-html-style))
2985 (write-file file)
2986 (kill-buffer (current-buffer))
2987 (message "HTML written to %s" file))
2988 ((string-match "\\.ps\\'" file)
2989 (require 'ps-print)
2990 (ps-print-buffer-with-faces file)
2991 (message "Postscript written to %s" file))
2992 ((string-match "\\.pdf\\'" file)
2993 (require 'ps-print)
2994 (ps-print-buffer-with-faces
2995 (concat (file-name-sans-extension file) ".ps"))
2996 (call-process "ps2pdf" nil nil nil
2997 (expand-file-name
2998 (concat (file-name-sans-extension file) ".ps"))
2999 (expand-file-name file))
3000 (delete-file (concat (file-name-sans-extension file) ".ps"))
3001 (message "PDF written to %s" file))
3002 ((string-match "\\.ics\\'" file)
3003 (require 'org-icalendar)
3004 (let ((org-agenda-marker-table
3005 (org-create-marker-find-array
3006 (org-agenda-collect-markers)))
3007 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3008 (org-combined-agenda-icalendar-file file))
3009 (apply 'org-export-icalendar 'combine
3010 (org-agenda-files nil 'ifmode))))
3012 (let ((bs (buffer-string)))
3013 (find-file file)
3014 (erase-buffer)
3015 (insert bs)
3016 (save-buffer 0)
3017 (kill-buffer (current-buffer))
3018 (message "Plain text written to %s" file))))))))
3019 (set-buffer (or agenda-bufname
3020 (and (called-interactively-p 'any) (buffer-name))
3021 org-agenda-buffer-name)))
3022 (when open (org-open-file file)))
3024 (defvar org-agenda-tag-filter-overlays nil)
3025 (defvar org-agenda-cat-filter-overlays nil)
3027 (defun org-agenda-mark-filtered-text ()
3028 "Mark all text hidden by filtering with a text property."
3029 (let ((inhibit-read-only t))
3030 (mapc
3031 (lambda (o)
3032 (when (equal (overlay-buffer o) (current-buffer))
3033 (put-text-property
3034 (overlay-start o) (overlay-end o)
3035 'org-filtered t)))
3036 (append org-agenda-tag-filter-overlays
3037 org-agenda-cat-filter-overlays))))
3039 (defun org-agenda-unmark-filtered-text ()
3040 "Remove the filtering text property."
3041 (let ((inhibit-read-only t))
3042 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3044 (defun org-agenda-remove-marked-text (property &optional value)
3045 "Delete all text marked with VALUE of PROPERTY.
3046 VALUE defaults to t."
3047 (let (beg)
3048 (setq value (or value t))
3049 (while (setq beg (text-property-any (point-min) (point-max)
3050 property value))
3051 (delete-region
3052 beg (or (next-single-property-change beg 'org-filtered)
3053 (point-max))))))
3055 (defun org-agenda-add-entry-text ()
3056 "Add entry text to agenda lines.
3057 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3058 entry text following headings shown in the agenda.
3059 Drawers will be excluded, also the line with scheduling/deadline info."
3060 (when (and (> org-agenda-add-entry-text-maxlines 0)
3061 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3062 (let (m txt)
3063 (goto-char (point-min))
3064 (while (not (eobp))
3065 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3066 (beginning-of-line 2)
3067 (setq txt (org-agenda-get-some-entry-text
3068 m org-agenda-add-entry-text-maxlines " > "))
3069 (end-of-line 1)
3070 (if (string-match "\\S-" txt)
3071 (insert "\n" txt)
3072 (or (eobp) (forward-char 1))))))))
3074 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3075 &rest keep)
3076 "Extract entry text from MARKER, at most N-LINES lines.
3077 This will ignore drawers etc, just get the text.
3078 If INDENT is given, prefix every line with this string. If KEEP is
3079 given, it is a list of symbols, defining stuff that should not be
3080 removed from the entry content. Currently only `planning' is allowed here."
3081 (let (txt drawer-re kwd-time-re ind)
3082 (save-excursion
3083 (with-current-buffer (marker-buffer marker)
3084 (if (not (derived-mode-p 'org-mode))
3085 (setq txt "")
3086 (save-excursion
3087 (save-restriction
3088 (widen)
3089 (goto-char marker)
3090 (end-of-line 1)
3091 (setq txt (buffer-substring
3092 (min (1+ (point)) (point-max))
3093 (progn (outline-next-heading) (point)))
3094 drawer-re org-drawer-regexp
3095 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3096 ".*\n?"))
3097 (with-temp-buffer
3098 (insert txt)
3099 (when org-agenda-add-entry-text-descriptive-links
3100 (goto-char (point-min))
3101 (while (org-activate-bracket-links (point-max))
3102 (add-text-properties (match-beginning 0) (match-end 0)
3103 '(face org-link))))
3104 (goto-char (point-min))
3105 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3106 (set-text-properties (match-beginning 0) (match-end 0)
3107 nil))
3108 (goto-char (point-min))
3109 (while (re-search-forward drawer-re nil t)
3110 (delete-region
3111 (match-beginning 0)
3112 (progn (re-search-forward
3113 "^[ \t]*:END:.*\n?" nil 'move)
3114 (point))))
3115 (unless (member 'planning keep)
3116 (goto-char (point-min))
3117 (while (re-search-forward kwd-time-re nil t)
3118 (replace-match "")))
3119 (goto-char (point-min))
3120 (when org-agenda-entry-text-exclude-regexps
3121 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3122 (while (setq re (pop re-list))
3123 (goto-char (point-min))
3124 (while (re-search-forward re nil t)
3125 (replace-match "")))))
3126 (goto-char (point-max))
3127 (skip-chars-backward " \t\n")
3128 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3130 ;; find and remove min common indentation
3131 (goto-char (point-min))
3132 (untabify (point-min) (point-max))
3133 (setq ind (org-get-indentation))
3134 (while (not (eobp))
3135 (unless (looking-at "[ \t]*$")
3136 (setq ind (min ind (org-get-indentation))))
3137 (beginning-of-line 2))
3138 (goto-char (point-min))
3139 (while (not (eobp))
3140 (unless (looking-at "[ \t]*$")
3141 (move-to-column ind)
3142 (delete-region (point-at-bol) (point)))
3143 (beginning-of-line 2))
3145 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3147 (goto-char (point-min))
3148 (when indent
3149 (while (and (not (eobp)) (re-search-forward "^" nil t))
3150 (replace-match indent t t)))
3151 (goto-char (point-min))
3152 (while (looking-at "[ \t]*\n") (replace-match ""))
3153 (goto-char (point-max))
3154 (when (> (org-current-line)
3155 n-lines)
3156 (org-goto-line (1+ n-lines))
3157 (backward-char 1))
3158 (setq txt (buffer-substring (point-min) (point)))))))))
3159 txt))
3161 (defun org-agenda-collect-markers ()
3162 "Collect the markers pointing to entries in the agenda buffer."
3163 (let (m markers)
3164 (save-excursion
3165 (goto-char (point-min))
3166 (while (not (eobp))
3167 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3168 (org-get-at-bol 'org-marker)))
3169 (push m markers))
3170 (beginning-of-line 2)))
3171 (nreverse markers)))
3173 (defun org-create-marker-find-array (marker-list)
3174 "Create a alist of files names with all marker positions in that file."
3175 (let (f tbl m a p)
3176 (while (setq m (pop marker-list))
3177 (setq p (marker-position m)
3178 f (buffer-file-name (or (buffer-base-buffer
3179 (marker-buffer m))
3180 (marker-buffer m))))
3181 (if (setq a (assoc f tbl))
3182 (push (marker-position m) (cdr a))
3183 (push (list f p) tbl)))
3184 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3185 tbl)))
3187 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3188 (defun org-check-agenda-marker-table ()
3189 "Check of the current entry is on the marker list."
3190 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3192 (and (setq a (assoc file org-agenda-marker-table))
3193 (save-match-data
3194 (save-excursion
3195 (org-back-to-heading t)
3196 (member (point) (cdr a)))))))
3198 (defun org-check-for-org-mode ()
3199 "Make sure current buffer is in org-mode. Error if not."
3200 (or (derived-mode-p 'org-mode)
3201 (error "Cannot execute org-mode agenda command on buffer in %s"
3202 major-mode)))
3204 (defun org-fit-agenda-window ()
3205 "Fit the window to the buffer size."
3206 (and (memq org-agenda-window-setup '(reorganize-frame))
3207 (fboundp 'fit-window-to-buffer)
3208 (org-fit-window-to-buffer
3210 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3211 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3213 ;;; Agenda prepare and finalize
3215 (defvar org-agenda-multi nil) ; dynamically scoped
3216 (defvar org-agenda-buffer-name "*Org Agenda*")
3217 (defvar org-pre-agenda-window-conf nil)
3218 (defvar org-agenda-columns-active nil)
3219 (defvar org-agenda-name nil)
3220 (defvar org-agenda-tag-filter nil)
3221 (defvar org-agenda-category-filter nil)
3222 (defvar org-agenda-top-category-filter nil)
3223 (defvar org-agenda-tag-filter-while-redo nil)
3224 (defvar org-agenda-tag-filter-preset nil
3225 "A preset of the tags filter used for secondary agenda filtering.
3226 This must be a list of strings, each string must be a single tag preceded
3227 by \"+\" or \"-\".
3228 This variable should not be set directly, but agenda custom commands can
3229 bind it in the options section. The preset filter is a global property of
3230 the entire agenda view. In a block agenda, it will not work reliably to
3231 define a filter for one of the individual blocks. You need to set it in
3232 the global options and expect it to be applied to the entire view.")
3234 (defvar org-agenda-category-filter-preset nil
3235 "A preset of the category filter used for secondary agenda filtering.
3236 This must be a list of strings, each string must be a single category
3237 preceded by \"+\" or \"-\".
3238 This variable should not be set directly, but agenda custom commands can
3239 bind it in the options section. The preset filter is a global property of
3240 the entire agenda view. In a block agenda, it will not work reliably to
3241 define a filter for one of the individual blocks. You need to set it in
3242 the global options and expect it to be applied to the entire view.")
3245 (defun org-agenda-use-sticky-p ()
3246 "Return non-nil if an agenda buffer named
3247 `org-agenda-buffer-name' exists and should be shown instead of
3248 generating a new one."
3249 (and
3250 ;; turned off by user
3251 org-agenda-sticky
3252 ;; For multi-agenda buffer already exists
3253 (not org-agenda-multi)
3254 ;; buffer found
3255 (get-buffer org-agenda-buffer-name)
3256 ;; C-u parameter is same as last call
3257 (with-current-buffer (get-buffer org-agenda-buffer-name)
3258 (and
3259 (equal current-prefix-arg
3260 org-agenda-last-prefix-arg)
3261 ;; In case user turned stickiness on, while having existing
3262 ;; Agenda buffer active, don't reuse that buffer, because it
3263 ;; does not have org variables local
3264 org-agenda-this-buffer-is-sticky))))
3266 (defun org-prepare-agenda-window (abuf)
3267 "Setup agenda buffer in the window."
3268 (let* ((awin (get-buffer-window abuf))
3269 wconf)
3270 (cond
3271 ((equal (current-buffer) abuf) nil)
3272 (awin (select-window awin))
3273 ((not (setq wconf (current-window-configuration))))
3274 ((equal org-agenda-window-setup 'current-window)
3275 (org-pop-to-buffer-same-window abuf))
3276 ((equal org-agenda-window-setup 'other-window)
3277 (org-switch-to-buffer-other-window abuf))
3278 ((equal org-agenda-window-setup 'other-frame)
3279 (switch-to-buffer-other-frame abuf))
3280 ((equal org-agenda-window-setup 'reorganize-frame)
3281 (delete-other-windows)
3282 (org-switch-to-buffer-other-window abuf)))
3283 ;; additional test in case agenda is invoked from within agenda
3284 ;; buffer via elisp link
3285 (unless (equal (current-buffer) abuf)
3286 (org-pop-to-buffer-same-window abuf))
3287 (setq org-pre-agenda-window-conf wconf)))
3289 (defun org-prepare-agenda (&optional name)
3290 (if (org-agenda-use-sticky-p)
3291 (progn
3292 ;; Popup existing buffer
3293 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3294 (message "Sticky Agenda buffer, use `r' to refresh")
3295 (throw 'exit nil))
3296 (setq org-todo-keywords-for-agenda nil)
3297 (setq org-drawers-for-agenda nil)
3298 (unless org-agenda-persistent-filter
3299 (setq org-agenda-tag-filter nil
3300 org-agenda-category-filter nil))
3301 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3302 (put 'org-agenda-category-filter :preset-filter
3303 org-agenda-category-filter-preset)
3304 (if org-agenda-multi
3305 (progn
3306 (setq buffer-read-only nil)
3307 (goto-char (point-max))
3308 (unless (or (bobp) org-agenda-compact-blocks
3309 (not org-agenda-block-separator))
3310 (insert "\n"
3311 (if (stringp org-agenda-block-separator)
3312 org-agenda-block-separator
3313 (make-string (window-width) org-agenda-block-separator))
3314 "\n"))
3315 (narrow-to-region (point) (point-max)))
3316 (setq org-done-keywords-for-agenda nil)
3318 ;; Setting any org variables that are in org-agenda-local-vars
3319 ;; list need to be done after the prepare call
3320 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3321 (setq buffer-read-only nil)
3322 (org-agenda-reset-markers)
3323 (let ((inhibit-read-only t)) (erase-buffer))
3324 (org-agenda-mode)
3325 (setq org-agenda-buffer (current-buffer))
3326 (setq org-agenda-contributing-files nil)
3327 (setq org-agenda-columns-active nil)
3328 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3329 (setq org-todo-keywords-for-agenda
3330 (org-uniquify org-todo-keywords-for-agenda))
3331 (setq org-done-keywords-for-agenda
3332 (org-uniquify org-done-keywords-for-agenda))
3333 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3334 (setq org-agenda-last-prefix-arg current-prefix-arg)
3335 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3336 (and name (not org-agenda-name)
3337 (org-set-local 'org-agenda-name name)))
3338 (setq buffer-read-only nil)))
3340 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3341 (defun org-finalize-agenda ()
3342 "Finishing touch for the agenda buffer, called just before displaying it."
3343 (unless org-agenda-multi
3344 (save-excursion
3345 (let ((inhibit-read-only t))
3346 (goto-char (point-min))
3347 (while (org-activate-bracket-links (point-max))
3348 (add-text-properties (match-beginning 0) (match-end 0)
3349 '(face org-link)))
3350 (org-agenda-align-tags)
3351 (unless org-agenda-with-colors
3352 (remove-text-properties (point-min) (point-max) '(face nil))))
3353 (if (and (boundp 'org-agenda-overriding-columns-format)
3354 org-agenda-overriding-columns-format)
3355 (org-set-local 'org-agenda-overriding-columns-format
3356 org-agenda-overriding-columns-format))
3357 (if (and (boundp 'org-agenda-view-columns-initially)
3358 org-agenda-view-columns-initially)
3359 (org-agenda-columns))
3360 (when org-agenda-fontify-priorities
3361 (org-agenda-fontify-priorities))
3362 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3363 (org-agenda-dim-blocked-tasks))
3364 (org-agenda-mark-clocking-task)
3365 (when org-agenda-entry-text-mode
3366 (org-agenda-entry-text-hide)
3367 (org-agenda-entry-text-show))
3368 (if (functionp 'org-habit-insert-consistency-graphs)
3369 (org-habit-insert-consistency-graphs))
3370 (run-hooks 'org-finalize-agenda-hook)
3371 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3372 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3373 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3374 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3375 (org-agenda-filter-apply org-agenda-category-filter 'category))
3376 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3379 (defun org-agenda-mark-clocking-task ()
3380 "Mark the current clock entry in the agenda if it is present."
3381 (mapc (lambda (o)
3382 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3383 (delete-overlay o)))
3384 (overlays-in (point-min) (point-max)))
3385 (when (marker-buffer org-clock-hd-marker)
3386 (save-excursion
3387 (goto-char (point-min))
3388 (let (s ov)
3389 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3390 (goto-char s)
3391 (when (equal (org-get-at-bol 'org-hd-marker)
3392 org-clock-hd-marker)
3393 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3394 (overlay-put ov 'type 'org-agenda-clocking)
3395 (overlay-put ov 'face 'org-agenda-clocking)
3396 (overlay-put ov 'help-echo
3397 "The clock is running in this item")))))))
3399 (defun org-agenda-fontify-priorities ()
3400 "Make highest priority lines bold, and lowest italic."
3401 (interactive)
3402 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3403 (delete-overlay o)))
3404 (overlays-in (point-min) (point-max)))
3405 (save-excursion
3406 (let ((inhibit-read-only t)
3407 b e p ov h l)
3408 (goto-char (point-min))
3409 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3410 (setq h (or (get-char-property (point) 'org-highest-priority)
3411 org-highest-priority)
3412 l (or (get-char-property (point) 'org-lowest-priority)
3413 org-lowest-priority)
3414 p (string-to-char (match-string 1))
3415 b (match-beginning 0)
3416 e (if (eq org-agenda-fontify-priorities 'cookies)
3417 (match-end 0)
3418 (point-at-eol))
3419 ov (make-overlay b e))
3420 (overlay-put
3421 ov 'face
3422 (cond ((org-face-from-face-or-color
3423 'priority nil
3424 (cdr (assoc p org-priority-faces))))
3425 ((and (listp org-agenda-fontify-priorities)
3426 (org-face-from-face-or-color
3427 'priority nil
3428 (cdr (assoc p org-agenda-fontify-priorities)))))
3429 ((equal p l) 'italic)
3430 ((equal p h) 'bold)))
3431 (overlay-put ov 'org-type 'org-priority)))))
3433 (defun org-agenda-dim-blocked-tasks ()
3434 "Dim currently blocked TODO's in the agenda display."
3435 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3436 (delete-overlay o)))
3437 (overlays-in (point-min) (point-max)))
3438 (save-excursion
3439 (let ((inhibit-read-only t)
3440 (org-depend-tag-blocked nil)
3441 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3442 org-blocked-by-checkboxes
3443 invis1 b e p ov h l)
3444 (goto-char (point-min))
3445 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3446 (and pos (goto-char (1+ pos))))
3447 (setq org-blocked-by-checkboxes nil invis1 invis)
3448 (let ((marker (org-get-at-bol 'org-hd-marker)))
3449 (when (and marker
3450 (with-current-buffer (marker-buffer marker)
3451 (save-excursion (goto-char marker)
3452 (org-entry-blocked-p))))
3453 (if org-blocked-by-checkboxes (setq invis1 nil))
3454 (setq b (if invis1
3455 (max (point-min) (1- (point-at-bol)))
3456 (point-at-bol))
3457 e (point-at-eol)
3458 ov (make-overlay b e))
3459 (if invis1
3460 (overlay-put ov 'invisible t)
3461 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3462 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3464 (defvar org-agenda-skip-function nil
3465 "Function to be called at each match during agenda construction.
3466 If this function returns nil, the current match should not be skipped.
3467 Otherwise, the function must return a position from where the search
3468 should be continued.
3469 This may also be a Lisp form, it will be evaluated.
3470 Never set this variable using `setq' or so, because then it will apply
3471 to all future agenda commands. If you do want a global skipping condition,
3472 use the option `org-agenda-skip-function-global' instead.
3473 The correct usage for `org-agenda-skip-function' is to bind it with
3474 `let' to scope it dynamically into the agenda-constructing command.
3475 A good way to set it is through options in `org-agenda-custom-commands'.")
3477 (defun org-agenda-skip ()
3478 "Throw to `:skip' in places that should be skipped.
3479 Also moves point to the end of the skipped region, so that search can
3480 continue from there."
3481 (let ((p (point-at-bol)) to)
3482 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3483 (get-text-property p :org-archived)
3484 (org-end-of-subtree t)
3485 (throw :skip t))
3486 (and org-agenda-skip-comment-trees
3487 (get-text-property p :org-comment)
3488 (org-end-of-subtree t)
3489 (throw :skip t))
3490 (if (equal (char-after p) ?#) (throw :skip t))
3491 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3492 (org-agenda-skip-eval org-agenda-skip-function)))
3493 (goto-char to)
3494 (throw :skip t))))
3496 (defun org-agenda-skip-eval (form)
3497 "If FORM is a function or a list, call (or eval) is and return result.
3498 `save-excursion' and `save-match-data' are wrapped around the call, so point
3499 and match data are returned to the previous state no matter what these
3500 functions do."
3501 (let (fp)
3502 (and form
3503 (or (setq fp (functionp form))
3504 (consp form))
3505 (save-excursion
3506 (save-match-data
3507 (if fp
3508 (funcall form)
3509 (eval form)))))))
3511 (defvar org-agenda-markers nil
3512 "List of all currently active markers created by `org-agenda'.")
3513 (defvar org-agenda-last-marker-time (org-float-time)
3514 "Creation time of the last agenda marker.")
3516 (defun org-agenda-new-marker (&optional pos)
3517 "Return a new agenda marker.
3518 Org-mode keeps a list of these markers and resets them when they are
3519 no longer in use."
3520 (let ((m (copy-marker (or pos (point)))))
3521 (setq org-agenda-last-marker-time (org-float-time))
3522 (if org-agenda-buffer
3523 (with-current-buffer org-agenda-buffer
3524 (push m org-agenda-markers))
3525 (push m org-agenda-markers))
3528 (defun org-agenda-reset-markers ()
3529 "Reset markers created by `org-agenda'."
3530 (while org-agenda-markers
3531 (move-marker (pop org-agenda-markers) nil)))
3533 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3534 "Save relative positions of markers in region.
3535 This check for agenda markers in all agenda buffers currently active."
3536 (dolist (buf (buffer-list))
3537 (with-current-buffer buf
3538 (when (eq major-mode 'org-agenda-mode)
3539 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3540 org-agenda-markers)))))
3542 ;;; Entry text mode
3544 (defun org-agenda-entry-text-show-here ()
3545 "Add some text from the entry as context to the current line."
3546 (let (m txt o)
3547 (setq m (org-get-at-bol 'org-hd-marker))
3548 (unless (marker-buffer m)
3549 (error "No marker points to an entry here"))
3550 (setq txt (concat "\n" (org-no-properties
3551 (org-agenda-get-some-entry-text
3552 m org-agenda-entry-text-maxlines " > "))))
3553 (when (string-match "\\S-" txt)
3554 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3555 (overlay-put o 'evaporate t)
3556 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3557 (overlay-put o 'after-string txt))))
3559 (defun org-agenda-entry-text-show ()
3560 "Add entry context for all agenda lines."
3561 (interactive)
3562 (save-excursion
3563 (goto-char (point-max))
3564 (beginning-of-line 1)
3565 (while (not (bobp))
3566 (when (org-get-at-bol 'org-hd-marker)
3567 (org-agenda-entry-text-show-here))
3568 (beginning-of-line 0))))
3570 (defun org-agenda-entry-text-hide ()
3571 "Remove any shown entry context."
3572 (delq nil
3573 (mapcar (lambda (o)
3574 (if (eq (overlay-get o 'org-overlay-type)
3575 'agenda-entry-content)
3576 (progn (delete-overlay o) t)))
3577 (overlays-in (point-min) (point-max)))))
3579 (defun org-agenda-get-day-face (date)
3580 "Return the face DATE should be displayed with."
3581 (or (and (functionp org-agenda-day-face-function)
3582 (funcall org-agenda-day-face-function date))
3583 (cond ((org-agenda-todayp date)
3584 'org-agenda-date-today)
3585 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3586 'org-agenda-date-weekend)
3587 (t 'org-agenda-date))))
3589 ;;; Agenda timeline
3591 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3593 (defun org-timeline (&optional dotodo)
3594 "Show a time-sorted view of the entries in the current org file.
3595 Only entries with a time stamp of today or later will be listed. With
3596 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3597 under the current date.
3598 If the buffer contains an active region, only check the region for
3599 dates."
3600 (interactive "P")
3601 (let* ((dopast t)
3602 (org-agenda-show-log-scoped org-agenda-show-log)
3603 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3604 (current-buffer))))
3605 (date (calendar-current-date))
3606 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3607 (end (if (org-region-active-p) (region-end) (point-max)))
3608 (day-numbers (org-get-all-dates
3609 beg end 'no-ranges
3610 t org-agenda-show-log-scoped ; always include today
3611 org-timeline-show-empty-dates))
3612 (org-deadline-warning-days 0)
3613 (org-agenda-only-exact-dates t)
3614 (today (org-today))
3615 (past t)
3616 args
3617 s e rtn d emptyp)
3618 (setq org-agenda-redo-command
3619 (list 'progn
3620 (list 'org-switch-to-buffer-other-window (current-buffer))
3621 (list 'org-timeline (list 'quote dotodo))))
3622 (if (not dopast)
3623 ;; Remove past dates from the list of dates.
3624 (setq day-numbers (delq nil (mapcar (lambda(x)
3625 (if (>= x today) x nil))
3626 day-numbers))))
3627 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3628 (org-compile-prefix-format 'timeline)
3629 (org-set-sorting-strategy 'timeline)
3630 (if org-agenda-show-log-scoped (push :closed args))
3631 (push :timestamp args)
3632 (push :deadline args)
3633 (push :scheduled args)
3634 (push :sexp args)
3635 (if dotodo (push :todo args))
3636 (insert "Timeline of file " entry "\n")
3637 (add-text-properties (point-min) (point)
3638 (list 'face 'org-agenda-structure))
3639 (org-agenda-mark-header-line (point-min))
3640 (while (setq d (pop day-numbers))
3641 (if (and (listp d) (eq (car d) :omitted))
3642 (progn
3643 (setq s (point))
3644 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3645 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3646 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3647 (if (and (>= d today)
3648 dopast
3649 past)
3650 (progn
3651 (setq past nil)
3652 (insert (make-string 79 ?-) "\n")))
3653 (setq date (calendar-gregorian-from-absolute d))
3654 (setq s (point))
3655 (setq rtn (and (not emptyp)
3656 (apply 'org-agenda-get-day-entries entry
3657 date args)))
3658 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3659 (progn
3660 (insert
3661 (if (stringp org-agenda-format-date)
3662 (format-time-string org-agenda-format-date
3663 (org-time-from-absolute date))
3664 (funcall org-agenda-format-date date))
3665 "\n")
3666 (put-text-property s (1- (point)) 'face
3667 (org-agenda-get-day-face date))
3668 (put-text-property s (1- (point)) 'org-date-line t)
3669 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3670 (if (equal d today)
3671 (put-text-property s (1- (point)) 'org-today t))
3672 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3673 (put-text-property s (1- (point)) 'day d)))))
3674 (goto-char (point-min))
3675 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3676 (point-min)))
3677 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3678 (org-finalize-agenda)
3679 (setq buffer-read-only t)))
3681 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3682 "Return a list of all relevant day numbers from BEG to END buffer positions.
3683 If NO-RANGES is non-nil, include only the start and end dates of a range,
3684 not every single day in the range. If FORCE-TODAY is non-nil, make
3685 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3686 inactive time stamps (those in square brackets) are included.
3687 When EMPTY is non-nil, also include days without any entries."
3688 (let ((re (concat
3689 (if pre-re pre-re "")
3690 (if inactive org-ts-regexp-both org-ts-regexp)))
3691 dates dates1 date day day1 day2 ts1 ts2 pos)
3692 (if force-today
3693 (setq dates (list (org-today))))
3694 (save-excursion
3695 (goto-char beg)
3696 (while (re-search-forward re end t)
3697 (setq day (time-to-days (org-time-string-to-time
3698 (substring (match-string 1) 0 10)
3699 (current-buffer) (match-beginning 0))))
3700 (or (memq day dates) (push day dates)))
3701 (unless no-ranges
3702 (goto-char beg)
3703 (while (re-search-forward org-tr-regexp end t)
3704 (setq pos (match-beginning 0))
3705 (setq ts1 (substring (match-string 1) 0 10)
3706 ts2 (substring (match-string 2) 0 10)
3707 day1 (time-to-days (org-time-string-to-time
3708 ts1 (current-buffer) pos))
3709 day2 (time-to-days (org-time-string-to-time
3710 ts2 (current-buffer) pos)))
3711 (while (< (setq day1 (1+ day1)) day2)
3712 (or (memq day1 dates) (push day1 dates)))))
3713 (setq dates (sort dates '<))
3714 (when empty
3715 (while (setq day (pop dates))
3716 (setq day2 (car dates))
3717 (push day dates1)
3718 (when (and day2 empty)
3719 (if (or (eq empty t)
3720 (and (numberp empty) (<= (- day2 day) empty)))
3721 (while (< (setq day (1+ day)) day2)
3722 (push (list day) dates1))
3723 (push (cons :omitted (- day2 day)) dates1))))
3724 (setq dates (nreverse dates1)))
3725 dates)))
3727 ;;; Agenda Daily/Weekly
3729 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3730 "Start day for the agenda view.
3731 Custom commands can set this variable in the options section.")
3732 (defvar org-starting-day nil) ; local variable in the agenda buffer
3733 (defvar org-agenda-current-span nil
3734 "The current span used in the agenda view.") ; local variable in the agenda buffer
3735 (defvar org-arg-loc nil) ; local variable
3737 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3738 "List of types searched for when creating the daily/weekly agenda.
3739 This variable is a list of symbols that controls the types of
3740 items that appear in the daily/weekly agenda. Allowed symbols in this
3741 list are are
3743 :timestamp List items containing a date stamp or date range matching
3744 the selected date. This includes sexp entries in
3745 angular brackets.
3747 :sexp List entries resulting from plain diary-like sexps.
3749 :deadline List deadline due on that date. When the date is today,
3750 also list any deadlines past due, or due within
3751 `org-deadline-warning-days'. `:deadline' must appear before
3752 `:scheduled' if the setting of
3753 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3754 any effect.
3756 :scheduled List all items which are scheduled for the given date.
3757 The diary for *today* also contains items which were
3758 scheduled earlier and are not yet marked DONE.
3760 By default, all four types are turned on.
3762 Never set this variable globally using `setq', because then it
3763 will apply to all future agenda commands. Instead, bind it with
3764 `let' to scope it dynamically into the agenda-constructing
3765 command. A good way to set it is through options in
3766 `org-agenda-custom-commands'. For a more flexible (though
3767 somewhat less efficient) way of determining what is included in
3768 the daily/weekly agenda, see `org-agenda-skip-function'.")
3770 ;;;###autoload
3771 (defun org-agenda-list (&optional arg start-day span)
3772 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3773 The view will be for the current day or week, but from the overview buffer
3774 you will be able to go to other days/weeks.
3776 With a numeric prefix argument in an interactive call, the agenda will
3777 span ARG days. Lisp programs should instead specify SPAN to change
3778 the number of days. SPAN defaults to `org-agenda-span'.
3780 START-DAY defaults to TODAY, or to the most recent match for the weekday
3781 given in `org-agenda-start-on-weekday'."
3782 (interactive "P")
3783 (if (and (integerp arg) (> arg 0))
3784 (setq span arg arg nil))
3785 (org-prepare-agenda "Day/Week")
3786 (setq start-day (or start-day org-agenda-start-day))
3787 (if org-agenda-overriding-arguments
3788 (setq arg (car org-agenda-overriding-arguments)
3789 start-day (nth 1 org-agenda-overriding-arguments)
3790 span (nth 2 org-agenda-overriding-arguments)))
3791 (if (stringp start-day)
3792 ;; Convert to an absolute day number
3793 (setq start-day (time-to-days (org-read-date nil t start-day))))
3794 (setq org-agenda-last-arguments (list arg start-day span))
3795 (org-compile-prefix-format 'agenda)
3796 (org-set-sorting-strategy 'agenda)
3797 (let* ((span (org-agenda-ndays-to-span
3798 (or span org-agenda-ndays org-agenda-span)))
3799 (today (org-today))
3800 (sd (or start-day today))
3801 (ndays (org-agenda-span-to-ndays span sd))
3802 (org-agenda-start-on-weekday
3803 (if (eq ndays 7)
3804 org-agenda-start-on-weekday))
3805 (thefiles (org-agenda-files nil 'ifmode))
3806 (files thefiles)
3807 (start (if (or (null org-agenda-start-on-weekday)
3808 (< ndays 7))
3810 (let* ((nt (calendar-day-of-week
3811 (calendar-gregorian-from-absolute sd)))
3812 (n1 org-agenda-start-on-weekday)
3813 (d (- nt n1)))
3814 (- sd (+ (if (< d 0) 7 0) d)))))
3815 (day-numbers (list start))
3816 (day-cnt 0)
3817 (inhibit-redisplay (not debug-on-error))
3818 (org-agenda-show-log-scoped org-agenda-show-log)
3819 s e rtn rtnall file date d start-pos end-pos todayp
3820 clocktable-start clocktable-end filter)
3821 (setq org-agenda-redo-command
3822 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3823 (dotimes (n (1- ndays))
3824 (push (1+ (car day-numbers)) day-numbers))
3825 (setq day-numbers (nreverse day-numbers))
3826 (setq clocktable-start (car day-numbers)
3827 clocktable-end (1+ (or (org-last day-numbers) 0)))
3828 (org-set-local 'org-starting-day (car day-numbers))
3829 (org-set-local 'org-arg-loc arg)
3830 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3831 (unless org-agenda-compact-blocks
3832 (let* ((d1 (car day-numbers))
3833 (d2 (org-last day-numbers))
3834 (w1 (org-days-to-iso-week d1))
3835 (w2 (org-days-to-iso-week d2)))
3836 (setq s (point))
3837 (if org-agenda-overriding-header
3838 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3839 nil 'face 'org-agenda-structure) "\n")
3840 (insert (org-agenda-span-name span)
3841 "-agenda"
3842 (if (< (- d2 d1) 350)
3843 (if (= w1 w2)
3844 (format " (W%02d)" w1)
3845 (format " (W%02d-W%02d)" w1 w2))
3847 ":\n")))
3848 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3849 'org-date-line t))
3850 (org-agenda-mark-header-line s))
3851 (while (setq d (pop day-numbers))
3852 (setq date (calendar-gregorian-from-absolute d)
3853 s (point))
3854 (if (or (setq todayp (= d today))
3855 (and (not start-pos) (= d sd)))
3856 (setq start-pos (point))
3857 (if (and start-pos (not end-pos))
3858 (setq end-pos (point))))
3859 (setq files thefiles
3860 rtnall nil)
3861 (while (setq file (pop files))
3862 (catch 'nextfile
3863 (org-check-agenda-file file)
3864 (let ((org-agenda-entry-types org-agenda-entry-types))
3865 (unless org-agenda-include-deadlines
3866 (setq org-agenda-entry-types
3867 (delq :deadline org-agenda-entry-types)))
3868 (cond
3869 ((memq org-agenda-show-log-scoped '(only clockcheck))
3870 (setq rtn (org-agenda-get-day-entries
3871 file date :closed)))
3872 (org-agenda-show-log-scoped
3873 (setq rtn (apply 'org-agenda-get-day-entries
3874 file date
3875 (append '(:closed) org-agenda-entry-types))))
3877 (setq rtn (apply 'org-agenda-get-day-entries
3878 file date
3879 org-agenda-entry-types)))))
3880 (setq rtnall (append rtnall rtn)))) ;; all entries
3881 (if org-agenda-include-diary
3882 (let ((org-agenda-search-headline-for-time t))
3883 (require 'diary-lib)
3884 (setq rtn (org-get-entries-from-diary date))
3885 (setq rtnall (append rtnall rtn))))
3886 (if (or rtnall org-agenda-show-all-dates)
3887 (progn
3888 (setq day-cnt (1+ day-cnt))
3889 (insert
3890 (if (stringp org-agenda-format-date)
3891 (format-time-string org-agenda-format-date
3892 (org-time-from-absolute date))
3893 (funcall org-agenda-format-date date))
3894 "\n")
3895 (put-text-property s (1- (point)) 'face
3896 (org-agenda-get-day-face date))
3897 (put-text-property s (1- (point)) 'org-date-line t)
3898 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3899 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3900 (when todayp
3901 (put-text-property s (1- (point)) 'org-today t))
3902 (setq rtnall
3903 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3904 (if rtnall (insert ;; all entries
3905 (org-finalize-agenda-entries rtnall)
3906 "\n"))
3907 (put-text-property s (1- (point)) 'day d)
3908 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3909 (when (and org-agenda-clockreport-mode clocktable-start)
3910 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3911 ;; the above line is to ensure the restricted range!
3912 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3913 tbl)
3914 (setq p (org-plist-delete p :block))
3915 (setq p (plist-put p :tstart clocktable-start))
3916 (setq p (plist-put p :tend clocktable-end))
3917 (setq p (plist-put p :scope 'agenda))
3918 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3919 (setq filter (or org-agenda-tag-filter-while-redo
3920 (get 'org-agenda-tag-filter :preset-filter))))
3921 (setq p (plist-put p :tags (mapconcat (lambda (x)
3922 (if (string-match "[<>=]" x)
3925 filter ""))))
3926 (setq tbl (apply 'org-get-clocktable p))
3927 (insert tbl)))
3928 (goto-char (point-min))
3929 (or org-agenda-multi (org-fit-agenda-window))
3930 (unless (and (pos-visible-in-window-p (point-min))
3931 (pos-visible-in-window-p (point-max)))
3932 (goto-char (1- (point-max)))
3933 (recenter -1)
3934 (if (not (pos-visible-in-window-p (or start-pos 1)))
3935 (progn
3936 (goto-char (or start-pos 1))
3937 (recenter 1))))
3938 (goto-char (or start-pos 1))
3939 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3940 (if (eq org-agenda-show-log-scoped 'clockcheck)
3941 (org-agenda-show-clocking-issues))
3942 (org-finalize-agenda)
3943 (setq buffer-read-only t)
3944 (message "")))
3946 (defun org-agenda-ndays-to-span (n)
3947 "Return a span symbol for a span of N days, or N if none matches."
3948 (cond ((symbolp n) n)
3949 ((= n 1) 'day)
3950 ((= n 7) 'week)
3951 (t n)))
3953 (defun org-agenda-span-to-ndays (span start-day)
3954 "Return ndays from SPAN starting at START-DAY."
3955 (cond ((numberp span) span)
3956 ((eq span 'day) 1)
3957 ((eq span 'week) 7)
3958 ((eq span 'month)
3959 (let ((date (calendar-gregorian-from-absolute start-day)))
3960 (calendar-last-day-of-month (car date) (caddr date))))
3961 ((eq span 'year)
3962 (let ((date (calendar-gregorian-from-absolute start-day)))
3963 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3965 (defun org-agenda-span-name (span)
3966 "Return a SPAN name."
3967 (if (null span)
3969 (if (symbolp span)
3970 (capitalize (symbol-name span))
3971 (format "%d days" span))))
3973 ;;; Agenda word search
3975 (defvar org-agenda-search-history nil)
3976 (defvar org-todo-only nil)
3978 (defvar org-search-syntax-table nil
3979 "Special syntax table for org-mode search.
3980 In this table, we have single quotes not as word constituents, to
3981 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3983 (defvar org-mode-syntax-table) ; From org.el
3984 (defun org-search-syntax-table ()
3985 (unless org-search-syntax-table
3986 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3987 (modify-syntax-entry ?' "." org-search-syntax-table)
3988 (modify-syntax-entry ?` "." org-search-syntax-table))
3989 org-search-syntax-table)
3991 (defvar org-agenda-last-search-view-search-was-boolean nil)
3993 ;;;###autoload
3994 (defun org-search-view (&optional todo-only string edit-at)
3995 "Show all entries that contain a phrase or words or regular expressions.
3997 With optional prefix argument TODO-ONLY, only consider entries that are
3998 TODO entries. The argument STRING can be used to pass a default search
3999 string into this function. If EDIT-AT is non-nil, it means that the
4000 user should get a chance to edit this string, with cursor at position
4001 EDIT-AT.
4003 The search string can be viewed either as a phrase that should be found as
4004 is, or it can be broken into a number of snippets, each of which must match
4005 in a Boolean way to select an entry. The default depends on the variable
4006 `org-agenda-search-view-always-boolean'.
4007 Even if this is turned off (the default) you can always switch to
4008 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4010 The default is a direct search of the whole phrase, where each space in
4011 the search string can expand to an arbitrary amount of whitespace,
4012 including newlines.
4014 If using a Boolean search, the search string is split on whitespace and
4015 each snippet is searched separately, with logical AND to select an entry.
4016 Words prefixed with a minus must *not* occur in the entry. Words without
4017 a prefix or prefixed with a plus must occur in the entry. Matching is
4018 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4019 match whole words, not parts of a word) if
4020 `org-agenda-search-view-force-full-words' is set (default is nil).
4022 Boolean search snippets enclosed by curly braces are interpreted as
4023 regular expressions that must or (when preceded with \"-\") must not
4024 match in the entry. Snippets enclosed into double quotes will be taken
4025 as a whole, to include whitespace.
4027 - If the search string starts with an asterisk, search only in headlines.
4028 - If (possibly after the leading star) the search string starts with an
4029 exclamation mark, this also means to look at TODO entries only, an effect
4030 that can also be achieved with a prefix argument.
4031 - If (possibly after star and exclamation mark) the search string starts
4032 with a colon, this will mean that the (non-regexp) snippets of the
4033 Boolean search must match as full words.
4035 This command searches the agenda files, and in addition the files listed
4036 in `org-agenda-text-search-extra-files'."
4037 (interactive "P")
4038 (org-prepare-agenda "SEARCH")
4039 (org-compile-prefix-format 'search)
4040 (org-set-sorting-strategy 'search)
4041 (let* ((props (list 'face nil
4042 'done-face 'org-agenda-done
4043 'org-not-done-regexp org-not-done-regexp
4044 'org-todo-regexp org-todo-regexp
4045 'org-complex-heading-regexp org-complex-heading-regexp
4046 'mouse-face 'highlight
4047 'help-echo (format "mouse-2 or RET jump to location")))
4048 (full-words org-agenda-search-view-force-full-words)
4049 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4050 regexp rtn rtnall files file pos
4051 marker category org-category-pos tags c neg re boolean
4052 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4053 (unless (and (not edit-at)
4054 (stringp string)
4055 (string-match "\\S-" string))
4056 (setq string (read-string
4057 (if org-agenda-search-view-always-boolean
4058 "[+-]Word/{Regexp} ...: "
4059 "Phrase, or [+-]Word/{Regexp} ...: ")
4060 (cond
4061 ((integerp edit-at) (cons string edit-at))
4062 (edit-at string))
4063 'org-agenda-search-history)))
4064 (org-set-local 'org-todo-only todo-only)
4065 (setq org-agenda-redo-command
4066 (list 'org-search-view (if todo-only t nil) string
4067 '(if current-prefix-arg 1 nil)))
4068 (setq org-agenda-query-string string)
4070 (if (equal (string-to-char string) ?*)
4071 (setq hdl-only t
4072 words (substring string 1))
4073 (setq words string))
4074 (when (equal (string-to-char words) ?!)
4075 (setq todo-only t
4076 words (substring words 1)))
4077 (when (equal (string-to-char words) ?:)
4078 (setq full-words t
4079 words (substring words 1)))
4080 (if (or org-agenda-search-view-always-boolean
4081 (member (string-to-char words) '(?- ?+ ?\{)))
4082 (setq boolean t))
4083 (setq words (org-split-string words))
4084 (let (www w)
4085 (while (setq w (pop words))
4086 (while (and (string-match "\\\\\\'" w) words)
4087 (setq w (concat (substring w 0 -1) " " (pop words))))
4088 (push w www))
4089 (setq words (nreverse www) www nil)
4090 (while (setq w (pop words))
4091 (when (and (string-match "\\`[-+]?{" w)
4092 (not (string-match "}\\'" w)))
4093 (while (and words (not (string-match "}\\'" (car words))))
4094 (setq w (concat w " " (pop words))))
4095 (setq w (concat w " " (pop words))))
4096 (push w www))
4097 (setq words (nreverse www)))
4098 (setq org-agenda-last-search-view-search-was-boolean boolean)
4099 (when boolean
4100 (let (wds w)
4101 (while (setq w (pop words))
4102 (if (or (equal (substring w 0 1) "\"")
4103 (and (> (length w) 1)
4104 (member (substring w 0 1) '("+" "-"))
4105 (equal (substring w 1 2) "\"")))
4106 (while (and words (not (equal (substring w -1) "\"")))
4107 (setq w (concat w " " (pop words)))))
4108 (and (string-match "\\`\\([-+]?\\)\"" w)
4109 (setq w (replace-match "\\1" nil nil w)))
4110 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4111 (push w wds))
4112 (setq words (nreverse wds))))
4113 (if boolean
4114 (mapc (lambda (w)
4115 (setq c (string-to-char w))
4116 (if (equal c ?-)
4117 (setq neg t w (substring w 1))
4118 (if (equal c ?+)
4119 (setq neg nil w (substring w 1))
4120 (setq neg nil)))
4121 (if (string-match "\\`{.*}\\'" w)
4122 (setq re (substring w 1 -1))
4123 (if full-words
4124 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4125 (setq re (regexp-quote (downcase w)))))
4126 (if neg (push re regexps-) (push re regexps+)))
4127 words)
4128 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4129 regexps+))
4130 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4131 (if (not regexps+)
4132 (setq regexp org-outline-regexp-bol)
4133 (setq regexp (pop regexps+))
4134 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4135 regexp))))
4136 (setq files (org-agenda-files nil 'ifmode))
4137 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4138 (pop org-agenda-text-search-extra-files)
4139 (setq files (org-add-archive-files files)))
4140 (setq files (append files org-agenda-text-search-extra-files)
4141 rtnall nil)
4142 (while (setq file (pop files))
4143 (setq ee nil)
4144 (catch 'nextfile
4145 (org-check-agenda-file file)
4146 (setq buffer (if (file-exists-p file)
4147 (org-get-agenda-file-buffer file)
4148 (error "No such file %s" file)))
4149 (if (not buffer)
4150 ;; If file does not exist, make sure an error message is sent
4151 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4152 file))))
4153 (with-current-buffer buffer
4154 (with-syntax-table (org-search-syntax-table)
4155 (unless (derived-mode-p 'org-mode)
4156 (error "Agenda file %s is not in `org-mode'" file))
4157 (let ((case-fold-search t))
4158 (save-excursion
4159 (save-restriction
4160 (if org-agenda-restrict
4161 (narrow-to-region org-agenda-restrict-begin
4162 org-agenda-restrict-end)
4163 (widen))
4164 (goto-char (point-min))
4165 (unless (or (org-at-heading-p)
4166 (outline-next-heading))
4167 (throw 'nextfile t))
4168 (goto-char (max (point-min) (1- (point))))
4169 (while (re-search-forward regexp nil t)
4170 (org-back-to-heading t)
4171 (skip-chars-forward "* ")
4172 (setq beg (point-at-bol)
4173 beg1 (point)
4174 end (progn (outline-next-heading) (point)))
4175 (catch :skip
4176 (goto-char beg)
4177 (org-agenda-skip)
4178 (setq str (buffer-substring-no-properties
4179 (point-at-bol)
4180 (if hdl-only (point-at-eol) end)))
4181 (mapc (lambda (wr) (when (string-match wr str)
4182 (goto-char (1- end))
4183 (throw :skip t)))
4184 regexps-)
4185 (mapc (lambda (wr) (unless (string-match wr str)
4186 (goto-char (1- end))
4187 (throw :skip t)))
4188 (if todo-only
4189 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4190 regexps+)
4191 regexps+))
4192 (goto-char beg)
4193 (setq marker (org-agenda-new-marker (point))
4194 category (org-get-category)
4195 org-category-pos (get-text-property (point) 'org-category-position)
4196 tags (org-get-tags-at (point))
4197 txt (org-agenda-format-item
4199 (buffer-substring-no-properties
4200 beg1 (point-at-eol))
4201 category tags))
4202 (org-add-props txt props
4203 'org-marker marker 'org-hd-marker marker
4204 'org-todo-regexp org-todo-regexp
4205 'org-complex-heading-regexp org-complex-heading-regexp
4206 'priority 1000 'org-category category
4207 'org-category-position org-category-pos
4208 'type "search")
4209 (push txt ee)
4210 (goto-char (1- end))))))))))
4211 (setq rtn (nreverse ee))
4212 (setq rtnall (append rtnall rtn)))
4213 (if org-agenda-overriding-header
4214 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4215 nil 'face 'org-agenda-structure) "\n")
4216 (insert "Search words: ")
4217 (add-text-properties (point-min) (1- (point))
4218 (list 'face 'org-agenda-structure))
4219 (setq pos (point))
4220 (insert string "\n")
4221 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4222 (setq pos (point))
4223 (unless org-agenda-multi
4224 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4225 (add-text-properties pos (1- (point))
4226 (list 'face 'org-agenda-structure))))
4227 (org-agenda-mark-header-line (point-min))
4228 (when rtnall
4229 (insert (org-finalize-agenda-entries rtnall) "\n"))
4230 (goto-char (point-min))
4231 (or org-agenda-multi (org-fit-agenda-window))
4232 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4233 (org-finalize-agenda)
4234 (setq buffer-read-only t)))
4236 ;;; Agenda TODO list
4238 (defvar org-select-this-todo-keyword nil)
4239 (defvar org-last-arg nil)
4241 ;;;###autoload
4242 (defun org-todo-list (arg)
4243 "Show all (not done) TODO entries from all agenda file in a single list.
4244 The prefix arg can be used to select a specific TODO keyword and limit
4245 the list to these. When using \\[universal-argument], you will be prompted
4246 for a keyword. A numeric prefix directly selects the Nth keyword in
4247 `org-todo-keywords-1'."
4248 (interactive "P")
4249 (org-prepare-agenda "TODO")
4250 (org-compile-prefix-format 'todo)
4251 (org-set-sorting-strategy 'todo)
4252 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4253 (let* ((today (org-today))
4254 (date (calendar-gregorian-from-absolute today))
4255 (kwds org-todo-keywords-for-agenda)
4256 (completion-ignore-case t)
4257 (org-select-this-todo-keyword
4258 (if (stringp arg) arg
4259 (and arg (integerp arg) (> arg 0)
4260 (nth (1- arg) kwds))))
4261 rtn rtnall files file pos)
4262 (when (equal arg '(4))
4263 (setq org-select-this-todo-keyword
4264 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4265 (mapcar 'list kwds) nil nil)))
4266 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4267 (org-set-local 'org-last-arg arg)
4268 (setq org-agenda-redo-command
4269 '(org-todo-list (or current-prefix-arg org-last-arg)))
4270 (setq files (org-agenda-files nil 'ifmode)
4271 rtnall nil)
4272 (while (setq file (pop files))
4273 (catch 'nextfile
4274 (org-check-agenda-file file)
4275 (setq rtn (org-agenda-get-day-entries file date :todo))
4276 (setq rtnall (append rtnall rtn))))
4277 (if org-agenda-overriding-header
4278 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4279 nil 'face 'org-agenda-structure) "\n")
4280 (insert "Global list of TODO items of type: ")
4281 (add-text-properties (point-min) (1- (point))
4282 (list 'face 'org-agenda-structure
4283 'short-heading
4284 (concat "ToDo: "
4285 (or org-select-this-todo-keyword "ALL"))))
4286 (org-agenda-mark-header-line (point-min))
4287 (setq pos (point))
4288 (insert (or org-select-this-todo-keyword "ALL") "\n")
4289 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4290 (setq pos (point))
4291 (unless org-agenda-multi
4292 (insert "Available with `N r': (0)ALL")
4293 (let ((n 0) s)
4294 (mapc (lambda (x)
4295 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4296 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4297 (insert "\n "))
4298 (insert " " s))
4299 kwds))
4300 (insert "\n"))
4301 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4302 (org-agenda-mark-header-line (point-min))
4303 (when rtnall
4304 (insert (org-finalize-agenda-entries rtnall) "\n"))
4305 (goto-char (point-min))
4306 (or org-agenda-multi (org-fit-agenda-window))
4307 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4308 (org-finalize-agenda)
4309 (setq buffer-read-only t)))
4311 ;;; Agenda tags match
4313 ;;;###autoload
4314 (defun org-tags-view (&optional todo-only match)
4315 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4316 The prefix arg TODO-ONLY limits the search to TODO entries."
4317 (interactive "P")
4318 (let* ((org-tags-match-list-sublevels
4319 org-tags-match-list-sublevels)
4320 (completion-ignore-case t)
4321 rtn rtnall files file pos matcher
4322 buffer)
4323 (when (and (stringp match) (not (string-match "\\S-" match)))
4324 (setq match nil))
4325 (setq matcher (org-make-tags-matcher match)
4326 match (car matcher) matcher (cdr matcher))
4327 (org-prepare-agenda (concat "TAGS " match))
4328 (org-compile-prefix-format 'tags)
4329 (org-set-sorting-strategy 'tags)
4330 (setq org-agenda-query-string match)
4331 (setq org-agenda-redo-command
4332 (list 'org-tags-view (list 'quote todo-only)
4333 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4334 (setq files (org-agenda-files nil 'ifmode)
4335 rtnall nil)
4336 (while (setq file (pop files))
4337 (catch 'nextfile
4338 (org-check-agenda-file file)
4339 (setq buffer (if (file-exists-p file)
4340 (org-get-agenda-file-buffer file)
4341 (error "No such file %s" file)))
4342 (if (not buffer)
4343 ;; If file does not exist, error message to agenda
4344 (setq rtn (list
4345 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4346 rtnall (append rtnall rtn))
4347 (with-current-buffer buffer
4348 (unless (derived-mode-p 'org-mode)
4349 (error "Agenda file %s is not in `org-mode'" file))
4350 (save-excursion
4351 (save-restriction
4352 (if org-agenda-restrict
4353 (narrow-to-region org-agenda-restrict-begin
4354 org-agenda-restrict-end)
4355 (widen))
4356 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4357 (setq rtnall (append rtnall rtn))))))))
4358 (if org-agenda-overriding-header
4359 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4360 nil 'face 'org-agenda-structure) "\n")
4361 (insert "Headlines with TAGS match: ")
4362 (add-text-properties (point-min) (1- (point))
4363 (list 'face 'org-agenda-structure
4364 'short-heading
4365 (concat "Match: " match)))
4366 (setq pos (point))
4367 (insert match "\n")
4368 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4369 (setq pos (point))
4370 (unless org-agenda-multi
4371 (insert "Press `C-u r' to search again with new search string\n"))
4372 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4373 (org-agenda-mark-header-line (point-min))
4374 (when rtnall
4375 (insert (org-finalize-agenda-entries rtnall) "\n"))
4376 (goto-char (point-min))
4377 (or org-agenda-multi (org-fit-agenda-window))
4378 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4379 (org-finalize-agenda)
4380 (setq buffer-read-only t)))
4382 ;;; Agenda Finding stuck projects
4384 (defvar org-agenda-skip-regexp nil
4385 "Regular expression used in skipping subtrees for the agenda.
4386 This is basically a temporary global variable that can be set and then
4387 used by user-defined selections using `org-agenda-skip-function'.")
4389 (defvar org-agenda-overriding-header nil
4390 "When set during agenda, todo and tags searches it replaces the header.
4391 This variable should not be set directly, but custom commands can bind it
4392 in the options section.")
4394 (defun org-agenda-skip-entry-when-regexp-matches ()
4395 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4396 If yes, it returns the end position of this entry, causing agenda commands
4397 to skip the entry but continuing the search in the subtree. This is a
4398 function that can be put into `org-agenda-skip-function' for the duration
4399 of a command."
4400 (let ((end (save-excursion (org-end-of-subtree t)))
4401 skip)
4402 (save-excursion
4403 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4404 (and skip end)))
4406 (defun org-agenda-skip-subtree-when-regexp-matches ()
4407 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4408 If yes, it returns the end position of this tree, causing agenda commands
4409 to skip this subtree. This is a function that can be put into
4410 `org-agenda-skip-function' for the duration of a command."
4411 (let ((end (save-excursion (org-end-of-subtree t)))
4412 skip)
4413 (save-excursion
4414 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4415 (and skip end)))
4417 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4418 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4419 If yes, it returns the end position of the current entry (NOT the tree),
4420 causing agenda commands to skip the entry but continuing the search in
4421 the subtree. This is a function that can be put into
4422 `org-agenda-skip-function' for the duration of a command. An important
4423 use of this function is for the stuck project list."
4424 (let ((end (save-excursion (org-end-of-subtree t)))
4425 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4426 skip)
4427 (save-excursion
4428 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4429 (and skip entry-end)))
4431 (defun org-agenda-skip-entry-if (&rest conditions)
4432 "Skip entry if any of CONDITIONS is true.
4433 See `org-agenda-skip-if' for details."
4434 (org-agenda-skip-if nil conditions))
4436 (defun org-agenda-skip-subtree-if (&rest conditions)
4437 "Skip entry if any of CONDITIONS is true.
4438 See `org-agenda-skip-if' for details."
4439 (org-agenda-skip-if t conditions))
4441 (defun org-agenda-skip-if (subtree conditions)
4442 "Checks current entity for CONDITIONS.
4443 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4444 the entry (i.e. the text before the next heading) is checked.
4446 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4447 from different tests. Valid conditions are:
4449 scheduled Check if there is a scheduled cookie
4450 notscheduled Check if there is no scheduled cookie
4451 deadline Check if there is a deadline
4452 notdeadline Check if there is no deadline
4453 timestamp Check if there is a timestamp (also deadline or scheduled)
4454 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4455 regexp Check if regexp matches
4456 notregexp Check if regexp does not match.
4457 todo Check if TODO keyword matches
4458 nottodo Check if TODO keyword does not match
4460 The regexp is taken from the conditions list, it must come right after
4461 the `regexp' or `notregexp' element.
4463 `todo' and `nottodo' accept as an argument a list of todo
4464 keywords, which may include \"*\" to match any todo keyword.
4466 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4468 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4470 Instead of a list, a keyword class may be given. For example:
4472 (org-agenda-skip-entry-if 'nottodo 'done)
4474 would skip entries that haven't been marked with any of \"DONE\"
4475 keywords. Possible classes are: `todo', `done', `any'.
4477 If any of these conditions is met, this function returns the end point of
4478 the entity, causing the search to continue from there. This is a function
4479 that can be put into `org-agenda-skip-function' for the duration of a command."
4480 (let (beg end m)
4481 (org-back-to-heading t)
4482 (setq beg (point)
4483 end (if subtree
4484 (progn (org-end-of-subtree t) (point))
4485 (progn (outline-next-heading) (1- (point)))))
4486 (goto-char beg)
4487 (and
4489 (and (memq 'scheduled conditions)
4490 (re-search-forward org-scheduled-time-regexp end t))
4491 (and (memq 'notscheduled conditions)
4492 (not (re-search-forward org-scheduled-time-regexp end t)))
4493 (and (memq 'deadline conditions)
4494 (re-search-forward org-deadline-time-regexp end t))
4495 (and (memq 'notdeadline conditions)
4496 (not (re-search-forward org-deadline-time-regexp end t)))
4497 (and (memq 'timestamp conditions)
4498 (re-search-forward org-ts-regexp end t))
4499 (and (memq 'nottimestamp conditions)
4500 (not (re-search-forward org-ts-regexp end t)))
4501 (and (setq m (memq 'regexp conditions))
4502 (stringp (nth 1 m))
4503 (re-search-forward (nth 1 m) end t))
4504 (and (setq m (memq 'notregexp conditions))
4505 (stringp (nth 1 m))
4506 (not (re-search-forward (nth 1 m) end t)))
4507 (and (or
4508 (setq m (memq 'nottodo conditions))
4509 (setq m (memq 'todo-unblocked conditions))
4510 (setq m (memq 'nottodo-unblocked conditions))
4511 (setq m (memq 'todo conditions)))
4512 (org-agenda-skip-if-todo m end)))
4513 end)))
4515 (defun org-agenda-skip-if-todo (args end)
4516 "Helper function for `org-agenda-skip-if', do not use it directly.
4517 ARGS is a list with first element either `todo', `nottodo',
4518 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4519 a list of TODO keywords, or a state symbol `todo' or `done' or
4520 `any'."
4521 (let ((kw (car args))
4522 (arg (cadr args))
4523 todo-wds todo-re)
4524 (setq todo-wds
4525 (org-uniquify
4526 (cond
4527 ((listp arg) ;; list of keywords
4528 (if (member "*" arg)
4529 (mapcar 'substring-no-properties org-todo-keywords-1)
4530 arg))
4531 ((symbolp arg) ;; keyword class name
4532 (cond
4533 ((eq arg 'todo)
4534 (org-delete-all org-done-keywords
4535 (mapcar 'substring-no-properties
4536 org-todo-keywords-1)))
4537 ((eq arg 'done) org-done-keywords)
4538 ((eq arg 'any)
4539 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4540 (setq todo-re
4541 (concat "^\\*+[ \t]+\\<\\("
4542 (mapconcat 'identity todo-wds "\\|")
4543 "\\)\\>"))
4544 (cond
4545 ((eq kw 'todo) (re-search-forward todo-re end t))
4546 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4547 ((eq kw 'todo-unblocked)
4548 (catch 'unblocked
4549 (while (re-search-forward todo-re end t)
4550 (or (org-entry-blocked-p) (throw 'unblocked t)))
4551 nil))
4552 ((eq kw 'nottodo-unblocked)
4553 (catch 'unblocked
4554 (while (re-search-forward todo-re end t)
4555 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4559 ;;;###autoload
4560 (defun org-agenda-list-stuck-projects (&rest ignore)
4561 "Create agenda view for projects that are stuck.
4562 Stuck projects are project that have no next actions. For the definitions
4563 of what a project is and how to check if it stuck, customize the variable
4564 `org-stuck-projects'."
4565 (interactive)
4566 (let* ((org-agenda-skip-function
4567 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4568 ;; We could have used org-agenda-skip-if here.
4569 (org-agenda-overriding-header
4570 (or org-agenda-overriding-header "List of stuck projects: "))
4571 (matcher (nth 0 org-stuck-projects))
4572 (todo (nth 1 org-stuck-projects))
4573 (todo-wds (if (member "*" todo)
4574 (progn
4575 (org-prepare-agenda-buffers (org-agenda-files
4576 nil 'ifmode))
4577 (org-delete-all
4578 org-done-keywords-for-agenda
4579 (copy-sequence org-todo-keywords-for-agenda)))
4580 todo))
4581 (todo-re (concat "^\\*+[ \t]+\\("
4582 (mapconcat 'identity todo-wds "\\|")
4583 "\\)\\>"))
4584 (tags (nth 2 org-stuck-projects))
4585 (tags-re (if (member "*" tags)
4586 (concat org-outline-regexp-bol
4587 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4588 (if tags
4589 (concat org-outline-regexp-bol
4590 ".*:\\("
4591 (mapconcat 'identity tags "\\|")
4592 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4593 (gen-re (nth 3 org-stuck-projects))
4594 (re-list
4595 (delq nil
4596 (list
4597 (if todo todo-re)
4598 (if tags tags-re)
4599 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4600 gen-re)))))
4601 (setq org-agenda-skip-regexp
4602 (if re-list
4603 (mapconcat 'identity re-list "\\|")
4604 (error "No information how to identify unstuck projects")))
4605 (org-tags-view nil matcher)
4606 (with-current-buffer org-agenda-buffer-name
4607 (setq org-agenda-redo-command
4608 '(org-agenda-list-stuck-projects
4609 (or current-prefix-arg org-last-arg))))))
4611 ;;; Diary integration
4613 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4614 (defvar diary-list-entries-hook)
4615 (defvar diary-time-regexp)
4616 (defun org-get-entries-from-diary (date)
4617 "Get the (Emacs Calendar) diary entries for DATE."
4618 (require 'diary-lib)
4619 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4620 (diary-display-hook '(fancy-diary-display))
4621 (diary-display-function 'fancy-diary-display)
4622 (pop-up-frames nil)
4623 (diary-list-entries-hook
4624 (cons 'org-diary-default-entry diary-list-entries-hook))
4625 (diary-file-name-prefix-function nil) ; turn this feature off
4626 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4627 entries
4628 (org-disable-agenda-to-diary t))
4629 (save-excursion
4630 (save-window-excursion
4631 (funcall (if (fboundp 'diary-list-entries)
4632 'diary-list-entries 'list-diary-entries)
4633 date 1)))
4634 (if (not (get-buffer diary-fancy-buffer))
4635 (setq entries nil)
4636 (with-current-buffer diary-fancy-buffer
4637 (setq buffer-read-only nil)
4638 (if (zerop (buffer-size))
4639 ;; No entries
4640 (setq entries nil)
4641 ;; Omit the date and other unnecessary stuff
4642 (org-agenda-cleanup-fancy-diary)
4643 ;; Add prefix to each line and extend the text properties
4644 (if (zerop (buffer-size))
4645 (setq entries nil)
4646 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4647 (setq entries
4648 (with-temp-buffer
4649 (insert entries) (goto-char (point-min))
4650 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4651 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4652 (replace-match (concat "; " (match-string 1)))))
4653 (buffer-string)))))
4654 (set-buffer-modified-p nil)
4655 (kill-buffer diary-fancy-buffer)))
4656 (when entries
4657 (setq entries (org-split-string entries "\n"))
4658 (setq entries
4659 (mapcar
4660 (lambda (x)
4661 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4662 ;; Extend the text properties to the beginning of the line
4663 (org-add-props x (text-properties-at (1- (length x)) x)
4664 'type "diary" 'date date 'face 'org-agenda-diary))
4665 entries)))))
4667 (defvar org-agenda-cleanup-fancy-diary-hook nil
4668 "Hook run when the fancy diary buffer is cleaned up.")
4670 (defun org-agenda-cleanup-fancy-diary ()
4671 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4672 This gets rid of the date, the underline under the date, and
4673 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4674 date. It also removes lines that contain only whitespace."
4675 (goto-char (point-min))
4676 (if (looking-at ".*?:[ \t]*")
4677 (progn
4678 (replace-match "")
4679 (re-search-forward "\n=+$" nil t)
4680 (replace-match "")
4681 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4682 (re-search-forward "\n=+$" nil t)
4683 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4684 (goto-char (point-min))
4685 (while (re-search-forward "^ +\n" nil t)
4686 (replace-match ""))
4687 (goto-char (point-min))
4688 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4689 (replace-match ""))
4690 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4692 ;; Make sure entries from the diary have the right text properties.
4693 (eval-after-load "diary-lib"
4694 '(if (boundp 'diary-modify-entry-list-string-function)
4695 ;; We can rely on the hook, nothing to do
4697 ;; Hook not available, must use advice to make this work
4698 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4699 "Make the position visible."
4700 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4701 (stringp string)
4702 buffer-file-name)
4703 (setq string (org-modify-diary-entry-string string))))))
4705 (defun org-modify-diary-entry-string (string)
4706 "Add text properties to string, allowing org-mode to act on it."
4707 (org-add-props string nil
4708 'mouse-face 'highlight
4709 'help-echo (if buffer-file-name
4710 (format "mouse-2 or RET jump to diary file %s"
4711 (abbreviate-file-name buffer-file-name))
4713 'org-agenda-diary-link t
4714 'org-marker (org-agenda-new-marker (point-at-bol))))
4716 (defun org-diary-default-entry ()
4717 "Add a dummy entry to the diary.
4718 Needed to avoid empty dates which mess up holiday display."
4719 ;; Catch the error if dealing with the new add-to-diary-alist
4720 (when org-disable-agenda-to-diary
4721 (condition-case nil
4722 (org-add-to-diary-list original-date "Org-mode dummy" "")
4723 (error
4724 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4726 (defun org-add-to-diary-list (&rest args)
4727 (if (fboundp 'diary-add-to-list)
4728 (apply 'diary-add-to-list args)
4729 (apply 'add-to-diary-list args)))
4731 (defvar org-diary-last-run-time nil)
4733 ;;;###autoload
4734 (defun org-diary (&rest args)
4735 "Return diary information from org-files.
4736 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4737 It accesses org files and extracts information from those files to be
4738 listed in the diary. The function accepts arguments specifying what
4739 items should be listed. For a list of arguments allowed here, see the
4740 variable `org-agenda-entry-types'.
4742 The call in the diary file should look like this:
4744 &%%(org-diary) ~/path/to/some/orgfile.org
4746 Use a separate line for each org file to check. Or, if you omit the file name,
4747 all files listed in `org-agenda-files' will be checked automatically:
4749 &%%(org-diary)
4751 If you don't give any arguments (as in the example above), the default
4752 arguments (:deadline :scheduled :timestamp :sexp) are used.
4753 So the example above may also be written as
4755 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4757 The function expects the lisp variables `entry' and `date' to be provided
4758 by the caller, because this is how the calendar works. Don't use this
4759 function from a program - use `org-agenda-get-day-entries' instead."
4760 (when (> (- (org-float-time)
4761 org-agenda-last-marker-time)
4763 ;; I am not sure if this works with sticky agendas, because the marker
4764 ;; list is then no longer a global variable.
4765 (org-agenda-reset-markers))
4766 ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
4767 (when (buffer-live-p org-agenda-buffer)
4768 (org-compile-prefix-format 'agenda))
4769 (org-set-sorting-strategy 'agenda)
4770 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4771 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4772 (list entry)
4773 (org-agenda-files t)))
4774 (time (org-float-time))
4775 file rtn results)
4776 (when (or (not org-diary-last-run-time)
4777 (> (- time
4778 org-diary-last-run-time)
4780 (org-prepare-agenda-buffers files))
4781 (setq org-diary-last-run-time time)
4782 ;; If this is called during org-agenda, don't return any entries to
4783 ;; the calendar. Org Agenda will list these entries itself.
4784 (if org-disable-agenda-to-diary (setq files nil))
4785 (while (setq file (pop files))
4786 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4787 (setq results (append results rtn)))
4788 (if results
4789 (concat (org-finalize-agenda-entries results) "\n"))))
4791 ;;; Agenda entry finders
4793 (defun org-agenda-get-day-entries (file date &rest args)
4794 "Does the work for `org-diary' and `org-agenda'.
4795 FILE is the path to a file to be checked for entries. DATE is date like
4796 the one returned by `calendar-current-date'. ARGS are symbols indicating
4797 which kind of entries should be extracted. For details about these, see
4798 the documentation of `org-diary'."
4799 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4800 (let* ((org-startup-folded nil)
4801 (org-startup-align-all-tables nil)
4802 (buffer (if (file-exists-p file)
4803 (org-get-agenda-file-buffer file)
4804 (error "No such file %s" file)))
4805 arg results rtn deadline-results)
4806 (if (not buffer)
4807 ;; If file does not exist, make sure an error message ends up in diary
4808 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4809 (with-current-buffer buffer
4810 (unless (derived-mode-p 'org-mode)
4811 (error "Agenda file %s is not in `org-mode'" file))
4812 (let ((case-fold-search nil))
4813 (save-excursion
4814 (save-restriction
4815 (if org-agenda-restrict
4816 (narrow-to-region org-agenda-restrict-begin
4817 org-agenda-restrict-end)
4818 (widen))
4819 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4820 (while (setq arg (pop args))
4821 (cond
4822 ((and (eq arg :todo)
4823 (equal date (calendar-gregorian-from-absolute
4824 (org-today))))
4825 (setq rtn (org-agenda-get-todos))
4826 (setq results (append results rtn)))
4827 ((eq arg :timestamp)
4828 (setq rtn (org-agenda-get-blocks))
4829 (setq results (append results rtn))
4830 (setq rtn (org-agenda-get-timestamps deadline-results))
4831 (setq results (append results rtn)))
4832 ((eq arg :sexp)
4833 (setq rtn (org-agenda-get-sexps))
4834 (setq results (append results rtn)))
4835 ((eq arg :scheduled)
4836 (setq rtn (org-agenda-get-scheduled deadline-results))
4837 (setq results (append results rtn)))
4838 ((eq arg :closed)
4839 (setq rtn (org-agenda-get-progress))
4840 (setq results (append results rtn)))
4841 ((eq arg :deadline)
4842 (setq rtn (org-agenda-get-deadlines))
4843 (setq deadline-results (copy-sequence rtn))
4844 (setq results (append results rtn))))))))
4845 results))))
4847 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4848 (defun org-agenda-get-todos ()
4849 "Return the TODO information for agenda display."
4850 (let* ((props (list 'face nil
4851 'done-face 'org-agenda-done
4852 'org-not-done-regexp org-not-done-regexp
4853 'org-todo-regexp org-todo-regexp
4854 'org-complex-heading-regexp org-complex-heading-regexp
4855 'mouse-face 'highlight
4856 'help-echo
4857 (format "mouse-2 or RET jump to org file %s"
4858 (abbreviate-file-name buffer-file-name))))
4859 (regexp (format org-heading-keyword-regexp-format
4860 (cond
4861 ((and org-select-this-todo-keyword
4862 (equal org-select-this-todo-keyword "*"))
4863 org-todo-regexp)
4864 (org-select-this-todo-keyword
4865 (concat "\\("
4866 (mapconcat 'identity
4867 (org-split-string
4868 org-select-this-todo-keyword
4869 "|")
4870 "\\|") "\\)"))
4871 (t org-not-done-regexp))))
4872 marker priority category org-category-pos tags todo-state
4873 ee txt beg end)
4874 (goto-char (point-min))
4875 (while (re-search-forward regexp nil t)
4876 (catch :skip
4877 (save-match-data
4878 (beginning-of-line)
4879 (org-agenda-skip)
4880 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4881 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4882 (goto-char (1+ beg))
4883 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4884 (throw :skip nil)))
4885 (goto-char (match-beginning 2))
4886 (setq marker (org-agenda-new-marker (match-beginning 0))
4887 category (org-get-category)
4888 org-category-pos (get-text-property (point) 'org-category-position)
4889 txt (org-trim
4890 (buffer-substring (match-beginning 2) (match-end 0)))
4891 tags (org-get-tags-at (point))
4892 txt (org-agenda-format-item "" txt category tags)
4893 priority (1+ (org-get-priority txt))
4894 todo-state (org-get-todo-state))
4895 (org-add-props txt props
4896 'org-marker marker 'org-hd-marker marker
4897 'priority priority 'org-category category
4898 'org-category-position org-category-pos
4899 'type "todo" 'todo-state todo-state)
4900 (push txt ee)
4901 (if org-agenda-todo-list-sublevels
4902 (goto-char (match-end 2))
4903 (org-end-of-subtree 'invisible))))
4904 (nreverse ee)))
4906 (defun org-agenda-todo-custom-ignore-p (time n)
4907 "Check whether timestamp is farther away then n number of days.
4908 This function is invoked if `org-agenda-todo-ignore-deadlines',
4909 `org-agenda-todo-ignore-scheduled' or
4910 `org-agenda-todo-ignore-timestamp' is set to an integer."
4911 (let ((days (org-days-to-time time)))
4912 (if (>= n 0)
4913 (>= days n)
4914 (<= days n))))
4916 ;;;###autoload
4917 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4918 (&optional end)
4919 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4920 (when (or org-agenda-todo-ignore-with-date
4921 org-agenda-todo-ignore-scheduled
4922 org-agenda-todo-ignore-deadlines
4923 org-agenda-todo-ignore-timestamp)
4924 (setq end (or end (save-excursion (outline-next-heading) (point))))
4925 (save-excursion
4926 (or (and org-agenda-todo-ignore-with-date
4927 (re-search-forward org-ts-regexp end t))
4928 (and org-agenda-todo-ignore-scheduled
4929 (re-search-forward org-scheduled-time-regexp end t)
4930 (cond
4931 ((eq org-agenda-todo-ignore-scheduled 'future)
4932 (> (org-days-to-time (match-string 1)) 0))
4933 ((eq org-agenda-todo-ignore-scheduled 'past)
4934 (<= (org-days-to-time (match-string 1)) 0))
4935 ((numberp org-agenda-todo-ignore-scheduled)
4936 (org-agenda-todo-custom-ignore-p
4937 (match-string 1) org-agenda-todo-ignore-scheduled))
4938 (t)))
4939 (and org-agenda-todo-ignore-deadlines
4940 (re-search-forward org-deadline-time-regexp end t)
4941 (cond
4942 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4943 ((eq org-agenda-todo-ignore-deadlines 'far)
4944 (not (org-deadline-close (match-string 1))))
4945 ((eq org-agenda-todo-ignore-deadlines 'future)
4946 (> (org-days-to-time (match-string 1)) 0))
4947 ((eq org-agenda-todo-ignore-deadlines 'past)
4948 (<= (org-days-to-time (match-string 1)) 0))
4949 ((numberp org-agenda-todo-ignore-deadlines)
4950 (org-agenda-todo-custom-ignore-p
4951 (match-string 1) org-agenda-todo-ignore-deadlines))
4952 (t (org-deadline-close (match-string 1)))))
4953 (and org-agenda-todo-ignore-timestamp
4954 (let ((buffer (current-buffer))
4955 (regexp
4956 (concat
4957 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4958 (start (point)))
4959 ;; Copy current buffer into a temporary one
4960 (with-temp-buffer
4961 (insert-buffer-substring buffer start end)
4962 (goto-char (point-min))
4963 ;; Delete SCHEDULED and DEADLINE items
4964 (while (re-search-forward regexp end t)
4965 (delete-region (match-beginning 0) (match-end 0)))
4966 (goto-char (point-min))
4967 ;; No search for timestamp left
4968 (when (re-search-forward org-ts-regexp nil t)
4969 (cond
4970 ((eq org-agenda-todo-ignore-timestamp 'future)
4971 (> (org-days-to-time (match-string 1)) 0))
4972 ((eq org-agenda-todo-ignore-timestamp 'past)
4973 (<= (org-days-to-time (match-string 1)) 0))
4974 ((numberp org-agenda-todo-ignore-timestamp)
4975 (org-agenda-todo-custom-ignore-p
4976 (match-string 1) org-agenda-todo-ignore-timestamp))
4977 (t))))))))))
4979 (defconst org-agenda-no-heading-message
4980 "No heading for this item in buffer or region.")
4982 (defun org-agenda-get-timestamps (&optional deadline-results)
4983 "Return the date stamp information for agenda display."
4984 (let* ((props (list 'face 'org-agenda-calendar-event
4985 'org-not-done-regexp org-not-done-regexp
4986 'org-todo-regexp org-todo-regexp
4987 'org-complex-heading-regexp org-complex-heading-regexp
4988 'mouse-face 'highlight
4989 'help-echo
4990 (format "mouse-2 or RET jump to org file %s"
4991 (abbreviate-file-name buffer-file-name))))
4992 (d1 (calendar-absolute-from-gregorian date))
4994 (deadline-position-alist
4995 (mapcar (lambda (a) (and (setq mm (get-text-property
4996 0 'org-hd-marker a))
4997 (cons (marker-position mm) a)))
4998 deadline-results))
4999 (remove-re org-ts-regexp)
5000 (regexp
5001 (concat
5002 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5003 (regexp-quote
5004 (substring
5005 (format-time-string
5006 (car org-time-stamp-formats)
5007 (apply 'encode-time ; DATE bound by calendar
5008 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5009 1 11))
5010 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5011 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5012 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5013 donep tmp priority category org-category-pos ee txt timestr tags
5014 b0 b3 e3 head todo-state end-of-match show-all)
5015 (goto-char (point-min))
5016 (while (setq end-of-match (re-search-forward regexp nil t))
5017 (setq b0 (match-beginning 0)
5018 b3 (match-beginning 3) e3 (match-end 3)
5019 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5020 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5021 (member todo-state
5022 org-agenda-repeating-timestamp-show-all)))
5023 (catch :skip
5024 (and (org-at-date-range-p) (throw :skip nil))
5025 (org-agenda-skip)
5026 (if (and (match-end 1)
5027 (not (= d1 (org-time-string-to-absolute
5028 (match-string 1) d1 nil show-all
5029 (current-buffer) b0))))
5030 (throw :skip nil))
5031 (if (and e3
5032 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5033 (throw :skip nil))
5034 (setq tmp (buffer-substring (max (point-min)
5035 (- b0 org-ds-keyword-length))
5037 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5038 inactivep (= (char-after b0) ?\[)
5039 deadlinep (string-match org-deadline-regexp tmp)
5040 scheduledp (string-match org-scheduled-regexp tmp)
5041 closedp (and org-agenda-include-inactive-timestamps
5042 (string-match org-closed-string tmp))
5043 clockp (and org-agenda-include-inactive-timestamps
5044 (or (string-match org-clock-string tmp)
5045 (string-match "]-+\\'" tmp)))
5046 donep (member todo-state org-done-keywords))
5047 (if (or scheduledp deadlinep closedp clockp
5048 (and donep org-agenda-skip-timestamp-if-done))
5049 (throw :skip t))
5050 (if (string-match ">" timestr)
5051 ;; substring should only run to end of time stamp
5052 (setq timestr (substring timestr 0 (match-end 0))))
5053 (setq marker (org-agenda-new-marker b0)
5054 category (org-get-category b0)
5055 org-category-pos (get-text-property b0 'org-category-position))
5056 (save-excursion
5057 (if (not (re-search-backward org-outline-regexp-bol nil t))
5058 (setq txt org-agenda-no-heading-message)
5059 (goto-char (match-beginning 0))
5060 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5061 (assoc (point) deadline-position-alist))
5062 (throw :skip nil))
5063 (setq hdmarker (org-agenda-new-marker)
5064 tags (org-get-tags-at))
5065 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5066 (setq head (or (match-string 1) ""))
5067 (setq txt (org-agenda-format-item
5068 (if inactivep org-agenda-inactive-leader nil)
5069 head category tags timestr
5070 remove-re)))
5071 (setq priority (org-get-priority txt))
5072 (org-add-props txt props
5073 'org-marker marker 'org-hd-marker hdmarker)
5074 (org-add-props txt nil 'priority priority
5075 'org-category category 'date date
5076 'org-category-position org-category-pos
5077 'todo-state todo-state
5078 'type "timestamp")
5079 (push txt ee))
5080 (if org-agenda-skip-additional-timestamps-same-entry
5081 (outline-next-heading)
5082 (goto-char end-of-match))))
5083 (nreverse ee)))
5085 (defun org-agenda-get-sexps ()
5086 "Return the sexp information for agenda display."
5087 (require 'diary-lib)
5088 (let* ((props (list 'face 'org-agenda-calendar-sexp
5089 'mouse-face 'highlight
5090 'help-echo
5091 (format "mouse-2 or RET jump to org file %s"
5092 (abbreviate-file-name buffer-file-name))))
5093 (regexp "^&?%%(")
5094 marker category extra org-category-pos ee txt tags entry
5095 result beg b sexp sexp-entry todo-state)
5096 (goto-char (point-min))
5097 (while (re-search-forward regexp nil t)
5098 (catch :skip
5099 (org-agenda-skip)
5100 (setq beg (match-beginning 0))
5101 (goto-char (1- (match-end 0)))
5102 (setq b (point))
5103 (forward-sexp 1)
5104 (setq sexp (buffer-substring b (point)))
5105 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5106 (org-trim (match-string 1))
5107 ""))
5108 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5109 (when result
5110 (setq marker (org-agenda-new-marker beg)
5111 category (org-get-category beg)
5112 org-category-pos (get-text-property beg 'org-category-position)
5113 tags (save-excursion (org-backward-heading-same-level 0)
5114 (org-get-tags-at))
5115 todo-state (org-get-todo-state))
5117 (dolist (r (if (stringp result)
5118 (list result)
5119 result)) ;; we expect a list here
5120 (when (and org-agenda-diary-sexp-prefix
5121 (string-match org-agenda-diary-sexp-prefix r))
5122 (setq extra (match-string 0 r)
5123 r (replace-match "" nil nil r)))
5124 (if (string-match "\\S-" r)
5125 (setq txt r)
5126 (setq txt "SEXP entry returned empty string"))
5128 (setq txt (org-agenda-format-item
5129 extra txt category tags 'time))
5130 (org-add-props txt props 'org-marker marker)
5131 (org-add-props txt nil
5132 'org-category category 'date date 'todo-state todo-state
5133 'org-category-position org-category-pos 'tags tags
5134 'type "sexp")
5135 (push txt ee)))))
5136 (nreverse ee)))
5138 ;; Calendar sanity: define some functions that are independent of
5139 ;; `calendar-date-style'.
5140 ;; Normally I would like to use ISO format when calling the diary functions,
5141 ;; but to make sure we still have Emacs 22 compatibility we bind
5142 ;; also `european-calendar-style' and use european format
5143 (defun org-anniversary (year month day &optional mark)
5144 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5145 (org-no-warnings
5146 (let ((calendar-date-style 'european) (european-calendar-style t))
5147 (diary-anniversary day month year mark))))
5148 (defun org-cyclic (N year month day &optional mark)
5149 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5150 (org-no-warnings
5151 (let ((calendar-date-style 'european) (european-calendar-style t))
5152 (diary-cyclic N day month year mark))))
5153 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5154 "Like `diary-block', but with fixed (ISO) order of arguments."
5155 (org-no-warnings
5156 (let ((calendar-date-style 'european) (european-calendar-style t))
5157 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5158 (defun org-date (year month day &optional mark)
5159 "Like `diary-date', but with fixed (ISO) order of arguments."
5160 (org-no-warnings
5161 (let ((calendar-date-style 'european) (european-calendar-style t))
5162 (diary-date day month year mark))))
5163 (defalias 'org-float 'diary-float)
5165 ;; Define the` org-class' function
5166 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5167 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5168 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5169 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5170 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5171 `holidays', then any date that is known by the Emacs calendar to be a
5172 holiday will also be skipped."
5173 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5174 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5175 (d (calendar-absolute-from-gregorian date)))
5176 (and
5177 (<= date1 d)
5178 (<= d date2)
5179 (= (calendar-day-of-week date) dayname)
5180 (or (not skip-weeks)
5181 (progn
5182 (require 'cal-iso)
5183 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5184 (not (and (memq 'holidays skip-weeks)
5185 (calendar-check-holidays date)))
5186 entry)))
5188 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5189 "Like `org-class', but honor `calendar-date-style'.
5190 The order of the first 2 times 3 arguments depends on the variable
5191 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5192 So for American calendars, give this as MONTH DAY YEAR, for European as
5193 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5194 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5195 is any number of ISO weeks in the block period for which the item should
5196 be skipped.
5198 This function is here only for backward compatibility and it is deprecated,
5199 please use `org-class' instead."
5200 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5201 (date2 (org-order-calendar-date-args m2 d2 y2)))
5202 (org-class
5203 (nth 2 date1) (car date1) (nth 1 date1)
5204 (nth 2 date2) (car date2) (nth 1 date2)
5205 dayname skip-weeks)))
5206 (make-obsolete 'org-diary-class 'org-class "")
5208 (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
5209 (defalias 'org-get-closed 'org-agenda-get-progress)
5210 (defun org-agenda-get-progress ()
5211 "Return the logged TODO entries for agenda display."
5212 (let* ((props (list 'mouse-face 'highlight
5213 'org-not-done-regexp org-not-done-regexp
5214 'org-todo-regexp org-todo-regexp
5215 'org-complex-heading-regexp org-complex-heading-regexp
5216 'help-echo
5217 (format "mouse-2 or RET jump to org file %s"
5218 (abbreviate-file-name buffer-file-name))))
5219 (items (if (consp org-agenda-show-log-scoped)
5220 org-agenda-show-log-scoped
5221 (if (eq org-agenda-show-log-scoped 'clockcheck)
5222 '(clock)
5223 org-agenda-log-mode-items)))
5224 (parts
5225 (delq nil
5226 (list
5227 (if (memq 'closed items) (concat "\\<" org-closed-string))
5228 (if (memq 'clock items) (concat "\\<" org-clock-string))
5229 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5230 (parts-re (if parts (mapconcat 'identity parts "\\|")
5231 (error "`org-agenda-log-mode-items' is empty")))
5232 (regexp (concat
5233 "\\(" parts-re "\\)"
5234 " *\\["
5235 (regexp-quote
5236 (substring
5237 (format-time-string
5238 (car org-time-stamp-formats)
5239 (apply 'encode-time ; DATE bound by calendar
5240 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5241 1 11))))
5242 (org-agenda-search-headline-for-time nil)
5243 marker hdmarker priority category org-category-pos tags closedp
5244 statep clockp state ee txt extra timestr rest clocked)
5245 (goto-char (point-min))
5246 (while (re-search-forward regexp nil t)
5247 (catch :skip
5248 (org-agenda-skip)
5249 (setq marker (org-agenda-new-marker (match-beginning 0))
5250 closedp (equal (match-string 1) org-closed-string)
5251 statep (equal (string-to-char (match-string 1)) ?-)
5252 clockp (not (or closedp statep))
5253 state (and statep (match-string 2))
5254 category (org-get-category (match-beginning 0))
5255 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5256 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5257 (when (string-match "\\]" timestr)
5258 ;; substring should only run to end of time stamp
5259 (setq rest (substring timestr (match-end 0))
5260 timestr (substring timestr 0 (match-end 0)))
5261 (if (and (not closedp) (not statep)
5262 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5263 rest))
5264 (progn (setq timestr (concat (substring timestr 0 -1)
5265 "-" (match-string 1 rest) "]"))
5266 (setq clocked (match-string 2 rest)))
5267 (setq clocked "-")))
5268 (save-excursion
5269 (setq extra
5270 (cond
5271 ((not org-agenda-log-mode-add-notes) nil)
5272 (statep
5273 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5274 (match-string 1)))
5275 (clockp
5276 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5277 (match-string 1)))))
5278 (if (not (re-search-backward org-outline-regexp-bol nil t))
5279 (setq txt org-agenda-no-heading-message)
5280 (goto-char (match-beginning 0))
5281 (setq hdmarker (org-agenda-new-marker)
5282 tags (org-get-tags-at))
5283 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5284 (setq txt (match-string 1))
5285 (when extra
5286 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5287 (setq txt (concat (substring txt 0 (match-beginning 1))
5288 " - " extra " " (match-string 2 txt)))
5289 (setq txt (concat txt " - " extra))))
5290 (setq txt (org-agenda-format-item
5291 (cond
5292 (closedp "Closed: ")
5293 (statep (concat "State: (" state ")"))
5294 (t (concat "Clocked: (" clocked ")")))
5295 txt category tags timestr)))
5296 (setq priority 100000)
5297 (org-add-props txt props
5298 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5299 'priority priority 'org-category category
5300 'org-category-position org-category-pos
5301 'type "closed" 'date date
5302 'undone-face 'org-warning 'done-face 'org-agenda-done)
5303 (push txt ee))
5304 (goto-char (point-at-eol))))
5305 (nreverse ee)))
5307 (defun org-agenda-show-clocking-issues ()
5308 "Add overlays, showing issues with clocking.
5309 See also the user option `org-agenda-clock-consistency-checks'."
5310 (interactive)
5311 (let* ((pl org-agenda-clock-consistency-checks)
5312 (re (concat "^[ \t]*"
5313 org-clock-string
5314 "[ \t]+"
5315 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5316 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5317 (tlstart 0.)
5318 (tlend 0.)
5319 (maxtime (org-hh:mm-string-to-minutes
5320 (or (plist-get pl :max-duration) "24:00")))
5321 (mintime (org-hh:mm-string-to-minutes
5322 (or (plist-get pl :min-duration) 0)))
5323 (maxgap (org-hh:mm-string-to-minutes
5324 ;; default 30:00 means never complain
5325 (or (plist-get pl :max-gap) "30:00")))
5326 (gapok (mapcar 'org-hh:mm-string-to-minutes
5327 (plist-get pl :gap-ok-around)))
5328 (def-face (or (plist-get pl :default-face)
5329 '((:background "DarkRed") (:foreground "white"))))
5330 issue face m te ts dt ov)
5331 (goto-char (point-min))
5332 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5333 (setq issue nil face def-face)
5334 (catch 'next
5335 (setq m (org-get-at-bol 'org-marker)
5336 te nil ts nil)
5337 (unless (and m (markerp m))
5338 (setq issue "No valid clock line") (throw 'next t))
5339 (org-with-point-at m
5340 (save-excursion
5341 (goto-char (point-at-bol))
5342 (unless (looking-at re)
5343 (error "No valid Clock line")
5344 (throw 'next t))
5345 (unless (match-end 3)
5346 (setq issue "No end time"
5347 face (or (plist-get pl :no-end-time-face) face))
5348 (throw 'next t))
5349 (setq ts (match-string 1)
5350 te (match-string 3)
5351 ts (org-float-time
5352 (apply 'encode-time (org-parse-time-string ts)))
5353 te (org-float-time
5354 (apply 'encode-time (org-parse-time-string te)))
5355 dt (- te ts))))
5356 (cond
5357 ((> dt (* 60 maxtime))
5358 ;; a very long clocking chunk
5359 (setq issue (format "Clocking interval is very long: %s"
5360 (org-minutes-to-hh:mm-string
5361 (floor (/ (float dt) 60.))))
5362 face (or (plist-get pl :long-face) face)))
5363 ((< dt (* 60 mintime))
5364 ;; a very short clocking chunk
5365 (setq issue (format "Clocking interval is very short: %s"
5366 (org-minutes-to-hh:mm-string
5367 (floor (/ (float dt) 60.))))
5368 face (or (plist-get pl :short-face) face)))
5369 ((and (> tlend 0) (< ts tlend))
5370 ;; Two clock entries are overlapping
5371 (setq issue (format "Clocking overlap: %d minutes"
5372 (/ (- tlend ts) 60))
5373 face (or (plist-get pl :overlap-face) face)))
5374 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5375 ;; There is a gap, lets see if we need to report it
5376 (unless (org-agenda-check-clock-gap tlend ts gapok)
5377 (setq issue (format "Clocking gap: %d minutes"
5378 (/ (- ts tlend) 60))
5379 face (or (plist-get pl :gap-face) face))))
5380 (t nil)))
5381 (setq tlend (or te tlend) tlstart (or ts tlstart))
5382 (when issue
5383 ;; OK, there was some issue, add an overlay to show the issue
5384 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5385 (overlay-put ov 'before-string
5386 (concat
5387 (org-add-props
5388 (format "%-43s" (concat " " issue))
5390 'face face)
5391 "\n"))
5392 (overlay-put ov 'evaporate t)))))
5394 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5395 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5396 (catch 'exit
5397 (unless ok-list
5398 ;; there are no OK times for gaps...
5399 (throw 'exit nil))
5400 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5401 ;; This is more than 24 hours, so it is OK.
5402 ;; because we have at least one OK time, that must be in the
5403 ;; 24 hour interval.
5404 (throw 'exit t))
5405 ;; We have a shorter gap.
5406 ;; Now we have to get the minute of the day when these times are
5407 (let* ((t1dec (decode-time (seconds-to-time t1)))
5408 (t2dec (decode-time (seconds-to-time t2)))
5409 ;; compute the minute on the day
5410 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5411 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5412 (when (< min2 min1)
5413 ;; if min2 is smaller than min1, this means it is on the next day.
5414 ;; Wrap it to after midnight.
5415 (setq min2 (+ min2 1440)))
5416 ;; Now check if any of the OK times is in the gap
5417 (mapc (lambda (x)
5418 ;; Wrap the time to after midnight if necessary
5419 (if (< x min1) (setq x (+ x 1440)))
5420 ;; Check if in interval
5421 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5422 ok-list)
5423 ;; Nope, this gap is not OK
5424 nil)))
5426 (defun org-agenda-get-deadlines ()
5427 "Return the deadline information for agenda display."
5428 (let* ((props (list 'mouse-face 'highlight
5429 'org-not-done-regexp org-not-done-regexp
5430 'org-todo-regexp org-todo-regexp
5431 'org-complex-heading-regexp org-complex-heading-regexp
5432 'help-echo
5433 (format "mouse-2 or RET jump to org file %s"
5434 (abbreviate-file-name buffer-file-name))))
5435 (regexp org-deadline-time-regexp)
5436 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5437 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5438 d2 diff dfrac wdays pos pos1 category org-category-pos
5439 tags suppress-prewarning ee txt head face s todo-state
5440 show-all upcomingp donep timestr)
5441 (goto-char (point-min))
5442 (while (re-search-forward regexp nil t)
5443 (setq suppress-prewarning nil)
5444 (catch :skip
5445 (org-agenda-skip)
5446 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5447 (save-match-data
5448 (string-match org-scheduled-time-regexp
5449 (buffer-substring (point-at-bol)
5450 (point-at-eol)))))
5451 (setq suppress-prewarning
5452 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5453 org-agenda-skip-deadline-prewarning-if-scheduled
5454 0)))
5455 (setq s (match-string 1)
5456 txt nil
5457 pos (1- (match-beginning 1))
5458 todo-state (save-match-data (org-get-todo-state))
5459 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5460 (member todo-state
5461 org-agenda-repeating-timestamp-show-all))
5462 d2 (org-time-string-to-absolute
5463 (match-string 1) d1 'past show-all
5464 (current-buffer) pos)
5465 diff (- d2 d1)
5466 wdays (if suppress-prewarning
5467 (let ((org-deadline-warning-days suppress-prewarning))
5468 (org-get-wdays s))
5469 (org-get-wdays s))
5470 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5471 upcomingp (and todayp (> diff 0)))
5472 ;; When to show a deadline in the calendar:
5473 ;; If the expiration is within wdays warning time.
5474 ;; Past-due deadlines are only shown on the current date
5475 (if (and (or (and (<= diff wdays)
5476 (and todayp (not org-agenda-only-exact-dates)))
5477 (= diff 0)))
5478 (save-excursion
5479 ;; (setq todo-state (org-get-todo-state))
5480 (setq donep (member todo-state org-done-keywords))
5481 (if (and donep
5482 (or org-agenda-skip-deadline-if-done
5483 (not (= diff 0))))
5484 (setq txt nil)
5485 (setq category (org-get-category)
5486 org-category-pos (get-text-property (point) 'org-category-position))
5487 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5488 (setq txt org-agenda-no-heading-message)
5489 (goto-char (match-end 0))
5490 (setq pos1 (match-beginning 0))
5491 (setq tags (org-get-tags-at pos1))
5492 (setq head (buffer-substring-no-properties
5493 (point)
5494 (progn (skip-chars-forward "^\r\n")
5495 (point))))
5496 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5497 (setq timestr
5498 (concat (substring s (match-beginning 1)) " "))
5499 (setq timestr 'time))
5500 (setq txt (org-agenda-format-item
5501 (if (= diff 0)
5502 (car org-agenda-deadline-leaders)
5503 (if (functionp
5504 (nth 1 org-agenda-deadline-leaders))
5505 (funcall
5506 (nth 1 org-agenda-deadline-leaders)
5507 diff date)
5508 (format (nth 1 org-agenda-deadline-leaders)
5509 diff)))
5510 head category tags
5511 (if (not (= diff 0)) nil timestr)))))
5512 (when txt
5513 (setq face (org-agenda-deadline-face dfrac))
5514 (org-add-props txt props
5515 'org-marker (org-agenda-new-marker pos)
5516 'org-hd-marker (org-agenda-new-marker pos1)
5517 'priority (+ (- diff)
5518 (org-get-priority txt))
5519 'org-category category
5520 'org-category-position org-category-pos
5521 'todo-state todo-state
5522 'type (if upcomingp "upcoming-deadline" "deadline")
5523 'date (if upcomingp date d2)
5524 'face (if donep 'org-agenda-done face)
5525 'undone-face face 'done-face 'org-agenda-done)
5526 (push txt ee))))))
5527 (nreverse ee)))
5529 (defun org-agenda-deadline-face (fraction)
5530 "Return the face to displaying a deadline item.
5531 FRACTION is what fraction of the head-warning time has passed."
5532 (let ((faces org-agenda-deadline-faces) f)
5533 (catch 'exit
5534 (while (setq f (pop faces))
5535 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5537 (defun org-agenda-get-scheduled (&optional deadline-results)
5538 "Return the scheduled information for agenda display."
5539 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5540 'org-todo-regexp org-todo-regexp
5541 'org-complex-heading-regexp org-complex-heading-regexp
5542 'done-face 'org-agenda-done
5543 'mouse-face 'highlight
5544 'help-echo
5545 (format "mouse-2 or RET jump to org file %s"
5546 (abbreviate-file-name buffer-file-name))))
5547 (regexp org-scheduled-time-regexp)
5548 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5549 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5551 (deadline-position-alist
5552 (mapcar (lambda (a) (and (setq mm (get-text-property
5553 0 'org-hd-marker a))
5554 (cons (marker-position mm) a)))
5555 deadline-results))
5556 d2 diff pos pos1 category org-category-pos tags donep
5557 ee txt head pastschedp todo-state face timestr s habitp show-all
5558 did-habit-check-p)
5559 (goto-char (point-min))
5560 (while (re-search-forward regexp nil t)
5561 (catch :skip
5562 (org-agenda-skip)
5563 (setq s (match-string 1)
5564 txt nil
5565 pos (1- (match-beginning 1))
5566 todo-state (save-match-data (org-get-todo-state))
5567 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5568 (member todo-state
5569 org-agenda-repeating-timestamp-show-all))
5570 d2 (org-time-string-to-absolute
5571 (match-string 1) d1 'past show-all
5572 (current-buffer) pos)
5573 diff (- d2 d1))
5574 (setq pastschedp (and todayp (< diff 0)))
5575 (setq did-habit-check-p nil)
5576 ;; When to show a scheduled item in the calendar:
5577 ;; If it is on or past the date.
5578 (when (or (and (< diff 0)
5579 (< (abs diff) org-scheduled-past-days)
5580 (and todayp (not org-agenda-only-exact-dates)))
5581 (= diff 0)
5582 ;; org-is-habit-p uses org-entry-get, which is expansive
5583 ;; so we go extra mile to only call it once
5584 (and todayp
5585 org-habit-show-all-today
5586 (setq did-habit-check-p t)
5587 (setq habitp (and (functionp 'org-is-habit-p)
5588 (org-is-habit-p)))))
5589 (save-excursion
5590 (setq donep (member todo-state org-done-keywords))
5591 (if (and donep
5592 (or org-agenda-skip-scheduled-if-done
5593 (not (= diff 0))
5594 (and (functionp 'org-is-habit-p)
5595 (org-is-habit-p))))
5596 (setq txt nil)
5597 (setq habitp (if did-habit-check-p habitp
5598 (and (functionp 'org-is-habit-p)
5599 (org-is-habit-p))))
5600 (setq category (org-get-category)
5601 org-category-pos (get-text-property (point) 'org-category-position))
5602 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5603 (setq txt org-agenda-no-heading-message)
5604 (goto-char (match-end 0))
5605 (setq pos1 (match-beginning 0))
5606 (if habitp
5607 (if (or (not org-habit-show-habits)
5608 (and (not todayp)
5609 org-habit-show-habits-only-for-today))
5610 (throw :skip nil))
5611 (if (and
5612 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5613 (and org-agenda-skip-scheduled-if-deadline-is-shown
5614 pastschedp))
5615 (setq mm (assoc pos1 deadline-position-alist)))
5616 (throw :skip nil)))
5617 (setq tags (org-get-tags-at))
5618 (setq head (buffer-substring-no-properties
5619 (point)
5620 (progn (skip-chars-forward "^\r\n") (point))))
5621 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5622 (setq timestr
5623 (concat (substring s (match-beginning 1)) " "))
5624 (setq timestr 'time))
5625 (setq txt (org-agenda-format-item
5626 (if (= diff 0)
5627 (car org-agenda-scheduled-leaders)
5628 (format (nth 1 org-agenda-scheduled-leaders)
5629 (- 1 diff)))
5630 head category tags
5631 (if (not (= diff 0)) nil timestr)
5632 nil habitp))))
5633 (when txt
5634 (setq face
5635 (cond
5636 ((and (not habitp) pastschedp)
5637 'org-scheduled-previously)
5638 (todayp 'org-scheduled-today)
5639 (t 'org-scheduled))
5640 habitp (and habitp (org-habit-parse-todo)))
5641 (org-add-props txt props
5642 'undone-face face
5643 'face (if donep 'org-agenda-done face)
5644 'org-marker (org-agenda-new-marker pos)
5645 'org-hd-marker (org-agenda-new-marker pos1)
5646 'type (if pastschedp "past-scheduled" "scheduled")
5647 'date (if pastschedp d2 date)
5648 'priority (if habitp
5649 (org-habit-get-priority habitp)
5650 (+ 94 (- 5 diff) (org-get-priority txt)))
5651 'org-category category
5652 'org-category-position org-category-pos
5653 'org-habit-p habitp
5654 'todo-state todo-state)
5655 (push txt ee))))))
5656 (nreverse ee)))
5658 (defun org-agenda-get-blocks ()
5659 "Return the date-range information for agenda display."
5660 (let* ((props (list 'face nil
5661 'org-not-done-regexp org-not-done-regexp
5662 'org-todo-regexp org-todo-regexp
5663 'org-complex-heading-regexp org-complex-heading-regexp
5664 'mouse-face 'highlight
5665 'help-echo
5666 (format "mouse-2 or RET jump to org file %s"
5667 (abbreviate-file-name buffer-file-name))))
5668 (regexp org-tr-regexp)
5669 (d0 (calendar-absolute-from-gregorian date))
5670 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5671 todo-state tags pos head donep)
5672 (goto-char (point-min))
5673 (while (re-search-forward regexp nil t)
5674 (catch :skip
5675 (org-agenda-skip)
5676 (setq pos (point))
5677 (let ((start-time (match-string 1))
5678 (end-time (match-string 2)))
5679 (setq s1 (match-string 1)
5680 s2 (match-string 2)
5681 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5682 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5683 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5684 ;; Only allow days between the limits, because the normal
5685 ;; date stamps will catch the limits.
5686 (save-excursion
5687 (setq todo-state (org-get-todo-state))
5688 (setq donep (member todo-state org-done-keywords))
5689 (if (and donep org-agenda-skip-timestamp-if-done)
5690 (throw :skip t))
5691 (setq marker (org-agenda-new-marker (point)))
5692 (setq category (org-get-category)
5693 org-category-pos (get-text-property (point) 'org-category-position))
5694 (if (not (re-search-backward org-outline-regexp-bol nil t))
5695 (setq txt org-agenda-no-heading-message)
5696 (goto-char (match-beginning 0))
5697 (setq hdmarker (org-agenda-new-marker (point)))
5698 (setq tags (org-get-tags-at))
5699 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5700 (setq head (match-string 1))
5701 (let ((remove-re
5702 (if org-agenda-remove-timeranges-from-blocks
5703 (concat
5704 "<" (regexp-quote s1) ".*?>"
5705 "--"
5706 "<" (regexp-quote s2) ".*?>")
5707 nil)))
5708 (setq txt (org-agenda-format-item
5709 (format
5710 (nth (if (= d1 d2) 0 1)
5711 org-agenda-timerange-leaders)
5712 (1+ (- d0 d1)) (1+ (- d2 d1)))
5713 head category tags
5714 (cond ((and (= d1 d0) (= d2 d0))
5715 (concat "<" start-time ">--<" end-time ">"))
5716 ((= d1 d0)
5717 (concat "<" start-time ">"))
5718 ((= d2 d0)
5719 (concat "<" end-time ">"))
5720 (t nil))
5721 remove-re))))
5722 (org-add-props txt props
5723 'org-marker marker 'org-hd-marker hdmarker
5724 'type "block" 'date date
5725 'todo-state todo-state
5726 'priority (org-get-priority txt) 'org-category category
5727 'org-category-position org-category-pos)
5728 (push txt ee))))
5729 (goto-char pos)))
5730 ;; Sort the entries by expiration date.
5731 (nreverse ee)))
5733 ;;; Agenda presentation and sorting
5735 (defvar org-prefix-has-time nil
5736 "A flag, set by `org-compile-prefix-format'.
5737 The flag is set if the currently compiled format contains a `%t'.")
5738 (defvar org-prefix-has-tag nil
5739 "A flag, set by `org-compile-prefix-format'.
5740 The flag is set if the currently compiled format contains a `%T'.")
5741 (defvar org-prefix-has-effort nil
5742 "A flag, set by `org-compile-prefix-format'.
5743 The flag is set if the currently compiled format contains a `%e'.")
5744 (defvar org-prefix-category-length nil
5745 "Used by `org-compile-prefix-format' to remember the category field width.")
5746 (defvar org-prefix-category-max-length nil
5747 "Used by `org-compile-prefix-format' to remember the category field width.")
5749 (defun org-agenda-get-category-icon (category)
5750 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5751 (dolist (entry org-agenda-category-icon-alist)
5752 (when (org-string-match-p (car entry) category)
5753 (if (listp (cadr entry))
5754 (return (cadr entry))
5755 (return (apply 'create-image (cdr entry)))))))
5757 (defun org-agenda-format-item (extra txt &optional category tags dotime
5758 remove-re habitp)
5759 "Format TXT to be inserted into the agenda buffer.
5760 In particular, it adds the prefix and corresponding text properties. EXTRA
5761 must be a string and replaces the `%s' specifier in the prefix format.
5762 CATEGORY (string, symbol or nil) may be used to overrule the default
5763 category taken from local variable or file name. It will replace the `%c'
5764 specifier in the format. DOTIME, when non-nil, indicates that a
5765 time-of-day should be extracted from TXT for sorting of this entry, and for
5766 the `%t' specifier in the format. When DOTIME is a string, this string is
5767 searched for a time before TXT is. TAGS can be the tags of the headline.
5768 Any match of REMOVE-RE will be removed from TXT."
5769 ;; We keep the org-prefix-* variable values along with a compiled
5770 ;; formatter, so that multiple agendas existing at the same time, do
5771 ;; not step on each other toes.
5773 ;; It was inconvenient to make these variables buffer local in
5774 ;; Agenda buffers, because this function expects to be called with
5775 ;; the buffer where item comes from being current, and not agenda
5776 ;; buffer
5777 (let* ((bindings (car org-prefix-format-compiled))
5778 (formatter (cadr org-prefix-format-compiled)))
5779 (loop for (var value) in bindings
5780 do (set var value))
5781 (save-match-data
5782 ;; Diary entries sometimes have extra whitespace at the beginning
5783 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5785 ;; Fix the tags part in txt
5786 (setq txt (org-agenda-fix-displayed-tags
5787 txt tags
5788 org-agenda-show-inherited-tags
5789 org-agenda-hide-tags-regexp))
5790 (let* ((category (or category
5791 (if (stringp org-category)
5792 org-category
5793 (and org-category (symbol-name org-category)))
5794 (if buffer-file-name
5795 (file-name-sans-extension
5796 (file-name-nondirectory buffer-file-name))
5797 "")))
5798 (category-icon (org-agenda-get-category-icon category))
5799 (category-icon (if category-icon
5800 (propertize " " 'display category-icon)
5801 ""))
5802 ;; time, tag, effort are needed for the eval of the prefix format
5803 (tag (if tags (nth (1- (length tags)) tags) ""))
5804 time effort neffort
5805 (ts (if dotime (concat
5806 (if (stringp dotime) dotime "")
5807 (and org-agenda-search-headline-for-time txt))))
5808 (time-of-day (and dotime (org-get-time-of-day ts)))
5809 stamp plain s0 s1 s2 rtn srp l
5810 duration thecategory)
5811 (and (derived-mode-p 'org-mode) buffer-file-name
5812 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5813 (when (and dotime time-of-day)
5814 ;; Extract starting and ending time and move them to prefix
5815 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5816 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5817 (setq s0 (match-string 0 ts)
5818 srp (and stamp (match-end 3))
5819 s1 (match-string (if plain 1 2) ts)
5820 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5822 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5823 ;; them, we might want to remove them there to avoid duplication.
5824 ;; The user can turn this off with a variable.
5825 (if (and org-prefix-has-time
5826 org-agenda-remove-times-when-in-prefix (or stamp plain)
5827 (string-match (concat (regexp-quote s0) " *") txt)
5828 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5829 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5830 (= (match-beginning 0) 0)
5832 (setq txt (replace-match "" nil nil txt))))
5833 ;; Normalize the time(s) to 24 hour
5834 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5835 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5837 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5838 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5839 (setq s2
5840 (org-minutes-to-hh:mm-string
5841 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5843 ;; Compute the duration
5844 (when s2
5845 (setq duration (- (org-hh:mm-string-to-minutes s2)
5846 (org-hh:mm-string-to-minutes s1)))))
5848 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5849 txt)
5850 ;; Tags are in the string
5851 (if (or (eq org-agenda-remove-tags t)
5852 (and org-agenda-remove-tags
5853 org-prefix-has-tag))
5854 (setq txt (replace-match "" t t txt))
5855 (setq txt (replace-match
5856 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5857 (match-string 2 txt))
5858 t t txt))))
5859 (when (derived-mode-p 'org-mode)
5860 (setq effort
5861 (condition-case nil
5862 (org-get-effort
5863 (or (get-text-property 0 'org-hd-marker txt)
5864 (get-text-property 0 'org-marker txt)))
5865 (error nil)))
5866 (when effort
5867 (setq neffort (org-duration-string-to-minutes effort)
5868 effort (setq effort (concat "[" effort "]")))))
5869 ;; prevent erroring out with %e format when there is no effort
5870 (or effort (setq effort ""))
5872 (when remove-re
5873 (while (string-match remove-re txt)
5874 (setq txt (replace-match "" t t txt))))
5876 ;; Set org-heading property on `txt' to mark the start of the
5877 ;; heading.
5878 (add-text-properties 0 (length txt) '(org-heading t) txt)
5880 ;; Prepare the variables needed in the eval of the compiled format
5881 (setq time (cond (s2 (concat
5882 (org-agenda-time-of-day-to-ampm-maybe s1)
5883 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5884 (if org-agenda-timegrid-use-ampm " ")))
5885 (s1 (concat
5886 (org-agenda-time-of-day-to-ampm-maybe s1)
5887 (if org-agenda-timegrid-use-ampm
5888 "........ "
5889 "......")))
5890 (t ""))
5891 extra (or (and (not habitp) extra) "")
5892 category (if (symbolp category) (symbol-name category) category)
5893 thecategory (copy-sequence category))
5894 (if (string-match org-bracket-link-regexp category)
5895 (progn
5896 (setq l (if (match-end 3)
5897 (- (match-end 3) (match-beginning 3))
5898 (- (match-end 1) (match-beginning 1))))
5899 (when (< l (or org-prefix-category-length 0))
5900 (setq category (copy-sequence category))
5901 (org-add-props category nil
5902 'extra-space (make-string
5903 (- org-prefix-category-length l 1) ?\ ))))
5904 (if (and org-prefix-category-max-length
5905 (>= (length category) org-prefix-category-max-length))
5906 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5907 ;; Evaluate the compiled format
5908 (setq rtn (concat (eval formatter) txt))
5910 ;; And finally add the text properties
5911 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5912 (org-add-props rtn nil
5913 'org-category (if thecategory (downcase thecategory) category)
5914 'tags (mapcar 'org-downcase-keep-props tags)
5915 'org-highest-priority org-highest-priority
5916 'org-lowest-priority org-lowest-priority
5917 'time-of-day time-of-day
5918 'duration duration
5919 'effort effort
5920 'effort-minutes neffort
5921 'txt txt
5922 'time time
5923 'extra extra
5924 'format org-prefix-format-compiled
5925 'dotime dotime)))))
5927 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5928 "Remove tags string from TXT, and add a modified list of tags.
5929 The modified list may contain inherited tags, and tags matched by
5930 `org-agenda-hide-tags-regexp' will be removed."
5931 (when (or add-inherited hide-re)
5932 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5933 (setq txt (substring txt 0 (match-beginning 0))))
5934 (setq tags
5935 (delq nil
5936 (mapcar (lambda (tg)
5937 (if (or (and hide-re (string-match hide-re tg))
5938 (and (not add-inherited)
5939 (get-text-property 0 'inherited tg)))
5941 tg))
5942 tags)))
5943 (when tags
5944 (let ((have-i (get-text-property 0 'inherited (car tags)))
5946 (setq txt (concat txt " :"
5947 (mapconcat
5948 (lambda (x)
5949 (setq i (get-text-property 0 'inherited x))
5950 (if (and have-i (not i))
5951 (progn
5952 (setq have-i nil)
5953 (concat ":" x))
5955 tags ":")
5956 (if have-i "::" ":"))))))
5957 txt)
5959 (defun org-downcase-keep-props (s)
5960 (let ((props (text-properties-at 0 s)))
5961 (setq s (downcase s))
5962 (add-text-properties 0 (length s) props s)
5965 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5966 (defvar org-agenda-sorting-strategy-selected nil)
5968 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5969 (catch 'exit
5970 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5971 ((and todayp (member 'today (car org-agenda-time-grid))))
5972 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5973 ((member 'weekly (car org-agenda-time-grid)))
5974 (t (throw 'exit list)))
5975 (let* ((have (delq nil (mapcar
5976 (lambda (x) (get-text-property 1 'time-of-day x))
5977 list)))
5978 (string (nth 1 org-agenda-time-grid))
5979 (gridtimes (nth 2 org-agenda-time-grid))
5980 (req (car org-agenda-time-grid))
5981 (remove (member 'remove-match req))
5982 new time)
5983 (if (and (member 'require-timed req) (not have))
5984 ;; don't show empty grid
5985 (throw 'exit list))
5986 (while (setq time (pop gridtimes))
5987 (unless (and remove (member time have))
5988 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5989 (push (org-agenda-format-item
5990 nil string "" nil
5991 (concat (substring time 0 -2) ":" (substring time -2)))
5992 new)
5993 (put-text-property
5994 2 (length (car new)) 'face 'org-time-grid (car new))))
5995 (when (and todayp org-agenda-show-current-time-in-grid)
5996 (push (org-agenda-format-item
5998 org-agenda-current-time-string
5999 "" nil
6000 (format-time-string "%H:%M "))
6001 new)
6002 (put-text-property
6003 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6005 (if (member 'time-up org-agenda-sorting-strategy-selected)
6006 (append new list)
6007 (append list new)))))
6009 (defun org-compile-prefix-format (key)
6010 "Compile the prefix format into a Lisp form that can be evaluated.
6011 The resulting form and associated variable bindings is returned
6012 and stored in the variable `org-prefix-format-compiled'."
6013 (setq org-prefix-has-time nil org-prefix-has-tag nil
6014 org-prefix-category-length nil
6015 org-prefix-has-effort nil)
6016 (let ((s (cond
6017 ((stringp org-agenda-prefix-format)
6018 org-agenda-prefix-format)
6019 ((assq key org-agenda-prefix-format)
6020 (cdr (assq key org-agenda-prefix-format)))
6021 (t " %-12:c%?-12t% s")))
6022 (start 0)
6023 varform vars var e c f opt)
6024 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6025 s start)
6026 (setq var (or (cdr (assoc (match-string 4 s)
6027 '(("c" . category) ("t" . time) ("s" . extra)
6028 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6029 'eval)
6030 c (or (match-string 3 s) "")
6031 opt (match-beginning 1)
6032 start (1+ (match-beginning 0)))
6033 (if (equal var 'time) (setq org-prefix-has-time t))
6034 (if (equal var 'tag) (setq org-prefix-has-tag t))
6035 (if (equal var 'effort) (setq org-prefix-has-effort t))
6036 (setq f (concat "%" (match-string 2 s) "s"))
6037 (when (equal var 'category)
6038 (setq org-prefix-category-length
6039 (floor (abs (string-to-number (match-string 2 s)))))
6040 (setq org-prefix-category-max-length
6041 (let ((x (match-string 2 s)))
6042 (save-match-data
6043 (if (string-match "\\.[0-9]+" x)
6044 (string-to-number (substring (match-string 0 x) 1)))))))
6045 (if (eq var 'eval)
6046 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6047 (if opt
6048 (setq varform
6049 `(if (equal "" ,var)
6051 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6052 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6053 (setq s (replace-match "%s" t nil s))
6054 (push varform vars))
6055 (setq vars (nreverse vars))
6056 (with-current-buffer org-agenda-buffer
6057 (setq org-prefix-format-compiled
6058 (list
6059 `((org-prefix-has-time ,org-prefix-has-time)
6060 (org-prefix-has-tag ,org-prefix-has-tag)
6061 (org-prefix-category-length ,org-prefix-category-length)
6062 (org-prefix-has-effort ,org-prefix-has-effort))
6063 `(format ,s ,@vars))))))
6065 (defun org-set-sorting-strategy (key)
6066 (if (symbolp (car org-agenda-sorting-strategy))
6067 ;; the old format
6068 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6069 (setq org-agenda-sorting-strategy-selected
6070 (or (cdr (assq key org-agenda-sorting-strategy))
6071 (cdr (assq 'agenda org-agenda-sorting-strategy))
6072 '(time-up category-keep priority-down)))))
6074 (defun org-get-time-of-day (s &optional string mod24)
6075 "Check string S for a time of day.
6076 If found, return it as a military time number between 0 and 2400.
6077 If not found, return nil.
6078 The optional STRING argument forces conversion into a 5 character wide string
6079 HH:MM."
6080 (save-match-data
6081 (when
6082 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6083 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6084 (let* ((h (string-to-number (match-string 1 s)))
6085 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6086 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6087 (am-p (equal ampm "am"))
6088 (h1 (cond ((not ampm) h)
6089 ((= h 12) (if am-p 0 12))
6090 (t (+ h (if am-p 0 12)))))
6091 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6092 (mod h1 24) h1))
6093 (t0 (+ (* 100 h2) m))
6094 (t1 (concat (if (>= h1 24) "+" " ")
6095 (if (and org-agenda-time-leading-zero
6096 (< t0 1000)) "0" "")
6097 (if (< t0 100) "0" "")
6098 (if (< t0 10) "0" "")
6099 (int-to-string t0))))
6100 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6102 (defvar org-agenda-before-sorting-filter-function nil
6103 "Function to be applied to agenda items prior to sorting.
6104 Prior to sorting also means just before they are inserted into the agenda.
6106 To aid sorting, you may revisit the original entries and add more text
6107 properties which will later be used by the sorting functions.
6109 The function should take a string argument, an agenda line.
6110 It has access to the text properties in that line, which contain among
6111 other things, the property `org-hd-marker' that points to the entry
6112 where the line comes from. Note that not all lines going into the agenda
6113 have this property, only most.
6115 The function should return the modified string. It is probably best
6116 to ONLY change text properties.
6118 You can also use this function as a filter, by returning nil for lines
6119 you don't want to have in the agenda at all. For this application, you
6120 could bind the variable in the options section of a custom command.")
6122 (defun org-finalize-agenda-entries (list &optional nosort)
6123 "Sort and concatenate the agenda items."
6124 (setq list (mapcar 'org-agenda-highlight-todo list))
6125 (if nosort
6126 list
6127 (when org-agenda-before-sorting-filter-function
6128 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6129 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6131 (defun org-agenda-highlight-todo (x)
6132 (let ((org-done-keywords org-done-keywords-for-agenda)
6133 (case-fold-search nil)
6135 (if (eq x 'line)
6136 (save-excursion
6137 (beginning-of-line 1)
6138 (setq re (org-get-at-bol 'org-todo-regexp))
6139 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6140 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6141 (add-text-properties (match-beginning 0) (match-end 1)
6142 (list 'face (org-get-todo-face 1)))
6143 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6144 (delete-region (match-beginning 1) (1- (match-end 0)))
6145 (goto-char (match-beginning 1))
6146 (insert (format org-agenda-todo-keyword-format s)))))
6147 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6148 (setq re (get-text-property 0 'org-todo-regexp x))
6149 (when (and re
6150 ;; Test `pl' because if there's no heading content,
6151 ;; there's no point matching to highlight. Note
6152 ;; that if we didn't test `pl' first, and there
6153 ;; happened to be no keyword from `org-todo-regexp'
6154 ;; on this heading line, then the `equal' comparison
6155 ;; afterwards would spuriously succeed in the case
6156 ;; where `pl' is nil -- causing an args-out-of-range
6157 ;; error when we try to add text properties to text
6158 ;; that isn't there.
6160 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6161 x pl) pl))
6162 (add-text-properties
6163 (or (match-end 1) (match-end 0)) (match-end 0)
6164 (list 'face (org-get-todo-face (match-string 2 x)))
6166 (when (match-end 1)
6167 (setq x (concat (substring x 0 (match-end 1))
6168 (format org-agenda-todo-keyword-format
6169 (match-string 2 x))
6170 (org-add-props " " (text-properties-at 0 x))
6171 (substring x (match-end 3)))))))
6172 x)))
6174 (defsubst org-cmp-priority (a b)
6175 "Compare the priorities of string A and B."
6176 (let ((pa (or (get-text-property 1 'priority a) 0))
6177 (pb (or (get-text-property 1 'priority b) 0)))
6178 (cond ((> pa pb) +1)
6179 ((< pa pb) -1)
6180 (t nil))))
6182 (defsubst org-cmp-effort (a b)
6183 "Compare the effort values of string A and B."
6184 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6185 (ea (or (get-text-property 1 'effort-minutes a) def))
6186 (eb (or (get-text-property 1 'effort-minutes b) def)))
6187 (cond ((> ea eb) +1)
6188 ((< ea eb) -1)
6189 (t nil))))
6191 (defsubst org-cmp-category (a b)
6192 "Compare the string values of categories of strings A and B."
6193 (let ((ca (or (get-text-property 1 'org-category a) ""))
6194 (cb (or (get-text-property 1 'org-category b) "")))
6195 (cond ((string-lessp ca cb) -1)
6196 ((string-lessp cb ca) +1)
6197 (t nil))))
6199 (defsubst org-cmp-todo-state (a b)
6200 "Compare the todo states of strings A and B."
6201 (let* ((ma (or (get-text-property 1 'org-marker a)
6202 (get-text-property 1 'org-hd-marker a)))
6203 (mb (or (get-text-property 1 'org-marker b)
6204 (get-text-property 1 'org-hd-marker b)))
6205 (fa (and ma (marker-buffer ma)))
6206 (fb (and mb (marker-buffer mb)))
6207 (todo-kwds
6208 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6209 (and fb (with-current-buffer fb org-todo-keywords-1))))
6210 (ta (or (get-text-property 1 'todo-state a) ""))
6211 (tb (or (get-text-property 1 'todo-state b) ""))
6212 (la (- (length (member ta todo-kwds))))
6213 (lb (- (length (member tb todo-kwds))))
6214 (donepa (member ta org-done-keywords-for-agenda))
6215 (donepb (member tb org-done-keywords-for-agenda)))
6216 (cond ((and donepa (not donepb)) -1)
6217 ((and (not donepa) donepb) +1)
6218 ((< la lb) -1)
6219 ((< lb la) +1)
6220 (t nil))))
6222 (defsubst org-cmp-alpha (a b)
6223 "Compare the headlines, alphabetically."
6224 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6225 (plb (text-property-any 0 (length b) 'org-heading t b))
6226 (ta (and pla (substring a pla)))
6227 (tb (and plb (substring b plb))))
6228 (when pla
6229 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6230 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6231 (setq ta (substring ta (match-end 0))))
6232 (setq ta (downcase ta)))
6233 (when plb
6234 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6235 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6236 (setq tb (substring tb (match-end 0))))
6237 (setq tb (downcase tb)))
6238 (cond ((not ta) +1)
6239 ((not tb) -1)
6240 ((string-lessp ta tb) -1)
6241 ((string-lessp tb ta) +1)
6242 (t nil))))
6244 (defsubst org-cmp-tag (a b)
6245 "Compare the string values of the first tags of A and B."
6246 (let ((ta (car (last (get-text-property 1 'tags a))))
6247 (tb (car (last (get-text-property 1 'tags b)))))
6248 (cond ((not ta) +1)
6249 ((not tb) -1)
6250 ((string-lessp ta tb) -1)
6251 ((string-lessp tb ta) +1)
6252 (t nil))))
6254 (defsubst org-cmp-time (a b)
6255 "Compare the time-of-day values of strings A and B."
6256 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6257 (ta (or (get-text-property 1 'time-of-day a) def))
6258 (tb (or (get-text-property 1 'time-of-day b) def)))
6259 (cond ((< ta tb) -1)
6260 ((< tb ta) +1)
6261 (t nil))))
6263 (defsubst org-cmp-habit-p (a b)
6264 "Compare the todo states of strings A and B."
6265 (let ((ha (get-text-property 1 'org-habit-p a))
6266 (hb (get-text-property 1 'org-habit-p b)))
6267 (cond ((and ha (not hb)) -1)
6268 ((and (not ha) hb) +1)
6269 (t nil))))
6271 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6273 (defun org-entries-lessp (a b)
6274 "Predicate for sorting agenda entries."
6275 ;; The following variables will be used when the form is evaluated.
6276 ;; So even though the compiler complains, keep them.
6277 (let* ((ss org-agenda-sorting-strategy-selected)
6278 (time-up (and (org-em 'time-up 'time-down ss)
6279 (org-cmp-time a b)))
6280 (time-down (if time-up (- time-up) nil))
6281 (priority-up (and (org-em 'priority-up 'priority-down ss)
6282 (org-cmp-priority a b)))
6283 (priority-down (if priority-up (- priority-up) nil))
6284 (effort-up (and (org-em 'effort-up 'effort-down ss)
6285 (org-cmp-effort a b)))
6286 (effort-down (if effort-up (- effort-up) nil))
6287 (category-up (and (or (org-em 'category-up 'category-down ss)
6288 (memq 'category-keep ss))
6289 (org-cmp-category a b)))
6290 (category-down (if category-up (- category-up) nil))
6291 (category-keep (if category-up +1 nil))
6292 (tag-up (and (org-em 'tag-up 'tag-down ss)
6293 (org-cmp-tag a b)))
6294 (tag-down (if tag-up (- tag-up) nil))
6295 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6296 (org-cmp-todo-state a b)))
6297 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6298 (habit-up (and (org-em 'habit-up 'habit-down ss)
6299 (org-cmp-habit-p a b)))
6300 (habit-down (if habit-up (- habit-up) nil))
6301 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6302 (org-cmp-alpha a b)))
6303 (alpha-down (if alpha-up (- alpha-up) nil))
6304 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6305 user-defined-up user-defined-down)
6306 (if (and need-user-cmp org-agenda-cmp-user-defined
6307 (functionp org-agenda-cmp-user-defined))
6308 (setq user-defined-up
6309 (funcall org-agenda-cmp-user-defined a b)
6310 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6311 (cdr (assoc
6312 (eval (cons 'or org-agenda-sorting-strategy-selected))
6313 '((-1 . t) (1 . nil) (nil . nil))))))
6315 ;;; Agenda restriction lock
6317 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6318 "Overlay to mark the headline to which agenda commands are restricted.")
6319 (overlay-put org-agenda-restriction-lock-overlay
6320 'face 'org-agenda-restriction-lock)
6321 (overlay-put org-agenda-restriction-lock-overlay
6322 'help-echo "Agendas are currently limited to this subtree.")
6323 (org-detach-overlay org-agenda-restriction-lock-overlay)
6325 (defun org-agenda-set-restriction-lock (&optional type)
6326 "Set restriction lock for agenda, to current subtree or file.
6327 Restriction will be the file if TYPE is `file', or if type is the
6328 universal prefix '(4), or if the cursor is before the first headline
6329 in the file. Otherwise, restriction will be to the current subtree."
6330 (interactive "P")
6331 (and (equal type '(4)) (setq type 'file))
6332 (setq type (cond
6333 (type type)
6334 ((org-at-heading-p) 'subtree)
6335 ((condition-case nil (org-back-to-heading t) (error nil))
6336 'subtree)
6337 (t 'file)))
6338 (if (eq type 'subtree)
6339 (progn
6340 (setq org-agenda-restrict t)
6341 (setq org-agenda-overriding-restriction 'subtree)
6342 (put 'org-agenda-files 'org-restrict
6343 (list (buffer-file-name (buffer-base-buffer))))
6344 (org-back-to-heading t)
6345 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6346 (move-marker org-agenda-restrict-begin (point))
6347 (move-marker org-agenda-restrict-end
6348 (save-excursion (org-end-of-subtree t)))
6349 (message "Locking agenda restriction to subtree"))
6350 (put 'org-agenda-files 'org-restrict
6351 (list (buffer-file-name (buffer-base-buffer))))
6352 (setq org-agenda-restrict nil)
6353 (setq org-agenda-overriding-restriction 'file)
6354 (move-marker org-agenda-restrict-begin nil)
6355 (move-marker org-agenda-restrict-end nil)
6356 (message "Locking agenda restriction to file"))
6357 (setq current-prefix-arg nil)
6358 (org-agenda-maybe-redo))
6360 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6361 "Remove the agenda restriction lock."
6362 (interactive "P")
6363 (org-detach-overlay org-agenda-restriction-lock-overlay)
6364 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6365 (setq org-agenda-overriding-restriction nil)
6366 (setq org-agenda-restrict nil)
6367 (put 'org-agenda-files 'org-restrict nil)
6368 (move-marker org-agenda-restrict-begin nil)
6369 (move-marker org-agenda-restrict-end nil)
6370 (setq current-prefix-arg nil)
6371 (message "Agenda restriction lock removed")
6372 (or noupdate (org-agenda-maybe-redo)))
6374 (defun org-agenda-maybe-redo ()
6375 "If there is any window showing the agenda view, update it."
6376 (let ((w (get-buffer-window org-agenda-buffer-name t))
6377 (w0 (selected-window)))
6378 (when w
6379 (select-window w)
6380 (org-agenda-redo)
6381 (select-window w0)
6382 (if org-agenda-overriding-restriction
6383 (message "Agenda view shifted to new %s restriction"
6384 org-agenda-overriding-restriction)
6385 (message "Agenda restriction lock removed")))))
6387 ;;; Agenda commands
6389 (defun org-agenda-check-type (error &rest types)
6390 "Check if agenda buffer is of allowed type.
6391 If ERROR is non-nil, throw an error, otherwise just return nil."
6392 (if (not org-agenda-type)
6393 (error "No Org agenda currently displayed")
6394 (if (memq org-agenda-type types)
6396 (if error
6397 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6398 nil))))
6400 (defun org-agenda-Quit (&optional arg)
6401 "Exit agenda by removing the window or the buffer."
6402 (interactive)
6403 (if org-agenda-columns-active
6404 (org-columns-quit)
6405 (let ((buf (current-buffer)))
6406 (if (eq org-agenda-window-setup 'other-frame)
6407 (progn
6408 (org-agenda-reset-markers)
6409 (kill-buffer buf)
6410 (org-columns-remove-overlays)
6411 (setq org-agenda-archives-mode nil)
6412 (delete-frame))
6413 (and (not (eq org-agenda-window-setup 'current-window))
6414 (not (one-window-p))
6415 (delete-window))
6416 (org-agenda-reset-markers)
6417 (kill-buffer buf)
6418 (org-columns-remove-overlays)
6419 (setq org-agenda-archives-mode nil)))
6420 ;; Maybe restore the pre-agenda window configuration.
6421 (and org-agenda-restore-windows-after-quit
6422 (not (eq org-agenda-window-setup 'other-frame))
6423 org-pre-agenda-window-conf
6424 (set-window-configuration org-pre-agenda-window-conf))))
6426 (defun org-agenda-quit ()
6427 "Exit agenda by killing agenda buffer or burying it when
6428 `org-agenda-sticky' is non-NIL"
6429 (interactive)
6430 (if org-agenda-columns-active
6431 (org-columns-quit)
6432 (if org-agenda-sticky
6433 (let ((buf (current-buffer)))
6434 (if (eq org-agenda-window-setup 'other-frame)
6435 (progn
6436 (delete-frame))
6437 (and (not (eq org-agenda-window-setup 'current-window))
6438 (not (one-window-p))
6439 (delete-window)))
6440 (with-current-buffer buf
6441 (bury-buffer)
6442 ;; Maybe restore the pre-agenda window configuration.
6443 (and org-agenda-restore-windows-after-quit
6444 (not (eq org-agenda-window-setup 'other-frame))
6445 org-pre-agenda-window-conf
6446 (set-window-configuration org-pre-agenda-window-conf))))
6447 (org-agenda-Quit))))
6449 (defun org-agenda-exit ()
6450 "Exit agenda by removing the window or the buffer.
6451 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6452 Org-mode buffers visited directly by the user will not be touched."
6453 (interactive)
6454 (org-release-buffers org-agenda-new-buffers)
6455 (setq org-agenda-new-buffers nil)
6456 (org-agenda-Quit))
6458 (defun org-agenda-kill-all-agenda-buffers ()
6459 "Kill all buffers in `org-agena-mode'.
6460 This is used when toggling sticky agendas. You can also explicitly invoke it
6461 with `C-c a C-k'."
6462 (interactive)
6463 (let (blist)
6464 (dolist (buf (buffer-list))
6465 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6466 (push buf blist)))
6467 (mapc 'kill-buffer blist)))
6469 (defun org-agenda-execute (arg)
6470 "Execute another agenda command, keeping same window.
6471 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6472 in the agenda."
6473 (interactive "P")
6474 (let ((org-agenda-window-setup 'current-window))
6475 (org-agenda arg)))
6477 (defun org-agenda-redo ()
6478 "Rebuild Agenda.
6479 When this is the global TODO list, a prefix argument will be interpreted."
6480 (interactive)
6481 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6482 (org-agenda-sticky nil)
6483 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6484 org-agenda-buffer-name))
6485 (org-agenda-keep-modes t)
6486 (tag-filter org-agenda-tag-filter)
6487 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6488 (top-cat-filter org-agenda-top-category-filter)
6489 (cat-filter org-agenda-category-filter)
6490 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6491 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6492 (cols org-agenda-columns-active)
6493 (line (org-current-line))
6494 (window-line (- line (org-current-line (window-start))))
6495 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6496 (put 'org-agenda-tag-filter :preset-filter nil)
6497 (put 'org-agenda-category-filter :preset-filter nil)
6498 (and cols (org-columns-quit))
6499 (message "Rebuilding agenda buffer...")
6500 (org-let lprops '(eval org-agenda-redo-command))
6501 (setq org-agenda-undo-list nil
6502 org-agenda-pending-undo-list nil)
6503 (message "Rebuilding agenda buffer...done")
6504 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6505 (put 'org-agenda-category-filter :preset-filter cat-preset)
6506 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6507 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6508 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6509 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6510 (org-goto-line line)
6511 (recenter window-line)))
6513 (defvar org-global-tags-completion-table nil)
6514 (defvar org-agenda-filter-form nil)
6515 (defvar org-agenda-filtered-by-category nil)
6517 (defun org-agenda-filter-by-category (strip)
6518 "Keep only those lines in the agenda buffer that have a specific category.
6519 The category is that of the current line."
6520 (interactive "P")
6521 (if org-agenda-filtered-by-category
6522 (org-agenda-filter-show-all-cat)
6523 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6524 (if cat (org-agenda-filter-apply
6525 (list (concat (if strip "-" "+") cat)) 'category)
6526 (error "No category at point")))))
6528 (defun org-find-top-category (&optional pos)
6529 (save-excursion
6530 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6531 (if pos (goto-char pos))
6532 ;; Skip up to the topmost parent
6533 (while (ignore-errors (outline-up-heading 1) t))
6534 (ignore-errors
6535 (nth 4 (org-heading-components))))))
6537 (defvar org-agenda-filtered-by-top-category nil)
6539 (defun org-agenda-filter-by-top-category (strip)
6540 "Keep only those lines in the agenda buffer that have a specific category.
6541 The category is that of the current line."
6542 (interactive "P")
6543 (if org-agenda-filtered-by-top-category
6544 (progn
6545 (setq org-agenda-filtered-by-top-category nil
6546 org-agenda-top-category-filter nil)
6547 (org-agenda-filter-show-all-cat))
6548 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6549 (if cat (org-agenda-filter-top-category-apply cat strip)
6550 (error "No top-level category at point")))))
6552 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6553 "Keep only those lines in the agenda buffer that have a specific tag.
6554 The tag is selected with its fast selection letter, as configured.
6555 With prefix argument STRIP, remove all lines that do have the tag.
6556 A lisp caller can specify CHAR. NARROW means that the new tag should be
6557 used to narrow the search - the interactive user can also press `-' or `+'
6558 to switch to narrowing."
6559 (interactive "P")
6560 (let* ((alist org-tag-alist-for-agenda)
6561 (tag-chars (mapconcat
6562 (lambda (x) (if (and (not (symbolp (car x)))
6563 (cdr x))
6564 (char-to-string (cdr x))
6565 ""))
6566 alist ""))
6567 (efforts (org-split-string
6568 (or (cdr (assoc (concat org-effort-property "_ALL")
6569 org-global-properties))
6570 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6571 "")))
6572 (effort-op org-agenda-filter-effort-default-operator)
6573 (effort-prompt "")
6574 (inhibit-read-only t)
6575 (current org-agenda-tag-filter)
6576 maybe-refresh a n tag)
6577 (unless char
6578 (message
6579 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6580 (if narrow "Narrow" "Filter") tag-chars
6581 (if org-agenda-auto-exclude-function "[RET], " ""))
6582 (setq char (read-char-exclusive)))
6583 (when (member char '(?+ ?-))
6584 ;; Narrowing down
6585 (cond ((equal char ?-) (setq strip t narrow t))
6586 ((equal char ?+) (setq strip nil narrow t)))
6587 (message
6588 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6589 (setq char (read-char-exclusive)))
6590 (when (member char '(?< ?> ?= ??))
6591 ;; An effort operator
6592 (setq effort-op (char-to-string char))
6593 (setq alist nil) ; to make sure it will be interpreted as effort.
6594 (unless (equal char ??)
6595 (loop for i from 0 to 9 do
6596 (setq effort-prompt
6597 (concat
6598 effort-prompt " ["
6599 (if (= i 9) "0" (int-to-string (1+ i)))
6600 "]" (nth i efforts))))
6601 (message "Effort%s: %s " effort-op effort-prompt)
6602 (setq char (read-char-exclusive))
6603 (when (or (< char ?0) (> char ?9))
6604 (error "Need 1-9,0 to select effort"))))
6605 (when (equal char ?\t)
6606 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6607 (org-set-local 'org-global-tags-completion-table
6608 (org-global-tags-completion-table)))
6609 (let ((completion-ignore-case t))
6610 (setq tag (org-icompleting-read
6611 "Tag: " org-global-tags-completion-table))))
6612 (cond
6613 ((equal char ?\r)
6614 (org-agenda-filter-show-all-tag)
6615 (when org-agenda-auto-exclude-function
6616 (setq org-agenda-tag-filter '())
6617 (dolist (tag (org-agenda-get-represented-tags))
6618 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6619 (if modifier
6620 (push modifier org-agenda-tag-filter))))
6621 (if (not (null org-agenda-tag-filter))
6622 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6623 (setq maybe-refresh t))
6624 ((equal char ?/)
6625 (org-agenda-filter-show-all-tag)
6626 (when (get 'org-agenda-tag-filter :preset-filter)
6627 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6628 (setq maybe-refresh t))
6629 ((equal char ?. )
6630 (setq org-agenda-tag-filter
6631 (mapcar (lambda(tag) (concat "+" tag))
6632 (org-get-at-bol 'tags)))
6633 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6634 (setq maybe-refresh t))
6635 ((or (equal char ?\ )
6636 (setq a (rassoc char alist))
6637 (and (>= char ?0) (<= char ?9)
6638 (setq n (if (= char ?0) 9 (- char ?0 1))
6639 tag (concat effort-op (nth n efforts))
6640 a (cons tag nil)))
6641 (and (= char ??)
6642 (setq tag "?eff")
6643 a (cons tag nil))
6644 (and tag (setq a (cons tag nil))))
6645 (org-agenda-filter-show-all-tag)
6646 (setq tag (car a))
6647 (setq org-agenda-tag-filter
6648 (cons (concat (if strip "-" "+") tag)
6649 (if narrow current nil)))
6650 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6651 (setq maybe-refresh t))
6652 (t (error "Invalid tag selection character %c" char)))
6653 (when (and maybe-refresh
6654 (eq org-agenda-clockreport-mode 'with-filter))
6655 (org-agenda-redo))))
6657 (defun org-agenda-get-represented-tags ()
6658 "Get a list of all tags currently represented in the agenda."
6659 (let (p tags)
6660 (save-excursion
6661 (goto-char (point-min))
6662 (while (setq p (next-single-property-change (point) 'tags))
6663 (goto-char p)
6664 (mapc (lambda (x) (add-to-list 'tags x))
6665 (get-text-property (point) 'tags))))
6666 tags))
6668 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6669 "Refine the current filter. See `org-agenda-filter-by-tag'."
6670 (interactive "P")
6671 (org-agenda-filter-by-tag strip char 'refine))
6673 (defun org-agenda-filter-make-matcher ()
6674 "Create the form that tests a line for agenda filter."
6675 (let (f f1)
6676 ;; first compute the tag-filter matcher
6677 (dolist (x (delete-dups
6678 (append (get 'org-agenda-tag-filter
6679 :preset-filter) org-agenda-tag-filter)))
6680 (if (member x '("-" "+"))
6681 (setq f1 (if (equal x "-") 'tags '(not tags)))
6682 (if (string-match "[<=>?]" x)
6683 (setq f1 (org-agenda-filter-effort-form x))
6684 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6685 (if (equal (string-to-char x) ?-)
6686 (setq f1 (list 'not f1))))
6687 (push f1 f))
6688 ;; then compute the category-filter matcher
6689 (dolist (x (delete-dups
6690 (append (get 'org-agenda-category-filter
6691 :preset-filter) org-agenda-category-filter)))
6692 (if (equal "-" (substring x 0 1))
6693 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6694 (setq f1 (list 'equal (substring x 1) 'cat)))
6695 (push f1 f))
6696 (cons 'and (nreverse f))))
6698 (defun org-agenda-filter-effort-form (e)
6699 "Return the form to compare the effort of the current line with what E says.
6700 E looks like \"+<2:25\"."
6701 (let (op)
6702 (setq e (substring e 1))
6703 (setq op (string-to-char e) e (substring e 1))
6704 (setq op (cond ((equal op ?<) '<=)
6705 ((equal op ?>) '>=)
6706 ((equal op ??) op)
6707 (t '=)))
6708 (list 'org-agenda-compare-effort (list 'quote op)
6709 (org-duration-string-to-minutes e))))
6711 (defun org-agenda-compare-effort (op value)
6712 "Compare the effort of the current line with VALUE, using OP.
6713 If the line does not have an effort defined, return nil."
6714 (let ((eff (org-get-at-bol 'effort-minutes)))
6715 (if (equal op ??)
6716 (not eff)
6717 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6718 value))))
6720 (defun org-agenda-filter-apply (filter type)
6721 "Set FILTER as the new agenda filter and apply it."
6722 (let (tags cat)
6723 (if (eq type 'tag)
6724 (setq org-agenda-tag-filter filter)
6725 (setq org-agenda-category-filter filter))
6726 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6727 (if (and (eq type 'category)
6728 (not (equal (substring (car filter) 0 1) "-")))
6729 ;; Only set `org-agenda-filtered-by-category' to t
6730 ;; when a unique category is used as the filter
6731 (setq org-agenda-filtered-by-category t))
6732 (org-agenda-set-mode-name)
6733 (save-excursion
6734 (goto-char (point-min))
6735 (while (not (eobp))
6736 (if (org-get-at-bol 'org-marker)
6737 (progn
6738 (setq tags (org-get-at-bol 'tags) ; used in eval
6739 cat (get-text-property (point) 'org-category))
6740 (if (not (eval org-agenda-filter-form))
6741 (org-agenda-filter-hide-line type))
6742 (beginning-of-line 2))
6743 (beginning-of-line 2))))
6744 (if (get-char-property (point) 'invisible)
6745 (ignore-errors (org-agenda-previous-line)))))
6747 (defun org-agenda-filter-top-category-apply (category &optional negative)
6748 "Set FILTER as the new agenda filter and apply it."
6749 (org-agenda-set-mode-name)
6750 (save-excursion
6751 (goto-char (point-min))
6752 (while (not (eobp))
6753 (let* ((pos (org-get-at-bol 'org-hd-marker))
6754 (topcat (and pos (org-find-top-category pos))))
6755 (if (and topcat (funcall (if negative 'identity 'not)
6756 (string= category topcat)))
6757 (org-agenda-filter-hide-line 'category)))
6758 (beginning-of-line 2)))
6759 (if (get-char-property (point) 'invisible)
6760 (org-agenda-previous-line))
6761 (setq org-agenda-top-category-filter category
6762 org-agenda-filtered-by-top-category t))
6764 (defun org-agenda-filter-hide-line (type)
6765 (let (ov)
6766 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6767 (point-at-eol)))
6768 (overlay-put ov 'invisible t)
6769 (overlay-put ov 'type type)
6770 (if (eq type 'tag)
6771 (push ov org-agenda-tag-filter-overlays)
6772 (push ov org-agenda-cat-filter-overlays))))
6774 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6775 (setq pos (or pos (point)))
6776 (save-excursion
6777 (dolist (ov (overlays-at pos))
6778 (when (and (overlay-get ov 'invisible)
6779 (eq (overlay-get ov 'type) 'tag))
6780 (goto-char pos)
6781 (if (< (overlay-start ov) (point-at-eol))
6782 (move-overlay ov (point-at-eol)
6783 (overlay-end ov)))))))
6785 (defun org-agenda-filter-show-all-tag nil
6786 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6787 (setq org-agenda-tag-filter-overlays nil
6788 org-agenda-tag-filter nil
6789 org-agenda-filter-form nil)
6790 (org-agenda-set-mode-name))
6792 (defun org-agenda-filter-show-all-cat nil
6793 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6794 (setq org-agenda-cat-filter-overlays nil
6795 org-agenda-filtered-by-category nil
6796 org-agenda-category-filter nil
6797 org-agenda-filter-form nil)
6798 (org-agenda-set-mode-name))
6800 (defun org-agenda-manipulate-query-add ()
6801 "Manipulate the query by adding a search term with positive selection.
6802 Positive selection means the term must be matched for selection of an entry."
6803 (interactive)
6804 (org-agenda-manipulate-query ?\[))
6805 (defun org-agenda-manipulate-query-subtract ()
6806 "Manipulate the query by adding a search term with negative selection.
6807 Negative selection means term must not be matched for selection of an entry."
6808 (interactive)
6809 (org-agenda-manipulate-query ?\]))
6810 (defun org-agenda-manipulate-query-add-re ()
6811 "Manipulate the query by adding a search regexp with positive selection.
6812 Positive selection means the regexp must match for selection of an entry."
6813 (interactive)
6814 (org-agenda-manipulate-query ?\{))
6815 (defun org-agenda-manipulate-query-subtract-re ()
6816 "Manipulate the query by adding a search regexp with negative selection.
6817 Negative selection means regexp must not match for selection of an entry."
6818 (interactive)
6819 (org-agenda-manipulate-query ?\}))
6820 (defun org-agenda-manipulate-query (char)
6821 (cond
6822 ((memq org-agenda-type '(timeline agenda))
6823 (let ((org-agenda-include-inactive-timestamps t))
6824 (org-agenda-redo))
6825 (message "Display now includes inactive timestamps as well"))
6826 ((eq org-agenda-type 'search)
6827 (org-add-to-string
6828 'org-agenda-query-string
6829 (if org-agenda-last-search-view-search-was-boolean
6830 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6831 (?\{ . " +{}") (?\} . " -{}"))))
6832 " "))
6833 (setq org-agenda-redo-command
6834 (list 'org-search-view
6835 org-todo-only
6836 org-agenda-query-string
6837 (+ (length org-agenda-query-string)
6838 (if (member char '(?\{ ?\})) 0 1))))
6839 (set-register org-agenda-query-register org-agenda-query-string)
6840 (org-agenda-redo))
6841 (t (error "Cannot manipulate query for %s-type agenda buffers"
6842 org-agenda-type))))
6844 (defun org-add-to-string (var string)
6845 (set var (concat (symbol-value var) string)))
6847 (defun org-agenda-goto-date (date)
6848 "Jump to DATE in agenda."
6849 (interactive (list (let ((org-read-date-prefer-future
6850 (eval org-agenda-jump-prefer-future)))
6851 (org-read-date))))
6852 (org-agenda-list nil date))
6854 (defun org-agenda-goto-today ()
6855 "Go to today."
6856 (interactive)
6857 (org-agenda-check-type t 'timeline 'agenda)
6858 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6859 (cond
6860 (tdpos (goto-char tdpos))
6861 ((eq org-agenda-type 'agenda)
6862 (let* ((sd (org-agenda-compute-starting-span
6863 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6864 (org-agenda-overriding-arguments org-agenda-last-arguments))
6865 (setf (nth 1 org-agenda-overriding-arguments) sd)
6866 (org-agenda-redo)
6867 (org-agenda-find-same-or-today-or-agenda)))
6868 (t (error "Cannot find today")))))
6870 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6871 (goto-char
6872 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6873 (text-property-any (point-min) (point-max) 'org-today t)
6874 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6875 (point-min))))
6877 (defun org-agenda-later (arg)
6878 "Go forward in time by thee current span.
6879 With prefix ARG, go forward that many times the current span."
6880 (interactive "p")
6881 (org-agenda-check-type t 'agenda)
6882 (let* ((span org-agenda-current-span)
6883 (sd org-starting-day)
6884 (greg (calendar-gregorian-from-absolute sd))
6885 (cnt (org-get-at-bol 'org-day-cnt))
6886 greg2)
6887 (cond
6888 ((eq span 'day)
6889 (setq sd (+ arg sd)))
6890 ((eq span 'week)
6891 (setq sd (+ (* 7 arg) sd)))
6892 ((eq span 'month)
6893 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6894 sd (calendar-absolute-from-gregorian greg2))
6895 (setcar greg2 (1+ (car greg2))))
6896 ((eq span 'year)
6897 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6898 sd (calendar-absolute-from-gregorian greg2))
6899 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6901 (setq sd (+ (* span arg) sd))))
6902 (let ((org-agenda-overriding-arguments
6903 (list (car org-agenda-last-arguments) sd span t)))
6904 (org-agenda-redo)
6905 (org-agenda-find-same-or-today-or-agenda cnt))))
6907 (defun org-agenda-earlier (arg)
6908 "Go backward in time by the current span.
6909 With prefix ARG, go backward that many times the current span."
6910 (interactive "p")
6911 (org-agenda-later (- arg)))
6913 (defun org-agenda-view-mode-dispatch ()
6914 "Call one of the view mode commands."
6915 (interactive)
6916 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6917 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6918 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
6919 (let ((a (read-char-exclusive)))
6920 (case a
6921 (?\ (call-interactively 'org-agenda-reset-view))
6922 (?d (call-interactively 'org-agenda-day-view))
6923 (?w (call-interactively 'org-agenda-week-view))
6924 (?m (call-interactively 'org-agenda-month-view))
6925 (?y (call-interactively 'org-agenda-year-view))
6926 (?l (call-interactively 'org-agenda-log-mode))
6927 (?L (org-agenda-log-mode '(4)))
6928 (?c (org-agenda-log-mode 'clockcheck))
6929 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6930 (?a (call-interactively 'org-agenda-archives-mode))
6931 (?A (org-agenda-archives-mode 'files))
6932 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6933 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6934 (?G (call-interactively 'org-agenda-toggle-time-grid))
6935 (?D (call-interactively 'org-agenda-toggle-diary))
6936 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6937 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6938 (org-agenda-check-type t 'timeline 'agenda)
6939 (org-agenda-redo))
6940 (message "Display now includes inactive timestamps as well"))
6941 (?q (message "Abort"))
6942 (otherwise (error "Invalid key" )))))
6944 (defun org-agenda-reset-view ()
6945 "Switch to default view for agenda."
6946 (interactive)
6947 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6948 (defun org-agenda-day-view (&optional day-of-year)
6949 "Switch to daily view for agenda.
6950 With argument DAY-OF-YEAR, switch to that day of the year."
6951 (interactive "P")
6952 (org-agenda-change-time-span 'day day-of-year))
6953 (defun org-agenda-week-view (&optional iso-week)
6954 "Switch to daily view for agenda.
6955 With argument ISO-WEEK, switch to the corresponding ISO week.
6956 If ISO-WEEK has more then 2 digits, only the last two encode the
6957 week. Any digits before this encode a year. So 200712 means
6958 week 12 of year 2007. Years in the range 1938-2037 can also be
6959 written as 2-digit years."
6960 (interactive "P")
6961 (org-agenda-change-time-span 'week iso-week))
6962 (defun org-agenda-month-view (&optional month)
6963 "Switch to monthly view for agenda.
6964 With argument MONTH, switch to that month."
6965 (interactive "P")
6966 (org-agenda-change-time-span 'month month))
6967 (defun org-agenda-year-view (&optional year)
6968 "Switch to yearly view for agenda.
6969 With argument YEAR, switch to that year.
6970 If MONTH has more then 2 digits, only the last two encode the
6971 month. Any digits before this encode a year. So 200712 means
6972 December year 2007. Years in the range 1938-2037 can also be
6973 written as 2-digit years."
6974 (interactive "P")
6975 (when year
6976 (setq year (org-small-year-to-year year)))
6977 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6978 (org-agenda-change-time-span 'year year)
6979 (error "Abort")))
6981 (defun org-agenda-change-time-span (span &optional n)
6982 "Change the agenda view to SPAN.
6983 SPAN may be `day', `week', `month', `year'."
6984 (org-agenda-check-type t 'agenda)
6985 (if (and (not n) (equal org-agenda-current-span span))
6986 (error "Viewing span is already \"%s\"" span))
6987 (let* ((sd (or (org-get-at-bol 'day)
6988 org-starting-day))
6989 (sd (org-agenda-compute-starting-span sd span n))
6990 (org-agenda-overriding-arguments
6991 (or org-agenda-overriding-arguments
6992 (list (car org-agenda-last-arguments) sd span t))))
6993 (org-agenda-redo)
6994 (org-agenda-find-same-or-today-or-agenda))
6995 (org-agenda-set-mode-name)
6996 (message "Switched to %s view" span))
6998 (defun org-agenda-compute-starting-span (sd span &optional n)
6999 "Compute starting date for agenda.
7000 SPAN may be `day', `week', `month', `year'. The return value
7001 is a cons cell with the starting date and the number of days,
7002 so that the date SD will be in that range."
7003 (let* ((greg (calendar-gregorian-from-absolute sd))
7004 (dg (nth 1 greg))
7005 (mg (car greg))
7006 (yg (nth 2 greg)))
7007 (cond
7008 ((eq span 'day)
7009 (when n
7010 (setq sd (+ (calendar-absolute-from-gregorian
7011 (list mg 1 yg))
7012 n -1))))
7013 ((eq span 'week)
7014 (let* ((nt (calendar-day-of-week
7015 (calendar-gregorian-from-absolute sd)))
7016 (d (if org-agenda-start-on-weekday
7017 (- nt org-agenda-start-on-weekday)
7020 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7021 (when n
7022 (require 'cal-iso)
7023 (when (> n 99)
7024 (setq y1 (org-small-year-to-year (/ n 100))
7025 n (mod n 100)))
7026 (setq sd
7027 (calendar-absolute-from-iso
7028 (list n 1
7029 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7030 ((eq span 'month)
7031 (let (y1)
7032 (when (and n (> n 99))
7033 (setq y1 (org-small-year-to-year (/ n 100))
7034 n (mod n 100)))
7035 (setq sd (calendar-absolute-from-gregorian
7036 (list (or n mg) 1 (or y1 yg))))))
7037 ((eq span 'year)
7038 (setq sd (calendar-absolute-from-gregorian
7039 (list 1 1 (or n yg))))))
7040 sd))
7042 (defun org-agenda-next-date-line (&optional arg)
7043 "Jump to the next line indicating a date in agenda buffer."
7044 (interactive "p")
7045 (org-agenda-check-type t 'agenda 'timeline)
7046 (beginning-of-line 1)
7047 ;; This does not work if user makes date format that starts with a blank
7048 (if (looking-at "^\\S-") (forward-char 1))
7049 (if (not (re-search-forward "^\\S-" nil t arg))
7050 (progn
7051 (backward-char 1)
7052 (error "No next date after this line in this buffer")))
7053 (goto-char (match-beginning 0)))
7055 (defun org-agenda-previous-date-line (&optional arg)
7056 "Jump to the previous line indicating a date in agenda buffer."
7057 (interactive "p")
7058 (org-agenda-check-type t 'agenda 'timeline)
7059 (beginning-of-line 1)
7060 (if (not (re-search-backward "^\\S-" nil t arg))
7061 (error "No previous date before this line in this buffer")))
7063 ;; Initialize the highlight
7064 (defvar org-hl (make-overlay 1 1))
7065 (overlay-put org-hl 'face 'highlight)
7067 (defun org-highlight (begin end &optional buffer)
7068 "Highlight a region with overlay."
7069 (move-overlay org-hl begin end (or buffer (current-buffer))))
7071 (defun org-unhighlight ()
7072 "Detach overlay INDEX."
7073 (org-detach-overlay org-hl))
7075 ;; FIXME this is currently not used.
7076 (defun org-highlight-until-next-command (beg end &optional buffer)
7077 "Move the highlight overlay to BEG/END, remove it before the next command."
7078 (org-highlight beg end buffer)
7079 (add-hook 'pre-command-hook 'org-unhighlight-once))
7080 (defun org-unhighlight-once ()
7081 "Remove the highlight from its position, and this function from the hook."
7082 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7083 (org-unhighlight))
7085 (defun org-agenda-follow-mode ()
7086 "Toggle follow mode in an agenda buffer."
7087 (interactive)
7088 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7089 (org-agenda-set-mode-name)
7090 (org-agenda-do-context-action)
7091 (message "Follow mode is %s"
7092 (if org-agenda-follow-mode "on" "off")))
7094 (defun org-agenda-entry-text-mode (&optional arg)
7095 "Toggle entry text mode in an agenda buffer."
7096 (interactive "P")
7097 (setq org-agenda-entry-text-mode (or (integerp arg)
7098 (not org-agenda-entry-text-mode)))
7099 (org-agenda-entry-text-hide)
7100 (and org-agenda-entry-text-mode
7101 (let ((org-agenda-entry-text-maxlines
7102 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7103 (org-agenda-entry-text-show)))
7104 (org-agenda-set-mode-name)
7105 (message "Entry text mode is %s. Maximum number of lines is %d"
7106 (if org-agenda-entry-text-mode "on" "off")
7107 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7109 (defun org-agenda-clockreport-mode (&optional with-filter)
7110 "Toggle clocktable mode in an agenda buffer.
7111 With prefix arg WITH-FILTER, make the clocktable respect the current
7112 agenda filter."
7113 (interactive "P")
7114 (org-agenda-check-type t 'agenda)
7115 (if with-filter
7116 (setq org-agenda-clockreport-mode 'with-filter)
7117 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7118 (org-agenda-set-mode-name)
7119 (org-agenda-redo)
7120 (message "Clocktable mode is %s"
7121 (if org-agenda-clockreport-mode "on" "off")))
7123 (defun org-agenda-log-mode (&optional special)
7124 "Toggle log mode in an agenda buffer.
7125 With argument SPECIAL, show all possible log items, not only the ones
7126 configured in `org-agenda-log-mode-items'.
7127 With a double `C-u' prefix arg, show *only* log items, nothing else."
7128 (interactive "P")
7129 (org-agenda-check-type t 'agenda 'timeline)
7130 (setq org-agenda-show-log
7131 (cond
7132 ((equal special '(16)) 'only)
7133 ((eq special 'clockcheck)
7134 (if (eq org-agenda-show-log 'clockcheck)
7135 nil 'clockcheck))
7136 (special '(closed clock state))
7137 (t (not org-agenda-show-log))))
7138 (org-agenda-set-mode-name)
7139 (org-agenda-redo)
7140 (message "Log mode is %s"
7141 (if org-agenda-show-log "on" "off")))
7143 (defun org-agenda-archives-mode (&optional with-files)
7144 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7145 When called with a prefix argument, include all archive files as well."
7146 (interactive "P")
7147 (setq org-agenda-archives-mode
7148 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7149 (org-agenda-set-mode-name)
7150 (org-agenda-redo)
7151 (message
7152 "%s"
7153 (cond
7154 ((eq org-agenda-archives-mode nil)
7155 "No archives are included")
7156 ((eq org-agenda-archives-mode 'trees)
7157 (format "Trees with :%s: tag are included" org-archive-tag))
7158 ((eq org-agenda-archives-mode t)
7159 (format "Trees with :%s: tag and all active archive files are included"
7160 org-archive-tag)))))
7162 (defun org-agenda-toggle-diary ()
7163 "Toggle diary inclusion in an agenda buffer."
7164 (interactive)
7165 (org-agenda-check-type t 'agenda)
7166 (setq org-agenda-include-diary (not org-agenda-include-diary))
7167 (org-agenda-redo)
7168 (org-agenda-set-mode-name)
7169 (message "Diary inclusion turned %s"
7170 (if org-agenda-include-diary "on" "off")))
7172 (defun org-agenda-toggle-deadlines ()
7173 "Toggle inclusion of entries with a deadline in an agenda buffer."
7174 (interactive)
7175 (org-agenda-check-type t 'agenda)
7176 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7177 (org-agenda-redo)
7178 (org-agenda-set-mode-name)
7179 (message "Deadlines inclusion turned %s"
7180 (if org-agenda-include-deadlines "on" "off")))
7182 (defun org-agenda-toggle-time-grid ()
7183 "Toggle time grid in an agenda buffer."
7184 (interactive)
7185 (org-agenda-check-type t 'agenda)
7186 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7187 (org-agenda-redo)
7188 (org-agenda-set-mode-name)
7189 (message "Time-grid turned %s"
7190 (if org-agenda-use-time-grid "on" "off")))
7192 (defun org-agenda-set-mode-name ()
7193 "Set the mode name to indicate all the small mode settings."
7194 (setq mode-name
7195 (list "Org-Agenda"
7196 (if (get 'org-agenda-files 'org-restrict) " []" "")
7198 '(:eval (org-agenda-span-name org-agenda-current-span))
7199 (if org-agenda-follow-mode " Follow" "")
7200 (if org-agenda-entry-text-mode " ETxt" "")
7201 (if org-agenda-include-diary " Diary" "")
7202 (if org-agenda-include-deadlines " Ddl" "")
7203 (if org-agenda-use-time-grid " Grid" "")
7204 (if (and (boundp 'org-habit-show-habits)
7205 org-habit-show-habits) " Habit" "")
7206 (cond
7207 ((consp org-agenda-show-log) " LogAll")
7208 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7209 (org-agenda-show-log " Log")
7210 (t ""))
7211 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7212 :preset-filter))
7213 '(:eval (org-propertize
7214 (concat " <"
7215 (mapconcat
7216 'identity
7217 (append
7218 (get 'org-agenda-category-filter :preset-filter)
7219 org-agenda-category-filter)
7221 ">")
7222 'face 'org-agenda-filter-category
7223 'help-echo "Category used in filtering"))
7225 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7226 :preset-filter))
7227 '(:eval (org-propertize
7228 (concat " {"
7229 (mapconcat
7230 'identity
7231 (append
7232 (get 'org-agenda-tag-filter :preset-filter)
7233 org-agenda-tag-filter)
7235 "}")
7236 'face 'org-agenda-filter-tags
7237 'help-echo "Tags used in filtering"))
7239 (if org-agenda-archives-mode
7240 (if (eq org-agenda-archives-mode t)
7241 " Archives"
7242 (format " :%s:" org-archive-tag))
7244 (if org-agenda-clockreport-mode
7245 (if (eq org-agenda-clockreport-mode 'with-filter)
7246 " Clock{}" " Clock")
7247 "")))
7248 (force-mode-line-update))
7250 (defun org-agenda-post-command-hook ()
7251 (setq org-agenda-type
7252 (or (get-text-property (point) 'org-agenda-type)
7253 (get-text-property (max (point-min) (1- (point)))
7254 'org-agenda-type))))
7256 (defun org-agenda-next-line ()
7257 "Move cursor to the next line, and show if follow mode is active."
7258 (interactive)
7259 (call-interactively 'next-line)
7260 (org-agenda-do-context-action))
7262 (defun org-agenda-previous-line ()
7263 "Move cursor to the previous line, and show if follow-mode is active."
7264 (interactive)
7265 (call-interactively 'previous-line)
7266 (org-agenda-do-context-action))
7268 (defun org-agenda-next-item (n)
7269 "Move cursor to next agenda item."
7270 (interactive "p")
7271 (let ((col (current-column)))
7272 (dotimes (c n)
7273 (when (next-single-property-change (point-at-eol) 'org-marker)
7274 (move-end-of-line 1)
7275 (goto-char (next-single-property-change (point) 'org-marker))))
7276 (org-move-to-column col))
7277 (org-agenda-do-context-action))
7279 (defun org-agenda-previous-item (n)
7280 "Move cursor to next agenda item."
7281 (interactive "p")
7282 (dotimes (c n)
7283 (let ((col (current-column))
7284 (goto (save-excursion
7285 (move-end-of-line 0)
7286 (previous-single-property-change (point) 'org-marker))))
7287 (if goto (goto-char goto))
7288 (org-move-to-column col)))
7289 (org-agenda-do-context-action))
7291 (defun org-agenda-do-context-action ()
7292 "Show outline path and, maybe, follow mode window."
7293 (let ((m (org-get-at-bol 'org-marker)))
7294 (when (and (markerp m) (marker-buffer m))
7295 (and org-agenda-follow-mode
7296 (if org-agenda-follow-indirect
7297 (org-agenda-tree-to-indirect-buffer)
7298 (org-agenda-show)))
7299 (and org-agenda-show-outline-path
7300 (org-with-point-at m (org-display-outline-path t))))))
7302 (defun org-agenda-show-priority ()
7303 "Show the priority of the current item.
7304 This priority is composed of the main priority given with the [#A] cookies,
7305 and by additional input from the age of a schedules or deadline entry."
7306 (interactive)
7307 (let* ((pri (org-get-at-bol 'priority)))
7308 (message "Priority is %d" (if pri pri -1000))))
7310 (defun org-agenda-show-tags ()
7311 "Show the tags applicable to the current item."
7312 (interactive)
7313 (let* ((tags (org-get-at-bol 'tags)))
7314 (if tags
7315 (message "Tags are :%s:"
7316 (org-no-properties (mapconcat 'identity tags ":")))
7317 (message "No tags associated with this line"))))
7319 (defun org-agenda-goto (&optional highlight)
7320 "Go to the Org-mode file which contains the item at point."
7321 (interactive)
7322 (let* ((marker (or (org-get-at-bol 'org-marker)
7323 (org-agenda-error)))
7324 (buffer (marker-buffer marker))
7325 (pos (marker-position marker)))
7326 (switch-to-buffer-other-window buffer)
7327 (widen)
7328 (push-mark)
7329 (goto-char pos)
7330 (when (derived-mode-p 'org-mode)
7331 (org-show-context 'agenda)
7332 (save-excursion
7333 (and (outline-next-heading)
7334 (org-flag-heading nil)))) ; show the next heading
7335 (when (outline-invisible-p)
7336 (show-entry)) ; display invisible text
7337 (recenter (/ (window-height) 2))
7338 (run-hooks 'org-agenda-after-show-hook)
7339 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7341 (defvar org-agenda-after-show-hook nil
7342 "Normal hook run after an item has been shown from the agenda.
7343 Point is in the buffer where the item originated.")
7345 (defun org-agenda-kill ()
7346 "Kill the entry or subtree belonging to the current agenda entry."
7347 (interactive)
7348 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7349 (let* ((marker (or (org-get-at-bol 'org-marker)
7350 (org-agenda-error)))
7351 (buffer (marker-buffer marker))
7352 (pos (marker-position marker))
7353 (type (org-get-at-bol 'type))
7354 dbeg dend (n 0) conf)
7355 (org-with-remote-undo buffer
7356 (with-current-buffer buffer
7357 (save-excursion
7358 (goto-char pos)
7359 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7360 (setq dbeg (progn (org-back-to-heading t) (point))
7361 dend (org-end-of-subtree t t))
7362 (setq dbeg (point-at-bol)
7363 dend (min (point-max) (1+ (point-at-eol)))))
7364 (goto-char dbeg)
7365 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7366 (setq conf (or (eq t org-agenda-confirm-kill)
7367 (and (numberp org-agenda-confirm-kill)
7368 (> n org-agenda-confirm-kill))))
7369 (and conf
7370 (not (y-or-n-p
7371 (format "Delete entry with %d lines in buffer \"%s\"? "
7372 n (buffer-name buffer))))
7373 (error "Abort"))
7374 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7375 (with-current-buffer buffer (delete-region dbeg dend))
7376 (message "Agenda item and source killed"))))
7378 (defvar org-archive-default-command)
7379 (defun org-agenda-archive-default ()
7380 "Archive the entry or subtree belonging to the current agenda entry."
7381 (interactive)
7382 (require 'org-archive)
7383 (org-agenda-archive-with org-archive-default-command))
7385 (defun org-agenda-archive-default-with-confirmation ()
7386 "Archive the entry or subtree belonging to the current agenda entry."
7387 (interactive)
7388 (require 'org-archive)
7389 (org-agenda-archive-with org-archive-default-command 'confirm))
7391 (defun org-agenda-archive ()
7392 "Archive the entry or subtree belonging to the current agenda entry."
7393 (interactive)
7394 (org-agenda-archive-with 'org-archive-subtree))
7396 (defun org-agenda-archive-to-archive-sibling ()
7397 "Move the entry to the archive sibling."
7398 (interactive)
7399 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7401 (defun org-agenda-archive-with (cmd &optional confirm)
7402 "Move the entry to the archive sibling."
7403 (interactive)
7404 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7405 (let* ((marker (or (org-get-at-bol 'org-marker)
7406 (org-agenda-error)))
7407 (buffer (marker-buffer marker))
7408 (pos (marker-position marker)))
7409 (org-with-remote-undo buffer
7410 (with-current-buffer buffer
7411 (if (derived-mode-p 'org-mode)
7412 (if (and confirm
7413 (not (y-or-n-p "Archive this subtree or entry? ")))
7414 (error "Abort")
7415 (save-excursion
7416 (goto-char pos)
7417 (org-remove-subtree-entries-from-agenda)
7418 (org-back-to-heading t)
7419 (funcall cmd)))
7420 (error "Archiving works only in Org-mode files"))))))
7422 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7423 "Remove all lines in the agenda that correspond to a given subtree.
7424 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7425 If this information is not given, the function uses the tree at point."
7426 (let ((buf (or buf (current-buffer))) m p)
7427 (save-excursion
7428 (unless (and beg end)
7429 (org-back-to-heading t)
7430 (setq beg (point))
7431 (org-end-of-subtree t)
7432 (setq end (point)))
7433 (set-buffer (get-buffer org-agenda-buffer-name))
7434 (save-excursion
7435 (goto-char (point-max))
7436 (beginning-of-line 1)
7437 (while (not (bobp))
7438 (when (and (setq m (org-get-at-bol 'org-marker))
7439 (equal buf (marker-buffer m))
7440 (setq p (marker-position m))
7441 (>= p beg)
7442 (< p end))
7443 (let ((inhibit-read-only t))
7444 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7445 (beginning-of-line 0))))))
7447 (defun org-agenda-refile (&optional goto rfloc no-update)
7448 "Refile the item at point."
7449 (interactive "P")
7450 (if (equal goto '(16))
7451 (org-refile-goto-last-stored)
7452 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7453 (org-agenda-error)))
7454 (buffer (marker-buffer marker))
7455 (pos (marker-position marker))
7456 (rfloc (or rfloc
7457 (org-refile-get-location
7458 (if goto "Goto" "Refile to") buffer
7459 org-refile-allow-creating-parent-nodes))))
7460 (with-current-buffer buffer
7461 (save-excursion
7462 (save-restriction
7463 (widen)
7464 (goto-char marker)
7465 (org-remove-subtree-entries-from-agenda)
7466 (org-refile goto buffer rfloc)))))
7467 (unless no-update (org-agenda-redo))))
7469 (defun org-agenda-open-link (&optional arg)
7470 "Follow the link in the current line, if any.
7471 This looks for a link in the displayed line in the agenda. It also looks
7472 at the text of the entry itself."
7473 (interactive "P")
7474 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7475 (org-get-at-bol 'org-marker)))
7476 (buffer (and marker (marker-buffer marker)))
7477 (prefix (buffer-substring
7478 (point-at-bol) (point-at-eol))))
7479 (cond
7480 (buffer
7481 (with-current-buffer buffer
7482 (save-excursion
7483 (save-restriction
7484 (widen)
7485 (goto-char marker)
7486 (org-offer-links-in-entry arg prefix)))))
7487 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7488 (save-excursion
7489 (beginning-of-line 1)
7490 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7491 (org-open-link-from-string (match-string 1)))
7492 (t (error "No link to open here")))))
7494 (defun org-agenda-copy-local-variable (var)
7495 "Get a variable from a referenced buffer and install it here."
7496 (let ((m (org-get-at-bol 'org-marker)))
7497 (when (and m (buffer-live-p (marker-buffer m)))
7498 (org-set-local var (with-current-buffer (marker-buffer m)
7499 (symbol-value var))))))
7501 (defun org-agenda-switch-to (&optional delete-other-windows)
7502 "Go to the Org-mode file which contains the item at point."
7503 (interactive)
7504 (if (and org-return-follows-link
7505 (not (org-get-at-bol 'org-marker))
7506 (org-in-regexp org-bracket-link-regexp))
7507 (org-open-link-from-string (match-string 0))
7508 (let* ((marker (or (org-get-at-bol 'org-marker)
7509 (org-agenda-error)))
7510 (buffer (marker-buffer marker))
7511 (pos (marker-position marker)))
7512 (org-pop-to-buffer-same-window buffer)
7513 (and delete-other-windows (delete-other-windows))
7514 (widen)
7515 (goto-char pos)
7516 (when (derived-mode-p 'org-mode)
7517 (org-show-context 'agenda)
7518 (save-excursion
7519 (and (outline-next-heading)
7520 (org-flag-heading nil))) ; show the next heading
7521 (when (outline-invisible-p)
7522 (show-entry)) ; display invisible text
7523 (run-hooks 'org-agenda-after-show-hook)))))
7525 (defun org-agenda-goto-mouse (ev)
7526 "Go to the Org-mode file which contains the item at the mouse click."
7527 (interactive "e")
7528 (mouse-set-point ev)
7529 (org-agenda-goto))
7531 (defun org-agenda-show (&optional full-entry)
7532 "Display the Org-mode file which contains the item at point.
7533 With prefix argument FULL-ENTRY, make the entire entry visible
7534 if it was hidden in the outline."
7535 (interactive "P")
7536 (let ((win (selected-window)))
7537 (if full-entry
7538 (let ((org-show-entry-below t))
7539 (org-agenda-goto t))
7540 (org-agenda-goto t))
7541 (select-window win)))
7543 (defvar org-agenda-show-window nil)
7544 (defun org-agenda-show-and-scroll-up (&optional arg)
7545 "Display the Org-mode file which contains the item at point.
7546 When called repeatedly, scroll the window that is displaying the buffer.
7547 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7548 `show-subtree' to display the item, so that drawers and logbooks stay
7549 folded."
7550 (interactive "P")
7551 (let ((win (selected-window)))
7552 (if (and (window-live-p org-agenda-show-window)
7553 (eq this-command last-command))
7554 (progn
7555 (select-window org-agenda-show-window)
7556 (ignore-errors (scroll-up)))
7557 (org-agenda-goto t)
7558 (if arg (org-show-entry) (show-subtree))
7559 (setq org-agenda-show-window (selected-window)))
7560 (select-window win)))
7562 (defun org-agenda-show-scroll-down ()
7563 "Scroll down the window showing the agenda."
7564 (interactive)
7565 (let ((win (selected-window)))
7566 (when (window-live-p org-agenda-show-window)
7567 (select-window org-agenda-show-window)
7568 (ignore-errors (scroll-down))
7569 (select-window win))))
7571 (defun org-agenda-show-1 (&optional more)
7572 "Display the Org-mode file which contains the item at point.
7573 The prefix arg selects the amount of information to display:
7575 0 hide the subtree
7576 1 just show the entry according to defaults.
7577 2 show the children view
7578 3 show the subtree view
7579 4 show the entire subtree and any LOGBOOK drawers
7580 5 show the entire subtree and any drawers
7581 With prefix argument FULL-ENTRY, make the entire entry visible
7582 if it was hidden in the outline."
7583 (interactive "p")
7584 (let ((win (selected-window)))
7585 (org-agenda-goto t)
7586 (org-recenter-heading 1)
7587 (cond
7588 ((= more 0)
7589 (hide-subtree)
7590 (save-excursion
7591 (org-back-to-heading)
7592 (run-hook-with-args 'org-cycle-hook 'folded))
7593 (message "Remote: FOLDED"))
7594 ((and (org-called-interactively-p 'any) (= more 1))
7595 (message "Remote: show with default settings"))
7596 ((= more 2)
7597 (show-entry)
7598 (show-children)
7599 (save-excursion
7600 (org-back-to-heading)
7601 (run-hook-with-args 'org-cycle-hook 'children))
7602 (message "Remote: CHILDREN"))
7603 ((= more 3)
7604 (show-subtree)
7605 (save-excursion
7606 (org-back-to-heading)
7607 (run-hook-with-args 'org-cycle-hook 'subtree))
7608 (message "Remote: SUBTREE"))
7609 ((= more 4)
7610 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7611 (org-drawer-regexp
7612 (concat "^[ \t]*:\\("
7613 (mapconcat 'regexp-quote org-drawers "\\|")
7614 "\\):[ \t]*$")))
7615 (show-subtree)
7616 (save-excursion
7617 (org-back-to-heading)
7618 (org-cycle-hide-drawers 'subtree)))
7619 (message "Remote: SUBTREE AND LOGBOOK"))
7620 ((> more 4)
7621 (show-subtree)
7622 (message "Remote: SUBTREE AND ALL DRAWERS")))
7623 (select-window win)))
7625 (defun org-recenter-heading (n)
7626 (save-excursion
7627 (org-back-to-heading)
7628 (recenter n)))
7630 (defvar org-agenda-cycle-counter nil)
7631 (defun org-agenda-cycle-show (&optional n)
7632 "Show the current entry in another window, with default settings.
7633 Default settings are taken from `org-show-hierarchy-above' and siblings.
7634 When use repeatedly in immediate succession, the remote entry will cycle
7635 through visibility
7637 children -> subtree -> folded
7639 When called with a numeric prefix arg, that arg will be passed through to
7640 `org-agenda-show-1'. For the interpretation of that argument, see the
7641 docstring of `org-agenda-show-1'."
7642 (interactive "P")
7643 (if (integerp n)
7644 (setq org-agenda-cycle-counter n)
7645 (if (not (eq last-command this-command))
7646 (setq org-agenda-cycle-counter 1)
7647 (if (equal org-agenda-cycle-counter 0)
7648 (setq org-agenda-cycle-counter 2)
7649 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7650 (if (> org-agenda-cycle-counter 3)
7651 (setq org-agenda-cycle-counter 0)))))
7652 (org-agenda-show-1 org-agenda-cycle-counter))
7654 (defun org-agenda-recenter (arg)
7655 "Display the Org-mode file which contains the item at point and recenter."
7656 (interactive "P")
7657 (let ((win (selected-window)))
7658 (org-agenda-goto t)
7659 (recenter arg)
7660 (select-window win)))
7662 (defun org-agenda-show-mouse (ev)
7663 "Display the Org-mode file which contains the item at the mouse click."
7664 (interactive "e")
7665 (mouse-set-point ev)
7666 (org-agenda-show))
7668 (defun org-agenda-check-no-diary ()
7669 "Check if the entry is a diary link and abort if yes."
7670 (if (org-get-at-bol 'org-agenda-diary-link)
7671 (org-agenda-error)))
7673 (defun org-agenda-error ()
7674 (error "Command not allowed in this line"))
7676 (defun org-agenda-tree-to-indirect-buffer ()
7677 "Show the subtree corresponding to the current entry in an indirect buffer.
7678 This calls the command `org-tree-to-indirect-buffer' from the original
7679 Org-mode buffer.
7680 With numerical prefix arg ARG, go up to this level and then take that tree.
7681 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7682 use the dedicated frame)."
7683 (interactive)
7684 (if (and current-prefix-arg (listp current-prefix-arg))
7685 (org-agenda-do-tree-to-indirect-buffer)
7686 (let ((agenda-window (selected-window))
7687 (indirect-window
7688 (and org-last-indirect-buffer
7689 (get-buffer-window org-last-indirect-buffer))))
7690 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7691 (unwind-protect
7692 (progn
7693 (unless (and indirect-window (window-live-p indirect-window))
7694 (setq indirect-window (split-window agenda-window)))
7695 (select-window indirect-window)
7696 (switch-to-buffer org-last-indirect-buffer :norecord)
7697 (fit-window-to-buffer indirect-window))
7698 (select-window (get-buffer-window org-agenda-buffer-name))))))
7700 (defun org-agenda-do-tree-to-indirect-buffer ()
7701 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7702 (org-agenda-check-no-diary)
7703 (let* ((marker (or (org-get-at-bol 'org-marker)
7704 (org-agenda-error)))
7705 (buffer (marker-buffer marker))
7706 (pos (marker-position marker)))
7707 (with-current-buffer buffer
7708 (save-excursion
7709 (goto-char pos)
7710 (call-interactively 'org-tree-to-indirect-buffer)))))
7712 (defvar org-last-heading-marker (make-marker)
7713 "Marker pointing to the headline that last changed its TODO state
7714 by a remote command from the agenda.")
7716 (defun org-agenda-todo-nextset ()
7717 "Switch TODO entry to next sequence."
7718 (interactive)
7719 (org-agenda-todo 'nextset))
7721 (defun org-agenda-todo-previousset ()
7722 "Switch TODO entry to previous sequence."
7723 (interactive)
7724 (org-agenda-todo 'previousset))
7726 (defun org-agenda-todo (&optional arg)
7727 "Cycle TODO state of line at point, also in Org-mode file.
7728 This changes the line at point, all other lines in the agenda referring to
7729 the same tree node, and the headline of the tree node in the Org-mode file."
7730 (interactive "P")
7731 (org-agenda-check-no-diary)
7732 (let* ((col (current-column))
7733 (marker (or (org-get-at-bol 'org-marker)
7734 (org-agenda-error)))
7735 (buffer (marker-buffer marker))
7736 (pos (marker-position marker))
7737 (hdmarker (org-get-at-bol 'org-hd-marker))
7738 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7739 (inhibit-read-only t)
7740 org-agenda-headline-snapshot-before-repeat newhead just-one)
7741 (org-with-remote-undo buffer
7742 (with-current-buffer buffer
7743 (widen)
7744 (goto-char pos)
7745 (org-show-context 'agenda)
7746 (save-excursion
7747 (and (outline-next-heading)
7748 (org-flag-heading nil))) ; show the next heading
7749 (let ((current-prefix-arg arg))
7750 (call-interactively 'org-todo))
7751 (and (bolp) (forward-char 1))
7752 (setq newhead (org-get-heading))
7753 (when (and (org-bound-and-true-p
7754 org-agenda-headline-snapshot-before-repeat)
7755 (not (equal org-agenda-headline-snapshot-before-repeat
7756 newhead))
7757 todayp)
7758 (setq newhead org-agenda-headline-snapshot-before-repeat
7759 just-one t))
7760 (save-excursion
7761 (org-back-to-heading)
7762 (move-marker org-last-heading-marker (point))))
7763 (beginning-of-line 1)
7764 (save-excursion
7765 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7766 (org-move-to-column col))))
7768 (defun org-agenda-add-note (&optional arg)
7769 "Add a time-stamped note to the entry at point."
7770 (interactive "P")
7771 (org-agenda-check-no-diary)
7772 (let* ((marker (or (org-get-at-bol 'org-marker)
7773 (org-agenda-error)))
7774 (buffer (marker-buffer marker))
7775 (pos (marker-position marker))
7776 (hdmarker (org-get-at-bol 'org-hd-marker))
7777 (inhibit-read-only t))
7778 (with-current-buffer buffer
7779 (widen)
7780 (goto-char pos)
7781 (org-show-context 'agenda)
7782 (save-excursion
7783 (and (outline-next-heading)
7784 (org-flag-heading nil))) ; show the next heading
7785 (org-add-note))))
7787 (defun org-agenda-change-all-lines (newhead hdmarker
7788 &optional fixface just-this)
7789 "Change all lines in the agenda buffer which match HDMARKER.
7790 The new content of the line will be NEWHEAD (as modified by
7791 `org-agenda-format-item'). HDMARKER is checked with
7792 `equal' against all `org-hd-marker' text properties in the file.
7793 If FIXFACE is non-nil, the face of each item is modified according to
7794 the new TODO state.
7795 If JUST-THIS is non-nil, change just the current line, not all.
7796 If FORCE-TAGS is non nil, the car of it returns the new tags."
7797 (let* ((inhibit-read-only t)
7798 (line (org-current-line))
7799 (org-agenda-buffer (current-buffer))
7800 (thetags (with-current-buffer (marker-buffer hdmarker)
7801 (save-excursion (save-restriction (widen)
7802 (goto-char hdmarker)
7803 (org-get-tags-at)))))
7804 props m pl undone-face done-face finish new dotime cat tags)
7805 (save-excursion
7806 (goto-char (point-max))
7807 (beginning-of-line 1)
7808 (while (not finish)
7809 (setq finish (bobp))
7810 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7811 (or (not just-this) (= (org-current-line) line))
7812 (equal m hdmarker))
7813 (setq props (text-properties-at (point))
7814 dotime (org-get-at-bol 'dotime)
7815 cat (org-get-at-bol 'org-category)
7816 tags thetags
7818 (let ((org-prefix-format-compiled
7819 (or (get-text-property (point) 'format)
7820 org-prefix-format-compiled))
7821 (extra (org-get-at-bol 'extra)))
7822 (with-current-buffer (marker-buffer hdmarker)
7823 (save-excursion
7824 (save-restriction
7825 (widen)
7826 (org-agenda-format-item extra newhead cat tags dotime)))))
7827 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7828 undone-face (org-get-at-bol 'undone-face)
7829 done-face (org-get-at-bol 'done-face))
7830 (beginning-of-line 1)
7831 (cond
7832 ((equal new "")
7833 (and (looking-at ".*\n?") (replace-match "")))
7834 ((looking-at ".*")
7835 (replace-match new t t)
7836 (beginning-of-line 1)
7837 (add-text-properties (point-at-bol) (point-at-eol) props)
7838 (when fixface
7839 (add-text-properties
7840 (point-at-bol) (point-at-eol)
7841 (list 'face
7842 (if org-last-todo-state-is-todo
7843 undone-face done-face))))
7844 (org-agenda-highlight-todo 'line)
7845 (beginning-of-line 1))
7846 (t (error "Line update did not work"))))
7847 (beginning-of-line 0)))
7848 (org-finalize-agenda)))
7850 (defun org-agenda-align-tags (&optional line)
7851 "Align all tags in agenda items to `org-agenda-tags-column'."
7852 (let ((inhibit-read-only t) l c)
7853 (save-excursion
7854 (goto-char (if line (point-at-bol) (point-min)))
7855 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7856 (if line (point-at-eol) nil) t)
7857 (add-text-properties
7858 (match-beginning 2) (match-end 2)
7859 (list 'face (delq nil (let ((prop (get-text-property
7860 (match-beginning 2) 'face)))
7861 (or (listp prop) (setq prop (list prop)))
7862 (if (memq 'org-tag prop)
7863 prop
7864 (cons 'org-tag prop))))))
7865 (setq l (- (match-end 2) (match-beginning 2))
7866 c (if (< org-agenda-tags-column 0)
7867 (- (abs org-agenda-tags-column) l)
7868 org-agenda-tags-column))
7869 (delete-region (match-beginning 1) (match-end 1))
7870 (goto-char (match-beginning 1))
7871 (insert (org-add-props
7872 (make-string (max 1 (- c (current-column))) ?\ )
7873 (plist-put (copy-sequence (text-properties-at (point)))
7874 'face nil))))
7875 (goto-char (point-min))
7876 (org-font-lock-add-tag-faces (point-max)))))
7878 (defun org-agenda-priority-up ()
7879 "Increase the priority of line at point, also in Org-mode file."
7880 (interactive)
7881 (org-agenda-priority 'up))
7883 (defun org-agenda-priority-down ()
7884 "Decrease the priority of line at point, also in Org-mode file."
7885 (interactive)
7886 (org-agenda-priority 'down))
7888 (defun org-agenda-priority (&optional force-direction)
7889 "Set the priority of line at point, also in Org-mode file.
7890 This changes the line at point, all other lines in the agenda referring to
7891 the same tree node, and the headline of the tree node in the Org-mode file."
7892 (interactive)
7893 (unless org-enable-priority-commands
7894 (error "Priority commands are disabled"))
7895 (org-agenda-check-no-diary)
7896 (let* ((marker (or (org-get-at-bol 'org-marker)
7897 (org-agenda-error)))
7898 (hdmarker (org-get-at-bol 'org-hd-marker))
7899 (buffer (marker-buffer hdmarker))
7900 (pos (marker-position hdmarker))
7901 (inhibit-read-only t)
7902 newhead)
7903 (org-with-remote-undo buffer
7904 (with-current-buffer buffer
7905 (widen)
7906 (goto-char pos)
7907 (org-show-context 'agenda)
7908 (save-excursion
7909 (and (outline-next-heading)
7910 (org-flag-heading nil))) ; show the next heading
7911 (funcall 'org-priority force-direction)
7912 (end-of-line 1)
7913 (setq newhead (org-get-heading)))
7914 (org-agenda-change-all-lines newhead hdmarker)
7915 (beginning-of-line 1))))
7917 ;; FIXME: should fix the tags property of the agenda line.
7918 (defun org-agenda-set-tags (&optional tag onoff)
7919 "Set tags for the current headline."
7920 (interactive)
7921 (org-agenda-check-no-diary)
7922 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7923 (call-interactively 'org-change-tag-in-region)
7924 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7925 (org-agenda-error)))
7926 (buffer (marker-buffer hdmarker))
7927 (pos (marker-position hdmarker))
7928 (inhibit-read-only t)
7929 newhead)
7930 (org-with-remote-undo buffer
7931 (with-current-buffer buffer
7932 (widen)
7933 (goto-char pos)
7934 (save-excursion
7935 (org-show-context 'agenda))
7936 (save-excursion
7937 (and (outline-next-heading)
7938 (org-flag-heading nil))) ; show the next heading
7939 (goto-char pos)
7940 (if tag
7941 (org-toggle-tag tag onoff)
7942 (call-interactively 'org-set-tags))
7943 (end-of-line 1)
7944 (setq newhead (org-get-heading)))
7945 (org-agenda-change-all-lines newhead hdmarker)
7946 (beginning-of-line 1)))))
7948 (defun org-agenda-set-property ()
7949 "Set a property for the current headline."
7950 (interactive)
7951 (org-agenda-check-no-diary)
7952 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7953 (org-agenda-error)))
7954 (buffer (marker-buffer hdmarker))
7955 (pos (marker-position hdmarker))
7956 (inhibit-read-only t)
7957 newhead)
7958 (org-with-remote-undo buffer
7959 (with-current-buffer buffer
7960 (widen)
7961 (goto-char pos)
7962 (save-excursion
7963 (org-show-context 'agenda))
7964 (save-excursion
7965 (and (outline-next-heading)
7966 (org-flag-heading nil))) ; show the next heading
7967 (goto-char pos)
7968 (call-interactively 'org-set-property)))))
7970 (defun org-agenda-set-effort ()
7971 "Set the effort property for the current headline."
7972 (interactive)
7973 (org-agenda-check-no-diary)
7974 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7975 (org-agenda-error)))
7976 (buffer (marker-buffer hdmarker))
7977 (pos (marker-position hdmarker))
7978 (inhibit-read-only t)
7979 newhead)
7980 (org-with-remote-undo buffer
7981 (with-current-buffer buffer
7982 (widen)
7983 (goto-char pos)
7984 (save-excursion
7985 (org-show-context 'agenda))
7986 (save-excursion
7987 (and (outline-next-heading)
7988 (org-flag-heading nil))) ; show the next heading
7989 (goto-char pos)
7990 (call-interactively 'org-set-effort)
7991 (end-of-line 1)
7992 (setq newhead (org-get-heading)))
7993 (org-agenda-change-all-lines newhead hdmarker))))
7995 (defun org-agenda-toggle-archive-tag ()
7996 "Toggle the archive tag for the current entry."
7997 (interactive)
7998 (org-agenda-check-no-diary)
7999 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8000 (org-agenda-error)))
8001 (buffer (marker-buffer hdmarker))
8002 (pos (marker-position hdmarker))
8003 (inhibit-read-only t)
8004 newhead)
8005 (org-with-remote-undo buffer
8006 (with-current-buffer buffer
8007 (widen)
8008 (goto-char pos)
8009 (org-show-context 'agenda)
8010 (save-excursion
8011 (and (outline-next-heading)
8012 (org-flag-heading nil))) ; show the next heading
8013 (call-interactively 'org-toggle-archive-tag)
8014 (end-of-line 1)
8015 (setq newhead (org-get-heading)))
8016 (org-agenda-change-all-lines newhead hdmarker)
8017 (beginning-of-line 1))))
8019 (defun org-agenda-do-date-later (arg)
8020 (interactive "P")
8021 (cond
8022 ((or (equal arg '(16))
8023 (memq last-command
8024 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8025 (setq this-command 'org-agenda-date-later-minutes)
8026 (org-agenda-date-later-minutes 1))
8027 ((or (equal arg '(4))
8028 (memq last-command
8029 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8030 (setq this-command 'org-agenda-date-later-hours)
8031 (org-agenda-date-later-hours 1))
8033 (org-agenda-date-later (prefix-numeric-value arg)))))
8035 (defun org-agenda-do-date-earlier (arg)
8036 (interactive "P")
8037 (cond
8038 ((or (equal arg '(16))
8039 (memq last-command
8040 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8041 (setq this-command 'org-agenda-date-earlier-minutes)
8042 (org-agenda-date-earlier-minutes 1))
8043 ((or (equal arg '(4))
8044 (memq last-command
8045 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8046 (setq this-command 'org-agenda-date-earlier-hours)
8047 (org-agenda-date-earlier-hours 1))
8049 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8051 (defun org-agenda-date-later (arg &optional what)
8052 "Change the date of this item to ARG day(s) later."
8053 (interactive "p")
8054 (org-agenda-check-type t 'agenda 'timeline)
8055 (org-agenda-check-no-diary)
8056 (let* ((marker (or (org-get-at-bol 'org-marker)
8057 (org-agenda-error)))
8058 (buffer (marker-buffer marker))
8059 (pos (marker-position marker))
8060 cdate today)
8061 (org-with-remote-undo buffer
8062 (with-current-buffer buffer
8063 (widen)
8064 (goto-char pos)
8065 (if (not (org-at-timestamp-p))
8066 (error "Cannot find time stamp"))
8067 (when (and org-agenda-move-date-from-past-immediately-to-today
8068 (equal arg 1)
8069 (or (not what) (eq what 'day))
8070 (not (save-match-data (org-at-date-range-p))))
8071 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8072 cdate (calendar-absolute-from-gregorian
8073 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8074 today (org-today))
8075 (if (> today cdate)
8076 ;; immediately shift to today
8077 (setq arg (- today cdate))))
8078 (org-timestamp-change arg (or what 'day))
8079 (when (and (org-at-date-range-p)
8080 (re-search-backward org-tr-regexp-both (point-at-bol)))
8081 (let ((end org-last-changed-timestamp))
8082 (org-timestamp-change arg (or what 'day))
8083 (setq org-last-changed-timestamp
8084 (concat org-last-changed-timestamp "--" end)))))
8085 (org-agenda-show-new-time marker org-last-changed-timestamp))
8086 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8088 (defun org-agenda-date-earlier (arg &optional what)
8089 "Change the date of this item to ARG day(s) earlier."
8090 (interactive "p")
8091 (org-agenda-date-later (- arg) what))
8093 (defun org-agenda-date-later-minutes (arg)
8094 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8095 (interactive "p")
8096 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8097 (org-agenda-date-later arg 'minute))
8099 (defun org-agenda-date-earlier-minutes (arg)
8100 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8101 (interactive "p")
8102 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8103 (org-agenda-date-earlier arg 'minute))
8105 (defun org-agenda-date-later-hours (arg)
8106 "Change the time of this item, in hour steps."
8107 (interactive "p")
8108 (org-agenda-date-later arg 'hour))
8110 (defun org-agenda-date-earlier-hours (arg)
8111 "Change the time of this item, in hour steps."
8112 (interactive "p")
8113 (org-agenda-date-earlier arg 'hour))
8115 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8116 "Show new date stamp via text properties."
8117 ;; We use text properties to make this undoable
8118 (let ((inhibit-read-only t)
8119 (buffer-invisibility-spec))
8120 (setq stamp (concat " " prefix " => " stamp))
8121 (save-excursion
8122 (goto-char (point-max))
8123 (while (not (bobp))
8124 (when (equal marker (org-get-at-bol 'org-marker))
8125 (org-move-to-column (- (window-width) (length stamp)) t)
8126 (org-agenda-fix-tags-filter-overlays-at (point))
8127 (if (featurep 'xemacs)
8128 ;; Use `duplicable' property to trigger undo recording
8129 (let ((ex (make-extent nil nil))
8130 (gl (make-glyph stamp)))
8131 (set-glyph-face gl 'secondary-selection)
8132 (set-extent-properties
8133 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8134 (insert-extent ex (1- (point)) (point-at-eol)))
8135 (add-text-properties
8136 (1- (point)) (point-at-eol)
8137 (list 'display (org-add-props stamp nil
8138 'face 'secondary-selection))))
8139 (beginning-of-line 1))
8140 (beginning-of-line 0)))))
8142 (defun org-agenda-date-prompt (arg)
8143 "Change the date of this item. Date is prompted for, with default today.
8144 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8145 be used to request time specification in the time stamp."
8146 (interactive "P")
8147 (org-agenda-check-type t 'agenda 'timeline)
8148 (org-agenda-check-no-diary)
8149 (let* ((marker (or (org-get-at-bol 'org-marker)
8150 (org-agenda-error)))
8151 (buffer (marker-buffer marker))
8152 (pos (marker-position marker)))
8153 (org-with-remote-undo buffer
8154 (with-current-buffer buffer
8155 (widen)
8156 (goto-char pos)
8157 (if (not (org-at-timestamp-p t))
8158 (error "Cannot find time stamp"))
8159 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8160 (org-agenda-show-new-time marker org-last-changed-timestamp))
8161 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8163 (defun org-agenda-schedule (arg &optional time)
8164 "Schedule the item at point.
8165 ARG is passed through to `org-schedule'."
8166 (interactive "P")
8167 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8168 (org-agenda-check-no-diary)
8169 (let* ((marker (or (org-get-at-bol 'org-marker)
8170 (org-agenda-error)))
8171 (type (marker-insertion-type marker))
8172 (buffer (marker-buffer marker))
8173 (pos (marker-position marker))
8174 (org-insert-labeled-timestamps-at-point nil)
8176 (set-marker-insertion-type marker t)
8177 (org-with-remote-undo buffer
8178 (with-current-buffer buffer
8179 (widen)
8180 (goto-char pos)
8181 (setq ts (org-schedule arg time)))
8182 (org-agenda-show-new-time marker ts "S"))
8183 (message "Item scheduled for %s" ts)))
8185 (defun org-agenda-deadline (arg &optional time)
8186 "Schedule the item at point.
8187 ARG is passed through to `org-deadline'."
8188 (interactive "P")
8189 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8190 (org-agenda-check-no-diary)
8191 (let* ((marker (or (org-get-at-bol 'org-marker)
8192 (org-agenda-error)))
8193 (buffer (marker-buffer marker))
8194 (pos (marker-position marker))
8195 (org-insert-labeled-timestamps-at-point nil)
8197 (org-with-remote-undo buffer
8198 (with-current-buffer buffer
8199 (widen)
8200 (goto-char pos)
8201 (setq ts (org-deadline arg time)))
8202 (org-agenda-show-new-time marker ts "D"))
8203 (message "Deadline for this item set to %s" ts)))
8205 (defun org-agenda-action ()
8206 "Select entry for agenda action, or execute an agenda action.
8207 This command prompts for another letter. Valid inputs are:
8209 m Mark the entry at point for an agenda action
8210 s Schedule the marked entry to the date at the cursor
8211 d Set the deadline of the marked entry to the date at the cursor
8212 r Call `org-remember' with cursor date as the default date
8213 c Call `org-capture' with cursor date as the default date
8214 SPC Show marked entry in other window
8215 TAB Visit marked entry in other window
8217 The cursor may be at a date in the calendar, or in the Org agenda."
8218 (interactive)
8219 (let (ans)
8220 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8221 (setq ans (read-char-exclusive))
8222 (cond
8223 ((equal ans ?m)
8224 ;; Mark this entry
8225 (if (eq major-mode 'org-agenda-mode)
8226 (let ((m (or (org-get-at-bol 'org-hd-marker)
8227 (org-get-at-bol 'org-marker))))
8228 (if m
8229 (progn
8230 (move-marker org-agenda-action-marker
8231 (marker-position m) (marker-buffer m))
8232 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8233 (error "Don't know which entry to mark")))
8234 (error "This command works only in the agenda")))
8235 ((equal ans ?s)
8236 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8237 ((equal ans ?d)
8238 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8239 ((equal ans ?r)
8240 (org-agenda-do-action '(org-remember) t))
8241 ((equal ans ?c)
8242 (org-agenda-do-action '(org-capture) t))
8243 ((equal ans ?\ )
8244 (let ((cw (selected-window)))
8245 (org-switch-to-buffer-other-window
8246 (marker-buffer org-agenda-action-marker))
8247 (goto-char org-agenda-action-marker)
8248 (org-show-context 'agenda)
8249 (select-window cw)))
8250 ((equal ans ?\C-i)
8251 (org-switch-to-buffer-other-window
8252 (marker-buffer org-agenda-action-marker))
8253 (goto-char org-agenda-action-marker)
8254 (org-show-context 'agenda))
8255 (t (error "Invalid agenda action %c" ans)))))
8257 (defun org-agenda-do-action (form &optional current-buffer)
8258 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8259 (let ((org-overriding-default-time (org-get-cursor-date)))
8260 (if current-buffer
8261 (eval form)
8262 (if (not (marker-buffer org-agenda-action-marker))
8263 (error "No entry has been selected for agenda action")
8264 (with-current-buffer (marker-buffer org-agenda-action-marker)
8265 (save-excursion
8266 (save-restriction
8267 (widen)
8268 (goto-char org-agenda-action-marker)
8269 (eval form))))))))
8271 (defun org-agenda-clock-in (&optional arg)
8272 "Start the clock on the currently selected item."
8273 (interactive "P")
8274 (org-agenda-check-no-diary)
8275 (if (equal arg '(4))
8276 (org-clock-in arg)
8277 (let* ((marker (or (org-get-at-bol 'org-marker)
8278 (org-agenda-error)))
8279 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8280 marker))
8281 (pos (marker-position marker))
8282 newhead)
8283 (org-with-remote-undo (marker-buffer marker)
8284 (with-current-buffer (marker-buffer marker)
8285 (widen)
8286 (goto-char pos)
8287 (org-show-context 'agenda)
8288 (org-show-entry)
8289 (org-cycle-hide-drawers 'children)
8290 (org-clock-in arg)
8291 (setq newhead (org-get-heading)))
8292 (org-agenda-change-all-lines newhead hdmarker)))))
8294 (defun org-agenda-clock-out ()
8295 "Stop the currently running clock."
8296 (interactive)
8297 (unless (marker-buffer org-clock-marker)
8298 (error "No running clock"))
8299 (let ((marker (make-marker)) newhead)
8300 (org-with-remote-undo (marker-buffer org-clock-marker)
8301 (with-current-buffer (marker-buffer org-clock-marker)
8302 (save-excursion
8303 (save-restriction
8304 (widen)
8305 (goto-char org-clock-marker)
8306 (org-back-to-heading t)
8307 (move-marker marker (point))
8308 (org-clock-out)
8309 (setq newhead (org-get-heading))))))
8310 (org-agenda-change-all-lines newhead marker)
8311 (move-marker marker nil)))
8313 (defun org-agenda-clock-cancel (&optional arg)
8314 "Cancel the currently running clock."
8315 (interactive "P")
8316 (unless (marker-buffer org-clock-marker)
8317 (error "No running clock"))
8318 (org-with-remote-undo (marker-buffer org-clock-marker)
8319 (org-clock-cancel)))
8321 (defun org-agenda-clock-goto ()
8322 "Jump to the currently clocked in task within the agenda.
8323 If the currently clocked in task is not listed in the agenda
8324 buffer, display it in another window."
8325 (interactive)
8326 (let (pos)
8327 (mapc (lambda (o)
8328 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8329 (setq pos (overlay-start o))))
8330 (overlays-in (point-min) (point-max)))
8331 (cond (pos (goto-char pos))
8332 ;; If the currently clocked entry is not in the agenda
8333 ;; buffer, we visit it in another window:
8334 (org-clock-current-task
8335 (org-switch-to-buffer-other-window (org-clock-goto)))
8336 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8338 (defun org-agenda-diary-entry-in-org-file ()
8339 "Make a diary entry in the file `org-agenda-diary-file'."
8340 (let (d1 d2 char (text "") dp1 dp2)
8341 (if (equal (buffer-name) "*Calendar*")
8342 (setq d1 (calendar-cursor-to-date t)
8343 d2 (car calendar-mark-ring))
8344 (setq dp1 (get-text-property (point-at-bol) 'day))
8345 (unless dp1 (error "No date defined in current line"))
8346 (setq d1 (calendar-gregorian-from-absolute dp1)
8347 d2 (and (ignore-errors (mark))
8348 (save-excursion
8349 (goto-char (mark))
8350 (setq dp2 (get-text-property (point-at-bol) 'day)))
8351 (calendar-gregorian-from-absolute dp2))))
8352 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8353 (setq char (read-char-exclusive))
8354 (cond
8355 ((equal char ?d)
8356 (setq text (read-string "Day entry: "))
8357 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8358 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8359 ((equal char ?a)
8360 (setq d1 (list (car d1) (nth 1 d1)
8361 (read-number (format "Reference year [%d]: " (nth 2 d1))
8362 (nth 2 d1))))
8363 (setq text (read-string "Anniversary (use %d to show years): "))
8364 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8365 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8366 ((equal char ?b)
8367 (setq text (read-string "Block entry: "))
8368 (unless (and d1 d2 (not (equal d1 d2)))
8369 (error "No block of days selected"))
8370 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8371 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8372 ((equal char ?j)
8373 (org-switch-to-buffer-other-window
8374 (find-file-noselect org-agenda-diary-file))
8375 (require 'org-datetree)
8376 (org-datetree-find-date-create d1)
8377 (org-reveal t))
8378 (t (error "Invalid selection character `%c'" char)))))
8380 (defcustom org-agenda-insert-diary-strategy 'date-tree
8381 "Where in `org-agenda-diary-file' should new entries be added?
8382 Valid values:
8384 date-tree in the date tree, as child of the date
8385 top-level as top-level entries at the end of the file."
8386 :group 'org-agenda
8387 :type '(choice
8388 (const :tag "in a date tree" date-tree)
8389 (const :tag "as top level at end of file" top-level)))
8391 (defcustom org-agenda-insert-diary-extract-time nil
8392 "Non-nil means extract any time specification from the diary entry."
8393 :group 'org-agenda
8394 :version "24.1"
8395 :type 'boolean)
8397 (defcustom org-agenda-bulk-mark-char ">"
8398 "A single-character string to be used as the bulk mark."
8399 :group 'org-agenda
8400 :version "24.1"
8401 :type 'string)
8403 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8404 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8405 If TEXT is not empty, it will become the headline of the new entry, and
8406 the resulting entry will not be shown. When TEXT is empty, switch to
8407 `org-agenda-diary-file' and let the user finish the entry there."
8408 (let ((cw (current-window-configuration)))
8409 (org-switch-to-buffer-other-window
8410 (find-file-noselect org-agenda-diary-file))
8411 (widen)
8412 (goto-char (point-min))
8413 (cond
8414 ((eq type 'anniversary)
8415 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8416 (progn
8417 (or (org-at-heading-p t)
8418 (progn
8419 (outline-next-heading)
8420 (insert "* Anniversaries\n\n")
8421 (beginning-of-line -1)))))
8422 (outline-next-heading)
8423 (org-back-over-empty-lines)
8424 (backward-char 1)
8425 (insert "\n")
8426 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8427 (nth 2 d1) (car d1) (nth 1 d1) text)))
8428 ((eq type 'day)
8429 (let ((org-prefix-has-time t)
8430 (org-agenda-time-leading-zero t)
8431 fmt time time2)
8432 (if org-agenda-insert-diary-extract-time
8433 ;; Use org-agenda-format-item to parse text for a time-range and
8434 ;; remove it. FIXME: This is a hack, we should refactor
8435 ;; that function to make time extraction available separately
8436 (setq fmt (org-agenda-format-item nil text nil nil t)
8437 time (get-text-property 0 'time fmt)
8438 time2 (if (> (length time) 0)
8439 ;; split-string removes trailing ...... if
8440 ;; no end time given. First space
8441 ;; separates time from date.
8442 (concat " " (car (split-string time "\\.")))
8443 nil)
8444 text (get-text-property 0 'txt fmt)))
8445 (if (eq org-agenda-insert-diary-strategy 'top-level)
8446 (org-agenda-insert-diary-as-top-level text)
8447 (require 'org-datetree)
8448 (org-datetree-find-date-create d1)
8449 (org-agenda-insert-diary-make-new-entry text))
8450 (org-insert-time-stamp (org-time-from-absolute
8451 (calendar-absolute-from-gregorian d1))
8452 nil nil nil nil time2))
8453 (end-of-line 0))
8454 ((eq type 'block)
8455 (if (> (calendar-absolute-from-gregorian d1)
8456 (calendar-absolute-from-gregorian d2))
8457 (setq d1 (prog1 d2 (setq d2 d1))))
8458 (if (eq org-agenda-insert-diary-strategy 'top-level)
8459 (org-agenda-insert-diary-as-top-level text)
8460 (require 'org-datetree)
8461 (org-datetree-find-date-create d1)
8462 (org-agenda-insert-diary-make-new-entry text))
8463 (org-insert-time-stamp (org-time-from-absolute
8464 (calendar-absolute-from-gregorian d1)))
8465 (insert "--")
8466 (org-insert-time-stamp (org-time-from-absolute
8467 (calendar-absolute-from-gregorian d2)))
8468 (end-of-line 0)))
8469 (if (string-match "\\S-" text)
8470 (progn
8471 (set-window-configuration cw)
8472 (message "%s entry added to %s"
8473 (capitalize (symbol-name type))
8474 (abbreviate-file-name org-agenda-diary-file)))
8475 (org-reveal t)
8476 (message "Please finish entry here"))))
8478 (defun org-agenda-insert-diary-as-top-level (text)
8479 "Make new entry as a top-level entry at the end of the file.
8480 Add TEXT as headline, and position the cursor in the second line so that
8481 a timestamp can be added there."
8482 (widen)
8483 (goto-char (point-max))
8484 (or (bolp) (insert "\n"))
8485 (insert "* " text "\n")
8486 (if org-adapt-indentation (org-indent-to-column 2)))
8488 (defun org-agenda-insert-diary-make-new-entry (text)
8489 "Make new entry as last child of current entry.
8490 Add TEXT as headline, and position the cursor in the second line so that
8491 a timestamp can be added there."
8492 (let ((org-show-following-heading t)
8493 (org-show-siblings t)
8494 (org-show-hierarchy-above t)
8495 (org-show-entry-below t)
8496 col)
8497 (outline-next-heading)
8498 (org-back-over-empty-lines)
8499 (or (looking-at "[ \t]*$")
8500 (progn (insert "\n") (backward-char 1)))
8501 (org-insert-heading nil t)
8502 (org-do-demote)
8503 (setq col (current-column))
8504 (insert text "\n")
8505 (if org-adapt-indentation (org-indent-to-column col))
8506 (let ((org-show-following-heading t)
8507 (org-show-siblings t)
8508 (org-show-hierarchy-above t)
8509 (org-show-entry-below t))
8510 (org-show-context))))
8512 (defun org-agenda-diary-entry ()
8513 "Make a diary entry, like the `i' command from the calendar.
8514 All the standard commands work: block, weekly etc.
8515 When `org-agenda-diary-file' points to a file,
8516 `org-agenda-diary-entry-in-org-file' is called instead to create
8517 entries in that Org-mode file."
8518 (interactive)
8519 (org-agenda-check-type t 'agenda 'timeline)
8520 (if (not (eq org-agenda-diary-file 'diary-file))
8521 (org-agenda-diary-entry-in-org-file)
8522 (require 'diary-lib)
8523 (let* ((char (progn
8524 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8525 (read-char-exclusive)))
8526 (cmd (cdr (assoc char
8527 '((?d . insert-diary-entry)
8528 (?w . insert-weekly-diary-entry)
8529 (?m . insert-monthly-diary-entry)
8530 (?y . insert-yearly-diary-entry)
8531 (?a . insert-anniversary-diary-entry)
8532 (?b . insert-block-diary-entry)
8533 (?c . insert-cyclic-diary-entry)))))
8534 (oldf (symbol-function 'calendar-cursor-to-date))
8535 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8536 (point (point))
8537 (mark (or (mark t) (point))))
8538 (unless cmd
8539 (error "No command associated with <%c>" char))
8540 (unless (and (get-text-property point 'day)
8541 (or (not (equal ?b char))
8542 (get-text-property mark 'day)))
8543 (error "Don't know which date to use for diary entry"))
8544 ;; We implement this by hacking the `calendar-cursor-to-date' function
8545 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8546 (let ((calendar-mark-ring
8547 (list (calendar-gregorian-from-absolute
8548 (or (get-text-property mark 'day)
8549 (get-text-property point 'day))))))
8550 (unwind-protect
8551 (progn
8552 (fset 'calendar-cursor-to-date
8553 (lambda (&optional error dummy)
8554 (calendar-gregorian-from-absolute
8555 (get-text-property point 'day))))
8556 (call-interactively cmd))
8557 (fset 'calendar-cursor-to-date oldf))))))
8559 (defun org-agenda-execute-calendar-command (cmd)
8560 "Execute a calendar command from the agenda, with the date associated to
8561 the cursor position."
8562 (org-agenda-check-type t 'agenda 'timeline)
8563 (require 'diary-lib)
8564 (unless (get-text-property (point) 'day)
8565 (error "Don't know which date to use for calendar command"))
8566 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8567 (point (point))
8568 (date (calendar-gregorian-from-absolute
8569 (get-text-property point 'day)))
8570 ;; the following 2 vars are needed in the calendar
8571 (displayed-month (car date))
8572 (displayed-year (nth 2 date)))
8573 (unwind-protect
8574 (progn
8575 (fset 'calendar-cursor-to-date
8576 (lambda (&optional error dummy)
8577 (calendar-gregorian-from-absolute
8578 (get-text-property point 'day))))
8579 (call-interactively cmd))
8580 (fset 'calendar-cursor-to-date oldf))))
8582 (defun org-agenda-phases-of-moon ()
8583 "Display the phases of the moon for the 3 months around the cursor date."
8584 (interactive)
8585 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8587 (defun org-agenda-holidays ()
8588 "Display the holidays for the 3 months around the cursor date."
8589 (interactive)
8590 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8592 (defvar calendar-longitude)
8593 (defvar calendar-latitude)
8594 (defvar calendar-location-name)
8596 (defun org-agenda-sunrise-sunset (arg)
8597 "Display sunrise and sunset for the cursor date.
8598 Latitude and longitude can be specified with the variables
8599 `calendar-latitude' and `calendar-longitude'. When called with prefix
8600 argument, latitude and longitude will be prompted for."
8601 (interactive "P")
8602 (require 'solar)
8603 (let ((calendar-longitude (if arg nil calendar-longitude))
8604 (calendar-latitude (if arg nil calendar-latitude))
8605 (calendar-location-name
8606 (if arg "the given coordinates" calendar-location-name)))
8607 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8609 (defun org-agenda-goto-calendar ()
8610 "Open the Emacs calendar with the date at the cursor."
8611 (interactive)
8612 (org-agenda-check-type t 'agenda 'timeline)
8613 (let* ((day (or (get-text-property (point) 'day)
8614 (error "Don't know which date to open in calendar")))
8615 (date (calendar-gregorian-from-absolute day))
8616 (calendar-move-hook nil)
8617 (calendar-view-holidays-initially-flag nil)
8618 (calendar-view-diary-initially-flag nil))
8619 (calendar)
8620 (calendar-goto-date date)))
8622 ;;;###autoload
8623 (defun org-calendar-goto-agenda ()
8624 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8625 This is a command that has to be installed in `calendar-mode-map'."
8626 (interactive)
8627 (org-agenda-list nil (calendar-absolute-from-gregorian
8628 (calendar-cursor-to-date))
8629 nil))
8631 (defun org-agenda-convert-date ()
8632 (interactive)
8633 (org-agenda-check-type t 'agenda 'timeline)
8634 (let ((day (get-text-property (point) 'day))
8635 date s)
8636 (unless day
8637 (error "Don't know which date to convert"))
8638 (setq date (calendar-gregorian-from-absolute day))
8639 (setq s (concat
8640 "Gregorian: " (calendar-date-string date) "\n"
8641 "ISO: " (calendar-iso-date-string date) "\n"
8642 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8643 "Julian: " (calendar-julian-date-string date) "\n"
8644 "Astron. JD: " (calendar-astro-date-string date)
8645 " (Julian date number at noon UTC)\n"
8646 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8647 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8648 "French: " (calendar-french-date-string date) "\n"
8649 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8650 "Mayan: " (calendar-mayan-date-string date) "\n"
8651 "Coptic: " (calendar-coptic-date-string date) "\n"
8652 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8653 "Persian: " (calendar-persian-date-string date) "\n"
8654 "Chinese: " (calendar-chinese-date-string date) "\n"))
8655 (with-output-to-temp-buffer "*Dates*"
8656 (princ s))
8657 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8659 ;;; Bulk commands
8661 (defvar org-agenda-bulk-marked-entries nil
8662 "List of markers that refer to marked entries in the agenda.")
8664 (defun org-agenda-bulk-marked-p ()
8665 (eq (get-char-property (point-at-bol) 'type)
8666 'org-marked-entry-overlay))
8668 (defun org-agenda-bulk-mark (&optional arg)
8669 "Mark the entry at point for future bulk action."
8670 (interactive "p")
8671 (dotimes (i (or arg 1))
8672 (unless (org-get-at-bol 'org-agenda-diary-link)
8673 (let* ((m (org-get-at-bol 'org-hd-marker))
8675 (unless (org-agenda-bulk-marked-p)
8676 (unless m (error "Nothing to mark at point"))
8677 (push m org-agenda-bulk-marked-entries)
8678 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8679 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8680 (org-get-todo-face "TODO")
8681 'evaporate)
8682 (overlay-put ov 'type 'org-marked-entry-overlay))
8683 (beginning-of-line 2)
8684 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8685 (beginning-of-line 2))
8686 (message "%d entries marked for bulk action"
8687 (length org-agenda-bulk-marked-entries))))))
8689 (defun org-agenda-bulk-mark-all ()
8690 "Mark all entries for future agenda bulk action."
8691 (interactive)
8692 (org-agenda-bulk-mark-regexp "."))
8694 (defun org-agenda-bulk-mark-regexp (regexp)
8695 "Mark entries matching REGEXP for future agenda bulk action."
8696 (interactive "sMark entries matching regexp: ")
8697 (let ((entries-marked 0))
8698 (save-excursion
8699 (goto-char (point-min))
8700 (goto-char (next-single-property-change (point) 'txt))
8701 (while (re-search-forward regexp nil t)
8702 (when (string-match regexp (get-text-property (point) 'txt))
8703 (setq entries-marked (1+ entries-marked))
8704 (call-interactively 'org-agenda-bulk-mark))))
8705 (if (not entries-marked)
8706 (message "No entry matching this regexp."))))
8708 (defun org-agenda-bulk-unmark (&optional arg)
8709 "Unmark the entry at point for future bulk action."
8710 (interactive "P")
8711 (if arg
8712 (org-agenda-bulk-unmark-all)
8713 (cond ((org-agenda-bulk-marked-p)
8714 (org-agenda-bulk-remove-overlays
8715 (point-at-bol) (+ 2 (point-at-bol)))
8716 (setq org-agenda-bulk-marked-entries
8717 (delete (org-get-at-bol 'org-hd-marker)
8718 org-agenda-bulk-marked-entries))
8719 (beginning-of-line 2)
8720 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8721 (beginning-of-line 2))
8722 (message "%d entries left marked for bulk action"
8723 (length org-agenda-bulk-marked-entries)))
8724 (t (message "No entry to unmark here")))))
8726 (defun org-agenda-bulk-toggle ()
8727 "Toggle marking the entry at point for bulk action."
8728 (interactive)
8729 (if (org-agenda-bulk-marked-p)
8730 (org-agenda-bulk-unmark)
8731 (org-agenda-bulk-mark)))
8733 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8734 "Remove the mark overlays between BEG and END in the agenda buffer.
8735 BEG and END default to the buffer limits.
8737 This only removes the overlays, it does not remove the markers
8738 from the list in `org-agenda-bulk-marked-entries'."
8739 (interactive)
8740 (mapc (lambda (ov)
8741 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8742 (delete-overlay ov)))
8743 (overlays-in (or beg (point-min)) (or end (point-max)))))
8745 (defun org-agenda-bulk-unmark-all ()
8746 "Remove all marks in the agenda buffer.
8747 This will remove the markers and the overlays."
8748 (interactive)
8749 (if (null org-agenda-bulk-marked-entries)
8750 (message "No entry to unmark")
8751 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8752 (setq org-agenda-bulk-marked-entries nil)
8753 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8755 (defcustom org-agenda-persistent-marks nil
8756 "Non-nil means marked items will stay marked after a bulk action.
8757 You can interactively and temporarily toggle by typing `p' when you
8758 are prompted for a bulk action."
8759 :group 'org-agenda
8760 :version "24.1"
8761 :type 'boolean)
8763 (defun org-agenda-bulk-action (&optional arg)
8764 "Execute an remote-editing action on all marked entries.
8765 The prefix arg is passed through to the command if possible."
8766 (interactive "P")
8767 ;; Make sure we have markers, and only valid ones
8768 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8769 (mapc
8770 (lambda (m)
8771 (unless (and (markerp m)
8772 (marker-buffer m)
8773 (buffer-live-p (marker-buffer m))
8774 (marker-position m))
8775 (error "Marker %s for bulk command is invalid" m)))
8776 org-agenda-bulk-marked-entries)
8778 ;; Prompt for the bulk command
8779 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8780 (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
8781 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
8782 (when org-agenda-bulk-custom-functions
8783 (concat " Custom: ["
8784 (mapconcat (lambda(f) (char-to-string (car f)))
8785 org-agenda-bulk-custom-functions "")
8786 "]"))))
8787 (catch 'exit
8788 (let* ((action (read-char-exclusive))
8789 (org-log-refile (if org-log-refile 'time nil))
8790 (entries (reverse org-agenda-bulk-marked-entries))
8791 redo-at-end
8792 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8793 (cond
8794 ((equal action ?p)
8795 (let ((org-agenda-persistent-marks
8796 (not org-agenda-persistent-marks)))
8797 (org-agenda-bulk-action)
8798 (throw 'exit nil)))
8800 ((equal action ?$)
8801 (setq cmd '(org-agenda-archive)))
8803 ((equal action ?A)
8804 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8806 ((member action '(?r ?w))
8807 (setq rfloc (org-refile-get-location
8808 "Refile to"
8809 (marker-buffer (car org-agenda-bulk-marked-entries))
8810 org-refile-allow-creating-parent-nodes))
8811 (if (nth 3 rfloc)
8812 (setcar (nthcdr 3 rfloc)
8813 (move-marker (make-marker) (nth 3 rfloc)
8814 (or (get-file-buffer (nth 1 rfloc))
8815 (find-buffer-visiting (nth 1 rfloc))
8816 (error "This should not happen")))))
8818 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8819 redo-at-end t))
8821 ((equal action ?t)
8822 (setq state (org-icompleting-read
8823 "Todo state: "
8824 (with-current-buffer (marker-buffer (car entries))
8825 (mapcar 'list org-todo-keywords-1))))
8826 (setq cmd `(let ((org-inhibit-blocking t)
8827 (org-inhibit-logging 'note))
8828 (org-agenda-todo ,state))))
8830 ((memq action '(?- ?+))
8831 (setq tag (org-icompleting-read
8832 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8833 (with-current-buffer (marker-buffer (car entries))
8834 (delq nil
8835 (mapcar (lambda (x)
8836 (if (stringp (car x)) x)) org-tag-alist)))))
8837 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8839 ((memq action '(?s ?d))
8840 (let* ((date (unless arg
8841 (org-read-date
8842 nil nil nil
8843 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8844 (ans (if arg nil org-read-date-final-answer))
8845 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8846 (setq cmd `(let* ((bound (fboundp 'read-string))
8847 (old (and bound (symbol-function 'read-string))))
8848 (unwind-protect
8849 (progn
8850 (fset 'read-string (lambda (&rest ignore) ,ans))
8851 (eval '(,c1 arg)))
8852 (if bound
8853 (fset 'read-string old)
8854 (fmakunbound 'read-string)))))))
8856 ((equal action ?S)
8857 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8858 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8859 (let ((days (read-number
8860 (format "Scatter tasks across how many %sdays: "
8861 (if arg "week" "")) 7)))
8862 (setq cmd
8863 `(let ((distance (1+ (random ,days))))
8864 (if arg
8865 (let ((dist distance)
8866 (day-of-week
8867 (calendar-day-of-week
8868 (calendar-gregorian-from-absolute (org-today)))))
8869 (dotimes (i (1+ dist))
8870 (while (member day-of-week org-agenda-weekend-days)
8871 (incf distance)
8872 (incf day-of-week)
8873 (if (= day-of-week 7)
8874 (setq day-of-week 0)))
8875 (incf day-of-week)
8876 (if (= day-of-week 7)
8877 (setq day-of-week 0)))))
8878 ;; silently fail when try to replan a sexp entry
8879 (condition-case nil
8880 (let* ((date (calendar-gregorian-from-absolute
8881 (+ (org-today) distance)))
8882 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8883 (nth 2 date))))
8884 (org-agenda-schedule nil time))
8885 (error nil)))))))
8887 ((assoc action org-agenda-bulk-custom-functions)
8888 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8889 redo-at-end t))
8891 ((equal action ?f)
8892 (setq cmd (list (intern
8893 (org-icompleting-read "Function: "
8894 obarray 'fboundp t nil nil)))))
8896 (t (error "Invalid bulk action")))
8898 ;; Sort the markers, to make sure that parents are handled before children
8899 (setq entries (sort entries
8900 (lambda (a b)
8901 (cond
8902 ((equal (marker-buffer a) (marker-buffer b))
8903 (< (marker-position a) (marker-position b)))
8905 (string< (buffer-name (marker-buffer a))
8906 (buffer-name (marker-buffer b))))))))
8908 ;; Now loop over all markers and apply cmd
8909 (while (setq e (pop entries))
8910 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8911 (if (not pos)
8912 (progn (message "Skipping removed entry at %s" e)
8913 (setq cntskip (1+ cntskip)))
8914 (goto-char pos)
8915 (let (org-loop-over-headlines-in-active-region)
8916 (eval cmd))
8917 (when (not org-agenda-persistent-marks)
8918 (setq org-agenda-bulk-marked-entries
8919 (delete e org-agenda-bulk-marked-entries)))
8920 (setq cnt (1+ cnt))))
8921 (when (not org-agenda-persistent-marks)
8922 (org-agenda-bulk-unmark-all))
8923 (when redo-at-end (org-agenda-redo))
8924 (message "Acted on %d entries%s%s"
8926 (if (= cntskip 0)
8928 (format ", skipped %d (disappeared before their turn)"
8929 cntskip))
8930 (if (not org-agenda-persistent-marks)
8931 "" " (kept marked)"))))))
8933 ;;; Flagging notes
8935 (defun org-agenda-show-the-flagging-note ()
8936 "Display the flagging note in the other window.
8937 When called a second time in direct sequence, offer to remove the FLAGGING
8938 tag and (if present) the flagging note."
8939 (interactive)
8940 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8941 (win (selected-window))
8942 note heading newhead)
8943 (unless hdmarker
8944 (error "No linked entry at point"))
8945 (if (and (eq this-command last-command)
8946 (y-or-n-p "Unflag and remove any flagging note? "))
8947 (progn
8948 (org-agenda-remove-flag hdmarker)
8949 (let ((win (get-buffer-window "*Flagging Note*")))
8950 (and win (delete-window win)))
8951 (message "Entry unflagged"))
8952 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8953 (unless note
8954 (error "No flagging note"))
8955 (org-kill-new note)
8956 (org-switch-to-buffer-other-window "*Flagging Note*")
8957 (erase-buffer)
8958 (insert note)
8959 (goto-char (point-min))
8960 (while (re-search-forward "\\\\n" nil t)
8961 (replace-match "\n" t t))
8962 (goto-char (point-min))
8963 (select-window win)
8964 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8966 (defun org-agenda-remove-flag (marker)
8967 "Remove the FLAGGED tag and any flagging note in the entry."
8968 (let (newhead)
8969 (org-with-point-at marker
8970 (org-toggle-tag "FLAGGED" 'off)
8971 (org-entry-delete nil "THEFLAGGINGNOTE")
8972 (setq newhead (org-get-heading)))
8973 (org-agenda-change-all-lines newhead marker)
8974 (message "Entry unflagged")))
8976 (defun org-agenda-get-any-marker (&optional pos)
8977 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8978 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8980 ;;; Appointment reminders
8982 (defvar appt-time-msg-list)
8984 ;;;###autoload
8985 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8986 "Activate appointments found in `org-agenda-files'.
8987 With a \\[universal-argument] prefix, refresh the list of
8988 appointments.
8990 If FILTER is t, interactively prompt the user for a regular
8991 expression, and filter out entries that don't match it.
8993 If FILTER is a string, use this string as a regular expression
8994 for filtering entries out.
8996 If FILTER is a function, filter out entries against which
8997 calling the function returns nil. This function takes one
8998 argument: an entry from `org-agenda-get-day-entries'.
9000 FILTER can also be an alist with the car of each cell being
9001 either 'headline or 'category. For example:
9003 '((headline \"IMPORTANT\")
9004 (category \"Work\"))
9006 will only add headlines containing IMPORTANT or headlines
9007 belonging to the \"Work\" category.
9009 ARGS are symbols indicating what kind of entries to consider.
9010 By default `org-agenda-to-appt' will use :deadline, :scheduled
9011 and :timestamp entries. See the docstring of `org-diary' for
9012 details and examples.
9014 If an entry as a APPT_WARNTIME property, its value will be used
9015 to override `appt-message-warning-time'."
9016 (interactive "P")
9017 (if refresh (setq appt-time-msg-list nil))
9018 (if (eq filter t)
9019 (setq filter (read-from-minibuffer "Regexp filter: ")))
9020 (let* ((cnt 0) ; count added events
9021 (scope (or args '(:deadline :scheduled :timestamp)))
9022 (org-agenda-new-buffers nil)
9023 (org-deadline-warning-days 0)
9024 ;; Do not use `org-today' here because appt only takes
9025 ;; time and without date as argument, so it may pass wrong
9026 ;; information otherwise
9027 (today (org-date-to-gregorian
9028 (time-to-days (current-time))))
9029 (org-agenda-restrict nil)
9030 (files (org-agenda-files 'unrestricted)) entries file
9031 (org-agenda-buffer nil))
9032 ;; Get all entries which may contain an appt
9033 (org-prepare-agenda-buffers files)
9034 (while (setq file (pop files))
9035 (setq entries
9036 (delq nil
9037 (append entries
9038 (apply 'org-agenda-get-day-entries
9039 file today scope)))))
9040 ;; Map thru entries and find if we should filter them out
9041 (mapc
9042 (lambda(x)
9043 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9044 (cat (get-text-property 1 'org-category x))
9045 (tod (get-text-property 1 'time-of-day x))
9046 (ok (or (null filter)
9047 (and (stringp filter) (string-match filter evt))
9048 (and (functionp filter) (funcall filter x))
9049 (and (listp filter)
9050 (let ((cat-filter (cadr (assoc 'category filter)))
9051 (evt-filter (cadr (assoc 'headline filter))))
9052 (or (and (stringp cat-filter)
9053 (string-match cat-filter cat))
9054 (and (stringp evt-filter)
9055 (string-match evt-filter evt)))))))
9056 (wrn (org-entry-get (point) "APPT_WARNTIME")))
9057 ;; FIXME: Shall we remove text-properties for the appt text?
9058 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9059 (when (and ok tod)
9060 (setq tod (concat "00" (number-to-string tod))
9061 tod (when (string-match
9062 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9063 (concat (match-string 1 tod) ":"
9064 (match-string 2 tod))))
9065 (if (version< emacs-version "23.3")
9066 (appt-add tod evt)
9067 (appt-add tod evt wrn))
9068 (setq cnt (1+ cnt))))) entries)
9069 (org-release-buffers org-agenda-new-buffers)
9070 (if (eq cnt 0)
9071 (message "No event to add")
9072 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9074 (defun org-agenda-todayp (date)
9075 "Does DATE mean today, when considering `org-extend-today-until'?"
9076 (let ((today (org-today))
9077 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9078 date)))
9079 (eq date today)))
9081 (defun org-agenda-todo-yesterday (&optional arg)
9082 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9083 (interactive "P")
9084 (let* ((hour (third (decode-time
9085 (org-current-time))))
9086 (org-extend-today-until (1+ hour)))
9087 (org-agenda-todo arg)))
9089 (provide 'org-agenda)
9091 ;;; org-agenda.el ends here