org-agenda.el: New commands `org-agenda-next/previous-item'.
[org-mode.git] / lisp / org-agenda.el
blobbffe65747df59c023491f228400f03a4a642eeec
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 (eval-when-compile
50 (require 'cl))
52 (declare-function diary-add-to-list "diary-lib"
53 (date string specifier &optional marker globcolor literal))
54 (declare-function calendar-absolute-from-iso "cal-iso" (date))
55 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
56 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
57 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
58 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
59 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-french-date-string "cal-french" (&optional date))
61 (declare-function calendar-goto-date "cal-move" (date))
62 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
63 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
64 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
65 (declare-function calendar-iso-from-absolute "cal-iso" (date))
66 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
67 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
68 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
69 (declare-function calendar-check-holidays "holidays" (date))
71 (declare-function org-datetree-find-date-create "org-datetree"
72 (date &optional keep-restriction))
73 (declare-function org-columns-quit "org-colview" ())
74 (declare-function diary-date-display-form "diary-lib" (&optional type))
75 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
76 (declare-function org-habit-insert-consistency-graphs
77 "org-habit" (&optional line))
78 (declare-function org-is-habit-p "org-habit" (&optional pom))
79 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
80 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
81 (declare-function org-pop-to-buffer-same-window "org-compat"
82 (&optional buffer-or-name norecord label))
84 (defvar calendar-mode-map)
85 (defvar org-clock-current-task) ; defined in org-clock.el
86 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
87 (defvar org-habit-show-habits)
88 (defvar org-habit-show-habits-only-for-today)
89 (defvar org-habit-show-all-today nil)
91 ;; Defined somewhere in this file, but used before definition.
92 (defvar org-agenda-buffer-name)
93 (defvar org-agenda-overriding-header)
94 (defvar org-agenda-title-append nil)
95 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
96 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
97 (defvar org-agenda-undo-list)
98 (defvar org-agenda-pending-undo-list)
99 (defvar original-date) ; dynamically scoped, calendar.el does scope this
101 (defcustom org-agenda-confirm-kill 1
102 "When set, remote killing from the agenda buffer needs confirmation.
103 When t, a confirmation is always needed. When a number N, confirmation is
104 only needed when the text to be killed contains more than N non-white lines."
105 :group 'org-agenda
106 :type '(choice
107 (const :tag "Never" nil)
108 (const :tag "Always" t)
109 (integer :tag "When more than N lines")))
111 (defcustom org-agenda-compact-blocks nil
112 "Non-nil means make the block agenda more compact.
113 This is done globally by leaving out lines like the agenda span
114 name and week number or the separator lines."
115 :group 'org-agenda
116 :type 'boolean)
118 (defcustom org-agenda-block-separator ?=
119 "The separator between blocks in the agenda.
120 If this is a string, it will be used as the separator, with a newline added.
121 If it is a character, it will be repeated to fill the window width.
122 If nil the separator is disabled. In `org-agenda-custom-commands' this
123 addresses the separator between the current and the previous block."
124 :group 'org-agenda
125 :type '(choice
126 (const :tag "Disabled" nil)
127 (character)
128 (string)))
130 (defgroup org-agenda-export nil
131 "Options concerning exporting agenda views in Org-mode."
132 :tag "Org Agenda Export"
133 :group 'org-agenda)
135 (defcustom org-agenda-with-colors t
136 "Non-nil means use colors in agenda views."
137 :group 'org-agenda-export
138 :type 'boolean)
140 (defcustom org-agenda-exporter-settings nil
141 "Alist of variable/value pairs that should be active during agenda export.
142 This is a good place to set options for ps-print and for htmlize.
143 Note that the way this is implemented, the values will be evaluated
144 before assigned to the variables. So make sure to quote values you do
145 *not* want evaluated, for example
147 (setq org-agenda-exporter-settings
148 '((ps-print-color-p 'black-white)))"
149 :group 'org-agenda-export
150 :type '(repeat
151 (list
152 (variable)
153 (sexp :tag "Value"))))
155 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
156 "Hook run in temporary buffer before writing it to an export file.
157 A useful function is `org-agenda-add-entry-text'."
158 :group 'org-agenda-export
159 :type 'hook
160 :options '(org-agenda-add-entry-text))
162 (defcustom org-agenda-add-entry-text-maxlines 0
163 "Maximum number of entry text lines to be added to agenda.
164 This is only relevant when `org-agenda-add-entry-text' is part of
165 `org-agenda-before-write-hook', which it is by default.
166 When this is 0, nothing will happen. When it is greater than 0, it
167 specifies the maximum number of lines that will be added for each entry
168 that is listed in the agenda view.
170 Note that this variable is not used during display, only when exporting
171 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
172 and `org-agenda-entry-text-maxlines'."
173 :group 'org-agenda
174 :type 'integer)
176 (defcustom org-agenda-add-entry-text-descriptive-links t
177 "Non-nil means export org-links as descriptive links in agenda added text.
178 This variable applies to the text added to the agenda when
179 `org-agenda-add-entry-text-maxlines' is larger than 0.
180 When this variable nil, the URL will (also) be shown."
181 :group 'org-agenda
182 :type 'boolean)
184 (defcustom org-agenda-export-html-style ""
185 "The style specification for exported HTML Agenda files.
186 If this variable contains a string, it will replace the default <style>
187 section as produced by `htmlize'.
188 Since there are different ways of setting style information, this variable
189 needs to contain the full HTML structure to provide a style, including the
190 surrounding HTML tags. The style specifications should include definitions
191 the fonts used by the agenda, here is an example:
193 <style type=\"text/css\">
194 p { font-weight: normal; color: gray; }
195 .org-agenda-structure {
196 font-size: 110%;
197 color: #003399;
198 font-weight: 600;
200 .org-todo {
201 color: #cc6666;
202 font-weight: bold;
204 .org-agenda-done {
205 color: #339933;
207 .org-done {
208 color: #339933;
210 .title { text-align: center; }
211 .todo, .deadline { color: red; }
212 .done { color: green; }
213 </style>
215 or, if you want to keep the style in a file,
217 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
219 As the value of this option simply gets inserted into the HTML <head> header,
220 you can \"misuse\" it to also add other text to the header. However,
221 <style>...</style> is required, if not present the variable will be ignored."
222 :group 'org-agenda-export
223 :group 'org-export-html
224 :type 'string)
226 (defcustom org-agenda-persistent-filter nil
227 "When set, keep filters from one agenda view to the next."
228 :group 'org-agenda
229 :type 'boolean)
231 (defgroup org-agenda-custom-commands nil
232 "Options concerning agenda views in Org-mode."
233 :tag "Org Agenda Custom Commands"
234 :group 'org-agenda)
236 (defconst org-sorting-choice
237 '(choice
238 (const time-up) (const time-down)
239 (const category-keep) (const category-up) (const category-down)
240 (const tag-down) (const tag-up)
241 (const priority-up) (const priority-down)
242 (const todo-state-up) (const todo-state-down)
243 (const effort-up) (const effort-down)
244 (const habit-up) (const habit-down)
245 (const alpha-up) (const alpha-down)
246 (const user-defined-up) (const user-defined-down))
247 "Sorting choices.")
249 ;; Keep custom values for `org-agenda-filter-preset' compatible with
250 ;; the new variable `org-agenda-tag-filter-preset'.
251 (if (fboundp 'defvaralias)
252 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
253 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
255 (defconst org-agenda-custom-commands-local-options
256 `(repeat :tag "Local settings for this command. Remember to quote values"
257 (choice :tag "Setting"
258 (list :tag "Heading for this block"
259 (const org-agenda-overriding-header)
260 (string :tag "Headline"))
261 (list :tag "Files to be searched"
262 (const org-agenda-files)
263 (list
264 (const :format "" quote)
265 (repeat (file))))
266 (list :tag "Sorting strategy"
267 (const org-agenda-sorting-strategy)
268 (list
269 (const :format "" quote)
270 (repeat
271 ,org-sorting-choice)))
272 (list :tag "Prefix format"
273 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
274 (string))
275 (list :tag "Number of days in agenda"
276 (const org-agenda-span)
277 (choice (const :tag "Day" 'day)
278 (const :tag "Week" 'week)
279 (const :tag "Month" 'month)
280 (const :tag "Year" 'year)
281 (integer :tag "Custom")))
282 (list :tag "Fixed starting date"
283 (const org-agenda-start-day)
284 (string :value "2007-11-01"))
285 (list :tag "Start on day of week"
286 (const org-agenda-start-on-weekday)
287 (choice :value 1
288 (const :tag "Today" nil)
289 (integer :tag "Weekday No.")))
290 (list :tag "Include data from diary"
291 (const org-agenda-include-diary)
292 (boolean))
293 (list :tag "Deadline Warning days"
294 (const org-deadline-warning-days)
295 (integer :value 1))
296 (list :tag "Category filter preset"
297 (const org-agenda-category-filter-preset)
298 (list
299 (const :format "" quote)
300 (repeat
301 (string :tag "+category or -category"))))
302 (list :tag "Tags filter preset"
303 (const org-agenda-tag-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+tag or -tag"))))
308 (list :tag "Set daily/weekly entry types"
309 (const org-agenda-entry-types)
310 (list
311 (const :format "" quote)
312 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
313 (const :deadline)
314 (const :scheduled)
315 (const :timestamp)
316 (const :sexp))))
317 (list :tag "Standard skipping condition"
318 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
319 (const org-agenda-skip-function)
320 (list
321 (const :format "" quote)
322 (list
323 (choice
324 :tag "Skipping range"
325 (const :tag "Skip entry" org-agenda-skip-entry-if)
326 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
327 (repeat :inline t :tag "Conditions for skipping"
328 (choice
329 :tag "Condition type"
330 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
331 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
332 (list :tag "TODO state is" :inline t
333 (const 'todo)
334 (choice
335 (const :tag "any not-done state" 'todo)
336 (const :tag "any done state" 'done)
337 (const :tag "any state" 'any)
338 (list :tag "Keyword list"
339 (const :format "" quote)
340 (repeat (string :tag "Keyword")))))
341 (list :tag "TODO state is not" :inline t
342 (const 'nottodo)
343 (choice
344 (const :tag "any not-done state" 'todo)
345 (const :tag "any done state" 'done)
346 (const :tag "any state" 'any)
347 (list :tag "Keyword list"
348 (const :format "" quote)
349 (repeat (string :tag "Keyword")))))
350 (const :tag "scheduled" 'scheduled)
351 (const :tag "not scheduled" 'notscheduled)
352 (const :tag "deadline" 'deadline)
353 (const :tag "no deadline" 'notdeadline)
354 (const :tag "timestamp" 'timestamp)
355 (const :tag "no timestamp" 'nottimestamp))))))
356 (list :tag "Non-standard skipping condition"
357 :value (org-agenda-skip-function)
358 (const org-agenda-skip-function)
359 (sexp :tag "Function or form (quoted!)"))
360 (list :tag "Any variable"
361 (variable :tag "Variable")
362 (sexp :tag "Value (sexp)"))))
363 "Selection of examples for agenda command settings.
364 This will be spliced into the custom type of
365 `org-agenda-custom-commands'.")
368 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
369 ((agenda "") (alltodo))))
370 "Custom commands for the agenda.
371 These commands will be offered on the splash screen displayed by the
372 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
374 (key desc type match settings files)
376 key The key (one or more characters as a string) to be associated
377 with the command.
378 desc A description of the command, when omitted or nil, a default
379 description is built using MATCH.
380 type The command type, any of the following symbols:
381 agenda The daily/weekly agenda.
382 todo Entries with a specific TODO keyword, in all agenda files.
383 search Entries containing search words entry or headline.
384 tags Tags/Property/TODO match in all agenda files.
385 tags-todo Tags/P/T match in all agenda files, TODO entries only.
386 todo-tree Sparse tree of specific TODO keyword in *current* file.
387 tags-tree Sparse tree with all tags matches in *current* file.
388 occur-tree Occur sparse tree for *current* file.
389 ... A user-defined function.
390 match What to search for:
391 - a single keyword for TODO keyword searches
392 - a tags match expression for tags searches
393 - a word search expression for text searches.
394 - a regular expression for occur searches
395 For all other commands, this should be the empty string.
396 settings A list of option settings, similar to that in a let form, so like
397 this: ((opt1 val1) (opt2 val2) ...). The values will be
398 evaluated at the moment of execution, so quote them when needed.
399 files A list of files file to write the produced agenda buffer to
400 with the command `org-store-agenda-views'.
401 If a file name ends in \".html\", an HTML version of the buffer
402 is written out. If it ends in \".ps\", a postscript version is
403 produced. Otherwise, only the plain text is written to the file.
405 You can also define a set of commands, to create a composite agenda buffer.
406 In this case, an entry looks like this:
408 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
410 where
412 desc A description string to be displayed in the dispatcher menu.
413 cmd An agenda command, similar to the above. However, tree commands
414 are not allowed, but instead you can get agenda and global todo list.
415 So valid commands for a set are:
416 (agenda \"\" settings)
417 (alltodo \"\" settings)
418 (stuck \"\" settings)
419 (todo \"match\" settings files)
420 (search \"match\" settings files)
421 (tags \"match\" settings files)
422 (tags-todo \"match\" settings files)
424 Each command can carry a list of options, and another set of options can be
425 given for the whole set of commands. Individual command options take
426 precedence over the general options.
428 When using several characters as key to a command, the first characters
429 are prefix commands. For the dispatcher to display useful information, you
430 should provide a description for the prefix, like
432 (setq org-agenda-custom-commands
433 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
434 (\"hl\" tags \"+HOME+Lisa\")
435 (\"hp\" tags \"+HOME+Peter\")
436 (\"hk\" tags \"+HOME+Kim\")))"
437 :group 'org-agenda-custom-commands
438 :type `(repeat
439 (choice :value ("x" "Describe command here" tags "" nil)
440 (list :tag "Single command"
441 (string :tag "Access Key(s) ")
442 (option (string :tag "Description"))
443 (choice
444 (const :tag "Agenda" agenda)
445 (const :tag "TODO list" alltodo)
446 (const :tag "Search words" search)
447 (const :tag "Stuck projects" stuck)
448 (const :tag "Tags/Property match (all agenda files)" tags)
449 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
450 (const :tag "TODO keyword search (all agenda files)" todo)
451 (const :tag "Tags sparse tree (current buffer)" tags-tree)
452 (const :tag "TODO keyword tree (current buffer)" todo-tree)
453 (const :tag "Occur tree (current buffer)" occur-tree)
454 (sexp :tag "Other, user-defined function"))
455 (string :tag "Match (only for some commands)")
456 ,org-agenda-custom-commands-local-options
457 (option (repeat :tag "Export" (file :tag "Export to"))))
458 (list :tag "Command series, all agenda files"
459 (string :tag "Access Key(s)")
460 (string :tag "Description ")
461 (repeat :tag "Component"
462 (choice
463 (list :tag "Agenda"
464 (const :format "" agenda)
465 (const :tag "" :format "" "")
466 ,org-agenda-custom-commands-local-options)
467 (list :tag "TODO list (all keywords)"
468 (const :format "" alltodo)
469 (const :tag "" :format "" "")
470 ,org-agenda-custom-commands-local-options)
471 (list :tag "Search words"
472 (const :format "" search)
473 (string :tag "Match")
474 ,org-agenda-custom-commands-local-options)
475 (list :tag "Stuck projects"
476 (const :format "" stuck)
477 (const :tag "" :format "" "")
478 ,org-agenda-custom-commands-local-options)
479 (list :tag "Tags search"
480 (const :format "" tags)
481 (string :tag "Match")
482 ,org-agenda-custom-commands-local-options)
483 (list :tag "Tags search, TODO entries only"
484 (const :format "" tags-todo)
485 (string :tag "Match")
486 ,org-agenda-custom-commands-local-options)
487 (list :tag "TODO keyword search"
488 (const :format "" todo)
489 (string :tag "Match")
490 ,org-agenda-custom-commands-local-options)
491 (list :tag "Other, user-defined function"
492 (symbol :tag "function")
493 (string :tag "Match")
494 ,org-agenda-custom-commands-local-options)))
496 (repeat :tag "Settings for entire command set"
497 (list (variable :tag "Any variable")
498 (sexp :tag "Value")))
499 (option (repeat :tag "Export" (file :tag "Export to"))))
500 (cons :tag "Prefix key documentation"
501 (string :tag "Access Key(s)")
502 (string :tag "Description ")))))
504 (defcustom org-agenda-query-register ?o
505 "The register holding the current query string.
506 The purpose of this is that if you construct a query string interactively,
507 you can then use it to define a custom command."
508 :group 'org-agenda-custom-commands
509 :type 'character)
511 (defcustom org-stuck-projects
512 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
513 "How to identify stuck projects.
514 This is a list of four items:
515 1. A tags/todo/property matcher string that is used to identify a project.
516 See the manual for a description of tag and property searches.
517 The entire tree below a headline matched by this is considered one project.
518 2. A list of TODO keywords identifying non-stuck projects.
519 If the project subtree contains any headline with one of these todo
520 keywords, the project is considered to be not stuck. If you specify
521 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
522 3. A list of tags identifying non-stuck projects.
523 If the project subtree contains any headline with one of these tags,
524 the project is considered to be not stuck. If you specify \"*\" as
525 a tag, any tag will mark the project unstuck. Note that this is about
526 the explicit presence of a tag somewhere in the subtree, inherited
527 tags to not count here. If inherited tags make a project not stuck,
528 use \"-TAG\" in the tags part of the matcher under (1.) above.
529 4. An arbitrary regular expression matching non-stuck projects.
531 If the project turns out to be not stuck, search continues also in the
532 subtree to see if any of the subtasks have project status.
534 See also the variable `org-tags-match-list-sublevels' which applies
535 to projects matched by this search as well.
537 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
538 or `C-c a #' to produce the list."
539 :group 'org-agenda-custom-commands
540 :type '(list
541 (string :tag "Tags/TODO match to identify a project")
542 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
543 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
544 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
546 (defcustom org-agenda-filter-effort-default-operator "<"
547 "The default operator for effort estimate filtering.
548 If you select an effort estimate limit without first pressing an operator,
549 this one will be used."
550 :group 'org-agenda-custom-commands
551 :type '(choice (const :tag "less or equal" "<")
552 (const :tag "greater or equal"">")
553 (const :tag "equal" "=")))
555 (defgroup org-agenda-skip nil
556 "Options concerning skipping parts of agenda files."
557 :tag "Org Agenda Skip"
558 :group 'org-agenda)
560 (defcustom org-agenda-skip-function-global nil
561 "Function to be called at each match during agenda construction.
562 If this function returns nil, the current match should not be skipped.
563 If the function decided to skip an agenda match, is must return the
564 buffer position from which the search should be continued.
565 This may also be a Lisp form, which will be evaluated.
567 This variable will be applied to every agenda match, including
568 tags/property searches and TODO lists. So try to make the test function
569 do its checking as efficiently as possible. To implement a skipping
570 condition just for specific agenda commands, use the variable
571 `org-agenda-skip-function' which can be set in the options section
572 of custom agenda commands."
573 :group 'org-agenda-skip
574 :type 'sexp)
576 (defgroup org-agenda-daily/weekly nil
577 "Options concerning the daily/weekly agenda."
578 :tag "Org Agenda Daily/Weekly"
579 :group 'org-agenda)
580 (defgroup org-agenda-todo-list nil
581 "Options concerning the global todo list agenda view."
582 :tag "Org Agenda Todo List"
583 :group 'org-agenda)
584 (defgroup org-agenda-match-view nil
585 "Options concerning the general tags/property/todo match agenda view."
586 :tag "Org Agenda Match View"
587 :group 'org-agenda)
588 (defgroup org-agenda-search-view nil
589 "Options concerning the general tags/property/todo match agenda view."
590 :tag "Org Agenda Match View"
591 :group 'org-agenda)
593 (defvar org-agenda-archives-mode nil
594 "Non-nil means the agenda will include archived items.
595 If this is the symbol `trees', trees in the selected agenda scope
596 that are marked with the ARCHIVE tag will be included anyway. When this is
597 t, also all archive files associated with the current selection of agenda
598 files will be included.")
600 (defcustom org-agenda-skip-comment-trees t
601 "Non-nil means skip trees that start with the COMMENT keyword.
602 When nil, these trees are also scanned by agenda commands."
603 :group 'org-agenda-skip
604 :type 'boolean)
606 (defcustom org-agenda-todo-list-sublevels t
607 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
608 When nil, the sublevels of a TODO entry are not checked, resulting in
609 potentially much shorter TODO lists."
610 :group 'org-agenda-skip
611 :group 'org-agenda-todo-list
612 :type 'boolean)
614 (defcustom org-agenda-todo-ignore-with-date nil
615 "Non-nil means don't show entries with a date in the global todo list.
616 You can use this if you prefer to mark mere appointments with a TODO keyword,
617 but don't want them to show up in the TODO list.
618 When this is set, it also covers deadlines and scheduled items, the settings
619 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
620 will be ignored.
621 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
622 :group 'org-agenda-skip
623 :group 'org-agenda-todo-list
624 :type 'boolean)
626 (defcustom org-agenda-todo-ignore-timestamp nil
627 "Non-nil means don't show entries with a timestamp.
628 This applies when creating the global todo list.
629 Valid values are:
631 past Don't show entries for today or in the past.
633 future Don't show entries with a timestamp in the future.
634 The idea behind this is that if it has a future
635 timestamp, you don't want to think about it until the
636 date.
638 all Don't show any entries with a timestamp in the global todo list.
639 The idea behind this is that by setting a timestamp, you
640 have already \"taken care\" of this item.
642 This variable can also have an integer as a value. If positive (N),
643 todos with a timestamp N or more days in the future will be ignored. If
644 negative (-N), todos with a timestamp N or more days in the past will be
645 ignored. If 0, todos with a timestamp either today or in the future will
646 be ignored. For example, a value of -1 will exclude todos with a
647 timestamp in the past (yesterday or earlier), while a value of 7 will
648 exclude todos with a timestamp a week or more in the future.
650 See also `org-agenda-todo-ignore-with-date'.
651 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
652 to make his option also apply to the tags-todo list."
653 :group 'org-agenda-skip
654 :group 'org-agenda-todo-list
655 :version "24.1"
656 :type '(choice
657 (const :tag "Ignore future timestamp todos" future)
658 (const :tag "Ignore past or present timestamp todos" past)
659 (const :tag "Ignore all timestamp todos" all)
660 (const :tag "Show timestamp todos" nil)
661 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
663 (defcustom org-agenda-todo-ignore-scheduled nil
664 "Non-nil means, ignore some scheduled TODO items when making TODO list.
665 This applies when creating the global todo list.
666 Valid values are:
668 past Don't show entries scheduled today or in the past.
670 future Don't show entries scheduled in the future.
671 The idea behind this is that by scheduling it, you don't want to
672 think about it until the scheduled date.
674 all Don't show any scheduled entries in the global todo list.
675 The idea behind this is that by scheduling it, you have already
676 \"taken care\" of this item.
678 t Same as `all', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group 'org-agenda-skip
687 :group 'org-agenda-todo-list
688 :type '(choice
689 (const :tag "Ignore future-scheduled todos" future)
690 (const :tag "Ignore past- or present-scheduled todos" past)
691 (const :tag "Ignore all scheduled todos" all)
692 (const :tag "Ignore all scheduled todos (compatibility)" t)
693 (const :tag "Show scheduled todos" nil)
694 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-todo-ignore-deadlines nil
697 "Non-nil means ignore some deadlined TODO items when making TODO list.
698 There are different motivations for using different values, please think
699 carefully when configuring this variable.
701 This applies when creating the global todo list.
702 Valid values are:
704 near Don't show near deadline entries. A deadline is near when it is
705 closer than `org-deadline-warning-days' days. The idea behind this
706 is that such items will appear in the agenda anyway.
708 far Don't show TODO entries where a deadline has been defined, but
709 the deadline is not near. This is useful if you don't want to
710 use the todo list to figure out what to do now.
712 past Don't show entries with a deadline timestamp for today or in the past.
714 future Don't show entries with a deadline timestamp in the future, not even
715 when they become `near' ones. Use it with caution.
717 all Ignore all TODO entries that do have a deadline.
719 t Same as `near', for backward compatibility.
721 This variable can also have an integer as a value. See
722 `org-agenda-todo-ignore-timestamp' for more details.
724 See also `org-agenda-todo-ignore-with-date'.
725 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
726 to make his option also apply to the tags-todo list."
727 :group 'org-agenda-skip
728 :group 'org-agenda-todo-list
729 :type '(choice
730 (const :tag "Ignore near deadlines" near)
731 (const :tag "Ignore near deadlines (compatibility)" t)
732 (const :tag "Ignore far deadlines" far)
733 (const :tag "Ignore all TODOs with a deadlines" all)
734 (const :tag "Show all TODOs, even if they have a deadline" nil)
735 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
737 (defcustom org-agenda-tags-todo-honor-ignore-options nil
738 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
739 The variables
740 `org-agenda-todo-ignore-with-date',
741 `org-agenda-todo-ignore-timestamp',
742 `org-agenda-todo-ignore-scheduled',
743 `org-agenda-todo-ignore-deadlines'
744 make the global TODO list skip entries that have time stamps of certain
745 kinds. If this option is set, the same options will also apply for the
746 tags-todo search, which is the general tags/property matcher
747 restricted to unfinished TODO entries only."
748 :group 'org-agenda-skip
749 :group 'org-agenda-todo-list
750 :group 'org-agenda-match-view
751 :type 'boolean)
753 (defcustom org-agenda-skip-scheduled-if-done nil
754 "Non-nil means don't show scheduled items in agenda when they are done.
755 This is relevant for the daily/weekly agenda, not for the TODO list. And
756 it applies only to the actual date of the scheduling. Warnings about
757 an item with a past scheduling dates are always turned off when the item
758 is DONE."
759 :group 'org-agenda-skip
760 :group 'org-agenda-daily/weekly
761 :type 'boolean)
763 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
764 "Non-nil means skip scheduling line if same entry shows because of deadline.
765 In the agenda of today, an entry can show up multiple times because
766 it is both scheduled and has a nearby deadline, and maybe a plain time
767 stamp as well.
768 When this variable is t, then only the deadline is shown and the fact that
769 the entry is scheduled today or was scheduled previously is not shown.
770 When this variable is nil, the entry will be shown several times. When
771 the variable is the symbol `not-today', then skip scheduled previously,
772 but not scheduled today."
773 :group 'org-agenda-skip
774 :group 'org-agenda-daily/weekly
775 :type '(choice
776 (const :tag "Never" nil)
777 (const :tag "Always" t)
778 (const :tag "Not when scheduled today" not-today)))
780 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
781 "Non-nil means skip timestamp line if same entry shows because of deadline.
782 In the agenda of today, an entry can show up multiple times
783 because it has both a plain timestamp and has a nearby deadline.
784 When this variable is t, then only the deadline is shown and the
785 fact that the entry has a timestamp for or including today is not
786 shown. When this variable is nil, the entry will be shown
787 several times."
788 :group 'org-agenda-skip
789 :group 'org-agenda-daily/weekly
790 :version "24.1"
791 :type '(choice
792 (const :tag "Never" nil)
793 (const :tag "Always" t)))
795 (defcustom org-agenda-skip-deadline-if-done nil
796 "Non-nil means don't show deadlines when the corresponding item is done.
797 When nil, the deadline is still shown and should give you a happy feeling.
798 This is relevant for the daily/weekly agenda. And it applied only to the
799 actually date of the deadline. Warnings about approaching and past-due
800 deadlines are always turned off when the item is DONE."
801 :group 'org-agenda-skip
802 :group 'org-agenda-daily/weekly
803 :type 'boolean)
805 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
806 "Non-nil means skip deadline prewarning when entry is also scheduled.
807 This will apply on all days where a prewarning for the deadline would
808 be shown, but not at the day when the entry is actually due. On that day,
809 the deadline will be shown anyway.
810 This variable may be set to nil, t, or a number which will then give
811 the number of days before the actual deadline when the prewarnings
812 should resume.
813 This can be used in a workflow where the first showing of the deadline will
814 trigger you to schedule it, and then you don't want to be reminded of it
815 because you will take care of it on the day when scheduled."
816 :group 'org-agenda-skip
817 :group 'org-agenda-daily/weekly
818 :version "24.1"
819 :type '(choice
820 (const :tag "Alwas show prewarning" nil)
821 (const :tag "Remove prewarning if entry is scheduled" t)
822 (integer :tag "Restart prewarning N days before deadline")))
824 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
825 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
826 When non-nil, after the search for timestamps has matched once in an
827 entry, the rest of the entry will not be searched."
828 :group 'org-agenda-skip
829 :type 'boolean)
831 (defcustom org-agenda-skip-timestamp-if-done nil
832 "Non-nil means don't select item by timestamp or -range if it is DONE."
833 :group 'org-agenda-skip
834 :group 'org-agenda-daily/weekly
835 :type 'boolean)
837 (defcustom org-agenda-dim-blocked-tasks t
838 "Non-nil means dim blocked tasks in the agenda display.
839 This causes some overhead during agenda construction, but if you
840 have turned on `org-enforce-todo-dependencies',
841 `org-enforce-todo-checkbox-dependencies', or any other blocking
842 mechanism, this will create useful feedback in the agenda.
844 Instead of t, this variable can also have the value `invisible'.
845 Then blocked tasks will be invisible and only become visible when
846 they become unblocked. An exemption to this behavior is when a task is
847 blocked because of unchecked checkboxes below it. Since checkboxes do
848 not show up in the agenda views, making this task invisible you remove any
849 trace from agenda views that there is something to do. Therefore, a task
850 that is blocked because of checkboxes will never be made invisible, it
851 will only be dimmed."
852 :group 'org-agenda-daily/weekly
853 :group 'org-agenda-todo-list
854 :type '(choice
855 (const :tag "Do not dim" nil)
856 (const :tag "Dim to a gray face" t)
857 (const :tag "Make invisible" invisible)))
859 (defcustom org-timeline-show-empty-dates 3
860 "Non-nil means `org-timeline' also shows dates without an entry.
861 When nil, only the days which actually have entries are shown.
862 When t, all days between the first and the last date are shown.
863 When an integer, show also empty dates, but if there is a gap of more than
864 N days, just insert a special line indicating the size of the gap."
865 :group 'org-agenda-skip
866 :type '(choice
867 (const :tag "None" nil)
868 (const :tag "All" t)
869 (integer :tag "at most")))
871 (defgroup org-agenda-startup nil
872 "Options concerning initial settings in the Agenda in Org Mode."
873 :tag "Org Agenda Startup"
874 :group 'org-agenda)
876 (defcustom org-agenda-menu-show-matcher t
877 "Non-nil means show the match string in the agenda dispatcher menu.
878 When nil, the matcher string is not shown, but is put into the help-echo
879 property so than moving the mouse over the command shows it.
880 Setting it to nil is good if matcher strings are very long and/or if
881 you want to use two-column display (see `org-agenda-menu-two-column')."
882 :group 'org-agenda
883 :version "24.1"
884 :type 'boolean)
886 (defcustom org-agenda-menu-two-column nil
887 "Non-nil means, use two columns to show custom commands in the dispatcher.
888 If you use this, you probably want to set `org-agenda-menu-show-matcher'
889 to nil."
890 :group 'org-agenda
891 :version "24.1"
892 :type 'boolean)
894 (defcustom org-finalize-agenda-hook nil
895 "Hook run just before displaying an agenda buffer."
896 :group 'org-agenda-startup
897 :type 'hook)
899 (defcustom org-agenda-mouse-1-follows-link nil
900 "Non-nil means mouse-1 on a link will follow the link in the agenda.
901 A longer mouse click will still set point. Does not work on XEmacs.
902 Needs to be set before org.el is loaded."
903 :group 'org-agenda-startup
904 :type 'boolean)
906 (defcustom org-agenda-start-with-follow-mode nil
907 "The initial value of follow mode in a newly created agenda window."
908 :group 'org-agenda-startup
909 :type 'boolean)
911 (defcustom org-agenda-follow-indirect nil
912 "Non-nil means `org-agenda-follow-mode' displays only the
913 current item's tree, in an indirect buffer."
914 :group 'org-agenda
915 :version "24.1"
916 :type 'boolean)
918 (defcustom org-agenda-show-outline-path t
919 "Non-nil means show outline path in echo area after line motion."
920 :group 'org-agenda-startup
921 :type 'boolean)
923 (defcustom org-agenda-start-with-entry-text-mode nil
924 "The initial value of entry-text-mode in a newly created agenda window."
925 :group 'org-agenda-startup
926 :type 'boolean)
928 (defcustom org-agenda-entry-text-maxlines 5
929 "Number of text lines to be added when `E' is pressed in the agenda.
931 Note that this variable only used during agenda display. Add add entry text
932 when exporting the agenda, configure the variable
933 `org-agenda-add-entry-ext-maxlines'."
934 :group 'org-agenda
935 :type 'integer)
937 (defcustom org-agenda-entry-text-exclude-regexps nil
938 "List of regular expressions to clean up entry text.
939 The complete matches of all regular expressions in this list will be
940 removed from entry text before it is shown in the agenda."
941 :group 'org-agenda
942 :type '(repeat (regexp)))
944 (defvar org-agenda-entry-text-cleanup-hook nil
945 "Hook that is run after basic cleanup of entry text to be shown in agenda.
946 This cleanup is done in a temporary buffer, so the function may inspect and
947 change the entire buffer.
948 Some default stuff like drawers and scheduling/deadline dates will already
949 have been removed when this is called, as will any matches for regular
950 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
952 (defvar org-agenda-include-inactive-timestamps nil
953 "Non-nil means include inactive time stamps in agenda and timeline.
954 Dynamically scoped.")
956 (defgroup org-agenda-windows nil
957 "Options concerning the windows used by the Agenda in Org Mode."
958 :tag "Org Agenda Windows"
959 :group 'org-agenda)
961 (defcustom org-agenda-window-setup 'reorganize-frame
962 "How the agenda buffer should be displayed.
963 Possible values for this option are:
965 current-window Show agenda in the current window, keeping all other windows.
966 other-window Use `switch-to-buffer-other-window' to display agenda.
967 reorganize-frame Show only two windows on the current frame, the current
968 window and the agenda.
969 other-frame Use `switch-to-buffer-other-frame' to display agenda.
970 Also, when exiting the agenda, kill that frame.
971 See also the variable `org-agenda-restore-windows-after-quit'."
972 :group 'org-agenda-windows
973 :type '(choice
974 (const current-window)
975 (const other-frame)
976 (const other-window)
977 (const reorganize-frame)))
979 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
980 "The min and max height of the agenda window as a fraction of frame height.
981 The value of the variable is a cons cell with two numbers between 0 and 1.
982 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
983 :group 'org-agenda-windows
984 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
986 (defcustom org-agenda-restore-windows-after-quit nil
987 "Non-nil means restore window configuration upon exiting agenda.
988 Before the window configuration is changed for displaying the agenda,
989 the current status is recorded. When the agenda is exited with
990 `q' or `x' and this option is set, the old state is restored. If
991 `org-agenda-window-setup' is `other-frame', the value of this
992 option will be ignored."
993 :group 'org-agenda-windows
994 :type 'boolean)
996 (defcustom org-agenda-ndays nil
997 "Number of days to include in overview display.
998 Should be 1 or 7.
999 Obsolete, see `org-agenda-span'."
1000 :group 'org-agenda-daily/weekly
1001 :type 'integer)
1003 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1005 (defcustom org-agenda-span 'week
1006 "Number of days to include in overview display.
1007 Can be day, week, month, year, or any number of days.
1008 Custom commands can set this variable in the options section."
1009 :group 'org-agenda-daily/weekly
1010 :type '(choice (const :tag "Day" day)
1011 (const :tag "Week" week)
1012 (const :tag "Month" month)
1013 (const :tag "Year" year)
1014 (integer :tag "Custom")))
1016 (defcustom org-agenda-start-on-weekday 1
1017 "Non-nil means start the overview always on the specified weekday.
1018 0 denotes Sunday, 1 denotes Monday etc.
1019 When nil, always start on the current day.
1020 Custom commands can set this variable in the options section."
1021 :group 'org-agenda-daily/weekly
1022 :type '(choice (const :tag "Today" nil)
1023 (integer :tag "Weekday No.")))
1025 (defcustom org-agenda-show-all-dates t
1026 "Non-nil means `org-agenda' shows every day in the selected range.
1027 When nil, only the days which actually have entries are shown."
1028 :group 'org-agenda-daily/weekly
1029 :type 'boolean)
1031 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1032 "Format string for displaying dates in the agenda.
1033 Used by the daily/weekly agenda and by the timeline. This should be
1034 a format string understood by `format-time-string', or a function returning
1035 the formatted date as a string. The function must take a single argument,
1036 a calendar-style date list like (month day year)."
1037 :group 'org-agenda-daily/weekly
1038 :type '(choice
1039 (string :tag "Format string")
1040 (function :tag "Function")))
1042 (defun org-agenda-format-date-aligned (date)
1043 "Format a date string for display in the daily/weekly agenda, or timeline.
1044 This function makes sure that dates are aligned for easy reading."
1045 (require 'cal-iso)
1046 (let* ((dayname (calendar-day-name date))
1047 (day (cadr date))
1048 (day-of-week (calendar-day-of-week date))
1049 (month (car date))
1050 (monthname (calendar-month-name month))
1051 (year (nth 2 date))
1052 (iso-week (org-days-to-iso-week
1053 (calendar-absolute-from-gregorian date)))
1054 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1055 (1- year))
1056 ((and (= month 12) (<= iso-week 1))
1057 (1+ year))
1058 (t year)))
1059 (weekstring (if (= day-of-week 1)
1060 (format " W%02d" iso-week)
1061 "")))
1062 (format "%-10s %2d %s %4d%s"
1063 dayname day monthname year weekstring)))
1065 (defcustom org-agenda-time-leading-zero nil
1066 "Non-nil means use leading zero for military times in agenda.
1067 For example, 9:30am would become 09:30 rather than 9:30."
1068 :group 'org-agenda-daily/weekly
1069 :version "24.1"
1070 :type 'boolean)
1072 (defcustom org-agenda-timegrid-use-ampm nil
1073 "When set, show AM/PM style timestamps on the timegrid."
1074 :group 'org-agenda
1075 :version "24.1"
1076 :type 'boolean)
1078 (defun org-agenda-time-of-day-to-ampm (time)
1079 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1080 (let* ((hour-number (string-to-number (substring time 0 -3)))
1081 (minute (substring time -2))
1082 (ampm "am"))
1083 (cond
1084 ((equal hour-number 12)
1085 (setq ampm "pm"))
1086 ((> hour-number 12)
1087 (setq ampm "pm")
1088 (setq hour-number (- hour-number 12))))
1089 (concat
1090 (if org-agenda-time-leading-zero
1091 (format "%02d" hour-number)
1092 (format "%02s" (number-to-string hour-number)))
1093 ":" minute ampm)))
1095 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1096 "Conditionally convert TIME to AM/PM format
1097 based on `org-agenda-timegrid-use-ampm'"
1098 (if org-agenda-timegrid-use-ampm
1099 (org-agenda-time-of-day-to-ampm time)
1100 time))
1102 (defcustom org-agenda-weekend-days '(6 0)
1103 "Which days are weekend?
1104 These days get the special face `org-agenda-date-weekend' in the agenda
1105 and timeline buffers."
1106 :group 'org-agenda-daily/weekly
1107 :type '(set :greedy t
1108 (const :tag "Monday" 1)
1109 (const :tag "Tuesday" 2)
1110 (const :tag "Wednesday" 3)
1111 (const :tag "Thursday" 4)
1112 (const :tag "Friday" 5)
1113 (const :tag "Saturday" 6)
1114 (const :tag "Sunday" 0)))
1116 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1117 "Non-nil means jump to today when moving a past date forward in time.
1118 When using S-right in the agenda to move a a date forward, and the date
1119 stamp currently points to the past, the first key press will move it
1120 to today. WHen nil, just move one day forward even if the date stays
1121 in the past."
1122 :group 'org-agenda-daily/weekly
1123 :version "24.1"
1124 :type 'boolean)
1126 (defcustom org-agenda-include-diary nil
1127 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1128 Custom commands can set this variable in the options section."
1129 :group 'org-agenda-daily/weekly
1130 :type 'boolean)
1132 (defcustom org-agenda-include-deadlines t
1133 "If non-nil, include entries within their deadline warning period.
1134 Custom commands can set this variable in the options section."
1135 :group 'org-agenda-daily/weekly
1136 :version "24.1"
1137 :type 'boolean)
1139 (defcustom org-agenda-repeating-timestamp-show-all t
1140 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1141 When set to a list of strings, only show occurrences of repeating
1142 stamps for these TODO keywords. When nil, only one occurrence is
1143 shown, either today or the nearest into the future."
1144 :group 'org-agenda-daily/weekly
1145 :type '(choice
1146 (const :tag "Show repeating stamps" t)
1147 (repeat :tag "Show repeating stamps for these TODO keywords"
1148 (string :tag "TODO Keyword"))
1149 (const :tag "Don't show repeating stamps" nil)))
1151 (defcustom org-scheduled-past-days 10000
1152 "No. of days to continue listing scheduled items that are not marked DONE.
1153 When an item is scheduled on a date, it shows up in the agenda on this
1154 day and will be listed until it is marked done for the number of days
1155 given here."
1156 :group 'org-agenda-daily/weekly
1157 :type 'integer)
1159 (defcustom org-agenda-log-mode-items '(closed clock)
1160 "List of items that should be shown in agenda log mode.
1161 This list may contain the following symbols:
1163 closed Show entries that have been closed on that day.
1164 clock Show entries that have received clocked time on that day.
1165 state Show all logged state changes.
1166 Note that instead of changing this variable, you can also press `C-u l' in
1167 the agenda to display all available LOG items temporarily."
1168 :group 'org-agenda-daily/weekly
1169 :type '(set :greedy t (const closed) (const clock) (const state)))
1171 (defcustom org-agenda-clock-consistency-checks
1172 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1173 :gap-ok-around ("4:00")
1174 :default-face ((:background "DarkRed") (:foreground "white"))
1175 :overlap-face nil :gap-face nil :no-end-time-face nil
1176 :long-face nil :short-face nil)
1177 "This is a property list, with the following keys:
1179 :max-duration Mark clocking chunks that are longer than this time.
1180 This is a time string like \"HH:MM\", or the number
1181 of minutes as an integer.
1183 :min-duration Mark clocking chunks that are shorter that this.
1184 This is a time string like \"HH:MM\", or the number
1185 of minutes as an integer.
1187 :max-gap Mark gaps between clocking chunks that are longer than
1188 this duration. A number of minutes, or a string
1189 like \"HH:MM\".
1191 :gap-ok-around List of times during the day which are usually not working
1192 times. When a gap is detected, but the gap contains any
1193 of these times, the gap is *not* reported. For example,
1194 if this is (\"4:00\" \"13:00\") then gaps that contain
1195 4:00 in the morning (i.e. the night) and 13:00
1196 (i.e. a typical lunch time) do not cause a warning.
1197 You should have at least one time during the night in this
1198 list, or otherwise the first task each morning will trigger
1199 a warning because it follows a long gap.
1201 Furthermore, the following properties can be used to define faces for
1202 issue display.
1204 :default-face the default face, if the specific face is undefined
1205 :overlap-face face for overlapping clocks
1206 :gap-face face for gaps between clocks
1207 :no-end-time-face face for incomplete clocks
1208 :long-face face for clock intervals that are too long
1209 :short-face face for clock intervals that are too short"
1210 :group 'org-agenda-daily/weekly
1211 :group 'org-clock
1212 :version "24.1"
1213 :type 'plist)
1215 (defcustom org-agenda-log-mode-add-notes t
1216 "Non-nil means add first line of notes to log entries in agenda views.
1217 If a log item like a state change or a clock entry is associated with
1218 notes, the first line of these notes will be added to the entry in the
1219 agenda display."
1220 :group 'org-agenda-daily/weekly
1221 :type 'boolean)
1223 (defcustom org-agenda-start-with-log-mode nil
1224 "The initial value of log-mode in a newly created agenda window.
1225 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1226 explanations on the possible values."
1227 :group 'org-agenda-startup
1228 :group 'org-agenda-daily/weekly
1229 :type '(choice (const :tag "Don't show log items" nil)
1230 (const :tag "Show only log items" 'only)
1231 (const :tag "Show all possible log items" 'clockcheck)
1232 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1233 (choice (const :tag "Show closed log items" 'closed)
1234 (const :tag "Show clocked log items" 'clock)
1235 (const :tag "Show all logged state changes" 'state)))))
1237 (defcustom org-agenda-start-with-clockreport-mode nil
1238 "The initial value of clockreport-mode in a newly created agenda window."
1239 :group 'org-agenda-startup
1240 :group 'org-agenda-daily/weekly
1241 :type 'boolean)
1243 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1244 "Property list with parameters for the clocktable in clockreport mode.
1245 This is the display mode that shows a clock table in the daily/weekly
1246 agenda, the properties for this dynamic block can be set here.
1247 The usual clocktable parameters are allowed here, but you cannot set
1248 the properties :name, :tstart, :tend, :block, and :scope - these will
1249 be overwritten to make sure the content accurately reflects the
1250 current display in the agenda."
1251 :group 'org-agenda-daily/weekly
1252 :type 'plist)
1254 (defcustom org-agenda-search-view-always-boolean nil
1255 "Non-nil means the search string is interpreted as individual parts.
1257 The search string for search view can either be interpreted as a phrase,
1258 or as a list of snippets that define a boolean search for a number of
1259 strings.
1261 When this is non-nil, the string will be split on whitespace, and each
1262 snippet will be searched individually, and all must match in order to
1263 select an entry. A snippet is then a single string of non-white
1264 characters, or a string in double quotes, or a regexp in {} braces.
1265 If a snippet is preceded by \"-\", the snippet must *not* match.
1266 \"+\" is syntactic sugar for positive selection. Each snippet may
1267 be found as a full word or a partial word, but see the variable
1268 `org-agenda-search-view-force-full-words'.
1270 When this is nil, search will look for the entire search phrase as one,
1271 with each space character matching any amount of whitespace, including
1272 line breaks.
1274 Even when this is nil, you can still switch to Boolean search dynamically
1275 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1276 is a regexp marked with braces like \"{abc}\", this will also switch to
1277 boolean search."
1278 :group 'org-agenda-search-view
1279 :version "24.1"
1280 :type 'boolean)
1282 (if (fboundp 'defvaralias)
1283 (defvaralias 'org-agenda-search-view-search-words-only
1284 'org-agenda-search-view-always-boolean))
1286 (defcustom org-agenda-search-view-force-full-words nil
1287 "Non-nil means, search words must be matches as complete words.
1288 When nil, they may also match part of a word."
1289 :group 'org-agenda-search-view
1290 :version "24.1"
1291 :type 'boolean)
1293 (defgroup org-agenda-time-grid nil
1294 "Options concerning the time grid in the Org-mode Agenda."
1295 :tag "Org Agenda Time Grid"
1296 :group 'org-agenda)
1298 (defcustom org-agenda-search-headline-for-time t
1299 "Non-nil means search headline for a time-of-day.
1300 If the headline contains a time-of-day in one format or another, it will
1301 be used to sort the entry into the time sequence of items for a day.
1302 Some people have time stamps in the headline that refer to the creation
1303 time or so, and then this produces an unwanted side effect. If this is
1304 the case for your, use this variable to turn off searching the headline
1305 for a time."
1306 :group 'org-agenda-time-grid
1307 :type 'boolean)
1309 (defcustom org-agenda-use-time-grid t
1310 "Non-nil means show a time grid in the agenda schedule.
1311 A time grid is a set of lines for specific times (like every two hours between
1312 8:00 and 20:00). The items scheduled for a day at specific times are
1313 sorted in between these lines.
1314 For details about when the grid will be shown, and what it will look like, see
1315 the variable `org-agenda-time-grid'."
1316 :group 'org-agenda-time-grid
1317 :type 'boolean)
1319 (defcustom org-agenda-time-grid
1320 '((daily today require-timed)
1321 "----------------"
1322 (800 1000 1200 1400 1600 1800 2000))
1324 "The settings for time grid for agenda display.
1325 This is a list of three items. The first item is again a list. It contains
1326 symbols specifying conditions when the grid should be displayed:
1328 daily if the agenda shows a single day
1329 weekly if the agenda shows an entire week
1330 today show grid on current date, independent of daily/weekly display
1331 require-timed show grid only if at least one item has a time specification
1333 The second item is a string which will be placed behind the grid time.
1335 The third item is a list of integers, indicating the times that should have
1336 a grid line."
1337 :group 'org-agenda-time-grid
1338 :type
1339 '(list
1340 (set :greedy t :tag "Grid Display Options"
1341 (const :tag "Show grid in single day agenda display" daily)
1342 (const :tag "Show grid in weekly agenda display" weekly)
1343 (const :tag "Always show grid for today" today)
1344 (const :tag "Show grid only if any timed entries are present"
1345 require-timed)
1346 (const :tag "Skip grid times already present in an entry"
1347 remove-match))
1348 (string :tag "Grid String")
1349 (repeat :tag "Grid Times" (integer :tag "Time"))))
1351 (defcustom org-agenda-show-current-time-in-grid t
1352 "Non-nil means show the current time in the time grid."
1353 :group 'org-agenda-time-grid
1354 :version "24.1"
1355 :type 'boolean)
1357 (defcustom org-agenda-current-time-string
1358 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1359 "The string for the current time marker in the agenda."
1360 :group 'org-agenda-time-grid
1361 :version "24.1"
1362 :type 'string)
1364 (defgroup org-agenda-sorting nil
1365 "Options concerning sorting in the Org-mode Agenda."
1366 :tag "Org Agenda Sorting"
1367 :group 'org-agenda)
1369 (defcustom org-agenda-sorting-strategy
1370 '((agenda habit-down time-up priority-down category-keep)
1371 (todo priority-down category-keep)
1372 (tags priority-down category-keep)
1373 (search category-keep))
1374 "Sorting structure for the agenda items of a single day.
1375 This is a list of symbols which will be used in sequence to determine
1376 if an entry should be listed before another entry. The following
1377 symbols are recognized:
1379 time-up Put entries with time-of-day indications first, early first
1380 time-down Put entries with time-of-day indications first, late first
1381 category-keep Keep the default order of categories, corresponding to the
1382 sequence in `org-agenda-files'.
1383 category-up Sort alphabetically by category, A-Z.
1384 category-down Sort alphabetically by category, Z-A.
1385 tag-up Sort alphabetically by last tag, A-Z.
1386 tag-down Sort alphabetically by last tag, Z-A.
1387 priority-up Sort numerically by priority, high priority last.
1388 priority-down Sort numerically by priority, high priority first.
1389 todo-state-up Sort by todo state, tasks that are done last.
1390 todo-state-down Sort by todo state, tasks that are done first.
1391 effort-up Sort numerically by estimated effort, high effort last.
1392 effort-down Sort numerically by estimated effort, high effort first.
1393 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1394 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1395 habit-up Put entries that are habits first
1396 habit-down Put entries that are habits last
1397 alpha-up Sort headlines alphabetically
1398 alpha-down Sort headlines alphabetically, reversed
1400 The different possibilities will be tried in sequence, and testing stops
1401 if one comparison returns a \"not-equal\". For example, the default
1402 '(time-up category-keep priority-down)
1403 means: Pull out all entries having a specified time of day and sort them,
1404 in order to make a time schedule for the current day the first thing in the
1405 agenda listing for the day. Of the entries without a time indication, keep
1406 the grouped in categories, don't sort the categories, but keep them in
1407 the sequence given in `org-agenda-files'. Within each category sort by
1408 priority.
1410 Leaving out `category-keep' would mean that items will be sorted across
1411 categories by priority.
1413 Instead of a single list, this can also be a set of list for specific
1414 contents, with a context symbol in the car of the list, any of
1415 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1417 Custom commands can bind this variable in the options section."
1418 :group 'org-agenda-sorting
1419 :type `(choice
1420 (repeat :tag "General" ,org-sorting-choice)
1421 (list :tag "Individually"
1422 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1423 (repeat ,org-sorting-choice))
1424 (cons (const :tag "Strategy for TODO lists" todo)
1425 (repeat ,org-sorting-choice))
1426 (cons (const :tag "Strategy for Tags matches" tags)
1427 (repeat ,org-sorting-choice))
1428 (cons (const :tag "Strategy for search matches" search)
1429 (repeat ,org-sorting-choice)))))
1431 (defcustom org-agenda-cmp-user-defined nil
1432 "A function to define the comparison `user-defined'.
1433 This function must receive two arguments, agenda entry a and b.
1434 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1435 the user comparison, return nil.
1436 When this is defined, you can make `user-defined-up' and `user-defined-down'
1437 part of an agenda sorting strategy."
1438 :group 'org-agenda-sorting
1439 :type 'symbol)
1441 (defcustom org-sort-agenda-notime-is-late t
1442 "Non-nil means items without time are considered late.
1443 This is only relevant for sorting. When t, items which have no explicit
1444 time like 15:30 will be considered as 99:01, i.e. later than any items which
1445 do have a time. When nil, the default time is before 0:00. You can use this
1446 option to decide if the schedule for today should come before or after timeless
1447 agenda entries."
1448 :group 'org-agenda-sorting
1449 :type 'boolean)
1451 (defcustom org-sort-agenda-noeffort-is-high t
1452 "Non-nil means items without effort estimate are sorted as high effort.
1453 This also applies when filtering an agenda view with respect to the
1454 < or > effort operator. Then, tasks with no effort defined will be treated
1455 as tasks with high effort.
1456 When nil, such items are sorted as 0 minutes effort."
1457 :group 'org-agenda-sorting
1458 :type 'boolean)
1460 (defgroup org-agenda-line-format nil
1461 "Options concerning the entry prefix in the Org-mode agenda display."
1462 :tag "Org Agenda Line Format"
1463 :group 'org-agenda)
1465 (defcustom org-agenda-prefix-format
1466 '((agenda . " %i %-12:c%?-12t% s")
1467 (timeline . " % s")
1468 (todo . " %i %-12:c")
1469 (tags . " %i %-12:c")
1470 (search . " %i %-12:c"))
1471 "Format specifications for the prefix of items in the agenda views.
1472 An alist with five entries, each for the different agenda types. The
1473 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1474 The values are format strings.
1476 This format works similar to a printf format, with the following meaning:
1478 %c the category of the item, \"Diary\" for entries from the diary,
1479 or as given by the CATEGORY keyword or derived from the file name
1480 %e the effort required by the item
1481 %i the icon category of the item, see `org-agenda-category-icon-alist'
1482 %T the last tag of the item (ignore inherited tags, which come first)
1483 %t the HH:MM time-of-day specification if one applies to the entry
1484 %s Scheduling/Deadline information, a short string
1485 %(expression) Eval EXPRESSION and replace the control string
1486 by the result
1488 All specifiers work basically like the standard `%s' of printf, but may
1489 contain two additional characters: a question mark just after the `%'
1490 and a whitespace/punctuation character just before the final letter.
1492 If the first character after `%' is a question mark, the entire field
1493 will only be included if the corresponding value applies to the current
1494 entry. This is useful for fields which should have fixed width when
1495 present, but zero width when absent. For example, \"%?-12t\" will
1496 result in a 12 character time field if a time of the day is specified,
1497 but will completely disappear in entries which do not contain a time.
1499 If there is punctuation or whitespace character just before the final
1500 format letter, this character will be appended to the field value if
1501 the value is not empty. For example, the format \"%-12:c\" leads to
1502 \"Diary: \" if the category is \"Diary\". If the category were be
1503 empty, no additional colon would be inserted.
1505 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1506 which means:
1508 - Indent the line with two space characters
1509 - Give the category a 12 chars wide field, padded with whitespace on
1510 the right (because of `-'). Append a colon if there is a category
1511 (because of `:').
1512 - If there is a time-of-day, put it into a 12 chars wide field. If no
1513 time, don't put in an empty field, just skip it (because of '?').
1514 - Finally, put the scheduling information.
1516 See also the variables `org-agenda-remove-times-when-in-prefix' and
1517 `org-agenda-remove-tags'.
1519 Custom commands can set this variable in the options section."
1520 :type '(choice
1521 (string :tag "General format")
1522 (list :greedy t :tag "View dependent"
1523 (cons (const agenda) (string :tag "Format"))
1524 (cons (const timeline) (string :tag "Format"))
1525 (cons (const todo) (string :tag "Format"))
1526 (cons (const tags) (string :tag "Format"))
1527 (cons (const search) (string :tag "Format"))))
1528 :group 'org-agenda-line-format)
1530 (defvar org-prefix-format-compiled nil
1531 "The compiled prefix format and associated variables.
1532 This is a list where first element is a list of variable bindings, and second
1533 element is the compiled format expression. See the variable
1534 `org-agenda-prefix-format'.")
1536 (defcustom org-agenda-todo-keyword-format "%-1s"
1537 "Format for the TODO keyword in agenda lines.
1538 Set this to something like \"%-12s\" if you want all TODO keywords
1539 to occupy a fixed space in the agenda display."
1540 :group 'org-agenda-line-format
1541 :type 'string)
1543 (defcustom org-agenda-diary-sexp-prefix nil
1544 "A regexp that matches part of a diary sexp entry
1545 which should be treated as scheduling/deadline information in
1546 `org-agenda'.
1548 For example, you can use this to extract the `diary-remind-message' from
1549 `diary-remind' entries."
1550 :group 'org-agenda-line-format
1551 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1553 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1554 "Text preceding timerange entries in the agenda view.
1555 This is a list with two strings. The first applies when the range
1556 is entirely on one day. The second applies if the range spans several days.
1557 The strings may have two \"%d\" format specifiers which will be filled
1558 with the sequence number of the days, and the total number of days in the
1559 range, respectively."
1560 :group 'org-agenda-line-format
1561 :type '(list
1562 (string :tag "Deadline today ")
1563 (choice :tag "Deadline relative"
1564 (string :tag "Format string")
1565 (function))))
1567 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1568 "Text preceding scheduled items in the agenda view.
1569 This is a list with two strings. The first applies when the item is
1570 scheduled on the current day. The second applies when it has been scheduled
1571 previously, it may contain a %d indicating that this is the nth time that
1572 this item is scheduled, due to automatic rescheduling of unfinished items
1573 for the following day. So this number is one larger than the number of days
1574 that passed since this item was scheduled first."
1575 :group 'org-agenda-line-format
1576 :type '(list
1577 (string :tag "Scheduled today ")
1578 (string :tag "Scheduled previously")))
1580 (defcustom org-agenda-inactive-leader "["
1581 "Text preceding item pulled into the agenda by inactive time stamps.
1582 These entries are added to the agenda when pressing \"[\"."
1583 :group 'org-agenda-line-format
1584 :version "24.1"
1585 :type '(list
1586 (string :tag "Scheduled today ")
1587 (string :tag "Scheduled previously")))
1589 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1590 "Text preceding deadline items in the agenda view.
1591 This is a list with two strings. The first applies when the item has its
1592 deadline on the current day. The second applies when it is in the past or
1593 in the future, it may contain %d to capture how many days away the deadline
1594 is (was)."
1595 :group 'org-agenda-line-format
1596 :type '(list
1597 (string :tag "Deadline today ")
1598 (choice :tag "Deadline relative"
1599 (string :tag "Format string")
1600 (function))))
1602 (defcustom org-agenda-remove-times-when-in-prefix t
1603 "Non-nil means remove duplicate time specifications in agenda items.
1604 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1605 time-of-day specification in a headline or diary entry is extracted and
1606 placed into the prefix. If this option is non-nil, the original specification
1607 \(a timestamp or -range, or just a plain time(range) specification like
1608 11:30-4pm) will be removed for agenda display. This makes the agenda less
1609 cluttered.
1610 The option can be t or nil. It may also be the symbol `beg', indicating
1611 that the time should only be removed when it is located at the beginning of
1612 the headline/diary entry."
1613 :group 'org-agenda-line-format
1614 :type '(choice
1615 (const :tag "Always" t)
1616 (const :tag "Never" nil)
1617 (const :tag "When at beginning of entry" beg)))
1619 (defcustom org-agenda-remove-timeranges-from-blocks nil
1620 "Non-nil means remove time ranges specifications in agenda
1621 items that span on several days."
1622 :group 'org-agenda-line-format
1623 :version "24.1"
1624 :type 'boolean)
1626 (defcustom org-agenda-default-appointment-duration nil
1627 "Default duration for appointments that only have a starting time.
1628 When nil, no duration is specified in such cases.
1629 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1630 :group 'org-agenda-line-format
1631 :type '(choice
1632 (integer :tag "Minutes")
1633 (const :tag "No default duration")))
1635 (defcustom org-agenda-show-inherited-tags t
1636 "Non-nil means show inherited tags in each agenda line."
1637 :group 'org-agenda-line-format
1638 :type 'boolean)
1640 (defcustom org-agenda-hide-tags-regexp nil
1641 "Regular expression used to filter away specific tags in agenda views.
1642 This means that these tags will be present, but not be shown in the agenda
1643 line. Secondary filtering will still work on the hidden tags.
1644 Nil means don't hide any tags."
1645 :group 'org-agenda-line-format
1646 :type '(choice
1647 (const :tag "Hide none" nil)
1648 (string :tag "Regexp ")))
1650 (defcustom org-agenda-remove-tags nil
1651 "Non-nil means remove the tags from the headline copy in the agenda.
1652 When this is the symbol `prefix', only remove tags when
1653 `org-agenda-prefix-format' contains a `%T' specifier."
1654 :group 'org-agenda-line-format
1655 :type '(choice
1656 (const :tag "Always" t)
1657 (const :tag "Never" nil)
1658 (const :tag "When prefix format contains %T" prefix)))
1660 (if (fboundp 'defvaralias)
1661 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1662 'org-agenda-remove-tags))
1664 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1665 "Shift tags in agenda items to this column.
1666 If this number is positive, it specifies the column. If it is negative,
1667 it means that the tags should be flushright to that column. For example,
1668 -80 works well for a normal 80 character screen."
1669 :group 'org-agenda-line-format
1670 :type 'integer)
1672 (if (fboundp 'defvaralias)
1673 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1675 (defcustom org-agenda-fontify-priorities 'cookies
1676 "Non-nil means highlight low and high priorities in agenda.
1677 When t, the highest priority entries are bold, lowest priority italic.
1678 However, settings in `org-priority-faces' will overrule these faces.
1679 When this variable is the symbol `cookies', only fontify the
1680 cookies, not the entire task.
1681 This may also be an association list of priority faces, whose
1682 keys are the character values of `org-highest-priority',
1683 `org-default-priority', and `org-lowest-priority' (the default values
1684 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1685 color as a string, or a list like `(:background \"Red\")'.
1686 If it is a color, the variable `org-faces-easy-properties'
1687 determines if it is a foreground or a background color."
1688 :group 'org-agenda-line-format
1689 :type '(choice
1690 (const :tag "Never" nil)
1691 (const :tag "Defaults" t)
1692 (const :tag "Cookies only" cookies)
1693 (repeat :tag "Specify"
1694 (list (character :tag "Priority" :value ?A)
1695 (choice :tag "Face "
1696 (string :tag "Color")
1697 (sexp :tag "Face"))))))
1699 (defcustom org-agenda-day-face-function nil
1700 "Function called to determine what face should be used to display a day.
1701 The only argument passed to that function is the day. It should
1702 returns a face, or nil if does not want to specify a face and let
1703 the normal rules apply."
1704 :group 'org-agenda-line-format
1705 :version "24.1"
1706 :type 'function)
1708 (defcustom org-agenda-category-icon-alist nil
1709 "Alist of category icon to be displayed in agenda views.
1711 Each entry should have the following format:
1713 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1715 Where CATEGORY-REGEXP is a regexp matching the categories where
1716 the icon should be displayed.
1717 FILE-OR-DATA either a file path or a string containing image data.
1719 The other fields can be omitted safely if not needed:
1720 TYPE indicates the image type.
1721 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1722 image data.
1723 PROPS are additional image attributes to assign to the image,
1724 like, e.g. `:ascent center'.
1726 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1728 If you want to set the display properties yourself, just put a
1729 list as second element:
1731 (CATEGORY-REGEXP (MY PROPERTY LIST))
1733 For example, to display a 16px horizontal space for Emacs
1734 category, you can use:
1736 (\"Emacs\" '(space . (:width (16))))"
1737 :group 'org-agenda-line-format
1738 :version "24.1"
1739 :type '(alist :key-type (string :tag "Regexp matching category")
1740 :value-type (choice (list :tag "Icon"
1741 (string :tag "File or data")
1742 (symbol :tag "Type")
1743 (boolean :tag "Data?")
1744 (repeat :tag "Extra image properties" :inline t symbol))
1745 (list :tag "Display properties" sexp))))
1747 (defgroup org-agenda-column-view nil
1748 "Options concerning column view in the agenda."
1749 :tag "Org Agenda Column View"
1750 :group 'org-agenda)
1752 (defcustom org-agenda-columns-show-summaries t
1753 "Non-nil means show summaries for columns displayed in the agenda view."
1754 :group 'org-agenda-column-view
1755 :type 'boolean)
1757 (defcustom org-agenda-columns-compute-summary-properties t
1758 "Non-nil means recompute all summary properties before column view.
1759 When column view in the agenda is listing properties that have a summary
1760 operator, it can go to all relevant buffers and recompute the summaries
1761 there. This can mean overhead for the agenda column view, but is necessary
1762 to have thing up to date.
1763 As a special case, a CLOCKSUM property also makes sure that the clock
1764 computations are current."
1765 :group 'org-agenda-column-view
1766 :type 'boolean)
1768 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1769 "Non-nil means the duration of an appointment will add to day effort.
1770 The property to which appointment durations will be added is the one given
1771 in the option `org-effort-property'. If an appointment does not have
1772 an end time, `org-agenda-default-appointment-duration' will be used. If that
1773 is not set, an appointment without end time will not contribute to the time
1774 estimate."
1775 :group 'org-agenda-column-view
1776 :type 'boolean)
1778 (defcustom org-agenda-auto-exclude-function nil
1779 "A function called with a tag to decide if it is filtered on '/ RET'.
1780 The sole argument to the function, which is called once for each
1781 possible tag, is a string giving the name of the tag. The
1782 function should return either nil if the tag should be included
1783 as normal, or \"-<TAG>\" to exclude the tag.
1784 Note that for the purpose of tag filtering, only the lower-case version of
1785 all tags will be considered, so that this function will only ever see
1786 the lower-case version of all tags."
1787 :group 'org-agenda
1788 :type 'function)
1790 (defcustom org-agenda-bulk-custom-functions nil
1791 "Alist of characters and custom functions for bulk actions.
1792 For example, this value makes those two functions available:
1794 '((?R set-category)
1795 (?C bulk-cut))
1797 With selected entries in an agenda buffer, `B R' will call
1798 the custom function `set-category' on the selected entries.
1799 Note that functions in this alist don't need to be quoted."
1800 :type 'alist
1801 :version "24.1"
1802 :group 'org-agenda)
1804 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1805 "Execute BODY with point at location given by `org-hd-marker' property.
1806 If STRING is non-nil, the text property will be fetched from position 0
1807 in that string. If STRING is nil, it will be fetched from the beginning
1808 of the current line."
1809 (org-with-gensyms (marker)
1810 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1811 'org-hd-marker ,string)))
1812 (with-current-buffer (marker-buffer ,marker)
1813 (save-excursion
1814 (goto-char ,marker)
1815 ,@body)))))
1816 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1818 (defun org-add-agenda-custom-command (entry)
1819 "Replace or add a command in `org-agenda-custom-commands'.
1820 This is mostly for hacking and trying a new command - once the command
1821 works you probably want to add it to `org-agenda-custom-commands' for good."
1822 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1823 (if ass
1824 (setcdr ass (cdr entry))
1825 (push entry org-agenda-custom-commands))))
1827 ;;; Define the org-agenda-mode
1829 (defvar org-agenda-mode-map (make-sparse-keymap)
1830 "Keymap for `org-agenda-mode'.")
1831 (if (fboundp 'defvaralias)
1832 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1834 (defvar org-agenda-menu) ; defined later in this file.
1835 (defvar org-agenda-restrict) ; defined later in this file.
1836 (defvar org-agenda-follow-mode nil)
1837 (defvar org-agenda-entry-text-mode nil)
1838 (defvar org-agenda-clockreport-mode nil)
1839 (defvar org-agenda-show-log nil)
1840 (defvar org-agenda-redo-command nil)
1841 (defvar org-agenda-query-string nil)
1842 (defvar org-agenda-mode-hook nil
1843 "Hook for `org-agenda-mode', run after the mode is turned on.")
1844 (defvar org-agenda-type nil)
1845 (defvar org-agenda-force-single-file nil)
1846 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1849 ;;; Multiple agenda buffers support
1851 (defcustom org-agenda-sticky nil
1852 "Non-nil means agenda q key will bury agenda buffers.
1853 Agenda commands will then show existing buffer instead of generating new ones.
1854 When nil, `q' will kill the single agenda buffer."
1855 :group 'org-agenda
1856 :type 'boolean
1857 :set (lambda (var val)
1858 (if (boundp var)
1859 (org-toggle-sticky-agenda (if val 1 0))
1860 (set var val))))
1862 (defun org-toggle-sticky-agenda (&optional arg)
1863 "Toggle `org-agenda-sticky'."
1864 (interactive "P")
1865 (let ((new-value (if arg
1866 (> (prefix-numeric-value arg) 0)
1867 (not org-agenda-sticky))))
1868 (if (equal new-value org-agenda-sticky)
1869 (and (org-called-interactively-p 'interactive)
1870 (message "Sticky agenda was already %s"
1871 (if org-agenda-sticky "enabled" "disabled")))
1872 (setq org-agenda-sticky new-value)
1873 (org-agenda-kill-all-agenda-buffers)
1874 (and (org-called-interactively-p 'interactive)
1875 (message "Sticky agenda was %s"
1876 (if org-agenda-sticky "enabled" "disabled"))))))
1878 (defvar org-agenda-buffer nil
1879 "Agenda buffer currently being generated.")
1881 (defvar org-agenda-last-prefix-arg nil)
1882 (defvar org-agenda-this-buffer-name nil)
1883 (defvar org-agenda-doing-sticky-redo nil)
1884 (defvar org-agenda-this-buffer-is-sticky nil)
1886 (defconst org-agenda-local-vars
1887 '(org-agenda-this-buffer-name
1888 org-agenda-undo-list
1889 org-agenda-pending-undo-list
1890 org-agenda-follow-mode
1891 org-agenda-entry-text-mode
1892 org-agenda-clockreport-mode
1893 org-agenda-show-log
1894 org-agenda-redo-command
1895 org-agenda-query-string
1896 org-agenda-type
1897 org-agenda-bulk-marked-entries
1898 org-agenda-undo-has-started-in
1899 org-agenda-last-arguments
1900 org-agenda-info
1901 org-agenda-tag-filter-overlays
1902 org-agenda-cat-filter-overlays
1903 org-pre-agenda-window-conf
1904 org-agenda-columns-active
1905 org-agenda-tag-filter
1906 org-agenda-category-filter
1907 org-agenda-markers
1908 org-agenda-last-search-view-search-was-boolean
1909 org-agenda-filtered-by-category
1910 org-agenda-filter-form
1911 org-agenda-show-window
1912 org-agenda-cycle-counter
1913 org-agenda-last-prefix-arg)
1914 "Variables that must be local in agenda buffers to allow multiple buffers.")
1916 (defun org-agenda-mode ()
1917 "Mode for time-sorted view on action items in Org-mode files.
1919 The following commands are available:
1921 \\{org-agenda-mode-map}"
1922 (interactive)
1923 (cond (org-agenda-doing-sticky-redo
1924 ;; Refreshing sticky agenda-buffer
1926 ;; Preserve the value of `org-agenda-local-vars' variables,
1927 ;; while letting `kill-all-local-variables' kill the rest
1928 (let ((save (buffer-local-variables)))
1929 (kill-all-local-variables)
1930 (mapc 'make-local-variable org-agenda-local-vars)
1931 (dolist (elem save)
1932 (let ((var (car elem))
1933 (val (cdr elem)))
1934 (when (and val
1935 (member var org-agenda-local-vars))
1936 (set var val)))))
1937 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1938 (org-agenda-sticky
1939 ;; Creating a sticky Agenda buffer for the first time
1940 (kill-all-local-variables)
1941 (mapc 'make-local-variable org-agenda-local-vars)
1942 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1944 ;; Creating a non-sticky agenda buffer
1945 (kill-all-local-variables)
1946 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1947 (setq org-agenda-undo-list nil
1948 org-agenda-pending-undo-list nil
1949 org-agenda-bulk-marked-entries nil)
1950 (setq major-mode 'org-agenda-mode)
1951 ;; Keep global-font-lock-mode from turning on font-lock-mode
1952 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1953 (setq mode-name "Org-Agenda")
1954 (use-local-map org-agenda-mode-map)
1955 (easy-menu-add org-agenda-menu)
1956 (if org-startup-truncated (setq truncate-lines t))
1957 (org-set-local 'line-move-visual nil)
1958 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1959 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1960 ;; Make sure properties are removed when copying text
1961 (make-local-variable 'filter-buffer-substring-functions)
1962 (add-hook 'filter-buffer-substring-functions
1963 (lambda (fun start end delete)
1964 (substring-no-properties (funcall fun start end delete))))
1965 (unless org-agenda-keep-modes
1966 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1967 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1968 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1969 org-agenda-show-log org-agenda-start-with-log-mode))
1971 (easy-menu-change
1972 '("Agenda") "Agenda Files"
1973 (append
1974 (list
1975 (vector
1976 (if (get 'org-agenda-files 'org-restrict)
1977 "Restricted to single file"
1978 "Edit File List")
1979 '(org-edit-agenda-file-list)
1980 (not (get 'org-agenda-files 'org-restrict)))
1981 "--")
1982 (mapcar 'org-file-menu-entry (org-agenda-files))))
1983 (org-agenda-set-mode-name)
1984 (apply
1985 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1986 (list 'org-agenda-mode-hook)))
1988 (substitute-key-definition 'undo 'org-agenda-undo
1989 org-agenda-mode-map global-map)
1990 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1991 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1992 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1993 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1994 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1995 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1996 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
1997 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1998 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1999 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2000 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2001 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2002 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2003 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2004 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2005 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2006 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2007 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2008 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2009 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2010 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2011 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2012 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2013 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2014 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2015 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2016 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2017 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2018 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2019 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2020 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2021 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2022 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2023 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2024 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2025 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2026 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2027 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2028 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2029 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2030 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2031 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2032 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2033 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2034 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2035 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2037 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2038 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2039 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2040 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2041 (while l (org-defkey org-agenda-mode-map
2042 (int-to-string (pop l)) 'digit-argument)))
2044 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2045 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2046 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2047 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2048 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2049 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2050 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2051 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2052 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2053 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2054 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2055 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2056 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2057 'org-clock-modify-effort-estimate)
2058 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2059 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2060 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2061 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2062 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2063 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2064 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2065 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2066 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2067 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2068 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2069 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2070 (substitute-key-definition 'next-line 'org-agenda-next-line
2071 org-agenda-mode-map global-map)
2072 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2073 org-agenda-mode-map global-map)
2074 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2075 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2076 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2077 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2078 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2079 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2080 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2081 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2082 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2083 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2084 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2085 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2086 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2087 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2088 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2089 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2090 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2091 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2092 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2093 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2094 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2095 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2096 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2097 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2098 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2099 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2100 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2101 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2102 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2103 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2105 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2106 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2107 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2108 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2109 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2110 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2111 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2112 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2113 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2114 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2115 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2116 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2118 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2119 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2120 (when org-agenda-mouse-1-follows-link
2121 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2122 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2123 '("Agenda"
2124 ("Agenda Files")
2125 "--"
2126 ("Agenda Dates"
2127 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2128 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2129 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2130 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2131 "--"
2132 ("View"
2133 ["Day View" org-agenda-day-view
2134 :active (org-agenda-check-type nil 'agenda)
2135 :style radio :selected (eq org-agenda-current-span 'day)
2136 :keys "v d (or just d)"]
2137 ["Week View" org-agenda-week-view
2138 :active (org-agenda-check-type nil 'agenda)
2139 :style radio :selected (eq org-agenda-current-span 'week)
2140 :keys "v w (or just w)"]
2141 ["Month View" org-agenda-month-view
2142 :active (org-agenda-check-type nil 'agenda)
2143 :style radio :selected (eq org-agenda-current-span 'month)
2144 :keys "v m"]
2145 ["Year View" org-agenda-year-view
2146 :active (org-agenda-check-type nil 'agenda)
2147 :style radio :selected (eq org-agenda-current-span 'year)
2148 :keys "v y"]
2149 "--"
2150 ["Include Diary" org-agenda-toggle-diary
2151 :style toggle :selected org-agenda-include-diary
2152 :active (org-agenda-check-type nil 'agenda)]
2153 ["Include Deadlines" org-agenda-toggle-deadlines
2154 :style toggle :selected org-agenda-include-deadlines
2155 :active (org-agenda-check-type nil 'agenda)]
2156 ["Use Time Grid" org-agenda-toggle-time-grid
2157 :style toggle :selected org-agenda-use-time-grid
2158 :active (org-agenda-check-type nil 'agenda)]
2159 "--"
2160 ["Show clock report" org-agenda-clockreport-mode
2161 :style toggle :selected org-agenda-clockreport-mode
2162 :active (org-agenda-check-type nil 'agenda)]
2163 ["Show some entry text" org-agenda-entry-text-mode
2164 :style toggle :selected org-agenda-entry-text-mode
2165 :active t]
2166 "--"
2167 ["Show Logbook entries" org-agenda-log-mode
2168 :style toggle :selected org-agenda-show-log
2169 :active (org-agenda-check-type nil 'agenda 'timeline)
2170 :keys "v l (or just l)"]
2171 ["Include archived trees" org-agenda-archives-mode
2172 :style toggle :selected org-agenda-archives-mode :active t
2173 :keys "v a"]
2174 ["Include archive files" (org-agenda-archives-mode t)
2175 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2176 :keys "v A"]
2177 "--"
2178 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2179 ["Write view to file" org-agenda-write t]
2180 ["Rebuild buffer" org-agenda-redo t]
2181 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2182 "--"
2183 ["Show original entry" org-agenda-show t]
2184 ["Go To (other window)" org-agenda-goto t]
2185 ["Go To (this window)" org-agenda-switch-to t]
2186 ["Follow Mode" org-agenda-follow-mode
2187 :style toggle :selected org-agenda-follow-mode :active t]
2188 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2189 "--"
2190 ("TODO"
2191 ["Cycle TODO" org-agenda-todo t]
2192 ["Next TODO set" org-agenda-todo-nextset t]
2193 ["Previous TODO set" org-agenda-todo-previousset t]
2194 ["Add note" org-agenda-add-note t])
2195 ("Archive/Refile/Delete"
2196 ["Archive default" org-agenda-archive-default t]
2197 ["Archive default" org-agenda-archive-default-with-confirmation t]
2198 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2199 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2200 ["Archive subtree" org-agenda-archive t]
2201 "--"
2202 ["Refile" org-agenda-refile t]
2203 "--"
2204 ["Delete subtree" org-agenda-kill t])
2205 ("Bulk action"
2206 ["Mark entry" org-agenda-bulk-mark t]
2207 ["Mark all" org-agenda-bulk-mark-all t]
2208 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2209 ["Unmark entry" org-agenda-bulk-unmark t]
2210 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
2211 ["Act on all marked" org-agenda-bulk-action t]
2212 "--"
2213 ("Tags and Properties"
2214 ["Show all Tags" org-agenda-show-tags t]
2215 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2216 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2217 "--"
2218 ["Column View" org-columns t])
2219 ("Deadline/Schedule"
2220 ["Schedule" org-agenda-schedule t]
2221 ["Set Deadline" org-agenda-deadline t]
2222 "--"
2223 ["Mark item" org-agenda-action :active t :keys "k m"]
2224 ["Show mark item" org-agenda-action :active t :keys "k v"]
2225 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2226 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2227 "--"
2228 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2229 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2230 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2231 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2232 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2233 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2234 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2235 ("Clock and Effort"
2236 ["Clock in" org-agenda-clock-in t]
2237 ["Clock out" org-agenda-clock-out t]
2238 ["Clock cancel" org-agenda-clock-cancel t]
2239 ["Goto running clock" org-clock-goto t]
2240 "--"
2241 ["Set Effort" org-agenda-set-effort t]
2242 ["Change clocked effort" org-clock-modify-effort-estimate
2243 (org-clock-is-active)])
2244 ("Priority"
2245 ["Set Priority" org-agenda-priority t]
2246 ["Increase Priority" org-agenda-priority-up t]
2247 ["Decrease Priority" org-agenda-priority-down t]
2248 ["Show Priority" org-agenda-show-priority t])
2249 ("Calendar/Diary"
2250 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2251 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2252 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2253 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2254 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2255 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2256 "--"
2257 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2258 "--"
2259 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2260 "--"
2261 ("MobileOrg"
2262 ["Push Files and Views" org-mobile-push t]
2263 ["Get Captured and Flagged" org-mobile-pull t]
2264 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2265 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2266 "--"
2267 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2268 "--"
2269 ["Quit" org-agenda-quit t]
2270 ["Exit and Release Buffers" org-agenda-exit t]
2273 ;;; Agenda undo
2275 (defvar org-agenda-allow-remote-undo t
2276 "Non-nil means allow remote undo from the agenda buffer.")
2277 (defvar org-agenda-undo-list nil
2278 "List of undoable operations in the agenda since last refresh.")
2279 (defvar org-agenda-undo-has-started-in nil
2280 "Buffers that have already seen `undo-start' in the current undo sequence.")
2281 (defvar org-agenda-pending-undo-list nil
2282 "In a series of undo commands, this is the list of remaining undo items.")
2284 (defun org-agenda-undo ()
2285 "Undo a remote editing step in the agenda.
2286 This undoes changes both in the agenda buffer and in the remote buffer
2287 that have been changed along."
2288 (interactive)
2289 (or org-agenda-allow-remote-undo
2290 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2291 (if (not (eq this-command last-command))
2292 (setq org-agenda-undo-has-started-in nil
2293 org-agenda-pending-undo-list org-agenda-undo-list))
2294 (if (not org-agenda-pending-undo-list)
2295 (error "No further undo information"))
2296 (let* ((entry (pop org-agenda-pending-undo-list))
2297 buf line cmd rembuf)
2298 (setq cmd (pop entry) line (pop entry))
2299 (setq rembuf (nth 2 entry))
2300 (org-with-remote-undo rembuf
2301 (while (bufferp (setq buf (pop entry)))
2302 (if (pop entry)
2303 (with-current-buffer buf
2304 (let ((last-undo-buffer buf)
2305 (inhibit-read-only t))
2306 (unless (memq buf org-agenda-undo-has-started-in)
2307 (push buf org-agenda-undo-has-started-in)
2308 (make-local-variable 'pending-undo-list)
2309 (undo-start))
2310 (while (and pending-undo-list
2311 (listp pending-undo-list)
2312 (not (car pending-undo-list)))
2313 (pop pending-undo-list))
2314 (undo-more 1))))))
2315 (org-goto-line line)
2316 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2318 (defun org-verify-change-for-undo (l1 l2)
2319 "Verify that a real change occurred between the undo lists L1 and L2."
2320 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2321 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2322 (not (eq l1 l2)))
2324 ;;; Agenda dispatch
2326 (defvar org-agenda-restrict nil)
2327 (defvar org-agenda-restrict-begin (make-marker))
2328 (defvar org-agenda-restrict-end (make-marker))
2329 (defvar org-agenda-last-dispatch-buffer nil)
2330 (defvar org-agenda-overriding-restriction nil)
2332 ;;;###autoload
2333 (defun org-agenda (&optional arg keys restriction)
2334 "Dispatch agenda commands to collect entries to the agenda buffer.
2335 Prompts for a command to execute. Any prefix arg will be passed
2336 on to the selected command. The default selections are:
2338 a Call `org-agenda-list' to display the agenda for current day or week.
2339 t Call `org-todo-list' to display the global todo list.
2340 T Call `org-todo-list' to display the global todo list, select only
2341 entries with a specific TODO keyword (the user gets a prompt).
2342 m Call `org-tags-view' to display headlines with tags matching
2343 a condition (the user is prompted for the condition).
2344 M Like `m', but select only TODO entries, no ordinary headlines.
2345 L Create a timeline for the current buffer.
2346 e Export views to associated files.
2347 s Search entries for keywords.
2348 / Multi occur across all agenda files and also files listed
2349 in `org-agenda-text-search-extra-files'.
2350 < Restrict agenda commands to buffer, subtree, or region.
2351 Press several times to get the desired effect.
2352 > Remove a previous restriction.
2353 # List \"stuck\" projects.
2354 ! Configure what \"stuck\" means.
2355 C Configure custom agenda commands.
2357 More commands can be added by configuring the variable
2358 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2359 searches can be pre-defined in this way.
2361 If the current buffer is in Org-mode and visiting a file, you can also
2362 first press `<' once to indicate that the agenda should be temporarily
2363 \(until the next use of \\[org-agenda]) restricted to the current file.
2364 Pressing `<' twice means to restrict to the current subtree or region
2365 \(if active)."
2366 (interactive "P")
2367 (catch 'exit
2368 (let* ((prefix-descriptions nil)
2369 (org-agenda-buffer-name org-agenda-buffer-name)
2370 (org-agenda-window-setup (if (equal (buffer-name)
2371 org-agenda-buffer-name)
2372 'current-window
2373 org-agenda-window-setup))
2374 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2375 (org-agenda-custom-commands
2376 ;; normalize different versions
2377 (delq nil
2378 (mapcar
2379 (lambda (x)
2380 (cond ((stringp (cdr x))
2381 (push x prefix-descriptions)
2382 nil)
2383 ((stringp (nth 1 x)) x)
2384 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2385 (t (cons (car x) (cons "" (cdr x))))))
2386 org-agenda-custom-commands)))
2387 (buf (current-buffer))
2388 (bfn (buffer-file-name (buffer-base-buffer)))
2389 entry key type match lprops ans)
2390 ;; Turn off restriction unless there is an overriding one,
2391 (unless org-agenda-overriding-restriction
2392 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2393 ;; There is a request to keep the file list in place
2394 (put 'org-agenda-files 'org-restrict nil))
2395 (setq org-agenda-restrict nil)
2396 (move-marker org-agenda-restrict-begin nil)
2397 (move-marker org-agenda-restrict-end nil))
2398 ;; Delete old local properties
2399 (put 'org-agenda-redo-command 'org-lprops nil)
2400 ;; Delete previously set last-arguments
2401 (put 'org-agenda-redo-command 'last-args nil)
2402 ;; Remember where this call originated
2403 (setq org-agenda-last-dispatch-buffer (current-buffer))
2404 (unless keys
2405 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2406 keys (car ans)
2407 restriction (cdr ans)))
2408 ;; If we have sticky agenda buffers, set a name for the buffer,
2409 ;; depending on the invoking keys. The user may still set this
2410 ;; as a command option, which will overwrite what we do here.
2411 (if org-agenda-sticky
2412 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2413 ;; Establish the restriction, if any
2414 (when (and (not org-agenda-overriding-restriction) restriction)
2415 (put 'org-agenda-files 'org-restrict (list bfn))
2416 (cond
2417 ((eq restriction 'region)
2418 (setq org-agenda-restrict t)
2419 (move-marker org-agenda-restrict-begin (region-beginning))
2420 (move-marker org-agenda-restrict-end (region-end)))
2421 ((eq restriction 'subtree)
2422 (save-excursion
2423 (setq org-agenda-restrict t)
2424 (org-back-to-heading t)
2425 (move-marker org-agenda-restrict-begin (point))
2426 (move-marker org-agenda-restrict-end
2427 (progn (org-end-of-subtree t)))))))
2429 ;; For example the todo list should not need it (but does...)
2430 (cond
2431 ((setq entry (assoc keys org-agenda-custom-commands))
2432 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2433 (progn
2434 (setq type (nth 2 entry) match (eval (nth 3 entry))
2435 lprops (nth 4 entry))
2436 (put 'org-agenda-redo-command 'org-lprops lprops)
2437 (cond
2438 ((eq type 'agenda)
2439 (org-let lprops '(org-agenda-list current-prefix-arg)))
2440 ((eq type 'alltodo)
2441 (org-let lprops '(org-todo-list current-prefix-arg)))
2442 ((eq type 'search)
2443 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2444 ((eq type 'stuck)
2445 (org-let lprops '(org-agenda-list-stuck-projects
2446 current-prefix-arg)))
2447 ((eq type 'tags)
2448 (org-let lprops '(org-tags-view current-prefix-arg match)))
2449 ((eq type 'tags-todo)
2450 (org-let lprops '(org-tags-view '(4) match)))
2451 ((eq type 'todo)
2452 (org-let lprops '(org-todo-list match)))
2453 ((eq type 'tags-tree)
2454 (org-check-for-org-mode)
2455 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2456 ((eq type 'todo-tree)
2457 (org-check-for-org-mode)
2458 (org-let lprops
2459 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2460 (regexp-quote match) "\\>"))))
2461 ((eq type 'occur-tree)
2462 (org-check-for-org-mode)
2463 (org-let lprops '(org-occur match)))
2464 ((functionp type)
2465 (org-let lprops '(funcall type match)))
2466 ((fboundp type)
2467 (org-let lprops '(funcall type match)))
2468 (t (error "Invalid custom agenda command type %s" type))))
2469 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2470 ((equal keys "C")
2471 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2472 (customize-variable 'org-agenda-custom-commands))
2473 ((equal keys "a") (call-interactively 'org-agenda-list))
2474 ((equal keys "s") (call-interactively 'org-search-view))
2475 ((equal keys "t") (call-interactively 'org-todo-list))
2476 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2477 ((equal keys "m") (call-interactively 'org-tags-view))
2478 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2479 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2480 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2481 (org-add-hook
2482 'post-command-hook
2483 (lambda ()
2484 (unless (current-message)
2485 (let* ((m (org-agenda-get-any-marker))
2486 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2487 (when note
2488 (message (concat
2489 "FLAGGING-NOTE ([?] for more info): "
2490 (org-add-props
2491 (replace-regexp-in-string
2492 "\\\\n" "//"
2493 (copy-sequence note))
2494 nil 'face 'org-warning)))))))
2495 t t))
2496 ((equal keys "L")
2497 (unless (derived-mode-p 'org-mode)
2498 (error "This is not an Org-mode file"))
2499 (unless restriction
2500 (put 'org-agenda-files 'org-restrict (list bfn))
2501 (org-call-with-arg 'org-timeline arg)))
2502 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2503 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2504 ((equal keys "!") (customize-variable 'org-stuck-projects))
2505 (t (error "Invalid agenda key"))))))
2507 (defun org-agenda-append-agenda ()
2508 "Append another agenda view to the current one.
2509 This function allows interactive building of block agendas.
2510 Agenda views are separated by `org-agenda-block-separator'."
2511 (interactive)
2512 (unless (string= (buffer-name) org-agenda-buffer-name)
2513 (error "Can only append from within agenda buffer"))
2514 (let ((org-agenda-multi t))
2515 (org-agenda)
2516 (widen)))
2518 (defun org-agenda-normalize-custom-commands (cmds)
2519 (delq nil
2520 (mapcar
2521 (lambda (x)
2522 (cond ((stringp (cdr x)) nil)
2523 ((stringp (nth 1 x)) x)
2524 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2525 (t (cons (car x) (cons "" (cdr x))))))
2526 cmds)))
2528 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2529 "The user interface for selecting an agenda command."
2530 (catch 'exit
2531 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2532 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2533 (region-p (org-region-active-p))
2534 (custom org-agenda-custom-commands)
2535 (selstring "")
2536 restriction second-time
2537 c entry key type match prefixes rmheader header-end custom1 desc
2538 line lines left right n n1)
2539 (save-window-excursion
2540 (delete-other-windows)
2541 (org-switch-to-buffer-other-window " *Agenda Commands*")
2542 (erase-buffer)
2543 (insert (eval-when-compile
2544 (let ((header
2545 "Press key for an agenda command: < Buffer, subtree/region restriction
2546 -------------------------------- > Remove restriction
2547 a Agenda for current week or day e Export agenda views
2548 t List of all TODO entries T Entries with special TODO kwd
2549 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2550 L Timeline for current buffer # List stuck projects (!=configure)
2551 s Search for keywords * Toggle sticky agenda views
2552 / Multi-occur ? Find :FLAGGED: entries
2553 C Configure custom agenda commands
2555 (start 0))
2556 (while (string-match
2557 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2558 header start)
2559 (setq start (match-end 0))
2560 (add-text-properties (match-beginning 2) (match-end 2)
2561 '(face bold) header))
2562 header)))
2563 (setq header-end (move-marker (make-marker) (point)))
2564 (while t
2565 (setq custom1 custom)
2566 (when (eq rmheader t)
2567 (org-goto-line 1)
2568 (re-search-forward ":" nil t)
2569 (delete-region (match-end 0) (point-at-eol))
2570 (forward-char 1)
2571 (looking-at "-+")
2572 (delete-region (match-end 0) (point-at-eol))
2573 (move-marker header-end (match-end 0)))
2574 (goto-char header-end)
2575 (delete-region (point) (point-max))
2577 ;; Produce all the lines that describe custom commands and prefixes
2578 (setq lines nil)
2579 (while (setq entry (pop custom1))
2580 (setq key (car entry) desc (nth 1 entry)
2581 type (nth 2 entry)
2582 match (nth 3 entry))
2583 (if (> (length key) 1)
2584 (add-to-list 'prefixes (string-to-char key))
2585 (setq line
2586 (format
2587 "%-4s%-14s"
2588 (org-add-props (copy-sequence key)
2589 '(face bold))
2590 (cond
2591 ((string-match "\\S-" desc) desc)
2592 ((eq type 'agenda) "Agenda for current week or day")
2593 ((eq type 'alltodo) "List of all TODO entries")
2594 ((eq type 'search) "Word search")
2595 ((eq type 'stuck) "List of stuck projects")
2596 ((eq type 'todo) "TODO keyword")
2597 ((eq type 'tags) "Tags query")
2598 ((eq type 'tags-todo) "Tags (TODO)")
2599 ((eq type 'tags-tree) "Tags tree")
2600 ((eq type 'todo-tree) "TODO kwd tree")
2601 ((eq type 'occur-tree) "Occur tree")
2602 ((functionp type) (if (symbolp type)
2603 (symbol-name type)
2604 "Lambda expression"))
2605 (t "???"))))
2606 (if org-agenda-menu-show-matcher
2607 (setq line
2608 (concat line ": "
2609 (cond
2610 ((stringp match)
2611 (setq match (copy-sequence match))
2612 (org-add-props match nil 'face 'org-warning))
2613 (match
2614 (format "set of %d commands" (length match)))
2615 (t ""))))
2616 (if (org-string-nw-p match)
2617 (add-text-properties
2618 0 (length line) (list 'help-echo
2619 (concat "Matcher: "match)) line)))
2620 (push line lines)))
2621 (setq lines (nreverse lines))
2622 (when prefixes
2623 (mapc (lambda (x)
2624 (push
2625 (format "%s %s"
2626 (org-add-props (char-to-string x)
2627 nil 'face 'bold)
2628 (or (cdr (assoc (concat selstring
2629 (char-to-string x))
2630 prefix-descriptions))
2631 "Prefix key"))
2632 lines))
2633 prefixes))
2635 ;; Check if we should display in two columns
2636 (if org-agenda-menu-two-column
2637 (progn
2638 (setq n (length lines)
2639 n1 (+ (/ n 2) (mod n 2))
2640 right (nthcdr n1 lines)
2641 left (copy-sequence lines))
2642 (setcdr (nthcdr (1- n1) left) nil))
2643 (setq left lines right nil))
2644 (while left
2645 (insert "\n" (pop left))
2646 (when right
2647 (if (< (current-column) 40)
2648 (move-to-column 40 t)
2649 (insert " "))
2650 (insert (pop right))))
2652 ;; Make the window the right size
2653 (goto-char (point-min))
2654 (if second-time
2655 (if (not (pos-visible-in-window-p (point-max)))
2656 (org-fit-window-to-buffer))
2657 (setq second-time t)
2658 (org-fit-window-to-buffer))
2660 ;; Ask for selection
2661 (message "Press key for agenda command%s:"
2662 (if (or restrict-ok org-agenda-overriding-restriction)
2663 (if org-agenda-overriding-restriction
2664 " (restriction lock active)"
2665 (if restriction
2666 (format " (restricted to %s)" restriction)
2667 " (unrestricted)"))
2668 ""))
2669 (setq c (read-char-exclusive))
2670 (message "")
2671 (cond
2672 ((assoc (char-to-string c) custom)
2673 (setq selstring (concat selstring (char-to-string c)))
2674 (throw 'exit (cons selstring restriction)))
2675 ((memq c prefixes)
2676 (setq selstring (concat selstring (char-to-string c))
2677 prefixes nil
2678 rmheader (or rmheader t)
2679 custom (delq nil (mapcar
2680 (lambda (x)
2681 (if (or (= (length (car x)) 1)
2682 (/= (string-to-char (car x)) c))
2684 (cons (substring (car x) 1) (cdr x))))
2685 custom))))
2686 ((eq c ?*)
2687 (call-interactively 'org-toggle-sticky-agenda)
2688 (sit-for 2))
2689 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2690 (message "Restriction is only possible in Org-mode buffers")
2691 (ding) (sit-for 1))
2692 ((eq c ?1)
2693 (org-agenda-remove-restriction-lock 'noupdate)
2694 (setq restriction 'buffer))
2695 ((eq c ?0)
2696 (org-agenda-remove-restriction-lock 'noupdate)
2697 (setq restriction (if region-p 'region 'subtree)))
2698 ((eq c ?<)
2699 (org-agenda-remove-restriction-lock 'noupdate)
2700 (setq restriction
2701 (cond
2702 ((eq restriction 'buffer)
2703 (if region-p 'region 'subtree))
2704 ((memq restriction '(subtree region))
2705 nil)
2706 (t 'buffer))))
2707 ((eq c ?>)
2708 (org-agenda-remove-restriction-lock 'noupdate)
2709 (setq restriction nil))
2710 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2711 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2712 ((and (> (length selstring) 0) (eq c ?\d))
2713 (delete-window)
2714 (org-agenda-get-restriction-and-command prefix-descriptions))
2716 ((equal c ?q) (error "Abort"))
2717 (t (error "Invalid key %c" c))))))))
2719 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2720 (defvar org-agenda-last-arguments nil
2721 "The arguments of the previous call to `org-agenda'.")
2722 (defun org-agenda-run-series (name series)
2723 (org-let (nth 1 series) '(org-prepare-agenda name))
2724 ;; We need to reset agenda markers here, because when constructing a
2725 ;; block agenda, the individual blocks do not do that.
2726 (org-agenda-reset-markers)
2727 (let* ((org-agenda-multi t)
2728 (redo (list 'org-agenda-run-series name (list 'quote series)))
2729 (org-agenda-overriding-arguments
2730 (or org-agenda-overriding-arguments
2731 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2732 (get 'org-agenda-redo-command 'last-args))))
2733 (cmds (car series))
2734 (gprops (nth 1 series))
2735 match ;; The byte compiler incorrectly complains about this. Keep it!
2736 cmd type lprops)
2737 (while (setq cmd (pop cmds))
2738 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2739 (cond
2740 ((eq type 'agenda)
2741 (org-let2 gprops lprops
2742 '(call-interactively 'org-agenda-list)))
2743 ((eq type 'alltodo)
2744 (org-let2 gprops lprops
2745 '(call-interactively 'org-todo-list)))
2746 ((eq type 'search)
2747 (org-let2 gprops lprops
2748 '(org-search-view current-prefix-arg match nil)))
2749 ((eq type 'stuck)
2750 (org-let2 gprops lprops
2751 '(call-interactively 'org-agenda-list-stuck-projects)))
2752 ((eq type 'tags)
2753 (org-let2 gprops lprops
2754 '(org-tags-view current-prefix-arg match)))
2755 ((eq type 'tags-todo)
2756 (org-let2 gprops lprops
2757 '(org-tags-view '(4) match)))
2758 ((eq type 'todo)
2759 (org-let2 gprops lprops
2760 '(org-todo-list match)))
2761 ((fboundp type)
2762 (org-let2 gprops lprops
2763 '(funcall type match)))
2764 (t (error "Invalid type in command series"))))
2765 (widen)
2766 (setq org-agenda-redo-command redo)
2767 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2768 (goto-char (point-min)))
2769 (org-fit-agenda-window)
2770 (org-let (nth 1 series) '(org-finalize-agenda)))
2772 ;;;###autoload
2773 (defmacro org-batch-agenda (cmd-key &rest parameters)
2774 "Run an agenda command in batch mode and send the result to STDOUT.
2775 If CMD-KEY is a string of length 1, it is used as a key in
2776 `org-agenda-custom-commands' and triggers this command. If it is a
2777 longer string it is used as a tags/todo match string.
2778 Parameters are alternating variable names and values that will be bound
2779 before running the agenda command."
2780 (org-eval-in-environment (org-make-parameter-alist parameters)
2781 (if (> (length cmd-key) 2)
2782 (org-tags-view nil cmd-key)
2783 (org-agenda nil cmd-key)))
2784 (set-buffer org-agenda-buffer-name)
2785 (princ (buffer-string)))
2786 (def-edebug-spec org-batch-agenda (form &rest sexp))
2788 (defvar org-agenda-info nil)
2790 ;;;###autoload
2791 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2792 "Run an agenda command in batch mode and send the result to STDOUT.
2793 If CMD-KEY is a string of length 1, it is used as a key in
2794 `org-agenda-custom-commands' and triggers this command. If it is a
2795 longer string it is used as a tags/todo match string.
2796 Parameters are alternating variable names and values that will be bound
2797 before running the agenda command.
2799 The output gives a line for each selected agenda item. Each
2800 item is a list of comma-separated values, like this:
2802 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2804 category The category of the item
2805 head The headline, without TODO kwd, TAGS and PRIORITY
2806 type The type of the agenda entry, can be
2807 todo selected in TODO match
2808 tagsmatch selected in tags match
2809 diary imported from diary
2810 deadline a deadline on given date
2811 scheduled scheduled on given date
2812 timestamp entry has timestamp on given date
2813 closed entry was closed on given date
2814 upcoming-deadline warning about deadline
2815 past-scheduled forwarded scheduled item
2816 block entry has date block including g. date
2817 todo The todo keyword, if any
2818 tags All tags including inherited ones, separated by colons
2819 date The relevant date, like 2007-2-14
2820 time The time, like 15:00-16:50
2821 extra Sting with extra planning info
2822 priority-l The priority letter if any was given
2823 priority-n The computed numerical priority
2824 agenda-day The day in the agenda where this is listed"
2825 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2826 (org-make-parameter-alist parameters))
2827 (if (> (length cmd-key) 2)
2828 (org-tags-view nil cmd-key)
2829 (org-agenda nil cmd-key)))
2830 (set-buffer org-agenda-buffer-name)
2831 (let* ((lines (org-split-string (buffer-string) "\n"))
2832 line)
2833 (while (setq line (pop lines))
2834 (catch 'next
2835 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2836 (setq org-agenda-info
2837 (org-fix-agenda-info (text-properties-at 0 line)))
2838 (princ
2839 (mapconcat 'org-agenda-export-csv-mapper
2840 '(org-category txt type todo tags date time extra
2841 priority-letter priority agenda-day)
2842 ","))
2843 (princ "\n")))))
2844 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2846 (defun org-fix-agenda-info (props)
2847 "Make sure all properties on an agenda item have a canonical form.
2848 This ensures the export commands can easily use it."
2849 (let (tmp re)
2850 (when (setq tmp (plist-get props 'tags))
2851 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2852 (when (setq tmp (plist-get props 'date))
2853 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2854 (let ((calendar-date-display-form '(year "-" month "-" day)))
2855 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2857 (setq tmp (calendar-date-string tmp)))
2858 (setq props (plist-put props 'date tmp)))
2859 (when (setq tmp (plist-get props 'day))
2860 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2861 (let ((calendar-date-display-form '(year "-" month "-" day)))
2862 (setq tmp (calendar-date-string tmp)))
2863 (setq props (plist-put props 'day tmp))
2864 (setq props (plist-put props 'agenda-day tmp)))
2865 (when (setq tmp (plist-get props 'txt))
2866 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2867 (plist-put props 'priority-letter (match-string 1 tmp))
2868 (setq tmp (replace-match "" t t tmp)))
2869 (when (and (setq re (plist-get props 'org-todo-regexp))
2870 (setq re (concat "\\`\\.*" re " ?"))
2871 (string-match re tmp))
2872 (plist-put props 'todo (match-string 1 tmp))
2873 (setq tmp (replace-match "" t t tmp)))
2874 (plist-put props 'txt tmp)))
2875 props)
2877 (defun org-agenda-export-csv-mapper (prop)
2878 (let ((res (plist-get org-agenda-info prop)))
2879 (setq res
2880 (cond
2881 ((not res) "")
2882 ((stringp res) res)
2883 (t (prin1-to-string res))))
2884 (while (string-match "," res)
2885 (setq res (replace-match ";" t t res)))
2886 (org-trim res)))
2888 ;;;###autoload
2889 (defun org-store-agenda-views (&rest parameters)
2890 (interactive)
2891 (eval (list 'org-batch-store-agenda-views)))
2893 ;;;###autoload
2894 (defmacro org-batch-store-agenda-views (&rest parameters)
2895 "Run all custom agenda commands that have a file argument."
2896 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2897 (pop-up-frames nil)
2898 (dir default-directory)
2899 (pars (org-make-parameter-alist parameters))
2900 cmd thiscmdkey files opts cmd-or-set bufname)
2901 (save-window-excursion
2902 (while cmds
2903 (setq cmd (pop cmds)
2904 thiscmdkey (car cmd)
2905 bufname (if org-agenda-sticky (format "*Org Agenda(%s)*" thiscmdkey)
2906 org-agenda-buffer-name)
2907 cmd-or-set (nth 2 cmd)
2908 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2909 files (nth (if (listp cmd-or-set) 4 5) cmd))
2910 (if (stringp files) (setq files (list files)))
2911 (when files
2912 (org-eval-in-environment (append org-agenda-exporter-settings
2913 opts pars)
2914 (org-agenda nil thiscmdkey))
2915 (set-buffer bufname)
2916 (while files
2917 (org-eval-in-environment (append org-agenda-exporter-settings
2918 opts pars)
2919 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
2920 (and (get-buffer bufname)
2921 (kill-buffer bufname)))))))
2922 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2924 (defun org-agenda-mark-header-line (pos)
2925 "Mark the line at POS as an agenda structure header."
2926 (save-excursion
2927 (goto-char pos)
2928 (put-text-property (point-at-bol) (point-at-eol)
2929 'org-agenda-structural-header t)
2930 (when org-agenda-title-append
2931 (put-text-property (point-at-bol) (point-at-eol)
2932 'org-agenda-title-append org-agenda-title-append))))
2934 (defvar org-mobile-creating-agendas)
2935 (defvar org-agenda-write-buffer-name "Agenda View")
2936 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
2937 "Write the current buffer (an agenda view) as a file.
2938 Depending on the extension of the file name, plain text (.txt),
2939 HTML (.html or .htm) or Postscript (.ps) is produced.
2940 If the extension is .ics, run icalendar export over all files used
2941 to construct the agenda and limit the export to entries listed in the
2942 agenda now.
2943 With prefix argument OPEN, open the new file immediately.
2944 If NOSETTINGS is given, do not scope the settings of
2945 `org-agenda-exporter-settings' into the export commands. This is used when
2946 the settings have already been scoped and we do not wish to overrule other,
2947 higher priority settings.
2948 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
2949 (interactive "FWrite agenda to file: \nP")
2950 (if (not (file-writable-p file))
2951 (error "Cannot write agenda to file %s" file))
2952 (org-let (if nosettings nil org-agenda-exporter-settings)
2953 '(save-excursion
2954 (save-window-excursion
2955 (org-agenda-mark-filtered-text)
2956 (let ((bs (copy-sequence (buffer-string))) beg)
2957 (org-agenda-unmark-filtered-text)
2958 (with-temp-buffer
2959 (rename-buffer org-agenda-write-buffer-name t)
2960 (set-buffer-modified-p nil)
2961 (insert bs)
2962 (org-agenda-remove-marked-text 'org-filtered)
2963 (while (setq beg (text-property-any (point-min) (point-max)
2964 'org-filtered t))
2965 (delete-region
2966 beg (or (next-single-property-change beg 'org-filtered)
2967 (point-max))))
2968 (run-hooks 'org-agenda-before-write-hook)
2969 (cond
2970 ((org-bound-and-true-p org-mobile-creating-agendas)
2971 (org-mobile-write-agenda-for-mobile file))
2972 ((string-match "\\.html?\\'" file)
2973 (require 'htmlize)
2974 (set-buffer (htmlize-buffer (current-buffer)))
2975 (when (and org-agenda-export-html-style
2976 (string-match "<style>" org-agenda-export-html-style))
2977 ;; replace <style> section with org-agenda-export-html-style
2978 (goto-char (point-min))
2979 (kill-region (- (search-forward "<style") 6)
2980 (search-forward "</style>"))
2981 (insert org-agenda-export-html-style))
2982 (write-file file)
2983 (kill-buffer (current-buffer))
2984 (message "HTML written to %s" file))
2985 ((string-match "\\.ps\\'" file)
2986 (require 'ps-print)
2987 (ps-print-buffer-with-faces file)
2988 (message "Postscript written to %s" file))
2989 ((string-match "\\.pdf\\'" file)
2990 (require 'ps-print)
2991 (ps-print-buffer-with-faces
2992 (concat (file-name-sans-extension file) ".ps"))
2993 (call-process "ps2pdf" nil nil nil
2994 (expand-file-name
2995 (concat (file-name-sans-extension file) ".ps"))
2996 (expand-file-name file))
2997 (delete-file (concat (file-name-sans-extension file) ".ps"))
2998 (message "PDF written to %s" file))
2999 ((string-match "\\.ics\\'" file)
3000 (require 'org-icalendar)
3001 (let ((org-agenda-marker-table
3002 (org-create-marker-find-array
3003 (org-agenda-collect-markers)))
3004 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3005 (org-combined-agenda-icalendar-file file))
3006 (apply 'org-export-icalendar 'combine
3007 (org-agenda-files nil 'ifmode))))
3009 (let ((bs (buffer-string)))
3010 (find-file file)
3011 (erase-buffer)
3012 (insert bs)
3013 (save-buffer 0)
3014 (kill-buffer (current-buffer))
3015 (message "Plain text written to %s" file))))))))
3016 (set-buffer (or agenda-bufname
3017 (and (called-interactively-p 'any) (buffer-name))
3018 org-agenda-buffer-name)))
3019 (when open (org-open-file file)))
3021 (defvar org-agenda-tag-filter-overlays nil)
3022 (defvar org-agenda-cat-filter-overlays nil)
3024 (defun org-agenda-mark-filtered-text ()
3025 "Mark all text hidden by filtering with a text property."
3026 (let ((inhibit-read-only t))
3027 (mapc
3028 (lambda (o)
3029 (when (equal (overlay-buffer o) (current-buffer))
3030 (put-text-property
3031 (overlay-start o) (overlay-end o)
3032 'org-filtered t)))
3033 (append org-agenda-tag-filter-overlays
3034 org-agenda-cat-filter-overlays))))
3036 (defun org-agenda-unmark-filtered-text ()
3037 "Remove the filtering text property."
3038 (let ((inhibit-read-only t))
3039 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3041 (defun org-agenda-remove-marked-text (property &optional value)
3042 "Delete all text marked with VALUE of PROPERTY.
3043 VALUE defaults to t."
3044 (let (beg)
3045 (setq value (or value t))
3046 (while (setq beg (text-property-any (point-min) (point-max)
3047 property value))
3048 (delete-region
3049 beg (or (next-single-property-change beg 'org-filtered)
3050 (point-max))))))
3052 (defun org-agenda-add-entry-text ()
3053 "Add entry text to agenda lines.
3054 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3055 entry text following headings shown in the agenda.
3056 Drawers will be excluded, also the line with scheduling/deadline info."
3057 (when (and (> org-agenda-add-entry-text-maxlines 0)
3058 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3059 (let (m txt)
3060 (goto-char (point-min))
3061 (while (not (eobp))
3062 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3063 (beginning-of-line 2)
3064 (setq txt (org-agenda-get-some-entry-text
3065 m org-agenda-add-entry-text-maxlines " > "))
3066 (end-of-line 1)
3067 (if (string-match "\\S-" txt)
3068 (insert "\n" txt)
3069 (or (eobp) (forward-char 1))))))))
3071 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3072 &rest keep)
3073 "Extract entry text from MARKER, at most N-LINES lines.
3074 This will ignore drawers etc, just get the text.
3075 If INDENT is given, prefix every line with this string. If KEEP is
3076 given, it is a list of symbols, defining stuff that should not be
3077 removed from the entry content. Currently only `planning' is allowed here."
3078 (let (txt drawer-re kwd-time-re ind)
3079 (save-excursion
3080 (with-current-buffer (marker-buffer marker)
3081 (if (not (derived-mode-p 'org-mode))
3082 (setq txt "")
3083 (save-excursion
3084 (save-restriction
3085 (widen)
3086 (goto-char marker)
3087 (end-of-line 1)
3088 (setq txt (buffer-substring
3089 (min (1+ (point)) (point-max))
3090 (progn (outline-next-heading) (point)))
3091 drawer-re org-drawer-regexp
3092 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3093 ".*\n?"))
3094 (with-temp-buffer
3095 (insert txt)
3096 (when org-agenda-add-entry-text-descriptive-links
3097 (goto-char (point-min))
3098 (while (org-activate-bracket-links (point-max))
3099 (add-text-properties (match-beginning 0) (match-end 0)
3100 '(face org-link))))
3101 (goto-char (point-min))
3102 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3103 (set-text-properties (match-beginning 0) (match-end 0)
3104 nil))
3105 (goto-char (point-min))
3106 (while (re-search-forward drawer-re nil t)
3107 (delete-region
3108 (match-beginning 0)
3109 (progn (re-search-forward
3110 "^[ \t]*:END:.*\n?" nil 'move)
3111 (point))))
3112 (unless (member 'planning keep)
3113 (goto-char (point-min))
3114 (while (re-search-forward kwd-time-re nil t)
3115 (replace-match "")))
3116 (goto-char (point-min))
3117 (when org-agenda-entry-text-exclude-regexps
3118 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3119 (while (setq re (pop re-list))
3120 (goto-char (point-min))
3121 (while (re-search-forward re nil t)
3122 (replace-match "")))))
3123 (goto-char (point-max))
3124 (skip-chars-backward " \t\n")
3125 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3127 ;; find and remove min common indentation
3128 (goto-char (point-min))
3129 (untabify (point-min) (point-max))
3130 (setq ind (org-get-indentation))
3131 (while (not (eobp))
3132 (unless (looking-at "[ \t]*$")
3133 (setq ind (min ind (org-get-indentation))))
3134 (beginning-of-line 2))
3135 (goto-char (point-min))
3136 (while (not (eobp))
3137 (unless (looking-at "[ \t]*$")
3138 (move-to-column ind)
3139 (delete-region (point-at-bol) (point)))
3140 (beginning-of-line 2))
3142 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3144 (goto-char (point-min))
3145 (when indent
3146 (while (and (not (eobp)) (re-search-forward "^" nil t))
3147 (replace-match indent t t)))
3148 (goto-char (point-min))
3149 (while (looking-at "[ \t]*\n") (replace-match ""))
3150 (goto-char (point-max))
3151 (when (> (org-current-line)
3152 n-lines)
3153 (org-goto-line (1+ n-lines))
3154 (backward-char 1))
3155 (setq txt (buffer-substring (point-min) (point)))))))))
3156 txt))
3158 (defun org-agenda-collect-markers ()
3159 "Collect the markers pointing to entries in the agenda buffer."
3160 (let (m markers)
3161 (save-excursion
3162 (goto-char (point-min))
3163 (while (not (eobp))
3164 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3165 (org-get-at-bol 'org-marker)))
3166 (push m markers))
3167 (beginning-of-line 2)))
3168 (nreverse markers)))
3170 (defun org-create-marker-find-array (marker-list)
3171 "Create a alist of files names with all marker positions in that file."
3172 (let (f tbl m a p)
3173 (while (setq m (pop marker-list))
3174 (setq p (marker-position m)
3175 f (buffer-file-name (or (buffer-base-buffer
3176 (marker-buffer m))
3177 (marker-buffer m))))
3178 (if (setq a (assoc f tbl))
3179 (push (marker-position m) (cdr a))
3180 (push (list f p) tbl)))
3181 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3182 tbl)))
3184 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3185 (defun org-check-agenda-marker-table ()
3186 "Check of the current entry is on the marker list."
3187 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3189 (and (setq a (assoc file org-agenda-marker-table))
3190 (save-match-data
3191 (save-excursion
3192 (org-back-to-heading t)
3193 (member (point) (cdr a)))))))
3195 (defun org-check-for-org-mode ()
3196 "Make sure current buffer is in org-mode. Error if not."
3197 (or (derived-mode-p 'org-mode)
3198 (error "Cannot execute org-mode agenda command on buffer in %s"
3199 major-mode)))
3201 (defun org-fit-agenda-window ()
3202 "Fit the window to the buffer size."
3203 (and (memq org-agenda-window-setup '(reorganize-frame))
3204 (fboundp 'fit-window-to-buffer)
3205 (org-fit-window-to-buffer
3207 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3208 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3210 ;;; Agenda prepare and finalize
3212 (defvar org-agenda-multi nil) ; dynamically scoped
3213 (defvar org-agenda-buffer-name "*Org Agenda*")
3214 (defvar org-pre-agenda-window-conf nil)
3215 (defvar org-agenda-columns-active nil)
3216 (defvar org-agenda-name nil)
3217 (defvar org-agenda-tag-filter nil)
3218 (defvar org-agenda-category-filter nil)
3219 (defvar org-agenda-top-category-filter nil)
3220 (defvar org-agenda-tag-filter-while-redo nil)
3221 (defvar org-agenda-tag-filter-preset nil
3222 "A preset of the tags filter used for secondary agenda filtering.
3223 This must be a list of strings, each string must be a single tag preceded
3224 by \"+\" or \"-\".
3225 This variable should not be set directly, but agenda custom commands can
3226 bind it in the options section. The preset filter is a global property of
3227 the entire agenda view. In a block agenda, it will not work reliably to
3228 define a filter for one of the individual blocks. You need to set it in
3229 the global options and expect it to be applied to the entire view.")
3231 (defvar org-agenda-category-filter-preset nil
3232 "A preset of the category filter used for secondary agenda filtering.
3233 This must be a list of strings, each string must be a single category
3234 preceded by \"+\" or \"-\".
3235 This variable should not be set directly, but agenda custom commands can
3236 bind it in the options section. The preset filter is a global property of
3237 the entire agenda view. In a block agenda, it will not work reliably to
3238 define a filter for one of the individual blocks. You need to set it in
3239 the global options and expect it to be applied to the entire view.")
3242 (defun org-agenda-use-sticky-p ()
3243 "Return non-nil if an agenda buffer named
3244 `org-agenda-buffer-name' exists and should be shown instead of
3245 generating a new one."
3246 (and
3247 ;; turned off by user
3248 org-agenda-sticky
3249 ;; For multi-agenda buffer already exists
3250 (not org-agenda-multi)
3251 ;; buffer found
3252 (get-buffer org-agenda-buffer-name)
3253 ;; C-u parameter is same as last call
3254 (with-current-buffer (get-buffer org-agenda-buffer-name)
3255 (and
3256 (equal current-prefix-arg
3257 org-agenda-last-prefix-arg)
3258 ;; In case user turned stickiness on, while having existing
3259 ;; Agenda buffer active, don't reuse that buffer, because it
3260 ;; does not have org variables local
3261 org-agenda-this-buffer-is-sticky))))
3263 (defun org-prepare-agenda-window (abuf)
3264 "Setup agenda buffer in the window."
3265 (let* ((awin (get-buffer-window abuf))
3266 wconf)
3267 (cond
3268 ((equal (current-buffer) abuf) nil)
3269 (awin (select-window awin))
3270 ((not (setq wconf (current-window-configuration))))
3271 ((equal org-agenda-window-setup 'current-window)
3272 (org-pop-to-buffer-same-window abuf))
3273 ((equal org-agenda-window-setup 'other-window)
3274 (org-switch-to-buffer-other-window abuf))
3275 ((equal org-agenda-window-setup 'other-frame)
3276 (switch-to-buffer-other-frame abuf))
3277 ((equal org-agenda-window-setup 'reorganize-frame)
3278 (delete-other-windows)
3279 (org-switch-to-buffer-other-window abuf)))
3280 ;; additional test in case agenda is invoked from within agenda
3281 ;; buffer via elisp link
3282 (unless (equal (current-buffer) abuf)
3283 (org-pop-to-buffer-same-window abuf))
3284 (setq org-pre-agenda-window-conf wconf)))
3286 (defun org-prepare-agenda (&optional name)
3287 (if (org-agenda-use-sticky-p)
3288 (progn
3289 ;; Popup existing buffer
3290 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3291 (message "Sticky Agenda buffer, use `r' to refresh")
3292 (throw 'exit nil))
3293 (setq org-todo-keywords-for-agenda nil)
3294 (setq org-drawers-for-agenda nil)
3295 (unless org-agenda-persistent-filter
3296 (setq org-agenda-tag-filter nil
3297 org-agenda-category-filter nil))
3298 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3299 (put 'org-agenda-category-filter :preset-filter
3300 org-agenda-category-filter-preset)
3301 (if org-agenda-multi
3302 (progn
3303 (setq buffer-read-only nil)
3304 (goto-char (point-max))
3305 (unless (or (bobp) org-agenda-compact-blocks
3306 (not org-agenda-block-separator))
3307 (insert "\n"
3308 (if (stringp org-agenda-block-separator)
3309 org-agenda-block-separator
3310 (make-string (window-width) org-agenda-block-separator))
3311 "\n"))
3312 (narrow-to-region (point) (point-max)))
3313 (setq org-done-keywords-for-agenda nil)
3315 ;; Setting any org variables that are in org-agenda-local-vars
3316 ;; list need to be done after the prepare call
3317 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3318 (setq buffer-read-only nil)
3319 (org-agenda-reset-markers)
3320 (let ((inhibit-read-only t)) (erase-buffer))
3321 (org-agenda-mode)
3322 (setq org-agenda-buffer (current-buffer))
3323 (setq org-agenda-contributing-files nil)
3324 (setq org-agenda-columns-active nil)
3325 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3326 (setq org-todo-keywords-for-agenda
3327 (org-uniquify org-todo-keywords-for-agenda))
3328 (setq org-done-keywords-for-agenda
3329 (org-uniquify org-done-keywords-for-agenda))
3330 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3331 (setq org-agenda-last-prefix-arg current-prefix-arg)
3332 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3333 (and name (not org-agenda-name)
3334 (org-set-local 'org-agenda-name name)))
3335 (setq buffer-read-only nil)))
3337 (defun org-finalize-agenda ()
3338 "Finishing touch for the agenda buffer, called just before displaying it."
3339 (unless org-agenda-multi
3340 (save-excursion
3341 (let ((inhibit-read-only t))
3342 (goto-char (point-min))
3343 (while (org-activate-bracket-links (point-max))
3344 (add-text-properties (match-beginning 0) (match-end 0)
3345 '(face org-link)))
3346 (org-agenda-align-tags)
3347 (unless org-agenda-with-colors
3348 (remove-text-properties (point-min) (point-max) '(face nil))))
3349 (if (and (boundp 'org-agenda-overriding-columns-format)
3350 org-agenda-overriding-columns-format)
3351 (org-set-local 'org-agenda-overriding-columns-format
3352 org-agenda-overriding-columns-format))
3353 (if (and (boundp 'org-agenda-view-columns-initially)
3354 org-agenda-view-columns-initially)
3355 (org-agenda-columns))
3356 (when org-agenda-fontify-priorities
3357 (org-agenda-fontify-priorities))
3358 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3359 (org-agenda-dim-blocked-tasks))
3360 (org-agenda-mark-clocking-task)
3361 (when org-agenda-entry-text-mode
3362 (org-agenda-entry-text-hide)
3363 (org-agenda-entry-text-show))
3364 (if (functionp 'org-habit-insert-consistency-graphs)
3365 (org-habit-insert-consistency-graphs))
3366 (run-hooks 'org-finalize-agenda-hook)
3367 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3368 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3369 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3370 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3371 (org-agenda-filter-apply org-agenda-category-filter 'category))
3372 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3375 (defun org-agenda-mark-clocking-task ()
3376 "Mark the current clock entry in the agenda if it is present."
3377 (mapc (lambda (o)
3378 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3379 (delete-overlay o)))
3380 (overlays-in (point-min) (point-max)))
3381 (when (marker-buffer org-clock-hd-marker)
3382 (save-excursion
3383 (goto-char (point-min))
3384 (let (s ov)
3385 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3386 (goto-char s)
3387 (when (equal (org-get-at-bol 'org-hd-marker)
3388 org-clock-hd-marker)
3389 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3390 (overlay-put ov 'type 'org-agenda-clocking)
3391 (overlay-put ov 'face 'org-agenda-clocking)
3392 (overlay-put ov 'help-echo
3393 "The clock is running in this item")))))))
3395 (defun org-agenda-fontify-priorities ()
3396 "Make highest priority lines bold, and lowest italic."
3397 (interactive)
3398 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3399 (delete-overlay o)))
3400 (overlays-in (point-min) (point-max)))
3401 (save-excursion
3402 (let ((inhibit-read-only t)
3403 b e p ov h l)
3404 (goto-char (point-min))
3405 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3406 (setq h (or (get-char-property (point) 'org-highest-priority)
3407 org-highest-priority)
3408 l (or (get-char-property (point) 'org-lowest-priority)
3409 org-lowest-priority)
3410 p (string-to-char (match-string 1))
3411 b (match-beginning 0)
3412 e (if (eq org-agenda-fontify-priorities 'cookies)
3413 (match-end 0)
3414 (point-at-eol))
3415 ov (make-overlay b e))
3416 (overlay-put
3417 ov 'face
3418 (cond ((org-face-from-face-or-color
3419 'priority nil
3420 (cdr (assoc p org-priority-faces))))
3421 ((and (listp org-agenda-fontify-priorities)
3422 (org-face-from-face-or-color
3423 'priority nil
3424 (cdr (assoc p org-agenda-fontify-priorities)))))
3425 ((equal p l) 'italic)
3426 ((equal p h) 'bold)))
3427 (overlay-put ov 'org-type 'org-priority)))))
3429 (defun org-agenda-dim-blocked-tasks ()
3430 "Dim currently blocked TODO's in the agenda display."
3431 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3432 (delete-overlay o)))
3433 (overlays-in (point-min) (point-max)))
3434 (save-excursion
3435 (let ((inhibit-read-only t)
3436 (org-depend-tag-blocked nil)
3437 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3438 org-blocked-by-checkboxes
3439 invis1 b e p ov h l)
3440 (goto-char (point-min))
3441 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3442 (and pos (goto-char (1+ pos))))
3443 (setq org-blocked-by-checkboxes nil invis1 invis)
3444 (let ((marker (org-get-at-bol 'org-hd-marker)))
3445 (when (and marker
3446 (with-current-buffer (marker-buffer marker)
3447 (save-excursion (goto-char marker)
3448 (org-entry-blocked-p))))
3449 (if org-blocked-by-checkboxes (setq invis1 nil))
3450 (setq b (if invis1
3451 (max (point-min) (1- (point-at-bol)))
3452 (point-at-bol))
3453 e (point-at-eol)
3454 ov (make-overlay b e))
3455 (if invis1
3456 (overlay-put ov 'invisible t)
3457 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3458 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3460 (defvar org-agenda-skip-function nil
3461 "Function to be called at each match during agenda construction.
3462 If this function returns nil, the current match should not be skipped.
3463 Otherwise, the function must return a position from where the search
3464 should be continued.
3465 This may also be a Lisp form, it will be evaluated.
3466 Never set this variable using `setq' or so, because then it will apply
3467 to all future agenda commands. If you do want a global skipping condition,
3468 use the option `org-agenda-skip-function-global' instead.
3469 The correct usage for `org-agenda-skip-function' is to bind it with
3470 `let' to scope it dynamically into the agenda-constructing command.
3471 A good way to set it is through options in `org-agenda-custom-commands'.")
3473 (defun org-agenda-skip ()
3474 "Throw to `:skip' in places that should be skipped.
3475 Also moves point to the end of the skipped region, so that search can
3476 continue from there."
3477 (let ((p (point-at-bol)) to)
3478 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3479 (get-text-property p :org-archived)
3480 (org-end-of-subtree t)
3481 (throw :skip t))
3482 (and org-agenda-skip-comment-trees
3483 (get-text-property p :org-comment)
3484 (org-end-of-subtree t)
3485 (throw :skip t))
3486 (if (equal (char-after p) ?#) (throw :skip t))
3487 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3488 (org-agenda-skip-eval org-agenda-skip-function)))
3489 (goto-char to)
3490 (throw :skip t))))
3492 (defun org-agenda-skip-eval (form)
3493 "If FORM is a function or a list, call (or eval) is and return result.
3494 `save-excursion' and `save-match-data' are wrapped around the call, so point
3495 and match data are returned to the previous state no matter what these
3496 functions do."
3497 (let (fp)
3498 (and form
3499 (or (setq fp (functionp form))
3500 (consp form))
3501 (save-excursion
3502 (save-match-data
3503 (if fp
3504 (funcall form)
3505 (eval form)))))))
3507 (defvar org-agenda-markers nil
3508 "List of all currently active markers created by `org-agenda'.")
3509 (defvar org-agenda-last-marker-time (org-float-time)
3510 "Creation time of the last agenda marker.")
3512 (defun org-agenda-new-marker (&optional pos)
3513 "Return a new agenda marker.
3514 Org-mode keeps a list of these markers and resets them when they are
3515 no longer in use."
3516 (let ((m (copy-marker (or pos (point)))))
3517 (setq org-agenda-last-marker-time (org-float-time))
3518 (if org-agenda-buffer
3519 (with-current-buffer org-agenda-buffer
3520 (push m org-agenda-markers))
3521 (push m org-agenda-markers))
3524 (defun org-agenda-reset-markers ()
3525 "Reset markers created by `org-agenda'."
3526 (while org-agenda-markers
3527 (move-marker (pop org-agenda-markers) nil)))
3529 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3530 "Save relative positions of markers in region.
3531 This check for agenda markers in all agenda buffers currently active."
3532 (dolist (buf (buffer-list))
3533 (with-current-buffer buf
3534 (when (eq major-mode 'org-agenda-mode)
3535 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3536 org-agenda-markers)))))
3538 ;;; Entry text mode
3540 (defun org-agenda-entry-text-show-here ()
3541 "Add some text from the entry as context to the current line."
3542 (let (m txt o)
3543 (setq m (org-get-at-bol 'org-hd-marker))
3544 (unless (marker-buffer m)
3545 (error "No marker points to an entry here"))
3546 (setq txt (concat "\n" (org-no-properties
3547 (org-agenda-get-some-entry-text
3548 m org-agenda-entry-text-maxlines " > "))))
3549 (when (string-match "\\S-" txt)
3550 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3551 (overlay-put o 'evaporate t)
3552 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3553 (overlay-put o 'after-string txt))))
3555 (defun org-agenda-entry-text-show ()
3556 "Add entry context for all agenda lines."
3557 (interactive)
3558 (save-excursion
3559 (goto-char (point-max))
3560 (beginning-of-line 1)
3561 (while (not (bobp))
3562 (when (org-get-at-bol 'org-hd-marker)
3563 (org-agenda-entry-text-show-here))
3564 (beginning-of-line 0))))
3566 (defun org-agenda-entry-text-hide ()
3567 "Remove any shown entry context."
3568 (delq nil
3569 (mapcar (lambda (o)
3570 (if (eq (overlay-get o 'org-overlay-type)
3571 'agenda-entry-content)
3572 (progn (delete-overlay o) t)))
3573 (overlays-in (point-min) (point-max)))))
3575 (defun org-agenda-get-day-face (date)
3576 "Return the face DATE should be displayed with."
3577 (or (and (functionp org-agenda-day-face-function)
3578 (funcall org-agenda-day-face-function date))
3579 (cond ((org-agenda-todayp date)
3580 'org-agenda-date-today)
3581 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3582 'org-agenda-date-weekend)
3583 (t 'org-agenda-date))))
3585 ;;; Agenda timeline
3587 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3589 (defun org-timeline (&optional dotodo)
3590 "Show a time-sorted view of the entries in the current org file.
3591 Only entries with a time stamp of today or later will be listed. With
3592 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3593 under the current date.
3594 If the buffer contains an active region, only check the region for
3595 dates."
3596 (interactive "P")
3597 (let* ((dopast t)
3598 (org-agenda-show-log-scoped org-agenda-show-log)
3599 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3600 (current-buffer))))
3601 (date (calendar-current-date))
3602 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3603 (end (if (org-region-active-p) (region-end) (point-max)))
3604 (day-numbers (org-get-all-dates
3605 beg end 'no-ranges
3606 t org-agenda-show-log-scoped ; always include today
3607 org-timeline-show-empty-dates))
3608 (org-deadline-warning-days 0)
3609 (org-agenda-only-exact-dates t)
3610 (today (org-today))
3611 (past t)
3612 args
3613 s e rtn d emptyp)
3614 (setq org-agenda-redo-command
3615 (list 'progn
3616 (list 'org-switch-to-buffer-other-window (current-buffer))
3617 (list 'org-timeline (list 'quote dotodo))))
3618 (if (not dopast)
3619 ;; Remove past dates from the list of dates.
3620 (setq day-numbers (delq nil (mapcar (lambda(x)
3621 (if (>= x today) x nil))
3622 day-numbers))))
3623 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3624 (org-compile-prefix-format 'timeline)
3625 (org-set-sorting-strategy 'timeline)
3626 (if org-agenda-show-log-scoped (push :closed args))
3627 (push :timestamp args)
3628 (push :deadline args)
3629 (push :scheduled args)
3630 (push :sexp args)
3631 (if dotodo (push :todo args))
3632 (insert "Timeline of file " entry "\n")
3633 (add-text-properties (point-min) (point)
3634 (list 'face 'org-agenda-structure))
3635 (org-agenda-mark-header-line (point-min))
3636 (while (setq d (pop day-numbers))
3637 (if (and (listp d) (eq (car d) :omitted))
3638 (progn
3639 (setq s (point))
3640 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3641 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3642 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3643 (if (and (>= d today)
3644 dopast
3645 past)
3646 (progn
3647 (setq past nil)
3648 (insert (make-string 79 ?-) "\n")))
3649 (setq date (calendar-gregorian-from-absolute d))
3650 (setq s (point))
3651 (setq rtn (and (not emptyp)
3652 (apply 'org-agenda-get-day-entries entry
3653 date args)))
3654 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3655 (progn
3656 (insert
3657 (if (stringp org-agenda-format-date)
3658 (format-time-string org-agenda-format-date
3659 (org-time-from-absolute date))
3660 (funcall org-agenda-format-date date))
3661 "\n")
3662 (put-text-property s (1- (point)) 'face
3663 (org-agenda-get-day-face date))
3664 (put-text-property s (1- (point)) 'org-date-line t)
3665 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3666 (if (equal d today)
3667 (put-text-property s (1- (point)) 'org-today t))
3668 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3669 (put-text-property s (1- (point)) 'day d)))))
3670 (goto-char (point-min))
3671 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3672 (point-min)))
3673 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3674 (org-finalize-agenda)
3675 (setq buffer-read-only t)))
3677 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3678 "Return a list of all relevant day numbers from BEG to END buffer positions.
3679 If NO-RANGES is non-nil, include only the start and end dates of a range,
3680 not every single day in the range. If FORCE-TODAY is non-nil, make
3681 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3682 inactive time stamps (those in square brackets) are included.
3683 When EMPTY is non-nil, also include days without any entries."
3684 (let ((re (concat
3685 (if pre-re pre-re "")
3686 (if inactive org-ts-regexp-both org-ts-regexp)))
3687 dates dates1 date day day1 day2 ts1 ts2 pos)
3688 (if force-today
3689 (setq dates (list (org-today))))
3690 (save-excursion
3691 (goto-char beg)
3692 (while (re-search-forward re end t)
3693 (setq day (time-to-days (org-time-string-to-time
3694 (substring (match-string 1) 0 10)
3695 (current-buffer) (match-beginning 0))))
3696 (or (memq day dates) (push day dates)))
3697 (unless no-ranges
3698 (goto-char beg)
3699 (while (re-search-forward org-tr-regexp end t)
3700 (setq pos (match-beginning 0))
3701 (setq ts1 (substring (match-string 1) 0 10)
3702 ts2 (substring (match-string 2) 0 10)
3703 day1 (time-to-days (org-time-string-to-time
3704 ts1 (current-buffer) pos))
3705 day2 (time-to-days (org-time-string-to-time
3706 ts2 (current-buffer) pos)))
3707 (while (< (setq day1 (1+ day1)) day2)
3708 (or (memq day1 dates) (push day1 dates)))))
3709 (setq dates (sort dates '<))
3710 (when empty
3711 (while (setq day (pop dates))
3712 (setq day2 (car dates))
3713 (push day dates1)
3714 (when (and day2 empty)
3715 (if (or (eq empty t)
3716 (and (numberp empty) (<= (- day2 day) empty)))
3717 (while (< (setq day (1+ day)) day2)
3718 (push (list day) dates1))
3719 (push (cons :omitted (- day2 day)) dates1))))
3720 (setq dates (nreverse dates1)))
3721 dates)))
3723 ;;; Agenda Daily/Weekly
3725 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3726 "Start day for the agenda view.
3727 Custom commands can set this variable in the options section.")
3728 (defvar org-starting-day nil) ; local variable in the agenda buffer
3729 (defvar org-agenda-current-span nil
3730 "The current span used in the agenda view.") ; local variable in the agenda buffer
3731 (defvar org-arg-loc nil) ; local variable
3733 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3734 "List of types searched for when creating the daily/weekly agenda.
3735 This variable is a list of symbols that controls the types of
3736 items that appear in the daily/weekly agenda. Allowed symbols in this
3737 list are are
3739 :timestamp List items containing a date stamp or date range matching
3740 the selected date. This includes sexp entries in
3741 angular brackets.
3743 :sexp List entries resulting from plain diary-like sexps.
3745 :deadline List deadline due on that date. When the date is today,
3746 also list any deadlines past due, or due within
3747 `org-deadline-warning-days'. `:deadline' must appear before
3748 `:scheduled' if the setting of
3749 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3750 any effect.
3752 :scheduled List all items which are scheduled for the given date.
3753 The diary for *today* also contains items which were
3754 scheduled earlier and are not yet marked DONE.
3756 By default, all four types are turned on.
3758 Never set this variable globally using `setq', because then it
3759 will apply to all future agenda commands. Instead, bind it with
3760 `let' to scope it dynamically into the agenda-constructing
3761 command. A good way to set it is through options in
3762 `org-agenda-custom-commands'. For a more flexible (though
3763 somewhat less efficient) way of determining what is included in
3764 the daily/weekly agenda, see `org-agenda-skip-function'.")
3766 ;;;###autoload
3767 (defun org-agenda-list (&optional arg start-day span)
3768 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3769 The view will be for the current day or week, but from the overview buffer
3770 you will be able to go to other days/weeks.
3772 With a numeric prefix argument in an interactive call, the agenda will
3773 span ARG days. Lisp programs should instead specify SPAN to change
3774 the number of days. SPAN defaults to `org-agenda-span'.
3776 START-DAY defaults to TODAY, or to the most recent match for the weekday
3777 given in `org-agenda-start-on-weekday'."
3778 (interactive "P")
3779 (if (and (integerp arg) (> arg 0))
3780 (setq span arg arg nil))
3781 (org-prepare-agenda "Day/Week")
3782 (setq start-day (or start-day org-agenda-start-day))
3783 (if org-agenda-overriding-arguments
3784 (setq arg (car org-agenda-overriding-arguments)
3785 start-day (nth 1 org-agenda-overriding-arguments)
3786 span (nth 2 org-agenda-overriding-arguments)))
3787 (if (stringp start-day)
3788 ;; Convert to an absolute day number
3789 (setq start-day (time-to-days (org-read-date nil t start-day))))
3790 (setq org-agenda-last-arguments (list arg start-day span))
3791 (org-compile-prefix-format 'agenda)
3792 (org-set-sorting-strategy 'agenda)
3793 (let* ((span (org-agenda-ndays-to-span
3794 (or span org-agenda-ndays org-agenda-span)))
3795 (today (org-today))
3796 (sd (or start-day today))
3797 (ndays (org-agenda-span-to-ndays span sd))
3798 (org-agenda-start-on-weekday
3799 (if (eq ndays 7)
3800 org-agenda-start-on-weekday))
3801 (thefiles (org-agenda-files nil 'ifmode))
3802 (files thefiles)
3803 (start (if (or (null org-agenda-start-on-weekday)
3804 (< ndays 7))
3806 (let* ((nt (calendar-day-of-week
3807 (calendar-gregorian-from-absolute sd)))
3808 (n1 org-agenda-start-on-weekday)
3809 (d (- nt n1)))
3810 (- sd (+ (if (< d 0) 7 0) d)))))
3811 (day-numbers (list start))
3812 (day-cnt 0)
3813 (inhibit-redisplay (not debug-on-error))
3814 (org-agenda-show-log-scoped org-agenda-show-log)
3815 s e rtn rtnall file date d start-pos end-pos todayp
3816 clocktable-start clocktable-end filter)
3817 (setq org-agenda-redo-command
3818 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3819 (dotimes (n (1- ndays))
3820 (push (1+ (car day-numbers)) day-numbers))
3821 (setq day-numbers (nreverse day-numbers))
3822 (setq clocktable-start (car day-numbers)
3823 clocktable-end (1+ (or (org-last day-numbers) 0)))
3824 (org-set-local 'org-starting-day (car day-numbers))
3825 (org-set-local 'org-arg-loc arg)
3826 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3827 (unless org-agenda-compact-blocks
3828 (let* ((d1 (car day-numbers))
3829 (d2 (org-last day-numbers))
3830 (w1 (org-days-to-iso-week d1))
3831 (w2 (org-days-to-iso-week d2)))
3832 (setq s (point))
3833 (if org-agenda-overriding-header
3834 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3835 nil 'face 'org-agenda-structure) "\n")
3836 (insert (org-agenda-span-name span)
3837 "-agenda"
3838 (if (< (- d2 d1) 350)
3839 (if (= w1 w2)
3840 (format " (W%02d)" w1)
3841 (format " (W%02d-W%02d)" w1 w2))
3843 ":\n")))
3844 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3845 'org-date-line t))
3846 (org-agenda-mark-header-line s))
3847 (while (setq d (pop day-numbers))
3848 (setq date (calendar-gregorian-from-absolute d)
3849 s (point))
3850 (if (or (setq todayp (= d today))
3851 (and (not start-pos) (= d sd)))
3852 (setq start-pos (point))
3853 (if (and start-pos (not end-pos))
3854 (setq end-pos (point))))
3855 (setq files thefiles
3856 rtnall nil)
3857 (while (setq file (pop files))
3858 (catch 'nextfile
3859 (org-check-agenda-file file)
3860 (let ((org-agenda-entry-types org-agenda-entry-types))
3861 (unless org-agenda-include-deadlines
3862 (setq org-agenda-entry-types
3863 (delq :deadline org-agenda-entry-types)))
3864 (cond
3865 ((memq org-agenda-show-log-scoped '(only clockcheck))
3866 (setq rtn (org-agenda-get-day-entries
3867 file date :closed)))
3868 (org-agenda-show-log-scoped
3869 (setq rtn (apply 'org-agenda-get-day-entries
3870 file date
3871 (append '(:closed) org-agenda-entry-types))))
3873 (setq rtn (apply 'org-agenda-get-day-entries
3874 file date
3875 org-agenda-entry-types)))))
3876 (setq rtnall (append rtnall rtn)))) ;; all entries
3877 (if org-agenda-include-diary
3878 (let ((org-agenda-search-headline-for-time t))
3879 (require 'diary-lib)
3880 (setq rtn (org-get-entries-from-diary date))
3881 (setq rtnall (append rtnall rtn))))
3882 (if (or rtnall org-agenda-show-all-dates)
3883 (progn
3884 (setq day-cnt (1+ day-cnt))
3885 (insert
3886 (if (stringp org-agenda-format-date)
3887 (format-time-string org-agenda-format-date
3888 (org-time-from-absolute date))
3889 (funcall org-agenda-format-date date))
3890 "\n")
3891 (put-text-property s (1- (point)) 'face
3892 (org-agenda-get-day-face date))
3893 (put-text-property s (1- (point)) 'org-date-line t)
3894 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3895 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3896 (when todayp
3897 (put-text-property s (1- (point)) 'org-today t))
3898 (if rtnall (insert ;; all entries
3899 (org-finalize-agenda-entries
3900 (org-agenda-add-time-grid-maybe
3901 rtnall ndays todayp))
3902 "\n"))
3903 (put-text-property s (1- (point)) 'day d)
3904 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3905 (when (and org-agenda-clockreport-mode clocktable-start)
3906 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3907 ;; the above line is to ensure the restricted range!
3908 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3909 tbl)
3910 (setq p (org-plist-delete p :block))
3911 (setq p (plist-put p :tstart clocktable-start))
3912 (setq p (plist-put p :tend clocktable-end))
3913 (setq p (plist-put p :scope 'agenda))
3914 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3915 (setq filter (or org-agenda-tag-filter-while-redo
3916 (get 'org-agenda-tag-filter :preset-filter))))
3917 (setq p (plist-put p :tags (mapconcat (lambda (x)
3918 (if (string-match "[<>=]" x)
3921 filter ""))))
3922 (setq tbl (apply 'org-get-clocktable p))
3923 (insert tbl)))
3924 (goto-char (point-min))
3925 (or org-agenda-multi (org-fit-agenda-window))
3926 (unless (and (pos-visible-in-window-p (point-min))
3927 (pos-visible-in-window-p (point-max)))
3928 (goto-char (1- (point-max)))
3929 (recenter -1)
3930 (if (not (pos-visible-in-window-p (or start-pos 1)))
3931 (progn
3932 (goto-char (or start-pos 1))
3933 (recenter 1))))
3934 (goto-char (or start-pos 1))
3935 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3936 (if (eq org-agenda-show-log-scoped 'clockcheck)
3937 (org-agenda-show-clocking-issues))
3938 (org-finalize-agenda)
3939 (setq buffer-read-only t)
3940 (message "")))
3942 (defun org-agenda-ndays-to-span (n)
3943 "Return a span symbol for a span of N days, or N if none matches."
3944 (cond ((symbolp n) n)
3945 ((= n 1) 'day)
3946 ((= n 7) 'week)
3947 (t n)))
3949 (defun org-agenda-span-to-ndays (span start-day)
3950 "Return ndays from SPAN starting at START-DAY."
3951 (cond ((numberp span) span)
3952 ((eq span 'day) 1)
3953 ((eq span 'week) 7)
3954 ((eq span 'month)
3955 (let ((date (calendar-gregorian-from-absolute start-day)))
3956 (calendar-last-day-of-month (car date) (caddr date))))
3957 ((eq span 'year)
3958 (let ((date (calendar-gregorian-from-absolute start-day)))
3959 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3961 (defun org-agenda-span-name (span)
3962 "Return a SPAN name."
3963 (if (null span)
3965 (if (symbolp span)
3966 (capitalize (symbol-name span))
3967 (format "%d days" span))))
3969 ;;; Agenda word search
3971 (defvar org-agenda-search-history nil)
3972 (defvar org-todo-only nil)
3974 (defvar org-search-syntax-table nil
3975 "Special syntax table for org-mode search.
3976 In this table, we have single quotes not as word constituents, to
3977 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3979 (defun org-search-syntax-table ()
3980 (unless org-search-syntax-table
3981 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3982 (modify-syntax-entry ?' "." org-search-syntax-table)
3983 (modify-syntax-entry ?` "." org-search-syntax-table))
3984 org-search-syntax-table)
3986 (defvar org-agenda-last-search-view-search-was-boolean nil)
3988 ;;;###autoload
3989 (defun org-search-view (&optional todo-only string edit-at)
3990 "Show all entries that contain a phrase or words or regular expressions.
3992 With optional prefix argument TODO-ONLY, only consider entries that are
3993 TODO entries. The argument STRING can be used to pass a default search
3994 string into this function. If EDIT-AT is non-nil, it means that the
3995 user should get a chance to edit this string, with cursor at position
3996 EDIT-AT.
3998 The search string can be viewed either as a phrase that should be found as
3999 is, or it can be broken into a number of snippets, each of which must match
4000 in a Boolean way to select an entry. The default depends on the variable
4001 `org-agenda-search-view-always-boolean'.
4002 Even if this is turned off (the default) you can always switch to
4003 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4005 The default is a direct search of the whole phrase, where each space in
4006 the search string can expand to an arbitrary amount of whitespace,
4007 including newlines.
4009 If using a Boolean search, the search string is split on whitespace and
4010 each snippet is searched separately, with logical AND to select an entry.
4011 Words prefixed with a minus must *not* occur in the entry. Words without
4012 a prefix or prefixed with a plus must occur in the entry. Matching is
4013 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4014 match whole words, not parts of a word) if
4015 `org-agenda-search-view-force-full-words' is set (default is nil).
4017 Boolean search snippets enclosed by curly braces are interpreted as
4018 regular expressions that must or (when preceded with \"-\") must not
4019 match in the entry. Snippets enclosed into double quotes will be taken
4020 as a whole, to include whitespace.
4022 - If the search string starts with an asterisk, search only in headlines.
4023 - If (possibly after the leading star) the search string starts with an
4024 exclamation mark, this also means to look at TODO entries only, an effect
4025 that can also be achieved with a prefix argument.
4026 - If (possibly after star and exclamation mark) the search string starts
4027 with a colon, this will mean that the (non-regexp) snippets of the
4028 Boolean search must match as full words.
4030 This command searches the agenda files, and in addition the files listed
4031 in `org-agenda-text-search-extra-files'."
4032 (interactive "P")
4033 (org-prepare-agenda "SEARCH")
4034 (org-compile-prefix-format 'search)
4035 (org-set-sorting-strategy 'search)
4036 (let* ((props (list 'face nil
4037 'done-face 'org-agenda-done
4038 'org-not-done-regexp org-not-done-regexp
4039 'org-todo-regexp org-todo-regexp
4040 'org-complex-heading-regexp org-complex-heading-regexp
4041 'mouse-face 'highlight
4042 'help-echo (format "mouse-2 or RET jump to location")))
4043 (full-words org-agenda-search-view-force-full-words)
4044 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4045 regexp rtn rtnall files file pos
4046 marker category org-category-pos tags c neg re boolean
4047 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4048 (unless (and (not edit-at)
4049 (stringp string)
4050 (string-match "\\S-" string))
4051 (setq string (read-string
4052 (if org-agenda-search-view-always-boolean
4053 "[+-]Word/{Regexp} ...: "
4054 "Phrase, or [+-]Word/{Regexp} ...: ")
4055 (cond
4056 ((integerp edit-at) (cons string edit-at))
4057 (edit-at string))
4058 'org-agenda-search-history)))
4059 (org-set-local 'org-todo-only todo-only)
4060 (setq org-agenda-redo-command
4061 (list 'org-search-view (if todo-only t nil) string
4062 '(if current-prefix-arg 1 nil)))
4063 (setq org-agenda-query-string string)
4065 (if (equal (string-to-char string) ?*)
4066 (setq hdl-only t
4067 words (substring string 1))
4068 (setq words string))
4069 (when (equal (string-to-char words) ?!)
4070 (setq todo-only t
4071 words (substring words 1)))
4072 (when (equal (string-to-char words) ?:)
4073 (setq full-words t
4074 words (substring words 1)))
4075 (if (or org-agenda-search-view-always-boolean
4076 (member (string-to-char words) '(?- ?+ ?\{)))
4077 (setq boolean t))
4078 (setq words (org-split-string words))
4079 (let (www w)
4080 (while (setq w (pop words))
4081 (while (and (string-match "\\\\\\'" w) words)
4082 (setq w (concat (substring w 0 -1) " " (pop words))))
4083 (push w www))
4084 (setq words (nreverse www) www nil)
4085 (while (setq w (pop words))
4086 (when (and (string-match "\\`[-+]?{" w)
4087 (not (string-match "}\\'" w)))
4088 (while (and words (not (string-match "}\\'" (car words))))
4089 (setq w (concat w " " (pop words))))
4090 (setq w (concat w " " (pop words))))
4091 (push w www))
4092 (setq words (nreverse www)))
4093 (setq org-agenda-last-search-view-search-was-boolean boolean)
4094 (when boolean
4095 (let (wds w)
4096 (while (setq w (pop words))
4097 (if (or (equal (substring w 0 1) "\"")
4098 (and (> (length w) 1)
4099 (member (substring w 0 1) '("+" "-"))
4100 (equal (substring w 1 2) "\"")))
4101 (while (and words (not (equal (substring w -1) "\"")))
4102 (setq w (concat w " " (pop words)))))
4103 (and (string-match "\\`\\([-+]?\\)\"" w)
4104 (setq w (replace-match "\\1" nil nil w)))
4105 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4106 (push w wds))
4107 (setq words (nreverse wds))))
4108 (if boolean
4109 (mapc (lambda (w)
4110 (setq c (string-to-char w))
4111 (if (equal c ?-)
4112 (setq neg t w (substring w 1))
4113 (if (equal c ?+)
4114 (setq neg nil w (substring w 1))
4115 (setq neg nil)))
4116 (if (string-match "\\`{.*}\\'" w)
4117 (setq re (substring w 1 -1))
4118 (if full-words
4119 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4120 (setq re (regexp-quote (downcase w)))))
4121 (if neg (push re regexps-) (push re regexps+)))
4122 words)
4123 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4124 regexps+))
4125 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4126 (if (not regexps+)
4127 (setq regexp org-outline-regexp-bol)
4128 (setq regexp (pop regexps+))
4129 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4130 regexp))))
4131 (setq files (org-agenda-files nil 'ifmode))
4132 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4133 (pop org-agenda-text-search-extra-files)
4134 (setq files (org-add-archive-files files)))
4135 (setq files (append files org-agenda-text-search-extra-files)
4136 rtnall nil)
4137 (while (setq file (pop files))
4138 (setq ee nil)
4139 (catch 'nextfile
4140 (org-check-agenda-file file)
4141 (setq buffer (if (file-exists-p file)
4142 (org-get-agenda-file-buffer file)
4143 (error "No such file %s" file)))
4144 (if (not buffer)
4145 ;; If file does not exist, make sure an error message is sent
4146 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4147 file))))
4148 (with-current-buffer buffer
4149 (with-syntax-table (org-search-syntax-table)
4150 (unless (derived-mode-p 'org-mode)
4151 (error "Agenda file %s is not in `org-mode'" file))
4152 (let ((case-fold-search t))
4153 (save-excursion
4154 (save-restriction
4155 (if org-agenda-restrict
4156 (narrow-to-region org-agenda-restrict-begin
4157 org-agenda-restrict-end)
4158 (widen))
4159 (goto-char (point-min))
4160 (unless (or (org-at-heading-p)
4161 (outline-next-heading))
4162 (throw 'nextfile t))
4163 (goto-char (max (point-min) (1- (point))))
4164 (while (re-search-forward regexp nil t)
4165 (org-back-to-heading t)
4166 (skip-chars-forward "* ")
4167 (setq beg (point-at-bol)
4168 beg1 (point)
4169 end (progn (outline-next-heading) (point)))
4170 (catch :skip
4171 (goto-char beg)
4172 (org-agenda-skip)
4173 (setq str (buffer-substring-no-properties
4174 (point-at-bol)
4175 (if hdl-only (point-at-eol) end)))
4176 (mapc (lambda (wr) (when (string-match wr str)
4177 (goto-char (1- end))
4178 (throw :skip t)))
4179 regexps-)
4180 (mapc (lambda (wr) (unless (string-match wr str)
4181 (goto-char (1- end))
4182 (throw :skip t)))
4183 (if todo-only
4184 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4185 regexps+)
4186 regexps+))
4187 (goto-char beg)
4188 (setq marker (org-agenda-new-marker (point))
4189 category (org-get-category)
4190 org-category-pos (get-text-property (point) 'org-category-position)
4191 tags (org-get-tags-at (point))
4192 txt (org-agenda-format-item
4194 (buffer-substring-no-properties
4195 beg1 (point-at-eol))
4196 category tags))
4197 (org-add-props txt props
4198 'org-marker marker 'org-hd-marker marker
4199 'org-todo-regexp org-todo-regexp
4200 'org-complex-heading-regexp org-complex-heading-regexp
4201 'priority 1000 'org-category category
4202 'org-category-position org-category-pos
4203 'type "search")
4204 (push txt ee)
4205 (goto-char (1- end))))))))))
4206 (setq rtn (nreverse ee))
4207 (setq rtnall (append rtnall rtn)))
4208 (if org-agenda-overriding-header
4209 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4210 nil 'face 'org-agenda-structure) "\n")
4211 (insert "Search words: ")
4212 (add-text-properties (point-min) (1- (point))
4213 (list 'face 'org-agenda-structure))
4214 (setq pos (point))
4215 (insert string "\n")
4216 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4217 (setq pos (point))
4218 (unless org-agenda-multi
4219 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4220 (add-text-properties pos (1- (point))
4221 (list 'face 'org-agenda-structure))))
4222 (org-agenda-mark-header-line (point-min))
4223 (when rtnall
4224 (insert (org-finalize-agenda-entries rtnall) "\n"))
4225 (goto-char (point-min))
4226 (or org-agenda-multi (org-fit-agenda-window))
4227 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4228 (org-finalize-agenda)
4229 (setq buffer-read-only t)))
4231 ;;; Agenda TODO list
4233 (defvar org-select-this-todo-keyword nil)
4234 (defvar org-last-arg nil)
4236 ;;;###autoload
4237 (defun org-todo-list (arg)
4238 "Show all (not done) TODO entries from all agenda file in a single list.
4239 The prefix arg can be used to select a specific TODO keyword and limit
4240 the list to these. When using \\[universal-argument], you will be prompted
4241 for a keyword. A numeric prefix directly selects the Nth keyword in
4242 `org-todo-keywords-1'."
4243 (interactive "P")
4244 (org-prepare-agenda "TODO")
4245 (org-compile-prefix-format 'todo)
4246 (org-set-sorting-strategy 'todo)
4247 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4248 (let* ((today (org-today))
4249 (date (calendar-gregorian-from-absolute today))
4250 (kwds org-todo-keywords-for-agenda)
4251 (completion-ignore-case t)
4252 (org-select-this-todo-keyword
4253 (if (stringp arg) arg
4254 (and arg (integerp arg) (> arg 0)
4255 (nth (1- arg) kwds))))
4256 rtn rtnall files file pos)
4257 (when (equal arg '(4))
4258 (setq org-select-this-todo-keyword
4259 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4260 (mapcar 'list kwds) nil nil)))
4261 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4262 (org-set-local 'org-last-arg arg)
4263 (setq org-agenda-redo-command
4264 '(org-todo-list (or current-prefix-arg org-last-arg)))
4265 (setq files (org-agenda-files nil 'ifmode)
4266 rtnall nil)
4267 (while (setq file (pop files))
4268 (catch 'nextfile
4269 (org-check-agenda-file file)
4270 (setq rtn (org-agenda-get-day-entries file date :todo))
4271 (setq rtnall (append rtnall rtn))))
4272 (if org-agenda-overriding-header
4273 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4274 nil 'face 'org-agenda-structure) "\n")
4275 (insert "Global list of TODO items of type: ")
4276 (add-text-properties (point-min) (1- (point))
4277 (list 'face 'org-agenda-structure
4278 'short-heading
4279 (concat "ToDo: "
4280 (or org-select-this-todo-keyword "ALL"))))
4281 (org-agenda-mark-header-line (point-min))
4282 (setq pos (point))
4283 (insert (or org-select-this-todo-keyword "ALL") "\n")
4284 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4285 (setq pos (point))
4286 (unless org-agenda-multi
4287 (insert "Available with `N r': (0)ALL")
4288 (let ((n 0) s)
4289 (mapc (lambda (x)
4290 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4291 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4292 (insert "\n "))
4293 (insert " " s))
4294 kwds))
4295 (insert "\n"))
4296 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4297 (org-agenda-mark-header-line (point-min))
4298 (when rtnall
4299 (insert (org-finalize-agenda-entries rtnall) "\n"))
4300 (goto-char (point-min))
4301 (or org-agenda-multi (org-fit-agenda-window))
4302 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4303 (org-finalize-agenda)
4304 (setq buffer-read-only t)))
4306 ;;; Agenda tags match
4308 ;;;###autoload
4309 (defun org-tags-view (&optional todo-only match)
4310 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4311 The prefix arg TODO-ONLY limits the search to TODO entries."
4312 (interactive "P")
4313 (let* ((org-tags-match-list-sublevels
4314 org-tags-match-list-sublevels)
4315 (completion-ignore-case t)
4316 rtn rtnall files file pos matcher
4317 buffer)
4318 (when (and (stringp match) (not (string-match "\\S-" match)))
4319 (setq match nil))
4320 (setq matcher (org-make-tags-matcher match)
4321 match (car matcher) matcher (cdr matcher))
4322 (org-prepare-agenda (concat "TAGS " match))
4323 (org-compile-prefix-format 'tags)
4324 (org-set-sorting-strategy 'tags)
4325 (setq org-agenda-query-string match)
4326 (setq org-agenda-redo-command
4327 (list 'org-tags-view (list 'quote todo-only)
4328 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4329 (setq files (org-agenda-files nil 'ifmode)
4330 rtnall nil)
4331 (while (setq file (pop files))
4332 (catch 'nextfile
4333 (org-check-agenda-file file)
4334 (setq buffer (if (file-exists-p file)
4335 (org-get-agenda-file-buffer file)
4336 (error "No such file %s" file)))
4337 (if (not buffer)
4338 ;; If file does not exist, error message to agenda
4339 (setq rtn (list
4340 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4341 rtnall (append rtnall rtn))
4342 (with-current-buffer buffer
4343 (unless (derived-mode-p 'org-mode)
4344 (error "Agenda file %s is not in `org-mode'" file))
4345 (save-excursion
4346 (save-restriction
4347 (if org-agenda-restrict
4348 (narrow-to-region org-agenda-restrict-begin
4349 org-agenda-restrict-end)
4350 (widen))
4351 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4352 (setq rtnall (append rtnall rtn))))))))
4353 (if org-agenda-overriding-header
4354 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4355 nil 'face 'org-agenda-structure) "\n")
4356 (insert "Headlines with TAGS match: ")
4357 (add-text-properties (point-min) (1- (point))
4358 (list 'face 'org-agenda-structure
4359 'short-heading
4360 (concat "Match: " match)))
4361 (setq pos (point))
4362 (insert match "\n")
4363 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4364 (setq pos (point))
4365 (unless org-agenda-multi
4366 (insert "Press `C-u r' to search again with new search string\n"))
4367 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4368 (org-agenda-mark-header-line (point-min))
4369 (when rtnall
4370 (insert (org-finalize-agenda-entries rtnall) "\n"))
4371 (goto-char (point-min))
4372 (or org-agenda-multi (org-fit-agenda-window))
4373 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4374 (org-finalize-agenda)
4375 (setq buffer-read-only t)))
4377 ;;; Agenda Finding stuck projects
4379 (defvar org-agenda-skip-regexp nil
4380 "Regular expression used in skipping subtrees for the agenda.
4381 This is basically a temporary global variable that can be set and then
4382 used by user-defined selections using `org-agenda-skip-function'.")
4384 (defvar org-agenda-overriding-header nil
4385 "When set during agenda, todo and tags searches it replaces the header.
4386 This variable should not be set directly, but custom commands can bind it
4387 in the options section.")
4389 (defun org-agenda-skip-entry-when-regexp-matches ()
4390 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4391 If yes, it returns the end position of this entry, causing agenda commands
4392 to skip the entry but continuing the search in the subtree. This is a
4393 function that can be put into `org-agenda-skip-function' for the duration
4394 of a command."
4395 (let ((end (save-excursion (org-end-of-subtree t)))
4396 skip)
4397 (save-excursion
4398 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4399 (and skip end)))
4401 (defun org-agenda-skip-subtree-when-regexp-matches ()
4402 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4403 If yes, it returns the end position of this tree, causing agenda commands
4404 to skip this subtree. This is a function that can be put into
4405 `org-agenda-skip-function' for the duration of a command."
4406 (let ((end (save-excursion (org-end-of-subtree t)))
4407 skip)
4408 (save-excursion
4409 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4410 (and skip end)))
4412 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4413 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4414 If yes, it returns the end position of the current entry (NOT the tree),
4415 causing agenda commands to skip the entry but continuing the search in
4416 the subtree. This is a function that can be put into
4417 `org-agenda-skip-function' for the duration of a command. An important
4418 use of this function is for the stuck project list."
4419 (let ((end (save-excursion (org-end-of-subtree t)))
4420 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4421 skip)
4422 (save-excursion
4423 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4424 (and skip entry-end)))
4426 (defun org-agenda-skip-entry-if (&rest conditions)
4427 "Skip entry if any of CONDITIONS is true.
4428 See `org-agenda-skip-if' for details."
4429 (org-agenda-skip-if nil conditions))
4431 (defun org-agenda-skip-subtree-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 t conditions))
4436 (defun org-agenda-skip-if (subtree conditions)
4437 "Checks current entity for CONDITIONS.
4438 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4439 the entry (i.e. the text before the next heading) is checked.
4441 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4442 from different tests. Valid conditions are:
4444 scheduled Check if there is a scheduled cookie
4445 notscheduled Check if there is no scheduled cookie
4446 deadline Check if there is a deadline
4447 notdeadline Check if there is no deadline
4448 timestamp Check if there is a timestamp (also deadline or scheduled)
4449 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4450 regexp Check if regexp matches
4451 notregexp Check if regexp does not match.
4452 todo Check if TODO keyword matches
4453 nottodo Check if TODO keyword does not match
4455 The regexp is taken from the conditions list, it must come right after
4456 the `regexp' or `notregexp' element.
4458 `todo' and `nottodo' accept as an argument a list of todo
4459 keywords, which may include \"*\" to match any todo keyword.
4461 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4463 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4465 Instead of a list, a keyword class may be given. For example:
4467 (org-agenda-skip-entry-if 'nottodo 'done)
4469 would skip entries that haven't been marked with any of \"DONE\"
4470 keywords. Possible classes are: `todo', `done', `any'.
4472 If any of these conditions is met, this function returns the end point of
4473 the entity, causing the search to continue from there. This is a function
4474 that can be put into `org-agenda-skip-function' for the duration of a command."
4475 (let (beg end m)
4476 (org-back-to-heading t)
4477 (setq beg (point)
4478 end (if subtree
4479 (progn (org-end-of-subtree t) (point))
4480 (progn (outline-next-heading) (1- (point)))))
4481 (goto-char beg)
4482 (and
4484 (and (memq 'scheduled conditions)
4485 (re-search-forward org-scheduled-time-regexp end t))
4486 (and (memq 'notscheduled conditions)
4487 (not (re-search-forward org-scheduled-time-regexp end t)))
4488 (and (memq 'deadline conditions)
4489 (re-search-forward org-deadline-time-regexp end t))
4490 (and (memq 'notdeadline conditions)
4491 (not (re-search-forward org-deadline-time-regexp end t)))
4492 (and (memq 'timestamp conditions)
4493 (re-search-forward org-ts-regexp end t))
4494 (and (memq 'nottimestamp conditions)
4495 (not (re-search-forward org-ts-regexp end t)))
4496 (and (setq m (memq 'regexp conditions))
4497 (stringp (nth 1 m))
4498 (re-search-forward (nth 1 m) end t))
4499 (and (setq m (memq 'notregexp conditions))
4500 (stringp (nth 1 m))
4501 (not (re-search-forward (nth 1 m) end t)))
4502 (and (or
4503 (setq m (memq 'nottodo conditions))
4504 (setq m (memq 'todo-unblocked conditions))
4505 (setq m (memq 'nottodo-unblocked conditions))
4506 (setq m (memq 'todo conditions)))
4507 (org-agenda-skip-if-todo m end)))
4508 end)))
4510 (defun org-agenda-skip-if-todo (args end)
4511 "Helper function for `org-agenda-skip-if', do not use it directly.
4512 ARGS is a list with first element either `todo', `nottodo',
4513 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4514 a list of TODO keywords, or a state symbol `todo' or `done' or
4515 `any'."
4516 (let ((kw (car args))
4517 (arg (cadr args))
4518 todo-wds todo-re)
4519 (setq todo-wds
4520 (org-uniquify
4521 (cond
4522 ((listp arg) ;; list of keywords
4523 (if (member "*" arg)
4524 (mapcar 'substring-no-properties org-todo-keywords-1)
4525 arg))
4526 ((symbolp arg) ;; keyword class name
4527 (cond
4528 ((eq arg 'todo)
4529 (org-delete-all org-done-keywords
4530 (mapcar 'substring-no-properties
4531 org-todo-keywords-1)))
4532 ((eq arg 'done) org-done-keywords)
4533 ((eq arg 'any)
4534 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4535 (setq todo-re
4536 (concat "^\\*+[ \t]+\\<\\("
4537 (mapconcat 'identity todo-wds "\\|")
4538 "\\)\\>"))
4539 (cond
4540 ((eq kw 'todo) (re-search-forward todo-re end t))
4541 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4542 ((eq kw 'todo-unblocked)
4543 (catch 'unblocked
4544 (while (re-search-forward todo-re end t)
4545 (or (org-entry-blocked-p) (throw 'unblocked t)))
4546 nil))
4547 ((eq kw 'nottodo-unblocked)
4548 (catch 'unblocked
4549 (while (re-search-forward todo-re end t)
4550 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4554 ;;;###autoload
4555 (defun org-agenda-list-stuck-projects (&rest ignore)
4556 "Create agenda view for projects that are stuck.
4557 Stuck projects are project that have no next actions. For the definitions
4558 of what a project is and how to check if it stuck, customize the variable
4559 `org-stuck-projects'."
4560 (interactive)
4561 (let* ((org-agenda-skip-function
4562 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4563 ;; We could have used org-agenda-skip-if here.
4564 (org-agenda-overriding-header
4565 (or org-agenda-overriding-header "List of stuck projects: "))
4566 (matcher (nth 0 org-stuck-projects))
4567 (todo (nth 1 org-stuck-projects))
4568 (todo-wds (if (member "*" todo)
4569 (progn
4570 (org-prepare-agenda-buffers (org-agenda-files
4571 nil 'ifmode))
4572 (org-delete-all
4573 org-done-keywords-for-agenda
4574 (copy-sequence org-todo-keywords-for-agenda)))
4575 todo))
4576 (todo-re (concat "^\\*+[ \t]+\\("
4577 (mapconcat 'identity todo-wds "\\|")
4578 "\\)\\>"))
4579 (tags (nth 2 org-stuck-projects))
4580 (tags-re (if (member "*" tags)
4581 (concat org-outline-regexp-bol
4582 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4583 (if tags
4584 (concat org-outline-regexp-bol
4585 ".*:\\("
4586 (mapconcat 'identity tags "\\|")
4587 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4588 (gen-re (nth 3 org-stuck-projects))
4589 (re-list
4590 (delq nil
4591 (list
4592 (if todo todo-re)
4593 (if tags tags-re)
4594 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4595 gen-re)))))
4596 (setq org-agenda-skip-regexp
4597 (if re-list
4598 (mapconcat 'identity re-list "\\|")
4599 (error "No information how to identify unstuck projects")))
4600 (org-tags-view nil matcher)
4601 (with-current-buffer org-agenda-buffer-name
4602 (setq org-agenda-redo-command
4603 '(org-agenda-list-stuck-projects
4604 (or current-prefix-arg org-last-arg))))))
4606 ;;; Diary integration
4608 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4609 (defvar diary-list-entries-hook)
4610 (defvar diary-time-regexp)
4611 (defun org-get-entries-from-diary (date)
4612 "Get the (Emacs Calendar) diary entries for DATE."
4613 (require 'diary-lib)
4614 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4615 (diary-display-hook '(fancy-diary-display))
4616 (diary-display-function 'fancy-diary-display)
4617 (pop-up-frames nil)
4618 (diary-list-entries-hook
4619 (cons 'org-diary-default-entry diary-list-entries-hook))
4620 (diary-file-name-prefix-function nil) ; turn this feature off
4621 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4622 entries
4623 (org-disable-agenda-to-diary t))
4624 (save-excursion
4625 (save-window-excursion
4626 (funcall (if (fboundp 'diary-list-entries)
4627 'diary-list-entries 'list-diary-entries)
4628 date 1)))
4629 (if (not (get-buffer diary-fancy-buffer))
4630 (setq entries nil)
4631 (with-current-buffer diary-fancy-buffer
4632 (setq buffer-read-only nil)
4633 (if (zerop (buffer-size))
4634 ;; No entries
4635 (setq entries nil)
4636 ;; Omit the date and other unnecessary stuff
4637 (org-agenda-cleanup-fancy-diary)
4638 ;; Add prefix to each line and extend the text properties
4639 (if (zerop (buffer-size))
4640 (setq entries nil)
4641 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4642 (setq entries
4643 (with-temp-buffer
4644 (insert entries) (goto-char (point-min))
4645 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4646 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4647 (replace-match (concat "; " (match-string 1)))))
4648 (buffer-string)))))
4649 (set-buffer-modified-p nil)
4650 (kill-buffer diary-fancy-buffer)))
4651 (when entries
4652 (setq entries (org-split-string entries "\n"))
4653 (setq entries
4654 (mapcar
4655 (lambda (x)
4656 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4657 ;; Extend the text properties to the beginning of the line
4658 (org-add-props x (text-properties-at (1- (length x)) x)
4659 'type "diary" 'date date 'face 'org-agenda-diary))
4660 entries)))))
4662 (defvar org-agenda-cleanup-fancy-diary-hook nil
4663 "Hook run when the fancy diary buffer is cleaned up.")
4665 (defun org-agenda-cleanup-fancy-diary ()
4666 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4667 This gets rid of the date, the underline under the date, and
4668 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4669 date. It also removes lines that contain only whitespace."
4670 (goto-char (point-min))
4671 (if (looking-at ".*?:[ \t]*")
4672 (progn
4673 (replace-match "")
4674 (re-search-forward "\n=+$" nil t)
4675 (replace-match "")
4676 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4677 (re-search-forward "\n=+$" nil t)
4678 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4679 (goto-char (point-min))
4680 (while (re-search-forward "^ +\n" nil t)
4681 (replace-match ""))
4682 (goto-char (point-min))
4683 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4684 (replace-match ""))
4685 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4687 ;; Make sure entries from the diary have the right text properties.
4688 (eval-after-load "diary-lib"
4689 '(if (boundp 'diary-modify-entry-list-string-function)
4690 ;; We can rely on the hook, nothing to do
4692 ;; Hook not available, must use advice to make this work
4693 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4694 "Make the position visible."
4695 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4696 (stringp string)
4697 buffer-file-name)
4698 (setq string (org-modify-diary-entry-string string))))))
4700 (defun org-modify-diary-entry-string (string)
4701 "Add text properties to string, allowing org-mode to act on it."
4702 (org-add-props string nil
4703 'mouse-face 'highlight
4704 'help-echo (if buffer-file-name
4705 (format "mouse-2 or RET jump to diary file %s"
4706 (abbreviate-file-name buffer-file-name))
4708 'org-agenda-diary-link t
4709 'org-marker (org-agenda-new-marker (point-at-bol))))
4711 (defun org-diary-default-entry ()
4712 "Add a dummy entry to the diary.
4713 Needed to avoid empty dates which mess up holiday display."
4714 ;; Catch the error if dealing with the new add-to-diary-alist
4715 (when org-disable-agenda-to-diary
4716 (condition-case nil
4717 (org-add-to-diary-list original-date "Org-mode dummy" "")
4718 (error
4719 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4721 (defun org-add-to-diary-list (&rest args)
4722 (if (fboundp 'diary-add-to-list)
4723 (apply 'diary-add-to-list args)
4724 (apply 'add-to-diary-list args)))
4726 (defvar org-diary-last-run-time nil)
4728 ;;;###autoload
4729 (defun org-diary (&rest args)
4730 "Return diary information from org-files.
4731 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4732 It accesses org files and extracts information from those files to be
4733 listed in the diary. The function accepts arguments specifying what
4734 items should be listed. For a list of arguments allowed here, see the
4735 variable `org-agenda-entry-types'.
4737 The call in the diary file should look like this:
4739 &%%(org-diary) ~/path/to/some/orgfile.org
4741 Use a separate line for each org file to check. Or, if you omit the file name,
4742 all files listed in `org-agenda-files' will be checked automatically:
4744 &%%(org-diary)
4746 If you don't give any arguments (as in the example above), the default
4747 arguments (:deadline :scheduled :timestamp :sexp) are used.
4748 So the example above may also be written as
4750 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4752 The function expects the lisp variables `entry' and `date' to be provided
4753 by the caller, because this is how the calendar works. Don't use this
4754 function from a program - use `org-agenda-get-day-entries' instead."
4755 (when (> (- (org-float-time)
4756 org-agenda-last-marker-time)
4758 ;; I am not sure if this works with sticky agendas, because the marker
4759 ;; list is then no longer a global variable.
4760 (org-agenda-reset-markers))
4761 ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
4762 (when (buffer-live-p org-agenda-buffer)
4763 (org-compile-prefix-format 'agenda))
4764 (org-set-sorting-strategy 'agenda)
4765 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4766 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4767 (list entry)
4768 (org-agenda-files t)))
4769 (time (org-float-time))
4770 file rtn results)
4771 (when (or (not org-diary-last-run-time)
4772 (> (- time
4773 org-diary-last-run-time)
4775 (org-prepare-agenda-buffers files))
4776 (setq org-diary-last-run-time time)
4777 ;; If this is called during org-agenda, don't return any entries to
4778 ;; the calendar. Org Agenda will list these entries itself.
4779 (if org-disable-agenda-to-diary (setq files nil))
4780 (while (setq file (pop files))
4781 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4782 (setq results (append results rtn)))
4783 (if results
4784 (concat (org-finalize-agenda-entries results) "\n"))))
4786 ;;; Agenda entry finders
4788 (defun org-agenda-get-day-entries (file date &rest args)
4789 "Does the work for `org-diary' and `org-agenda'.
4790 FILE is the path to a file to be checked for entries. DATE is date like
4791 the one returned by `calendar-current-date'. ARGS are symbols indicating
4792 which kind of entries should be extracted. For details about these, see
4793 the documentation of `org-diary'."
4794 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4795 (let* ((org-startup-folded nil)
4796 (org-startup-align-all-tables nil)
4797 (buffer (if (file-exists-p file)
4798 (org-get-agenda-file-buffer file)
4799 (error "No such file %s" file)))
4800 arg results rtn deadline-results)
4801 (if (not buffer)
4802 ;; If file does not exist, make sure an error message ends up in diary
4803 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4804 (with-current-buffer buffer
4805 (unless (derived-mode-p 'org-mode)
4806 (error "Agenda file %s is not in `org-mode'" file))
4807 (let ((case-fold-search nil))
4808 (save-excursion
4809 (save-restriction
4810 (if org-agenda-restrict
4811 (narrow-to-region org-agenda-restrict-begin
4812 org-agenda-restrict-end)
4813 (widen))
4814 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4815 (while (setq arg (pop args))
4816 (cond
4817 ((and (eq arg :todo)
4818 (equal date (calendar-gregorian-from-absolute
4819 (org-today))))
4820 (setq rtn (org-agenda-get-todos))
4821 (setq results (append results rtn)))
4822 ((eq arg :timestamp)
4823 (setq rtn (org-agenda-get-blocks))
4824 (setq results (append results rtn))
4825 (setq rtn (org-agenda-get-timestamps deadline-results))
4826 (setq results (append results rtn)))
4827 ((eq arg :sexp)
4828 (setq rtn (org-agenda-get-sexps))
4829 (setq results (append results rtn)))
4830 ((eq arg :scheduled)
4831 (setq rtn (org-agenda-get-scheduled deadline-results))
4832 (setq results (append results rtn)))
4833 ((eq arg :closed)
4834 (setq rtn (org-agenda-get-progress))
4835 (setq results (append results rtn)))
4836 ((eq arg :deadline)
4837 (setq rtn (org-agenda-get-deadlines))
4838 (setq deadline-results (copy-sequence rtn))
4839 (setq results (append results rtn))))))))
4840 results))))
4842 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4843 (defun org-agenda-get-todos ()
4844 "Return the TODO information for agenda display."
4845 (let* ((props (list 'face nil
4846 'done-face 'org-agenda-done
4847 'org-not-done-regexp org-not-done-regexp
4848 'org-todo-regexp org-todo-regexp
4849 'org-complex-heading-regexp org-complex-heading-regexp
4850 'mouse-face 'highlight
4851 'help-echo
4852 (format "mouse-2 or RET jump to org file %s"
4853 (abbreviate-file-name buffer-file-name))))
4854 (regexp (format org-heading-keyword-regexp-format
4855 (cond
4856 ((and org-select-this-todo-keyword
4857 (equal org-select-this-todo-keyword "*"))
4858 org-todo-regexp)
4859 (org-select-this-todo-keyword
4860 (concat "\\("
4861 (mapconcat 'identity
4862 (org-split-string
4863 org-select-this-todo-keyword
4864 "|")
4865 "\\|") "\\)"))
4866 (t org-not-done-regexp))))
4867 marker priority category org-category-pos tags todo-state
4868 ee txt beg end)
4869 (goto-char (point-min))
4870 (while (re-search-forward regexp nil t)
4871 (catch :skip
4872 (save-match-data
4873 (beginning-of-line)
4874 (org-agenda-skip)
4875 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4876 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4877 (goto-char (1+ beg))
4878 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4879 (throw :skip nil)))
4880 (goto-char (match-beginning 2))
4881 (setq marker (org-agenda-new-marker (match-beginning 0))
4882 category (org-get-category)
4883 org-category-pos (get-text-property (point) 'org-category-position)
4884 txt (org-trim
4885 (buffer-substring (match-beginning 2) (match-end 0)))
4886 tags (org-get-tags-at (point))
4887 txt (org-agenda-format-item "" txt category tags)
4888 priority (1+ (org-get-priority txt))
4889 todo-state (org-get-todo-state))
4890 (org-add-props txt props
4891 'org-marker marker 'org-hd-marker marker
4892 'priority priority 'org-category category
4893 'org-category-position org-category-pos
4894 'type "todo" 'todo-state todo-state)
4895 (push txt ee)
4896 (if org-agenda-todo-list-sublevels
4897 (goto-char (match-end 2))
4898 (org-end-of-subtree 'invisible))))
4899 (nreverse ee)))
4901 (defun org-agenda-todo-custom-ignore-p (time n)
4902 "Check whether timestamp is farther away then n number of days.
4903 This function is invoked if `org-agenda-todo-ignore-deadlines',
4904 `org-agenda-todo-ignore-scheduled' or
4905 `org-agenda-todo-ignore-timestamp' is set to an integer."
4906 (let ((days (org-days-to-time time)))
4907 (if (>= n 0)
4908 (>= days n)
4909 (<= days n))))
4911 ;;;###autoload
4912 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4913 (&optional end)
4914 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4915 (when (or org-agenda-todo-ignore-with-date
4916 org-agenda-todo-ignore-scheduled
4917 org-agenda-todo-ignore-deadlines
4918 org-agenda-todo-ignore-timestamp)
4919 (setq end (or end (save-excursion (outline-next-heading) (point))))
4920 (save-excursion
4921 (or (and org-agenda-todo-ignore-with-date
4922 (re-search-forward org-ts-regexp end t))
4923 (and org-agenda-todo-ignore-scheduled
4924 (re-search-forward org-scheduled-time-regexp end t)
4925 (cond
4926 ((eq org-agenda-todo-ignore-scheduled 'future)
4927 (> (org-days-to-time (match-string 1)) 0))
4928 ((eq org-agenda-todo-ignore-scheduled 'past)
4929 (<= (org-days-to-time (match-string 1)) 0))
4930 ((numberp org-agenda-todo-ignore-scheduled)
4931 (org-agenda-todo-custom-ignore-p
4932 (match-string 1) org-agenda-todo-ignore-scheduled))
4933 (t)))
4934 (and org-agenda-todo-ignore-deadlines
4935 (re-search-forward org-deadline-time-regexp end t)
4936 (cond
4937 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4938 ((eq org-agenda-todo-ignore-deadlines 'far)
4939 (not (org-deadline-close (match-string 1))))
4940 ((eq org-agenda-todo-ignore-deadlines 'future)
4941 (> (org-days-to-time (match-string 1)) 0))
4942 ((eq org-agenda-todo-ignore-deadlines 'past)
4943 (<= (org-days-to-time (match-string 1)) 0))
4944 ((numberp org-agenda-todo-ignore-deadlines)
4945 (org-agenda-todo-custom-ignore-p
4946 (match-string 1) org-agenda-todo-ignore-deadlines))
4947 (t (org-deadline-close (match-string 1)))))
4948 (and org-agenda-todo-ignore-timestamp
4949 (let ((buffer (current-buffer))
4950 (regexp
4951 (concat
4952 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4953 (start (point)))
4954 ;; Copy current buffer into a temporary one
4955 (with-temp-buffer
4956 (insert-buffer-substring buffer start end)
4957 (goto-char (point-min))
4958 ;; Delete SCHEDULED and DEADLINE items
4959 (while (re-search-forward regexp end t)
4960 (delete-region (match-beginning 0) (match-end 0)))
4961 (goto-char (point-min))
4962 ;; No search for timestamp left
4963 (when (re-search-forward org-ts-regexp nil t)
4964 (cond
4965 ((eq org-agenda-todo-ignore-timestamp 'future)
4966 (> (org-days-to-time (match-string 1)) 0))
4967 ((eq org-agenda-todo-ignore-timestamp 'past)
4968 (<= (org-days-to-time (match-string 1)) 0))
4969 ((numberp org-agenda-todo-ignore-timestamp)
4970 (org-agenda-todo-custom-ignore-p
4971 (match-string 1) org-agenda-todo-ignore-timestamp))
4972 (t))))))))))
4974 (defconst org-agenda-no-heading-message
4975 "No heading for this item in buffer or region.")
4977 (defun org-agenda-get-timestamps (&optional deadline-results)
4978 "Return the date stamp information for agenda display."
4979 (let* ((props (list 'face 'org-agenda-calendar-event
4980 'org-not-done-regexp org-not-done-regexp
4981 'org-todo-regexp org-todo-regexp
4982 'org-complex-heading-regexp org-complex-heading-regexp
4983 'mouse-face 'highlight
4984 'help-echo
4985 (format "mouse-2 or RET jump to org file %s"
4986 (abbreviate-file-name buffer-file-name))))
4987 (d1 (calendar-absolute-from-gregorian date))
4989 (deadline-position-alist
4990 (mapcar (lambda (a) (and (setq mm (get-text-property
4991 0 'org-hd-marker a))
4992 (cons (marker-position mm) a)))
4993 deadline-results))
4994 (remove-re org-ts-regexp)
4995 (regexp
4996 (concat
4997 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4998 (regexp-quote
4999 (substring
5000 (format-time-string
5001 (car org-time-stamp-formats)
5002 (apply 'encode-time ; DATE bound by calendar
5003 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5004 1 11))
5005 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5006 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5007 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5008 donep tmp priority category org-category-pos ee txt timestr tags
5009 b0 b3 e3 head todo-state end-of-match show-all)
5010 (goto-char (point-min))
5011 (while (setq end-of-match (re-search-forward regexp nil t))
5012 (setq b0 (match-beginning 0)
5013 b3 (match-beginning 3) e3 (match-end 3)
5014 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5015 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5016 (member todo-state
5017 org-agenda-repeating-timestamp-show-all)))
5018 (catch :skip
5019 (and (org-at-date-range-p) (throw :skip nil))
5020 (org-agenda-skip)
5021 (if (and (match-end 1)
5022 (not (= d1 (org-time-string-to-absolute
5023 (match-string 1) d1 nil show-all
5024 (current-buffer) b0))))
5025 (throw :skip nil))
5026 (if (and e3
5027 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5028 (throw :skip nil))
5029 (setq tmp (buffer-substring (max (point-min)
5030 (- b0 org-ds-keyword-length))
5032 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5033 inactivep (= (char-after b0) ?\[)
5034 deadlinep (string-match org-deadline-regexp tmp)
5035 scheduledp (string-match org-scheduled-regexp tmp)
5036 closedp (and org-agenda-include-inactive-timestamps
5037 (string-match org-closed-string tmp))
5038 clockp (and org-agenda-include-inactive-timestamps
5039 (or (string-match org-clock-string tmp)
5040 (string-match "]-+\\'" tmp)))
5041 donep (member todo-state org-done-keywords))
5042 (if (or scheduledp deadlinep closedp clockp
5043 (and donep org-agenda-skip-timestamp-if-done))
5044 (throw :skip t))
5045 (if (string-match ">" timestr)
5046 ;; substring should only run to end of time stamp
5047 (setq timestr (substring timestr 0 (match-end 0))))
5048 (setq marker (org-agenda-new-marker b0)
5049 category (org-get-category b0)
5050 org-category-pos (get-text-property b0 'org-category-position))
5051 (save-excursion
5052 (if (not (re-search-backward org-outline-regexp-bol nil t))
5053 (setq txt org-agenda-no-heading-message)
5054 (goto-char (match-beginning 0))
5055 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5056 (assoc (point) deadline-position-alist))
5057 (throw :skip nil))
5058 (setq hdmarker (org-agenda-new-marker)
5059 tags (org-get-tags-at))
5060 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5061 (setq head (or (match-string 1) ""))
5062 (setq txt (org-agenda-format-item
5063 (if inactivep org-agenda-inactive-leader nil)
5064 head category tags timestr
5065 remove-re)))
5066 (setq priority (org-get-priority txt))
5067 (org-add-props txt props
5068 'org-marker marker 'org-hd-marker hdmarker)
5069 (org-add-props txt nil 'priority priority
5070 'org-category category 'date date
5071 'org-category-position org-category-pos
5072 'todo-state todo-state
5073 'type "timestamp")
5074 (push txt ee))
5075 (if org-agenda-skip-additional-timestamps-same-entry
5076 (outline-next-heading)
5077 (goto-char end-of-match))))
5078 (nreverse ee)))
5080 (defun org-agenda-get-sexps ()
5081 "Return the sexp information for agenda display."
5082 (require 'diary-lib)
5083 (let* ((props (list 'face 'org-agenda-calendar-sexp
5084 'mouse-face 'highlight
5085 'help-echo
5086 (format "mouse-2 or RET jump to org file %s"
5087 (abbreviate-file-name buffer-file-name))))
5088 (regexp "^&?%%(")
5089 marker category extra org-category-pos ee txt tags entry
5090 result beg b sexp sexp-entry todo-state)
5091 (goto-char (point-min))
5092 (while (re-search-forward regexp nil t)
5093 (catch :skip
5094 (org-agenda-skip)
5095 (setq beg (match-beginning 0))
5096 (goto-char (1- (match-end 0)))
5097 (setq b (point))
5098 (forward-sexp 1)
5099 (setq sexp (buffer-substring b (point)))
5100 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5101 (org-trim (match-string 1))
5102 ""))
5103 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5104 (when result
5105 (setq marker (org-agenda-new-marker beg)
5106 category (org-get-category beg)
5107 org-category-pos (get-text-property beg 'org-category-position)
5108 todo-state (org-get-todo-state))
5110 (dolist (r (if (stringp result)
5111 (list result)
5112 result)) ;; we expect a list here
5113 (when (and org-agenda-diary-sexp-prefix
5114 (string-match org-agenda-diary-sexp-prefix r))
5115 (setq extra (match-string 0 r)
5116 r (replace-match "" nil nil r)))
5117 (if (string-match "\\S-" r)
5118 (setq txt r)
5119 (setq txt "SEXP entry returned empty string"))
5121 (setq txt (org-agenda-format-item
5122 extra txt category tags 'time))
5123 (org-add-props txt props 'org-marker marker)
5124 (org-add-props txt nil
5125 'org-category category 'date date 'todo-state todo-state
5126 'org-category-position org-category-pos
5127 'type "sexp")
5128 (push txt ee)))))
5129 (nreverse ee)))
5131 ;; Calendar sanity: define some functions that are independent of
5132 ;; `calendar-date-style'.
5133 ;; Normally I would like to use ISO format when calling the diary functions,
5134 ;; but to make sure we still have Emacs 22 compatibility we bind
5135 ;; also `european-calendar-style' and use european format
5136 (defun org-anniversary (year month day &optional mark)
5137 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5138 (org-no-warnings
5139 (let ((calendar-date-style 'european) (european-calendar-style t))
5140 (diary-anniversary day month year mark))))
5141 (defun org-cyclic (N year month day &optional mark)
5142 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5143 (org-no-warnings
5144 (let ((calendar-date-style 'european) (european-calendar-style t))
5145 (diary-cyclic N day month year mark))))
5146 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5147 "Like `diary-block', but with fixed (ISO) order of arguments."
5148 (org-no-warnings
5149 (let ((calendar-date-style 'european) (european-calendar-style t))
5150 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5151 (defun org-date (year month day &optional mark)
5152 "Like `diary-date', but with fixed (ISO) order of arguments."
5153 (org-no-warnings
5154 (let ((calendar-date-style 'european) (european-calendar-style t))
5155 (diary-date day month year mark))))
5156 (defalias 'org-float 'diary-float)
5158 ;; Define the` org-class' function
5159 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5160 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5161 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5162 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5163 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5164 `holidays', then any date that is known by the Emacs calendar to be a
5165 holiday will also be skipped."
5166 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5167 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5168 (d (calendar-absolute-from-gregorian date)))
5169 (and
5170 (<= date1 d)
5171 (<= d date2)
5172 (= (calendar-day-of-week date) dayname)
5173 (or (not skip-weeks)
5174 (progn
5175 (require 'cal-iso)
5176 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5177 (not (and (memq 'holidays skip-weeks)
5178 (calendar-check-holidays date)))
5179 entry)))
5181 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5182 "Like `org-class', but honor `calendar-date-style'.
5183 The order of the first 2 times 3 arguments depends on the variable
5184 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5185 So for American calendars, give this as MONTH DAY YEAR, for European as
5186 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5187 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5188 is any number of ISO weeks in the block period for which the item should
5189 be skipped.
5191 This function is here only for backward compatibility and it is deprecated,
5192 please use `org-class' instead."
5193 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5194 (date2 (org-order-calendar-date-args m2 d2 y2)))
5195 (org-class
5196 (nth 2 date1) (car date1) (nth 1 date1)
5197 (nth 2 date2) (car date2) (nth 1 date2)
5198 dayname skip-weeks)))
5199 (make-obsolete 'org-diary-class 'org-class "")
5201 (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
5202 (defalias 'org-get-closed 'org-agenda-get-progress)
5203 (defun org-agenda-get-progress ()
5204 "Return the logged TODO entries for agenda display."
5205 (let* ((props (list 'mouse-face 'highlight
5206 'org-not-done-regexp org-not-done-regexp
5207 'org-todo-regexp org-todo-regexp
5208 'org-complex-heading-regexp org-complex-heading-regexp
5209 'help-echo
5210 (format "mouse-2 or RET jump to org file %s"
5211 (abbreviate-file-name buffer-file-name))))
5212 (items (if (consp org-agenda-show-log-scoped)
5213 org-agenda-show-log-scoped
5214 (if (eq org-agenda-show-log-scoped 'clockcheck)
5215 '(clock)
5216 org-agenda-log-mode-items)))
5217 (parts
5218 (delq nil
5219 (list
5220 (if (memq 'closed items) (concat "\\<" org-closed-string))
5221 (if (memq 'clock items) (concat "\\<" org-clock-string))
5222 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5223 (parts-re (if parts (mapconcat 'identity parts "\\|")
5224 (error "`org-agenda-log-mode-items' is empty")))
5225 (regexp (concat
5226 "\\(" parts-re "\\)"
5227 " *\\["
5228 (regexp-quote
5229 (substring
5230 (format-time-string
5231 (car org-time-stamp-formats)
5232 (apply 'encode-time ; DATE bound by calendar
5233 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5234 1 11))))
5235 (org-agenda-search-headline-for-time nil)
5236 marker hdmarker priority category org-category-pos tags closedp
5237 statep clockp state ee txt extra timestr rest clocked)
5238 (goto-char (point-min))
5239 (while (re-search-forward regexp nil t)
5240 (catch :skip
5241 (org-agenda-skip)
5242 (setq marker (org-agenda-new-marker (match-beginning 0))
5243 closedp (equal (match-string 1) org-closed-string)
5244 statep (equal (string-to-char (match-string 1)) ?-)
5245 clockp (not (or closedp statep))
5246 state (and statep (match-string 2))
5247 category (org-get-category (match-beginning 0))
5248 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5249 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5250 (when (string-match "\\]" timestr)
5251 ;; substring should only run to end of time stamp
5252 (setq rest (substring timestr (match-end 0))
5253 timestr (substring timestr 0 (match-end 0)))
5254 (if (and (not closedp) (not statep)
5255 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5256 rest))
5257 (progn (setq timestr (concat (substring timestr 0 -1)
5258 "-" (match-string 1 rest) "]"))
5259 (setq clocked (match-string 2 rest)))
5260 (setq clocked "-")))
5261 (save-excursion
5262 (setq extra
5263 (cond
5264 ((not org-agenda-log-mode-add-notes) nil)
5265 (statep
5266 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5267 (match-string 1)))
5268 (clockp
5269 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5270 (match-string 1)))))
5271 (if (not (re-search-backward org-outline-regexp-bol nil t))
5272 (setq txt org-agenda-no-heading-message)
5273 (goto-char (match-beginning 0))
5274 (setq hdmarker (org-agenda-new-marker)
5275 tags (org-get-tags-at))
5276 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5277 (setq txt (match-string 1))
5278 (when extra
5279 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5280 (setq txt (concat (substring txt 0 (match-beginning 1))
5281 " - " extra " " (match-string 2 txt)))
5282 (setq txt (concat txt " - " extra))))
5283 (setq txt (org-agenda-format-item
5284 (cond
5285 (closedp "Closed: ")
5286 (statep (concat "State: (" state ")"))
5287 (t (concat "Clocked: (" clocked ")")))
5288 txt category tags timestr)))
5289 (setq priority 100000)
5290 (org-add-props txt props
5291 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5292 'priority priority 'org-category category
5293 'org-category-position org-category-pos
5294 'type "closed" 'date date
5295 'undone-face 'org-warning 'done-face 'org-agenda-done)
5296 (push txt ee))
5297 (goto-char (point-at-eol))))
5298 (nreverse ee)))
5300 (defun org-agenda-show-clocking-issues ()
5301 "Add overlays, showing issues with clocking.
5302 See also the user option `org-agenda-clock-consistency-checks'."
5303 (interactive)
5304 (let* ((pl org-agenda-clock-consistency-checks)
5305 (re (concat "^[ \t]*"
5306 org-clock-string
5307 "[ \t]+"
5308 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5309 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5310 (tlstart 0.)
5311 (tlend 0.)
5312 (maxtime (org-hh:mm-string-to-minutes
5313 (or (plist-get pl :max-duration) "24:00")))
5314 (mintime (org-hh:mm-string-to-minutes
5315 (or (plist-get pl :min-duration) 0)))
5316 (maxgap (org-hh:mm-string-to-minutes
5317 ;; default 30:00 means never complain
5318 (or (plist-get pl :max-gap) "30:00")))
5319 (gapok (mapcar 'org-hh:mm-string-to-minutes
5320 (plist-get pl :gap-ok-around)))
5321 (def-face (or (plist-get pl :default-face)
5322 '((:background "DarkRed") (:foreground "white"))))
5323 issue face m te ts dt ov)
5324 (goto-char (point-min))
5325 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5326 (setq issue nil face def-face)
5327 (catch 'next
5328 (setq m (org-get-at-bol 'org-marker)
5329 te nil ts nil)
5330 (unless (and m (markerp m))
5331 (setq issue "No valid clock line") (throw 'next t))
5332 (org-with-point-at m
5333 (save-excursion
5334 (goto-char (point-at-bol))
5335 (unless (looking-at re)
5336 (error "No valid Clock line")
5337 (throw 'next t))
5338 (unless (match-end 3)
5339 (setq issue "No end time"
5340 face (or (plist-get pl :no-end-time-face) face))
5341 (throw 'next t))
5342 (setq ts (match-string 1)
5343 te (match-string 3)
5344 ts (org-float-time
5345 (apply 'encode-time (org-parse-time-string ts)))
5346 te (org-float-time
5347 (apply 'encode-time (org-parse-time-string te)))
5348 dt (- te ts))))
5349 (cond
5350 ((> dt (* 60 maxtime))
5351 ;; a very long clocking chunk
5352 (setq issue (format "Clocking interval is very long: %s"
5353 (org-minutes-to-hh:mm-string
5354 (floor (/ (float dt) 60.))))
5355 face (or (plist-get pl :long-face) face)))
5356 ((< dt (* 60 mintime))
5357 ;; a very short clocking chunk
5358 (setq issue (format "Clocking interval is very short: %s"
5359 (org-minutes-to-hh:mm-string
5360 (floor (/ (float dt) 60.))))
5361 face (or (plist-get pl :short-face) face)))
5362 ((and (> tlend 0) (< ts tlend))
5363 ;; Two clock entries are overlapping
5364 (setq issue (format "Clocking overlap: %d minutes"
5365 (/ (- tlend ts) 60))
5366 face (or (plist-get pl :overlap-face) face)))
5367 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5368 ;; There is a gap, lets see if we need to report it
5369 (unless (org-agenda-check-clock-gap tlend ts gapok)
5370 (setq issue (format "Clocking gap: %d minutes"
5371 (/ (- ts tlend) 60))
5372 face (or (plist-get pl :gap-face) face))))
5373 (t nil)))
5374 (setq tlend (or te tlend) tlstart (or ts tlstart))
5375 (when issue
5376 ;; OK, there was some issue, add an overlay to show the issue
5377 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5378 (overlay-put ov 'before-string
5379 (concat
5380 (org-add-props
5381 (format "%-43s" (concat " " issue))
5383 'face face)
5384 "\n"))
5385 (overlay-put ov 'evaporate t)))))
5387 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5388 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5389 (catch 'exit
5390 (unless ok-list
5391 ;; there are no OK times for gaps...
5392 (throw 'exit nil))
5393 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5394 ;; This is more than 24 hours, so it is OK.
5395 ;; because we have at least one OK time, that must be in the
5396 ;; 24 hour interval.
5397 (throw 'exit t))
5398 ;; We have a shorter gap.
5399 ;; Now we have to get the minute of the day when these times are
5400 (let* ((t1dec (decode-time (seconds-to-time t1)))
5401 (t2dec (decode-time (seconds-to-time t2)))
5402 ;; compute the minute on the day
5403 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5404 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5405 (when (< min2 min1)
5406 ;; if min2 is smaller than min1, this means it is on the next day.
5407 ;; Wrap it to after midnight.
5408 (setq min2 (+ min2 1440)))
5409 ;; Now check if any of the OK times is in the gap
5410 (mapc (lambda (x)
5411 ;; Wrap the time to after midnight if necessary
5412 (if (< x min1) (setq x (+ x 1440)))
5413 ;; Check if in interval
5414 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5415 ok-list)
5416 ;; Nope, this gap is not OK
5417 nil)))
5419 (defun org-agenda-get-deadlines ()
5420 "Return the deadline information for agenda display."
5421 (let* ((props (list 'mouse-face 'highlight
5422 'org-not-done-regexp org-not-done-regexp
5423 'org-todo-regexp org-todo-regexp
5424 'org-complex-heading-regexp org-complex-heading-regexp
5425 'help-echo
5426 (format "mouse-2 or RET jump to org file %s"
5427 (abbreviate-file-name buffer-file-name))))
5428 (regexp org-deadline-time-regexp)
5429 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5430 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5431 d2 diff dfrac wdays pos pos1 category org-category-pos
5432 tags suppress-prewarning ee txt head face s todo-state
5433 show-all upcomingp donep timestr)
5434 (goto-char (point-min))
5435 (while (re-search-forward regexp nil t)
5436 (setq suppress-prewarning nil)
5437 (catch :skip
5438 (org-agenda-skip)
5439 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5440 (save-match-data
5441 (string-match org-scheduled-time-regexp
5442 (buffer-substring (point-at-bol)
5443 (point-at-eol)))))
5444 (setq suppress-prewarning
5445 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5446 org-agenda-skip-deadline-prewarning-if-scheduled
5447 0)))
5448 (setq s (match-string 1)
5449 txt nil
5450 pos (1- (match-beginning 1))
5451 todo-state (save-match-data (org-get-todo-state))
5452 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5453 (member todo-state
5454 org-agenda-repeating-timestamp-show-all))
5455 d2 (org-time-string-to-absolute
5456 (match-string 1) d1 'past show-all
5457 (current-buffer) pos)
5458 diff (- d2 d1)
5459 wdays (if suppress-prewarning
5460 (let ((org-deadline-warning-days suppress-prewarning))
5461 (org-get-wdays s))
5462 (org-get-wdays s))
5463 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5464 upcomingp (and todayp (> diff 0)))
5465 ;; When to show a deadline in the calendar:
5466 ;; If the expiration is within wdays warning time.
5467 ;; Past-due deadlines are only shown on the current date
5468 (if (and (or (and (<= diff wdays)
5469 (and todayp (not org-agenda-only-exact-dates)))
5470 (= diff 0)))
5471 (save-excursion
5472 ;; (setq todo-state (org-get-todo-state))
5473 (setq donep (member todo-state org-done-keywords))
5474 (if (and donep
5475 (or org-agenda-skip-deadline-if-done
5476 (not (= diff 0))))
5477 (setq txt nil)
5478 (setq category (org-get-category)
5479 org-category-pos (get-text-property (point) 'org-category-position))
5480 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5481 (setq txt org-agenda-no-heading-message)
5482 (goto-char (match-end 0))
5483 (setq pos1 (match-beginning 0))
5484 (setq tags (org-get-tags-at pos1))
5485 (setq head (buffer-substring-no-properties
5486 (point)
5487 (progn (skip-chars-forward "^\r\n")
5488 (point))))
5489 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5490 (setq timestr
5491 (concat (substring s (match-beginning 1)) " "))
5492 (setq timestr 'time))
5493 (setq txt (org-agenda-format-item
5494 (if (= diff 0)
5495 (car org-agenda-deadline-leaders)
5496 (if (functionp
5497 (nth 1 org-agenda-deadline-leaders))
5498 (funcall
5499 (nth 1 org-agenda-deadline-leaders)
5500 diff date)
5501 (format (nth 1 org-agenda-deadline-leaders)
5502 diff)))
5503 head category tags
5504 (if (not (= diff 0)) nil timestr)))))
5505 (when txt
5506 (setq face (org-agenda-deadline-face dfrac))
5507 (org-add-props txt props
5508 'org-marker (org-agenda-new-marker pos)
5509 'org-hd-marker (org-agenda-new-marker pos1)
5510 'priority (+ (- diff)
5511 (org-get-priority txt))
5512 'org-category category
5513 'org-category-position org-category-pos
5514 'todo-state todo-state
5515 'type (if upcomingp "upcoming-deadline" "deadline")
5516 'date (if upcomingp date d2)
5517 'face (if donep 'org-agenda-done face)
5518 'undone-face face 'done-face 'org-agenda-done)
5519 (push txt ee))))))
5520 (nreverse ee)))
5522 (defun org-agenda-deadline-face (fraction)
5523 "Return the face to displaying a deadline item.
5524 FRACTION is what fraction of the head-warning time has passed."
5525 (let ((faces org-agenda-deadline-faces) f)
5526 (catch 'exit
5527 (while (setq f (pop faces))
5528 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5530 (defun org-agenda-get-scheduled (&optional deadline-results)
5531 "Return the scheduled information for agenda display."
5532 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5533 'org-todo-regexp org-todo-regexp
5534 'org-complex-heading-regexp org-complex-heading-regexp
5535 'done-face 'org-agenda-done
5536 'mouse-face 'highlight
5537 'help-echo
5538 (format "mouse-2 or RET jump to org file %s"
5539 (abbreviate-file-name buffer-file-name))))
5540 (regexp org-scheduled-time-regexp)
5541 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5542 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5544 (deadline-position-alist
5545 (mapcar (lambda (a) (and (setq mm (get-text-property
5546 0 'org-hd-marker a))
5547 (cons (marker-position mm) a)))
5548 deadline-results))
5549 d2 diff pos pos1 category org-category-pos tags donep
5550 ee txt head pastschedp todo-state face timestr s habitp show-all
5551 did-habit-check-p)
5552 (goto-char (point-min))
5553 (while (re-search-forward regexp nil t)
5554 (catch :skip
5555 (org-agenda-skip)
5556 (setq s (match-string 1)
5557 txt nil
5558 pos (1- (match-beginning 1))
5559 todo-state (save-match-data (org-get-todo-state))
5560 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5561 (member todo-state
5562 org-agenda-repeating-timestamp-show-all))
5563 d2 (org-time-string-to-absolute
5564 (match-string 1) d1 'past show-all
5565 (current-buffer) pos)
5566 diff (- d2 d1))
5567 (setq pastschedp (and todayp (< diff 0)))
5568 (setq did-habit-check-p nil)
5569 ;; When to show a scheduled item in the calendar:
5570 ;; If it is on or past the date.
5571 (when (or (and (< diff 0)
5572 (< (abs diff) org-scheduled-past-days)
5573 (and todayp (not org-agenda-only-exact-dates)))
5574 (= diff 0)
5575 ;; org-is-habit-p uses org-entry-get, which is expansive
5576 ;; so we go extra mile to only call it once
5577 (and todayp
5578 org-habit-show-all-today
5579 (setq did-habit-check-p t)
5580 (setq habitp (and (functionp 'org-is-habit-p)
5581 (org-is-habit-p)))))
5582 (save-excursion
5583 (setq donep (member todo-state org-done-keywords))
5584 (if (and donep
5585 (or org-agenda-skip-scheduled-if-done
5586 (not (= diff 0))
5587 (and (functionp 'org-is-habit-p)
5588 (org-is-habit-p))))
5589 (setq txt nil)
5590 (setq habitp (if did-habit-check-p habitp
5591 (and (functionp 'org-is-habit-p)
5592 (org-is-habit-p))))
5593 (setq category (org-get-category)
5594 org-category-pos (get-text-property (point) 'org-category-position))
5595 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5596 (setq txt org-agenda-no-heading-message)
5597 (goto-char (match-end 0))
5598 (setq pos1 (match-beginning 0))
5599 (if habitp
5600 (if (or (not org-habit-show-habits)
5601 (and (not todayp)
5602 org-habit-show-habits-only-for-today))
5603 (throw :skip nil))
5604 (if (and
5605 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5606 (and org-agenda-skip-scheduled-if-deadline-is-shown
5607 pastschedp))
5608 (setq mm (assoc pos1 deadline-position-alist)))
5609 (throw :skip nil)))
5610 (setq tags (org-get-tags-at))
5611 (setq head (buffer-substring-no-properties
5612 (point)
5613 (progn (skip-chars-forward "^\r\n") (point))))
5614 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5615 (setq timestr
5616 (concat (substring s (match-beginning 1)) " "))
5617 (setq timestr 'time))
5618 (setq txt (org-agenda-format-item
5619 (if (= diff 0)
5620 (car org-agenda-scheduled-leaders)
5621 (format (nth 1 org-agenda-scheduled-leaders)
5622 (- 1 diff)))
5623 head category tags
5624 (if (not (= diff 0)) nil timestr)
5625 nil habitp))))
5626 (when txt
5627 (setq face
5628 (cond
5629 ((and (not habitp) pastschedp)
5630 'org-scheduled-previously)
5631 (todayp 'org-scheduled-today)
5632 (t 'org-scheduled))
5633 habitp (and habitp (org-habit-parse-todo)))
5634 (org-add-props txt props
5635 'undone-face face
5636 'face (if donep 'org-agenda-done face)
5637 'org-marker (org-agenda-new-marker pos)
5638 'org-hd-marker (org-agenda-new-marker pos1)
5639 'type (if pastschedp "past-scheduled" "scheduled")
5640 'date (if pastschedp d2 date)
5641 'priority (if habitp
5642 (org-habit-get-priority habitp)
5643 (+ 94 (- 5 diff) (org-get-priority txt)))
5644 'org-category category
5645 'org-category-position org-category-pos
5646 'org-habit-p habitp
5647 'todo-state todo-state)
5648 (push txt ee))))))
5649 (nreverse ee)))
5651 (defun org-agenda-get-blocks ()
5652 "Return the date-range information for agenda display."
5653 (let* ((props (list 'face nil
5654 'org-not-done-regexp org-not-done-regexp
5655 'org-todo-regexp org-todo-regexp
5656 'org-complex-heading-regexp org-complex-heading-regexp
5657 'mouse-face 'highlight
5658 'help-echo
5659 (format "mouse-2 or RET jump to org file %s"
5660 (abbreviate-file-name buffer-file-name))))
5661 (regexp org-tr-regexp)
5662 (d0 (calendar-absolute-from-gregorian date))
5663 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5664 todo-state tags pos head donep)
5665 (goto-char (point-min))
5666 (while (re-search-forward regexp nil t)
5667 (catch :skip
5668 (org-agenda-skip)
5669 (setq pos (point))
5670 (let ((start-time (match-string 1))
5671 (end-time (match-string 2)))
5672 (setq s1 (match-string 1)
5673 s2 (match-string 2)
5674 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5675 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5676 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5677 ;; Only allow days between the limits, because the normal
5678 ;; date stamps will catch the limits.
5679 (save-excursion
5680 (setq todo-state (org-get-todo-state))
5681 (setq donep (member todo-state org-done-keywords))
5682 (if (and donep org-agenda-skip-timestamp-if-done)
5683 (throw :skip t))
5684 (setq marker (org-agenda-new-marker (point)))
5685 (setq category (org-get-category)
5686 org-category-pos (get-text-property (point) 'org-category-position))
5687 (if (not (re-search-backward org-outline-regexp-bol nil t))
5688 (setq txt org-agenda-no-heading-message)
5689 (goto-char (match-beginning 0))
5690 (setq hdmarker (org-agenda-new-marker (point)))
5691 (setq tags (org-get-tags-at))
5692 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5693 (setq head (match-string 1))
5694 (let ((remove-re
5695 (if org-agenda-remove-timeranges-from-blocks
5696 (concat
5697 "<" (regexp-quote s1) ".*?>"
5698 "--"
5699 "<" (regexp-quote s2) ".*?>")
5700 nil)))
5701 (setq txt (org-agenda-format-item
5702 (format
5703 (nth (if (= d1 d2) 0 1)
5704 org-agenda-timerange-leaders)
5705 (1+ (- d0 d1)) (1+ (- d2 d1)))
5706 head category tags
5707 (cond ((and (= d1 d0) (= d2 d0))
5708 (concat "<" start-time ">--<" end-time ">"))
5709 ((= d1 d0)
5710 (concat "<" start-time ">"))
5711 ((= d2 d0)
5712 (concat "<" end-time ">"))
5713 (t nil))
5714 remove-re))))
5715 (org-add-props txt props
5716 'org-marker marker 'org-hd-marker hdmarker
5717 'type "block" 'date date
5718 'todo-state todo-state
5719 'priority (org-get-priority txt) 'org-category category
5720 'org-category-position org-category-pos)
5721 (push txt ee))))
5722 (goto-char pos)))
5723 ;; Sort the entries by expiration date.
5724 (nreverse ee)))
5726 ;;; Agenda presentation and sorting
5728 (defvar org-prefix-has-time nil
5729 "A flag, set by `org-compile-prefix-format'.
5730 The flag is set if the currently compiled format contains a `%t'.")
5731 (defvar org-prefix-has-tag nil
5732 "A flag, set by `org-compile-prefix-format'.
5733 The flag is set if the currently compiled format contains a `%T'.")
5734 (defvar org-prefix-has-effort nil
5735 "A flag, set by `org-compile-prefix-format'.
5736 The flag is set if the currently compiled format contains a `%e'.")
5737 (defvar org-prefix-category-length nil
5738 "Used by `org-compile-prefix-format' to remember the category field width.")
5739 (defvar org-prefix-category-max-length nil
5740 "Used by `org-compile-prefix-format' to remember the category field width.")
5742 (defun org-agenda-get-category-icon (category)
5743 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5744 (dolist (entry org-agenda-category-icon-alist)
5745 (when (org-string-match-p (car entry) category)
5746 (if (listp (cadr entry))
5747 (return (cadr entry))
5748 (return (apply 'create-image (cdr entry)))))))
5750 (defun org-agenda-format-item (extra txt &optional category tags dotime
5751 remove-re habitp)
5752 "Format TXT to be inserted into the agenda buffer.
5753 In particular, it adds the prefix and corresponding text properties. EXTRA
5754 must be a string and replaces the `%s' specifier in the prefix format.
5755 CATEGORY (string, symbol or nil) may be used to overrule the default
5756 category taken from local variable or file name. It will replace the `%c'
5757 specifier in the format. DOTIME, when non-nil, indicates that a
5758 time-of-day should be extracted from TXT for sorting of this entry, and for
5759 the `%t' specifier in the format. When DOTIME is a string, this string is
5760 searched for a time before TXT is. TAGS can be the tags of the headline.
5761 Any match of REMOVE-RE will be removed from TXT."
5762 ;; We keep the org-prefix-* variable values along with a compiled
5763 ;; formatter, so that multiple agendas existing at the same time, do
5764 ;; not step on each other toes.
5766 ;; It was inconvenient to make these variables buffer local in
5767 ;; Agenda buffers, because this function expects to be called with
5768 ;; the buffer where item comes from being current, and not agenda
5769 ;; buffer
5770 (let* ((bindings (car org-prefix-format-compiled))
5771 (formatter (cadr org-prefix-format-compiled)))
5772 (loop for (var value) in bindings
5773 do (set var value))
5774 (save-match-data
5775 ;; Diary entries sometimes have extra whitespace at the beginning
5776 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5778 ;; Fix the tags part in txt
5779 (setq txt (org-agenda-fix-displayed-tags
5780 txt tags
5781 org-agenda-show-inherited-tags
5782 org-agenda-hide-tags-regexp))
5783 (let* ((category (or category
5784 (if (stringp org-category)
5785 org-category
5786 (and org-category (symbol-name org-category)))
5787 (if buffer-file-name
5788 (file-name-sans-extension
5789 (file-name-nondirectory buffer-file-name))
5790 "")))
5791 (category-icon (org-agenda-get-category-icon category))
5792 (category-icon (if category-icon
5793 (propertize " " 'display category-icon)
5794 ""))
5795 ;; time, tag, effort are needed for the eval of the prefix format
5796 (tag (if tags (nth (1- (length tags)) tags) ""))
5797 time effort neffort
5798 (ts (if dotime (concat
5799 (if (stringp dotime) dotime "")
5800 (and org-agenda-search-headline-for-time txt))))
5801 (time-of-day (and dotime (org-get-time-of-day ts)))
5802 stamp plain s0 s1 s2 rtn srp l
5803 duration thecategory)
5804 (and (derived-mode-p 'org-mode) buffer-file-name
5805 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5806 (when (and dotime time-of-day)
5807 ;; Extract starting and ending time and move them to prefix
5808 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5809 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5810 (setq s0 (match-string 0 ts)
5811 srp (and stamp (match-end 3))
5812 s1 (match-string (if plain 1 2) ts)
5813 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5815 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5816 ;; them, we might want to remove them there to avoid duplication.
5817 ;; The user can turn this off with a variable.
5818 (if (and org-prefix-has-time
5819 org-agenda-remove-times-when-in-prefix (or stamp plain)
5820 (string-match (concat (regexp-quote s0) " *") txt)
5821 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5822 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5823 (= (match-beginning 0) 0)
5825 (setq txt (replace-match "" nil nil txt))))
5826 ;; Normalize the time(s) to 24 hour
5827 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5828 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5830 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5831 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5832 (setq s2
5833 (org-minutes-to-hh:mm-string
5834 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5836 ;; Compute the duration
5837 (when s2
5838 (setq duration (- (org-hh:mm-string-to-minutes s2)
5839 (org-hh:mm-string-to-minutes s1)))))
5841 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5842 txt)
5843 ;; Tags are in the string
5844 (if (or (eq org-agenda-remove-tags t)
5845 (and org-agenda-remove-tags
5846 org-prefix-has-tag))
5847 (setq txt (replace-match "" t t txt))
5848 (setq txt (replace-match
5849 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5850 (match-string 2 txt))
5851 t t txt))))
5852 (when (derived-mode-p 'org-mode)
5853 (setq effort
5854 (condition-case nil
5855 (org-get-effort
5856 (or (get-text-property 0 'org-hd-marker txt)
5857 (get-text-property 0 'org-marker txt)))
5858 (error nil)))
5859 (when effort
5860 (setq neffort (org-duration-string-to-minutes effort)
5861 effort (setq effort (concat "[" effort "]")))))
5862 ;; prevent erroring out with %e format when there is no effort
5863 (or effort (setq effort ""))
5865 (when remove-re
5866 (while (string-match remove-re txt)
5867 (setq txt (replace-match "" t t txt))))
5869 ;; Set org-heading property on `txt' to mark the start of the
5870 ;; heading.
5871 (add-text-properties 0 (length txt) '(org-heading t) txt)
5873 ;; Prepare the variables needed in the eval of the compiled format
5874 (setq time (cond (s2 (concat
5875 (org-agenda-time-of-day-to-ampm-maybe s1)
5876 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5877 (if org-agenda-timegrid-use-ampm " ")))
5878 (s1 (concat
5879 (org-agenda-time-of-day-to-ampm-maybe s1)
5880 (if org-agenda-timegrid-use-ampm
5881 "........ "
5882 "......")))
5883 (t ""))
5884 extra (or (and (not habitp) extra) "")
5885 category (if (symbolp category) (symbol-name category) category)
5886 thecategory (copy-sequence category))
5887 (if (string-match org-bracket-link-regexp category)
5888 (progn
5889 (setq l (if (match-end 3)
5890 (- (match-end 3) (match-beginning 3))
5891 (- (match-end 1) (match-beginning 1))))
5892 (when (< l (or org-prefix-category-length 0))
5893 (setq category (copy-sequence category))
5894 (org-add-props category nil
5895 'extra-space (make-string
5896 (- org-prefix-category-length l 1) ?\ ))))
5897 (if (and org-prefix-category-max-length
5898 (>= (length category) org-prefix-category-max-length))
5899 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5900 ;; Evaluate the compiled format
5901 (setq rtn (concat (eval formatter) txt))
5903 ;; And finally add the text properties
5904 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5905 (org-add-props rtn nil
5906 'org-category (if thecategory (downcase thecategory) category)
5907 'tags (mapcar 'org-downcase-keep-props tags)
5908 'org-highest-priority org-highest-priority
5909 'org-lowest-priority org-lowest-priority
5910 'time-of-day time-of-day
5911 'duration duration
5912 'effort effort
5913 'effort-minutes neffort
5914 'txt txt
5915 'time time
5916 'extra extra
5917 'format org-prefix-format-compiled
5918 'dotime dotime)))))
5920 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5921 "Remove tags string from TXT, and add a modified list of tags.
5922 The modified list may contain inherited tags, and tags matched by
5923 `org-agenda-hide-tags-regexp' will be removed."
5924 (when (or add-inherited hide-re)
5925 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5926 (setq txt (substring txt 0 (match-beginning 0))))
5927 (setq tags
5928 (delq nil
5929 (mapcar (lambda (tg)
5930 (if (or (and hide-re (string-match hide-re tg))
5931 (and (not add-inherited)
5932 (get-text-property 0 'inherited tg)))
5934 tg))
5935 tags)))
5936 (when tags
5937 (let ((have-i (get-text-property 0 'inherited (car tags)))
5939 (setq txt (concat txt " :"
5940 (mapconcat
5941 (lambda (x)
5942 (setq i (get-text-property 0 'inherited x))
5943 (if (and have-i (not i))
5944 (progn
5945 (setq have-i nil)
5946 (concat ":" x))
5948 tags ":")
5949 (if have-i "::" ":"))))))
5950 txt)
5952 (defun org-downcase-keep-props (s)
5953 (let ((props (text-properties-at 0 s)))
5954 (setq s (downcase s))
5955 (add-text-properties 0 (length s) props s)
5958 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5959 (defvar org-agenda-sorting-strategy-selected nil)
5961 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5962 (catch 'exit
5963 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5964 ((and todayp (member 'today (car org-agenda-time-grid))))
5965 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5966 ((member 'weekly (car org-agenda-time-grid)))
5967 (t (throw 'exit list)))
5968 (let* ((have (delq nil (mapcar
5969 (lambda (x) (get-text-property 1 'time-of-day x))
5970 list)))
5971 (string (nth 1 org-agenda-time-grid))
5972 (gridtimes (nth 2 org-agenda-time-grid))
5973 (req (car org-agenda-time-grid))
5974 (remove (member 'remove-match req))
5975 new time)
5976 (if (and (member 'require-timed req) (not have))
5977 ;; don't show empty grid
5978 (throw 'exit list))
5979 (while (setq time (pop gridtimes))
5980 (unless (and remove (member time have))
5981 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5982 (push (org-agenda-format-item
5983 nil string "" nil
5984 (concat (substring time 0 -2) ":" (substring time -2)))
5985 new)
5986 (put-text-property
5987 2 (length (car new)) 'face 'org-time-grid (car new))))
5988 (when (and todayp org-agenda-show-current-time-in-grid)
5989 (push (org-agenda-format-item
5991 org-agenda-current-time-string
5992 "" nil
5993 (format-time-string "%H:%M "))
5994 new)
5995 (put-text-property
5996 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5998 (if (member 'time-up org-agenda-sorting-strategy-selected)
5999 (append new list)
6000 (append list new)))))
6002 (defun org-compile-prefix-format (key)
6003 "Compile the prefix format into a Lisp form that can be evaluated.
6004 The resulting form and associated variable bindings is returned
6005 and stored in the variable `org-prefix-format-compiled'."
6006 (setq org-prefix-has-time nil org-prefix-has-tag nil
6007 org-prefix-category-length nil
6008 org-prefix-has-effort nil)
6009 (let ((s (cond
6010 ((stringp org-agenda-prefix-format)
6011 org-agenda-prefix-format)
6012 ((assq key org-agenda-prefix-format)
6013 (cdr (assq key org-agenda-prefix-format)))
6014 (t " %-12:c%?-12t% s")))
6015 (start 0)
6016 varform vars var e c f opt)
6017 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6018 s start)
6019 (setq var (or (cdr (assoc (match-string 4 s)
6020 '(("c" . category) ("t" . time) ("s" . extra)
6021 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6022 'eval)
6023 c (or (match-string 3 s) "")
6024 opt (match-beginning 1)
6025 start (1+ (match-beginning 0)))
6026 (if (equal var 'time) (setq org-prefix-has-time t))
6027 (if (equal var 'tag) (setq org-prefix-has-tag t))
6028 (if (equal var 'effort) (setq org-prefix-has-effort t))
6029 (setq f (concat "%" (match-string 2 s) "s"))
6030 (when (equal var 'category)
6031 (setq org-prefix-category-length
6032 (floor (abs (string-to-number (match-string 2 s)))))
6033 (setq org-prefix-category-max-length
6034 (let ((x (match-string 2 s)))
6035 (save-match-data
6036 (if (string-match "\\.[0-9]+" x)
6037 (string-to-number (substring (match-string 0 x) 1)))))))
6038 (if (eq var 'eval)
6039 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6040 (if opt
6041 (setq varform
6042 `(if (equal "" ,var)
6044 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6045 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6046 (setq s (replace-match "%s" t nil s))
6047 (push varform vars))
6048 (setq vars (nreverse vars))
6049 (with-current-buffer org-agenda-buffer
6050 (setq org-prefix-format-compiled
6051 (list
6052 `((org-prefix-has-time ,org-prefix-has-time)
6053 (org-prefix-has-tag ,org-prefix-has-tag)
6054 (org-prefix-category-length ,org-prefix-category-length)
6055 (org-prefix-has-effort ,org-prefix-has-effort))
6056 `(format ,s ,@vars))))))
6058 (defun org-set-sorting-strategy (key)
6059 (if (symbolp (car org-agenda-sorting-strategy))
6060 ;; the old format
6061 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6062 (setq org-agenda-sorting-strategy-selected
6063 (or (cdr (assq key org-agenda-sorting-strategy))
6064 (cdr (assq 'agenda org-agenda-sorting-strategy))
6065 '(time-up category-keep priority-down)))))
6067 (defun org-get-time-of-day (s &optional string mod24)
6068 "Check string S for a time of day.
6069 If found, return it as a military time number between 0 and 2400.
6070 If not found, return nil.
6071 The optional STRING argument forces conversion into a 5 character wide string
6072 HH:MM."
6073 (save-match-data
6074 (when
6075 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6076 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6077 (let* ((h (string-to-number (match-string 1 s)))
6078 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6079 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6080 (am-p (equal ampm "am"))
6081 (h1 (cond ((not ampm) h)
6082 ((= h 12) (if am-p 0 12))
6083 (t (+ h (if am-p 0 12)))))
6084 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6085 (mod h1 24) h1))
6086 (t0 (+ (* 100 h2) m))
6087 (t1 (concat (if (>= h1 24) "+" " ")
6088 (if (and org-agenda-time-leading-zero
6089 (< t0 1000)) "0" "")
6090 (if (< t0 100) "0" "")
6091 (if (< t0 10) "0" "")
6092 (int-to-string t0))))
6093 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6095 (defvar org-agenda-before-sorting-filter-function nil
6096 "Function to be applied to agenda items prior to sorting.
6097 Prior to sorting also means just before they are inserted into the agenda.
6099 To aid sorting, you may revisit the original entries and add more text
6100 properties which will later be used by the sorting functions.
6102 The function should take a string argument, an agenda line.
6103 It has access to the text properties in that line, which contain among
6104 other things, the property `org-hd-marker' that points to the entry
6105 where the line comes from. Note that not all lines going into the agenda
6106 have this property, only most.
6108 The function should return the modified string. It is probably best
6109 to ONLY change text properties.
6111 You can also use this function as a filter, by returning nil for lines
6112 you don't want to have in the agenda at all. For this application, you
6113 could bind the variable in the options section of a custom command.")
6115 (defun org-finalize-agenda-entries (list &optional nosort)
6116 "Sort and concatenate the agenda items."
6117 (setq list (mapcar 'org-agenda-highlight-todo list))
6118 (if nosort
6119 list
6120 (when org-agenda-before-sorting-filter-function
6121 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6122 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6124 (defun org-agenda-highlight-todo (x)
6125 (let ((org-done-keywords org-done-keywords-for-agenda)
6126 (case-fold-search nil)
6128 (if (eq x 'line)
6129 (save-excursion
6130 (beginning-of-line 1)
6131 (setq re (org-get-at-bol 'org-todo-regexp))
6132 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6133 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6134 (add-text-properties (match-beginning 0) (match-end 1)
6135 (list 'face (org-get-todo-face 1)))
6136 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6137 (delete-region (match-beginning 1) (1- (match-end 0)))
6138 (goto-char (match-beginning 1))
6139 (insert (format org-agenda-todo-keyword-format s)))))
6140 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6141 (setq re (get-text-property 0 'org-todo-regexp x))
6142 (when (and re
6143 ;; Test `pl' because if there's no heading content,
6144 ;; there's no point matching to highlight. Note
6145 ;; that if we didn't test `pl' first, and there
6146 ;; happened to be no keyword from `org-todo-regexp'
6147 ;; on this heading line, then the `equal' comparison
6148 ;; afterwards would spuriously succeed in the case
6149 ;; where `pl' is nil -- causing an args-out-of-range
6150 ;; error when we try to add text properties to text
6151 ;; that isn't there.
6153 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6154 x pl) pl))
6155 (add-text-properties
6156 (or (match-end 1) (match-end 0)) (match-end 0)
6157 (list 'face (org-get-todo-face (match-string 2 x)))
6159 (when (match-end 1)
6160 (setq x (concat (substring x 0 (match-end 1))
6161 (format org-agenda-todo-keyword-format
6162 (match-string 2 x))
6163 (org-add-props " " (text-properties-at 0 x))
6164 (substring x (match-end 3)))))))
6165 x)))
6167 (defsubst org-cmp-priority (a b)
6168 "Compare the priorities of string A and B."
6169 (let ((pa (or (get-text-property 1 'priority a) 0))
6170 (pb (or (get-text-property 1 'priority b) 0)))
6171 (cond ((> pa pb) +1)
6172 ((< pa pb) -1)
6173 (t nil))))
6175 (defsubst org-cmp-effort (a b)
6176 "Compare the effort values of string A and B."
6177 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6178 (ea (or (get-text-property 1 'effort-minutes a) def))
6179 (eb (or (get-text-property 1 'effort-minutes b) def)))
6180 (cond ((> ea eb) +1)
6181 ((< ea eb) -1)
6182 (t nil))))
6184 (defsubst org-cmp-category (a b)
6185 "Compare the string values of categories of strings A and B."
6186 (let ((ca (or (get-text-property 1 'org-category a) ""))
6187 (cb (or (get-text-property 1 'org-category b) "")))
6188 (cond ((string-lessp ca cb) -1)
6189 ((string-lessp cb ca) +1)
6190 (t nil))))
6192 (defsubst org-cmp-todo-state (a b)
6193 "Compare the todo states of strings A and B."
6194 (let* ((ma (or (get-text-property 1 'org-marker a)
6195 (get-text-property 1 'org-hd-marker a)))
6196 (mb (or (get-text-property 1 'org-marker b)
6197 (get-text-property 1 'org-hd-marker b)))
6198 (fa (and ma (marker-buffer ma)))
6199 (fb (and mb (marker-buffer mb)))
6200 (todo-kwds
6201 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6202 (and fb (with-current-buffer fb org-todo-keywords-1))))
6203 (ta (or (get-text-property 1 'todo-state a) ""))
6204 (tb (or (get-text-property 1 'todo-state b) ""))
6205 (la (- (length (member ta todo-kwds))))
6206 (lb (- (length (member tb todo-kwds))))
6207 (donepa (member ta org-done-keywords-for-agenda))
6208 (donepb (member tb org-done-keywords-for-agenda)))
6209 (cond ((and donepa (not donepb)) -1)
6210 ((and (not donepa) donepb) +1)
6211 ((< la lb) -1)
6212 ((< lb la) +1)
6213 (t nil))))
6215 (defsubst org-cmp-alpha (a b)
6216 "Compare the headlines, alphabetically."
6217 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6218 (plb (text-property-any 0 (length b) 'org-heading t b))
6219 (ta (and pla (substring a pla)))
6220 (tb (and plb (substring b plb))))
6221 (when pla
6222 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6223 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6224 (setq ta (substring ta (match-end 0))))
6225 (setq ta (downcase ta)))
6226 (when plb
6227 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6228 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6229 (setq tb (substring tb (match-end 0))))
6230 (setq tb (downcase tb)))
6231 (cond ((not ta) +1)
6232 ((not tb) -1)
6233 ((string-lessp ta tb) -1)
6234 ((string-lessp tb ta) +1)
6235 (t nil))))
6237 (defsubst org-cmp-tag (a b)
6238 "Compare the string values of the first tags of A and B."
6239 (let ((ta (car (last (get-text-property 1 'tags a))))
6240 (tb (car (last (get-text-property 1 'tags b)))))
6241 (cond ((not ta) +1)
6242 ((not tb) -1)
6243 ((string-lessp ta tb) -1)
6244 ((string-lessp tb ta) +1)
6245 (t nil))))
6247 (defsubst org-cmp-time (a b)
6248 "Compare the time-of-day values of strings A and B."
6249 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6250 (ta (or (get-text-property 1 'time-of-day a) def))
6251 (tb (or (get-text-property 1 'time-of-day b) def)))
6252 (cond ((< ta tb) -1)
6253 ((< tb ta) +1)
6254 (t nil))))
6256 (defsubst org-cmp-habit-p (a b)
6257 "Compare the todo states of strings A and B."
6258 (let ((ha (get-text-property 1 'org-habit-p a))
6259 (hb (get-text-property 1 'org-habit-p b)))
6260 (cond ((and ha (not hb)) -1)
6261 ((and (not ha) hb) +1)
6262 (t nil))))
6264 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6266 (defun org-entries-lessp (a b)
6267 "Predicate for sorting agenda entries."
6268 ;; The following variables will be used when the form is evaluated.
6269 ;; So even though the compiler complains, keep them.
6270 (let* ((ss org-agenda-sorting-strategy-selected)
6271 (time-up (and (org-em 'time-up 'time-down ss)
6272 (org-cmp-time a b)))
6273 (time-down (if time-up (- time-up) nil))
6274 (priority-up (and (org-em 'priority-up 'priority-down ss)
6275 (org-cmp-priority a b)))
6276 (priority-down (if priority-up (- priority-up) nil))
6277 (effort-up (and (org-em 'effort-up 'effort-down ss)
6278 (org-cmp-effort a b)))
6279 (effort-down (if effort-up (- effort-up) nil))
6280 (category-up (and (or (org-em 'category-up 'category-down ss)
6281 (memq 'category-keep ss))
6282 (org-cmp-category a b)))
6283 (category-down (if category-up (- category-up) nil))
6284 (category-keep (if category-up +1 nil))
6285 (tag-up (and (org-em 'tag-up 'tag-down ss)
6286 (org-cmp-tag a b)))
6287 (tag-down (if tag-up (- tag-up) nil))
6288 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6289 (org-cmp-todo-state a b)))
6290 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6291 (habit-up (and (org-em 'habit-up 'habit-down ss)
6292 (org-cmp-habit-p a b)))
6293 (habit-down (if habit-up (- habit-up) nil))
6294 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6295 (org-cmp-alpha a b)))
6296 (alpha-down (if alpha-up (- alpha-up) nil))
6297 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6298 user-defined-up user-defined-down)
6299 (if (and need-user-cmp org-agenda-cmp-user-defined
6300 (functionp org-agenda-cmp-user-defined))
6301 (setq user-defined-up
6302 (funcall org-agenda-cmp-user-defined a b)
6303 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6304 (cdr (assoc
6305 (eval (cons 'or org-agenda-sorting-strategy-selected))
6306 '((-1 . t) (1 . nil) (nil . nil))))))
6308 ;;; Agenda restriction lock
6310 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6311 "Overlay to mark the headline to which agenda commands are restricted.")
6312 (overlay-put org-agenda-restriction-lock-overlay
6313 'face 'org-agenda-restriction-lock)
6314 (overlay-put org-agenda-restriction-lock-overlay
6315 'help-echo "Agendas are currently limited to this subtree.")
6316 (org-detach-overlay org-agenda-restriction-lock-overlay)
6318 (defun org-agenda-set-restriction-lock (&optional type)
6319 "Set restriction lock for agenda, to current subtree or file.
6320 Restriction will be the file if TYPE is `file', or if type is the
6321 universal prefix '(4), or if the cursor is before the first headline
6322 in the file. Otherwise, restriction will be to the current subtree."
6323 (interactive "P")
6324 (and (equal type '(4)) (setq type 'file))
6325 (setq type (cond
6326 (type type)
6327 ((org-at-heading-p) 'subtree)
6328 ((condition-case nil (org-back-to-heading t) (error nil))
6329 'subtree)
6330 (t 'file)))
6331 (if (eq type 'subtree)
6332 (progn
6333 (setq org-agenda-restrict t)
6334 (setq org-agenda-overriding-restriction 'subtree)
6335 (put 'org-agenda-files 'org-restrict
6336 (list (buffer-file-name (buffer-base-buffer))))
6337 (org-back-to-heading t)
6338 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6339 (move-marker org-agenda-restrict-begin (point))
6340 (move-marker org-agenda-restrict-end
6341 (save-excursion (org-end-of-subtree t)))
6342 (message "Locking agenda restriction to subtree"))
6343 (put 'org-agenda-files 'org-restrict
6344 (list (buffer-file-name (buffer-base-buffer))))
6345 (setq org-agenda-restrict nil)
6346 (setq org-agenda-overriding-restriction 'file)
6347 (move-marker org-agenda-restrict-begin nil)
6348 (move-marker org-agenda-restrict-end nil)
6349 (message "Locking agenda restriction to file"))
6350 (setq current-prefix-arg nil)
6351 (org-agenda-maybe-redo))
6353 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6354 "Remove the agenda restriction lock."
6355 (interactive "P")
6356 (org-detach-overlay org-agenda-restriction-lock-overlay)
6357 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6358 (setq org-agenda-overriding-restriction nil)
6359 (setq org-agenda-restrict nil)
6360 (put 'org-agenda-files 'org-restrict nil)
6361 (move-marker org-agenda-restrict-begin nil)
6362 (move-marker org-agenda-restrict-end nil)
6363 (setq current-prefix-arg nil)
6364 (message "Agenda restriction lock removed")
6365 (or noupdate (org-agenda-maybe-redo)))
6367 (defun org-agenda-maybe-redo ()
6368 "If there is any window showing the agenda view, update it."
6369 (let ((w (get-buffer-window org-agenda-buffer-name t))
6370 (w0 (selected-window)))
6371 (when w
6372 (select-window w)
6373 (org-agenda-redo)
6374 (select-window w0)
6375 (if org-agenda-overriding-restriction
6376 (message "Agenda view shifted to new %s restriction"
6377 org-agenda-overriding-restriction)
6378 (message "Agenda restriction lock removed")))))
6380 ;;; Agenda commands
6382 (defun org-agenda-check-type (error &rest types)
6383 "Check if agenda buffer is of allowed type.
6384 If ERROR is non-nil, throw an error, otherwise just return nil."
6385 (if (not org-agenda-type)
6386 (error "No Org agenda currently displayed")
6387 (if (memq org-agenda-type types)
6389 (if error
6390 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6391 nil))))
6393 (defun org-agenda-Quit (&optional arg)
6394 "Exit agenda by removing the window or the buffer."
6395 (interactive)
6396 (if org-agenda-columns-active
6397 (org-columns-quit)
6398 (let ((buf (current-buffer)))
6399 (if (eq org-agenda-window-setup 'other-frame)
6400 (progn
6401 (org-agenda-reset-markers)
6402 (kill-buffer buf)
6403 (org-columns-remove-overlays)
6404 (setq org-agenda-archives-mode nil)
6405 (delete-frame))
6406 (and (not (eq org-agenda-window-setup 'current-window))
6407 (not (one-window-p))
6408 (delete-window))
6409 (org-agenda-reset-markers)
6410 (kill-buffer buf)
6411 (org-columns-remove-overlays)
6412 (setq org-agenda-archives-mode nil)))
6413 ;; Maybe restore the pre-agenda window configuration.
6414 (and org-agenda-restore-windows-after-quit
6415 (not (eq org-agenda-window-setup 'other-frame))
6416 org-pre-agenda-window-conf
6417 (set-window-configuration org-pre-agenda-window-conf))))
6419 (defun org-agenda-quit ()
6420 "Exit agenda by killing agenda buffer or burying it when
6421 `org-agenda-sticky' is non-NIL"
6422 (interactive)
6423 (if org-agenda-columns-active
6424 (org-columns-quit)
6425 (if org-agenda-sticky
6426 (let ((buf (current-buffer)))
6427 (if (eq org-agenda-window-setup 'other-frame)
6428 (progn
6429 (delete-frame))
6430 (and (not (eq org-agenda-window-setup 'current-window))
6431 (not (one-window-p))
6432 (delete-window)))
6433 (with-current-buffer buf
6434 (bury-buffer)
6435 ;; Maybe restore the pre-agenda window configuration.
6436 (and org-agenda-restore-windows-after-quit
6437 (not (eq org-agenda-window-setup 'other-frame))
6438 org-pre-agenda-window-conf
6439 (set-window-configuration org-pre-agenda-window-conf))))
6440 (org-agenda-Quit))))
6442 (defun org-agenda-exit ()
6443 "Exit agenda by removing the window or the buffer.
6444 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6445 Org-mode buffers visited directly by the user will not be touched."
6446 (interactive)
6447 (org-release-buffers org-agenda-new-buffers)
6448 (setq org-agenda-new-buffers nil)
6449 (org-agenda-Quit))
6451 (defun org-agenda-kill-all-agenda-buffers ()
6452 "Kill all buffers in `org-agena-mode'.
6453 This is used when toggling sticky agendas. You can also explicitly invoke it
6454 with `C-c a C-k'."
6455 (interactive)
6456 (let (blist)
6457 (dolist (buf (buffer-list))
6458 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6459 (push buf blist)))
6460 (mapc 'kill-buffer blist)))
6462 (defun org-agenda-execute (arg)
6463 "Execute another agenda command, keeping same window.
6464 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6465 in the agenda."
6466 (interactive "P")
6467 (let ((org-agenda-window-setup 'current-window))
6468 (org-agenda arg)))
6470 (defun org-agenda-redo ()
6471 "Rebuild Agenda.
6472 When this is the global TODO list, a prefix argument will be interpreted."
6473 (interactive)
6474 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6475 (org-agenda-sticky nil)
6476 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6477 org-agenda-buffer-name))
6478 (org-agenda-keep-modes t)
6479 (tag-filter org-agenda-tag-filter)
6480 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6481 (top-cat-filter org-agenda-top-category-filter)
6482 (cat-filter org-agenda-category-filter)
6483 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6484 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6485 (cols org-agenda-columns-active)
6486 (line (org-current-line))
6487 (window-line (- line (org-current-line (window-start))))
6488 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6489 (put 'org-agenda-tag-filter :preset-filter nil)
6490 (put 'org-agenda-category-filter :preset-filter nil)
6491 (and cols (org-columns-quit))
6492 (message "Rebuilding agenda buffer...")
6493 (org-let lprops '(eval org-agenda-redo-command))
6494 (setq org-agenda-undo-list nil
6495 org-agenda-pending-undo-list nil)
6496 (message "Rebuilding agenda buffer...done")
6497 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6498 (put 'org-agenda-category-filter :preset-filter cat-preset)
6499 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6500 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6501 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6502 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6503 (org-goto-line line)
6504 (recenter window-line)))
6506 (defvar org-global-tags-completion-table nil)
6507 (defvar org-agenda-filter-form nil)
6508 (defvar org-agenda-filtered-by-category nil)
6510 (defun org-agenda-filter-by-category (strip)
6511 "Keep only those lines in the agenda buffer that have a specific category.
6512 The category is that of the current line."
6513 (interactive "P")
6514 (if org-agenda-filtered-by-category
6515 (org-agenda-filter-show-all-cat)
6516 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6517 (if cat (org-agenda-filter-apply
6518 (list (concat (if strip "-" "+") cat)) 'category)
6519 (error "No category at point")))))
6521 (defun org-find-top-category (&optional pos)
6522 (save-excursion
6523 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6524 (if pos (goto-char pos))
6525 ;; Skip up to the topmost parent
6526 (while (ignore-errors (outline-up-heading 1) t))
6527 (ignore-errors
6528 (nth 4 (org-heading-components))))))
6530 (defvar org-agenda-filtered-by-top-category nil)
6532 (defun org-agenda-filter-by-top-category (strip)
6533 "Keep only those lines in the agenda buffer that have a specific category.
6534 The category is that of the current line."
6535 (interactive "P")
6536 (if org-agenda-filtered-by-top-category
6537 (progn
6538 (setq org-agenda-filtered-by-top-category nil
6539 org-agenda-top-category-filter nil)
6540 (org-agenda-filter-show-all-cat))
6541 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6542 (if cat (org-agenda-filter-top-category-apply cat strip)
6543 (error "No top-level category at point")))))
6545 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6546 "Keep only those lines in the agenda buffer that have a specific tag.
6547 The tag is selected with its fast selection letter, as configured.
6548 With prefix argument STRIP, remove all lines that do have the tag.
6549 A lisp caller can specify CHAR. NARROW means that the new tag should be
6550 used to narrow the search - the interactive user can also press `-' or `+'
6551 to switch to narrowing."
6552 (interactive "P")
6553 (let* ((alist org-tag-alist-for-agenda)
6554 (tag-chars (mapconcat
6555 (lambda (x) (if (and (not (symbolp (car x)))
6556 (cdr x))
6557 (char-to-string (cdr x))
6558 ""))
6559 alist ""))
6560 (efforts (org-split-string
6561 (or (cdr (assoc (concat org-effort-property "_ALL")
6562 org-global-properties))
6563 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6564 "")))
6565 (effort-op org-agenda-filter-effort-default-operator)
6566 (effort-prompt "")
6567 (inhibit-read-only t)
6568 (current org-agenda-tag-filter)
6569 maybe-refresh a n tag)
6570 (unless char
6571 (message
6572 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6573 (if narrow "Narrow" "Filter") tag-chars
6574 (if org-agenda-auto-exclude-function "[RET], " ""))
6575 (setq char (read-char-exclusive)))
6576 (when (member char '(?+ ?-))
6577 ;; Narrowing down
6578 (cond ((equal char ?-) (setq strip t narrow t))
6579 ((equal char ?+) (setq strip nil narrow t)))
6580 (message
6581 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6582 (setq char (read-char-exclusive)))
6583 (when (member char '(?< ?> ?= ??))
6584 ;; An effort operator
6585 (setq effort-op (char-to-string char))
6586 (setq alist nil) ; to make sure it will be interpreted as effort.
6587 (unless (equal char ??)
6588 (loop for i from 0 to 9 do
6589 (setq effort-prompt
6590 (concat
6591 effort-prompt " ["
6592 (if (= i 9) "0" (int-to-string (1+ i)))
6593 "]" (nth i efforts))))
6594 (message "Effort%s: %s " effort-op effort-prompt)
6595 (setq char (read-char-exclusive))
6596 (when (or (< char ?0) (> char ?9))
6597 (error "Need 1-9,0 to select effort"))))
6598 (when (equal char ?\t)
6599 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6600 (org-set-local 'org-global-tags-completion-table
6601 (org-global-tags-completion-table)))
6602 (let ((completion-ignore-case t))
6603 (setq tag (org-icompleting-read
6604 "Tag: " org-global-tags-completion-table))))
6605 (cond
6606 ((equal char ?\r)
6607 (org-agenda-filter-show-all-tag)
6608 (when org-agenda-auto-exclude-function
6609 (setq org-agenda-tag-filter '())
6610 (dolist (tag (org-agenda-get-represented-tags))
6611 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6612 (if modifier
6613 (push modifier org-agenda-tag-filter))))
6614 (if (not (null org-agenda-tag-filter))
6615 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6616 (setq maybe-refresh t))
6617 ((equal char ?/)
6618 (org-agenda-filter-show-all-tag)
6619 (when (get 'org-agenda-tag-filter :preset-filter)
6620 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6621 (setq maybe-refresh t))
6622 ((equal char ?. )
6623 (setq org-agenda-tag-filter
6624 (mapcar (lambda(tag) (concat "+" tag))
6625 (org-get-at-bol 'tags)))
6626 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6627 (setq maybe-refresh t))
6628 ((or (equal char ?\ )
6629 (setq a (rassoc char alist))
6630 (and (>= char ?0) (<= char ?9)
6631 (setq n (if (= char ?0) 9 (- char ?0 1))
6632 tag (concat effort-op (nth n efforts))
6633 a (cons tag nil)))
6634 (and (= char ??)
6635 (setq tag "?eff")
6636 a (cons tag nil))
6637 (and tag (setq a (cons tag nil))))
6638 (org-agenda-filter-show-all-tag)
6639 (setq tag (car a))
6640 (setq org-agenda-tag-filter
6641 (cons (concat (if strip "-" "+") tag)
6642 (if narrow current nil)))
6643 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6644 (setq maybe-refresh t))
6645 (t (error "Invalid tag selection character %c" char)))
6646 (when (and maybe-refresh
6647 (eq org-agenda-clockreport-mode 'with-filter))
6648 (org-agenda-redo))))
6650 (defun org-agenda-get-represented-tags ()
6651 "Get a list of all tags currently represented in the agenda."
6652 (let (p tags)
6653 (save-excursion
6654 (goto-char (point-min))
6655 (while (setq p (next-single-property-change (point) 'tags))
6656 (goto-char p)
6657 (mapc (lambda (x) (add-to-list 'tags x))
6658 (get-text-property (point) 'tags))))
6659 tags))
6661 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6662 "Refine the current filter. See `org-agenda-filter-by-tag'."
6663 (interactive "P")
6664 (org-agenda-filter-by-tag strip char 'refine))
6666 (defun org-agenda-filter-make-matcher ()
6667 "Create the form that tests a line for agenda filter."
6668 (let (f f1)
6669 ;; first compute the tag-filter matcher
6670 (dolist (x (delete-dups
6671 (append (get 'org-agenda-tag-filter
6672 :preset-filter) org-agenda-tag-filter)))
6673 (if (member x '("-" "+"))
6674 (setq f1 (if (equal x "-") 'tags '(not tags)))
6675 (if (string-match "[<=>?]" x)
6676 (setq f1 (org-agenda-filter-effort-form x))
6677 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6678 (if (equal (string-to-char x) ?-)
6679 (setq f1 (list 'not f1))))
6680 (push f1 f))
6681 ;; then compute the category-filter matcher
6682 (dolist (x (delete-dups
6683 (append (get 'org-agenda-category-filter
6684 :preset-filter) org-agenda-category-filter)))
6685 (if (equal "-" (substring x 0 1))
6686 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6687 (setq f1 (list 'equal (substring x 1) 'cat)))
6688 (push f1 f))
6689 (cons 'and (nreverse f))))
6691 (defun org-agenda-filter-effort-form (e)
6692 "Return the form to compare the effort of the current line with what E says.
6693 E looks like \"+<2:25\"."
6694 (let (op)
6695 (setq e (substring e 1))
6696 (setq op (string-to-char e) e (substring e 1))
6697 (setq op (cond ((equal op ?<) '<=)
6698 ((equal op ?>) '>=)
6699 ((equal op ??) op)
6700 (t '=)))
6701 (list 'org-agenda-compare-effort (list 'quote op)
6702 (org-duration-string-to-minutes e))))
6704 (defun org-agenda-compare-effort (op value)
6705 "Compare the effort of the current line with VALUE, using OP.
6706 If the line does not have an effort defined, return nil."
6707 (let ((eff (org-get-at-bol 'effort-minutes)))
6708 (if (equal op ??)
6709 (not eff)
6710 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6711 value))))
6713 (defun org-agenda-filter-apply (filter type)
6714 "Set FILTER as the new agenda filter and apply it."
6715 (let (tags cat)
6716 (if (eq type 'tag)
6717 (setq org-agenda-tag-filter filter)
6718 (setq org-agenda-category-filter filter))
6719 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6720 (if (and (eq type 'category)
6721 (not (equal (substring (car filter) 0 1) "-")))
6722 ;; Only set `org-agenda-filtered-by-category' to t
6723 ;; when a unique category is used as the filter
6724 (setq org-agenda-filtered-by-category t))
6725 (org-agenda-set-mode-name)
6726 (save-excursion
6727 (goto-char (point-min))
6728 (while (not (eobp))
6729 (if (org-get-at-bol 'org-marker)
6730 (progn
6731 (setq tags (org-get-at-bol 'tags) ; used in eval
6732 cat (get-text-property (point) 'org-category))
6733 (if (not (eval org-agenda-filter-form))
6734 (org-agenda-filter-hide-line type))
6735 (beginning-of-line 2))
6736 (beginning-of-line 2))))
6737 (if (get-char-property (point) 'invisible)
6738 (ignore-errors (org-agenda-previous-line)))))
6740 (defun org-agenda-filter-top-category-apply (category &optional negative)
6741 "Set FILTER as the new agenda filter and apply it."
6742 (org-agenda-set-mode-name)
6743 (save-excursion
6744 (goto-char (point-min))
6745 (while (not (eobp))
6746 (let* ((pos (org-get-at-bol 'org-hd-marker))
6747 (topcat (and pos (org-find-top-category pos))))
6748 (if (and topcat (funcall (if negative 'identity 'not)
6749 (string= category topcat)))
6750 (org-agenda-filter-hide-line 'category)))
6751 (beginning-of-line 2)))
6752 (if (get-char-property (point) 'invisible)
6753 (org-agenda-previous-line))
6754 (setq org-agenda-top-category-filter category
6755 org-agenda-filtered-by-top-category t))
6757 (defun org-agenda-filter-hide-line (type)
6758 (let (ov)
6759 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6760 (point-at-eol)))
6761 (overlay-put ov 'invisible t)
6762 (overlay-put ov 'type type)
6763 (if (eq type 'tag)
6764 (push ov org-agenda-tag-filter-overlays)
6765 (push ov org-agenda-cat-filter-overlays))))
6767 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6768 (setq pos (or pos (point)))
6769 (save-excursion
6770 (dolist (ov (overlays-at pos))
6771 (when (and (overlay-get ov 'invisible)
6772 (eq (overlay-get ov 'type) 'tag))
6773 (goto-char pos)
6774 (if (< (overlay-start ov) (point-at-eol))
6775 (move-overlay ov (point-at-eol)
6776 (overlay-end ov)))))))
6778 (defun org-agenda-filter-show-all-tag nil
6779 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6780 (setq org-agenda-tag-filter-overlays nil
6781 org-agenda-tag-filter nil
6782 org-agenda-filter-form nil)
6783 (org-agenda-set-mode-name))
6785 (defun org-agenda-filter-show-all-cat nil
6786 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6787 (setq org-agenda-cat-filter-overlays nil
6788 org-agenda-filtered-by-category nil
6789 org-agenda-category-filter nil
6790 org-agenda-filter-form nil)
6791 (org-agenda-set-mode-name))
6793 (defun org-agenda-manipulate-query-add ()
6794 "Manipulate the query by adding a search term with positive selection.
6795 Positive selection means the term must be matched for selection of an entry."
6796 (interactive)
6797 (org-agenda-manipulate-query ?\[))
6798 (defun org-agenda-manipulate-query-subtract ()
6799 "Manipulate the query by adding a search term with negative selection.
6800 Negative selection means term must not be matched for selection of an entry."
6801 (interactive)
6802 (org-agenda-manipulate-query ?\]))
6803 (defun org-agenda-manipulate-query-add-re ()
6804 "Manipulate the query by adding a search regexp with positive selection.
6805 Positive selection means the regexp must match for selection of an entry."
6806 (interactive)
6807 (org-agenda-manipulate-query ?\{))
6808 (defun org-agenda-manipulate-query-subtract-re ()
6809 "Manipulate the query by adding a search regexp with negative selection.
6810 Negative selection means regexp must not match for selection of an entry."
6811 (interactive)
6812 (org-agenda-manipulate-query ?\}))
6813 (defun org-agenda-manipulate-query (char)
6814 (cond
6815 ((memq org-agenda-type '(timeline agenda))
6816 (let ((org-agenda-include-inactive-timestamps t))
6817 (org-agenda-redo))
6818 (message "Display now includes inactive timestamps as well"))
6819 ((eq org-agenda-type 'search)
6820 (org-add-to-string
6821 'org-agenda-query-string
6822 (if org-agenda-last-search-view-search-was-boolean
6823 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6824 (?\{ . " +{}") (?\} . " -{}"))))
6825 " "))
6826 (setq org-agenda-redo-command
6827 (list 'org-search-view
6828 org-todo-only
6829 org-agenda-query-string
6830 (+ (length org-agenda-query-string)
6831 (if (member char '(?\{ ?\})) 0 1))))
6832 (set-register org-agenda-query-register org-agenda-query-string)
6833 (org-agenda-redo))
6834 (t (error "Cannot manipulate query for %s-type agenda buffers"
6835 org-agenda-type))))
6837 (defun org-add-to-string (var string)
6838 (set var (concat (symbol-value var) string)))
6840 (defun org-agenda-goto-date (date)
6841 "Jump to DATE in agenda."
6842 (interactive (list (let ((org-read-date-prefer-future
6843 (eval org-agenda-jump-prefer-future)))
6844 (org-read-date))))
6845 (org-agenda-list nil date))
6847 (defun org-agenda-goto-today ()
6848 "Go to today."
6849 (interactive)
6850 (org-agenda-check-type t 'timeline 'agenda)
6851 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6852 (cond
6853 (tdpos (goto-char tdpos))
6854 ((eq org-agenda-type 'agenda)
6855 (let* ((sd (org-agenda-compute-starting-span
6856 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6857 (org-agenda-overriding-arguments org-agenda-last-arguments))
6858 (setf (nth 1 org-agenda-overriding-arguments) sd)
6859 (org-agenda-redo)
6860 (org-agenda-find-same-or-today-or-agenda)))
6861 (t (error "Cannot find today")))))
6863 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6864 (goto-char
6865 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6866 (text-property-any (point-min) (point-max) 'org-today t)
6867 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6868 (point-min))))
6870 (defun org-agenda-later (arg)
6871 "Go forward in time by thee current span.
6872 With prefix ARG, go forward that many times the current span."
6873 (interactive "p")
6874 (org-agenda-check-type t 'agenda)
6875 (let* ((span org-agenda-current-span)
6876 (sd org-starting-day)
6877 (greg (calendar-gregorian-from-absolute sd))
6878 (cnt (org-get-at-bol 'org-day-cnt))
6879 greg2)
6880 (cond
6881 ((eq span 'day)
6882 (setq sd (+ arg sd)))
6883 ((eq span 'week)
6884 (setq sd (+ (* 7 arg) sd)))
6885 ((eq span 'month)
6886 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6887 sd (calendar-absolute-from-gregorian greg2))
6888 (setcar greg2 (1+ (car greg2))))
6889 ((eq span 'year)
6890 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6891 sd (calendar-absolute-from-gregorian greg2))
6892 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6894 (setq sd (+ (* span arg) sd))))
6895 (let ((org-agenda-overriding-arguments
6896 (list (car org-agenda-last-arguments) sd span t)))
6897 (org-agenda-redo)
6898 (org-agenda-find-same-or-today-or-agenda cnt))))
6900 (defun org-agenda-earlier (arg)
6901 "Go backward in time by the current span.
6902 With prefix ARG, go backward that many times the current span."
6903 (interactive "p")
6904 (org-agenda-later (- arg)))
6906 (defun org-agenda-view-mode-dispatch ()
6907 "Call one of the view mode commands."
6908 (interactive)
6909 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6910 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6911 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
6912 (let ((a (read-char-exclusive)))
6913 (case a
6914 (?\ (call-interactively 'org-agenda-reset-view))
6915 (?d (call-interactively 'org-agenda-day-view))
6916 (?w (call-interactively 'org-agenda-week-view))
6917 (?m (call-interactively 'org-agenda-month-view))
6918 (?y (call-interactively 'org-agenda-year-view))
6919 (?l (call-interactively 'org-agenda-log-mode))
6920 (?L (org-agenda-log-mode '(4)))
6921 (?c (org-agenda-log-mode 'clockcheck))
6922 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6923 (?a (call-interactively 'org-agenda-archives-mode))
6924 (?A (org-agenda-archives-mode 'files))
6925 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6926 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6927 (?G (call-interactively 'org-agenda-toggle-time-grid))
6928 (?D (call-interactively 'org-agenda-toggle-diary))
6929 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6930 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6931 (org-agenda-check-type t 'timeline 'agenda)
6932 (org-agenda-redo))
6933 (message "Display now includes inactive timestamps as well"))
6934 (?q (message "Abort"))
6935 (otherwise (error "Invalid key" )))))
6937 (defun org-agenda-reset-view ()
6938 "Switch to default view for agenda."
6939 (interactive)
6940 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6941 (defun org-agenda-day-view (&optional day-of-year)
6942 "Switch to daily view for agenda.
6943 With argument DAY-OF-YEAR, switch to that day of the year."
6944 (interactive "P")
6945 (org-agenda-change-time-span 'day day-of-year))
6946 (defun org-agenda-week-view (&optional iso-week)
6947 "Switch to daily view for agenda.
6948 With argument ISO-WEEK, switch to the corresponding ISO week.
6949 If ISO-WEEK has more then 2 digits, only the last two encode the
6950 week. Any digits before this encode a year. So 200712 means
6951 week 12 of year 2007. Years in the range 1938-2037 can also be
6952 written as 2-digit years."
6953 (interactive "P")
6954 (org-agenda-change-time-span 'week iso-week))
6955 (defun org-agenda-month-view (&optional month)
6956 "Switch to monthly view for agenda.
6957 With argument MONTH, switch to that month."
6958 (interactive "P")
6959 (org-agenda-change-time-span 'month month))
6960 (defun org-agenda-year-view (&optional year)
6961 "Switch to yearly view for agenda.
6962 With argument YEAR, switch to that year.
6963 If MONTH has more then 2 digits, only the last two encode the
6964 month. Any digits before this encode a year. So 200712 means
6965 December year 2007. Years in the range 1938-2037 can also be
6966 written as 2-digit years."
6967 (interactive "P")
6968 (when year
6969 (setq year (org-small-year-to-year year)))
6970 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6971 (org-agenda-change-time-span 'year year)
6972 (error "Abort")))
6974 (defun org-agenda-change-time-span (span &optional n)
6975 "Change the agenda view to SPAN.
6976 SPAN may be `day', `week', `month', `year'."
6977 (org-agenda-check-type t 'agenda)
6978 (if (and (not n) (equal org-agenda-current-span span))
6979 (error "Viewing span is already \"%s\"" span))
6980 (let* ((sd (or (org-get-at-bol 'day)
6981 org-starting-day))
6982 (sd (org-agenda-compute-starting-span sd span n))
6983 (org-agenda-overriding-arguments
6984 (or org-agenda-overriding-arguments
6985 (list (car org-agenda-last-arguments) sd span t))))
6986 (org-agenda-redo)
6987 (org-agenda-find-same-or-today-or-agenda))
6988 (org-agenda-set-mode-name)
6989 (message "Switched to %s view" span))
6991 (defun org-agenda-compute-starting-span (sd span &optional n)
6992 "Compute starting date for agenda.
6993 SPAN may be `day', `week', `month', `year'. The return value
6994 is a cons cell with the starting date and the number of days,
6995 so that the date SD will be in that range."
6996 (let* ((greg (calendar-gregorian-from-absolute sd))
6997 (dg (nth 1 greg))
6998 (mg (car greg))
6999 (yg (nth 2 greg)))
7000 (cond
7001 ((eq span 'day)
7002 (when n
7003 (setq sd (+ (calendar-absolute-from-gregorian
7004 (list mg 1 yg))
7005 n -1))))
7006 ((eq span 'week)
7007 (let* ((nt (calendar-day-of-week
7008 (calendar-gregorian-from-absolute sd)))
7009 (d (if org-agenda-start-on-weekday
7010 (- nt org-agenda-start-on-weekday)
7013 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7014 (when n
7015 (require 'cal-iso)
7016 (when (> n 99)
7017 (setq y1 (org-small-year-to-year (/ n 100))
7018 n (mod n 100)))
7019 (setq sd
7020 (calendar-absolute-from-iso
7021 (list n 1
7022 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7023 ((eq span 'month)
7024 (let (y1)
7025 (when (and n (> n 99))
7026 (setq y1 (org-small-year-to-year (/ n 100))
7027 n (mod n 100)))
7028 (setq sd (calendar-absolute-from-gregorian
7029 (list (or n mg) 1 (or y1 yg))))))
7030 ((eq span 'year)
7031 (setq sd (calendar-absolute-from-gregorian
7032 (list 1 1 (or n yg))))))
7033 sd))
7035 (defun org-agenda-next-date-line (&optional arg)
7036 "Jump to the next line indicating a date in agenda buffer."
7037 (interactive "p")
7038 (org-agenda-check-type t 'agenda 'timeline)
7039 (beginning-of-line 1)
7040 ;; This does not work if user makes date format that starts with a blank
7041 (if (looking-at "^\\S-") (forward-char 1))
7042 (if (not (re-search-forward "^\\S-" nil t arg))
7043 (progn
7044 (backward-char 1)
7045 (error "No next date after this line in this buffer")))
7046 (goto-char (match-beginning 0)))
7048 (defun org-agenda-previous-date-line (&optional arg)
7049 "Jump to the previous line indicating a date in agenda buffer."
7050 (interactive "p")
7051 (org-agenda-check-type t 'agenda 'timeline)
7052 (beginning-of-line 1)
7053 (if (not (re-search-backward "^\\S-" nil t arg))
7054 (error "No previous date before this line in this buffer")))
7056 ;; Initialize the highlight
7057 (defvar org-hl (make-overlay 1 1))
7058 (overlay-put org-hl 'face 'highlight)
7060 (defun org-highlight (begin end &optional buffer)
7061 "Highlight a region with overlay."
7062 (move-overlay org-hl begin end (or buffer (current-buffer))))
7064 (defun org-unhighlight ()
7065 "Detach overlay INDEX."
7066 (org-detach-overlay org-hl))
7068 ;; FIXME this is currently not used.
7069 (defun org-highlight-until-next-command (beg end &optional buffer)
7070 "Move the highlight overlay to BEG/END, remove it before the next command."
7071 (org-highlight beg end buffer)
7072 (add-hook 'pre-command-hook 'org-unhighlight-once))
7073 (defun org-unhighlight-once ()
7074 "Remove the highlight from its position, and this function from the hook."
7075 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7076 (org-unhighlight))
7078 (defun org-agenda-follow-mode ()
7079 "Toggle follow mode in an agenda buffer."
7080 (interactive)
7081 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7082 (org-agenda-set-mode-name)
7083 (org-agenda-do-context-action)
7084 (message "Follow mode is %s"
7085 (if org-agenda-follow-mode "on" "off")))
7087 (defun org-agenda-entry-text-mode (&optional arg)
7088 "Toggle entry text mode in an agenda buffer."
7089 (interactive "P")
7090 (setq org-agenda-entry-text-mode (or (integerp arg)
7091 (not org-agenda-entry-text-mode)))
7092 (org-agenda-entry-text-hide)
7093 (and org-agenda-entry-text-mode
7094 (let ((org-agenda-entry-text-maxlines
7095 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7096 (org-agenda-entry-text-show)))
7097 (org-agenda-set-mode-name)
7098 (message "Entry text mode is %s. Maximum number of lines is %d"
7099 (if org-agenda-entry-text-mode "on" "off")
7100 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7102 (defun org-agenda-clockreport-mode (&optional with-filter)
7103 "Toggle clocktable mode in an agenda buffer.
7104 With prefix arg WITH-FILTER, make the clocktable respect the current
7105 agenda filter."
7106 (interactive "P")
7107 (org-agenda-check-type t 'agenda)
7108 (if with-filter
7109 (setq org-agenda-clockreport-mode 'with-filter)
7110 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7111 (org-agenda-set-mode-name)
7112 (org-agenda-redo)
7113 (message "Clocktable mode is %s"
7114 (if org-agenda-clockreport-mode "on" "off")))
7116 (defun org-agenda-log-mode (&optional special)
7117 "Toggle log mode in an agenda buffer.
7118 With argument SPECIAL, show all possible log items, not only the ones
7119 configured in `org-agenda-log-mode-items'.
7120 With a double `C-u' prefix arg, show *only* log items, nothing else."
7121 (interactive "P")
7122 (org-agenda-check-type t 'agenda 'timeline)
7123 (setq org-agenda-show-log
7124 (cond
7125 ((equal special '(16)) 'only)
7126 ((eq special 'clockcheck)
7127 (if (eq org-agenda-show-log 'clockcheck)
7128 nil 'clockcheck))
7129 (special '(closed clock state))
7130 (t (not org-agenda-show-log))))
7131 (org-agenda-set-mode-name)
7132 (org-agenda-redo)
7133 (message "Log mode is %s"
7134 (if org-agenda-show-log "on" "off")))
7136 (defun org-agenda-archives-mode (&optional with-files)
7137 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7138 When called with a prefix argument, include all archive files as well."
7139 (interactive "P")
7140 (setq org-agenda-archives-mode
7141 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7142 (org-agenda-set-mode-name)
7143 (org-agenda-redo)
7144 (message
7145 "%s"
7146 (cond
7147 ((eq org-agenda-archives-mode nil)
7148 "No archives are included")
7149 ((eq org-agenda-archives-mode 'trees)
7150 (format "Trees with :%s: tag are included" org-archive-tag))
7151 ((eq org-agenda-archives-mode t)
7152 (format "Trees with :%s: tag and all active archive files are included"
7153 org-archive-tag)))))
7155 (defun org-agenda-toggle-diary ()
7156 "Toggle diary inclusion in an agenda buffer."
7157 (interactive)
7158 (org-agenda-check-type t 'agenda)
7159 (setq org-agenda-include-diary (not org-agenda-include-diary))
7160 (org-agenda-redo)
7161 (org-agenda-set-mode-name)
7162 (message "Diary inclusion turned %s"
7163 (if org-agenda-include-diary "on" "off")))
7165 (defun org-agenda-toggle-deadlines ()
7166 "Toggle inclusion of entries with a deadline in an agenda buffer."
7167 (interactive)
7168 (org-agenda-check-type t 'agenda)
7169 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7170 (org-agenda-redo)
7171 (org-agenda-set-mode-name)
7172 (message "Deadlines inclusion turned %s"
7173 (if org-agenda-include-deadlines "on" "off")))
7175 (defun org-agenda-toggle-time-grid ()
7176 "Toggle time grid in an agenda buffer."
7177 (interactive)
7178 (org-agenda-check-type t 'agenda)
7179 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7180 (org-agenda-redo)
7181 (org-agenda-set-mode-name)
7182 (message "Time-grid turned %s"
7183 (if org-agenda-use-time-grid "on" "off")))
7185 (defun org-agenda-set-mode-name ()
7186 "Set the mode name to indicate all the small mode settings."
7187 (setq mode-name
7188 (list "Org-Agenda"
7189 (if (get 'org-agenda-files 'org-restrict) " []" "")
7191 '(:eval (org-agenda-span-name org-agenda-current-span))
7192 (if org-agenda-follow-mode " Follow" "")
7193 (if org-agenda-entry-text-mode " ETxt" "")
7194 (if org-agenda-include-diary " Diary" "")
7195 (if org-agenda-include-deadlines " Ddl" "")
7196 (if org-agenda-use-time-grid " Grid" "")
7197 (if (and (boundp 'org-habit-show-habits)
7198 org-habit-show-habits) " Habit" "")
7199 (cond
7200 ((consp org-agenda-show-log) " LogAll")
7201 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7202 (org-agenda-show-log " Log")
7203 (t ""))
7204 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7205 :preset-filter))
7206 '(:eval (org-propertize
7207 (concat " <"
7208 (mapconcat
7209 'identity
7210 (append
7211 (get 'org-agenda-category-filter :preset-filter)
7212 org-agenda-category-filter)
7214 ">")
7215 'face 'org-agenda-filter-category
7216 'help-echo "Category used in filtering"))
7218 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7219 :preset-filter))
7220 '(:eval (org-propertize
7221 (concat " {"
7222 (mapconcat
7223 'identity
7224 (append
7225 (get 'org-agenda-tag-filter :preset-filter)
7226 org-agenda-tag-filter)
7228 "}")
7229 'face 'org-agenda-filter-tags
7230 'help-echo "Tags used in filtering"))
7232 (if org-agenda-archives-mode
7233 (if (eq org-agenda-archives-mode t)
7234 " Archives"
7235 (format " :%s:" org-archive-tag))
7237 (if org-agenda-clockreport-mode
7238 (if (eq org-agenda-clockreport-mode 'with-filter)
7239 " Clock{}" " Clock")
7240 "")))
7241 (force-mode-line-update))
7243 (defun org-agenda-post-command-hook ()
7244 (setq org-agenda-type
7245 (or (get-text-property (point) 'org-agenda-type)
7246 (get-text-property (max (point-min) (1- (point)))
7247 'org-agenda-type))))
7249 (defun org-agenda-next-line ()
7250 "Move cursor to the next line, and show if follow mode is active."
7251 (interactive)
7252 (call-interactively 'next-line)
7253 (org-agenda-do-context-action))
7255 (defun org-agenda-previous-line ()
7256 "Move cursor to the previous line, and show if follow-mode is active."
7257 (interactive)
7258 (call-interactively 'previous-line)
7259 (org-agenda-do-context-action))
7261 (defun org-agenda-next-item (n)
7262 "Move cursor to next agenda item."
7263 (interactive "p")
7264 (let ((col (current-column)))
7265 (dotimes (c n)
7266 (when (next-single-property-change (point-at-eol) 'org-marker)
7267 (move-end-of-line 1)
7268 (goto-char (next-single-property-change (point) 'org-marker))))
7269 (org-move-to-column col))
7270 (org-agenda-do-context-action))
7272 (defun org-agenda-previous-item (n)
7273 "Move cursor to next agenda item."
7274 (interactive "p")
7275 (dotimes (c n)
7276 (let ((col (current-column))
7277 (goto (save-excursion
7278 (move-end-of-line 0)
7279 (previous-single-property-change (point) 'org-marker))))
7280 (if goto (goto-char goto))
7281 (org-move-to-column col)))
7282 (org-agenda-do-context-action))
7284 (defun org-agenda-do-context-action ()
7285 "Show outline path and, maybe, follow mode window."
7286 (let ((m (org-get-at-bol 'org-marker)))
7287 (when (and (markerp m) (marker-buffer m))
7288 (and org-agenda-follow-mode
7289 (if org-agenda-follow-indirect
7290 (org-agenda-tree-to-indirect-buffer)
7291 (org-agenda-show)))
7292 (and org-agenda-show-outline-path
7293 (org-with-point-at m (org-display-outline-path t))))))
7295 (defun org-agenda-show-priority ()
7296 "Show the priority of the current item.
7297 This priority is composed of the main priority given with the [#A] cookies,
7298 and by additional input from the age of a schedules or deadline entry."
7299 (interactive)
7300 (let* ((pri (org-get-at-bol 'priority)))
7301 (message "Priority is %d" (if pri pri -1000))))
7303 (defun org-agenda-show-tags ()
7304 "Show the tags applicable to the current item."
7305 (interactive)
7306 (let* ((tags (org-get-at-bol 'tags)))
7307 (if tags
7308 (message "Tags are :%s:"
7309 (org-no-properties (mapconcat 'identity tags ":")))
7310 (message "No tags associated with this line"))))
7312 (defun org-agenda-goto (&optional highlight)
7313 "Go to the Org-mode file which contains the item at point."
7314 (interactive)
7315 (let* ((marker (or (org-get-at-bol 'org-marker)
7316 (org-agenda-error)))
7317 (buffer (marker-buffer marker))
7318 (pos (marker-position marker)))
7319 (switch-to-buffer-other-window buffer)
7320 (widen)
7321 (push-mark)
7322 (goto-char pos)
7323 (when (derived-mode-p 'org-mode)
7324 (org-show-context 'agenda)
7325 (save-excursion
7326 (and (outline-next-heading)
7327 (org-flag-heading nil)))) ; show the next heading
7328 (when (outline-invisible-p)
7329 (show-entry)) ; display invisible text
7330 (recenter (/ (window-height) 2))
7331 (run-hooks 'org-agenda-after-show-hook)
7332 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7334 (defvar org-agenda-after-show-hook nil
7335 "Normal hook run after an item has been shown from the agenda.
7336 Point is in the buffer where the item originated.")
7338 (defun org-agenda-kill ()
7339 "Kill the entry or subtree belonging to the current agenda entry."
7340 (interactive)
7341 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7342 (let* ((marker (or (org-get-at-bol 'org-marker)
7343 (org-agenda-error)))
7344 (buffer (marker-buffer marker))
7345 (pos (marker-position marker))
7346 (type (org-get-at-bol 'type))
7347 dbeg dend (n 0) conf)
7348 (org-with-remote-undo buffer
7349 (with-current-buffer buffer
7350 (save-excursion
7351 (goto-char pos)
7352 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7353 (setq dbeg (progn (org-back-to-heading t) (point))
7354 dend (org-end-of-subtree t t))
7355 (setq dbeg (point-at-bol)
7356 dend (min (point-max) (1+ (point-at-eol)))))
7357 (goto-char dbeg)
7358 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7359 (setq conf (or (eq t org-agenda-confirm-kill)
7360 (and (numberp org-agenda-confirm-kill)
7361 (> n org-agenda-confirm-kill))))
7362 (and conf
7363 (not (y-or-n-p
7364 (format "Delete entry with %d lines in buffer \"%s\"? "
7365 n (buffer-name buffer))))
7366 (error "Abort"))
7367 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7368 (with-current-buffer buffer (delete-region dbeg dend))
7369 (message "Agenda item and source killed"))))
7371 (defvar org-archive-default-command)
7372 (defun org-agenda-archive-default ()
7373 "Archive the entry or subtree belonging to the current agenda entry."
7374 (interactive)
7375 (require 'org-archive)
7376 (org-agenda-archive-with org-archive-default-command))
7378 (defun org-agenda-archive-default-with-confirmation ()
7379 "Archive the entry or subtree belonging to the current agenda entry."
7380 (interactive)
7381 (require 'org-archive)
7382 (org-agenda-archive-with org-archive-default-command 'confirm))
7384 (defun org-agenda-archive ()
7385 "Archive the entry or subtree belonging to the current agenda entry."
7386 (interactive)
7387 (org-agenda-archive-with 'org-archive-subtree))
7389 (defun org-agenda-archive-to-archive-sibling ()
7390 "Move the entry to the archive sibling."
7391 (interactive)
7392 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7394 (defun org-agenda-archive-with (cmd &optional confirm)
7395 "Move the entry to the archive sibling."
7396 (interactive)
7397 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7398 (let* ((marker (or (org-get-at-bol 'org-marker)
7399 (org-agenda-error)))
7400 (buffer (marker-buffer marker))
7401 (pos (marker-position marker)))
7402 (org-with-remote-undo buffer
7403 (with-current-buffer buffer
7404 (if (derived-mode-p 'org-mode)
7405 (if (and confirm
7406 (not (y-or-n-p "Archive this subtree or entry? ")))
7407 (error "Abort")
7408 (save-excursion
7409 (goto-char pos)
7410 (org-remove-subtree-entries-from-agenda)
7411 (org-back-to-heading t)
7412 (funcall cmd)))
7413 (error "Archiving works only in Org-mode files"))))))
7415 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7416 "Remove all lines in the agenda that correspond to a given subtree.
7417 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7418 If this information is not given, the function uses the tree at point."
7419 (let ((buf (or buf (current-buffer))) m p)
7420 (save-excursion
7421 (unless (and beg end)
7422 (org-back-to-heading t)
7423 (setq beg (point))
7424 (org-end-of-subtree t)
7425 (setq end (point)))
7426 (set-buffer (get-buffer org-agenda-buffer-name))
7427 (save-excursion
7428 (goto-char (point-max))
7429 (beginning-of-line 1)
7430 (while (not (bobp))
7431 (when (and (setq m (org-get-at-bol 'org-marker))
7432 (equal buf (marker-buffer m))
7433 (setq p (marker-position m))
7434 (>= p beg)
7435 (< p end))
7436 (let ((inhibit-read-only t))
7437 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7438 (beginning-of-line 0))))))
7440 (defun org-agenda-refile (&optional goto rfloc no-update)
7441 "Refile the item at point."
7442 (interactive "P")
7443 (if (equal goto '(16))
7444 (org-refile-goto-last-stored)
7445 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7446 (org-agenda-error)))
7447 (buffer (marker-buffer marker))
7448 (pos (marker-position marker))
7449 (rfloc (or rfloc
7450 (org-refile-get-location
7451 (if goto "Goto" "Refile to") buffer
7452 org-refile-allow-creating-parent-nodes))))
7453 (with-current-buffer buffer
7454 (save-excursion
7455 (save-restriction
7456 (widen)
7457 (goto-char marker)
7458 (org-remove-subtree-entries-from-agenda)
7459 (org-refile goto buffer rfloc)))))
7460 (unless no-update (org-agenda-redo))))
7462 (defun org-agenda-open-link (&optional arg)
7463 "Follow the link in the current line, if any.
7464 This looks for a link in the displayed line in the agenda. It also looks
7465 at the text of the entry itself."
7466 (interactive "P")
7467 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7468 (org-get-at-bol 'org-marker)))
7469 (buffer (and marker (marker-buffer marker)))
7470 (prefix (buffer-substring
7471 (point-at-bol) (point-at-eol))))
7472 (cond
7473 (buffer
7474 (with-current-buffer buffer
7475 (save-excursion
7476 (save-restriction
7477 (widen)
7478 (goto-char marker)
7479 (org-offer-links-in-entry arg prefix)))))
7480 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7481 (save-excursion
7482 (beginning-of-line 1)
7483 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7484 (org-open-link-from-string (match-string 1)))
7485 (t (error "No link to open here")))))
7487 (defun org-agenda-copy-local-variable (var)
7488 "Get a variable from a referenced buffer and install it here."
7489 (let ((m (org-get-at-bol 'org-marker)))
7490 (when (and m (buffer-live-p (marker-buffer m)))
7491 (org-set-local var (with-current-buffer (marker-buffer m)
7492 (symbol-value var))))))
7494 (defun org-agenda-switch-to (&optional delete-other-windows)
7495 "Go to the Org-mode file which contains the item at point."
7496 (interactive)
7497 (if (and org-return-follows-link
7498 (not (org-get-at-bol 'org-marker))
7499 (org-in-regexp org-bracket-link-regexp))
7500 (org-open-link-from-string (match-string 0))
7501 (let* ((marker (or (org-get-at-bol 'org-marker)
7502 (org-agenda-error)))
7503 (buffer (marker-buffer marker))
7504 (pos (marker-position marker)))
7505 (org-pop-to-buffer-same-window buffer)
7506 (and delete-other-windows (delete-other-windows))
7507 (widen)
7508 (goto-char pos)
7509 (when (derived-mode-p 'org-mode)
7510 (org-show-context 'agenda)
7511 (save-excursion
7512 (and (outline-next-heading)
7513 (org-flag-heading nil))) ; show the next heading
7514 (when (outline-invisible-p)
7515 (show-entry)))))) ; display invisible text
7517 (defun org-agenda-goto-mouse (ev)
7518 "Go to the Org-mode file which contains the item at the mouse click."
7519 (interactive "e")
7520 (mouse-set-point ev)
7521 (org-agenda-goto))
7523 (defun org-agenda-show (&optional full-entry)
7524 "Display the Org-mode file which contains the item at point.
7525 With prefix argument FULL-ENTRY, make the entire entry visible
7526 if it was hidden in the outline."
7527 (interactive "P")
7528 (let ((win (selected-window)))
7529 (if full-entry
7530 (let ((org-show-entry-below t))
7531 (org-agenda-goto t))
7532 (org-agenda-goto t))
7533 (select-window win)))
7535 (defvar org-agenda-show-window nil)
7536 (defun org-agenda-show-and-scroll-up (&optional arg)
7537 "Display the Org-mode file which contains the item at point.
7538 When called repeatedly, scroll the window that is displaying the buffer.
7539 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7540 `show-subtree' to display the item, so that drawers and logbooks stay
7541 folded."
7542 (interactive "P")
7543 (let ((win (selected-window)))
7544 (if (and (window-live-p org-agenda-show-window)
7545 (eq this-command last-command))
7546 (progn
7547 (select-window org-agenda-show-window)
7548 (ignore-errors (scroll-up)))
7549 (org-agenda-goto t)
7550 (if arg (org-show-entry) (show-subtree))
7551 (setq org-agenda-show-window (selected-window)))
7552 (select-window win)))
7554 (defun org-agenda-show-scroll-down ()
7555 "Scroll down the window showing the agenda."
7556 (interactive)
7557 (let ((win (selected-window)))
7558 (when (window-live-p org-agenda-show-window)
7559 (select-window org-agenda-show-window)
7560 (ignore-errors (scroll-down))
7561 (select-window win))))
7563 (defun org-agenda-show-1 (&optional more)
7564 "Display the Org-mode file which contains the item at point.
7565 The prefix arg selects the amount of information to display:
7567 0 hide the subtree
7568 1 just show the entry according to defaults.
7569 2 show the children view
7570 3 show the subtree view
7571 4 show the entire subtree and any LOGBOOK drawers
7572 5 show the entire subtree and any drawers
7573 With prefix argument FULL-ENTRY, make the entire entry visible
7574 if it was hidden in the outline."
7575 (interactive "p")
7576 (let ((win (selected-window)))
7577 (org-agenda-goto t)
7578 (org-recenter-heading 1)
7579 (cond
7580 ((= more 0)
7581 (hide-subtree)
7582 (save-excursion
7583 (org-back-to-heading)
7584 (run-hook-with-args 'org-cycle-hook 'folded))
7585 (message "Remote: FOLDED"))
7586 ((and (org-called-interactively-p 'any) (= more 1))
7587 (message "Remote: show with default settings"))
7588 ((= more 2)
7589 (show-entry)
7590 (show-children)
7591 (save-excursion
7592 (org-back-to-heading)
7593 (run-hook-with-args 'org-cycle-hook 'children))
7594 (message "Remote: CHILDREN"))
7595 ((= more 3)
7596 (show-subtree)
7597 (save-excursion
7598 (org-back-to-heading)
7599 (run-hook-with-args 'org-cycle-hook 'subtree))
7600 (message "Remote: SUBTREE"))
7601 ((= more 4)
7602 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7603 (org-drawer-regexp
7604 (concat "^[ \t]*:\\("
7605 (mapconcat 'regexp-quote org-drawers "\\|")
7606 "\\):[ \t]*$")))
7607 (show-subtree)
7608 (save-excursion
7609 (org-back-to-heading)
7610 (org-cycle-hide-drawers 'subtree)))
7611 (message "Remote: SUBTREE AND LOGBOOK"))
7612 ((> more 4)
7613 (show-subtree)
7614 (message "Remote: SUBTREE AND ALL DRAWERS")))
7615 (select-window win)))
7617 (defun org-recenter-heading (n)
7618 (save-excursion
7619 (org-back-to-heading)
7620 (recenter n)))
7622 (defvar org-agenda-cycle-counter nil)
7623 (defun org-agenda-cycle-show (&optional n)
7624 "Show the current entry in another window, with default settings.
7625 Default settings are taken from `org-show-hierarchy-above' and siblings.
7626 When use repeatedly in immediate succession, the remote entry will cycle
7627 through visibility
7629 children -> subtree -> folded
7631 When called with a numeric prefix arg, that arg will be passed through to
7632 `org-agenda-show-1'. For the interpretation of that argument, see the
7633 docstring of `org-agenda-show-1'."
7634 (interactive "P")
7635 (if (integerp n)
7636 (setq org-agenda-cycle-counter n)
7637 (if (not (eq last-command this-command))
7638 (setq org-agenda-cycle-counter 1)
7639 (if (equal org-agenda-cycle-counter 0)
7640 (setq org-agenda-cycle-counter 2)
7641 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7642 (if (> org-agenda-cycle-counter 3)
7643 (setq org-agenda-cycle-counter 0)))))
7644 (org-agenda-show-1 org-agenda-cycle-counter))
7646 (defun org-agenda-recenter (arg)
7647 "Display the Org-mode file which contains the item at point and recenter."
7648 (interactive "P")
7649 (let ((win (selected-window)))
7650 (org-agenda-goto t)
7651 (recenter arg)
7652 (select-window win)))
7654 (defun org-agenda-show-mouse (ev)
7655 "Display the Org-mode file which contains the item at the mouse click."
7656 (interactive "e")
7657 (mouse-set-point ev)
7658 (org-agenda-show))
7660 (defun org-agenda-check-no-diary ()
7661 "Check if the entry is a diary link and abort if yes."
7662 (if (org-get-at-bol 'org-agenda-diary-link)
7663 (org-agenda-error)))
7665 (defun org-agenda-error ()
7666 (error "Command not allowed in this line"))
7668 (defun org-agenda-tree-to-indirect-buffer ()
7669 "Show the subtree corresponding to the current entry in an indirect buffer.
7670 This calls the command `org-tree-to-indirect-buffer' from the original
7671 Org-mode buffer.
7672 With numerical prefix arg ARG, go up to this level and then take that tree.
7673 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7674 use the dedicated frame)."
7675 (interactive)
7676 (if (and current-prefix-arg (listp current-prefix-arg))
7677 (org-agenda-do-tree-to-indirect-buffer)
7678 (let ((agenda-window (selected-window))
7679 (indirect-window
7680 (and org-last-indirect-buffer
7681 (get-buffer-window org-last-indirect-buffer))))
7682 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7683 (unwind-protect
7684 (progn
7685 (unless (and indirect-window (window-live-p indirect-window))
7686 (setq indirect-window (split-window agenda-window)))
7687 (select-window indirect-window)
7688 (switch-to-buffer org-last-indirect-buffer :norecord)
7689 (fit-window-to-buffer indirect-window))
7690 (select-window (get-buffer-window org-agenda-buffer-name))))))
7692 (defun org-agenda-do-tree-to-indirect-buffer ()
7693 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7694 (org-agenda-check-no-diary)
7695 (let* ((marker (or (org-get-at-bol 'org-marker)
7696 (org-agenda-error)))
7697 (buffer (marker-buffer marker))
7698 (pos (marker-position marker)))
7699 (with-current-buffer buffer
7700 (save-excursion
7701 (goto-char pos)
7702 (call-interactively 'org-tree-to-indirect-buffer)))))
7704 (defvar org-last-heading-marker (make-marker)
7705 "Marker pointing to the headline that last changed its TODO state
7706 by a remote command from the agenda.")
7708 (defun org-agenda-todo-nextset ()
7709 "Switch TODO entry to next sequence."
7710 (interactive)
7711 (org-agenda-todo 'nextset))
7713 (defun org-agenda-todo-previousset ()
7714 "Switch TODO entry to previous sequence."
7715 (interactive)
7716 (org-agenda-todo 'previousset))
7718 (defun org-agenda-todo (&optional arg)
7719 "Cycle TODO state of line at point, also in Org-mode file.
7720 This changes the line at point, all other lines in the agenda referring to
7721 the same tree node, and the headline of the tree node in the Org-mode file."
7722 (interactive "P")
7723 (org-agenda-check-no-diary)
7724 (let* ((col (current-column))
7725 (marker (or (org-get-at-bol 'org-marker)
7726 (org-agenda-error)))
7727 (buffer (marker-buffer marker))
7728 (pos (marker-position marker))
7729 (hdmarker (org-get-at-bol 'org-hd-marker))
7730 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7731 (inhibit-read-only t)
7732 org-agenda-headline-snapshot-before-repeat newhead just-one)
7733 (org-with-remote-undo buffer
7734 (with-current-buffer buffer
7735 (widen)
7736 (goto-char pos)
7737 (org-show-context 'agenda)
7738 (save-excursion
7739 (and (outline-next-heading)
7740 (org-flag-heading nil))) ; show the next heading
7741 (let ((current-prefix-arg arg))
7742 (call-interactively 'org-todo))
7743 (and (bolp) (forward-char 1))
7744 (setq newhead (org-get-heading))
7745 (when (and (org-bound-and-true-p
7746 org-agenda-headline-snapshot-before-repeat)
7747 (not (equal org-agenda-headline-snapshot-before-repeat
7748 newhead))
7749 todayp)
7750 (setq newhead org-agenda-headline-snapshot-before-repeat
7751 just-one t))
7752 (save-excursion
7753 (org-back-to-heading)
7754 (move-marker org-last-heading-marker (point))))
7755 (beginning-of-line 1)
7756 (save-excursion
7757 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7758 (org-move-to-column col))))
7760 (defun org-agenda-add-note (&optional arg)
7761 "Add a time-stamped note to the entry at point."
7762 (interactive "P")
7763 (org-agenda-check-no-diary)
7764 (let* ((marker (or (org-get-at-bol 'org-marker)
7765 (org-agenda-error)))
7766 (buffer (marker-buffer marker))
7767 (pos (marker-position marker))
7768 (hdmarker (org-get-at-bol 'org-hd-marker))
7769 (inhibit-read-only t))
7770 (with-current-buffer buffer
7771 (widen)
7772 (goto-char pos)
7773 (org-show-context 'agenda)
7774 (save-excursion
7775 (and (outline-next-heading)
7776 (org-flag-heading nil))) ; show the next heading
7777 (org-add-note))))
7779 (defun org-agenda-change-all-lines (newhead hdmarker
7780 &optional fixface just-this)
7781 "Change all lines in the agenda buffer which match HDMARKER.
7782 The new content of the line will be NEWHEAD (as modified by
7783 `org-agenda-format-item'). HDMARKER is checked with
7784 `equal' against all `org-hd-marker' text properties in the file.
7785 If FIXFACE is non-nil, the face of each item is modified according to
7786 the new TODO state.
7787 If JUST-THIS is non-nil, change just the current line, not all.
7788 If FORCE-TAGS is non nil, the car of it returns the new tags."
7789 (let* ((inhibit-read-only t)
7790 (line (org-current-line))
7791 (org-agenda-buffer (current-buffer))
7792 (thetags (with-current-buffer (marker-buffer hdmarker)
7793 (save-excursion (save-restriction (widen)
7794 (goto-char hdmarker)
7795 (org-get-tags-at)))))
7796 props m pl undone-face done-face finish new dotime cat tags)
7797 (save-excursion
7798 (goto-char (point-max))
7799 (beginning-of-line 1)
7800 (while (not finish)
7801 (setq finish (bobp))
7802 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7803 (or (not just-this) (= (org-current-line) line))
7804 (equal m hdmarker))
7805 (setq props (text-properties-at (point))
7806 dotime (org-get-at-bol 'dotime)
7807 cat (org-get-at-bol 'org-category)
7808 tags thetags
7810 (let ((org-prefix-format-compiled
7811 (or (get-text-property (point) 'format)
7812 org-prefix-format-compiled))
7813 (extra (org-get-at-bol 'extra)))
7814 (with-current-buffer (marker-buffer hdmarker)
7815 (save-excursion
7816 (save-restriction
7817 (widen)
7818 (org-agenda-format-item extra newhead cat tags dotime)))))
7819 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7820 undone-face (org-get-at-bol 'undone-face)
7821 done-face (org-get-at-bol 'done-face))
7822 (beginning-of-line 1)
7823 (cond
7824 ((equal new "")
7825 (and (looking-at ".*\n?") (replace-match "")))
7826 ((looking-at ".*")
7827 (replace-match new t t)
7828 (beginning-of-line 1)
7829 (add-text-properties (point-at-bol) (point-at-eol) props)
7830 (when fixface
7831 (add-text-properties
7832 (point-at-bol) (point-at-eol)
7833 (list 'face
7834 (if org-last-todo-state-is-todo
7835 undone-face done-face))))
7836 (org-agenda-highlight-todo 'line)
7837 (beginning-of-line 1))
7838 (t (error "Line update did not work"))))
7839 (beginning-of-line 0)))
7840 (org-finalize-agenda)))
7842 (defun org-agenda-align-tags (&optional line)
7843 "Align all tags in agenda items to `org-agenda-tags-column'."
7844 (let ((inhibit-read-only t) l c)
7845 (save-excursion
7846 (goto-char (if line (point-at-bol) (point-min)))
7847 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7848 (if line (point-at-eol) nil) t)
7849 (add-text-properties
7850 (match-beginning 2) (match-end 2)
7851 (list 'face (delq nil (let ((prop (get-text-property
7852 (match-beginning 2) 'face)))
7853 (or (listp prop) (setq prop (list prop)))
7854 (if (memq 'org-tag prop)
7855 prop
7856 (cons 'org-tag prop))))))
7857 (setq l (- (match-end 2) (match-beginning 2))
7858 c (if (< org-agenda-tags-column 0)
7859 (- (abs org-agenda-tags-column) l)
7860 org-agenda-tags-column))
7861 (delete-region (match-beginning 1) (match-end 1))
7862 (goto-char (match-beginning 1))
7863 (insert (org-add-props
7864 (make-string (max 1 (- c (current-column))) ?\ )
7865 (plist-put (copy-sequence (text-properties-at (point)))
7866 'face nil))))
7867 (goto-char (point-min))
7868 (org-font-lock-add-tag-faces (point-max)))))
7870 (defun org-agenda-priority-up ()
7871 "Increase the priority of line at point, also in Org-mode file."
7872 (interactive)
7873 (org-agenda-priority 'up))
7875 (defun org-agenda-priority-down ()
7876 "Decrease the priority of line at point, also in Org-mode file."
7877 (interactive)
7878 (org-agenda-priority 'down))
7880 (defun org-agenda-priority (&optional force-direction)
7881 "Set the priority of line at point, also in Org-mode file.
7882 This changes the line at point, all other lines in the agenda referring to
7883 the same tree node, and the headline of the tree node in the Org-mode file."
7884 (interactive)
7885 (unless org-enable-priority-commands
7886 (error "Priority commands are disabled"))
7887 (org-agenda-check-no-diary)
7888 (let* ((marker (or (org-get-at-bol 'org-marker)
7889 (org-agenda-error)))
7890 (hdmarker (org-get-at-bol 'org-hd-marker))
7891 (buffer (marker-buffer hdmarker))
7892 (pos (marker-position hdmarker))
7893 (inhibit-read-only t)
7894 newhead)
7895 (org-with-remote-undo buffer
7896 (with-current-buffer buffer
7897 (widen)
7898 (goto-char pos)
7899 (org-show-context 'agenda)
7900 (save-excursion
7901 (and (outline-next-heading)
7902 (org-flag-heading nil))) ; show the next heading
7903 (funcall 'org-priority force-direction)
7904 (end-of-line 1)
7905 (setq newhead (org-get-heading)))
7906 (org-agenda-change-all-lines newhead hdmarker)
7907 (beginning-of-line 1))))
7909 ;; FIXME: should fix the tags property of the agenda line.
7910 (defun org-agenda-set-tags (&optional tag onoff)
7911 "Set tags for the current headline."
7912 (interactive)
7913 (org-agenda-check-no-diary)
7914 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7915 (call-interactively 'org-change-tag-in-region)
7916 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7917 (org-agenda-error)))
7918 (buffer (marker-buffer hdmarker))
7919 (pos (marker-position hdmarker))
7920 (inhibit-read-only t)
7921 newhead)
7922 (org-with-remote-undo buffer
7923 (with-current-buffer buffer
7924 (widen)
7925 (goto-char pos)
7926 (save-excursion
7927 (org-show-context 'agenda))
7928 (save-excursion
7929 (and (outline-next-heading)
7930 (org-flag-heading nil))) ; show the next heading
7931 (goto-char pos)
7932 (if tag
7933 (org-toggle-tag tag onoff)
7934 (call-interactively 'org-set-tags))
7935 (end-of-line 1)
7936 (setq newhead (org-get-heading)))
7937 (org-agenda-change-all-lines newhead hdmarker)
7938 (beginning-of-line 1)))))
7940 (defun org-agenda-set-property ()
7941 "Set a property for the current headline."
7942 (interactive)
7943 (org-agenda-check-no-diary)
7944 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7945 (org-agenda-error)))
7946 (buffer (marker-buffer hdmarker))
7947 (pos (marker-position hdmarker))
7948 (inhibit-read-only t)
7949 newhead)
7950 (org-with-remote-undo buffer
7951 (with-current-buffer buffer
7952 (widen)
7953 (goto-char pos)
7954 (save-excursion
7955 (org-show-context 'agenda))
7956 (save-excursion
7957 (and (outline-next-heading)
7958 (org-flag-heading nil))) ; show the next heading
7959 (goto-char pos)
7960 (call-interactively 'org-set-property)))))
7962 (defun org-agenda-set-effort ()
7963 "Set the effort property for the current headline."
7964 (interactive)
7965 (org-agenda-check-no-diary)
7966 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7967 (org-agenda-error)))
7968 (buffer (marker-buffer hdmarker))
7969 (pos (marker-position hdmarker))
7970 (inhibit-read-only t)
7971 newhead)
7972 (org-with-remote-undo buffer
7973 (with-current-buffer buffer
7974 (widen)
7975 (goto-char pos)
7976 (save-excursion
7977 (org-show-context 'agenda))
7978 (save-excursion
7979 (and (outline-next-heading)
7980 (org-flag-heading nil))) ; show the next heading
7981 (goto-char pos)
7982 (call-interactively 'org-set-effort)
7983 (end-of-line 1)
7984 (setq newhead (org-get-heading)))
7985 (org-agenda-change-all-lines newhead hdmarker))))
7987 (defun org-agenda-toggle-archive-tag ()
7988 "Toggle the archive tag for the current entry."
7989 (interactive)
7990 (org-agenda-check-no-diary)
7991 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7992 (org-agenda-error)))
7993 (buffer (marker-buffer hdmarker))
7994 (pos (marker-position hdmarker))
7995 (inhibit-read-only t)
7996 newhead)
7997 (org-with-remote-undo buffer
7998 (with-current-buffer buffer
7999 (widen)
8000 (goto-char pos)
8001 (org-show-context 'agenda)
8002 (save-excursion
8003 (and (outline-next-heading)
8004 (org-flag-heading nil))) ; show the next heading
8005 (call-interactively 'org-toggle-archive-tag)
8006 (end-of-line 1)
8007 (setq newhead (org-get-heading)))
8008 (org-agenda-change-all-lines newhead hdmarker)
8009 (beginning-of-line 1))))
8011 (defun org-agenda-do-date-later (arg)
8012 (interactive "P")
8013 (cond
8014 ((or (equal arg '(16))
8015 (memq last-command
8016 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8017 (setq this-command 'org-agenda-date-later-minutes)
8018 (org-agenda-date-later-minutes 1))
8019 ((or (equal arg '(4))
8020 (memq last-command
8021 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8022 (setq this-command 'org-agenda-date-later-hours)
8023 (org-agenda-date-later-hours 1))
8025 (org-agenda-date-later (prefix-numeric-value arg)))))
8027 (defun org-agenda-do-date-earlier (arg)
8028 (interactive "P")
8029 (cond
8030 ((or (equal arg '(16))
8031 (memq last-command
8032 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8033 (setq this-command 'org-agenda-date-earlier-minutes)
8034 (org-agenda-date-earlier-minutes 1))
8035 ((or (equal arg '(4))
8036 (memq last-command
8037 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8038 (setq this-command 'org-agenda-date-earlier-hours)
8039 (org-agenda-date-earlier-hours 1))
8041 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8043 (defun org-agenda-date-later (arg &optional what)
8044 "Change the date of this item to ARG day(s) later."
8045 (interactive "p")
8046 (org-agenda-check-type t 'agenda 'timeline)
8047 (org-agenda-check-no-diary)
8048 (let* ((marker (or (org-get-at-bol 'org-marker)
8049 (org-agenda-error)))
8050 (buffer (marker-buffer marker))
8051 (pos (marker-position marker))
8052 cdate today)
8053 (org-with-remote-undo buffer
8054 (with-current-buffer buffer
8055 (widen)
8056 (goto-char pos)
8057 (if (not (org-at-timestamp-p))
8058 (error "Cannot find time stamp"))
8059 (when (and org-agenda-move-date-from-past-immediately-to-today
8060 (equal arg 1)
8061 (or (not what) (eq what 'day))
8062 (not (save-match-data (org-at-date-range-p))))
8063 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8064 cdate (calendar-absolute-from-gregorian
8065 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8066 today (org-today))
8067 (if (> today cdate)
8068 ;; immediately shift to today
8069 (setq arg (- today cdate))))
8070 (org-timestamp-change arg (or what 'day))
8071 (when (and (org-at-date-range-p)
8072 (re-search-backward org-tr-regexp-both (point-at-bol)))
8073 (let ((end org-last-changed-timestamp))
8074 (org-timestamp-change arg (or what 'day))
8075 (setq org-last-changed-timestamp
8076 (concat org-last-changed-timestamp "--" end)))))
8077 (org-agenda-show-new-time marker org-last-changed-timestamp))
8078 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8080 (defun org-agenda-date-earlier (arg &optional what)
8081 "Change the date of this item to ARG day(s) earlier."
8082 (interactive "p")
8083 (org-agenda-date-later (- arg) what))
8085 (defun org-agenda-date-later-minutes (arg)
8086 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8087 (interactive "p")
8088 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8089 (org-agenda-date-later arg 'minute))
8091 (defun org-agenda-date-earlier-minutes (arg)
8092 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8093 (interactive "p")
8094 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8095 (org-agenda-date-earlier arg 'minute))
8097 (defun org-agenda-date-later-hours (arg)
8098 "Change the time of this item, in hour steps."
8099 (interactive "p")
8100 (org-agenda-date-later arg 'hour))
8102 (defun org-agenda-date-earlier-hours (arg)
8103 "Change the time of this item, in hour steps."
8104 (interactive "p")
8105 (org-agenda-date-earlier arg 'hour))
8107 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8108 "Show new date stamp via text properties."
8109 ;; We use text properties to make this undoable
8110 (let ((inhibit-read-only t)
8111 (buffer-invisibility-spec))
8112 (setq stamp (concat " " prefix " => " stamp))
8113 (save-excursion
8114 (goto-char (point-max))
8115 (while (not (bobp))
8116 (when (equal marker (org-get-at-bol 'org-marker))
8117 (org-move-to-column (- (window-width) (length stamp)) t)
8118 (org-agenda-fix-tags-filter-overlays-at (point))
8119 (if (featurep 'xemacs)
8120 ;; Use `duplicable' property to trigger undo recording
8121 (let ((ex (make-extent nil nil))
8122 (gl (make-glyph stamp)))
8123 (set-glyph-face gl 'secondary-selection)
8124 (set-extent-properties
8125 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8126 (insert-extent ex (1- (point)) (point-at-eol)))
8127 (add-text-properties
8128 (1- (point)) (point-at-eol)
8129 (list 'display (org-add-props stamp nil
8130 'face 'secondary-selection))))
8131 (beginning-of-line 1))
8132 (beginning-of-line 0)))))
8134 (defun org-agenda-date-prompt (arg)
8135 "Change the date of this item. Date is prompted for, with default today.
8136 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8137 be used to request time specification in the time stamp."
8138 (interactive "P")
8139 (org-agenda-check-type t 'agenda 'timeline)
8140 (org-agenda-check-no-diary)
8141 (let* ((marker (or (org-get-at-bol 'org-marker)
8142 (org-agenda-error)))
8143 (buffer (marker-buffer marker))
8144 (pos (marker-position marker)))
8145 (org-with-remote-undo buffer
8146 (with-current-buffer buffer
8147 (widen)
8148 (goto-char pos)
8149 (if (not (org-at-timestamp-p t))
8150 (error "Cannot find time stamp"))
8151 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8152 (org-agenda-show-new-time marker org-last-changed-timestamp))
8153 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8155 (defun org-agenda-schedule (arg &optional time)
8156 "Schedule the item at point.
8157 ARG is passed through to `org-schedule'."
8158 (interactive "P")
8159 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8160 (org-agenda-check-no-diary)
8161 (let* ((marker (or (org-get-at-bol 'org-marker)
8162 (org-agenda-error)))
8163 (type (marker-insertion-type marker))
8164 (buffer (marker-buffer marker))
8165 (pos (marker-position marker))
8166 (org-insert-labeled-timestamps-at-point nil)
8168 (set-marker-insertion-type marker t)
8169 (org-with-remote-undo buffer
8170 (with-current-buffer buffer
8171 (widen)
8172 (goto-char pos)
8173 (setq ts (org-schedule arg time)))
8174 (org-agenda-show-new-time marker ts "S"))
8175 (message "Item scheduled for %s" ts)))
8177 (defun org-agenda-deadline (arg &optional time)
8178 "Schedule the item at point.
8179 ARG is passed through to `org-deadline'."
8180 (interactive "P")
8181 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8182 (org-agenda-check-no-diary)
8183 (let* ((marker (or (org-get-at-bol 'org-marker)
8184 (org-agenda-error)))
8185 (buffer (marker-buffer marker))
8186 (pos (marker-position marker))
8187 (org-insert-labeled-timestamps-at-point nil)
8189 (org-with-remote-undo buffer
8190 (with-current-buffer buffer
8191 (widen)
8192 (goto-char pos)
8193 (setq ts (org-deadline arg time)))
8194 (org-agenda-show-new-time marker ts "D"))
8195 (message "Deadline for this item set to %s" ts)))
8197 (defun org-agenda-action ()
8198 "Select entry for agenda action, or execute an agenda action.
8199 This command prompts for another letter. Valid inputs are:
8201 m Mark the entry at point for an agenda action
8202 s Schedule the marked entry to the date at the cursor
8203 d Set the deadline of the marked entry to the date at the cursor
8204 r Call `org-remember' with cursor date as the default date
8205 c Call `org-capture' with cursor date as the default date
8206 SPC Show marked entry in other window
8207 TAB Visit marked entry in other window
8209 The cursor may be at a date in the calendar, or in the Org agenda."
8210 (interactive)
8211 (let (ans)
8212 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8213 (setq ans (read-char-exclusive))
8214 (cond
8215 ((equal ans ?m)
8216 ;; Mark this entry
8217 (if (eq major-mode 'org-agenda-mode)
8218 (let ((m (or (org-get-at-bol 'org-hd-marker)
8219 (org-get-at-bol 'org-marker))))
8220 (if m
8221 (progn
8222 (move-marker org-agenda-action-marker
8223 (marker-position m) (marker-buffer m))
8224 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8225 (error "Don't know which entry to mark")))
8226 (error "This command works only in the agenda")))
8227 ((equal ans ?s)
8228 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8229 ((equal ans ?d)
8230 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8231 ((equal ans ?r)
8232 (org-agenda-do-action '(org-remember) t))
8233 ((equal ans ?c)
8234 (org-agenda-do-action '(org-capture) t))
8235 ((equal ans ?\ )
8236 (let ((cw (selected-window)))
8237 (org-switch-to-buffer-other-window
8238 (marker-buffer org-agenda-action-marker))
8239 (goto-char org-agenda-action-marker)
8240 (org-show-context 'agenda)
8241 (select-window cw)))
8242 ((equal ans ?\C-i)
8243 (org-switch-to-buffer-other-window
8244 (marker-buffer org-agenda-action-marker))
8245 (goto-char org-agenda-action-marker)
8246 (org-show-context 'agenda))
8247 (t (error "Invalid agenda action %c" ans)))))
8249 (defun org-agenda-do-action (form &optional current-buffer)
8250 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8251 (let ((org-overriding-default-time (org-get-cursor-date)))
8252 (if current-buffer
8253 (eval form)
8254 (if (not (marker-buffer org-agenda-action-marker))
8255 (error "No entry has been selected for agenda action")
8256 (with-current-buffer (marker-buffer org-agenda-action-marker)
8257 (save-excursion
8258 (save-restriction
8259 (widen)
8260 (goto-char org-agenda-action-marker)
8261 (eval form))))))))
8263 (defun org-agenda-clock-in (&optional arg)
8264 "Start the clock on the currently selected item."
8265 (interactive "P")
8266 (org-agenda-check-no-diary)
8267 (if (equal arg '(4))
8268 (org-clock-in arg)
8269 (let* ((marker (or (org-get-at-bol 'org-marker)
8270 (org-agenda-error)))
8271 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8272 marker))
8273 (pos (marker-position marker))
8274 newhead)
8275 (org-with-remote-undo (marker-buffer marker)
8276 (with-current-buffer (marker-buffer marker)
8277 (widen)
8278 (goto-char pos)
8279 (org-show-context 'agenda)
8280 (org-show-entry)
8281 (org-cycle-hide-drawers 'children)
8282 (org-clock-in arg)
8283 (setq newhead (org-get-heading)))
8284 (org-agenda-change-all-lines newhead hdmarker)))))
8286 (defun org-agenda-clock-out ()
8287 "Stop the currently running clock."
8288 (interactive)
8289 (unless (marker-buffer org-clock-marker)
8290 (error "No running clock"))
8291 (let ((marker (make-marker)) newhead)
8292 (org-with-remote-undo (marker-buffer org-clock-marker)
8293 (with-current-buffer (marker-buffer org-clock-marker)
8294 (save-excursion
8295 (save-restriction
8296 (widen)
8297 (goto-char org-clock-marker)
8298 (org-back-to-heading t)
8299 (move-marker marker (point))
8300 (org-clock-out)
8301 (setq newhead (org-get-heading))))))
8302 (org-agenda-change-all-lines newhead marker)
8303 (move-marker marker nil)))
8305 (defun org-agenda-clock-cancel (&optional arg)
8306 "Cancel the currently running clock."
8307 (interactive "P")
8308 (unless (marker-buffer org-clock-marker)
8309 (error "No running clock"))
8310 (org-with-remote-undo (marker-buffer org-clock-marker)
8311 (org-clock-cancel)))
8313 (defun org-agenda-clock-goto ()
8314 "Jump to the currently clocked in task within the agenda.
8315 If the currently clocked in task is not listed in the agenda
8316 buffer, display it in another window."
8317 (interactive)
8318 (let (pos)
8319 (mapc (lambda (o)
8320 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8321 (setq pos (overlay-start o))))
8322 (overlays-in (point-min) (point-max)))
8323 (cond (pos (goto-char pos))
8324 ;; If the currently clocked entry is not in the agenda
8325 ;; buffer, we visit it in another window:
8326 (org-clock-current-task
8327 (org-switch-to-buffer-other-window (org-clock-goto)))
8328 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8330 (defun org-agenda-diary-entry-in-org-file ()
8331 "Make a diary entry in the file `org-agenda-diary-file'."
8332 (let (d1 d2 char (text "") dp1 dp2)
8333 (if (equal (buffer-name) "*Calendar*")
8334 (setq d1 (calendar-cursor-to-date t)
8335 d2 (car calendar-mark-ring))
8336 (setq dp1 (get-text-property (point-at-bol) 'day))
8337 (unless dp1 (error "No date defined in current line"))
8338 (setq d1 (calendar-gregorian-from-absolute dp1)
8339 d2 (and (ignore-errors (mark))
8340 (save-excursion
8341 (goto-char (mark))
8342 (setq dp2 (get-text-property (point-at-bol) 'day)))
8343 (calendar-gregorian-from-absolute dp2))))
8344 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8345 (setq char (read-char-exclusive))
8346 (cond
8347 ((equal char ?d)
8348 (setq text (read-string "Day entry: "))
8349 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8350 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8351 ((equal char ?a)
8352 (setq d1 (list (car d1) (nth 1 d1)
8353 (read-number (format "Reference year [%d]: " (nth 2 d1))
8354 (nth 2 d1))))
8355 (setq text (read-string "Anniversary (use %d to show years): "))
8356 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8357 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8358 ((equal char ?b)
8359 (setq text (read-string "Block entry: "))
8360 (unless (and d1 d2 (not (equal d1 d2)))
8361 (error "No block of days selected"))
8362 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8363 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8364 ((equal char ?j)
8365 (org-switch-to-buffer-other-window
8366 (find-file-noselect org-agenda-diary-file))
8367 (require 'org-datetree)
8368 (org-datetree-find-date-create d1)
8369 (org-reveal t))
8370 (t (error "Invalid selection character `%c'" char)))))
8372 (defcustom org-agenda-insert-diary-strategy 'date-tree
8373 "Where in `org-agenda-diary-file' should new entries be added?
8374 Valid values:
8376 date-tree in the date tree, as child of the date
8377 top-level as top-level entries at the end of the file."
8378 :group 'org-agenda
8379 :type '(choice
8380 (const :tag "in a date tree" date-tree)
8381 (const :tag "as top level at end of file" top-level)))
8383 (defcustom org-agenda-insert-diary-extract-time nil
8384 "Non-nil means extract any time specification from the diary entry."
8385 :group 'org-agenda
8386 :version "24.1"
8387 :type 'boolean)
8389 (defcustom org-agenda-bulk-mark-char ">"
8390 "A single-character string to be used as the bulk mark."
8391 :group 'org-agenda
8392 :version "24.1"
8393 :type 'string)
8395 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8396 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8397 If TEXT is not empty, it will become the headline of the new entry, and
8398 the resulting entry will not be shown. When TEXT is empty, switch to
8399 `org-agenda-diary-file' and let the user finish the entry there."
8400 (let ((cw (current-window-configuration)))
8401 (org-switch-to-buffer-other-window
8402 (find-file-noselect org-agenda-diary-file))
8403 (widen)
8404 (goto-char (point-min))
8405 (cond
8406 ((eq type 'anniversary)
8407 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8408 (progn
8409 (or (org-at-heading-p t)
8410 (progn
8411 (outline-next-heading)
8412 (insert "* Anniversaries\n\n")
8413 (beginning-of-line -1)))))
8414 (outline-next-heading)
8415 (org-back-over-empty-lines)
8416 (backward-char 1)
8417 (insert "\n")
8418 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8419 (nth 2 d1) (car d1) (nth 1 d1) text)))
8420 ((eq type 'day)
8421 (let ((org-prefix-has-time t)
8422 (org-agenda-time-leading-zero t)
8423 fmt time time2)
8424 (if org-agenda-insert-diary-extract-time
8425 ;; Use org-agenda-format-item to parse text for a time-range and
8426 ;; remove it. FIXME: This is a hack, we should refactor
8427 ;; that function to make time extraction available separately
8428 (setq fmt (org-agenda-format-item nil text nil nil t)
8429 time (get-text-property 0 'time fmt)
8430 time2 (if (> (length time) 0)
8431 ;; split-string removes trailing ...... if
8432 ;; no end time given. First space
8433 ;; separates time from date.
8434 (concat " " (car (split-string time "\\.")))
8435 nil)
8436 text (get-text-property 0 'txt fmt)))
8437 (if (eq org-agenda-insert-diary-strategy 'top-level)
8438 (org-agenda-insert-diary-as-top-level text)
8439 (require 'org-datetree)
8440 (org-datetree-find-date-create d1)
8441 (org-agenda-insert-diary-make-new-entry text))
8442 (org-insert-time-stamp (org-time-from-absolute
8443 (calendar-absolute-from-gregorian d1))
8444 nil nil nil nil time2))
8445 (end-of-line 0))
8446 ((eq type 'block)
8447 (if (> (calendar-absolute-from-gregorian d1)
8448 (calendar-absolute-from-gregorian d2))
8449 (setq d1 (prog1 d2 (setq d2 d1))))
8450 (if (eq org-agenda-insert-diary-strategy 'top-level)
8451 (org-agenda-insert-diary-as-top-level text)
8452 (require 'org-datetree)
8453 (org-datetree-find-date-create d1)
8454 (org-agenda-insert-diary-make-new-entry text))
8455 (org-insert-time-stamp (org-time-from-absolute
8456 (calendar-absolute-from-gregorian d1)))
8457 (insert "--")
8458 (org-insert-time-stamp (org-time-from-absolute
8459 (calendar-absolute-from-gregorian d2)))
8460 (end-of-line 0)))
8461 (if (string-match "\\S-" text)
8462 (progn
8463 (set-window-configuration cw)
8464 (message "%s entry added to %s"
8465 (capitalize (symbol-name type))
8466 (abbreviate-file-name org-agenda-diary-file)))
8467 (org-reveal t)
8468 (message "Please finish entry here"))))
8470 (defun org-agenda-insert-diary-as-top-level (text)
8471 "Make new entry as a top-level entry at the end of the file.
8472 Add TEXT as headline, and position the cursor in the second line so that
8473 a timestamp can be added there."
8474 (widen)
8475 (goto-char (point-max))
8476 (or (bolp) (insert "\n"))
8477 (insert "* " text "\n")
8478 (if org-adapt-indentation (org-indent-to-column 2)))
8480 (defun org-agenda-insert-diary-make-new-entry (text)
8481 "Make new entry as last child of current entry.
8482 Add TEXT as headline, and position the cursor in the second line so that
8483 a timestamp can be added there."
8484 (let ((org-show-following-heading t)
8485 (org-show-siblings t)
8486 (org-show-hierarchy-above t)
8487 (org-show-entry-below t)
8488 col)
8489 (outline-next-heading)
8490 (org-back-over-empty-lines)
8491 (or (looking-at "[ \t]*$")
8492 (progn (insert "\n") (backward-char 1)))
8493 (org-insert-heading nil t)
8494 (org-do-demote)
8495 (setq col (current-column))
8496 (insert text "\n")
8497 (if org-adapt-indentation (org-indent-to-column col))
8498 (let ((org-show-following-heading t)
8499 (org-show-siblings t)
8500 (org-show-hierarchy-above t)
8501 (org-show-entry-below t))
8502 (org-show-context))))
8504 (defun org-agenda-diary-entry ()
8505 "Make a diary entry, like the `i' command from the calendar.
8506 All the standard commands work: block, weekly etc.
8507 When `org-agenda-diary-file' points to a file,
8508 `org-agenda-diary-entry-in-org-file' is called instead to create
8509 entries in that Org-mode file."
8510 (interactive)
8511 (org-agenda-check-type t 'agenda 'timeline)
8512 (if (not (eq org-agenda-diary-file 'diary-file))
8513 (org-agenda-diary-entry-in-org-file)
8514 (require 'diary-lib)
8515 (let* ((char (progn
8516 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8517 (read-char-exclusive)))
8518 (cmd (cdr (assoc char
8519 '((?d . insert-diary-entry)
8520 (?w . insert-weekly-diary-entry)
8521 (?m . insert-monthly-diary-entry)
8522 (?y . insert-yearly-diary-entry)
8523 (?a . insert-anniversary-diary-entry)
8524 (?b . insert-block-diary-entry)
8525 (?c . insert-cyclic-diary-entry)))))
8526 (oldf (symbol-function 'calendar-cursor-to-date))
8527 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8528 (point (point))
8529 (mark (or (mark t) (point))))
8530 (unless cmd
8531 (error "No command associated with <%c>" char))
8532 (unless (and (get-text-property point 'day)
8533 (or (not (equal ?b char))
8534 (get-text-property mark 'day)))
8535 (error "Don't know which date to use for diary entry"))
8536 ;; We implement this by hacking the `calendar-cursor-to-date' function
8537 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8538 (let ((calendar-mark-ring
8539 (list (calendar-gregorian-from-absolute
8540 (or (get-text-property mark 'day)
8541 (get-text-property point 'day))))))
8542 (unwind-protect
8543 (progn
8544 (fset 'calendar-cursor-to-date
8545 (lambda (&optional error dummy)
8546 (calendar-gregorian-from-absolute
8547 (get-text-property point 'day))))
8548 (call-interactively cmd))
8549 (fset 'calendar-cursor-to-date oldf))))))
8551 (defun org-agenda-execute-calendar-command (cmd)
8552 "Execute a calendar command from the agenda, with the date associated to
8553 the cursor position."
8554 (org-agenda-check-type t 'agenda 'timeline)
8555 (require 'diary-lib)
8556 (unless (get-text-property (point) 'day)
8557 (error "Don't know which date to use for calendar command"))
8558 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8559 (point (point))
8560 (date (calendar-gregorian-from-absolute
8561 (get-text-property point 'day)))
8562 ;; the following 2 vars are needed in the calendar
8563 (displayed-month (car date))
8564 (displayed-year (nth 2 date)))
8565 (unwind-protect
8566 (progn
8567 (fset 'calendar-cursor-to-date
8568 (lambda (&optional error dummy)
8569 (calendar-gregorian-from-absolute
8570 (get-text-property point 'day))))
8571 (call-interactively cmd))
8572 (fset 'calendar-cursor-to-date oldf))))
8574 (defun org-agenda-phases-of-moon ()
8575 "Display the phases of the moon for the 3 months around the cursor date."
8576 (interactive)
8577 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8579 (defun org-agenda-holidays ()
8580 "Display the holidays for the 3 months around the cursor date."
8581 (interactive)
8582 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8584 (defvar calendar-longitude)
8585 (defvar calendar-latitude)
8586 (defvar calendar-location-name)
8588 (defun org-agenda-sunrise-sunset (arg)
8589 "Display sunrise and sunset for the cursor date.
8590 Latitude and longitude can be specified with the variables
8591 `calendar-latitude' and `calendar-longitude'. When called with prefix
8592 argument, latitude and longitude will be prompted for."
8593 (interactive "P")
8594 (require 'solar)
8595 (let ((calendar-longitude (if arg nil calendar-longitude))
8596 (calendar-latitude (if arg nil calendar-latitude))
8597 (calendar-location-name
8598 (if arg "the given coordinates" calendar-location-name)))
8599 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8601 (defun org-agenda-goto-calendar ()
8602 "Open the Emacs calendar with the date at the cursor."
8603 (interactive)
8604 (org-agenda-check-type t 'agenda 'timeline)
8605 (let* ((day (or (get-text-property (point) 'day)
8606 (error "Don't know which date to open in calendar")))
8607 (date (calendar-gregorian-from-absolute day))
8608 (calendar-move-hook nil)
8609 (calendar-view-holidays-initially-flag nil)
8610 (calendar-view-diary-initially-flag nil))
8611 (calendar)
8612 (calendar-goto-date date)))
8614 ;;;###autoload
8615 (defun org-calendar-goto-agenda ()
8616 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8617 This is a command that has to be installed in `calendar-mode-map'."
8618 (interactive)
8619 (org-agenda-list nil (calendar-absolute-from-gregorian
8620 (calendar-cursor-to-date))
8621 nil))
8623 (defun org-agenda-convert-date ()
8624 (interactive)
8625 (org-agenda-check-type t 'agenda 'timeline)
8626 (let ((day (get-text-property (point) 'day))
8627 date s)
8628 (unless day
8629 (error "Don't know which date to convert"))
8630 (setq date (calendar-gregorian-from-absolute day))
8631 (setq s (concat
8632 "Gregorian: " (calendar-date-string date) "\n"
8633 "ISO: " (calendar-iso-date-string date) "\n"
8634 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8635 "Julian: " (calendar-julian-date-string date) "\n"
8636 "Astron. JD: " (calendar-astro-date-string date)
8637 " (Julian date number at noon UTC)\n"
8638 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8639 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8640 "French: " (calendar-french-date-string date) "\n"
8641 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8642 "Mayan: " (calendar-mayan-date-string date) "\n"
8643 "Coptic: " (calendar-coptic-date-string date) "\n"
8644 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8645 "Persian: " (calendar-persian-date-string date) "\n"
8646 "Chinese: " (calendar-chinese-date-string date) "\n"))
8647 (with-output-to-temp-buffer "*Dates*"
8648 (princ s))
8649 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8651 ;;; Bulk commands
8653 (defvar org-agenda-bulk-marked-entries nil
8654 "List of markers that refer to marked entries in the agenda.")
8656 (defun org-agenda-bulk-marked-p ()
8657 (eq (get-char-property (point-at-bol) 'type)
8658 'org-marked-entry-overlay))
8660 (defun org-agenda-bulk-mark (&optional arg)
8661 "Mark the entry at point for future bulk action."
8662 (interactive "p")
8663 (dotimes (i (or arg 1))
8664 (unless (org-get-at-bol 'org-agenda-diary-link)
8665 (let* ((m (org-get-at-bol 'org-hd-marker))
8667 (unless (org-agenda-bulk-marked-p)
8668 (unless m (error "Nothing to mark at point"))
8669 (push m org-agenda-bulk-marked-entries)
8670 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8671 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8672 (org-get-todo-face "TODO")
8673 'evaporate)
8674 (overlay-put ov 'type 'org-marked-entry-overlay))
8675 (beginning-of-line 2)
8676 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8677 (beginning-of-line 2))
8678 (message "%d entries marked for bulk action"
8679 (length org-agenda-bulk-marked-entries))))))
8681 (defun org-agenda-bulk-mark-all ()
8682 "Mark all entries for future agenda bulk action."
8683 (interactive)
8684 (org-agenda-bulk-mark-regexp "."))
8686 (defun org-agenda-bulk-mark-regexp (regexp)
8687 "Mark entries matching REGEXP for future agenda bulk action."
8688 (interactive "sMark entries matching regexp: ")
8689 (let ((entries-marked 0))
8690 (save-excursion
8691 (goto-char (point-min))
8692 (goto-char (next-single-property-change (point) 'txt))
8693 (while (re-search-forward regexp nil t)
8694 (when (string-match regexp (get-text-property (point) 'txt))
8695 (setq entries-marked (1+ entries-marked))
8696 (call-interactively 'org-agenda-bulk-mark))))
8697 (if (not entries-marked)
8698 (message "No entry matching this regexp."))))
8700 (defun org-agenda-bulk-unmark (&optional arg)
8701 "Unmark the entry at point for future bulk action."
8702 (interactive "P")
8703 (if arg
8704 (org-agenda-bulk-unmark-all)
8705 (cond ((org-agenda-bulk-marked-p)
8706 (org-agenda-bulk-remove-overlays
8707 (point-at-bol) (+ 2 (point-at-bol)))
8708 (setq org-agenda-bulk-marked-entries
8709 (delete (org-get-at-bol 'org-hd-marker)
8710 org-agenda-bulk-marked-entries))
8711 (beginning-of-line 2)
8712 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8713 (beginning-of-line 2))
8714 (message "%d entries left marked for bulk action"
8715 (length org-agenda-bulk-marked-entries)))
8716 (t (message "No entry to unmark here")))))
8718 (defun org-agenda-bulk-toggle ()
8719 "Toggle marking the entry at point for bulk action."
8720 (interactive)
8721 (if (org-agenda-bulk-marked-p)
8722 (org-agenda-bulk-unmark)
8723 (org-agenda-bulk-mark)))
8725 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8726 "Remove the mark overlays between BEG and END in the agenda buffer.
8727 BEG and END default to the buffer limits.
8729 This only removes the overlays, it does not remove the markers
8730 from the list in `org-agenda-bulk-marked-entries'."
8731 (interactive)
8732 (mapc (lambda (ov)
8733 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8734 (delete-overlay ov)))
8735 (overlays-in (or beg (point-min)) (or end (point-max)))))
8737 (defun org-agenda-bulk-unmark-all ()
8738 "Remove all marks in the agenda buffer.
8739 This will remove the markers and the overlays."
8740 (interactive)
8741 (if (null org-agenda-bulk-marked-entries)
8742 (message "No entry to unmark")
8743 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8744 (setq org-agenda-bulk-marked-entries nil)
8745 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8747 (defcustom org-agenda-persistent-marks nil
8748 "Non-nil means marked items will stay marked after a bulk action.
8749 You can interactively and temporarily toggle by typing `p' when you
8750 are prompted for a bulk action."
8751 :group 'org-agenda
8752 :version "24.1"
8753 :type 'boolean)
8755 (defun org-agenda-bulk-action (&optional arg)
8756 "Execute an remote-editing action on all marked entries.
8757 The prefix arg is passed through to the command if possible."
8758 (interactive "P")
8759 ;; Make sure we have markers, and only valid ones
8760 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8761 (mapc
8762 (lambda (m)
8763 (unless (and (markerp m)
8764 (marker-buffer m)
8765 (buffer-live-p (marker-buffer m))
8766 (marker-position m))
8767 (error "Marker %s for bulk command is invalid" m)))
8768 org-agenda-bulk-marked-entries)
8770 ;; Prompt for the bulk command
8771 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8772 (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
8773 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
8774 (when org-agenda-bulk-custom-functions
8775 (concat " Custom: ["
8776 (mapconcat (lambda(f) (char-to-string (car f)))
8777 org-agenda-bulk-custom-functions "")
8778 "]"))))
8779 (catch 'exit
8780 (let* ((action (read-char-exclusive))
8781 (org-log-refile (if org-log-refile 'time nil))
8782 (entries (reverse org-agenda-bulk-marked-entries))
8783 redo-at-end
8784 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8785 (cond
8786 ((equal action ?p)
8787 (let ((org-agenda-persistent-marks
8788 (not org-agenda-persistent-marks)))
8789 (org-agenda-bulk-action)
8790 (throw 'exit nil)))
8792 ((equal action ?$)
8793 (setq cmd '(org-agenda-archive)))
8795 ((equal action ?A)
8796 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8798 ((member action '(?r ?w))
8799 (setq rfloc (org-refile-get-location
8800 "Refile to"
8801 (marker-buffer (car org-agenda-bulk-marked-entries))
8802 org-refile-allow-creating-parent-nodes))
8803 (if (nth 3 rfloc)
8804 (setcar (nthcdr 3 rfloc)
8805 (move-marker (make-marker) (nth 3 rfloc)
8806 (or (get-file-buffer (nth 1 rfloc))
8807 (find-buffer-visiting (nth 1 rfloc))
8808 (error "This should not happen")))))
8810 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8811 redo-at-end t))
8813 ((equal action ?t)
8814 (setq state (org-icompleting-read
8815 "Todo state: "
8816 (with-current-buffer (marker-buffer (car entries))
8817 (mapcar 'list org-todo-keywords-1))))
8818 (setq cmd `(let ((org-inhibit-blocking t)
8819 (org-inhibit-logging 'note))
8820 (org-agenda-todo ,state))))
8822 ((memq action '(?- ?+))
8823 (setq tag (org-icompleting-read
8824 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8825 (with-current-buffer (marker-buffer (car entries))
8826 (delq nil
8827 (mapcar (lambda (x)
8828 (if (stringp (car x)) x)) org-tag-alist)))))
8829 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8831 ((memq action '(?s ?d))
8832 (let* ((date (unless arg
8833 (org-read-date
8834 nil nil nil
8835 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8836 (ans (if arg nil org-read-date-final-answer))
8837 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8838 (setq cmd `(let* ((bound (fboundp 'read-string))
8839 (old (and bound (symbol-function 'read-string))))
8840 (unwind-protect
8841 (progn
8842 (fset 'read-string (lambda (&rest ignore) ,ans))
8843 (eval '(,c1 arg)))
8844 (if bound
8845 (fset 'read-string old)
8846 (fmakunbound 'read-string)))))))
8848 ((equal action ?S)
8849 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8850 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8851 (let ((days (read-number
8852 (format "Scatter tasks across how many %sdays: "
8853 (if arg "week" "")) 7)))
8854 (setq cmd
8855 `(let ((distance (1+ (random ,days))))
8856 (if arg
8857 (let ((dist distance)
8858 (day-of-week
8859 (calendar-day-of-week
8860 (calendar-gregorian-from-absolute (org-today)))))
8861 (dotimes (i (1+ dist))
8862 (while (member day-of-week org-agenda-weekend-days)
8863 (incf distance)
8864 (incf day-of-week)
8865 (if (= day-of-week 7)
8866 (setq day-of-week 0)))
8867 (incf day-of-week)
8868 (if (= day-of-week 7)
8869 (setq day-of-week 0)))))
8870 ;; silently fail when try to replan a sexp entry
8871 (condition-case nil
8872 (let* ((date (calendar-gregorian-from-absolute
8873 (+ (org-today) distance)))
8874 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8875 (nth 2 date))))
8876 (org-agenda-schedule nil time))
8877 (error nil)))))))
8879 ((assoc action org-agenda-bulk-custom-functions)
8880 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8881 redo-at-end t))
8883 ((equal action ?f)
8884 (setq cmd (list (intern
8885 (org-icompleting-read "Function: "
8886 obarray 'fboundp t nil nil)))))
8888 (t (error "Invalid bulk action")))
8890 ;; Sort the markers, to make sure that parents are handled before children
8891 (setq entries (sort entries
8892 (lambda (a b)
8893 (cond
8894 ((equal (marker-buffer a) (marker-buffer b))
8895 (< (marker-position a) (marker-position b)))
8897 (string< (buffer-name (marker-buffer a))
8898 (buffer-name (marker-buffer b))))))))
8900 ;; Now loop over all markers and apply cmd
8901 (while (setq e (pop entries))
8902 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8903 (if (not pos)
8904 (progn (message "Skipping removed entry at %s" e)
8905 (setq cntskip (1+ cntskip)))
8906 (goto-char pos)
8907 (let (org-loop-over-headlines-in-active-region)
8908 (eval cmd))
8909 (when (not org-agenda-persistent-marks)
8910 (setq org-agenda-bulk-marked-entries
8911 (delete e org-agenda-bulk-marked-entries)))
8912 (setq cnt (1+ cnt))))
8913 (when (not org-agenda-persistent-marks)
8914 (org-agenda-bulk-unmark-all))
8915 (when redo-at-end (org-agenda-redo))
8916 (message "Acted on %d entries%s%s"
8918 (if (= cntskip 0)
8920 (format ", skipped %d (disappeared before their turn)"
8921 cntskip))
8922 (if (not org-agenda-persistent-marks)
8923 "" " (kept marked)"))))))
8925 ;;; Flagging notes
8927 (defun org-agenda-show-the-flagging-note ()
8928 "Display the flagging note in the other window.
8929 When called a second time in direct sequence, offer to remove the FLAGGING
8930 tag and (if present) the flagging note."
8931 (interactive)
8932 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8933 (win (selected-window))
8934 note heading newhead)
8935 (unless hdmarker
8936 (error "No linked entry at point"))
8937 (if (and (eq this-command last-command)
8938 (y-or-n-p "Unflag and remove any flagging note? "))
8939 (progn
8940 (org-agenda-remove-flag hdmarker)
8941 (let ((win (get-buffer-window "*Flagging Note*")))
8942 (and win (delete-window win)))
8943 (message "Entry unflagged"))
8944 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8945 (unless note
8946 (error "No flagging note"))
8947 (org-kill-new note)
8948 (org-switch-to-buffer-other-window "*Flagging Note*")
8949 (erase-buffer)
8950 (insert note)
8951 (goto-char (point-min))
8952 (while (re-search-forward "\\\\n" nil t)
8953 (replace-match "\n" t t))
8954 (goto-char (point-min))
8955 (select-window win)
8956 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8958 (defun org-agenda-remove-flag (marker)
8959 "Remove the FLAGGED tag and any flagging note in the entry."
8960 (let (newhead)
8961 (org-with-point-at marker
8962 (org-toggle-tag "FLAGGED" 'off)
8963 (org-entry-delete nil "THEFLAGGINGNOTE")
8964 (setq newhead (org-get-heading)))
8965 (org-agenda-change-all-lines newhead marker)
8966 (message "Entry unflagged")))
8968 (defun org-agenda-get-any-marker (&optional pos)
8969 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8970 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8972 ;;; Appointment reminders
8974 (defvar appt-time-msg-list)
8976 ;;;###autoload
8977 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8978 "Activate appointments found in `org-agenda-files'.
8979 With a \\[universal-argument] prefix, refresh the list of
8980 appointments.
8982 If FILTER is t, interactively prompt the user for a regular
8983 expression, and filter out entries that don't match it.
8985 If FILTER is a string, use this string as a regular expression
8986 for filtering entries out.
8988 If FILTER is a function, filter out entries against which
8989 calling the function returns nil. This function takes one
8990 argument: an entry from `org-agenda-get-day-entries'.
8992 FILTER can also be an alist with the car of each cell being
8993 either 'headline or 'category. For example:
8995 '((headline \"IMPORTANT\")
8996 (category \"Work\"))
8998 will only add headlines containing IMPORTANT or headlines
8999 belonging to the \"Work\" category.
9001 ARGS are symbols indicating what kind of entries to consider.
9002 By default `org-agenda-to-appt' will use :deadline, :scheduled
9003 and :timestamp entries. See the docstring of `org-diary' for
9004 details and examples.
9006 If an entry as a APPT_WARNTIME property, its value will be used
9007 to override `appt-message-warning-time'."
9008 (interactive "P")
9009 (if refresh (setq appt-time-msg-list nil))
9010 (if (eq filter t)
9011 (setq filter (read-from-minibuffer "Regexp filter: ")))
9012 (let* ((cnt 0) ; count added events
9013 (scope (or args '(:deadline :scheduled :timestamp)))
9014 (org-agenda-new-buffers nil)
9015 (org-deadline-warning-days 0)
9016 ;; Do not use `org-today' here because appt only takes
9017 ;; time and without date as argument, so it may pass wrong
9018 ;; information otherwise
9019 (today (org-date-to-gregorian
9020 (time-to-days (current-time))))
9021 (org-agenda-restrict nil)
9022 (files (org-agenda-files 'unrestricted)) entries file
9023 (org-agenda-buffer nil))
9024 ;; Get all entries which may contain an appt
9025 (org-prepare-agenda-buffers files)
9026 (while (setq file (pop files))
9027 (setq entries
9028 (delq nil
9029 (append entries
9030 (apply 'org-agenda-get-day-entries
9031 file today scope)))))
9032 ;; Map thru entries and find if we should filter them out
9033 (mapc
9034 (lambda(x)
9035 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9036 (cat (get-text-property 1 'org-category x))
9037 (tod (get-text-property 1 'time-of-day x))
9038 (ok (or (null filter)
9039 (and (stringp filter) (string-match filter evt))
9040 (and (functionp filter) (funcall filter x))
9041 (and (listp filter)
9042 (let ((cat-filter (cadr (assoc 'category filter)))
9043 (evt-filter (cadr (assoc 'headline filter))))
9044 (or (and (stringp cat-filter)
9045 (string-match cat-filter cat))
9046 (and (stringp evt-filter)
9047 (string-match evt-filter evt)))))))
9048 (wrn (org-entry-get (point) "APPT_WARNTIME")))
9049 ;; FIXME: Shall we remove text-properties for the appt text?
9050 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9051 (when (and ok tod)
9052 (setq tod (concat "00" (number-to-string tod))
9053 tod (when (string-match
9054 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9055 (concat (match-string 1 tod) ":"
9056 (match-string 2 tod))))
9057 (if (version< emacs-version "23.3")
9058 (appt-add tod evt)
9059 (appt-add tod evt wrn))
9060 (setq cnt (1+ cnt))))) entries)
9061 (org-release-buffers org-agenda-new-buffers)
9062 (if (eq cnt 0)
9063 (message "No event to add")
9064 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9066 (defun org-agenda-todayp (date)
9067 "Does DATE mean today, when considering `org-extend-today-until'?"
9068 (let ((today (org-today))
9069 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9070 date)))
9071 (eq date today)))
9073 (defun org-agenda-todo-yesterday (&optional arg)
9074 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9075 (interactive "P")
9076 (let* ((hour (third (decode-time
9077 (org-current-time))))
9078 (org-extend-today-until (1+ hour)))
9079 (org-agenda-todo arg)))
9081 (provide 'org-agenda)
9083 ;;; org-agenda.el ends here