Docstring fixes.
[org-mode.git] / lisp / org-agenda.el
blob05fb797cec21d4551411c67399e2b182196c820d
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-tags-todo-honor-ignore-options nil
744 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
745 The variables
746 `org-agenda-todo-ignore-with-date',
747 `org-agenda-todo-ignore-timestamp',
748 `org-agenda-todo-ignore-scheduled',
749 `org-agenda-todo-ignore-deadlines'
750 make the global TODO list skip entries that have time stamps of certain
751 kinds. If this option is set, the same options will also apply for the
752 tags-todo search, which is the general tags/property matcher
753 restricted to unfinished TODO entries only."
754 :group 'org-agenda-skip
755 :group 'org-agenda-todo-list
756 :group 'org-agenda-match-view
757 :type 'boolean)
759 (defcustom org-agenda-skip-scheduled-if-done nil
760 "Non-nil means don't show scheduled items in agenda when they are done.
761 This is relevant for the daily/weekly agenda, not for the TODO list. And
762 it applies only to the actual date of the scheduling. Warnings about
763 an item with a past scheduling dates are always turned off when the item
764 is DONE."
765 :group 'org-agenda-skip
766 :group 'org-agenda-daily/weekly
767 :type 'boolean)
769 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
770 "Non-nil means skip scheduling line if same entry shows because of deadline.
771 In the agenda of today, an entry can show up multiple times because
772 it is both scheduled and has a nearby deadline, and maybe a plain time
773 stamp as well.
774 When this variable is t, then only the deadline is shown and the fact that
775 the entry is scheduled today or was scheduled previously is not shown.
776 When this variable is nil, the entry will be shown several times. When
777 the variable is the symbol `not-today', then skip scheduled previously,
778 but not scheduled today."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type '(choice
782 (const :tag "Never" nil)
783 (const :tag "Always" t)
784 (const :tag "Not when scheduled today" not-today)))
786 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
787 "Non-nil means skip timestamp line if same entry shows because of deadline.
788 In the agenda of today, an entry can show up multiple times
789 because it has both a plain timestamp and has a nearby deadline.
790 When this variable is t, then only the deadline is shown and the
791 fact that the entry has a timestamp for or including today is not
792 shown. When this variable is nil, the entry will be shown
793 several times."
794 :group 'org-agenda-skip
795 :group 'org-agenda-daily/weekly
796 :version "24.1"
797 :type '(choice
798 (const :tag "Never" nil)
799 (const :tag "Always" t)))
801 (defcustom org-agenda-skip-deadline-if-done nil
802 "Non-nil means don't show deadlines when the corresponding item is done.
803 When nil, the deadline is still shown and should give you a happy feeling.
804 This is relevant for the daily/weekly agenda. And it applied only to the
805 actually date of the deadline. Warnings about approaching and past-due
806 deadlines are always turned off when the item is DONE."
807 :group 'org-agenda-skip
808 :group 'org-agenda-daily/weekly
809 :type 'boolean)
811 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
812 "Non-nil means skip deadline prewarning when entry is also scheduled.
813 This will apply on all days where a prewarning for the deadline would
814 be shown, but not at the day when the entry is actually due. On that day,
815 the deadline will be shown anyway.
816 This variable may be set to nil, t, or a number which will then give
817 the number of days before the actual deadline when the prewarnings
818 should resume.
819 This can be used in a workflow where the first showing of the deadline will
820 trigger you to schedule it, and then you don't want to be reminded of it
821 because you will take care of it on the day when scheduled."
822 :group 'org-agenda-skip
823 :group 'org-agenda-daily/weekly
824 :version "24.1"
825 :type '(choice
826 (const :tag "Always show prewarning" nil)
827 (const :tag "Remove prewarning if entry is scheduled" t)
828 (integer :tag "Restart prewarning N days before deadline")))
830 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
831 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
832 When non-nil, after the search for timestamps has matched once in an
833 entry, the rest of the entry will not be searched."
834 :group 'org-agenda-skip
835 :type 'boolean)
837 (defcustom org-agenda-skip-timestamp-if-done nil
838 "Non-nil means don't select item by timestamp or -range if it is DONE."
839 :group 'org-agenda-skip
840 :group 'org-agenda-daily/weekly
841 :type 'boolean)
843 (defcustom org-agenda-dim-blocked-tasks nil
844 "Non-nil means dim blocked tasks in the agenda display.
845 This causes some overhead during agenda construction, but if you
846 have turned on `org-enforce-todo-dependencies',
847 `org-enforce-todo-checkbox-dependencies', or any other blocking
848 mechanism, this will create useful feedback in the agenda.
850 Instead of t, this variable can also have the value `invisible'.
851 Then blocked tasks will be invisible and only become visible when
852 they become unblocked. An exemption to this behavior is when a task is
853 blocked because of unchecked checkboxes below it. Since checkboxes do
854 not show up in the agenda views, making this task invisible you remove any
855 trace from agenda views that there is something to do. Therefore, a task
856 that is blocked because of checkboxes will never be made invisible, it
857 will only be dimmed."
858 :group 'org-agenda-daily/weekly
859 :group 'org-agenda-todo-list
860 :version "24.3"
861 :type '(choice
862 (const :tag "Do not dim" nil)
863 (const :tag "Dim to a gray face" t)
864 (const :tag "Make invisible" invisible)))
866 (defcustom org-timeline-show-empty-dates 3
867 "Non-nil means `org-timeline' also shows dates without an entry.
868 When nil, only the days which actually have entries are shown.
869 When t, all days between the first and the last date are shown.
870 When an integer, show also empty dates, but if there is a gap of more than
871 N days, just insert a special line indicating the size of the gap."
872 :group 'org-agenda-skip
873 :type '(choice
874 (const :tag "None" nil)
875 (const :tag "All" t)
876 (integer :tag "at most")))
878 (defgroup org-agenda-startup nil
879 "Options concerning initial settings in the Agenda in Org Mode."
880 :tag "Org Agenda Startup"
881 :group 'org-agenda)
883 (defcustom org-agenda-menu-show-matcher t
884 "Non-nil means show the match string in the agenda dispatcher menu.
885 When nil, the matcher string is not shown, but is put into the help-echo
886 property so than moving the mouse over the command shows it.
887 Setting it to nil is good if matcher strings are very long and/or if
888 you want to use two-columns display (see `org-agenda-menu-two-columns')."
889 :group 'org-agenda
890 :version "24.1"
891 :type 'boolean)
893 (org-define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
895 (defcustom org-agenda-menu-two-columns nil
896 "Non-nil means, use two columns to show custom commands in the dispatcher.
897 If you use this, you probably want to set `org-agenda-menu-show-matcher'
898 to nil."
899 :group 'org-agenda
900 :version "24.1"
901 :type 'boolean)
903 (org-define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
904 (defcustom org-agenda-finalize-hook nil
905 "Hook run just before displaying an agenda buffer.
906 The buffer is still writable when the hook is called.
908 You can modify some of the buffer substrings but you should be
909 extra careful not to modify the text properties of the agenda
910 headlines as the agenda display heavily relies on them."
911 :group 'org-agenda-startup
912 :type 'hook)
914 (defcustom org-agenda-mouse-1-follows-link nil
915 "Non-nil means mouse-1 on a link will follow the link in the agenda.
916 A longer mouse click will still set point. Does not work on XEmacs.
917 Needs to be set before org.el is loaded."
918 :group 'org-agenda-startup
919 :type 'boolean)
921 (defcustom org-agenda-start-with-follow-mode nil
922 "The initial value of follow mode in a newly created agenda window."
923 :group 'org-agenda-startup
924 :type 'boolean)
926 (defcustom org-agenda-follow-indirect nil
927 "Non-nil means `org-agenda-follow-mode' displays only the
928 current item's tree, in an indirect buffer."
929 :group 'org-agenda
930 :version "24.1"
931 :type 'boolean)
933 (defcustom org-agenda-show-outline-path t
934 "Non-nil means show outline path in echo area after line motion."
935 :group 'org-agenda-startup
936 :type 'boolean)
938 (defcustom org-agenda-start-with-entry-text-mode nil
939 "The initial value of entry-text-mode in a newly created agenda window."
940 :group 'org-agenda-startup
941 :type 'boolean)
943 (defcustom org-agenda-entry-text-maxlines 5
944 "Number of text lines to be added when `E' is pressed in the agenda.
946 Note that this variable only used during agenda display. Add add entry text
947 when exporting the agenda, configure the variable
948 `org-agenda-add-entry-ext-maxlines'."
949 :group 'org-agenda
950 :type 'integer)
952 (defcustom org-agenda-entry-text-exclude-regexps nil
953 "List of regular expressions to clean up entry text.
954 The complete matches of all regular expressions in this list will be
955 removed from entry text before it is shown in the agenda."
956 :group 'org-agenda
957 :type '(repeat (regexp)))
959 (defvar org-agenda-entry-text-cleanup-hook nil
960 "Hook that is run after basic cleanup of entry text to be shown in agenda.
961 This cleanup is done in a temporary buffer, so the function may inspect and
962 change the entire buffer.
963 Some default stuff like drawers and scheduling/deadline dates will already
964 have been removed when this is called, as will any matches for regular
965 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
967 (defvar org-agenda-include-inactive-timestamps nil
968 "Non-nil means include inactive time stamps in agenda and timeline.
969 Dynamically scoped.")
971 (defgroup org-agenda-windows nil
972 "Options concerning the windows used by the Agenda in Org Mode."
973 :tag "Org Agenda Windows"
974 :group 'org-agenda)
976 (defcustom org-agenda-window-setup 'reorganize-frame
977 "How the agenda buffer should be displayed.
978 Possible values for this option are:
980 current-window Show agenda in the current window, keeping all other windows.
981 other-window Use `switch-to-buffer-other-window' to display agenda.
982 reorganize-frame Show only two windows on the current frame, the current
983 window and the agenda.
984 other-frame Use `switch-to-buffer-other-frame' to display agenda.
985 Also, when exiting the agenda, kill that frame.
986 See also the variable `org-agenda-restore-windows-after-quit'."
987 :group 'org-agenda-windows
988 :type '(choice
989 (const current-window)
990 (const other-frame)
991 (const other-window)
992 (const reorganize-frame)))
994 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
995 "The min and max height of the agenda window as a fraction of frame height.
996 The value of the variable is a cons cell with two numbers between 0 and 1.
997 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
998 :group 'org-agenda-windows
999 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1001 (defcustom org-agenda-restore-windows-after-quit nil
1002 "Non-nil means restore window configuration upon exiting agenda.
1003 Before the window configuration is changed for displaying the agenda,
1004 the current status is recorded. When the agenda is exited with
1005 `q' or `x' and this option is set, the old state is restored. If
1006 `org-agenda-window-setup' is `other-frame', the value of this
1007 option will be ignored."
1008 :group 'org-agenda-windows
1009 :type 'boolean)
1011 (defcustom org-agenda-ndays nil
1012 "Number of days to include in overview display.
1013 Should be 1 or 7.
1014 Obsolete, see `org-agenda-span'."
1015 :group 'org-agenda-daily/weekly
1016 :type 'integer)
1018 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1020 (defcustom org-agenda-span 'week
1021 "Number of days to include in overview display.
1022 Can be day, week, month, year, or any number of days.
1023 Custom commands can set this variable in the options section."
1024 :group 'org-agenda-daily/weekly
1025 :type '(choice (const :tag "Day" day)
1026 (const :tag "Week" week)
1027 (const :tag "Month" month)
1028 (const :tag "Year" year)
1029 (integer :tag "Custom")))
1031 (defcustom org-agenda-start-on-weekday 1
1032 "Non-nil means start the overview always on the specified weekday.
1033 0 denotes Sunday, 1 denotes Monday etc.
1034 When nil, always start on the current day.
1035 Custom commands can set this variable in the options section."
1036 :group 'org-agenda-daily/weekly
1037 :type '(choice (const :tag "Today" nil)
1038 (integer :tag "Weekday No.")))
1040 (defcustom org-agenda-show-all-dates t
1041 "Non-nil means `org-agenda' shows every day in the selected range.
1042 When nil, only the days which actually have entries are shown."
1043 :group 'org-agenda-daily/weekly
1044 :type 'boolean)
1046 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1047 "Format string for displaying dates in the agenda.
1048 Used by the daily/weekly agenda and by the timeline. This should be
1049 a format string understood by `format-time-string', or a function returning
1050 the formatted date as a string. The function must take a single argument,
1051 a calendar-style date list like (month day year)."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice
1054 (string :tag "Format string")
1055 (function :tag "Function")))
1057 (defun org-agenda-format-date-aligned (date)
1058 "Format a date string for display in the daily/weekly agenda, or timeline.
1059 This function makes sure that dates are aligned for easy reading."
1060 (require 'cal-iso)
1061 (let* ((dayname (calendar-day-name date))
1062 (day (cadr date))
1063 (day-of-week (calendar-day-of-week date))
1064 (month (car date))
1065 (monthname (calendar-month-name month))
1066 (year (nth 2 date))
1067 (iso-week (org-days-to-iso-week
1068 (calendar-absolute-from-gregorian date)))
1069 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1070 (1- year))
1071 ((and (= month 12) (<= iso-week 1))
1072 (1+ year))
1073 (t year)))
1074 (weekstring (if (= day-of-week 1)
1075 (format " W%02d" iso-week)
1076 "")))
1077 (format "%-10s %2d %s %4d%s"
1078 dayname day monthname year weekstring)))
1080 (defcustom org-agenda-time-leading-zero nil
1081 "Non-nil means use leading zero for military times in agenda.
1082 For example, 9:30am would become 09:30 rather than 9:30."
1083 :group 'org-agenda-daily/weekly
1084 :version "24.1"
1085 :type 'boolean)
1087 (defcustom org-agenda-timegrid-use-ampm nil
1088 "When set, show AM/PM style timestamps on the timegrid."
1089 :group 'org-agenda
1090 :version "24.1"
1091 :type 'boolean)
1093 (defun org-agenda-time-of-day-to-ampm (time)
1094 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1095 (let* ((hour-number (string-to-number (substring time 0 -3)))
1096 (minute (substring time -2))
1097 (ampm "am"))
1098 (cond
1099 ((equal hour-number 12)
1100 (setq ampm "pm"))
1101 ((> hour-number 12)
1102 (setq ampm "pm")
1103 (setq hour-number (- hour-number 12))))
1104 (concat
1105 (if org-agenda-time-leading-zero
1106 (format "%02d" hour-number)
1107 (format "%02s" (number-to-string hour-number)))
1108 ":" minute ampm)))
1110 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1111 "Conditionally convert TIME to AM/PM format
1112 based on `org-agenda-timegrid-use-ampm'"
1113 (if org-agenda-timegrid-use-ampm
1114 (org-agenda-time-of-day-to-ampm time)
1115 time))
1117 (defcustom org-agenda-weekend-days '(6 0)
1118 "Which days are weekend?
1119 These days get the special face `org-agenda-date-weekend' in the agenda
1120 and timeline buffers."
1121 :group 'org-agenda-daily/weekly
1122 :type '(set :greedy t
1123 (const :tag "Monday" 1)
1124 (const :tag "Tuesday" 2)
1125 (const :tag "Wednesday" 3)
1126 (const :tag "Thursday" 4)
1127 (const :tag "Friday" 5)
1128 (const :tag "Saturday" 6)
1129 (const :tag "Sunday" 0)))
1131 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1132 "Non-nil means jump to today when moving a past date forward in time.
1133 When using S-right in the agenda to move a a date forward, and the date
1134 stamp currently points to the past, the first key press will move it
1135 to today. WHen nil, just move one day forward even if the date stays
1136 in the past."
1137 :group 'org-agenda-daily/weekly
1138 :version "24.1"
1139 :type 'boolean)
1141 (defcustom org-agenda-include-diary nil
1142 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1143 Custom commands can set this variable in the options section."
1144 :group 'org-agenda-daily/weekly
1145 :type 'boolean)
1147 (defcustom org-agenda-include-deadlines t
1148 "If non-nil, include entries within their deadline warning period.
1149 Custom commands can set this variable in the options section."
1150 :group 'org-agenda-daily/weekly
1151 :version "24.1"
1152 :type 'boolean)
1154 (defcustom org-agenda-repeating-timestamp-show-all t
1155 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1156 When set to a list of strings, only show occurrences of repeating
1157 stamps for these TODO keywords. When nil, only one occurrence is
1158 shown, either today or the nearest into the future."
1159 :group 'org-agenda-daily/weekly
1160 :type '(choice
1161 (const :tag "Show repeating stamps" t)
1162 (repeat :tag "Show repeating stamps for these TODO keywords"
1163 (string :tag "TODO Keyword"))
1164 (const :tag "Don't show repeating stamps" nil)))
1166 (defcustom org-scheduled-past-days 10000
1167 "No. of days to continue listing scheduled items that are not marked DONE.
1168 When an item is scheduled on a date, it shows up in the agenda on this
1169 day and will be listed until it is marked done for the number of days
1170 given here."
1171 :group 'org-agenda-daily/weekly
1172 :type 'integer)
1174 (defcustom org-agenda-log-mode-items '(closed clock)
1175 "List of items that should be shown in agenda log mode.
1176 This list may contain the following symbols:
1178 closed Show entries that have been closed on that day.
1179 clock Show entries that have received clocked time on that day.
1180 state Show all logged state changes.
1181 Note that instead of changing this variable, you can also press `C-u l' in
1182 the agenda to display all available LOG items temporarily."
1183 :group 'org-agenda-daily/weekly
1184 :type '(set :greedy t (const closed) (const clock) (const state)))
1186 (defcustom org-agenda-clock-consistency-checks
1187 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1188 :gap-ok-around ("4:00")
1189 :default-face ((:background "DarkRed") (:foreground "white"))
1190 :overlap-face nil :gap-face nil :no-end-time-face nil
1191 :long-face nil :short-face nil)
1192 "This is a property list, with the following keys:
1194 :max-duration Mark clocking chunks that are longer than this time.
1195 This is a time string like \"HH:MM\", or the number
1196 of minutes as an integer.
1198 :min-duration Mark clocking chunks that are shorter that this.
1199 This is a time string like \"HH:MM\", or the number
1200 of minutes as an integer.
1202 :max-gap Mark gaps between clocking chunks that are longer than
1203 this duration. A number of minutes, or a string
1204 like \"HH:MM\".
1206 :gap-ok-around List of times during the day which are usually not working
1207 times. When a gap is detected, but the gap contains any
1208 of these times, the gap is *not* reported. For example,
1209 if this is (\"4:00\" \"13:00\") then gaps that contain
1210 4:00 in the morning (i.e. the night) and 13:00
1211 (i.e. a typical lunch time) do not cause a warning.
1212 You should have at least one time during the night in this
1213 list, or otherwise the first task each morning will trigger
1214 a warning because it follows a long gap.
1216 Furthermore, the following properties can be used to define faces for
1217 issue display.
1219 :default-face the default face, if the specific face is undefined
1220 :overlap-face face for overlapping clocks
1221 :gap-face face for gaps between clocks
1222 :no-end-time-face face for incomplete clocks
1223 :long-face face for clock intervals that are too long
1224 :short-face face for clock intervals that are too short"
1225 :group 'org-agenda-daily/weekly
1226 :group 'org-clock
1227 :version "24.1"
1228 :type 'plist)
1230 (defcustom org-agenda-log-mode-add-notes t
1231 "Non-nil means add first line of notes to log entries in agenda views.
1232 If a log item like a state change or a clock entry is associated with
1233 notes, the first line of these notes will be added to the entry in the
1234 agenda display."
1235 :group 'org-agenda-daily/weekly
1236 :type 'boolean)
1238 (defcustom org-agenda-start-with-log-mode nil
1239 "The initial value of log-mode in a newly created agenda window.
1240 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1241 explanations on the possible values."
1242 :group 'org-agenda-startup
1243 :group 'org-agenda-daily/weekly
1244 :type '(choice (const :tag "Don't show log items" nil)
1245 (const :tag "Show only log items" 'only)
1246 (const :tag "Show all possible log items" 'clockcheck)
1247 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1248 (choice (const :tag "Show closed log items" 'closed)
1249 (const :tag "Show clocked log items" 'clock)
1250 (const :tag "Show all logged state changes" 'state)))))
1252 (defcustom org-agenda-start-with-clockreport-mode nil
1253 "The initial value of clockreport-mode in a newly created agenda window."
1254 :group 'org-agenda-startup
1255 :group 'org-agenda-daily/weekly
1256 :type 'boolean)
1258 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1259 "Property list with parameters for the clocktable in clockreport mode.
1260 This is the display mode that shows a clock table in the daily/weekly
1261 agenda, the properties for this dynamic block can be set here.
1262 The usual clocktable parameters are allowed here, but you cannot set
1263 the properties :name, :tstart, :tend, :block, and :scope - these will
1264 be overwritten to make sure the content accurately reflects the
1265 current display in the agenda."
1266 :group 'org-agenda-daily/weekly
1267 :type 'plist)
1269 (defcustom org-agenda-search-view-always-boolean nil
1270 "Non-nil means the search string is interpreted as individual parts.
1272 The search string for search view can either be interpreted as a phrase,
1273 or as a list of snippets that define a boolean search for a number of
1274 strings.
1276 When this is non-nil, the string will be split on whitespace, and each
1277 snippet will be searched individually, and all must match in order to
1278 select an entry. A snippet is then a single string of non-white
1279 characters, or a string in double quotes, or a regexp in {} braces.
1280 If a snippet is preceded by \"-\", the snippet must *not* match.
1281 \"+\" is syntactic sugar for positive selection. Each snippet may
1282 be found as a full word or a partial word, but see the variable
1283 `org-agenda-search-view-force-full-words'.
1285 When this is nil, search will look for the entire search phrase as one,
1286 with each space character matching any amount of whitespace, including
1287 line breaks.
1289 Even when this is nil, you can still switch to Boolean search dynamically
1290 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1291 is a regexp marked with braces like \"{abc}\", this will also switch to
1292 boolean search."
1293 :group 'org-agenda-search-view
1294 :version "24.1"
1295 :type 'boolean)
1297 (if (fboundp 'defvaralias)
1298 (defvaralias 'org-agenda-search-view-search-words-only
1299 'org-agenda-search-view-always-boolean))
1301 (defcustom org-agenda-search-view-force-full-words nil
1302 "Non-nil means, search words must be matches as complete words.
1303 When nil, they may also match part of a word."
1304 :group 'org-agenda-search-view
1305 :version "24.1"
1306 :type 'boolean)
1308 (defgroup org-agenda-time-grid nil
1309 "Options concerning the time grid in the Org-mode Agenda."
1310 :tag "Org Agenda Time Grid"
1311 :group 'org-agenda)
1313 (defcustom org-agenda-search-headline-for-time t
1314 "Non-nil means search headline for a time-of-day.
1315 If the headline contains a time-of-day in one format or another, it will
1316 be used to sort the entry into the time sequence of items for a day.
1317 Some people have time stamps in the headline that refer to the creation
1318 time or so, and then this produces an unwanted side effect. If this is
1319 the case for your, use this variable to turn off searching the headline
1320 for a time."
1321 :group 'org-agenda-time-grid
1322 :type 'boolean)
1324 (defcustom org-agenda-use-time-grid t
1325 "Non-nil means show a time grid in the agenda schedule.
1326 A time grid is a set of lines for specific times (like every two hours between
1327 8:00 and 20:00). The items scheduled for a day at specific times are
1328 sorted in between these lines.
1329 For details about when the grid will be shown, and what it will look like, see
1330 the variable `org-agenda-time-grid'."
1331 :group 'org-agenda-time-grid
1332 :type 'boolean)
1334 (defcustom org-agenda-time-grid
1335 '((daily today require-timed)
1336 "----------------"
1337 (800 1000 1200 1400 1600 1800 2000))
1339 "The settings for time grid for agenda display.
1340 This is a list of three items. The first item is again a list. It contains
1341 symbols specifying conditions when the grid should be displayed:
1343 daily if the agenda shows a single day
1344 weekly if the agenda shows an entire week
1345 today show grid on current date, independent of daily/weekly display
1346 require-timed show grid only if at least one item has a time specification
1348 The second item is a string which will be placed behind the grid time.
1350 The third item is a list of integers, indicating the times that should have
1351 a grid line."
1352 :group 'org-agenda-time-grid
1353 :type
1354 '(list
1355 (set :greedy t :tag "Grid Display Options"
1356 (const :tag "Show grid in single day agenda display" daily)
1357 (const :tag "Show grid in weekly agenda display" weekly)
1358 (const :tag "Always show grid for today" today)
1359 (const :tag "Show grid only if any timed entries are present"
1360 require-timed)
1361 (const :tag "Skip grid times already present in an entry"
1362 remove-match))
1363 (string :tag "Grid String")
1364 (repeat :tag "Grid Times" (integer :tag "Time"))))
1366 (defcustom org-agenda-show-current-time-in-grid t
1367 "Non-nil means show the current time in the time grid."
1368 :group 'org-agenda-time-grid
1369 :version "24.1"
1370 :type 'boolean)
1372 (defcustom org-agenda-current-time-string
1373 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1374 "The string for the current time marker in the agenda."
1375 :group 'org-agenda-time-grid
1376 :version "24.1"
1377 :type 'string)
1379 (defgroup org-agenda-sorting nil
1380 "Options concerning sorting in the Org-mode Agenda."
1381 :tag "Org Agenda Sorting"
1382 :group 'org-agenda)
1384 (defcustom org-agenda-sorting-strategy
1385 '((agenda habit-down time-up priority-down category-keep)
1386 (todo priority-down category-keep)
1387 (tags priority-down category-keep)
1388 (search category-keep))
1389 "Sorting structure for the agenda items of a single day.
1390 This is a list of symbols which will be used in sequence to determine
1391 if an entry should be listed before another entry. The following
1392 symbols are recognized:
1394 time-up Put entries with time-of-day indications first, early first
1395 time-down Put entries with time-of-day indications first, late first
1396 category-keep Keep the default order of categories, corresponding to the
1397 sequence in `org-agenda-files'.
1398 category-up Sort alphabetically by category, A-Z.
1399 category-down Sort alphabetically by category, Z-A.
1400 tag-up Sort alphabetically by last tag, A-Z.
1401 tag-down Sort alphabetically by last tag, Z-A.
1402 priority-up Sort numerically by priority, high priority last.
1403 priority-down Sort numerically by priority, high priority first.
1404 todo-state-up Sort by todo state, tasks that are done last.
1405 todo-state-down Sort by todo state, tasks that are done first.
1406 effort-up Sort numerically by estimated effort, high effort last.
1407 effort-down Sort numerically by estimated effort, high effort first.
1408 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1409 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1410 habit-up Put entries that are habits first
1411 habit-down Put entries that are habits last
1412 alpha-up Sort headlines alphabetically
1413 alpha-down Sort headlines alphabetically, reversed
1415 The different possibilities will be tried in sequence, and testing stops
1416 if one comparison returns a \"not-equal\". For example, the default
1417 '(time-up category-keep priority-down)
1418 means: Pull out all entries having a specified time of day and sort them,
1419 in order to make a time schedule for the current day the first thing in the
1420 agenda listing for the day. Of the entries without a time indication, keep
1421 the grouped in categories, don't sort the categories, but keep them in
1422 the sequence given in `org-agenda-files'. Within each category sort by
1423 priority.
1425 Leaving out `category-keep' would mean that items will be sorted across
1426 categories by priority.
1428 Instead of a single list, this can also be a set of list for specific
1429 contents, with a context symbol in the car of the list, any of
1430 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1432 Custom commands can bind this variable in the options section."
1433 :group 'org-agenda-sorting
1434 :type `(choice
1435 (repeat :tag "General" ,org-sorting-choice)
1436 (list :tag "Individually"
1437 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1438 (repeat ,org-sorting-choice))
1439 (cons (const :tag "Strategy for TODO lists" todo)
1440 (repeat ,org-sorting-choice))
1441 (cons (const :tag "Strategy for Tags matches" tags)
1442 (repeat ,org-sorting-choice))
1443 (cons (const :tag "Strategy for search matches" search)
1444 (repeat ,org-sorting-choice)))))
1446 (defcustom org-agenda-cmp-user-defined nil
1447 "A function to define the comparison `user-defined'.
1448 This function must receive two arguments, agenda entry a and b.
1449 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1450 the user comparison, return nil.
1451 When this is defined, you can make `user-defined-up' and `user-defined-down'
1452 part of an agenda sorting strategy."
1453 :group 'org-agenda-sorting
1454 :type 'symbol)
1456 (defcustom org-sort-agenda-notime-is-late t
1457 "Non-nil means items without time are considered late.
1458 This is only relevant for sorting. When t, items which have no explicit
1459 time like 15:30 will be considered as 99:01, i.e. later than any items which
1460 do have a time. When nil, the default time is before 0:00. You can use this
1461 option to decide if the schedule for today should come before or after timeless
1462 agenda entries."
1463 :group 'org-agenda-sorting
1464 :type 'boolean)
1466 (defcustom org-sort-agenda-noeffort-is-high t
1467 "Non-nil means items without effort estimate are sorted as high effort.
1468 This also applies when filtering an agenda view with respect to the
1469 < or > effort operator. Then, tasks with no effort defined will be treated
1470 as tasks with high effort.
1471 When nil, such items are sorted as 0 minutes effort."
1472 :group 'org-agenda-sorting
1473 :type 'boolean)
1475 (defgroup org-agenda-line-format nil
1476 "Options concerning the entry prefix in the Org-mode agenda display."
1477 :tag "Org Agenda Line Format"
1478 :group 'org-agenda)
1480 (defcustom org-agenda-prefix-format
1481 '((agenda . " %i %-12:c%?-12t% s")
1482 (timeline . " % s")
1483 (todo . " %i %-12:c")
1484 (tags . " %i %-12:c")
1485 (search . " %i %-12:c"))
1486 "Format specifications for the prefix of items in the agenda views.
1487 An alist with five entries, each for the different agenda types. The
1488 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1489 The values are format strings.
1491 This format works similar to a printf format, with the following meaning:
1493 %c the category of the item, \"Diary\" for entries from the diary,
1494 or as given by the CATEGORY keyword or derived from the file name
1495 %e the effort required by the item
1496 %i the icon category of the item, see `org-agenda-category-icon-alist'
1497 %T the last tag of the item (ignore inherited tags, which come first)
1498 %t the HH:MM time-of-day specification if one applies to the entry
1499 %s Scheduling/Deadline information, a short string
1500 %(expression) Eval EXPRESSION and replace the control string
1501 by the result
1503 All specifiers work basically like the standard `%s' of printf, but may
1504 contain two additional characters: a question mark just after the `%'
1505 and a whitespace/punctuation character just before the final letter.
1507 If the first character after `%' is a question mark, the entire field
1508 will only be included if the corresponding value applies to the current
1509 entry. This is useful for fields which should have fixed width when
1510 present, but zero width when absent. For example, \"%?-12t\" will
1511 result in a 12 character time field if a time of the day is specified,
1512 but will completely disappear in entries which do not contain a time.
1514 If there is punctuation or whitespace character just before the final
1515 format letter, this character will be appended to the field value if
1516 the value is not empty. For example, the format \"%-12:c\" leads to
1517 \"Diary: \" if the category is \"Diary\". If the category were be
1518 empty, no additional colon would be inserted.
1520 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1521 which means:
1523 - Indent the line with two space characters
1524 - Give the category a 12 chars wide field, padded with whitespace on
1525 the right (because of `-'). Append a colon if there is a category
1526 (because of `:').
1527 - If there is a time-of-day, put it into a 12 chars wide field. If no
1528 time, don't put in an empty field, just skip it (because of '?').
1529 - Finally, put the scheduling information.
1531 See also the variables `org-agenda-remove-times-when-in-prefix' and
1532 `org-agenda-remove-tags'.
1534 Custom commands can set this variable in the options section."
1535 :type '(choice
1536 (string :tag "General format")
1537 (list :greedy t :tag "View dependent"
1538 (cons (const agenda) (string :tag "Format"))
1539 (cons (const timeline) (string :tag "Format"))
1540 (cons (const todo) (string :tag "Format"))
1541 (cons (const tags) (string :tag "Format"))
1542 (cons (const search) (string :tag "Format"))))
1543 :group 'org-agenda-line-format)
1545 (defvar org-prefix-format-compiled nil
1546 "The compiled prefix format and associated variables.
1547 This is a list where first element is a list of variable bindings, and second
1548 element is the compiled format expression. See the variable
1549 `org-agenda-prefix-format'.")
1551 (defcustom org-agenda-todo-keyword-format "%-1s"
1552 "Format for the TODO keyword in agenda lines.
1553 Set this to something like \"%-12s\" if you want all TODO keywords
1554 to occupy a fixed space in the agenda display."
1555 :group 'org-agenda-line-format
1556 :type 'string)
1558 (defcustom org-agenda-diary-sexp-prefix nil
1559 "A regexp that matches part of a diary sexp entry
1560 which should be treated as scheduling/deadline information in
1561 `org-agenda'.
1563 For example, you can use this to extract the `diary-remind-message' from
1564 `diary-remind' entries."
1565 :group 'org-agenda-line-format
1566 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1568 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1569 "Text preceding timerange entries in the agenda view.
1570 This is a list with two strings. The first applies when the range
1571 is entirely on one day. The second applies if the range spans several days.
1572 The strings may have two \"%d\" format specifiers which will be filled
1573 with the sequence number of the days, and the total number of days in the
1574 range, respectively."
1575 :group 'org-agenda-line-format
1576 :type '(list
1577 (string :tag "Deadline today ")
1578 (choice :tag "Deadline relative"
1579 (string :tag "Format string")
1580 (function))))
1582 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1583 "Text preceding scheduled items in the agenda view.
1584 This is a list with two strings. The first applies when the item is
1585 scheduled on the current day. The second applies when it has been scheduled
1586 previously, it may contain a %d indicating that this is the nth time that
1587 this item is scheduled, due to automatic rescheduling of unfinished items
1588 for the following day. So this number is one larger than the number of days
1589 that passed since this item was scheduled first."
1590 :group 'org-agenda-line-format
1591 :type '(list
1592 (string :tag "Scheduled today ")
1593 (string :tag "Scheduled previously")))
1595 (defcustom org-agenda-inactive-leader "["
1596 "Text preceding item pulled into the agenda by inactive time stamps.
1597 These entries are added to the agenda when pressing \"[\"."
1598 :group 'org-agenda-line-format
1599 :version "24.1"
1600 :type '(list
1601 (string :tag "Scheduled today ")
1602 (string :tag "Scheduled previously")))
1604 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1605 "Text preceding deadline items in the agenda view.
1606 This is a list with two strings. The first applies when the item has its
1607 deadline on the current day. The second applies when it is in the past or
1608 in the future, it may contain %d to capture how many days away the deadline
1609 is (was)."
1610 :group 'org-agenda-line-format
1611 :type '(list
1612 (string :tag "Deadline today ")
1613 (choice :tag "Deadline relative"
1614 (string :tag "Format string")
1615 (function))))
1617 (defcustom org-agenda-remove-times-when-in-prefix t
1618 "Non-nil means remove duplicate time specifications in agenda items.
1619 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1620 time-of-day specification in a headline or diary entry is extracted and
1621 placed into the prefix. If this option is non-nil, the original specification
1622 \(a timestamp or -range, or just a plain time(range) specification like
1623 11:30-4pm) will be removed for agenda display. This makes the agenda less
1624 cluttered.
1625 The option can be t or nil. It may also be the symbol `beg', indicating
1626 that the time should only be removed when it is located at the beginning of
1627 the headline/diary entry."
1628 :group 'org-agenda-line-format
1629 :type '(choice
1630 (const :tag "Always" t)
1631 (const :tag "Never" nil)
1632 (const :tag "When at beginning of entry" beg)))
1634 (defcustom org-agenda-remove-timeranges-from-blocks nil
1635 "Non-nil means remove time ranges specifications in agenda
1636 items that span on several days."
1637 :group 'org-agenda-line-format
1638 :version "24.1"
1639 :type 'boolean)
1641 (defcustom org-agenda-default-appointment-duration nil
1642 "Default duration for appointments that only have a starting time.
1643 When nil, no duration is specified in such cases.
1644 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1645 :group 'org-agenda-line-format
1646 :type '(choice
1647 (integer :tag "Minutes")
1648 (const :tag "No default duration")))
1650 (defcustom org-agenda-show-inherited-tags t
1651 "Non-nil means show inherited tags in each agenda line.
1653 When this option is set to 'always, it take precedences over
1654 `org-agenda-use-tag-inheritance' and inherited tags are shown
1655 in every agenda.
1657 When this option is set to t (the default), inherited tags are
1658 shown when they are available, i.e. when the value of
1659 `org-agenda-use-tag-inheritance' has been taken into account.
1661 This can be set to a list of agenda types in which the agenda
1662 must display the inherited tags. Available types are 'todo,
1663 'agenda, 'search and 'timeline.
1665 When set to nil, never show inherited tags in agenda lines."
1666 :group 'org-agenda-line-format
1667 :group 'org-agenda
1668 :version "24.3"
1669 :type '(choice
1670 (const :tag "Show inherited tags when available" t)
1671 (const :tag "Always show inherited tags" 'always)
1672 (repeat :tag "Show inherited tags only in selected agenda types"
1673 (symbol :tag "Agenda type"))))
1675 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1676 "List of agenda view types where to use tag inheritance.
1678 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1679 controlled by `org-use-tag-inheritance'. In other agenda types,
1680 `org-use-tag-inheritance' is not used for the selection of the
1681 agenda entries. Still, you may want the agenda to be aware of
1682 the inherited tags anyway, e.g. for later tag filtering.
1684 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1686 This variable has no effect if `org-agenda-show-inherited-tags'
1687 is set to 'always. In that case, the agenda is aware of those
1688 tags.
1690 The default value sets tags in every agenda type. Setting this
1691 option to nil will speed up non-tags agenda view a lot."
1692 :group 'org-agenda
1693 :version "24.3"
1694 :type '(choice
1695 (const :tag "Use tag inheritance in all agenda types" t)
1696 (repeat :tag "Use tag inheritance in selected agenda types"
1697 (symbol :tag "Agenda type"))))
1699 (defcustom org-agenda-hide-tags-regexp nil
1700 "Regular expression used to filter away specific tags in agenda views.
1701 This means that these tags will be present, but not be shown in the agenda
1702 line. Secondary filtering will still work on the hidden tags.
1703 Nil means don't hide any tags."
1704 :group 'org-agenda-line-format
1705 :type '(choice
1706 (const :tag "Hide none" nil)
1707 (string :tag "Regexp ")))
1709 (defcustom org-agenda-remove-tags nil
1710 "Non-nil means remove the tags from the headline copy in the agenda.
1711 When this is the symbol `prefix', only remove tags when
1712 `org-agenda-prefix-format' contains a `%T' specifier."
1713 :group 'org-agenda-line-format
1714 :type '(choice
1715 (const :tag "Always" t)
1716 (const :tag "Never" nil)
1717 (const :tag "When prefix format contains %T" prefix)))
1719 (if (fboundp 'defvaralias)
1720 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1721 'org-agenda-remove-tags))
1723 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1724 "Shift tags in agenda items to this column.
1725 If this number is positive, it specifies the column. If it is negative,
1726 it means that the tags should be flushright to that column. For example,
1727 -80 works well for a normal 80 character screen."
1728 :group 'org-agenda-line-format
1729 :type 'integer)
1731 (if (fboundp 'defvaralias)
1732 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1734 (defcustom org-agenda-fontify-priorities 'cookies
1735 "Non-nil means highlight low and high priorities in agenda.
1736 When t, the highest priority entries are bold, lowest priority italic.
1737 However, settings in `org-priority-faces' will overrule these faces.
1738 When this variable is the symbol `cookies', only fontify the
1739 cookies, not the entire task.
1740 This may also be an association list of priority faces, whose
1741 keys are the character values of `org-highest-priority',
1742 `org-default-priority', and `org-lowest-priority' (the default values
1743 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1744 color as a string, or a list like `(:background \"Red\")'.
1745 If it is a color, the variable `org-faces-easy-properties'
1746 determines if it is a foreground or a background color."
1747 :group 'org-agenda-line-format
1748 :type '(choice
1749 (const :tag "Never" nil)
1750 (const :tag "Defaults" t)
1751 (const :tag "Cookies only" cookies)
1752 (repeat :tag "Specify"
1753 (list (character :tag "Priority" :value ?A)
1754 (choice :tag "Face "
1755 (string :tag "Color")
1756 (sexp :tag "Face"))))))
1758 (defcustom org-agenda-day-face-function nil
1759 "Function called to determine what face should be used to display a day.
1760 The only argument passed to that function is the day. It should
1761 returns a face, or nil if does not want to specify a face and let
1762 the normal rules apply."
1763 :group 'org-agenda-line-format
1764 :version "24.1"
1765 :type 'function)
1767 (defcustom org-agenda-category-icon-alist nil
1768 "Alist of category icon to be displayed in agenda views.
1770 Each entry should have the following format:
1772 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1774 Where CATEGORY-REGEXP is a regexp matching the categories where
1775 the icon should be displayed.
1776 FILE-OR-DATA either a file path or a string containing image data.
1778 The other fields can be omitted safely if not needed:
1779 TYPE indicates the image type.
1780 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1781 image data.
1782 PROPS are additional image attributes to assign to the image,
1783 like, e.g. `:ascent center'.
1785 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1787 If you want to set the display properties yourself, just put a
1788 list as second element:
1790 (CATEGORY-REGEXP (MY PROPERTY LIST))
1792 For example, to display a 16px horizontal space for Emacs
1793 category, you can use:
1795 (\"Emacs\" '(space . (:width (16))))"
1796 :group 'org-agenda-line-format
1797 :version "24.1"
1798 :type '(alist :key-type (string :tag "Regexp matching category")
1799 :value-type (choice (list :tag "Icon"
1800 (string :tag "File or data")
1801 (symbol :tag "Type")
1802 (boolean :tag "Data?")
1803 (repeat :tag "Extra image properties" :inline t symbol))
1804 (list :tag "Display properties" sexp))))
1806 (defgroup org-agenda-column-view nil
1807 "Options concerning column view in the agenda."
1808 :tag "Org Agenda Column View"
1809 :group 'org-agenda)
1811 (defcustom org-agenda-columns-show-summaries t
1812 "Non-nil means show summaries for columns displayed in the agenda view."
1813 :group 'org-agenda-column-view
1814 :type 'boolean)
1816 (defcustom org-agenda-columns-compute-summary-properties t
1817 "Non-nil means recompute all summary properties before column view.
1818 When column view in the agenda is listing properties that have a summary
1819 operator, it can go to all relevant buffers and recompute the summaries
1820 there. This can mean overhead for the agenda column view, but is necessary
1821 to have thing up to date.
1822 As a special case, a CLOCKSUM property also makes sure that the clock
1823 computations are current."
1824 :group 'org-agenda-column-view
1825 :type 'boolean)
1827 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1828 "Non-nil means the duration of an appointment will add to day effort.
1829 The property to which appointment durations will be added is the one given
1830 in the option `org-effort-property'. If an appointment does not have
1831 an end time, `org-agenda-default-appointment-duration' will be used. If that
1832 is not set, an appointment without end time will not contribute to the time
1833 estimate."
1834 :group 'org-agenda-column-view
1835 :type 'boolean)
1837 (defcustom org-agenda-auto-exclude-function nil
1838 "A function called with a tag to decide if it is filtered on '/ RET'.
1839 The sole argument to the function, which is called once for each
1840 possible tag, is a string giving the name of the tag. The
1841 function should return either nil if the tag should be included
1842 as normal, or \"-<TAG>\" to exclude the tag.
1843 Note that for the purpose of tag filtering, only the lower-case version of
1844 all tags will be considered, so that this function will only ever see
1845 the lower-case version of all tags."
1846 :group 'org-agenda
1847 :type 'function)
1849 (defcustom org-agenda-bulk-custom-functions nil
1850 "Alist of characters and custom functions for bulk actions.
1851 For example, this value makes those two functions available:
1853 '((?R set-category)
1854 (?C bulk-cut))
1856 With selected entries in an agenda buffer, `B R' will call
1857 the custom function `set-category' on the selected entries.
1858 Note that functions in this alist don't need to be quoted."
1859 :type 'alist
1860 :version "24.1"
1861 :group 'org-agenda)
1863 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1864 "Execute BODY with point at location given by `org-hd-marker' property.
1865 If STRING is non-nil, the text property will be fetched from position 0
1866 in that string. If STRING is nil, it will be fetched from the beginning
1867 of the current line."
1868 (org-with-gensyms (marker)
1869 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1870 'org-hd-marker ,string)))
1871 (with-current-buffer (marker-buffer ,marker)
1872 (save-excursion
1873 (goto-char ,marker)
1874 ,@body)))))
1875 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1877 (defun org-add-agenda-custom-command (entry)
1878 "Replace or add a command in `org-agenda-custom-commands'.
1879 This is mostly for hacking and trying a new command - once the command
1880 works you probably want to add it to `org-agenda-custom-commands' for good."
1881 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1882 (if ass
1883 (setcdr ass (cdr entry))
1884 (push entry org-agenda-custom-commands))))
1886 ;;; Define the org-agenda-mode
1888 (defvar org-agenda-mode-map (make-sparse-keymap)
1889 "Keymap for `org-agenda-mode'.")
1890 (if (fboundp 'defvaralias)
1891 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1893 (defvar org-agenda-menu) ; defined later in this file.
1894 (defvar org-agenda-restrict nil) ; defined later in this file.
1895 (defvar org-agenda-follow-mode nil)
1896 (defvar org-agenda-entry-text-mode nil)
1897 (defvar org-agenda-clockreport-mode nil)
1898 (defvar org-agenda-show-log nil)
1899 (defvar org-agenda-redo-command nil)
1900 (defvar org-agenda-query-string nil)
1901 (defvar org-agenda-mode-hook nil
1902 "Hook run after `org-agenda-mode' is turned on.
1903 The buffer is still writable when this hook is called.")
1904 (defvar org-agenda-type nil)
1905 (defvar org-agenda-force-single-file nil)
1906 (defvar org-agenda-bulk-marked-entries nil
1907 "List of markers that refer to marked entries in the agenda.")
1909 ;;; Multiple agenda buffers support
1911 (defcustom org-agenda-sticky nil
1912 "Non-nil means agenda q key will bury agenda buffers.
1913 Agenda commands will then show existing buffer instead of generating new ones.
1914 When nil, `q' will kill the single agenda buffer."
1915 :group 'org-agenda
1916 :version "24.3"
1917 :type 'boolean)
1920 ;;;###autoload
1921 (defun org-toggle-sticky-agenda (&optional arg)
1922 "Toggle `org-agenda-sticky'."
1923 (interactive "P")
1924 (let ((new-value (if arg
1925 (> (prefix-numeric-value arg) 0)
1926 (not org-agenda-sticky))))
1927 (if (equal new-value org-agenda-sticky)
1928 (and (org-called-interactively-p 'interactive)
1929 (message "Sticky agenda was already %s"
1930 (if org-agenda-sticky "enabled" "disabled")))
1931 (setq org-agenda-sticky new-value)
1932 (org-agenda-kill-all-agenda-buffers)
1933 (and (org-called-interactively-p 'interactive)
1934 (message "Sticky agenda was %s"
1935 (if org-agenda-sticky "enabled" "disabled"))))))
1937 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1938 Toggle `org-agenda-sticky'.
1940 \(fn &optional ARG)" t nil)
1942 (defvar org-agenda-buffer nil
1943 "Agenda buffer currently being generated.")
1945 (defvar org-agenda-last-prefix-arg nil)
1946 (defvar org-agenda-this-buffer-name nil)
1947 (defvar org-agenda-doing-sticky-redo nil)
1948 (defvar org-agenda-this-buffer-is-sticky nil)
1950 (defconst org-agenda-local-vars
1951 '(org-agenda-this-buffer-name
1952 org-agenda-undo-list
1953 org-agenda-pending-undo-list
1954 org-agenda-follow-mode
1955 org-agenda-entry-text-mode
1956 org-agenda-clockreport-mode
1957 org-agenda-show-log
1958 org-agenda-redo-command
1959 org-agenda-query-string
1960 org-agenda-type
1961 org-agenda-bulk-marked-entries
1962 org-agenda-undo-has-started-in
1963 org-agenda-info
1964 org-agenda-tag-filter-overlays
1965 org-agenda-cat-filter-overlays
1966 org-agenda-pre-window-conf
1967 org-agenda-columns-active
1968 org-agenda-tag-filter
1969 org-agenda-category-filter
1970 org-agenda-markers
1971 org-agenda-last-search-view-search-was-boolean
1972 org-agenda-filtered-by-category
1973 org-agenda-filter-form
1974 org-agenda-show-window
1975 org-agenda-cycle-counter
1976 org-agenda-last-prefix-arg)
1977 "Variables that must be local in agenda buffers to allow multiple buffers.")
1979 (defun org-agenda-mode ()
1980 "Mode for time-sorted view on action items in Org-mode files.
1982 The following commands are available:
1984 \\{org-agenda-mode-map}"
1985 (interactive)
1986 (cond (org-agenda-doing-sticky-redo
1987 ;; Refreshing sticky agenda-buffer
1989 ;; Preserve the value of `org-agenda-local-vars' variables,
1990 ;; while letting `kill-all-local-variables' kill the rest
1991 (let ((save (buffer-local-variables)))
1992 (kill-all-local-variables)
1993 (mapc 'make-local-variable org-agenda-local-vars)
1994 (dolist (elem save)
1995 (let ((var (car elem))
1996 (val (cdr elem)))
1997 (when (and val
1998 (member var org-agenda-local-vars))
1999 (set var val)))))
2000 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2001 (org-agenda-sticky
2002 ;; Creating a sticky Agenda buffer for the first time
2003 (kill-all-local-variables)
2004 (mapc 'make-local-variable org-agenda-local-vars)
2005 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2007 ;; Creating a non-sticky agenda buffer
2008 (kill-all-local-variables)
2009 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2010 (setq org-agenda-undo-list nil
2011 org-agenda-pending-undo-list nil
2012 org-agenda-bulk-marked-entries nil)
2013 (setq major-mode 'org-agenda-mode)
2014 ;; Keep global-font-lock-mode from turning on font-lock-mode
2015 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2016 (setq mode-name "Org-Agenda")
2017 (use-local-map org-agenda-mode-map)
2018 (easy-menu-add org-agenda-menu)
2019 (if org-startup-truncated (setq truncate-lines t))
2020 (org-set-local 'line-move-visual nil)
2021 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2022 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2023 ;; Make sure properties are removed when copying text
2024 (make-local-variable 'filter-buffer-substring-functions)
2025 (add-hook 'filter-buffer-substring-functions
2026 (lambda (fun start end delete)
2027 (substring-no-properties (funcall fun start end delete))))
2028 (unless org-agenda-keep-modes
2029 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2030 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2031 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2032 org-agenda-show-log org-agenda-start-with-log-mode))
2034 (easy-menu-change
2035 '("Agenda") "Agenda Files"
2036 (append
2037 (list
2038 (vector
2039 (if (get 'org-agenda-files 'org-restrict)
2040 "Restricted to single file"
2041 "Edit File List")
2042 '(org-edit-agenda-file-list)
2043 (not (get 'org-agenda-files 'org-restrict)))
2044 "--")
2045 (mapcar 'org-file-menu-entry (org-agenda-files))))
2046 (org-agenda-set-mode-name)
2047 (apply
2048 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2049 (list 'org-agenda-mode-hook)))
2051 (substitute-key-definition 'undo 'org-agenda-undo
2052 org-agenda-mode-map global-map)
2053 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2054 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2055 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2056 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2057 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2058 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2059 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2060 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2061 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2062 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2063 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2064 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2065 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2066 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2067 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2068 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2069 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2070 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2071 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2072 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2073 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2074 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2075 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2076 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2077 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2078 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2079 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2080 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2081 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2082 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2083 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2084 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2085 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2086 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2087 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2088 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2089 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2090 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2091 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2092 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2093 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2094 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2095 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2096 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2097 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2098 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2100 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2101 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2102 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2103 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2104 (while l (org-defkey org-agenda-mode-map
2105 (int-to-string (pop l)) 'digit-argument)))
2107 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2108 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2109 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2110 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2111 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2112 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2113 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2114 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2115 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2116 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2117 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2118 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2119 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2120 'org-clock-modify-effort-estimate)
2121 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2122 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2123 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2124 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2125 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2126 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2127 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2128 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2129 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2130 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2131 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2132 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2133 (substitute-key-definition 'next-line 'org-agenda-next-line
2134 org-agenda-mode-map global-map)
2135 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2136 org-agenda-mode-map global-map)
2137 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2138 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2139 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2140 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2141 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2142 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2143 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2144 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2145 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2146 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2147 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2148 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2149 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2150 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2151 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2152 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2153 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2154 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2155 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2156 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2157 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2158 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2159 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2160 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2161 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2162 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2163 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2164 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2165 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2166 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2168 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2169 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2170 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2171 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2172 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2173 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2174 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2175 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2176 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2177 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2178 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2179 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2181 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2182 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2183 (when org-agenda-mouse-1-follows-link
2184 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2185 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2186 '("Agenda"
2187 ("Agenda Files")
2188 "--"
2189 ("Agenda Dates"
2190 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2191 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2192 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2193 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2194 "--"
2195 ("View"
2196 ["Day View" org-agenda-day-view
2197 :active (org-agenda-check-type nil 'agenda)
2198 :style radio :selected (eq org-agenda-current-span 'day)
2199 :keys "v d (or just d)"]
2200 ["Week View" org-agenda-week-view
2201 :active (org-agenda-check-type nil 'agenda)
2202 :style radio :selected (eq org-agenda-current-span 'week)
2203 :keys "v w (or just w)"]
2204 ["Month View" org-agenda-month-view
2205 :active (org-agenda-check-type nil 'agenda)
2206 :style radio :selected (eq org-agenda-current-span 'month)
2207 :keys "v m"]
2208 ["Year View" org-agenda-year-view
2209 :active (org-agenda-check-type nil 'agenda)
2210 :style radio :selected (eq org-agenda-current-span 'year)
2211 :keys "v y"]
2212 "--"
2213 ["Include Diary" org-agenda-toggle-diary
2214 :style toggle :selected org-agenda-include-diary
2215 :active (org-agenda-check-type nil 'agenda)]
2216 ["Include Deadlines" org-agenda-toggle-deadlines
2217 :style toggle :selected org-agenda-include-deadlines
2218 :active (org-agenda-check-type nil 'agenda)]
2219 ["Use Time Grid" org-agenda-toggle-time-grid
2220 :style toggle :selected org-agenda-use-time-grid
2221 :active (org-agenda-check-type nil 'agenda)]
2222 "--"
2223 ["Show clock report" org-agenda-clockreport-mode
2224 :style toggle :selected org-agenda-clockreport-mode
2225 :active (org-agenda-check-type nil 'agenda)]
2226 ["Show some entry text" org-agenda-entry-text-mode
2227 :style toggle :selected org-agenda-entry-text-mode
2228 :active t]
2229 "--"
2230 ["Show Logbook entries" org-agenda-log-mode
2231 :style toggle :selected org-agenda-show-log
2232 :active (org-agenda-check-type nil 'agenda 'timeline)
2233 :keys "v l (or just l)"]
2234 ["Include archived trees" org-agenda-archives-mode
2235 :style toggle :selected org-agenda-archives-mode :active t
2236 :keys "v a"]
2237 ["Include archive files" (org-agenda-archives-mode t)
2238 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2239 :keys "v A"]
2240 "--"
2241 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2242 ["Write view to file" org-agenda-write t]
2243 ["Rebuild buffer" org-agenda-redo t]
2244 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2245 "--"
2246 ["Show original entry" org-agenda-show t]
2247 ["Go To (other window)" org-agenda-goto t]
2248 ["Go To (this window)" org-agenda-switch-to t]
2249 ["Capture with cursor date" org-agenda-capture t]
2250 ["Follow Mode" org-agenda-follow-mode
2251 :style toggle :selected org-agenda-follow-mode :active t]
2252 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2253 "--"
2254 ("TODO"
2255 ["Cycle TODO" org-agenda-todo t]
2256 ["Next TODO set" org-agenda-todo-nextset t]
2257 ["Previous TODO set" org-agenda-todo-previousset t]
2258 ["Add note" org-agenda-add-note t])
2259 ("Archive/Refile/Delete"
2260 ["Archive default" org-agenda-archive-default t]
2261 ["Archive default" org-agenda-archive-default-with-confirmation t]
2262 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2263 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2264 ["Archive subtree" org-agenda-archive t]
2265 "--"
2266 ["Refile" org-agenda-refile t]
2267 "--"
2268 ["Delete subtree" org-agenda-kill t])
2269 ("Bulk action"
2270 ["Mark entry" org-agenda-bulk-mark t]
2271 ["Mark all" org-agenda-bulk-mark-all t]
2272 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2273 ["Unmark entry" org-agenda-bulk-unmark t]
2274 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2275 ["Act on all marked" org-agenda-bulk-action t]
2276 "--"
2277 ("Tags and Properties"
2278 ["Show all Tags" org-agenda-show-tags t]
2279 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2280 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2281 "--"
2282 ["Column View" org-columns t])
2283 ("Deadline/Schedule"
2284 ["Schedule" org-agenda-schedule t]
2285 ["Set Deadline" org-agenda-deadline t]
2286 "--"
2287 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2288 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2289 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2290 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2291 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2292 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2293 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2294 ("Clock and Effort"
2295 ["Clock in" org-agenda-clock-in t]
2296 ["Clock out" org-agenda-clock-out t]
2297 ["Clock cancel" org-agenda-clock-cancel t]
2298 ["Goto running clock" org-clock-goto t]
2299 "--"
2300 ["Set Effort" org-agenda-set-effort t]
2301 ["Change clocked effort" org-clock-modify-effort-estimate
2302 (org-clock-is-active)])
2303 ("Priority"
2304 ["Set Priority" org-agenda-priority t]
2305 ["Increase Priority" org-agenda-priority-up t]
2306 ["Decrease Priority" org-agenda-priority-down t]
2307 ["Show Priority" org-show-priority t])
2308 ("Calendar/Diary"
2309 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2310 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2311 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2312 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2313 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2314 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2315 "--"
2316 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2317 "--"
2318 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2319 "--"
2320 ("MobileOrg"
2321 ["Push Files and Views" org-mobile-push t]
2322 ["Get Captured and Flagged" org-mobile-pull t]
2323 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2324 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2325 "--"
2326 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2327 "--"
2328 ["Quit" org-agenda-quit t]
2329 ["Exit and Release Buffers" org-agenda-exit t]
2332 ;;; Agenda undo
2334 (defvar org-agenda-allow-remote-undo t
2335 "Non-nil means allow remote undo from the agenda buffer.")
2336 (defvar org-agenda-undo-has-started-in nil
2337 "Buffers that have already seen `undo-start' in the current undo sequence.")
2339 (defun org-agenda-undo ()
2340 "Undo a remote editing step in the agenda.
2341 This undoes changes both in the agenda buffer and in the remote buffer
2342 that have been changed along."
2343 (interactive)
2344 (or org-agenda-allow-remote-undo
2345 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2346 (if (not (eq this-command last-command))
2347 (setq org-agenda-undo-has-started-in nil
2348 org-agenda-pending-undo-list org-agenda-undo-list))
2349 (if (not org-agenda-pending-undo-list)
2350 (error "No further undo information"))
2351 (let* ((entry (pop org-agenda-pending-undo-list))
2352 buf line cmd rembuf)
2353 (setq cmd (pop entry) line (pop entry))
2354 (setq rembuf (nth 2 entry))
2355 (org-with-remote-undo rembuf
2356 (while (bufferp (setq buf (pop entry)))
2357 (if (pop entry)
2358 (with-current-buffer buf
2359 (let ((last-undo-buffer buf)
2360 (inhibit-read-only t))
2361 (unless (memq buf org-agenda-undo-has-started-in)
2362 (push buf org-agenda-undo-has-started-in)
2363 (make-local-variable 'pending-undo-list)
2364 (undo-start))
2365 (while (and pending-undo-list
2366 (listp pending-undo-list)
2367 (not (car pending-undo-list)))
2368 (pop pending-undo-list))
2369 (undo-more 1))))))
2370 (org-goto-line line)
2371 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2373 (defun org-verify-change-for-undo (l1 l2)
2374 "Verify that a real change occurred between the undo lists L1 and L2."
2375 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2376 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2377 (not (eq l1 l2)))
2379 ;;; Agenda dispatch
2381 (defvar org-agenda-restrict-begin (make-marker))
2382 (defvar org-agenda-restrict-end (make-marker))
2383 (defvar org-agenda-last-dispatch-buffer nil)
2384 (defvar org-agenda-overriding-restriction nil)
2386 (defcustom org-agenda-custom-commands-contexts nil
2387 "Alist of custom agenda keys and contextual rules.
2389 For example, if you have a custom agenda command \"p\" and you
2390 want this command to be accessible only from plain text files,
2391 use this:
2393 '((\"p\" ((in-file . \"\\.txt\"))))
2395 Here are the available contexts definitions:
2397 in-file: command displayed only in matching files
2398 in-mode: command displayed only in matching modes
2399 not-in-file: command not displayed in matching files
2400 not-in-mode: command not displayed in matching modes
2401 [function]: a custom function taking no argument
2403 If you define several checks, the agenda command will be
2404 accessible if there is at least one valid check.
2406 You can also bind a key to another agenda custom command
2407 depending on contextual rules.
2409 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2411 Here it means: in .txt files, use \"p\" as the key for the
2412 agenda command otherwise associated with \"q\". (The command
2413 originally associated with \"q\" is not displayed to avoid
2414 duplicates.)"
2415 :version "24.3"
2416 :group 'org-agenda-custom-commands
2417 :type '(repeat (list :tag "Rule"
2418 (string :tag " Agenda key")
2419 (string :tag "Replace by command")
2420 (repeat :tag "Available when"
2421 (choice
2422 (cons :tag "Condition"
2423 (choice
2424 (const :tag "In file" in-file)
2425 (const :tag "Not in file" not-in-file)
2426 (const :tag "In mode" in-mode)
2427 (const :tag "Not in mode" not-in-mode))
2428 (regexp))
2429 (function :tag "Custom function"))))))
2431 (defvar org-keys nil)
2432 (defvar org-match nil)
2433 ;;;###autoload
2434 (defun org-agenda (&optional arg org-keys restriction)
2435 "Dispatch agenda commands to collect entries to the agenda buffer.
2436 Prompts for a command to execute. Any prefix arg will be passed
2437 on to the selected command. The default selections are:
2439 a Call `org-agenda-list' to display the agenda for current day or week.
2440 t Call `org-todo-list' to display the global todo list.
2441 T Call `org-todo-list' to display the global todo list, select only
2442 entries with a specific TODO keyword (the user gets a prompt).
2443 m Call `org-tags-view' to display headlines with tags matching
2444 a condition (the user is prompted for the condition).
2445 M Like `m', but select only TODO entries, no ordinary headlines.
2446 L Create a timeline for the current buffer.
2447 e Export views to associated files.
2448 s Search entries for keywords.
2449 S Search entries for keywords, only with TODO keywords.
2450 / Multi occur across all agenda files and also files listed
2451 in `org-agenda-text-search-extra-files'.
2452 < Restrict agenda commands to buffer, subtree, or region.
2453 Press several times to get the desired effect.
2454 > Remove a previous restriction.
2455 # List \"stuck\" projects.
2456 ! Configure what \"stuck\" means.
2457 C Configure custom agenda commands.
2459 More commands can be added by configuring the variable
2460 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2461 searches can be pre-defined in this way.
2463 If the current buffer is in Org-mode and visiting a file, you can also
2464 first press `<' once to indicate that the agenda should be temporarily
2465 \(until the next use of \\[org-agenda]) restricted to the current file.
2466 Pressing `<' twice means to restrict to the current subtree or region
2467 \(if active)."
2468 (interactive "P")
2469 (catch 'exit
2470 (let* ((prefix-descriptions nil)
2471 (org-agenda-buffer-name org-agenda-buffer-name)
2472 (org-agenda-window-setup (if (equal (buffer-name)
2473 org-agenda-buffer-name)
2474 'current-window
2475 org-agenda-window-setup))
2476 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2477 (org-agenda-custom-commands
2478 ;; normalize different versions
2479 (delq nil
2480 (mapcar
2481 (lambda (x)
2482 (cond ((stringp (cdr x))
2483 (push x prefix-descriptions)
2484 nil)
2485 ((stringp (nth 1 x)) x)
2486 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2487 (t (cons (car x) (cons "" (cdr x))))))
2488 org-agenda-custom-commands)))
2489 (org-agenda-custom-commands
2490 (org-contextualize-keys
2491 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2492 (buf (current-buffer))
2493 (bfn (buffer-file-name (buffer-base-buffer)))
2494 entry key type org-match lprops ans)
2495 ;; Turn off restriction unless there is an overriding one,
2496 (unless org-agenda-overriding-restriction
2497 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2498 ;; There is a request to keep the file list in place
2499 (put 'org-agenda-files 'org-restrict nil))
2500 (setq org-agenda-restrict nil)
2501 (move-marker org-agenda-restrict-begin nil)
2502 (move-marker org-agenda-restrict-end nil))
2503 ;; Delete old local properties
2504 (put 'org-agenda-redo-command 'org-lprops nil)
2505 ;; Delete previously set last-arguments
2506 (put 'org-agenda-redo-command 'last-args nil)
2507 ;; Remember where this call originated
2508 (setq org-agenda-last-dispatch-buffer (current-buffer))
2509 (unless org-keys
2510 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2511 org-keys (car ans)
2512 restriction (cdr ans)))
2513 ;; If we have sticky agenda buffers, set a name for the buffer,
2514 ;; depending on the invoking keys. The user may still set this
2515 ;; as a command option, which will overwrite what we do here.
2516 (if org-agenda-sticky
2517 (setq org-agenda-buffer-name
2518 (format "*Org Agenda(%s)*" org-keys)))
2519 ;; Establish the restriction, if any
2520 (when (and (not org-agenda-overriding-restriction) restriction)
2521 (put 'org-agenda-files 'org-restrict (list bfn))
2522 (cond
2523 ((eq restriction 'region)
2524 (setq org-agenda-restrict t)
2525 (move-marker org-agenda-restrict-begin (region-beginning))
2526 (move-marker org-agenda-restrict-end (region-end)))
2527 ((eq restriction 'subtree)
2528 (save-excursion
2529 (setq org-agenda-restrict t)
2530 (org-back-to-heading t)
2531 (move-marker org-agenda-restrict-begin (point))
2532 (move-marker org-agenda-restrict-end
2533 (progn (org-end-of-subtree t)))))))
2535 ;; For example the todo list should not need it (but does...)
2536 (cond
2537 ((setq entry (assoc org-keys org-agenda-custom-commands))
2538 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2539 (progn
2540 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2541 lprops (nth 4 entry))
2542 (if org-agenda-sticky
2543 (setq org-agenda-buffer-name
2544 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2545 (format "*Org Agenda(%s)*" org-keys))))
2546 (put 'org-agenda-redo-command 'org-lprops lprops)
2547 (cond
2548 ((eq type 'agenda)
2549 (org-let lprops '(org-agenda-list current-prefix-arg)))
2550 ((eq type 'alltodo)
2551 (org-let lprops '(org-todo-list current-prefix-arg)))
2552 ((eq type 'search)
2553 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2554 ((eq type 'stuck)
2555 (org-let lprops '(org-agenda-list-stuck-projects
2556 current-prefix-arg)))
2557 ((eq type 'tags)
2558 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2559 ((eq type 'tags-todo)
2560 (org-let lprops '(org-tags-view '(4) org-match)))
2561 ((eq type 'todo)
2562 (org-let lprops '(org-todo-list org-match)))
2563 ((eq type 'tags-tree)
2564 (org-check-for-org-mode)
2565 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2566 ((eq type 'todo-tree)
2567 (org-check-for-org-mode)
2568 (org-let lprops
2569 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2570 (regexp-quote org-match) "\\>"))))
2571 ((eq type 'occur-tree)
2572 (org-check-for-org-mode)
2573 (org-let lprops '(org-occur org-match)))
2574 ((functionp type)
2575 (org-let lprops '(funcall type org-match)))
2576 ((fboundp type)
2577 (org-let lprops '(funcall type org-match)))
2578 (t (error "Invalid custom agenda command type %s" type))))
2579 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2580 ((equal org-keys "C")
2581 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2582 (customize-variable 'org-agenda-custom-commands))
2583 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2584 ((equal org-keys "s") (call-interactively 'org-search-view))
2585 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2586 ((equal org-keys "t") (call-interactively 'org-todo-list))
2587 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2588 ((equal org-keys "m") (call-interactively 'org-tags-view))
2589 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2590 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2591 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2592 (org-add-hook
2593 'post-command-hook
2594 (lambda ()
2595 (unless (current-message)
2596 (let* ((m (org-agenda-get-any-marker))
2597 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2598 (when note
2599 (message (concat
2600 "FLAGGING-NOTE ([?] for more info): "
2601 (org-add-props
2602 (replace-regexp-in-string
2603 "\\\\n" "//"
2604 (copy-sequence note))
2605 nil 'face 'org-warning)))))))
2606 t t))
2607 ((equal org-keys "L")
2608 (unless (derived-mode-p 'org-mode)
2609 (error "This is not an Org-mode file"))
2610 (unless restriction
2611 (put 'org-agenda-files 'org-restrict (list bfn))
2612 (org-call-with-arg 'org-timeline arg)))
2613 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2614 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2615 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2616 (t (error "Invalid agenda key"))))))
2618 (autoload 'org-agenda "org-agenda" "\
2619 Dispatch agenda commands to collect entries to the agenda buffer.
2620 Prompts for a command to execute. Any prefix arg will be passed
2621 on to the selected command. The default selections are:
2623 a Call `org-agenda-list' to display the agenda for current day or week.
2624 t Call `org-todo-list' to display the global todo list.
2625 T Call `org-todo-list' to display the global todo list, select only
2626 entries with a specific TODO keyword (the user gets a prompt).
2627 m Call `org-tags-view' to display headlines with tags matching
2628 a condition (the user is prompted for the condition).
2629 M Like `m', but select only TODO entries, no ordinary headlines.
2630 L Create a timeline for the current buffer.
2631 e Export views to associated files.
2632 s Search entries for keywords.
2633 S Search entries for keywords, only with TODO keywords.
2634 / Multi occur across all agenda files and also files listed
2635 in `org-agenda-text-search-extra-files'.
2636 < Restrict agenda commands to buffer, subtree, or region.
2637 Press several times to get the desired effect.
2638 > Remove a previous restriction.
2639 # List \"stuck\" projects.
2640 ! Configure what \"stuck\" means.
2641 C Configure custom agenda commands.
2643 More commands can be added by configuring the variable
2644 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2645 searches can be pre-defined in this way.
2647 If the current buffer is in Org-mode and visiting a file, you can also
2648 first press `<' once to indicate that the agenda should be temporarily
2649 \(until the next use of \\[org-agenda]) restricted to the current file.
2650 Pressing `<' twice means to restrict to the current subtree or region
2651 \(if active).
2653 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2655 (defun org-agenda-append-agenda ()
2656 "Append another agenda view to the current one.
2657 This function allows interactive building of block agendas.
2658 Agenda views are separated by `org-agenda-block-separator'."
2659 (interactive)
2660 (unless (derived-mode-p 'org-agenda-mode)
2661 (error "Can only append from within agenda buffer"))
2662 (let ((org-agenda-multi t))
2663 (org-agenda)
2664 (widen)
2665 (org-agenda-finalize)
2666 (org-agenda-fit-window-to-buffer)))
2668 (defun org-agenda-normalize-custom-commands (cmds)
2669 (delq nil
2670 (mapcar
2671 (lambda (x)
2672 (cond ((stringp (cdr x)) nil)
2673 ((stringp (nth 1 x)) x)
2674 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2675 (t (cons (car x) (cons "" (cdr x))))))
2676 cmds)))
2678 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2679 "The user interface for selecting an agenda command."
2680 (catch 'exit
2681 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2682 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2683 (region-p (org-region-active-p))
2684 (custom org-agenda-custom-commands)
2685 (selstring "")
2686 restriction second-time
2687 c entry key type match prefixes rmheader header-end custom1 desc
2688 line lines left right n n1)
2689 (save-window-excursion
2690 (delete-other-windows)
2691 (org-switch-to-buffer-other-window " *Agenda Commands*")
2692 (erase-buffer)
2693 (insert (eval-when-compile
2694 (let ((header
2695 "Press key for an agenda command: < Buffer, subtree/region restriction
2696 -------------------------------- > Remove restriction
2697 a Agenda for current week or day e Export agenda views
2698 t List of all TODO entries T Entries with special TODO kwd
2699 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2700 s Search for keywords S Like s, but only TODO entries
2701 L Timeline for current buffer # List stuck projects (!=configure)
2702 / Multi-occur C Configure custom agenda commands
2703 ? Find :FLAGGED: entries * Toggle sticky agenda views
2705 (start 0))
2706 (while (string-match
2707 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2708 header start)
2709 (setq start (match-end 0))
2710 (add-text-properties (match-beginning 2) (match-end 2)
2711 '(face bold) header))
2712 header)))
2713 (setq header-end (point-marker))
2714 (while t
2715 (setq custom1 custom)
2716 (when (eq rmheader t)
2717 (org-goto-line 1)
2718 (re-search-forward ":" nil t)
2719 (delete-region (match-end 0) (point-at-eol))
2720 (forward-char 1)
2721 (looking-at "-+")
2722 (delete-region (match-end 0) (point-at-eol))
2723 (move-marker header-end (match-end 0)))
2724 (goto-char header-end)
2725 (delete-region (point) (point-max))
2727 ;; Produce all the lines that describe custom commands and prefixes
2728 (setq lines nil)
2729 (while (setq entry (pop custom1))
2730 (setq key (car entry) desc (nth 1 entry)
2731 type (nth 2 entry)
2732 match (nth 3 entry))
2733 (if (> (length key) 1)
2734 (add-to-list 'prefixes (string-to-char key))
2735 (setq line
2736 (format
2737 "%-4s%-14s"
2738 (org-add-props (copy-sequence key)
2739 '(face bold))
2740 (cond
2741 ((string-match "\\S-" desc) desc)
2742 ((eq type 'agenda) "Agenda for current week or day")
2743 ((eq type 'alltodo) "List of all TODO entries")
2744 ((eq type 'search) "Word search")
2745 ((eq type 'stuck) "List of stuck projects")
2746 ((eq type 'todo) "TODO keyword")
2747 ((eq type 'tags) "Tags query")
2748 ((eq type 'tags-todo) "Tags (TODO)")
2749 ((eq type 'tags-tree) "Tags tree")
2750 ((eq type 'todo-tree) "TODO kwd tree")
2751 ((eq type 'occur-tree) "Occur tree")
2752 ((functionp type) (if (symbolp type)
2753 (symbol-name type)
2754 "Lambda expression"))
2755 (t "???"))))
2756 (if org-agenda-menu-show-matcher
2757 (setq line
2758 (concat line ": "
2759 (cond
2760 ((stringp match)
2761 (setq match (copy-sequence match))
2762 (org-add-props match nil 'face 'org-warning))
2763 ((listp type)
2764 (format "set of %d commands" (length type))))))
2765 (if (org-string-nw-p match)
2766 (add-text-properties
2767 0 (length line) (list 'help-echo
2768 (concat "Matcher: " match)) line)))
2769 (push line lines)))
2770 (setq lines (nreverse lines))
2771 (when prefixes
2772 (mapc (lambda (x)
2773 (push
2774 (format "%s %s"
2775 (org-add-props (char-to-string x)
2776 nil 'face 'bold)
2777 (or (cdr (assoc (concat selstring
2778 (char-to-string x))
2779 prefix-descriptions))
2780 "Prefix key"))
2781 lines))
2782 prefixes))
2784 ;; Check if we should display in two columns
2785 (if org-agenda-menu-two-columns
2786 (progn
2787 (setq n (length lines)
2788 n1 (+ (/ n 2) (mod n 2))
2789 right (nthcdr n1 lines)
2790 left (copy-sequence lines))
2791 (setcdr (nthcdr (1- n1) left) nil))
2792 (setq left lines right nil))
2793 (while left
2794 (insert "\n" (pop left))
2795 (when right
2796 (if (< (current-column) 40)
2797 (move-to-column 40 t)
2798 (insert " "))
2799 (insert (pop right))))
2801 ;; Make the window the right size
2802 (goto-char (point-min))
2803 (if second-time
2804 (if (not (pos-visible-in-window-p (point-max)))
2805 (org-fit-window-to-buffer))
2806 (setq second-time t)
2807 (org-fit-window-to-buffer))
2809 ;; Ask for selection
2810 (message "Press key for agenda command%s:"
2811 (if (or restrict-ok org-agenda-overriding-restriction)
2812 (if org-agenda-overriding-restriction
2813 " (restriction lock active)"
2814 (if restriction
2815 (format " (restricted to %s)" restriction)
2816 " (unrestricted)"))
2817 ""))
2818 (setq c (read-char-exclusive))
2819 (message "")
2820 (cond
2821 ((assoc (char-to-string c) custom)
2822 (setq selstring (concat selstring (char-to-string c)))
2823 (throw 'exit (cons selstring restriction)))
2824 ((memq c prefixes)
2825 (setq selstring (concat selstring (char-to-string c))
2826 prefixes nil
2827 rmheader (or rmheader t)
2828 custom (delq nil (mapcar
2829 (lambda (x)
2830 (if (or (= (length (car x)) 1)
2831 (/= (string-to-char (car x)) c))
2833 (cons (substring (car x) 1) (cdr x))))
2834 custom))))
2835 ((eq c ?*)
2836 (call-interactively 'org-toggle-sticky-agenda)
2837 (sit-for 2))
2838 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2839 (message "Restriction is only possible in Org-mode buffers")
2840 (ding) (sit-for 1))
2841 ((eq c ?1)
2842 (org-agenda-remove-restriction-lock 'noupdate)
2843 (setq restriction 'buffer))
2844 ((eq c ?0)
2845 (org-agenda-remove-restriction-lock 'noupdate)
2846 (setq restriction (if region-p 'region 'subtree)))
2847 ((eq c ?<)
2848 (org-agenda-remove-restriction-lock 'noupdate)
2849 (setq restriction
2850 (cond
2851 ((eq restriction 'buffer)
2852 (if region-p 'region 'subtree))
2853 ((memq restriction '(subtree region))
2854 nil)
2855 (t 'buffer))))
2856 ((eq c ?>)
2857 (org-agenda-remove-restriction-lock 'noupdate)
2858 (setq restriction nil))
2859 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2860 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2861 ((and (> (length selstring) 0) (eq c ?\d))
2862 (delete-window)
2863 (org-agenda-get-restriction-and-command prefix-descriptions))
2865 ((equal c ?q) (error "Abort"))
2866 (t (error "Invalid key %c" c))))))))
2868 (defun org-agenda-fit-window-to-buffer ()
2869 "Fit the window to the buffer size."
2870 (and (memq org-agenda-window-setup '(reorganize-frame))
2871 (fboundp 'fit-window-to-buffer)
2872 (org-fit-window-to-buffer
2874 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2875 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2877 (defvar org-cmd nil)
2878 (defvar org-agenda-overriding-cmd nil)
2879 (defvar org-agenda-overriding-arguments nil)
2880 (defvar org-agenda-overriding-cmd-arguments nil)
2881 (defun org-agenda-run-series (name series)
2882 (org-let (nth 1 series) '(org-agenda-prepare name))
2883 ;; We need to reset agenda markers here, because when constructing a
2884 ;; block agenda, the individual blocks do not do that.
2885 (org-agenda-reset-markers)
2886 (let* ((org-agenda-multi t)
2887 (redo (list 'org-agenda-run-series name (list 'quote series)))
2888 (cmds (car series))
2889 (gprops (nth 1 series))
2890 match ;; The byte compiler incorrectly complains about this. Keep it!
2891 org-cmd type lprops)
2892 (while (setq org-cmd (pop cmds))
2893 (setq type (car org-cmd)
2894 match (eval (nth 1 org-cmd))
2895 lprops (nth 2 org-cmd))
2896 (let ((org-agenda-overriding-arguments
2897 (if (eq org-agenda-overriding-cmd org-cmd)
2898 (or org-agenda-overriding-arguments
2899 org-agenda-overriding-cmd-arguments))))
2900 (cond
2901 ((eq type 'agenda)
2902 (org-let2 gprops lprops
2903 '(call-interactively 'org-agenda-list)))
2904 ((eq type 'alltodo)
2905 (org-let2 gprops lprops
2906 '(call-interactively 'org-todo-list)))
2907 ((eq type 'search)
2908 (org-let2 gprops lprops
2909 '(org-search-view current-prefix-arg match nil)))
2910 ((eq type 'stuck)
2911 (org-let2 gprops lprops
2912 '(call-interactively 'org-agenda-list-stuck-projects)))
2913 ((eq type 'tags)
2914 (org-let2 gprops lprops
2915 '(org-tags-view current-prefix-arg match)))
2916 ((eq type 'tags-todo)
2917 (org-let2 gprops lprops
2918 '(org-tags-view '(4) match)))
2919 ((eq type 'todo)
2920 (org-let2 gprops lprops
2921 '(org-todo-list match)))
2922 ((fboundp type)
2923 (org-let2 gprops lprops
2924 '(funcall type match)))
2925 (t (error "Invalid type in command series")))))
2926 (widen)
2927 (let ((inhibit-read-only t))
2928 (add-text-properties (point-min) (point-max)
2929 `(org-series t org-series-redo-cmd ,redo)))
2930 (setq org-agenda-redo-command redo)
2931 (goto-char (point-min)))
2932 (org-agenda-fit-window-to-buffer)
2933 (org-let (nth 1 series) '(org-agenda-finalize)))
2935 ;;;###autoload
2936 (defmacro org-batch-agenda (cmd-key &rest parameters)
2937 "Run an agenda command in batch mode and send the result to STDOUT.
2938 If CMD-KEY is a string of length 1, it is used as a key in
2939 `org-agenda-custom-commands' and triggers this command. If it is a
2940 longer string it is used as a tags/todo match string.
2941 Parameters are alternating variable names and values that will be bound
2942 before running the agenda command."
2943 (org-eval-in-environment (org-make-parameter-alist parameters)
2944 (if (> (length cmd-key) 2)
2945 (org-tags-view nil cmd-key)
2946 (org-agenda nil cmd-key)))
2947 (set-buffer org-agenda-buffer-name)
2948 (princ (buffer-string)))
2950 (autoload 'org-batch-agenda "org-agenda" "\
2951 Run an agenda command in batch mode and send the result to STDOUT.
2952 If CMD-KEY is a string of length 1, it is used as a key in
2953 `org-agenda-custom-commands' and triggers this command. If it is a
2954 longer string it is used as a tags/todo match string.
2955 Parameters are alternating variable names and values that will be bound
2956 before running the agenda command.
2958 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2959 (def-edebug-spec org-batch-agenda (form &rest sexp))
2961 (defvar org-agenda-info nil)
2963 ;;;###autoload
2964 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2965 "Run an agenda command in batch mode and send the result to STDOUT.
2966 If CMD-KEY is a string of length 1, it is used as a key in
2967 `org-agenda-custom-commands' and triggers this command. If it is a
2968 longer string it is used as a tags/todo match string.
2969 Parameters are alternating variable names and values that will be bound
2970 before running the agenda command.
2972 The output gives a line for each selected agenda item. Each
2973 item is a list of comma-separated values, like this:
2975 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2977 category The category of the item
2978 head The headline, without TODO kwd, TAGS and PRIORITY
2979 type The type of the agenda entry, can be
2980 todo selected in TODO match
2981 tagsmatch selected in tags match
2982 diary imported from diary
2983 deadline a deadline on given date
2984 scheduled scheduled on given date
2985 timestamp entry has timestamp on given date
2986 closed entry was closed on given date
2987 upcoming-deadline warning about deadline
2988 past-scheduled forwarded scheduled item
2989 block entry has date block including g. date
2990 todo The todo keyword, if any
2991 tags All tags including inherited ones, separated by colons
2992 date The relevant date, like 2007-2-14
2993 time The time, like 15:00-16:50
2994 extra Sting with extra planning info
2995 priority-l The priority letter if any was given
2996 priority-n The computed numerical priority
2997 agenda-day The day in the agenda where this is listed"
2998 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2999 (org-make-parameter-alist parameters))
3000 (if (> (length cmd-key) 2)
3001 (org-tags-view nil cmd-key)
3002 (org-agenda nil cmd-key)))
3003 (set-buffer org-agenda-buffer-name)
3004 (let* ((lines (org-split-string (buffer-string) "\n"))
3005 line)
3006 (while (setq line (pop lines))
3007 (catch 'next
3008 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3009 (setq org-agenda-info
3010 (org-fix-agenda-info (text-properties-at 0 line)))
3011 (princ
3012 (mapconcat 'org-agenda-export-csv-mapper
3013 '(org-category txt type todo tags date time extra
3014 priority-letter priority agenda-day)
3015 ","))
3016 (princ "\n")))))
3018 (autoload 'org-batch-agenda-csv "org-agenda" "\
3019 Run an agenda command in batch mode and send the result to STDOUT.
3020 If CMD-KEY is a string of length 1, it is used as a key in
3021 `org-agenda-custom-commands' and triggers this command. If it is a
3022 longer string it is used as a tags/todo match string.
3023 Parameters are alternating variable names and values that will be bound
3024 before running the agenda command.
3026 The output gives a line for each selected agenda item. Each
3027 item is a list of comma-separated values, like this:
3029 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3031 category The category of the item
3032 head The headline, without TODO kwd, TAGS and PRIORITY
3033 type The type of the agenda entry, can be
3034 todo selected in TODO match
3035 tagsmatch selected in tags match
3036 diary imported from diary
3037 deadline a deadline on given date
3038 scheduled scheduled on given date
3039 timestamp entry has timestamp on given date
3040 closed entry was closed on given date
3041 upcoming-deadline warning about deadline
3042 past-scheduled forwarded scheduled item
3043 block entry has date block including g. date
3044 todo The todo keyword, if any
3045 tags All tags including inherited ones, separated by colons
3046 date The relevant date, like 2007-2-14
3047 time The time, like 15:00-16:50
3048 extra Sting with extra planning info
3049 priority-l The priority letter if any was given
3050 priority-n The computed numerical priority
3051 agenda-day The day in the agenda where this is listed
3053 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3054 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3056 (defun org-fix-agenda-info (props)
3057 "Make sure all properties on an agenda item have a canonical form.
3058 This ensures the export commands can easily use it."
3059 (let (tmp re)
3060 (when (setq tmp (plist-get props 'tags))
3061 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3062 (when (setq tmp (plist-get props 'date))
3063 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3064 (let ((calendar-date-display-form '(year "-" month "-" day)))
3065 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3067 (setq tmp (calendar-date-string tmp)))
3068 (setq props (plist-put props 'date tmp)))
3069 (when (setq tmp (plist-get props 'day))
3070 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3071 (let ((calendar-date-display-form '(year "-" month "-" day)))
3072 (setq tmp (calendar-date-string tmp)))
3073 (setq props (plist-put props 'day tmp))
3074 (setq props (plist-put props 'agenda-day tmp)))
3075 (when (setq tmp (plist-get props 'txt))
3076 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3077 (plist-put props 'priority-letter (match-string 1 tmp))
3078 (setq tmp (replace-match "" t t tmp)))
3079 (when (and (setq re (plist-get props 'org-todo-regexp))
3080 (setq re (concat "\\`\\.*" re " ?"))
3081 (string-match re tmp))
3082 (plist-put props 'todo (match-string 1 tmp))
3083 (setq tmp (replace-match "" t t tmp)))
3084 (plist-put props 'txt tmp)))
3085 props)
3087 (defun org-agenda-export-csv-mapper (prop)
3088 (let ((res (plist-get org-agenda-info prop)))
3089 (setq res
3090 (cond
3091 ((not res) "")
3092 ((stringp res) res)
3093 (t (prin1-to-string res))))
3094 (while (string-match "," res)
3095 (setq res (replace-match ";" t t res)))
3096 (org-trim res)))
3098 ;;;###autoload
3099 (defun org-store-agenda-views (&rest parameters)
3100 (interactive)
3101 (eval (list 'org-batch-store-agenda-views)))
3103 (autoload 'org-store-agenda-views "org-agenda" "\
3106 \(fn &rest PARAMETERS)" t nil)
3108 ;;;###autoload
3109 (defmacro org-batch-store-agenda-views (&rest parameters)
3110 "Run all custom agenda commands that have a file argument."
3111 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3112 (pop-up-frames nil)
3113 (dir default-directory)
3114 (pars (org-make-parameter-alist parameters))
3115 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3116 (save-window-excursion
3117 (while cmds
3118 (setq cmd (pop cmds)
3119 thiscmdkey (car cmd)
3120 thiscmdcmd (cdr cmd)
3121 match (nth 2 thiscmdcmd)
3122 bufname (if org-agenda-sticky
3123 (or (and (stringp match)
3124 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3125 (format "*Org Agenda(%s)*" thiscmdkey))
3126 org-agenda-buffer-name)
3127 cmd-or-set (nth 2 cmd)
3128 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3129 files (nth (if (listp cmd-or-set) 4 5) cmd))
3130 (if (stringp files) (setq files (list files)))
3131 (when files
3132 (org-eval-in-environment (append org-agenda-exporter-settings
3133 opts pars)
3134 (org-agenda nil thiscmdkey))
3135 (set-buffer bufname)
3136 (while files
3137 (org-eval-in-environment (append org-agenda-exporter-settings
3138 opts pars)
3139 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3140 (and (get-buffer bufname)
3141 (kill-buffer bufname)))))))
3143 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3144 Run all custom agenda commands that have a file argument.
3146 \(fn &rest PARAMETERS)" nil t)
3147 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3149 (defvar org-agenda-current-span nil
3150 "The current span used in the agenda view.") ; local variable in the agenda buffer
3151 (defun org-agenda-mark-header-line (pos)
3152 "Mark the line at POS as an agenda structure header."
3153 (save-excursion
3154 (goto-char pos)
3155 (put-text-property (point-at-bol) (point-at-eol)
3156 'org-agenda-structural-header t)
3157 (when org-agenda-title-append
3158 (put-text-property (point-at-bol) (point-at-eol)
3159 'org-agenda-title-append org-agenda-title-append))))
3161 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3162 (defvar org-agenda-write-buffer-name "Agenda View")
3163 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3164 "Write the current buffer (an agenda view) as a file.
3165 Depending on the extension of the file name, plain text (.txt),
3166 HTML (.html or .htm) or Postscript (.ps) is produced.
3167 If the extension is .ics, run icalendar export over all files used
3168 to construct the agenda and limit the export to entries listed in the
3169 agenda now.
3170 With prefix argument OPEN, open the new file immediately.
3171 If NOSETTINGS is given, do not scope the settings of
3172 `org-agenda-exporter-settings' into the export commands. This is used when
3173 the settings have already been scoped and we do not wish to overrule other,
3174 higher priority settings.
3175 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3176 (interactive "FWrite agenda to file: \nP")
3177 (if (not (file-writable-p file))
3178 (error "Cannot write agenda to file %s" file))
3179 (org-let (if nosettings nil org-agenda-exporter-settings)
3180 '(save-excursion
3181 (save-window-excursion
3182 (org-agenda-mark-filtered-text)
3183 (let ((bs (copy-sequence (buffer-string))) beg)
3184 (org-agenda-unmark-filtered-text)
3185 (with-temp-buffer
3186 (rename-buffer org-agenda-write-buffer-name t)
3187 (set-buffer-modified-p nil)
3188 (insert bs)
3189 (org-agenda-remove-marked-text 'org-filtered)
3190 (while (setq beg (text-property-any (point-min) (point-max)
3191 'org-filtered t))
3192 (delete-region
3193 beg (or (next-single-property-change beg 'org-filtered)
3194 (point-max))))
3195 (run-hooks 'org-agenda-before-write-hook)
3196 (cond
3197 ((org-bound-and-true-p org-mobile-creating-agendas)
3198 (org-mobile-write-agenda-for-mobile file))
3199 ((string-match "\\.html?\\'" file)
3200 (require 'htmlize)
3201 (set-buffer (htmlize-buffer (current-buffer)))
3202 (when org-agenda-export-html-style
3203 ;; replace <style> section with org-agenda-export-html-style
3204 (goto-char (point-min))
3205 (kill-region (- (search-forward "<style") 6)
3206 (search-forward "</style>"))
3207 (insert org-agenda-export-html-style))
3208 (write-file file)
3209 (kill-buffer (current-buffer))
3210 (message "HTML written to %s" file))
3211 ((string-match "\\.ps\\'" file)
3212 (require 'ps-print)
3213 (ps-print-buffer-with-faces file)
3214 (message "Postscript written to %s" file))
3215 ((string-match "\\.pdf\\'" file)
3216 (require 'ps-print)
3217 (ps-print-buffer-with-faces
3218 (concat (file-name-sans-extension file) ".ps"))
3219 (call-process "ps2pdf" nil nil nil
3220 (expand-file-name
3221 (concat (file-name-sans-extension file) ".ps"))
3222 (expand-file-name file))
3223 (delete-file (concat (file-name-sans-extension file) ".ps"))
3224 (message "PDF written to %s" file))
3225 ((string-match "\\.ics\\'" file)
3226 (require 'org-icalendar)
3227 (let ((org-agenda-marker-table
3228 (org-create-marker-find-array
3229 (org-agenda-collect-markers)))
3230 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3231 (org-combined-agenda-icalendar-file file))
3232 (apply 'org-export-icalendar 'combine
3233 (org-agenda-files nil 'ifmode))))
3235 (let ((bs (buffer-string)))
3236 (find-file file)
3237 (erase-buffer)
3238 (insert bs)
3239 (save-buffer 0)
3240 (kill-buffer (current-buffer))
3241 (message "Plain text written to %s" file))))))))
3242 (set-buffer (or agenda-bufname
3243 (and (org-called-interactively-p 'any) (buffer-name))
3244 org-agenda-buffer-name)))
3245 (when open (org-open-file file)))
3247 (defvar org-agenda-tag-filter-overlays nil)
3248 (defvar org-agenda-cat-filter-overlays nil)
3250 (defun org-agenda-mark-filtered-text ()
3251 "Mark all text hidden by filtering with a text property."
3252 (let ((inhibit-read-only t))
3253 (mapc
3254 (lambda (o)
3255 (when (equal (overlay-buffer o) (current-buffer))
3256 (put-text-property
3257 (overlay-start o) (overlay-end o)
3258 'org-filtered t)))
3259 (append org-agenda-tag-filter-overlays
3260 org-agenda-cat-filter-overlays))))
3262 (defun org-agenda-unmark-filtered-text ()
3263 "Remove the filtering text property."
3264 (let ((inhibit-read-only t))
3265 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3267 (defun org-agenda-remove-marked-text (property &optional value)
3268 "Delete all text marked with VALUE of PROPERTY.
3269 VALUE defaults to t."
3270 (let (beg)
3271 (setq value (or value t))
3272 (while (setq beg (text-property-any (point-min) (point-max)
3273 property value))
3274 (delete-region
3275 beg (or (next-single-property-change beg 'org-filtered)
3276 (point-max))))))
3278 (defun org-agenda-add-entry-text ()
3279 "Add entry text to agenda lines.
3280 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3281 entry text following headings shown in the agenda.
3282 Drawers will be excluded, also the line with scheduling/deadline info."
3283 (when (and (> org-agenda-add-entry-text-maxlines 0)
3284 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3285 (let (m txt)
3286 (goto-char (point-min))
3287 (while (not (eobp))
3288 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3289 (beginning-of-line 2)
3290 (setq txt (org-agenda-get-some-entry-text
3291 m org-agenda-add-entry-text-maxlines " > "))
3292 (end-of-line 1)
3293 (if (string-match "\\S-" txt)
3294 (insert "\n" txt)
3295 (or (eobp) (forward-char 1))))))))
3297 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3298 &rest keep)
3299 "Extract entry text from MARKER, at most N-LINES lines.
3300 This will ignore drawers etc, just get the text.
3301 If INDENT is given, prefix every line with this string. If KEEP is
3302 given, it is a list of symbols, defining stuff that should not be
3303 removed from the entry content. Currently only `planning' is allowed here."
3304 (let (txt drawer-re kwd-time-re ind)
3305 (save-excursion
3306 (with-current-buffer (marker-buffer marker)
3307 (if (not (derived-mode-p 'org-mode))
3308 (setq txt "")
3309 (save-excursion
3310 (save-restriction
3311 (widen)
3312 (goto-char marker)
3313 (end-of-line 1)
3314 (setq txt (buffer-substring
3315 (min (1+ (point)) (point-max))
3316 (progn (outline-next-heading) (point)))
3317 drawer-re org-drawer-regexp
3318 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3319 ".*\n?"))
3320 (with-temp-buffer
3321 (insert txt)
3322 (when org-agenda-add-entry-text-descriptive-links
3323 (goto-char (point-min))
3324 (while (org-activate-bracket-links (point-max))
3325 (add-text-properties (match-beginning 0) (match-end 0)
3326 '(face org-link))))
3327 (goto-char (point-min))
3328 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3329 (set-text-properties (match-beginning 0) (match-end 0)
3330 nil))
3331 (goto-char (point-min))
3332 (while (re-search-forward drawer-re nil t)
3333 (delete-region
3334 (match-beginning 0)
3335 (progn (re-search-forward
3336 "^[ \t]*:END:.*\n?" nil 'move)
3337 (point))))
3338 (unless (member 'planning keep)
3339 (goto-char (point-min))
3340 (while (re-search-forward kwd-time-re nil t)
3341 (replace-match "")))
3342 (goto-char (point-min))
3343 (when org-agenda-entry-text-exclude-regexps
3344 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3345 (while (setq re (pop re-list))
3346 (goto-char (point-min))
3347 (while (re-search-forward re nil t)
3348 (replace-match "")))))
3349 (goto-char (point-max))
3350 (skip-chars-backward " \t\n")
3351 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3353 ;; find and remove min common indentation
3354 (goto-char (point-min))
3355 (untabify (point-min) (point-max))
3356 (setq ind (org-get-indentation))
3357 (while (not (eobp))
3358 (unless (looking-at "[ \t]*$")
3359 (setq ind (min ind (org-get-indentation))))
3360 (beginning-of-line 2))
3361 (goto-char (point-min))
3362 (while (not (eobp))
3363 (unless (looking-at "[ \t]*$")
3364 (move-to-column ind)
3365 (delete-region (point-at-bol) (point)))
3366 (beginning-of-line 2))
3368 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3370 (goto-char (point-min))
3371 (when indent
3372 (while (and (not (eobp)) (re-search-forward "^" nil t))
3373 (replace-match indent t t)))
3374 (goto-char (point-min))
3375 (while (looking-at "[ \t]*\n") (replace-match ""))
3376 (goto-char (point-max))
3377 (when (> (org-current-line)
3378 n-lines)
3379 (org-goto-line (1+ n-lines))
3380 (backward-char 1))
3381 (setq txt (buffer-substring (point-min) (point)))))))))
3382 txt))
3384 (defun org-agenda-collect-markers ()
3385 "Collect the markers pointing to entries in the agenda buffer."
3386 (let (m markers)
3387 (save-excursion
3388 (goto-char (point-min))
3389 (while (not (eobp))
3390 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3391 (org-get-at-bol 'org-marker)))
3392 (push m markers))
3393 (beginning-of-line 2)))
3394 (nreverse markers)))
3396 (defun org-create-marker-find-array (marker-list)
3397 "Create a alist of files names with all marker positions in that file."
3398 (let (f tbl m a p)
3399 (while (setq m (pop marker-list))
3400 (setq p (marker-position m)
3401 f (buffer-file-name (or (buffer-base-buffer
3402 (marker-buffer m))
3403 (marker-buffer m))))
3404 (if (setq a (assoc f tbl))
3405 (push (marker-position m) (cdr a))
3406 (push (list f p) tbl)))
3407 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3408 tbl)))
3410 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3411 (defun org-check-agenda-marker-table ()
3412 "Check of the current entry is on the marker list."
3413 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3415 (and (setq a (assoc file org-agenda-marker-table))
3416 (save-match-data
3417 (save-excursion
3418 (org-back-to-heading t)
3419 (member (point) (cdr a)))))))
3421 (defun org-check-for-org-mode ()
3422 "Make sure current buffer is in org-mode. Error if not."
3423 (or (derived-mode-p 'org-mode)
3424 (error "Cannot execute org-mode agenda command on buffer in %s"
3425 major-mode)))
3427 ;;; Agenda prepare and finalize
3429 (defvar org-agenda-multi nil) ; dynamically scoped
3430 (defvar org-agenda-pre-window-conf nil)
3431 (defvar org-agenda-columns-active nil)
3432 (defvar org-agenda-name nil)
3433 (defvar org-agenda-tag-filter nil)
3434 (defvar org-agenda-category-filter nil)
3435 (defvar org-agenda-top-category-filter nil)
3436 (defvar org-agenda-tag-filter-while-redo nil)
3437 (defvar org-agenda-tag-filter-preset nil
3438 "A preset of the tags filter used for secondary agenda filtering.
3439 This must be a list of strings, each string must be a single tag preceded
3440 by \"+\" or \"-\".
3441 This variable should not be set directly, but agenda custom commands can
3442 bind it in the options section. The preset filter is a global property of
3443 the entire agenda view. In a block agenda, it will not work reliably to
3444 define a filter for one of the individual blocks. You need to set it in
3445 the global options and expect it to be applied to the entire view.")
3447 (defvar org-agenda-category-filter-preset nil
3448 "A preset of the category filter used for secondary agenda filtering.
3449 This must be a list of strings, each string must be a single category
3450 preceded by \"+\" or \"-\".
3451 This variable should not be set directly, but agenda custom commands can
3452 bind it in the options section. The preset filter is a global property of
3453 the entire agenda view. In a block agenda, it will not work reliably to
3454 define a filter for one of the individual blocks. You need to set it in
3455 the global options and expect it to be applied to the entire view.")
3458 (defun org-agenda-use-sticky-p ()
3459 "Return non-nil if an agenda buffer named
3460 `org-agenda-buffer-name' exists and should be shown instead of
3461 generating a new one."
3462 (and
3463 ;; turned off by user
3464 org-agenda-sticky
3465 ;; For multi-agenda buffer already exists
3466 (not org-agenda-multi)
3467 ;; buffer found
3468 (get-buffer org-agenda-buffer-name)
3469 ;; C-u parameter is same as last call
3470 (with-current-buffer (get-buffer org-agenda-buffer-name)
3471 (and
3472 (equal current-prefix-arg
3473 org-agenda-last-prefix-arg)
3474 ;; In case user turned stickiness on, while having existing
3475 ;; Agenda buffer active, don't reuse that buffer, because it
3476 ;; does not have org variables local
3477 org-agenda-this-buffer-is-sticky))))
3479 (defun org-agenda-prepare-window (abuf)
3480 "Setup agenda buffer in the window."
3481 (let* ((awin (get-buffer-window abuf))
3482 wconf)
3483 (cond
3484 ((equal (current-buffer) abuf) nil)
3485 (awin (select-window awin))
3486 ((not (setq wconf (current-window-configuration))))
3487 ((equal org-agenda-window-setup 'current-window)
3488 (org-pop-to-buffer-same-window abuf))
3489 ((equal org-agenda-window-setup 'other-window)
3490 (org-switch-to-buffer-other-window abuf))
3491 ((equal org-agenda-window-setup 'other-frame)
3492 (switch-to-buffer-other-frame abuf))
3493 ((equal org-agenda-window-setup 'reorganize-frame)
3494 (delete-other-windows)
3495 (org-switch-to-buffer-other-window abuf)))
3496 ;; additional test in case agenda is invoked from within agenda
3497 ;; buffer via elisp link
3498 (unless (equal (current-buffer) abuf)
3499 (org-pop-to-buffer-same-window abuf))
3500 (setq org-agenda-pre-window-conf
3501 (or org-agenda-pre-window-conf wconf))))
3503 (defun org-agenda-prepare (&optional name)
3504 (if (org-agenda-use-sticky-p)
3505 (progn
3506 ;; Popup existing buffer
3507 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3508 (message "Sticky Agenda buffer, use `r' to refresh")
3509 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3510 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3511 (setq org-todo-keywords-for-agenda nil)
3512 (setq org-drawers-for-agenda nil)
3513 (unless org-agenda-persistent-filter
3514 (setq org-agenda-tag-filter nil
3515 org-agenda-category-filter nil))
3516 (put 'org-agenda-tag-filter :preset-filter
3517 org-agenda-tag-filter-preset)
3518 (put 'org-agenda-category-filter :preset-filter
3519 org-agenda-category-filter-preset)
3520 (if org-agenda-multi
3521 (progn
3522 (setq buffer-read-only nil)
3523 (goto-char (point-max))
3524 (unless (or (bobp) org-agenda-compact-blocks
3525 (not org-agenda-block-separator))
3526 (insert "\n"
3527 (if (stringp org-agenda-block-separator)
3528 org-agenda-block-separator
3529 (make-string (window-width) org-agenda-block-separator))
3530 "\n"))
3531 (narrow-to-region (point) (point-max)))
3532 (setq org-done-keywords-for-agenda nil)
3534 ;; Setting any org variables that are in org-agenda-local-vars
3535 ;; list need to be done after the prepare call
3536 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3537 (setq buffer-read-only nil)
3538 (org-agenda-reset-markers)
3539 (let ((inhibit-read-only t)) (erase-buffer))
3540 (org-agenda-mode)
3541 (setq org-agenda-buffer (current-buffer))
3542 (setq org-agenda-contributing-files nil)
3543 (setq org-agenda-columns-active nil)
3544 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3545 (setq org-todo-keywords-for-agenda
3546 (org-uniquify org-todo-keywords-for-agenda))
3547 (setq org-done-keywords-for-agenda
3548 (org-uniquify org-done-keywords-for-agenda))
3549 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3550 (setq org-agenda-last-prefix-arg current-prefix-arg)
3551 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3552 (and name (not org-agenda-name)
3553 (org-set-local 'org-agenda-name name)))
3554 (setq buffer-read-only nil)))
3556 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3557 (defun org-agenda-finalize ()
3558 "Finishing touch for the agenda buffer, called just before displaying it."
3559 (unless org-agenda-multi
3560 (save-excursion
3561 (let ((inhibit-read-only t))
3562 (goto-char (point-min))
3563 (save-excursion
3564 (while (org-activate-bracket-links (point-max))
3565 (add-text-properties (match-beginning 0) (match-end 0)
3566 '(face org-link))))
3567 (save-excursion
3568 (while (org-activate-plain-links (point-max))
3569 (add-text-properties (match-beginning 0) (match-end 0)
3570 '(face org-link))))
3571 (unless (eq org-agenda-remove-tags t)
3572 (org-agenda-align-tags))
3573 (unless org-agenda-with-colors
3574 (remove-text-properties (point-min) (point-max) '(face nil)))
3575 (if (and (boundp 'org-agenda-overriding-columns-format)
3576 org-agenda-overriding-columns-format)
3577 (org-set-local 'org-agenda-overriding-columns-format
3578 org-agenda-overriding-columns-format))
3579 (if (and (boundp 'org-agenda-view-columns-initially)
3580 org-agenda-view-columns-initially)
3581 (org-agenda-columns))
3582 (when org-agenda-fontify-priorities
3583 (org-agenda-fontify-priorities))
3584 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3585 (org-agenda-dim-blocked-tasks))
3586 ;; We need to widen when `org-agenda-finalize' is called from
3587 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3588 (when org-clock-current-task
3589 (save-restriction
3590 (widen)
3591 (org-agenda-mark-clocking-task)))
3592 (when org-agenda-entry-text-mode
3593 (org-agenda-entry-text-hide)
3594 (org-agenda-entry-text-show))
3595 (if (and (functionp 'org-habit-insert-consistency-graphs)
3596 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3597 (org-habit-insert-consistency-graphs))
3598 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3599 (unless (or (eq org-agenda-show-inherited-tags 'always)
3600 (and (listp org-agenda-show-inherited-tags)
3601 (memq org-agenda-type org-agenda-show-inherited-tags))
3602 (and (eq org-agenda-show-inherited-tags t)
3603 (or (eq org-agenda-use-tag-inheritance t)
3604 (and (listp org-agenda-use-tag-inheritance)
3605 (not (memq org-agenda-type
3606 org-agenda-use-tag-inheritance))))))
3607 (let (mrk)
3608 (save-excursion
3609 (goto-char (point-min))
3610 (while (equal (forward-line) 0)
3611 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3612 (get-text-property (point) 'org-hd-marker)))
3613 (put-text-property (point-at-bol) (point-at-eol)
3614 'tags (org-with-point-at mrk
3615 (delete-dups
3616 (mapcar 'downcase (org-get-tags-at))))))))))
3617 (run-hooks 'org-agenda-finalize-hook)
3618 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3619 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3620 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3621 (org-agenda-filter-apply org-agenda-category-filter 'category))
3622 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3624 (defun org-agenda-mark-clocking-task ()
3625 "Mark the current clock entry in the agenda if it is present."
3626 (mapc (lambda (o)
3627 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3628 (delete-overlay o)))
3629 (overlays-in (point-min) (point-max)))
3630 (when (marker-buffer org-clock-hd-marker)
3631 (save-excursion
3632 (goto-char (point-min))
3633 (let (s ov)
3634 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3635 (goto-char s)
3636 (when (equal (org-get-at-bol 'org-hd-marker)
3637 org-clock-hd-marker)
3638 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3639 (overlay-put ov 'type 'org-agenda-clocking)
3640 (overlay-put ov 'face 'org-agenda-clocking)
3641 (overlay-put ov 'help-echo
3642 "The clock is running in this item")))))))
3644 (defun org-agenda-fontify-priorities ()
3645 "Make highest priority lines bold, and lowest italic."
3646 (interactive)
3647 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3648 (delete-overlay o)))
3649 (overlays-in (point-min) (point-max)))
3650 (save-excursion
3651 (let ((inhibit-read-only t)
3652 b e p ov h l)
3653 (goto-char (point-min))
3654 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3655 (setq h (or (get-char-property (point) 'org-highest-priority)
3656 org-highest-priority)
3657 l (or (get-char-property (point) 'org-lowest-priority)
3658 org-lowest-priority)
3659 p (string-to-char (match-string 1))
3660 b (match-beginning 0)
3661 e (if (eq org-agenda-fontify-priorities 'cookies)
3662 (match-end 0)
3663 (point-at-eol))
3664 ov (make-overlay b e))
3665 (overlay-put
3666 ov 'face
3667 (cond ((org-face-from-face-or-color
3668 'priority nil
3669 (cdr (assoc p org-priority-faces))))
3670 ((and (listp org-agenda-fontify-priorities)
3671 (org-face-from-face-or-color
3672 'priority nil
3673 (cdr (assoc p org-agenda-fontify-priorities)))))
3674 ((equal p l) 'italic)
3675 ((equal p h) 'bold)))
3676 (overlay-put ov 'org-type 'org-priority)))))
3678 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3679 (interactive "P")
3680 "Dim currently blocked TODO's in the agenda display."
3681 (message "Dim or hide blocked tasks...")
3682 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3683 (delete-overlay o)))
3684 (overlays-in (point-min) (point-max)))
3685 (save-excursion
3686 (let ((inhibit-read-only t)
3687 (org-depend-tag-blocked nil)
3688 (invis (or (not (null invisible))
3689 (eq org-agenda-dim-blocked-tasks 'invisible)))
3690 org-blocked-by-checkboxes
3691 invis1 b e p ov h l)
3692 (goto-char (point-min))
3693 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3694 (and pos (goto-char (1+ pos))))
3695 (setq org-blocked-by-checkboxes nil invis1 invis)
3696 (let ((marker (org-get-at-bol 'org-hd-marker)))
3697 (when (and marker
3698 (with-current-buffer (marker-buffer marker)
3699 (save-excursion (goto-char marker)
3700 (org-entry-blocked-p))))
3701 (if org-blocked-by-checkboxes (setq invis1 nil))
3702 (setq b (if invis1
3703 (max (point-min) (1- (point-at-bol)))
3704 (point-at-bol))
3705 e (point-at-eol)
3706 ov (make-overlay b e))
3707 (if invis1
3708 (overlay-put ov 'invisible t)
3709 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3710 (overlay-put ov 'org-type 'org-blocked-todo))))))
3711 (message "Dim or hide blocked tasks...done"))
3713 (defvar org-agenda-skip-function nil
3714 "Function to be called at each match during agenda construction.
3715 If this function returns nil, the current match should not be skipped.
3716 Otherwise, the function must return a position from where the search
3717 should be continued.
3718 This may also be a Lisp form, it will be evaluated.
3719 Never set this variable using `setq' or so, because then it will apply
3720 to all future agenda commands. If you do want a global skipping condition,
3721 use the option `org-agenda-skip-function-global' instead.
3722 The correct usage for `org-agenda-skip-function' is to bind it with
3723 `let' to scope it dynamically into the agenda-constructing command.
3724 A good way to set it is through options in `org-agenda-custom-commands'.")
3726 (defun org-agenda-skip ()
3727 "Throw to `:skip' in places that should be skipped.
3728 Also moves point to the end of the skipped region, so that search can
3729 continue from there."
3730 (let ((p (point-at-bol)) to)
3731 (when (org-in-src-block-p t) (throw :skip t))
3732 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3733 (get-text-property p :org-archived)
3734 (org-end-of-subtree t)
3735 (throw :skip t))
3736 (and org-agenda-skip-comment-trees
3737 (get-text-property p :org-comment)
3738 (org-end-of-subtree t)
3739 (throw :skip t))
3740 (if (equal (char-after p) ?#) (throw :skip t))
3741 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3742 (org-agenda-skip-eval org-agenda-skip-function)))
3743 (goto-char to)
3744 (throw :skip t))))
3746 (defun org-agenda-skip-eval (form)
3747 "If FORM is a function or a list, call (or eval) is and return result.
3748 `save-excursion' and `save-match-data' are wrapped around the call, so point
3749 and match data are returned to the previous state no matter what these
3750 functions do."
3751 (let (fp)
3752 (and form
3753 (or (setq fp (functionp form))
3754 (consp form))
3755 (save-excursion
3756 (save-match-data
3757 (if fp
3758 (funcall form)
3759 (eval form)))))))
3761 (defvar org-agenda-markers nil
3762 "List of all currently active markers created by `org-agenda'.")
3763 (defvar org-agenda-last-marker-time (org-float-time)
3764 "Creation time of the last agenda marker.")
3766 (defun org-agenda-new-marker (&optional pos)
3767 "Return a new agenda marker.
3768 Org-mode keeps a list of these markers and resets them when they are
3769 no longer in use."
3770 (let ((m (copy-marker (or pos (point)))))
3771 (setq org-agenda-last-marker-time (org-float-time))
3772 (if org-agenda-buffer
3773 (with-current-buffer org-agenda-buffer
3774 (push m org-agenda-markers))
3775 (push m org-agenda-markers))
3778 (defun org-agenda-reset-markers ()
3779 "Reset markers created by `org-agenda'."
3780 (while org-agenda-markers
3781 (move-marker (pop org-agenda-markers) nil)))
3783 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3784 "Save relative positions of markers in region.
3785 This check for agenda markers in all agenda buffers currently active."
3786 (dolist (buf (buffer-list))
3787 (with-current-buffer buf
3788 (when (eq major-mode 'org-agenda-mode)
3789 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3790 org-agenda-markers)))))
3792 ;;; Entry text mode
3794 (defun org-agenda-entry-text-show-here ()
3795 "Add some text from the entry as context to the current line."
3796 (let (m txt o)
3797 (setq m (org-get-at-bol 'org-hd-marker))
3798 (unless (marker-buffer m)
3799 (error "No marker points to an entry here"))
3800 (setq txt (concat "\n" (org-no-properties
3801 (org-agenda-get-some-entry-text
3802 m org-agenda-entry-text-maxlines " > "))))
3803 (when (string-match "\\S-" txt)
3804 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3805 (overlay-put o 'evaporate t)
3806 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3807 (overlay-put o 'after-string txt))))
3809 (defun org-agenda-entry-text-show ()
3810 "Add entry context for all agenda lines."
3811 (interactive)
3812 (save-excursion
3813 (goto-char (point-max))
3814 (beginning-of-line 1)
3815 (while (not (bobp))
3816 (when (org-get-at-bol 'org-hd-marker)
3817 (org-agenda-entry-text-show-here))
3818 (beginning-of-line 0))))
3820 (defun org-agenda-entry-text-hide ()
3821 "Remove any shown entry context."
3822 (delq nil
3823 (mapcar (lambda (o)
3824 (if (eq (overlay-get o 'org-overlay-type)
3825 'agenda-entry-content)
3826 (progn (delete-overlay o) t)))
3827 (overlays-in (point-min) (point-max)))))
3829 (defun org-agenda-get-day-face (date)
3830 "Return the face DATE should be displayed with."
3831 (or (and (functionp org-agenda-day-face-function)
3832 (funcall org-agenda-day-face-function date))
3833 (cond ((org-agenda-todayp date)
3834 'org-agenda-date-today)
3835 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3836 'org-agenda-date-weekend)
3837 (t 'org-agenda-date))))
3839 ;;; Agenda timeline
3841 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3843 (defun org-timeline (&optional dotodo)
3844 "Show a time-sorted view of the entries in the current org file.
3845 Only entries with a time stamp of today or later will be listed. With
3846 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3847 under the current date.
3848 If the buffer contains an active region, only check the region for
3849 dates."
3850 (interactive "P")
3851 (let* ((dopast t)
3852 (org-agenda-show-log-scoped org-agenda-show-log)
3853 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3854 (current-buffer))))
3855 (date (calendar-current-date))
3856 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3857 (end (if (org-region-active-p) (region-end) (point-max)))
3858 (day-numbers (org-get-all-dates
3859 beg end 'no-ranges
3860 t org-agenda-show-log-scoped ; always include today
3861 org-timeline-show-empty-dates))
3862 (org-deadline-warning-days 0)
3863 (org-agenda-only-exact-dates t)
3864 (today (org-today))
3865 (past t)
3866 args
3867 s e rtn d emptyp)
3868 (setq org-agenda-redo-command
3869 (list 'progn
3870 (list 'org-switch-to-buffer-other-window (current-buffer))
3871 (list 'org-timeline (list 'quote dotodo))))
3872 (if (not dopast)
3873 ;; Remove past dates from the list of dates.
3874 (setq day-numbers (delq nil (mapcar (lambda(x)
3875 (if (>= x today) x nil))
3876 day-numbers))))
3877 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3878 (org-compile-prefix-format 'timeline)
3879 (org-set-sorting-strategy 'timeline)
3880 (if org-agenda-show-log-scoped (push :closed args))
3881 (push :timestamp args)
3882 (push :deadline args)
3883 (push :scheduled args)
3884 (push :sexp args)
3885 (if dotodo (push :todo args))
3886 (insert "Timeline of file " entry "\n")
3887 (add-text-properties (point-min) (point)
3888 (list 'face 'org-agenda-structure))
3889 (org-agenda-mark-header-line (point-min))
3890 (while (setq d (pop day-numbers))
3891 (if (and (listp d) (eq (car d) :omitted))
3892 (progn
3893 (setq s (point))
3894 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3895 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3896 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3897 (if (and (>= d today)
3898 dopast
3899 past)
3900 (progn
3901 (setq past nil)
3902 (insert (make-string 79 ?-) "\n")))
3903 (setq date (calendar-gregorian-from-absolute d))
3904 (setq s (point))
3905 (setq rtn (and (not emptyp)
3906 (apply 'org-agenda-get-day-entries entry
3907 date args)))
3908 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3909 (progn
3910 (insert
3911 (if (stringp org-agenda-format-date)
3912 (format-time-string org-agenda-format-date
3913 (org-time-from-absolute date))
3914 (funcall org-agenda-format-date date))
3915 "\n")
3916 (put-text-property s (1- (point)) 'face
3917 (org-agenda-get-day-face date))
3918 (put-text-property s (1- (point)) 'org-date-line t)
3919 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3920 (if (equal d today)
3921 (put-text-property s (1- (point)) 'org-today t))
3922 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3923 (put-text-property s (1- (point)) 'day d)))))
3924 (goto-char (point-min))
3925 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3926 (point-min)))
3927 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3928 (org-agenda-finalize)
3929 (setq buffer-read-only t)))
3931 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3932 "Return a list of all relevant day numbers from BEG to END buffer positions.
3933 If NO-RANGES is non-nil, include only the start and end dates of a range,
3934 not every single day in the range. If FORCE-TODAY is non-nil, make
3935 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3936 inactive time stamps (those in square brackets) are included.
3937 When EMPTY is non-nil, also include days without any entries."
3938 (let ((re (concat
3939 (if pre-re pre-re "")
3940 (if inactive org-ts-regexp-both org-ts-regexp)))
3941 dates dates1 date day day1 day2 ts1 ts2 pos)
3942 (if force-today
3943 (setq dates (list (org-today))))
3944 (save-excursion
3945 (goto-char beg)
3946 (while (re-search-forward re end t)
3947 (setq day (time-to-days (org-time-string-to-time
3948 (substring (match-string 1) 0 10)
3949 (current-buffer) (match-beginning 0))))
3950 (or (memq day dates) (push day dates)))
3951 (unless no-ranges
3952 (goto-char beg)
3953 (while (re-search-forward org-tr-regexp end t)
3954 (setq pos (match-beginning 0))
3955 (setq ts1 (substring (match-string 1) 0 10)
3956 ts2 (substring (match-string 2) 0 10)
3957 day1 (time-to-days (org-time-string-to-time
3958 ts1 (current-buffer) pos))
3959 day2 (time-to-days (org-time-string-to-time
3960 ts2 (current-buffer) pos)))
3961 (while (< (setq day1 (1+ day1)) day2)
3962 (or (memq day1 dates) (push day1 dates)))))
3963 (setq dates (sort dates '<))
3964 (when empty
3965 (while (setq day (pop dates))
3966 (setq day2 (car dates))
3967 (push day dates1)
3968 (when (and day2 empty)
3969 (if (or (eq empty t)
3970 (and (numberp empty) (<= (- day2 day) empty)))
3971 (while (< (setq day (1+ day)) day2)
3972 (push (list day) dates1))
3973 (push (cons :omitted (- day2 day)) dates1))))
3974 (setq dates (nreverse dates1)))
3975 dates)))
3977 ;;; Agenda Daily/Weekly
3979 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3980 "Start day for the agenda view.
3981 Custom commands can set this variable in the options section.")
3982 (defvar org-starting-day nil) ; local variable in the agenda buffer
3983 (defvar org-arg-loc nil) ; local variable
3985 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3986 "List of types searched for when creating the daily/weekly agenda.
3987 This variable is a list of symbols that controls the types of
3988 items that appear in the daily/weekly agenda. Allowed symbols in this
3989 list are are
3991 :timestamp List items containing a date stamp or date range matching
3992 the selected date. This includes sexp entries in
3993 angular brackets.
3995 :sexp List entries resulting from plain diary-like sexps.
3997 :deadline List deadline due on that date. When the date is today,
3998 also list any deadlines past due, or due within
3999 `org-deadline-warning-days'. `:deadline' must appear before
4000 `:scheduled' if the setting of
4001 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4002 any effect.
4004 :scheduled List all items which are scheduled for the given date.
4005 The diary for *today* also contains items which were
4006 scheduled earlier and are not yet marked DONE.
4008 By default, all four types are turned on.
4010 Never set this variable globally using `setq', because then it
4011 will apply to all future agenda commands. Instead, bind it with
4012 `let' to scope it dynamically into the agenda-constructing
4013 command. A good way to set it is through options in
4014 `org-agenda-custom-commands'. For a more flexible (though
4015 somewhat less efficient) way of determining what is included in
4016 the daily/weekly agenda, see `org-agenda-skip-function'.")
4018 (defvar org-agenda-buffer-tmp-name nil)
4019 ;;;###autoload
4020 (defun org-agenda-list (&optional arg start-day span)
4021 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4022 The view will be for the current day or week, but from the overview buffer
4023 you will be able to go to other days/weeks.
4025 With a numeric prefix argument in an interactive call, the agenda will
4026 span ARG days. Lisp programs should instead specify SPAN to change
4027 the number of days. SPAN defaults to `org-agenda-span'.
4029 START-DAY defaults to TODAY, or to the most recent match for the weekday
4030 given in `org-agenda-start-on-weekday'."
4031 (interactive "P")
4032 (if org-agenda-overriding-arguments
4033 (setq arg (car org-agenda-overriding-arguments)
4034 start-day (nth 1 org-agenda-overriding-arguments)
4035 span (nth 2 org-agenda-overriding-arguments)))
4036 (if (and (integerp arg) (> arg 0))
4037 (setq span arg arg nil))
4038 (catch 'exit
4039 (setq org-agenda-buffer-name
4040 (or org-agenda-buffer-tmp-name
4041 (if org-agenda-sticky
4042 (cond ((and org-keys (stringp org-match))
4043 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4044 (org-keys
4045 (format "*Org Agenda(%s)*" org-keys))
4046 (t "*Org Agenda(a)*")))
4047 org-agenda-buffer-name))
4048 (org-agenda-prepare "Day/Week")
4049 (setq start-day (or start-day org-agenda-start-day))
4050 (if (stringp start-day)
4051 ;; Convert to an absolute day number
4052 (setq start-day (time-to-days (org-read-date nil t start-day))))
4053 (org-compile-prefix-format 'agenda)
4054 (org-set-sorting-strategy 'agenda)
4055 (let* ((span (org-agenda-ndays-to-span
4056 (or span org-agenda-ndays org-agenda-span)))
4057 (today (org-today))
4058 (sd (or start-day today))
4059 (ndays (org-agenda-span-to-ndays span sd))
4060 (org-agenda-start-on-weekday
4061 (if (eq ndays 7)
4062 org-agenda-start-on-weekday))
4063 (thefiles (org-agenda-files nil 'ifmode))
4064 (files thefiles)
4065 (start (if (or (null org-agenda-start-on-weekday)
4066 (< ndays 7))
4068 (let* ((nt (calendar-day-of-week
4069 (calendar-gregorian-from-absolute sd)))
4070 (n1 org-agenda-start-on-weekday)
4071 (d (- nt n1)))
4072 (- sd (+ (if (< d 0) 7 0) d)))))
4073 (day-numbers (list start))
4074 (day-cnt 0)
4075 (inhibit-redisplay (not debug-on-error))
4076 (org-agenda-show-log-scoped org-agenda-show-log)
4077 s e rtn rtnall file date d start-pos end-pos todayp
4078 clocktable-start clocktable-end filter)
4079 (setq org-agenda-redo-command
4080 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4081 (dotimes (n (1- ndays))
4082 (push (1+ (car day-numbers)) day-numbers))
4083 (setq day-numbers (nreverse day-numbers))
4084 (setq clocktable-start (car day-numbers)
4085 clocktable-end (1+ (or (org-last day-numbers) 0)))
4086 (org-set-local 'org-starting-day (car day-numbers))
4087 (org-set-local 'org-arg-loc arg)
4088 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4089 (unless org-agenda-compact-blocks
4090 (let* ((d1 (car day-numbers))
4091 (d2 (org-last day-numbers))
4092 (w1 (org-days-to-iso-week d1))
4093 (w2 (org-days-to-iso-week d2)))
4094 (setq s (point))
4095 (if org-agenda-overriding-header
4096 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4097 nil 'face 'org-agenda-structure) "\n")
4098 (insert (org-agenda-span-name span)
4099 "-agenda"
4100 (if (< (- d2 d1) 350)
4101 (if (= w1 w2)
4102 (format " (W%02d)" w1)
4103 (format " (W%02d-W%02d)" w1 w2))
4105 ":\n")))
4106 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4107 'org-date-line t))
4108 (org-agenda-mark-header-line s))
4109 (while (setq d (pop day-numbers))
4110 (setq date (calendar-gregorian-from-absolute d)
4111 s (point))
4112 (if (or (setq todayp (= d today))
4113 (and (not start-pos) (= d sd)))
4114 (setq start-pos (point))
4115 (if (and start-pos (not end-pos))
4116 (setq end-pos (point))))
4117 (setq files thefiles
4118 rtnall nil)
4119 (while (setq file (pop files))
4120 (catch 'nextfile
4121 (org-check-agenda-file file)
4122 (let ((org-agenda-entry-types org-agenda-entry-types))
4123 (unless org-agenda-include-deadlines
4124 (setq org-agenda-entry-types
4125 (delq :deadline org-agenda-entry-types)))
4126 (cond
4127 ((memq org-agenda-show-log-scoped '(only clockcheck))
4128 (setq rtn (org-agenda-get-day-entries
4129 file date :closed)))
4130 (org-agenda-show-log-scoped
4131 (setq rtn (apply 'org-agenda-get-day-entries
4132 file date
4133 (append '(:closed) org-agenda-entry-types))))
4135 (setq rtn (apply 'org-agenda-get-day-entries
4136 file date
4137 org-agenda-entry-types)))))
4138 (setq rtnall (append rtnall rtn)))) ;; all entries
4139 (if org-agenda-include-diary
4140 (let ((org-agenda-search-headline-for-time t))
4141 (require 'diary-lib)
4142 (setq rtn (org-get-entries-from-diary date))
4143 (setq rtnall (append rtnall rtn))))
4144 (if (or rtnall org-agenda-show-all-dates)
4145 (progn
4146 (setq day-cnt (1+ day-cnt))
4147 (insert
4148 (if (stringp org-agenda-format-date)
4149 (format-time-string org-agenda-format-date
4150 (org-time-from-absolute date))
4151 (funcall org-agenda-format-date date))
4152 "\n")
4153 (put-text-property s (1- (point)) 'face
4154 (org-agenda-get-day-face date))
4155 (put-text-property s (1- (point)) 'org-date-line t)
4156 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4157 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4158 (when todayp
4159 (put-text-property s (1- (point)) 'org-today t))
4160 (setq rtnall
4161 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4162 (if rtnall (insert ;; all entries
4163 (org-agenda-finalize-entries rtnall)
4164 "\n"))
4165 (put-text-property s (1- (point)) 'day d)
4166 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4167 (when (and org-agenda-clockreport-mode clocktable-start)
4168 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4169 ;; the above line is to ensure the restricted range!
4170 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4171 tbl)
4172 (setq p (org-plist-delete p :block))
4173 (setq p (plist-put p :tstart clocktable-start))
4174 (setq p (plist-put p :tend clocktable-end))
4175 (setq p (plist-put p :scope 'agenda))
4176 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4177 (setq filter (or org-agenda-tag-filter-while-redo
4178 (get 'org-agenda-tag-filter :preset-filter))))
4179 (setq p (plist-put p :tags (mapconcat (lambda (x)
4180 (if (string-match "[<>=]" x)
4183 filter ""))))
4184 (setq tbl (apply 'org-clock-get-clocktable p))
4185 (insert tbl)))
4186 (goto-char (point-min))
4187 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4188 (unless (and (pos-visible-in-window-p (point-min))
4189 (pos-visible-in-window-p (point-max)))
4190 (goto-char (1- (point-max)))
4191 (recenter -1)
4192 (if (not (pos-visible-in-window-p (or start-pos 1)))
4193 (progn
4194 (goto-char (or start-pos 1))
4195 (recenter 1))))
4196 (goto-char (or start-pos 1))
4197 (add-text-properties (point-min) (point-max)
4198 `(org-agenda-type agenda
4199 org-last-args (,arg ,start-day ,span)
4200 org-redo-cmd ,org-agenda-redo-command
4201 org-series-cmd ,org-cmd))
4202 (if (eq org-agenda-show-log-scoped 'clockcheck)
4203 (org-agenda-show-clocking-issues))
4204 (org-agenda-finalize)
4205 (setq buffer-read-only t)
4206 (message ""))))
4208 (autoload 'org-agenda-list "org-agenda" "\
4209 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4210 The view will be for the current day or week, but from the overview buffer
4211 you will be able to go to other days/weeks.
4213 With a numeric prefix argument in an interactive call, the agenda will
4214 span ARG days. Lisp programs should instead specify SPAN to change
4215 the number of days. SPAN defaults to `org-agenda-span'.
4217 START-DAY defaults to TODAY, or to the most recent match for the weekday
4218 given in `org-agenda-start-on-weekday'.
4220 \(fn &optional ARG START-DAY SPAN)" t nil)
4222 (defun org-agenda-ndays-to-span (n)
4223 "Return a span symbol for a span of N days, or N if none matches."
4224 (cond ((symbolp n) n)
4225 ((= n 1) 'day)
4226 ((= n 7) 'week)
4227 (t n)))
4229 (defun org-agenda-span-to-ndays (span &optional start-day)
4230 "Return ndays from SPAN, possibly starting at START-DAY."
4231 (cond ((numberp span) span)
4232 ((eq span 'day) 1)
4233 ((eq span 'week) 7)
4234 ((eq span 'month)
4235 (let ((date (calendar-gregorian-from-absolute start-day)))
4236 (calendar-last-day-of-month (car date) (caddr date))))
4237 ((eq span 'year)
4238 (let ((date (calendar-gregorian-from-absolute start-day)))
4239 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4241 (defun org-agenda-span-name (span)
4242 "Return a SPAN name."
4243 (if (null span)
4245 (if (symbolp span)
4246 (capitalize (symbol-name span))
4247 (format "%d days" span))))
4249 ;;; Agenda word search
4251 (defvar org-agenda-search-history nil)
4253 (defvar org-search-syntax-table nil
4254 "Special syntax table for org-mode search.
4255 In this table, we have single quotes not as word constituents, to
4256 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4258 (defvar org-mode-syntax-table) ; From org.el
4259 (defun org-search-syntax-table ()
4260 (unless org-search-syntax-table
4261 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4262 (modify-syntax-entry ?' "." org-search-syntax-table)
4263 (modify-syntax-entry ?` "." org-search-syntax-table))
4264 org-search-syntax-table)
4266 (defvar org-agenda-last-search-view-search-was-boolean nil)
4268 ;;;###autoload
4269 (defun org-search-view (&optional todo-only string edit-at)
4270 "Show all entries that contain a phrase or words or regular expressions.
4272 With optional prefix argument TODO-ONLY, only consider entries that are
4273 TODO entries. The argument STRING can be used to pass a default search
4274 string into this function. If EDIT-AT is non-nil, it means that the
4275 user should get a chance to edit this string, with cursor at position
4276 EDIT-AT.
4278 The search string can be viewed either as a phrase that should be found as
4279 is, or it can be broken into a number of snippets, each of which must match
4280 in a Boolean way to select an entry. The default depends on the variable
4281 `org-agenda-search-view-always-boolean'.
4282 Even if this is turned off (the default) you can always switch to
4283 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4285 The default is a direct search of the whole phrase, where each space in
4286 the search string can expand to an arbitrary amount of whitespace,
4287 including newlines.
4289 If using a Boolean search, the search string is split on whitespace and
4290 each snippet is searched separately, with logical AND to select an entry.
4291 Words prefixed with a minus must *not* occur in the entry. Words without
4292 a prefix or prefixed with a plus must occur in the entry. Matching is
4293 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4294 match whole words, not parts of a word) if
4295 `org-agenda-search-view-force-full-words' is set (default is nil).
4297 Boolean search snippets enclosed by curly braces are interpreted as
4298 regular expressions that must or (when preceded with \"-\") must not
4299 match in the entry. Snippets enclosed into double quotes will be taken
4300 as a whole, to include whitespace.
4302 - If the search string starts with an asterisk, search only in headlines.
4303 - If (possibly after the leading star) the search string starts with an
4304 exclamation mark, this also means to look at TODO entries only, an effect
4305 that can also be achieved with a prefix argument.
4306 - If (possibly after star and exclamation mark) the search string starts
4307 with a colon, this will mean that the (non-regexp) snippets of the
4308 Boolean search must match as full words.
4310 This command searches the agenda files, and in addition the files listed
4311 in `org-agenda-text-search-extra-files'."
4312 (interactive "P")
4313 (if org-agenda-overriding-arguments
4314 (setq todo-only (car org-agenda-overriding-arguments)
4315 string (nth 1 org-agenda-overriding-arguments)
4316 edit-at (nth 2 org-agenda-overriding-arguments)))
4317 (let* ((props (list 'face nil
4318 'done-face 'org-agenda-done
4319 'org-not-done-regexp org-not-done-regexp
4320 'org-todo-regexp org-todo-regexp
4321 'org-complex-heading-regexp org-complex-heading-regexp
4322 'mouse-face 'highlight
4323 'help-echo (format "mouse-2 or RET jump to location")))
4324 (full-words org-agenda-search-view-force-full-words)
4325 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4326 regexp rtn rtnall files file pos inherited-tags
4327 marker category category-pos tags c neg re boolean
4328 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4329 (unless (and (not edit-at)
4330 (stringp string)
4331 (string-match "\\S-" string))
4332 (setq string (read-string
4333 (if org-agenda-search-view-always-boolean
4334 "[+-]Word/{Regexp} ...: "
4335 "Phrase or [+-]Word/{Regexp} ...: ")
4336 (cond
4337 ((integerp edit-at) (cons string edit-at))
4338 (edit-at string))
4339 'org-agenda-search-history)))
4340 (catch 'exit
4341 (if org-agenda-sticky
4342 (setq org-agenda-buffer-name
4343 (if (stringp string)
4344 (format "*Org Agenda(%s:%s)*"
4345 (or org-keys (or (and todo-only "S") "s")) string)
4346 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4347 (org-agenda-prepare "SEARCH")
4348 (org-compile-prefix-format 'search)
4349 (org-set-sorting-strategy 'search)
4350 (setq org-agenda-redo-command
4351 (list 'org-search-view (if todo-only t nil)
4352 (list 'if 'current-prefix-arg nil string)))
4353 (setq org-agenda-query-string string)
4354 (if (equal (string-to-char string) ?*)
4355 (setq hdl-only t
4356 words (substring string 1))
4357 (setq words string))
4358 (when (equal (string-to-char words) ?!)
4359 (setq todo-only t
4360 words (substring words 1)))
4361 (when (equal (string-to-char words) ?:)
4362 (setq full-words t
4363 words (substring words 1)))
4364 (if (or org-agenda-search-view-always-boolean
4365 (member (string-to-char words) '(?- ?+ ?\{)))
4366 (setq boolean t))
4367 (setq words (org-split-string words))
4368 (let (www w)
4369 (while (setq w (pop words))
4370 (while (and (string-match "\\\\\\'" w) words)
4371 (setq w (concat (substring w 0 -1) " " (pop words))))
4372 (push w www))
4373 (setq words (nreverse www) www nil)
4374 (while (setq w (pop words))
4375 (when (and (string-match "\\`[-+]?{" w)
4376 (not (string-match "}\\'" w)))
4377 (while (and words (not (string-match "}\\'" (car words))))
4378 (setq w (concat w " " (pop words))))
4379 (setq w (concat w " " (pop words))))
4380 (push w www))
4381 (setq words (nreverse www)))
4382 (setq org-agenda-last-search-view-search-was-boolean boolean)
4383 (when boolean
4384 (let (wds w)
4385 (while (setq w (pop words))
4386 (if (or (equal (substring w 0 1) "\"")
4387 (and (> (length w) 1)
4388 (member (substring w 0 1) '("+" "-"))
4389 (equal (substring w 1 2) "\"")))
4390 (while (and words (not (equal (substring w -1) "\"")))
4391 (setq w (concat w " " (pop words)))))
4392 (and (string-match "\\`\\([-+]?\\)\"" w)
4393 (setq w (replace-match "\\1" nil nil w)))
4394 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4395 (push w wds))
4396 (setq words (nreverse wds))))
4397 (if boolean
4398 (mapc (lambda (w)
4399 (setq c (string-to-char w))
4400 (if (equal c ?-)
4401 (setq neg t w (substring w 1))
4402 (if (equal c ?+)
4403 (setq neg nil w (substring w 1))
4404 (setq neg nil)))
4405 (if (string-match "\\`{.*}\\'" w)
4406 (setq re (substring w 1 -1))
4407 (if full-words
4408 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4409 (setq re (regexp-quote (downcase w)))))
4410 (if neg (push re regexps-) (push re regexps+)))
4411 words)
4412 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4413 regexps+))
4414 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4415 (if (not regexps+)
4416 (setq regexp org-outline-regexp-bol)
4417 (setq regexp (pop regexps+))
4418 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4419 regexp))))
4420 (setq files (org-agenda-files nil 'ifmode))
4421 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4422 (pop org-agenda-text-search-extra-files)
4423 (setq files (org-add-archive-files files)))
4424 (setq files (append files org-agenda-text-search-extra-files)
4425 rtnall nil)
4426 (while (setq file (pop files))
4427 (setq ee nil)
4428 (catch 'nextfile
4429 (org-check-agenda-file file)
4430 (setq buffer (if (file-exists-p file)
4431 (org-get-agenda-file-buffer file)
4432 (error "No such file %s" file)))
4433 (if (not buffer)
4434 ;; If file does not exist, make sure an error message is sent
4435 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4436 file))))
4437 (with-current-buffer buffer
4438 (with-syntax-table (org-search-syntax-table)
4439 (unless (derived-mode-p 'org-mode)
4440 (error "Agenda file %s is not in `org-mode'" file))
4441 (let ((case-fold-search t))
4442 (save-excursion
4443 (save-restriction
4444 (if org-agenda-restrict
4445 (narrow-to-region org-agenda-restrict-begin
4446 org-agenda-restrict-end)
4447 (widen))
4448 (goto-char (point-min))
4449 (unless (or (org-at-heading-p)
4450 (outline-next-heading))
4451 (throw 'nextfile t))
4452 (goto-char (max (point-min) (1- (point))))
4453 (while (re-search-forward regexp nil t)
4454 (org-back-to-heading t)
4455 (skip-chars-forward "* ")
4456 (setq beg (point-at-bol)
4457 beg1 (point)
4458 end (progn (outline-next-heading) (point)))
4459 (catch :skip
4460 (goto-char beg)
4461 (org-agenda-skip)
4462 (setq str (buffer-substring-no-properties
4463 (point-at-bol)
4464 (if hdl-only (point-at-eol) end)))
4465 (mapc (lambda (wr) (when (string-match wr str)
4466 (goto-char (1- end))
4467 (throw :skip t)))
4468 regexps-)
4469 (mapc (lambda (wr) (unless (string-match wr str)
4470 (goto-char (1- end))
4471 (throw :skip t)))
4472 (if todo-only
4473 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4474 regexps+)
4475 regexps+))
4476 (goto-char beg)
4477 (setq marker (org-agenda-new-marker (point))
4478 category (org-get-category)
4479 category-pos (get-text-property (point) 'org-category-position)
4480 inherited-tags
4481 (or (eq org-agenda-show-inherited-tags 'always)
4482 (memq 'todo org-agenda-show-inherited-tags)
4483 (and (eq org-agenda-show-inherited-tags t)
4484 (or (eq org-agenda-use-tag-inheritance t)
4485 (memq 'todo org-agenda-use-tag-inheritance))))
4486 tags (org-get-tags-at nil (not inherited-tags))
4487 txt (org-agenda-format-item
4489 (buffer-substring-no-properties
4490 beg1 (point-at-eol))
4491 category tags t))
4492 (org-add-props txt props
4493 'org-marker marker 'org-hd-marker marker
4494 'org-todo-regexp org-todo-regexp
4495 'org-complex-heading-regexp org-complex-heading-regexp
4496 'priority 1000 'org-category category
4497 'org-category-position category-pos
4498 'type "search")
4499 (push txt ee)
4500 (goto-char (1- end))))))))))
4501 (setq rtn (nreverse ee))
4502 (setq rtnall (append rtnall rtn)))
4503 (if org-agenda-overriding-header
4504 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4505 nil 'face 'org-agenda-structure) "\n")
4506 (insert "Search words: ")
4507 (add-text-properties (point-min) (1- (point))
4508 (list 'face 'org-agenda-structure))
4509 (setq pos (point))
4510 (insert string "\n")
4511 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4512 (setq pos (point))
4513 (unless org-agenda-multi
4514 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4515 (add-text-properties pos (1- (point))
4516 (list 'face 'org-agenda-structure))))
4517 (org-agenda-mark-header-line (point-min))
4518 (when rtnall
4519 (insert (org-agenda-finalize-entries rtnall) "\n"))
4520 (goto-char (point-min))
4521 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4522 (add-text-properties (point-min) (point-max)
4523 `(org-agenda-type search
4524 org-last-args (,todo-only ,string ,edit-at)
4525 org-redo-cmd ,org-agenda-redo-command
4526 org-series-cmd ,org-cmd))
4527 (org-agenda-finalize)
4528 (setq buffer-read-only t))))
4530 (autoload 'org-search-view "org-agenda" "\
4531 Show all entries that contain a phrase or words or regular expressions.
4533 With optional prefix argument TODO-ONLY, only consider entries that are
4534 TODO entries. The argument STRING can be used to pass a default search
4535 string into this function. If EDIT-AT is non-nil, it means that the
4536 user should get a chance to edit this string, with cursor at position
4537 EDIT-AT.
4539 The search string can be viewed either as a phrase that should be found as
4540 is, or it can be broken into a number of snippets, each of which must match
4541 in a Boolean way to select an entry. The default depends on the variable
4542 `org-agenda-search-view-always-boolean'.
4543 Even if this is turned off (the default) you can always switch to
4544 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4546 The default is a direct search of the whole phrase, where each space in
4547 the search string can expand to an arbitrary amount of whitespace,
4548 including newlines.
4550 If using a Boolean search, the search string is split on whitespace and
4551 each snippet is searched separately, with logical AND to select an entry.
4552 Words prefixed with a minus must *not* occur in the entry. Words without
4553 a prefix or prefixed with a plus must occur in the entry. Matching is
4554 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4555 match whole words, not parts of a word) if
4556 `org-agenda-search-view-force-full-words' is set (default is nil).
4558 Boolean search snippets enclosed by curly braces are interpreted as
4559 regular expressions that must or (when preceded with \"-\") must not
4560 match in the entry. Snippets enclosed into double quotes will be taken
4561 as a whole, to include whitespace.
4563 - If the search string starts with an asterisk, search only in headlines.
4564 - If (possibly after the leading star) the search string starts with an
4565 exclamation mark, this also means to look at TODO entries only, an effect
4566 that can also be achieved with a prefix argument.
4567 - If (possibly after star and exclamation mark) the search string starts
4568 with a colon, this will mean that the (non-regexp) snippets of the
4569 Boolean search must match as full words.
4571 This command searches the agenda files, and in addition the files listed
4572 in `org-agenda-text-search-extra-files'.
4574 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4576 ;;; Agenda TODO list
4578 (defvar org-select-this-todo-keyword nil)
4579 (defvar org-last-arg nil)
4581 ;;;###autoload
4582 (defun org-todo-list (&optional arg)
4583 "Show all (not done) TODO entries from all agenda file in a single list.
4584 The prefix arg can be used to select a specific TODO keyword and limit
4585 the list to these. When using \\[universal-argument], you will be prompted
4586 for a keyword. A numeric prefix directly selects the Nth keyword in
4587 `org-todo-keywords-1'."
4588 (interactive "P")
4589 (if org-agenda-overriding-arguments
4590 (setq arg org-agenda-overriding-arguments))
4591 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4592 (let* ((today (org-today))
4593 (date (calendar-gregorian-from-absolute today))
4594 (kwds org-todo-keywords-for-agenda)
4595 (completion-ignore-case t)
4596 (org-select-this-todo-keyword
4597 (if (stringp arg) arg
4598 (and arg (integerp arg) (> arg 0)
4599 (nth (1- arg) kwds))))
4600 rtn rtnall files file pos)
4601 (when (equal arg '(4))
4602 (setq org-select-this-todo-keyword
4603 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4604 (mapcar 'list kwds) nil nil)))
4605 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4606 (catch 'exit
4607 (if org-agenda-sticky
4608 (setq org-agenda-buffer-name
4609 (if (stringp org-select-this-todo-keyword)
4610 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4611 org-select-this-todo-keyword)
4612 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4613 (org-agenda-prepare "TODO")
4614 (org-compile-prefix-format 'todo)
4615 (org-set-sorting-strategy 'todo)
4616 (setq org-agenda-redo-command
4617 `(org-todo-list (or (and (numberp current-prefix-arg)
4618 current-prefix-arg)
4619 ,org-select-this-todo-keyword
4620 current-prefix-arg ,arg)))
4621 (setq files (org-agenda-files nil 'ifmode)
4622 rtnall nil)
4623 (while (setq file (pop files))
4624 (catch 'nextfile
4625 (org-check-agenda-file file)
4626 (setq rtn (org-agenda-get-day-entries file date :todo))
4627 (setq rtnall (append rtnall rtn))))
4628 (if org-agenda-overriding-header
4629 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4630 nil 'face 'org-agenda-structure) "\n")
4631 (insert "Global list of TODO items of type: ")
4632 (add-text-properties (point-min) (1- (point))
4633 (list 'face 'org-agenda-structure
4634 'short-heading
4635 (concat "ToDo: "
4636 (or org-select-this-todo-keyword "ALL"))))
4637 (org-agenda-mark-header-line (point-min))
4638 (setq pos (point))
4639 (insert (or org-select-this-todo-keyword "ALL") "\n")
4640 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4641 (setq pos (point))
4642 (unless org-agenda-multi
4643 (insert "Available with `N r': (0)[ALL]")
4644 (let ((n 0) s)
4645 (mapc (lambda (x)
4646 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4647 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4648 (insert "\n "))
4649 (insert " " s))
4650 kwds))
4651 (insert "\n"))
4652 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4653 (org-agenda-mark-header-line (point-min))
4654 (when rtnall
4655 (insert (org-agenda-finalize-entries rtnall) "\n"))
4656 (goto-char (point-min))
4657 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4658 (add-text-properties (point-min) (point-max)
4659 `(org-agenda-type todo
4660 org-last-args ,arg
4661 org-redo-cmd ,org-agenda-redo-command
4662 org-series-cmd ,org-cmd))
4663 (org-agenda-finalize)
4664 (setq buffer-read-only t))))
4666 (autoload 'org-todo-list "org-agenda" "\
4667 Show all (not done) TODO entries from all agenda file in a single list.
4668 The prefix arg can be used to select a specific TODO keyword and limit
4669 the list to these. When using \\[universal-argument], you will be prompted
4670 for a keyword. A numeric prefix directly selects the Nth keyword in
4671 `org-todo-keywords-1'.
4673 \(fn &optional ARG)" t nil)
4675 ;;; Agenda tags match
4677 ;;;###autoload
4678 (defun org-tags-view (&optional todo-only match)
4679 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4680 The prefix arg TODO-ONLY limits the search to TODO entries."
4681 (interactive "P")
4682 (if org-agenda-overriding-arguments
4683 (setq todo-only (car org-agenda-overriding-arguments)
4684 match (nth 1 org-agenda-overriding-arguments)))
4685 (let* ((org-tags-match-list-sublevels
4686 org-tags-match-list-sublevels)
4687 (completion-ignore-case t)
4688 rtn rtnall files file pos matcher
4689 buffer)
4690 (when (and (stringp match) (not (string-match "\\S-" match)))
4691 (setq match nil))
4692 (setq matcher (org-make-tags-matcher match)
4693 match (car matcher) matcher (cdr matcher))
4694 (catch 'exit
4695 (if org-agenda-sticky
4696 (setq org-agenda-buffer-name
4697 (if (stringp match)
4698 (format "*Org Agenda(%s:%s)*"
4699 (or org-keys (or (and todo-only "M") "m")) match)
4700 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4701 (org-agenda-prepare (concat "TAGS " match))
4702 (org-compile-prefix-format 'tags)
4703 (org-set-sorting-strategy 'tags)
4704 (setq org-agenda-query-string match)
4705 (setq org-agenda-redo-command
4706 (list 'org-tags-view `(quote ,todo-only)
4707 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4708 (setq files (org-agenda-files nil 'ifmode)
4709 rtnall nil)
4710 (while (setq file (pop files))
4711 (catch 'nextfile
4712 (org-check-agenda-file file)
4713 (setq buffer (if (file-exists-p file)
4714 (org-get-agenda-file-buffer file)
4715 (error "No such file %s" file)))
4716 (if (not buffer)
4717 ;; If file does not exist, error message to agenda
4718 (setq rtn (list
4719 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4720 rtnall (append rtnall rtn))
4721 (with-current-buffer buffer
4722 (unless (derived-mode-p 'org-mode)
4723 (error "Agenda file %s is not in `org-mode'" file))
4724 (save-excursion
4725 (save-restriction
4726 (if org-agenda-restrict
4727 (narrow-to-region org-agenda-restrict-begin
4728 org-agenda-restrict-end)
4729 (widen))
4730 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4731 (setq rtnall (append rtnall rtn))))))))
4732 (if org-agenda-overriding-header
4733 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4734 nil 'face 'org-agenda-structure) "\n")
4735 (insert "Headlines with TAGS match: ")
4736 (add-text-properties (point-min) (1- (point))
4737 (list 'face 'org-agenda-structure
4738 'short-heading
4739 (concat "Match: " match)))
4740 (setq pos (point))
4741 (insert match "\n")
4742 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4743 (setq pos (point))
4744 (unless org-agenda-multi
4745 (insert "Press `C-u r' to search again with new search string\n"))
4746 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4747 (org-agenda-mark-header-line (point-min))
4748 (when rtnall
4749 (insert (org-agenda-finalize-entries rtnall) "\n"))
4750 (goto-char (point-min))
4751 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4752 (add-text-properties (point-min) (point-max)
4753 `(org-agenda-type tags
4754 org-last-args (,todo-only ,match)
4755 org-redo-cmd ,org-agenda-redo-command
4756 org-series-cmd ,org-cmd))
4757 (org-agenda-finalize)
4758 (setq buffer-read-only t))))
4760 (autoload 'org-tags-view "org-agenda" "\
4761 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4762 The prefix arg TODO-ONLY limits the search to TODO entries.
4764 \(fn &optional TODO-ONLY MATCH)" t nil)
4766 ;;; Agenda Finding stuck projects
4768 (defvar org-agenda-skip-regexp nil
4769 "Regular expression used in skipping subtrees for the agenda.
4770 This is basically a temporary global variable that can be set and then
4771 used by user-defined selections using `org-agenda-skip-function'.")
4773 (defvar org-agenda-overriding-header nil
4774 "When set during agenda, todo and tags searches it replaces the header.
4775 This variable should not be set directly, but custom commands can bind it
4776 in the options section.")
4778 (defun org-agenda-skip-entry-when-regexp-matches ()
4779 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4780 If yes, it returns the end position of this entry, causing agenda commands
4781 to skip the entry but continuing the search in the subtree. This is a
4782 function that can be put into `org-agenda-skip-function' for the duration
4783 of a command."
4784 (let ((end (save-excursion (org-end-of-subtree t)))
4785 skip)
4786 (save-excursion
4787 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4788 (and skip end)))
4790 (defun org-agenda-skip-subtree-when-regexp-matches ()
4791 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4792 If yes, it returns the end position of this tree, causing agenda commands
4793 to skip this subtree. This is a function that can be put into
4794 `org-agenda-skip-function' for the duration of a command."
4795 (let ((end (save-excursion (org-end-of-subtree t)))
4796 skip)
4797 (save-excursion
4798 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4799 (and skip end)))
4801 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4802 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4803 If yes, it returns the end position of the current entry (NOT the tree),
4804 causing agenda commands to skip the entry but continuing the search in
4805 the subtree. This is a function that can be put into
4806 `org-agenda-skip-function' for the duration of a command. An important
4807 use of this function is for the stuck project list."
4808 (let ((end (save-excursion (org-end-of-subtree t)))
4809 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4810 skip)
4811 (save-excursion
4812 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4813 (and skip entry-end)))
4815 (defun org-agenda-skip-entry-if (&rest conditions)
4816 "Skip entry if any of CONDITIONS is true.
4817 See `org-agenda-skip-if' for details."
4818 (org-agenda-skip-if nil conditions))
4820 (defun org-agenda-skip-subtree-if (&rest conditions)
4821 "Skip entry if any of CONDITIONS is true.
4822 See `org-agenda-skip-if' for details."
4823 (org-agenda-skip-if t conditions))
4825 (defun org-agenda-skip-if (subtree conditions)
4826 "Checks current entity for CONDITIONS.
4827 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4828 the entry (i.e. the text before the next heading) is checked.
4830 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4831 from different tests. Valid conditions are:
4833 scheduled Check if there is a scheduled cookie
4834 notscheduled Check if there is no scheduled cookie
4835 deadline Check if there is a deadline
4836 notdeadline Check if there is no deadline
4837 timestamp Check if there is a timestamp (also deadline or scheduled)
4838 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4839 regexp Check if regexp matches
4840 notregexp Check if regexp does not match.
4841 todo Check if TODO keyword matches
4842 nottodo Check if TODO keyword does not match
4844 The regexp is taken from the conditions list, it must come right after
4845 the `regexp' or `notregexp' element.
4847 `todo' and `nottodo' accept as an argument a list of todo
4848 keywords, which may include \"*\" to match any todo keyword.
4850 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4852 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4854 Instead of a list, a keyword class may be given. For example:
4856 (org-agenda-skip-entry-if 'nottodo 'done)
4858 would skip entries that haven't been marked with any of \"DONE\"
4859 keywords. Possible classes are: `todo', `done', `any'.
4861 If any of these conditions is met, this function returns the end point of
4862 the entity, causing the search to continue from there. This is a function
4863 that can be put into `org-agenda-skip-function' for the duration of a command."
4864 (let (beg end m)
4865 (org-back-to-heading t)
4866 (setq beg (point)
4867 end (if subtree
4868 (progn (org-end-of-subtree t) (point))
4869 (progn (outline-next-heading) (1- (point)))))
4870 (goto-char beg)
4871 (and
4873 (and (memq 'scheduled conditions)
4874 (re-search-forward org-scheduled-time-regexp end t))
4875 (and (memq 'notscheduled conditions)
4876 (not (re-search-forward org-scheduled-time-regexp end t)))
4877 (and (memq 'deadline conditions)
4878 (re-search-forward org-deadline-time-regexp end t))
4879 (and (memq 'notdeadline conditions)
4880 (not (re-search-forward org-deadline-time-regexp end t)))
4881 (and (memq 'timestamp conditions)
4882 (re-search-forward org-ts-regexp end t))
4883 (and (memq 'nottimestamp conditions)
4884 (not (re-search-forward org-ts-regexp end t)))
4885 (and (setq m (memq 'regexp conditions))
4886 (stringp (nth 1 m))
4887 (re-search-forward (nth 1 m) end t))
4888 (and (setq m (memq 'notregexp conditions))
4889 (stringp (nth 1 m))
4890 (not (re-search-forward (nth 1 m) end t)))
4891 (and (or
4892 (setq m (memq 'nottodo conditions))
4893 (setq m (memq 'todo-unblocked conditions))
4894 (setq m (memq 'nottodo-unblocked conditions))
4895 (setq m (memq 'todo conditions)))
4896 (org-agenda-skip-if-todo m end)))
4897 end)))
4899 (defun org-agenda-skip-if-todo (args end)
4900 "Helper function for `org-agenda-skip-if', do not use it directly.
4901 ARGS is a list with first element either `todo', `nottodo',
4902 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4903 a list of TODO keywords, or a state symbol `todo' or `done' or
4904 `any'."
4905 (let ((kw (car args))
4906 (arg (cadr args))
4907 todo-wds todo-re)
4908 (setq todo-wds
4909 (org-uniquify
4910 (cond
4911 ((listp arg) ;; list of keywords
4912 (if (member "*" arg)
4913 (mapcar 'substring-no-properties org-todo-keywords-1)
4914 arg))
4915 ((symbolp arg) ;; keyword class name
4916 (cond
4917 ((eq arg 'todo)
4918 (org-delete-all org-done-keywords
4919 (mapcar 'substring-no-properties
4920 org-todo-keywords-1)))
4921 ((eq arg 'done) org-done-keywords)
4922 ((eq arg 'any)
4923 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4924 (setq todo-re
4925 (concat "^\\*+[ \t]+\\<\\("
4926 (mapconcat 'identity todo-wds "\\|")
4927 "\\)\\>"))
4928 (cond
4929 ((eq kw 'todo) (re-search-forward todo-re end t))
4930 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4931 ((eq kw 'todo-unblocked)
4932 (catch 'unblocked
4933 (while (re-search-forward todo-re end t)
4934 (or (org-entry-blocked-p) (throw 'unblocked t)))
4935 nil))
4936 ((eq kw 'nottodo-unblocked)
4937 (catch 'unblocked
4938 (while (re-search-forward todo-re end t)
4939 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4943 ;;;###autoload
4944 (defun org-agenda-list-stuck-projects (&rest ignore)
4945 "Create agenda view for projects that are stuck.
4946 Stuck projects are project that have no next actions. For the definitions
4947 of what a project is and how to check if it stuck, customize the variable
4948 `org-stuck-projects'."
4949 (interactive)
4950 (let* ((org-agenda-skip-function
4951 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4952 ;; We could have used org-agenda-skip-if here.
4953 (org-agenda-overriding-header
4954 (or org-agenda-overriding-header "List of stuck projects: "))
4955 (matcher (nth 0 org-stuck-projects))
4956 (todo (nth 1 org-stuck-projects))
4957 (todo-wds (if (member "*" todo)
4958 (progn
4959 (org-agenda-prepare-buffers (org-agenda-files
4960 nil 'ifmode))
4961 (org-delete-all
4962 org-done-keywords-for-agenda
4963 (copy-sequence org-todo-keywords-for-agenda)))
4964 todo))
4965 (todo-re (concat "^\\*+[ \t]+\\("
4966 (mapconcat 'identity todo-wds "\\|")
4967 "\\)\\>"))
4968 (tags (nth 2 org-stuck-projects))
4969 (tags-re (if (member "*" tags)
4970 (concat org-outline-regexp-bol
4971 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4972 (if tags
4973 (concat org-outline-regexp-bol
4974 ".*:\\("
4975 (mapconcat 'identity tags "\\|")
4976 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4977 (gen-re (nth 3 org-stuck-projects))
4978 (re-list
4979 (delq nil
4980 (list
4981 (if todo todo-re)
4982 (if tags tags-re)
4983 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4984 gen-re)))))
4985 (setq org-agenda-skip-regexp
4986 (if re-list
4987 (mapconcat 'identity re-list "\\|")
4988 (error "No information how to identify unstuck projects")))
4989 (org-tags-view nil matcher)
4990 (with-current-buffer org-agenda-buffer-name
4991 (setq org-agenda-redo-command
4992 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4994 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4995 Create agenda view for projects that are stuck.
4996 Stuck projects are project that have no next actions. For the definitions
4997 of what a project is and how to check if it stuck, customize the variable
4998 `org-stuck-projects'.
5000 \(fn &rest IGNORE)" t nil)
5002 ;;; Diary integration
5004 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5005 (defvar diary-list-entries-hook)
5006 (defvar diary-time-regexp)
5007 (defun org-get-entries-from-diary (date)
5008 "Get the (Emacs Calendar) diary entries for DATE."
5009 (require 'diary-lib)
5010 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5011 (diary-display-hook '(fancy-diary-display))
5012 (diary-display-function 'fancy-diary-display)
5013 (pop-up-frames nil)
5014 (diary-list-entries-hook
5015 (cons 'org-diary-default-entry diary-list-entries-hook))
5016 (diary-file-name-prefix nil) ; turn this feature off
5017 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5018 entries
5019 (org-disable-agenda-to-diary t))
5020 (save-excursion
5021 (save-window-excursion
5022 (funcall (if (fboundp 'diary-list-entries)
5023 'diary-list-entries 'list-diary-entries)
5024 date 1)))
5025 (if (not (get-buffer diary-fancy-buffer))
5026 (setq entries nil)
5027 (with-current-buffer diary-fancy-buffer
5028 (setq buffer-read-only nil)
5029 (if (zerop (buffer-size))
5030 ;; No entries
5031 (setq entries nil)
5032 ;; Omit the date and other unnecessary stuff
5033 (org-agenda-cleanup-fancy-diary)
5034 ;; Add prefix to each line and extend the text properties
5035 (if (zerop (buffer-size))
5036 (setq entries nil)
5037 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5038 (setq entries
5039 (with-temp-buffer
5040 (insert entries) (goto-char (point-min))
5041 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5042 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5043 (replace-match (concat "; " (match-string 1)))))
5044 (buffer-string)))))
5045 (set-buffer-modified-p nil)
5046 (kill-buffer diary-fancy-buffer)))
5047 (when entries
5048 (setq entries (org-split-string entries "\n"))
5049 (setq entries
5050 (mapcar
5051 (lambda (x)
5052 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
5053 ;; Extend the text properties to the beginning of the line
5054 (org-add-props x (text-properties-at (1- (length x)) x)
5055 'type "diary" 'date date 'face 'org-agenda-diary))
5056 entries)))))
5058 (defvar org-agenda-cleanup-fancy-diary-hook nil
5059 "Hook run when the fancy diary buffer is cleaned up.")
5061 (defun org-agenda-cleanup-fancy-diary ()
5062 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5063 This gets rid of the date, the underline under the date, and
5064 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5065 date. It also removes lines that contain only whitespace."
5066 (goto-char (point-min))
5067 (if (looking-at ".*?:[ \t]*")
5068 (progn
5069 (replace-match "")
5070 (re-search-forward "\n=+$" nil t)
5071 (replace-match "")
5072 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5073 (re-search-forward "\n=+$" nil t)
5074 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5075 (goto-char (point-min))
5076 (while (re-search-forward "^ +\n" nil t)
5077 (replace-match ""))
5078 (goto-char (point-min))
5079 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5080 (replace-match ""))
5081 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5083 ;; Make sure entries from the diary have the right text properties.
5084 (eval-after-load "diary-lib"
5085 '(if (boundp 'diary-modify-entry-list-string-function)
5086 ;; We can rely on the hook, nothing to do
5088 ;; Hook not available, must use advice to make this work
5089 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5090 "Make the position visible."
5091 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5092 (stringp string)
5093 buffer-file-name)
5094 (setq string (org-modify-diary-entry-string string))))))
5096 (defun org-modify-diary-entry-string (string)
5097 "Add text properties to string, allowing org-mode to act on it."
5098 (org-add-props string nil
5099 'mouse-face 'highlight
5100 'help-echo (if buffer-file-name
5101 (format "mouse-2 or RET jump to diary file %s"
5102 (abbreviate-file-name buffer-file-name))
5104 'org-agenda-diary-link t
5105 'org-marker (org-agenda-new-marker (point-at-bol))))
5107 (defun org-diary-default-entry ()
5108 "Add a dummy entry to the diary.
5109 Needed to avoid empty dates which mess up holiday display."
5110 ;; Catch the error if dealing with the new add-to-diary-alist
5111 (when org-disable-agenda-to-diary
5112 (condition-case nil
5113 (org-add-to-diary-list original-date "Org-mode dummy" "")
5114 (error
5115 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5117 (defun org-add-to-diary-list (&rest args)
5118 (if (fboundp 'diary-add-to-list)
5119 (apply 'diary-add-to-list args)
5120 (apply 'add-to-diary-list args)))
5122 (defvar org-diary-last-run-time nil)
5124 ;;;###autoload
5125 (defun org-diary (&rest args)
5126 "Return diary information from org files.
5127 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5128 It accesses org files and extracts information from those files to be
5129 listed in the diary. The function accepts arguments specifying what
5130 items should be listed. For a list of arguments allowed here, see the
5131 variable `org-agenda-entry-types'.
5133 The call in the diary file should look like this:
5135 &%%(org-diary) ~/path/to/some/orgfile.org
5137 Use a separate line for each org file to check. Or, if you omit the file name,
5138 all files listed in `org-agenda-files' will be checked automatically:
5140 &%%(org-diary)
5142 If you don't give any arguments (as in the example above), the default
5143 arguments (:deadline :scheduled :timestamp :sexp) are used.
5144 So the example above may also be written as
5146 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5148 The function expects the lisp variables `entry' and `date' to be provided
5149 by the caller, because this is how the calendar works. Don't use this
5150 function from a program - use `org-agenda-get-day-entries' instead."
5151 (when (> (- (org-float-time)
5152 org-agenda-last-marker-time)
5154 ;; I am not sure if this works with sticky agendas, because the marker
5155 ;; list is then no longer a global variable.
5156 (org-agenda-reset-markers))
5157 (org-compile-prefix-format 'agenda)
5158 (org-set-sorting-strategy 'agenda)
5159 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5160 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5161 (list entry)
5162 (org-agenda-files t)))
5163 (time (org-float-time))
5164 file rtn results)
5165 (when (or (not org-diary-last-run-time)
5166 (> (- time
5167 org-diary-last-run-time)
5169 (org-agenda-prepare-buffers files))
5170 (setq org-diary-last-run-time time)
5171 ;; If this is called during org-agenda, don't return any entries to
5172 ;; the calendar. Org Agenda will list these entries itself.
5173 (if org-disable-agenda-to-diary (setq files nil))
5174 (while (setq file (pop files))
5175 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5176 (setq results (append results rtn)))
5177 (if results
5178 (concat (org-agenda-finalize-entries results) "\n"))))
5180 (autoload 'org-diary "org-agenda" "\
5181 Return diary information from org files.
5182 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5183 It accesses org files and extracts information from those files to be
5184 listed in the diary. The function accepts arguments specifying what
5185 items should be listed. For a list of arguments allowed here, see the
5186 variable `org-agenda-entry-types'.
5188 The call in the diary file should look like this:
5190 &%%(org-diary) ~/path/to/some/orgfile.org
5192 Use a separate line for each org file to check. Or, if you omit the file name,
5193 all files listed in `org-agenda-files' will be checked automatically:
5195 &%%(org-diary)
5197 If you don't give any arguments (as in the example above), the default
5198 arguments (:deadline :scheduled :timestamp :sexp) are used.
5199 So the example above may also be written as
5201 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5203 The function expects the lisp variables `entry' and `date' to be provided
5204 by the caller, because this is how the calendar works. Don't use this
5205 function from a program - use `org-agenda-get-day-entries' instead.
5207 \(fn &rest ARGS)" nil nil)
5209 ;;; Agenda entry finders
5211 (defun org-agenda-get-day-entries (file date &rest args)
5212 "Does the work for `org-diary' and `org-agenda'.
5213 FILE is the path to a file to be checked for entries. DATE is date like
5214 the one returned by `calendar-current-date'. ARGS are symbols indicating
5215 which kind of entries should be extracted. For details about these, see
5216 the documentation of `org-diary'."
5217 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5218 (let* ((org-startup-folded nil)
5219 (org-startup-align-all-tables nil)
5220 (buffer (if (file-exists-p file)
5221 (org-get-agenda-file-buffer file)
5222 (error "No such file %s" file)))
5223 arg results rtn deadline-results)
5224 (if (not buffer)
5225 ;; If file does not exist, make sure an error message ends up in diary
5226 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5227 (with-current-buffer buffer
5228 (unless (derived-mode-p 'org-mode)
5229 (error "Agenda file %s is not in `org-mode'" file))
5230 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5231 (let ((case-fold-search nil))
5232 (save-excursion
5233 (save-restriction
5234 (if org-agenda-restrict
5235 (narrow-to-region org-agenda-restrict-begin
5236 org-agenda-restrict-end)
5237 (widen))
5238 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5239 (while (setq arg (pop args))
5240 (cond
5241 ((and (eq arg :todo)
5242 (equal date (calendar-gregorian-from-absolute
5243 (org-today))))
5244 (setq rtn (org-agenda-get-todos))
5245 (setq results (append results rtn)))
5246 ((eq arg :timestamp)
5247 (setq rtn (org-agenda-get-blocks))
5248 (setq results (append results rtn))
5249 (setq rtn (org-agenda-get-timestamps deadline-results))
5250 (setq results (append results rtn)))
5251 ((eq arg :sexp)
5252 (setq rtn (org-agenda-get-sexps))
5253 (setq results (append results rtn)))
5254 ((eq arg :scheduled)
5255 (setq rtn (org-agenda-get-scheduled deadline-results))
5256 (setq results (append results rtn)))
5257 ((eq arg :closed)
5258 (setq rtn (org-agenda-get-progress))
5259 (setq results (append results rtn)))
5260 ((eq arg :deadline)
5261 (setq rtn (org-agenda-get-deadlines))
5262 (setq deadline-results (copy-sequence rtn))
5263 (setq results (append results rtn))))))))
5264 results))))
5266 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5267 (defun org-agenda-get-todos ()
5268 "Return the TODO information for agenda display."
5269 (let* ((props (list 'face nil
5270 'done-face 'org-agenda-done
5271 'org-not-done-regexp org-not-done-regexp
5272 'org-todo-regexp org-todo-regexp
5273 'org-complex-heading-regexp org-complex-heading-regexp
5274 'mouse-face 'highlight
5275 'help-echo
5276 (format "mouse-2 or RET jump to org file %s"
5277 (abbreviate-file-name buffer-file-name))))
5278 (regexp (format org-heading-keyword-regexp-format
5279 (cond
5280 ((and org-select-this-todo-keyword
5281 (equal org-select-this-todo-keyword "*"))
5282 org-todo-regexp)
5283 (org-select-this-todo-keyword
5284 (concat "\\("
5285 (mapconcat 'identity
5286 (org-split-string
5287 org-select-this-todo-keyword
5288 "|")
5289 "\\|") "\\)"))
5290 (t org-not-done-regexp))))
5291 marker priority category category-pos tags todo-state
5292 ee txt beg end inherited-tags)
5293 (goto-char (point-min))
5294 (while (re-search-forward regexp nil t)
5295 (catch :skip
5296 (save-match-data
5297 (beginning-of-line)
5298 (org-agenda-skip)
5299 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5300 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5301 (goto-char (1+ beg))
5302 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5303 (throw :skip nil)))
5304 (goto-char (match-beginning 2))
5305 (setq marker (org-agenda-new-marker (match-beginning 0))
5306 category (org-get-category)
5307 category-pos (get-text-property (point) 'org-category-position)
5308 txt (org-trim
5309 (buffer-substring (match-beginning 2) (match-end 0)))
5310 inherited-tags
5311 (or (eq org-agenda-show-inherited-tags 'always)
5312 (and (listp org-agenda-show-inherited-tags)
5313 (memq 'todo org-agenda-show-inherited-tags))
5314 (and (eq org-agenda-show-inherited-tags t)
5315 (or (eq org-agenda-use-tag-inheritance t)
5316 (memq 'todo org-agenda-use-tag-inheritance))))
5317 tags (org-get-tags-at nil (not inherited-tags))
5318 txt (org-agenda-format-item "" txt category tags t)
5319 priority (1+ (org-get-priority txt))
5320 todo-state (org-get-todo-state))
5321 (org-add-props txt props
5322 'org-marker marker 'org-hd-marker marker
5323 'priority priority 'org-category category
5324 'org-category-position category-pos
5325 'type "todo" 'todo-state todo-state)
5326 (push txt ee)
5327 (if org-agenda-todo-list-sublevels
5328 (goto-char (match-end 2))
5329 (org-end-of-subtree 'invisible))))
5330 (nreverse ee)))
5332 (defun org-agenda-todo-custom-ignore-p (time n)
5333 "Check whether timestamp is farther away than n number of days.
5334 This function is invoked if `org-agenda-todo-ignore-deadlines',
5335 `org-agenda-todo-ignore-scheduled' or
5336 `org-agenda-todo-ignore-timestamp' is set to an integer."
5337 (let ((days (org-days-to-time time)))
5338 (if (>= n 0)
5339 (>= days n)
5340 (<= days n))))
5342 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5343 (&optional end)
5344 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5345 (when (or org-agenda-todo-ignore-with-date
5346 org-agenda-todo-ignore-scheduled
5347 org-agenda-todo-ignore-deadlines
5348 org-agenda-todo-ignore-timestamp)
5349 (setq end (or end (save-excursion (outline-next-heading) (point))))
5350 (save-excursion
5351 (or (and org-agenda-todo-ignore-with-date
5352 (re-search-forward org-ts-regexp end t))
5353 (and org-agenda-todo-ignore-scheduled
5354 (re-search-forward org-scheduled-time-regexp end t)
5355 (cond
5356 ((eq org-agenda-todo-ignore-scheduled 'future)
5357 (> (org-days-to-time (match-string 1)) 0))
5358 ((eq org-agenda-todo-ignore-scheduled 'past)
5359 (<= (org-days-to-time (match-string 1)) 0))
5360 ((numberp org-agenda-todo-ignore-scheduled)
5361 (org-agenda-todo-custom-ignore-p
5362 (match-string 1) org-agenda-todo-ignore-scheduled))
5363 (t)))
5364 (and org-agenda-todo-ignore-deadlines
5365 (re-search-forward org-deadline-time-regexp end t)
5366 (cond
5367 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5368 ((eq org-agenda-todo-ignore-deadlines 'far)
5369 (not (org-deadline-close (match-string 1))))
5370 ((eq org-agenda-todo-ignore-deadlines 'future)
5371 (> (org-days-to-time (match-string 1)) 0))
5372 ((eq org-agenda-todo-ignore-deadlines 'past)
5373 (<= (org-days-to-time (match-string 1)) 0))
5374 ((numberp org-agenda-todo-ignore-deadlines)
5375 (org-agenda-todo-custom-ignore-p
5376 (match-string 1) org-agenda-todo-ignore-deadlines))
5377 (t (org-deadline-close (match-string 1)))))
5378 (and org-agenda-todo-ignore-timestamp
5379 (let ((buffer (current-buffer))
5380 (regexp
5381 (concat
5382 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5383 (start (point)))
5384 ;; Copy current buffer into a temporary one
5385 (with-temp-buffer
5386 (insert-buffer-substring buffer start end)
5387 (goto-char (point-min))
5388 ;; Delete SCHEDULED and DEADLINE items
5389 (while (re-search-forward regexp end t)
5390 (delete-region (match-beginning 0) (match-end 0)))
5391 (goto-char (point-min))
5392 ;; No search for timestamp left
5393 (when (re-search-forward org-ts-regexp nil t)
5394 (cond
5395 ((eq org-agenda-todo-ignore-timestamp 'future)
5396 (> (org-days-to-time (match-string 1)) 0))
5397 ((eq org-agenda-todo-ignore-timestamp 'past)
5398 (<= (org-days-to-time (match-string 1)) 0))
5399 ((numberp org-agenda-todo-ignore-timestamp)
5400 (org-agenda-todo-custom-ignore-p
5401 (match-string 1) org-agenda-todo-ignore-timestamp))
5402 (t))))))))))
5404 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5405 Do we have a reason to ignore this TODO entry because it has a time stamp?
5407 \(fn &optional END)" nil nil)
5409 (defconst org-agenda-no-heading-message
5410 "No heading for this item in buffer or region.")
5412 (defun org-agenda-get-timestamps (&optional deadline-results)
5413 "Return the date stamp information for agenda display."
5414 (let* ((props (list 'face 'org-agenda-calendar-event
5415 'org-not-done-regexp org-not-done-regexp
5416 'org-todo-regexp org-todo-regexp
5417 'org-complex-heading-regexp org-complex-heading-regexp
5418 'mouse-face 'highlight
5419 'help-echo
5420 (format "mouse-2 or RET jump to org file %s"
5421 (abbreviate-file-name buffer-file-name))))
5422 (d1 (calendar-absolute-from-gregorian date))
5424 (deadline-position-alist
5425 (mapcar (lambda (a) (and (setq mm (get-text-property
5426 0 'org-hd-marker a))
5427 (cons (marker-position mm) a)))
5428 deadline-results))
5429 (remove-re org-ts-regexp)
5430 (regexp
5431 (concat
5432 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5433 (regexp-quote
5434 (substring
5435 (format-time-string
5436 (car org-time-stamp-formats)
5437 (apply 'encode-time ; DATE bound by calendar
5438 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5439 1 11))
5440 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5441 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5442 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5443 donep tmp priority category category-pos ee txt timestr tags
5444 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5445 inherited-tags)
5446 (goto-char (point-min))
5447 (while (setq end-of-match (re-search-forward regexp nil t))
5448 (setq b0 (match-beginning 0)
5449 b3 (match-beginning 3) e3 (match-end 3)
5450 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5451 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5452 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5453 (member todo-state
5454 org-agenda-repeating-timestamp-show-all)))
5455 (catch :skip
5456 (and (org-at-date-range-p) (throw :skip nil))
5457 (org-agenda-skip)
5458 (if (and (match-end 1)
5459 (not (= d1 (org-time-string-to-absolute
5460 (match-string 1) d1 nil show-all
5461 (current-buffer) b0))))
5462 (throw :skip nil))
5463 (if (and e3
5464 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5465 (throw :skip nil))
5466 (setq tmp (buffer-substring (max (point-min)
5467 (- b0 org-ds-keyword-length))
5469 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5470 inactivep (= (char-after b0) ?\[)
5471 deadlinep (string-match org-deadline-regexp tmp)
5472 scheduledp (string-match org-scheduled-regexp tmp)
5473 closedp (and org-agenda-include-inactive-timestamps
5474 (string-match org-closed-string tmp))
5475 clockp (and org-agenda-include-inactive-timestamps
5476 (or (string-match org-clock-string tmp)
5477 (string-match "]-+\\'" tmp)))
5478 warntime (get-text-property (point) 'org-appt-warntime)
5479 donep (member todo-state org-done-keywords))
5480 (if (or scheduledp deadlinep closedp clockp
5481 (and donep org-agenda-skip-timestamp-if-done))
5482 (throw :skip t))
5483 (if (string-match ">" timestr)
5484 ;; substring should only run to end of time stamp
5485 (setq timestr (substring timestr 0 (match-end 0))))
5486 (setq marker (org-agenda-new-marker b0)
5487 category (org-get-category b0)
5488 category-pos (get-text-property b0 'org-category-position))
5489 (save-excursion
5490 (if (not (re-search-backward org-outline-regexp-bol nil t))
5491 (setq txt org-agenda-no-heading-message)
5492 (goto-char (match-beginning 0))
5493 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5494 (assoc (point) deadline-position-alist))
5495 (throw :skip nil))
5496 (setq hdmarker (org-agenda-new-marker)
5497 inherited-tags
5498 (or (eq org-agenda-show-inherited-tags 'always)
5499 (and (listp org-agenda-show-inherited-tags)
5500 (memq 'agenda org-agenda-show-inherited-tags))
5501 (and (eq org-agenda-show-inherited-tags t)
5502 (or (eq org-agenda-use-tag-inheritance t)
5503 (memq 'agenda org-agenda-use-tag-inheritance))))
5504 tags (org-get-tags-at nil (not inherited-tags)))
5505 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5506 (setq head (or (match-string 1) ""))
5507 (setq txt (org-agenda-format-item
5508 (if inactivep org-agenda-inactive-leader nil)
5509 head category tags timestr
5510 remove-re habitp)))
5511 (setq priority (org-get-priority txt))
5512 (org-add-props txt props
5513 'org-marker marker 'org-hd-marker hdmarker)
5514 (org-add-props txt nil 'priority priority
5515 'org-category category 'date date
5516 'org-category-position category-pos
5517 'todo-state todo-state
5518 'warntime warntime
5519 'type "timestamp")
5520 (push txt ee))
5521 (if org-agenda-skip-additional-timestamps-same-entry
5522 (outline-next-heading)
5523 (goto-char end-of-match))))
5524 (nreverse ee)))
5526 (defun org-agenda-get-sexps ()
5527 "Return the sexp information for agenda display."
5528 (require 'diary-lib)
5529 (let* ((props (list 'face 'org-agenda-calendar-sexp
5530 'mouse-face 'highlight
5531 'help-echo
5532 (format "mouse-2 or RET jump to org file %s"
5533 (abbreviate-file-name buffer-file-name))))
5534 (regexp "^&?%%(")
5535 marker category extra category-pos ee txt tags entry
5536 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5537 (goto-char (point-min))
5538 (while (re-search-forward regexp nil t)
5539 (catch :skip
5540 (org-agenda-skip)
5541 (setq beg (match-beginning 0))
5542 (goto-char (1- (match-end 0)))
5543 (setq b (point))
5544 (forward-sexp 1)
5545 (setq sexp (buffer-substring b (point)))
5546 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5547 (org-trim (match-string 1))
5548 ""))
5549 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5550 (when result
5551 (setq marker (org-agenda-new-marker beg)
5552 category (org-get-category beg)
5553 category-pos (get-text-property beg 'org-category-position)
5554 inherited-tags
5555 (or (eq org-agenda-show-inherited-tags 'always)
5556 (and (listp org-agenda-show-inherited-tags)
5557 (memq 'agenda org-agenda-show-inherited-tags))
5558 (and (eq org-agenda-show-inherited-tags t)
5559 (or (eq org-agenda-use-tag-inheritance t)
5560 (memq 'agenda org-agenda-use-tag-inheritance))))
5561 tags (org-get-tags-at nil (not inherited-tags))
5562 todo-state (org-get-todo-state)
5563 warntime (get-text-property (point) 'org-appt-warntime)
5564 extra nil)
5566 (dolist (r (if (stringp result)
5567 (list result)
5568 result)) ;; we expect a list here
5569 (when (and org-agenda-diary-sexp-prefix
5570 (string-match org-agenda-diary-sexp-prefix r))
5571 (setq extra (match-string 0 r)
5572 r (replace-match "" nil nil r)))
5573 (if (string-match "\\S-" r)
5574 (setq txt r)
5575 (setq txt "SEXP entry returned empty string"))
5577 (setq txt (org-agenda-format-item
5578 extra txt category tags 'time))
5579 (org-add-props txt props 'org-marker marker)
5580 (org-add-props txt nil
5581 'org-category category 'date date 'todo-state todo-state
5582 'org-category-position category-pos 'tags tags
5583 'type "sexp" 'warntime warntime)
5584 (push txt ee)))))
5585 (nreverse ee)))
5587 ;; Calendar sanity: define some functions that are independent of
5588 ;; `calendar-date-style'.
5589 ;; Normally I would like to use ISO format when calling the diary functions,
5590 ;; but to make sure we still have Emacs 22 compatibility we bind
5591 ;; also `european-calendar-style' and use european format
5592 (defun org-anniversary (year month day &optional mark)
5593 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5594 (org-no-warnings
5595 (let ((calendar-date-style 'european) (european-calendar-style t))
5596 (diary-anniversary day month year mark))))
5597 (defun org-cyclic (N year month day &optional mark)
5598 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5599 (org-no-warnings
5600 (let ((calendar-date-style 'european) (european-calendar-style t))
5601 (diary-cyclic N day month year mark))))
5602 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5603 "Like `diary-block', but with fixed (ISO) order of arguments."
5604 (org-no-warnings
5605 (let ((calendar-date-style 'european) (european-calendar-style t))
5606 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5607 (defun org-date (year month day &optional mark)
5608 "Like `diary-date', but with fixed (ISO) order of arguments."
5609 (org-no-warnings
5610 (let ((calendar-date-style 'european) (european-calendar-style t))
5611 (diary-date day month year mark))))
5613 ;; Define the` org-class' function
5614 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5615 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5616 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5617 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5618 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5619 `holidays', then any date that is known by the Emacs calendar to be a
5620 holiday will also be skipped."
5621 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5622 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5623 (d (calendar-absolute-from-gregorian date)))
5624 (and
5625 (<= date1 d)
5626 (<= d date2)
5627 (= (calendar-day-of-week date) dayname)
5628 (or (not skip-weeks)
5629 (progn
5630 (require 'cal-iso)
5631 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5632 (not (and (memq 'holidays skip-weeks)
5633 (calendar-check-holidays date)))
5634 entry)))
5636 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5637 "Like `org-class', but honor `calendar-date-style'.
5638 The order of the first 2 times 3 arguments depends on the variable
5639 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5640 So for American calendars, give this as MONTH DAY YEAR, for European as
5641 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5642 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5643 is any number of ISO weeks in the block period for which the item should
5644 be skipped.
5646 This function is here only for backward compatibility and it is deprecated,
5647 please use `org-class' instead."
5648 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5649 (date2 (org-order-calendar-date-args m2 d2 y2)))
5650 (org-class
5651 (nth 2 date1) (car date1) (nth 1 date1)
5652 (nth 2 date2) (car date2) (nth 1 date2)
5653 dayname skip-weeks)))
5654 (make-obsolete 'org-diary-class 'org-class "")
5656 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5657 (defalias 'org-get-closed 'org-agenda-get-progress)
5658 (defun org-agenda-get-progress ()
5659 "Return the logged TODO entries for agenda display."
5660 (let* ((props (list 'mouse-face 'highlight
5661 'org-not-done-regexp org-not-done-regexp
5662 'org-todo-regexp org-todo-regexp
5663 'org-complex-heading-regexp org-complex-heading-regexp
5664 'help-echo
5665 (format "mouse-2 or RET jump to org file %s"
5666 (abbreviate-file-name buffer-file-name))))
5667 (items (if (consp org-agenda-show-log-scoped)
5668 org-agenda-show-log-scoped
5669 (if (eq org-agenda-show-log-scoped 'clockcheck)
5670 '(clock)
5671 org-agenda-log-mode-items)))
5672 (parts
5673 (delq nil
5674 (list
5675 (if (memq 'closed items) (concat "\\<" org-closed-string))
5676 (if (memq 'clock items) (concat "\\<" org-clock-string))
5677 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5678 (parts-re (if parts (mapconcat 'identity parts "\\|")
5679 (error "`org-agenda-log-mode-items' is empty")))
5680 (regexp (concat
5681 "\\(" parts-re "\\)"
5682 " *\\["
5683 (regexp-quote
5684 (substring
5685 (format-time-string
5686 (car org-time-stamp-formats)
5687 (apply 'encode-time ; DATE bound by calendar
5688 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5689 1 11))))
5690 (org-agenda-search-headline-for-time nil)
5691 marker hdmarker priority category category-pos tags closedp
5692 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5693 (goto-char (point-min))
5694 (while (re-search-forward regexp nil t)
5695 (catch :skip
5696 (org-agenda-skip)
5697 (setq marker (org-agenda-new-marker (match-beginning 0))
5698 closedp (equal (match-string 1) org-closed-string)
5699 statep (equal (string-to-char (match-string 1)) ?-)
5700 clockp (not (or closedp statep))
5701 state (and statep (match-string 2))
5702 category (org-get-category (match-beginning 0))
5703 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5704 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5705 (when (string-match "\\]" timestr)
5706 ;; substring should only run to end of time stamp
5707 (setq rest (substring timestr (match-end 0))
5708 timestr (substring timestr 0 (match-end 0)))
5709 (if (and (not closedp) (not statep)
5710 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5711 rest))
5712 (progn (setq timestr (concat (substring timestr 0 -1)
5713 "-" (match-string 1 rest) "]"))
5714 (setq clocked (match-string 2 rest)))
5715 (setq clocked "-")))
5716 (save-excursion
5717 (setq extra
5718 (cond
5719 ((not org-agenda-log-mode-add-notes) nil)
5720 (statep
5721 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5722 (match-string 1)))
5723 (clockp
5724 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5725 (match-string 1)))))
5726 (if (not (re-search-backward org-outline-regexp-bol nil t))
5727 (setq txt org-agenda-no-heading-message)
5728 (goto-char (match-beginning 0))
5729 (setq hdmarker (org-agenda-new-marker)
5730 inherited-tags
5731 (or (eq org-agenda-show-inherited-tags 'always)
5732 (and (listp org-agenda-show-inherited-tags)
5733 (memq 'todo org-agenda-show-inherited-tags))
5734 (and (eq org-agenda-show-inherited-tags t)
5735 (or (eq org-agenda-use-tag-inheritance t)
5736 (memq 'todo org-agenda-use-tag-inheritance))))
5737 tags (org-get-tags-at nil (not inherited-tags)))
5738 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5739 (setq txt (match-string 1))
5740 (when extra
5741 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5742 (setq txt (concat (substring txt 0 (match-beginning 1))
5743 " - " extra " " (match-string 2 txt)))
5744 (setq txt (concat txt " - " extra))))
5745 (setq txt (org-agenda-format-item
5746 (cond
5747 (closedp "Closed: ")
5748 (statep (concat "State: (" state ")"))
5749 (t (concat "Clocked: (" clocked ")")))
5750 txt category tags timestr)))
5751 (setq priority 100000)
5752 (org-add-props txt props
5753 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5754 'priority priority 'org-category category
5755 'org-category-position category-pos
5756 'type "closed" 'date date
5757 'undone-face 'org-warning 'done-face 'org-agenda-done)
5758 (push txt ee))
5759 (goto-char (point-at-eol))))
5760 (nreverse ee)))
5762 (defun org-agenda-show-clocking-issues ()
5763 "Add overlays, showing issues with clocking.
5764 See also the user option `org-agenda-clock-consistency-checks'."
5765 (interactive)
5766 (let* ((pl org-agenda-clock-consistency-checks)
5767 (re (concat "^[ \t]*"
5768 org-clock-string
5769 "[ \t]+"
5770 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5771 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5772 (tlstart 0.)
5773 (tlend 0.)
5774 (maxtime (org-hh:mm-string-to-minutes
5775 (or (plist-get pl :max-duration) "24:00")))
5776 (mintime (org-hh:mm-string-to-minutes
5777 (or (plist-get pl :min-duration) 0)))
5778 (maxgap (org-hh:mm-string-to-minutes
5779 ;; default 30:00 means never complain
5780 (or (plist-get pl :max-gap) "30:00")))
5781 (gapok (mapcar 'org-hh:mm-string-to-minutes
5782 (plist-get pl :gap-ok-around)))
5783 (def-face (or (plist-get pl :default-face)
5784 '((:background "DarkRed") (:foreground "white"))))
5785 issue face m te ts dt ov)
5786 (goto-char (point-min))
5787 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5788 (setq issue nil face def-face)
5789 (catch 'next
5790 (setq m (org-get-at-bol 'org-marker)
5791 te nil ts nil)
5792 (unless (and m (markerp m))
5793 (setq issue "No valid clock line") (throw 'next t))
5794 (org-with-point-at m
5795 (save-excursion
5796 (goto-char (point-at-bol))
5797 (unless (looking-at re)
5798 (error "No valid Clock line")
5799 (throw 'next t))
5800 (unless (match-end 3)
5801 (setq issue "No end time"
5802 face (or (plist-get pl :no-end-time-face) face))
5803 (throw 'next t))
5804 (setq ts (match-string 1)
5805 te (match-string 3)
5806 ts (org-float-time
5807 (apply 'encode-time (org-parse-time-string ts)))
5808 te (org-float-time
5809 (apply 'encode-time (org-parse-time-string te)))
5810 dt (- te ts))))
5811 (cond
5812 ((> dt (* 60 maxtime))
5813 ;; a very long clocking chunk
5814 (setq issue (format "Clocking interval is very long: %s"
5815 (org-minutes-to-hh:mm-string
5816 (floor (/ (float dt) 60.))))
5817 face (or (plist-get pl :long-face) face)))
5818 ((< dt (* 60 mintime))
5819 ;; a very short clocking chunk
5820 (setq issue (format "Clocking interval is very short: %s"
5821 (org-minutes-to-hh:mm-string
5822 (floor (/ (float dt) 60.))))
5823 face (or (plist-get pl :short-face) face)))
5824 ((and (> tlend 0) (< ts tlend))
5825 ;; Two clock entries are overlapping
5826 (setq issue (format "Clocking overlap: %d minutes"
5827 (/ (- tlend ts) 60))
5828 face (or (plist-get pl :overlap-face) face)))
5829 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5830 ;; There is a gap, lets see if we need to report it
5831 (unless (org-agenda-check-clock-gap tlend ts gapok)
5832 (setq issue (format "Clocking gap: %d minutes"
5833 (/ (- ts tlend) 60))
5834 face (or (plist-get pl :gap-face) face))))
5835 (t nil)))
5836 (setq tlend (or te tlend) tlstart (or ts tlstart))
5837 (when issue
5838 ;; OK, there was some issue, add an overlay to show the issue
5839 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5840 (overlay-put ov 'before-string
5841 (concat
5842 (org-add-props
5843 (format "%-43s" (concat " " issue))
5845 'face face)
5846 "\n"))
5847 (overlay-put ov 'evaporate t)))))
5849 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5850 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5851 (catch 'exit
5852 (unless ok-list
5853 ;; there are no OK times for gaps...
5854 (throw 'exit nil))
5855 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5856 ;; This is more than 24 hours, so it is OK.
5857 ;; because we have at least one OK time, that must be in the
5858 ;; 24 hour interval.
5859 (throw 'exit t))
5860 ;; We have a shorter gap.
5861 ;; Now we have to get the minute of the day when these times are
5862 (let* ((t1dec (decode-time (seconds-to-time t1)))
5863 (t2dec (decode-time (seconds-to-time t2)))
5864 ;; compute the minute on the day
5865 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5866 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5867 (when (< min2 min1)
5868 ;; if min2 is smaller than min1, this means it is on the next day.
5869 ;; Wrap it to after midnight.
5870 (setq min2 (+ min2 1440)))
5871 ;; Now check if any of the OK times is in the gap
5872 (mapc (lambda (x)
5873 ;; Wrap the time to after midnight if necessary
5874 (if (< x min1) (setq x (+ x 1440)))
5875 ;; Check if in interval
5876 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5877 ok-list)
5878 ;; Nope, this gap is not OK
5879 nil)))
5881 (defun org-agenda-get-deadlines ()
5882 "Return the deadline information for agenda display."
5883 (let* ((props (list 'mouse-face 'highlight
5884 'org-not-done-regexp org-not-done-regexp
5885 'org-todo-regexp org-todo-regexp
5886 'org-complex-heading-regexp org-complex-heading-regexp
5887 'help-echo
5888 (format "mouse-2 or RET jump to org file %s"
5889 (abbreviate-file-name buffer-file-name))))
5890 (regexp org-deadline-time-regexp)
5891 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5892 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5893 d2 diff dfrac wdays pos pos1 category category-pos
5894 tags suppress-prewarning ee txt head face s todo-state
5895 show-all upcomingp donep timestr warntime)
5896 (goto-char (point-min))
5897 (while (re-search-forward regexp nil t)
5898 (setq suppress-prewarning nil)
5899 (catch :skip
5900 (org-agenda-skip)
5901 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5902 (save-match-data
5903 (string-match org-scheduled-time-regexp
5904 (buffer-substring (point-at-bol)
5905 (point-at-eol)))))
5906 (setq suppress-prewarning
5907 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5908 org-agenda-skip-deadline-prewarning-if-scheduled
5909 0)))
5910 (setq s (match-string 1)
5911 txt nil
5912 pos (1- (match-beginning 1))
5913 todo-state (save-match-data (org-get-todo-state))
5914 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5915 (member todo-state
5916 org-agenda-repeating-timestamp-show-all))
5917 d2 (org-time-string-to-absolute
5918 (match-string 1) d1 'past show-all
5919 (current-buffer) pos)
5920 diff (- d2 d1)
5921 wdays (if suppress-prewarning
5922 (let ((org-deadline-warning-days suppress-prewarning))
5923 (org-get-wdays s))
5924 (org-get-wdays s))
5925 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5926 upcomingp (and todayp (> diff 0)))
5927 ;; When to show a deadline in the calendar:
5928 ;; If the expiration is within wdays warning time.
5929 ;; Past-due deadlines are only shown on the current date
5930 (if (and (or (and (<= diff wdays)
5931 (and todayp (not org-agenda-only-exact-dates)))
5932 (= diff 0)))
5933 (save-excursion
5934 ;; (setq todo-state (org-get-todo-state))
5935 (setq donep (member todo-state org-done-keywords))
5936 (if (and donep
5937 (or org-agenda-skip-deadline-if-done
5938 (not (= diff 0))))
5939 (setq txt nil)
5940 (setq category (org-get-category)
5941 warntime (get-text-property (point) 'org-appt-warntime)
5942 category-pos (get-text-property (point) 'org-category-position))
5943 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5944 (setq txt org-agenda-no-heading-message)
5945 (goto-char (match-end 0))
5946 (setq pos1 (match-beginning 0))
5947 (setq tags (org-get-tags-at pos1 t))
5948 (setq head (buffer-substring-no-properties
5949 (point)
5950 (progn (skip-chars-forward "^\r\n")
5951 (point))))
5952 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5953 (setq timestr
5954 (concat (substring s (match-beginning 1)) " "))
5955 (setq timestr 'time))
5956 (setq txt (org-agenda-format-item
5957 (if (= diff 0)
5958 (car org-agenda-deadline-leaders)
5959 (if (functionp
5960 (nth 1 org-agenda-deadline-leaders))
5961 (funcall
5962 (nth 1 org-agenda-deadline-leaders)
5963 diff date)
5964 (format (nth 1 org-agenda-deadline-leaders)
5965 diff)))
5966 head category tags
5967 (if (not (= diff 0)) nil timestr)))))
5968 (when txt
5969 (setq face (org-agenda-deadline-face dfrac))
5970 (org-add-props txt props
5971 'org-marker (org-agenda-new-marker pos)
5972 'warntime warntime
5973 'org-hd-marker (org-agenda-new-marker pos1)
5974 'priority (+ (- diff)
5975 (org-get-priority txt))
5976 'org-category category
5977 'org-category-position category-pos
5978 'todo-state todo-state
5979 'type (if upcomingp "upcoming-deadline" "deadline")
5980 'date (if upcomingp date d2)
5981 'face (if donep 'org-agenda-done face)
5982 'undone-face face 'done-face 'org-agenda-done)
5983 (push txt ee))))))
5984 (nreverse ee)))
5986 (defun org-agenda-deadline-face (fraction)
5987 "Return the face to displaying a deadline item.
5988 FRACTION is what fraction of the head-warning time has passed."
5989 (let ((faces org-agenda-deadline-faces) f)
5990 (catch 'exit
5991 (while (setq f (pop faces))
5992 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5994 (defun org-agenda-get-scheduled (&optional deadline-results)
5995 "Return the scheduled information for agenda display."
5996 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5997 'org-todo-regexp org-todo-regexp
5998 'org-complex-heading-regexp org-complex-heading-regexp
5999 'done-face 'org-agenda-done
6000 'mouse-face 'highlight
6001 'help-echo
6002 (format "mouse-2 or RET jump to org file %s"
6003 (abbreviate-file-name buffer-file-name))))
6004 (regexp org-scheduled-time-regexp)
6005 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6006 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6008 (deadline-position-alist
6009 (mapcar (lambda (a) (and (setq mm (get-text-property
6010 0 'org-hd-marker a))
6011 (cons (marker-position mm) a)))
6012 deadline-results))
6013 d2 diff pos pos1 category category-pos tags donep
6014 ee txt head pastschedp todo-state face timestr s habitp show-all
6015 did-habit-check-p warntime inherited-tags)
6016 (goto-char (point-min))
6017 (while (re-search-forward regexp nil t)
6018 (catch :skip
6019 (org-agenda-skip)
6020 (setq s (match-string 1)
6021 txt nil
6022 pos (1- (match-beginning 1))
6023 todo-state (save-match-data (org-get-todo-state))
6024 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6025 (member todo-state
6026 org-agenda-repeating-timestamp-show-all))
6027 d2 (org-time-string-to-absolute
6028 (match-string 1) d1 'past show-all
6029 (current-buffer) pos)
6030 diff (- d2 d1)
6031 warntime (get-text-property (point) 'org-appt-warntime))
6032 (setq pastschedp (and todayp (< diff 0)))
6033 (setq did-habit-check-p nil)
6034 ;; When to show a scheduled item in the calendar:
6035 ;; If it is on or past the date.
6036 (when (or (and (< diff 0)
6037 (< (abs diff) org-scheduled-past-days)
6038 (and todayp (not org-agenda-only-exact-dates)))
6039 (= diff 0)
6040 ;; org-is-habit-p uses org-entry-get, which is expansive
6041 ;; so we go extra mile to only call it once
6042 (and todayp
6043 (boundp 'org-habit-show-all-today)
6044 org-habit-show-all-today
6045 (setq did-habit-check-p t)
6046 (setq habitp (and (functionp 'org-is-habit-p)
6047 (org-is-habit-p)))))
6048 (save-excursion
6049 (setq donep (member todo-state org-done-keywords))
6050 (if (and donep
6051 (or org-agenda-skip-scheduled-if-done
6052 (not (= diff 0))
6053 (and (functionp 'org-is-habit-p)
6054 (org-is-habit-p))))
6055 (setq txt nil)
6056 (setq habitp (if did-habit-check-p habitp
6057 (and (functionp 'org-is-habit-p)
6058 (org-is-habit-p))))
6059 (setq category (org-get-category)
6060 category-pos (get-text-property (point) 'org-category-position))
6061 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6062 (setq txt org-agenda-no-heading-message)
6063 (goto-char (match-end 0))
6064 (setq pos1 (match-beginning 0))
6065 (if habitp
6066 (if (or (not org-habit-show-habits)
6067 (and (not todayp)
6068 (boundp 'org-habit-show-habits-only-for-today)
6069 org-habit-show-habits-only-for-today))
6070 (throw :skip nil))
6071 (if (and
6072 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6073 (and org-agenda-skip-scheduled-if-deadline-is-shown
6074 pastschedp))
6075 (setq mm (assoc pos1 deadline-position-alist)))
6076 (throw :skip nil)))
6077 (setq inherited-tags
6078 (or (eq org-agenda-show-inherited-tags 'always)
6079 (and (listp org-agenda-show-inherited-tags)
6080 (memq 'agenda org-agenda-show-inherited-tags))
6081 (and (eq org-agenda-show-inherited-tags t)
6082 (or (eq org-agenda-use-tag-inheritance t)
6083 (memq 'agenda org-agenda-use-tag-inheritance))))
6084 tags (org-get-tags-at nil (not inherited-tags)))
6085 (setq head (buffer-substring-no-properties
6086 (point)
6087 (progn (skip-chars-forward "^\r\n") (point))))
6088 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6089 (setq timestr
6090 (concat (substring s (match-beginning 1)) " "))
6091 (setq timestr 'time))
6092 (setq txt (org-agenda-format-item
6093 (if (= diff 0)
6094 (car org-agenda-scheduled-leaders)
6095 (format (nth 1 org-agenda-scheduled-leaders)
6096 (- 1 diff)))
6097 head category tags
6098 (if (not (= diff 0)) nil timestr)
6099 nil habitp))))
6100 (when txt
6101 (setq face
6102 (cond
6103 ((and (not habitp) pastschedp)
6104 'org-scheduled-previously)
6105 (todayp 'org-scheduled-today)
6106 (t 'org-scheduled))
6107 habitp (and habitp (org-habit-parse-todo)))
6108 (org-add-props txt props
6109 'undone-face face
6110 'face (if donep 'org-agenda-done face)
6111 'org-marker (org-agenda-new-marker pos)
6112 'org-hd-marker (org-agenda-new-marker pos1)
6113 'type (if pastschedp "past-scheduled" "scheduled")
6114 'date (if pastschedp d2 date)
6115 'warntime warntime
6116 'priority (if habitp
6117 (org-habit-get-priority habitp)
6118 (+ 94 (- 5 diff) (org-get-priority txt)))
6119 'org-category category
6120 'category-position category-pos
6121 'org-habit-p habitp
6122 'todo-state todo-state)
6123 (push txt ee))))))
6124 (nreverse ee)))
6126 (defun org-agenda-get-blocks ()
6127 "Return the date-range information for agenda display."
6128 (let* ((props (list 'face nil
6129 'org-not-done-regexp org-not-done-regexp
6130 'org-todo-regexp org-todo-regexp
6131 'org-complex-heading-regexp org-complex-heading-regexp
6132 'mouse-face 'highlight
6133 'help-echo
6134 (format "mouse-2 or RET jump to org file %s"
6135 (abbreviate-file-name buffer-file-name))))
6136 (regexp org-tr-regexp)
6137 (d0 (calendar-absolute-from-gregorian date))
6138 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6139 todo-state tags pos head donep inherited-tags)
6140 (goto-char (point-min))
6141 (while (re-search-forward regexp nil t)
6142 (catch :skip
6143 (org-agenda-skip)
6144 (setq pos (point))
6145 (let ((start-time (match-string 1))
6146 (end-time (match-string 2)))
6147 (setq s1 (match-string 1)
6148 s2 (match-string 2)
6149 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6150 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6151 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6152 ;; Only allow days between the limits, because the normal
6153 ;; date stamps will catch the limits.
6154 (save-excursion
6155 (setq todo-state (org-get-todo-state))
6156 (setq donep (member todo-state org-done-keywords))
6157 (if (and donep org-agenda-skip-timestamp-if-done)
6158 (throw :skip t))
6159 (setq marker (org-agenda-new-marker (point)))
6160 (setq category (org-get-category)
6161 category-pos (get-text-property (point) 'org-category-position))
6162 (if (not (re-search-backward org-outline-regexp-bol nil t))
6163 (setq txt org-agenda-no-heading-message)
6164 (goto-char (match-beginning 0))
6165 (setq hdmarker (org-agenda-new-marker (point))
6166 inherited-tags
6167 (or (eq org-agenda-show-inherited-tags 'always)
6168 (and (listp org-agenda-show-inherited-tags)
6169 (memq 'agenda org-agenda-show-inherited-tags))
6170 (and (eq org-agenda-show-inherited-tags t)
6171 (or (eq org-agenda-use-tag-inheritance t)
6172 (memq 'agenda org-agenda-use-tag-inheritance))))
6173 tags (org-get-tags-at nil (not inherited-tags)))
6174 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6175 (setq head (match-string 1))
6176 (let ((remove-re
6177 (if org-agenda-remove-timeranges-from-blocks
6178 (concat
6179 "<" (regexp-quote s1) ".*?>"
6180 "--"
6181 "<" (regexp-quote s2) ".*?>")
6182 nil)))
6183 (setq txt (org-agenda-format-item
6184 (format
6185 (nth (if (= d1 d2) 0 1)
6186 org-agenda-timerange-leaders)
6187 (1+ (- d0 d1)) (1+ (- d2 d1)))
6188 head category tags
6189 (cond ((and (= d1 d0) (= d2 d0))
6190 (concat "<" start-time ">--<" end-time ">"))
6191 ((= d1 d0)
6192 (concat "<" start-time ">"))
6193 ((= d2 d0)
6194 (concat "<" end-time ">")))
6195 remove-re))))
6196 (org-add-props txt props
6197 'org-marker marker 'org-hd-marker hdmarker
6198 'type "block" 'date date
6199 'todo-state todo-state
6200 'priority (org-get-priority txt) 'org-category category
6201 'org-category-position category-pos)
6202 (push txt ee))))
6203 (goto-char pos)))
6204 ;; Sort the entries by expiration date.
6205 (nreverse ee)))
6207 ;;; Agenda presentation and sorting
6209 (defvar org-prefix-has-time nil
6210 "A flag, set by `org-compile-prefix-format'.
6211 The flag is set if the currently compiled format contains a `%t'.")
6212 (defvar org-prefix-has-tag nil
6213 "A flag, set by `org-compile-prefix-format'.
6214 The flag is set if the currently compiled format contains a `%T'.")
6215 (defvar org-prefix-has-effort nil
6216 "A flag, set by `org-compile-prefix-format'.
6217 The flag is set if the currently compiled format contains a `%e'.")
6218 (defvar org-prefix-category-length nil
6219 "Used by `org-compile-prefix-format' to remember the category field width.")
6220 (defvar org-prefix-category-max-length nil
6221 "Used by `org-compile-prefix-format' to remember the category field width.")
6223 (defun org-agenda-get-category-icon (category)
6224 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6225 (dolist (entry org-agenda-category-icon-alist)
6226 (when (org-string-match-p (car entry) category)
6227 (if (listp (cadr entry))
6228 (return (cadr entry))
6229 (return (apply 'create-image (cdr entry)))))))
6231 (defun org-agenda-format-item (extra txt &optional category tags dotime
6232 remove-re habitp)
6233 "Format TXT to be inserted into the agenda buffer.
6234 In particular, it adds the prefix and corresponding text properties. EXTRA
6235 must be a string and replaces the `%s' specifier in the prefix format.
6236 CATEGORY (string, symbol or nil) may be used to overrule the default
6237 category taken from local variable or file name. It will replace the `%c'
6238 specifier in the format. DOTIME, when non-nil, indicates that a
6239 time-of-day should be extracted from TXT for sorting of this entry, and for
6240 the `%t' specifier in the format. When DOTIME is a string, this string is
6241 searched for a time before TXT is. TAGS can be the tags of the headline.
6242 Any match of REMOVE-RE will be removed from TXT."
6243 ;; We keep the org-prefix-* variable values along with a compiled
6244 ;; formatter, so that multiple agendas existing at the same time, do
6245 ;; not step on each other toes.
6247 ;; It was inconvenient to make these variables buffer local in
6248 ;; Agenda buffers, because this function expects to be called with
6249 ;; the buffer where item comes from being current, and not agenda
6250 ;; buffer
6251 (let* ((bindings (car org-prefix-format-compiled))
6252 (formatter (cadr org-prefix-format-compiled)))
6253 (loop for (var value) in bindings
6254 do (set var value))
6255 (save-match-data
6256 ;; Diary entries sometimes have extra whitespace at the beginning
6257 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
6259 ;; Fix the tags part in txt
6260 (setq txt (org-agenda-fix-displayed-tags
6261 txt tags
6262 org-agenda-show-inherited-tags
6263 org-agenda-hide-tags-regexp))
6264 (let* ((category (or category
6265 (if (stringp org-category)
6266 org-category
6267 (and org-category (symbol-name org-category)))
6268 (if buffer-file-name
6269 (file-name-sans-extension
6270 (file-name-nondirectory buffer-file-name))
6271 "")))
6272 (category-icon (org-agenda-get-category-icon category))
6273 (category-icon (if category-icon
6274 (propertize " " 'display category-icon)
6275 ""))
6276 ;; time, tag, effort are needed for the eval of the prefix format
6277 (tag (if tags (nth (1- (length tags)) tags) ""))
6278 time effort neffort
6279 (ts (if dotime (concat
6280 (if (stringp dotime) dotime "")
6281 (and org-agenda-search-headline-for-time txt))))
6282 (time-of-day (and dotime (org-get-time-of-day ts)))
6283 stamp plain s0 s1 s2 rtn srp l
6284 duration thecategory)
6285 (and (derived-mode-p 'org-mode) buffer-file-name
6286 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6287 (when (and dotime time-of-day)
6288 ;; Extract starting and ending time and move them to prefix
6289 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6290 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6291 (setq s0 (match-string 0 ts)
6292 srp (and stamp (match-end 3))
6293 s1 (match-string (if plain 1 2) ts)
6294 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6296 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6297 ;; them, we might want to remove them there to avoid duplication.
6298 ;; The user can turn this off with a variable.
6299 (if (and org-prefix-has-time
6300 org-agenda-remove-times-when-in-prefix (or stamp plain)
6301 (string-match (concat (regexp-quote s0) " *") txt)
6302 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6303 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6304 (= (match-beginning 0) 0)
6306 (setq txt (replace-match "" nil nil txt))))
6307 ;; Normalize the time(s) to 24 hour
6308 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6309 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6311 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6312 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6313 (setq s2
6314 (org-minutes-to-hh:mm-string
6315 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6317 ;; Compute the duration
6318 (when s2
6319 (setq duration (- (org-hh:mm-string-to-minutes s2)
6320 (org-hh:mm-string-to-minutes s1)))))
6322 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6323 txt)
6324 ;; Tags are in the string
6325 (if (or (eq org-agenda-remove-tags t)
6326 (and org-agenda-remove-tags
6327 org-prefix-has-tag))
6328 (setq txt (replace-match "" t t txt))
6329 (setq txt (replace-match
6330 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6331 (match-string 2 txt))
6332 t t txt))))
6333 (when (derived-mode-p 'org-mode)
6334 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6335 (when effort
6336 (setq neffort (org-duration-string-to-minutes effort)
6337 effort (setq effort (concat "[" effort "]")))))
6338 ;; prevent erroring out with %e format when there is no effort
6339 (or effort (setq effort ""))
6341 (when remove-re
6342 (while (string-match remove-re txt)
6343 (setq txt (replace-match "" t t txt))))
6345 ;; Set org-heading property on `txt' to mark the start of the
6346 ;; heading.
6347 (add-text-properties 0 (length txt) '(org-heading t) txt)
6349 ;; Prepare the variables needed in the eval of the compiled format
6350 (setq time (cond (s2 (concat
6351 (org-agenda-time-of-day-to-ampm-maybe s1)
6352 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6353 (if org-agenda-timegrid-use-ampm " ")))
6354 (s1 (concat
6355 (org-agenda-time-of-day-to-ampm-maybe s1)
6356 (if org-agenda-timegrid-use-ampm
6357 "........ "
6358 "......")))
6359 (t ""))
6360 extra (or (and (not habitp) extra) "")
6361 category (if (symbolp category) (symbol-name category) category)
6362 thecategory (copy-sequence category))
6363 (if (string-match org-bracket-link-regexp category)
6364 (progn
6365 (setq l (if (match-end 3)
6366 (- (match-end 3) (match-beginning 3))
6367 (- (match-end 1) (match-beginning 1))))
6368 (when (< l (or org-prefix-category-length 0))
6369 (setq category (copy-sequence category))
6370 (org-add-props category nil
6371 'extra-space (make-string
6372 (- org-prefix-category-length l 1) ?\ ))))
6373 (if (and org-prefix-category-max-length
6374 (>= (length category) org-prefix-category-max-length))
6375 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6376 ;; Evaluate the compiled format
6377 (setq rtn (concat (eval formatter) txt))
6379 ;; And finally add the text properties
6380 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6381 (org-add-props rtn nil
6382 'org-category (if thecategory (downcase thecategory) category)
6383 'tags (mapcar 'org-downcase-keep-props tags)
6384 'org-highest-priority org-highest-priority
6385 'org-lowest-priority org-lowest-priority
6386 'time-of-day time-of-day
6387 'duration duration
6388 'effort effort
6389 'effort-minutes neffort
6390 'txt txt
6391 'time time
6392 'extra extra
6393 'format org-prefix-format-compiled
6394 'dotime dotime)))))
6396 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6397 "Remove tags string from TXT, and add a modified list of tags.
6398 The modified list may contain inherited tags, and tags matched by
6399 `org-agenda-hide-tags-regexp' will be removed."
6400 (when (or add-inherited hide-re)
6401 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6402 (setq txt (substring txt 0 (match-beginning 0))))
6403 (setq tags
6404 (delq nil
6405 (mapcar (lambda (tg)
6406 (if (or (and hide-re (string-match hide-re tg))
6407 (and (not add-inherited)
6408 (get-text-property 0 'inherited tg)))
6410 tg))
6411 tags)))
6412 (when tags
6413 (let ((have-i (get-text-property 0 'inherited (car tags)))
6415 (setq txt (concat txt " :"
6416 (mapconcat
6417 (lambda (x)
6418 (setq i (get-text-property 0 'inherited x))
6419 (if (and have-i (not i))
6420 (progn
6421 (setq have-i nil)
6422 (concat ":" x))
6424 tags ":")
6425 (if have-i "::" ":"))))))
6426 txt)
6428 (defun org-downcase-keep-props (s)
6429 (let ((props (text-properties-at 0 s)))
6430 (setq s (downcase s))
6431 (add-text-properties 0 (length s) props s)
6434 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6435 (defvar org-agenda-sorting-strategy-selected nil)
6437 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6438 (catch 'exit
6439 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6440 ((and todayp (member 'today (car org-agenda-time-grid))))
6441 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6442 ((member 'weekly (car org-agenda-time-grid)))
6443 (t (throw 'exit list)))
6444 (let* ((have (delq nil (mapcar
6445 (lambda (x) (get-text-property 1 'time-of-day x))
6446 list)))
6447 (string (nth 1 org-agenda-time-grid))
6448 (gridtimes (nth 2 org-agenda-time-grid))
6449 (req (car org-agenda-time-grid))
6450 (remove (member 'remove-match req))
6451 new time)
6452 (if (and (member 'require-timed req) (not have))
6453 ;; don't show empty grid
6454 (throw 'exit list))
6455 (while (setq time (pop gridtimes))
6456 (unless (and remove (member time have))
6457 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6458 (push (org-agenda-format-item
6459 nil string "" nil
6460 (concat (substring time 0 -2) ":" (substring time -2)))
6461 new)
6462 (put-text-property
6463 2 (length (car new)) 'face 'org-time-grid (car new))))
6464 (when (and todayp org-agenda-show-current-time-in-grid)
6465 (push (org-agenda-format-item
6467 org-agenda-current-time-string
6468 "" nil
6469 (format-time-string "%H:%M "))
6470 new)
6471 (put-text-property
6472 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6474 (if (member 'time-up org-agenda-sorting-strategy-selected)
6475 (append new list)
6476 (append list new)))))
6478 (defun org-compile-prefix-format (key)
6479 "Compile the prefix format into a Lisp form that can be evaluated.
6480 The resulting form and associated variable bindings is returned
6481 and stored in the variable `org-prefix-format-compiled'."
6482 (setq org-prefix-has-time nil org-prefix-has-tag nil
6483 org-prefix-category-length nil
6484 org-prefix-has-effort nil)
6485 (let ((s (cond
6486 ((stringp org-agenda-prefix-format)
6487 org-agenda-prefix-format)
6488 ((assq key org-agenda-prefix-format)
6489 (cdr (assq key org-agenda-prefix-format)))
6490 (t " %-12:c%?-12t% s")))
6491 (start 0)
6492 varform vars var e c f opt)
6493 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6494 s start)
6495 (setq var (or (cdr (assoc (match-string 4 s)
6496 '(("c" . category) ("t" . time) ("s" . extra)
6497 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6498 'eval)
6499 c (or (match-string 3 s) "")
6500 opt (match-beginning 1)
6501 start (1+ (match-beginning 0)))
6502 (if (equal var 'time) (setq org-prefix-has-time t))
6503 (if (equal var 'tag) (setq org-prefix-has-tag t))
6504 (if (equal var 'effort) (setq org-prefix-has-effort t))
6505 (setq f (concat "%" (match-string 2 s) "s"))
6506 (when (equal var 'category)
6507 (setq org-prefix-category-length
6508 (floor (abs (string-to-number (match-string 2 s)))))
6509 (setq org-prefix-category-max-length
6510 (let ((x (match-string 2 s)))
6511 (save-match-data
6512 (if (string-match "\\.[0-9]+" x)
6513 (string-to-number (substring (match-string 0 x) 1)))))))
6514 (if (eq var 'eval)
6515 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6516 (if opt
6517 (setq varform
6518 `(if (equal "" ,var)
6520 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6521 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6522 (setq s (replace-match "%s" t nil s))
6523 (push varform vars))
6524 (setq vars (nreverse vars))
6525 (with-current-buffer (or org-agenda-buffer (current-buffer))
6526 (setq org-prefix-format-compiled
6527 (list
6528 `((org-prefix-has-time ,org-prefix-has-time)
6529 (org-prefix-has-tag ,org-prefix-has-tag)
6530 (org-prefix-category-length ,org-prefix-category-length)
6531 (org-prefix-has-effort ,org-prefix-has-effort))
6532 `(format ,s ,@vars))))))
6534 (defun org-set-sorting-strategy (key)
6535 (if (symbolp (car org-agenda-sorting-strategy))
6536 ;; the old format
6537 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6538 (setq org-agenda-sorting-strategy-selected
6539 (or (cdr (assq key org-agenda-sorting-strategy))
6540 (cdr (assq 'agenda org-agenda-sorting-strategy))
6541 '(time-up category-keep priority-down)))))
6543 (defun org-get-time-of-day (s &optional string mod24)
6544 "Check string S for a time of day.
6545 If found, return it as a military time number between 0 and 2400.
6546 If not found, return nil.
6547 The optional STRING argument forces conversion into a 5 character wide string
6548 HH:MM."
6549 (save-match-data
6550 (when
6551 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6552 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6553 (let* ((h (string-to-number (match-string 1 s)))
6554 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6555 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6556 (am-p (equal ampm "am"))
6557 (h1 (cond ((not ampm) h)
6558 ((= h 12) (if am-p 0 12))
6559 (t (+ h (if am-p 0 12)))))
6560 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6561 (mod h1 24) h1))
6562 (t0 (+ (* 100 h2) m))
6563 (t1 (concat (if (>= h1 24) "+" " ")
6564 (if (and org-agenda-time-leading-zero
6565 (< t0 1000)) "0" "")
6566 (if (< t0 100) "0" "")
6567 (if (< t0 10) "0" "")
6568 (int-to-string t0))))
6569 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6571 (defvar org-agenda-before-sorting-filter-function nil
6572 "Function to be applied to agenda items prior to sorting.
6573 Prior to sorting also means just before they are inserted into the agenda.
6575 To aid sorting, you may revisit the original entries and add more text
6576 properties which will later be used by the sorting functions.
6578 The function should take a string argument, an agenda line.
6579 It has access to the text properties in that line, which contain among
6580 other things, the property `org-hd-marker' that points to the entry
6581 where the line comes from. Note that not all lines going into the agenda
6582 have this property, only most.
6584 The function should return the modified string. It is probably best
6585 to ONLY change text properties.
6587 You can also use this function as a filter, by returning nil for lines
6588 you don't want to have in the agenda at all. For this application, you
6589 could bind the variable in the options section of a custom command.")
6591 (defun org-agenda-finalize-entries (list &optional nosort)
6592 "Sort and concatenate the agenda items."
6593 (setq list (mapcar 'org-agenda-highlight-todo list))
6594 (if nosort
6595 list
6596 (when org-agenda-before-sorting-filter-function
6597 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6598 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6600 (defun org-agenda-highlight-todo (x)
6601 (let ((org-done-keywords org-done-keywords-for-agenda)
6602 (case-fold-search nil)
6604 (if (eq x 'line)
6605 (save-excursion
6606 (beginning-of-line 1)
6607 (setq re (org-get-at-bol 'org-todo-regexp))
6608 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6609 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6610 (add-text-properties (match-beginning 0) (match-end 1)
6611 (list 'face (org-get-todo-face 1)))
6612 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6613 (delete-region (match-beginning 1) (1- (match-end 0)))
6614 (goto-char (match-beginning 1))
6615 (insert (format org-agenda-todo-keyword-format s)))))
6616 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6617 (setq re (get-text-property 0 'org-todo-regexp x))
6618 (when (and re
6619 ;; Test `pl' because if there's no heading content,
6620 ;; there's no point matching to highlight. Note
6621 ;; that if we didn't test `pl' first, and there
6622 ;; happened to be no keyword from `org-todo-regexp'
6623 ;; on this heading line, then the `equal' comparison
6624 ;; afterwards would spuriously succeed in the case
6625 ;; where `pl' is nil -- causing an args-out-of-range
6626 ;; error when we try to add text properties to text
6627 ;; that isn't there.
6629 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6630 x pl) pl))
6631 (add-text-properties
6632 (or (match-end 1) (match-end 0)) (match-end 0)
6633 (list 'face (org-get-todo-face (match-string 2 x)))
6635 (when (match-end 1)
6636 (setq x (concat (substring x 0 (match-end 1))
6637 (format org-agenda-todo-keyword-format
6638 (match-string 2 x))
6639 (org-add-props " " (text-properties-at 0 x))
6640 (substring x (match-end 3)))))))
6641 x)))
6643 (defsubst org-cmp-priority (a b)
6644 "Compare the priorities of string A and B."
6645 (let ((pa (or (get-text-property 1 'priority a) 0))
6646 (pb (or (get-text-property 1 'priority b) 0)))
6647 (cond ((> pa pb) +1)
6648 ((< pa pb) -1))))
6650 (defsubst org-cmp-effort (a b)
6651 "Compare the effort values of string A and B."
6652 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6653 (ea (or (get-text-property 1 'effort-minutes a) def))
6654 (eb (or (get-text-property 1 'effort-minutes b) def)))
6655 (cond ((> ea eb) +1)
6656 ((< ea eb) -1))))
6658 (defsubst org-cmp-category (a b)
6659 "Compare the string values of categories of strings A and B."
6660 (let ((ca (or (get-text-property 1 'org-category a) ""))
6661 (cb (or (get-text-property 1 'org-category b) "")))
6662 (cond ((string-lessp ca cb) -1)
6663 ((string-lessp cb ca) +1))))
6665 (defsubst org-cmp-todo-state (a b)
6666 "Compare the todo states of strings A and B."
6667 (let* ((ma (or (get-text-property 1 'org-marker a)
6668 (get-text-property 1 'org-hd-marker a)))
6669 (mb (or (get-text-property 1 'org-marker b)
6670 (get-text-property 1 'org-hd-marker b)))
6671 (fa (and ma (marker-buffer ma)))
6672 (fb (and mb (marker-buffer mb)))
6673 (todo-kwds
6674 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6675 (and fb (with-current-buffer fb org-todo-keywords-1))))
6676 (ta (or (get-text-property 1 'todo-state a) ""))
6677 (tb (or (get-text-property 1 'todo-state b) ""))
6678 (la (- (length (member ta todo-kwds))))
6679 (lb (- (length (member tb todo-kwds))))
6680 (donepa (member ta org-done-keywords-for-agenda))
6681 (donepb (member tb org-done-keywords-for-agenda)))
6682 (cond ((and donepa (not donepb)) -1)
6683 ((and (not donepa) donepb) +1)
6684 ((< la lb) -1)
6685 ((< lb la) +1))))
6687 (defsubst org-cmp-alpha (a b)
6688 "Compare the headlines, alphabetically."
6689 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6690 (plb (text-property-any 0 (length b) 'org-heading t b))
6691 (ta (and pla (substring a pla)))
6692 (tb (and plb (substring b plb))))
6693 (when pla
6694 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6695 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6696 (setq ta (substring ta (match-end 0))))
6697 (setq ta (downcase ta)))
6698 (when plb
6699 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6700 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6701 (setq tb (substring tb (match-end 0))))
6702 (setq tb (downcase tb)))
6703 (cond ((not ta) +1)
6704 ((not tb) -1)
6705 ((string-lessp ta tb) -1)
6706 ((string-lessp tb ta) +1))))
6708 (defsubst org-cmp-tag (a b)
6709 "Compare the string values of the first tags of A and B."
6710 (let ((ta (car (last (get-text-property 1 'tags a))))
6711 (tb (car (last (get-text-property 1 'tags b)))))
6712 (cond ((not ta) +1)
6713 ((not tb) -1)
6714 ((string-lessp ta tb) -1)
6715 ((string-lessp tb ta) +1))))
6717 (defsubst org-cmp-time (a b)
6718 "Compare the time-of-day values of strings A and B."
6719 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6720 (ta (or (get-text-property 1 'time-of-day a) def))
6721 (tb (or (get-text-property 1 'time-of-day b) def)))
6722 (cond ((< ta tb) -1)
6723 ((< tb ta) +1))))
6725 (defsubst org-cmp-habit-p (a b)
6726 "Compare the todo states of strings A and B."
6727 (let ((ha (get-text-property 1 'org-habit-p a))
6728 (hb (get-text-property 1 'org-habit-p b)))
6729 (cond ((and ha (not hb)) -1)
6730 ((and (not ha) hb) +1))))
6732 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6734 (defun org-entries-lessp (a b)
6735 "Predicate for sorting agenda entries."
6736 ;; The following variables will be used when the form is evaluated.
6737 ;; So even though the compiler complains, keep them.
6738 (let* ((ss org-agenda-sorting-strategy-selected)
6739 (time-up (and (org-em 'time-up 'time-down ss)
6740 (org-cmp-time a b)))
6741 (time-down (if time-up (- time-up) nil))
6742 (priority-up (and (org-em 'priority-up 'priority-down ss)
6743 (org-cmp-priority a b)))
6744 (priority-down (if priority-up (- priority-up) nil))
6745 (effort-up (and (org-em 'effort-up 'effort-down ss)
6746 (org-cmp-effort a b)))
6747 (effort-down (if effort-up (- effort-up) nil))
6748 (category-up (and (or (org-em 'category-up 'category-down ss)
6749 (memq 'category-keep ss))
6750 (org-cmp-category a b)))
6751 (category-down (if category-up (- category-up) nil))
6752 (category-keep (if category-up +1 nil))
6753 (tag-up (and (org-em 'tag-up 'tag-down ss)
6754 (org-cmp-tag a b)))
6755 (tag-down (if tag-up (- tag-up) nil))
6756 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6757 (org-cmp-todo-state a b)))
6758 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6759 (habit-up (and (org-em 'habit-up 'habit-down ss)
6760 (org-cmp-habit-p a b)))
6761 (habit-down (if habit-up (- habit-up) nil))
6762 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6763 (org-cmp-alpha a b)))
6764 (alpha-down (if alpha-up (- alpha-up) nil))
6765 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6766 user-defined-up user-defined-down)
6767 (if (and need-user-cmp org-agenda-cmp-user-defined
6768 (functionp org-agenda-cmp-user-defined))
6769 (setq user-defined-up
6770 (funcall org-agenda-cmp-user-defined a b)
6771 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6772 (cdr (assoc
6773 (eval (cons 'or org-agenda-sorting-strategy-selected))
6774 '((-1 . t) (1 . nil) (nil . nil))))))
6776 ;;; Agenda restriction lock
6778 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6779 "Overlay to mark the headline to which agenda commands are restricted.")
6780 (overlay-put org-agenda-restriction-lock-overlay
6781 'face 'org-agenda-restriction-lock)
6782 (overlay-put org-agenda-restriction-lock-overlay
6783 'help-echo "Agendas are currently limited to this subtree.")
6784 (org-detach-overlay org-agenda-restriction-lock-overlay)
6786 (defun org-agenda-set-restriction-lock (&optional type)
6787 "Set restriction lock for agenda, to current subtree or file.
6788 Restriction will be the file if TYPE is `file', or if type is the
6789 universal prefix '(4), or if the cursor is before the first headline
6790 in the file. Otherwise, restriction will be to the current subtree."
6791 (interactive "P")
6792 (and (equal type '(4)) (setq type 'file))
6793 (setq type (cond
6794 (type type)
6795 ((org-at-heading-p) 'subtree)
6796 ((condition-case nil (org-back-to-heading t) (error nil))
6797 'subtree)
6798 (t 'file)))
6799 (if (eq type 'subtree)
6800 (progn
6801 (setq org-agenda-restrict t)
6802 (setq org-agenda-overriding-restriction 'subtree)
6803 (put 'org-agenda-files 'org-restrict
6804 (list (buffer-file-name (buffer-base-buffer))))
6805 (org-back-to-heading t)
6806 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6807 (move-marker org-agenda-restrict-begin (point))
6808 (move-marker org-agenda-restrict-end
6809 (save-excursion (org-end-of-subtree t)))
6810 (message "Locking agenda restriction to subtree"))
6811 (put 'org-agenda-files 'org-restrict
6812 (list (buffer-file-name (buffer-base-buffer))))
6813 (setq org-agenda-restrict nil)
6814 (setq org-agenda-overriding-restriction 'file)
6815 (move-marker org-agenda-restrict-begin nil)
6816 (move-marker org-agenda-restrict-end nil)
6817 (message "Locking agenda restriction to file"))
6818 (setq current-prefix-arg nil)
6819 (org-agenda-maybe-redo))
6821 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6822 "Remove the agenda restriction lock."
6823 (interactive "P")
6824 (org-detach-overlay org-agenda-restriction-lock-overlay)
6825 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6826 (setq org-agenda-overriding-restriction nil)
6827 (setq org-agenda-restrict nil)
6828 (put 'org-agenda-files 'org-restrict nil)
6829 (move-marker org-agenda-restrict-begin nil)
6830 (move-marker org-agenda-restrict-end nil)
6831 (setq current-prefix-arg nil)
6832 (message "Agenda restriction lock removed")
6833 (or noupdate (org-agenda-maybe-redo)))
6835 (defun org-agenda-maybe-redo ()
6836 "If there is any window showing the agenda view, update it."
6837 (let ((w (get-buffer-window org-agenda-buffer-name t))
6838 (w0 (selected-window)))
6839 (when w
6840 (select-window w)
6841 (org-agenda-redo)
6842 (select-window w0)
6843 (if org-agenda-overriding-restriction
6844 (message "Agenda view shifted to new %s restriction"
6845 org-agenda-overriding-restriction)
6846 (message "Agenda restriction lock removed")))))
6848 ;;; Agenda commands
6850 (defun org-agenda-check-type (error &rest types)
6851 "Check if agenda buffer is of allowed type.
6852 If ERROR is non-nil, throw an error, otherwise just return nil.
6853 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6854 (if (not org-agenda-type)
6855 (error "No Org agenda currently displayed")
6856 (if (memq org-agenda-type types)
6858 (if error
6859 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6860 nil))))
6862 (defun org-agenda-Quit (&optional arg)
6863 "Exit agenda by removing the window or the buffer."
6864 (interactive)
6865 (if org-agenda-columns-active
6866 (org-columns-quit)
6867 (let ((buf (current-buffer)))
6868 (if (eq org-agenda-window-setup 'other-frame)
6869 (progn
6870 (org-agenda-reset-markers)
6871 (kill-buffer buf)
6872 (org-columns-remove-overlays)
6873 (setq org-agenda-archives-mode nil)
6874 (delete-frame))
6875 (and (not (eq org-agenda-window-setup 'current-window))
6876 (not (one-window-p))
6877 (delete-window))
6878 (org-agenda-reset-markers)
6879 (kill-buffer buf)
6880 (org-columns-remove-overlays)
6881 (setq org-agenda-archives-mode nil)))
6882 ;; Maybe restore the pre-agenda window configuration.
6883 (and org-agenda-restore-windows-after-quit
6884 (not (eq org-agenda-window-setup 'other-frame))
6885 org-agenda-pre-window-conf
6886 (set-window-configuration org-agenda-pre-window-conf)
6887 (setq org-agenda-pre-window-conf nil))))
6889 (defun org-agenda-quit ()
6890 "Exit agenda by killing agenda buffer or burying it when
6891 `org-agenda-sticky' is non-NIL"
6892 (interactive)
6893 (if (and (eq org-indirect-buffer-display 'other-window)
6894 org-last-indirect-buffer)
6895 (delete-window (get-buffer-window org-last-indirect-buffer)))
6896 (if org-agenda-columns-active
6897 (org-columns-quit)
6898 (if org-agenda-sticky
6899 (let ((buf (current-buffer)))
6900 (if (eq org-agenda-window-setup 'other-frame)
6901 (progn
6902 (delete-frame))
6903 (and (not (eq org-agenda-window-setup 'current-window))
6904 (not (one-window-p))
6905 (delete-window)))
6906 (with-current-buffer buf
6907 (bury-buffer)
6908 ;; Maybe restore the pre-agenda window configuration.
6909 (and org-agenda-restore-windows-after-quit
6910 (not (eq org-agenda-window-setup 'other-frame))
6911 org-agenda-pre-window-conf
6912 (set-window-configuration org-agenda-pre-window-conf)
6913 (setq org-agenda-pre-window-conf nil))))
6914 (org-agenda-Quit))))
6916 (defun org-agenda-exit ()
6917 "Exit agenda by removing the window or the buffer.
6918 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6919 Org-mode buffers visited directly by the user will not be touched."
6920 (interactive)
6921 (org-release-buffers org-agenda-new-buffers)
6922 (setq org-agenda-new-buffers nil)
6923 (org-agenda-Quit))
6925 (defun org-agenda-kill-all-agenda-buffers ()
6926 "Kill all buffers in `org-agenda-mode'.
6927 This is used when toggling sticky agendas. You can also explicitly invoke it
6928 with `C-c a C-k'."
6929 (interactive)
6930 (let (blist)
6931 (dolist (buf (buffer-list))
6932 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6933 (push buf blist)))
6934 (mapc 'kill-buffer blist)))
6936 (defun org-agenda-execute (arg)
6937 "Execute another agenda command, keeping same window.
6938 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6939 in the agenda."
6940 (interactive "P")
6941 (let ((org-agenda-window-setup 'current-window))
6942 (org-agenda arg)))
6944 (defun org-agenda-redo (&optional all)
6945 "Rebuild possibly ALL agenda view(s) in the current buffer."
6946 (interactive "P")
6947 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6948 (cpa (unless (eq all t) current-prefix-arg))
6949 (org-agenda-doing-sticky-redo org-agenda-sticky)
6950 (org-agenda-sticky nil)
6951 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6952 org-agenda-buffer-name))
6953 (org-agenda-keep-modes t)
6954 (tag-filter org-agenda-tag-filter)
6955 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6956 (top-cat-filter org-agenda-top-category-filter)
6957 (cat-filter org-agenda-category-filter)
6958 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6959 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6960 (cols org-agenda-columns-active)
6961 (line (org-current-line))
6962 (window-line (- line (org-current-line (window-start))))
6963 (lprops (get 'org-agenda-redo-command 'org-lprops))
6964 (redo-cmd (get-text-property p 'org-redo-cmd))
6965 (last-args (get-text-property p 'org-last-args))
6966 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6967 (org-agenda-overriding-cmd-arguments
6968 (unless (eq all t)
6969 (cond ((listp last-args)
6970 (cons (or cpa (car last-args)) (cdr last-args)))
6971 ((stringp last-args)
6972 last-args))))
6973 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6974 (put 'org-agenda-tag-filter :preset-filter nil)
6975 (put 'org-agenda-category-filter :preset-filter nil)
6976 (and cols (org-columns-quit))
6977 (message "Rebuilding agenda buffer...")
6978 (if series-redo-cmd
6979 (eval series-redo-cmd)
6980 (org-let lprops '(eval redo-cmd)))
6981 (setq org-agenda-undo-list nil
6982 org-agenda-pending-undo-list nil)
6983 (message "Rebuilding agenda buffer...done")
6984 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6985 (put 'org-agenda-category-filter :preset-filter cat-preset)
6986 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6987 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6988 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6989 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6990 (org-goto-line line)
6991 (recenter window-line)))
6993 (defvar org-global-tags-completion-table nil)
6994 (defvar org-agenda-filter-form nil)
6995 (defvar org-agenda-filtered-by-category nil)
6997 (defun org-agenda-filter-by-category (strip)
6998 "Keep only those lines in the agenda buffer that have a specific category.
6999 The category is that of the current line."
7000 (interactive "P")
7001 (if (and org-agenda-filtered-by-category
7002 org-agenda-category-filter)
7003 (org-agenda-filter-show-all-cat)
7004 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7005 (if cat (org-agenda-filter-apply
7006 (list (concat (if strip "-" "+") cat)) 'category)
7007 (error "No category at point")))))
7009 (defun org-find-top-category (&optional pos)
7010 (save-excursion
7011 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7012 (if pos (goto-char pos))
7013 ;; Skip up to the topmost parent
7014 (while (ignore-errors (outline-up-heading 1) t))
7015 (ignore-errors
7016 (nth 4 (org-heading-components))))))
7018 (defvar org-agenda-filtered-by-top-category nil)
7020 (defun org-agenda-filter-by-top-category (strip)
7021 "Keep only those lines in the agenda buffer that have a specific category.
7022 The category is that of the current line."
7023 (interactive "P")
7024 (if org-agenda-filtered-by-top-category
7025 (progn
7026 (setq org-agenda-filtered-by-top-category nil
7027 org-agenda-top-category-filter nil)
7028 (org-agenda-filter-show-all-cat))
7029 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7030 (if cat (org-agenda-filter-top-category-apply cat strip)
7031 (error "No top-level category at point")))))
7033 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7034 "Keep only those lines in the agenda buffer that have a specific tag.
7035 The tag is selected with its fast selection letter, as configured.
7036 With prefix argument STRIP, remove all lines that do have the tag.
7037 A lisp caller can specify CHAR. NARROW means that the new tag should be
7038 used to narrow the search - the interactive user can also press `-' or `+'
7039 to switch to narrowing."
7040 (interactive "P")
7041 (let* ((alist org-tag-alist-for-agenda)
7042 (tag-chars (mapconcat
7043 (lambda (x) (if (and (not (symbolp (car x)))
7044 (cdr x))
7045 (char-to-string (cdr x))
7046 ""))
7047 alist ""))
7048 (efforts (org-split-string
7049 (or (cdr (assoc (concat org-effort-property "_ALL")
7050 org-global-properties))
7051 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7052 "")))
7053 (effort-op org-agenda-filter-effort-default-operator)
7054 (effort-prompt "")
7055 (inhibit-read-only t)
7056 (current org-agenda-tag-filter)
7057 maybe-refresh a n tag)
7058 (unless char
7059 (message
7060 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7061 (if narrow "Narrow" "Filter") tag-chars
7062 (if org-agenda-auto-exclude-function "[RET], " ""))
7063 (setq char (read-char-exclusive)))
7064 (when (member char '(?+ ?-))
7065 ;; Narrowing down
7066 (cond ((equal char ?-) (setq strip t narrow t))
7067 ((equal char ?+) (setq strip nil narrow t)))
7068 (message
7069 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7070 (setq char (read-char-exclusive)))
7071 (when (member char '(?< ?> ?= ??))
7072 ;; An effort operator
7073 (setq effort-op (char-to-string char))
7074 (setq alist nil) ; to make sure it will be interpreted as effort.
7075 (unless (equal char ??)
7076 (loop for i from 0 to 9 do
7077 (setq effort-prompt
7078 (concat
7079 effort-prompt " ["
7080 (if (= i 9) "0" (int-to-string (1+ i)))
7081 "]" (nth i efforts))))
7082 (message "Effort%s: %s " effort-op effort-prompt)
7083 (setq char (read-char-exclusive))
7084 (when (or (< char ?0) (> char ?9))
7085 (error "Need 1-9,0 to select effort"))))
7086 (when (equal char ?\t)
7087 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7088 (org-set-local 'org-global-tags-completion-table
7089 (org-global-tags-completion-table)))
7090 (let ((completion-ignore-case t))
7091 (setq tag (org-icompleting-read
7092 "Tag: " org-global-tags-completion-table))))
7093 (cond
7094 ((equal char ?\r)
7095 (org-agenda-filter-show-all-tag)
7096 (when org-agenda-auto-exclude-function
7097 (setq org-agenda-tag-filter '())
7098 (dolist (tag (org-agenda-get-represented-tags))
7099 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7100 (if modifier
7101 (push modifier org-agenda-tag-filter))))
7102 (if (not (null org-agenda-tag-filter))
7103 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7104 (setq maybe-refresh t))
7105 ((equal char ?/)
7106 (org-agenda-filter-show-all-tag)
7107 (when (get 'org-agenda-tag-filter :preset-filter)
7108 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7109 (setq maybe-refresh t))
7110 ((equal char ?. )
7111 (setq org-agenda-tag-filter
7112 (mapcar (lambda(tag) (concat "+" tag))
7113 (org-get-at-bol 'tags)))
7114 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7115 (setq maybe-refresh t))
7116 ((or (equal char ?\ )
7117 (setq a (rassoc char alist))
7118 (and (>= char ?0) (<= char ?9)
7119 (setq n (if (= char ?0) 9 (- char ?0 1))
7120 tag (concat effort-op (nth n efforts))
7121 a (cons tag nil)))
7122 (and (= char ??)
7123 (setq tag "?eff")
7124 a (cons tag nil))
7125 (and tag (setq a (cons tag nil))))
7126 (org-agenda-filter-show-all-tag)
7127 (setq tag (car a))
7128 (setq org-agenda-tag-filter
7129 (cons (concat (if strip "-" "+") tag)
7130 (if narrow current nil)))
7131 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7132 (setq maybe-refresh t))
7133 (t (error "Invalid tag selection character %c" char)))
7134 (when (and maybe-refresh
7135 (eq org-agenda-clockreport-mode 'with-filter))
7136 (org-agenda-redo))))
7138 (defun org-agenda-get-represented-tags ()
7139 "Get a list of all tags currently represented in the agenda."
7140 (let (p tags)
7141 (save-excursion
7142 (goto-char (point-min))
7143 (while (setq p (next-single-property-change (point) 'tags))
7144 (goto-char p)
7145 (mapc (lambda (x) (add-to-list 'tags x))
7146 (get-text-property (point) 'tags))))
7147 tags))
7149 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7150 "Refine the current filter. See `org-agenda-filter-by-tag'."
7151 (interactive "P")
7152 (org-agenda-filter-by-tag strip char 'refine))
7154 (defun org-agenda-filter-make-matcher ()
7155 "Create the form that tests a line for agenda filter."
7156 (let (f f1)
7157 ;; first compute the tag-filter matcher
7158 (dolist (x (delete-dups
7159 (append (get 'org-agenda-tag-filter
7160 :preset-filter) org-agenda-tag-filter)))
7161 (if (member x '("-" "+"))
7162 (setq f1 (if (equal x "-") 'tags '(not tags)))
7163 (if (string-match "[<=>?]" x)
7164 (setq f1 (org-agenda-filter-effort-form x))
7165 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7166 (if (equal (string-to-char x) ?-)
7167 (setq f1 (list 'not f1))))
7168 (push f1 f))
7169 ;; then compute the category-filter matcher
7170 (dolist (x (delete-dups
7171 (append (get 'org-agenda-category-filter
7172 :preset-filter) org-agenda-category-filter)))
7173 (if (equal "-" (substring x 0 1))
7174 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7175 (setq f1 (list 'equal (substring x 1) 'cat)))
7176 (push f1 f))
7177 (cons 'and (nreverse f))))
7179 (defun org-agenda-filter-effort-form (e)
7180 "Return the form to compare the effort of the current line with what E says.
7181 E looks like \"+<2:25\"."
7182 (let (op)
7183 (setq e (substring e 1))
7184 (setq op (string-to-char e) e (substring e 1))
7185 (setq op (cond ((equal op ?<) '<=)
7186 ((equal op ?>) '>=)
7187 ((equal op ??) op)
7188 (t '=)))
7189 (list 'org-agenda-compare-effort (list 'quote op)
7190 (org-duration-string-to-minutes e))))
7192 (defun org-agenda-compare-effort (op value)
7193 "Compare the effort of the current line with VALUE, using OP.
7194 If the line does not have an effort defined, return nil."
7195 (let ((eff (org-get-at-bol 'effort-minutes)))
7196 (if (equal op ??)
7197 (not eff)
7198 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7199 value))))
7201 (defun org-agenda-filter-apply (filter type)
7202 "Set FILTER as the new agenda filter and apply it."
7203 (let (tags cat)
7204 (if (eq type 'tag)
7205 (setq org-agenda-tag-filter filter)
7206 (setq org-agenda-category-filter filter))
7207 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7208 (if (and (eq type 'category)
7209 (not (equal (substring (car filter) 0 1) "-")))
7210 ;; Only set `org-agenda-filtered-by-category' to t
7211 ;; when a unique category is used as the filter
7212 (setq org-agenda-filtered-by-category t))
7213 (org-agenda-set-mode-name)
7214 (save-excursion
7215 (goto-char (point-min))
7216 (while (not (eobp))
7217 (if (org-get-at-bol 'org-marker)
7218 (progn
7219 (setq tags (org-get-at-bol 'tags) ; used in eval
7220 cat (get-text-property (point) 'org-category))
7221 (if (not (eval org-agenda-filter-form))
7222 (org-agenda-filter-hide-line type))
7223 (beginning-of-line 2))
7224 (beginning-of-line 2))))
7225 (if (get-char-property (point) 'invisible)
7226 (ignore-errors (org-agenda-previous-line)))))
7228 (defun org-agenda-filter-top-category-apply (category &optional negative)
7229 "Set FILTER as the new agenda filter and apply it."
7230 (org-agenda-set-mode-name)
7231 (save-excursion
7232 (goto-char (point-min))
7233 (while (not (eobp))
7234 (let* ((pos (org-get-at-bol 'org-hd-marker))
7235 (topcat (and pos (org-find-top-category pos))))
7236 (if (and topcat (funcall (if negative 'identity 'not)
7237 (string= category topcat)))
7238 (org-agenda-filter-hide-line 'category)))
7239 (beginning-of-line 2)))
7240 (if (get-char-property (point) 'invisible)
7241 (org-agenda-previous-line))
7242 (setq org-agenda-top-category-filter category
7243 org-agenda-filtered-by-top-category t))
7245 (defun org-agenda-filter-hide-line (type)
7246 (let (ov)
7247 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7248 (point-at-eol)))
7249 (overlay-put ov 'invisible t)
7250 (overlay-put ov 'type type)
7251 (if (eq type 'tag)
7252 (push ov org-agenda-tag-filter-overlays)
7253 (push ov org-agenda-cat-filter-overlays))))
7255 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7256 (setq pos (or pos (point)))
7257 (save-excursion
7258 (dolist (ov (overlays-at pos))
7259 (when (and (overlay-get ov 'invisible)
7260 (eq (overlay-get ov 'type) 'tag))
7261 (goto-char pos)
7262 (if (< (overlay-start ov) (point-at-eol))
7263 (move-overlay ov (point-at-eol)
7264 (overlay-end ov)))))))
7266 (defun org-agenda-filter-show-all-tag nil
7267 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7268 (setq org-agenda-tag-filter-overlays nil
7269 org-agenda-tag-filter nil
7270 org-agenda-filter-form nil)
7271 (org-agenda-set-mode-name))
7273 (defun org-agenda-filter-show-all-cat nil
7274 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7275 (setq org-agenda-cat-filter-overlays nil
7276 org-agenda-filtered-by-category nil
7277 org-agenda-category-filter nil
7278 org-agenda-filter-form nil)
7279 (org-agenda-set-mode-name))
7281 (defun org-agenda-manipulate-query-add ()
7282 "Manipulate the query by adding a search term with positive selection.
7283 Positive selection means the term must be matched for selection of an entry."
7284 (interactive)
7285 (org-agenda-manipulate-query ?\[))
7286 (defun org-agenda-manipulate-query-subtract ()
7287 "Manipulate the query by adding a search term with negative selection.
7288 Negative selection means term must not be matched for selection of an entry."
7289 (interactive)
7290 (org-agenda-manipulate-query ?\]))
7291 (defun org-agenda-manipulate-query-add-re ()
7292 "Manipulate the query by adding a search regexp with positive selection.
7293 Positive selection means the regexp must match for selection of an entry."
7294 (interactive)
7295 (org-agenda-manipulate-query ?\{))
7296 (defun org-agenda-manipulate-query-subtract-re ()
7297 "Manipulate the query by adding a search regexp with negative selection.
7298 Negative selection means regexp must not match for selection of an entry."
7299 (interactive)
7300 (org-agenda-manipulate-query ?\}))
7301 (defun org-agenda-manipulate-query (char)
7302 (cond
7303 ((memq org-agenda-type '(timeline agenda))
7304 (let ((org-agenda-include-inactive-timestamps t))
7305 (org-agenda-redo))
7306 (message "Display now includes inactive timestamps as well"))
7307 ((eq org-agenda-type 'search)
7308 (org-add-to-string
7309 'org-agenda-query-string
7310 (if org-agenda-last-search-view-search-was-boolean
7311 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7312 (?\{ . " +{}") (?\} . " -{}"))))
7313 " "))
7314 (setq org-agenda-redo-command
7315 (list 'org-search-view
7316 (car (get-text-property (min (1- (point-max)) (point))
7317 'org-last-args))
7318 org-agenda-query-string
7319 (+ (length org-agenda-query-string)
7320 (if (member char '(?\{ ?\})) 0 1))))
7321 (set-register org-agenda-query-register org-agenda-query-string)
7322 (let ((org-agenda-overriding-arguments
7323 (cdr org-agenda-redo-command)))
7324 (org-agenda-redo)))
7325 (t (error "Cannot manipulate query for %s-type agenda buffers"
7326 org-agenda-type))))
7328 (defun org-add-to-string (var string)
7329 (set var (concat (symbol-value var) string)))
7331 (defun org-agenda-goto-date (span)
7332 "Jump to DATE in agenda."
7333 (interactive "P")
7334 (let* ((org-read-date-prefer-future
7335 (eval org-agenda-jump-prefer-future))
7336 (date (org-read-date))
7337 (org-agenda-sticky-orig org-agenda-sticky)
7338 (org-agenda-buffer-tmp-name (buffer-name))
7339 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7340 (0-arg (or current-prefix-arg (car args)))
7341 (2-arg (nth 2 args))
7342 (newcmd (list 'org-agenda-list 0-arg date
7343 (org-agenda-span-to-ndays 2-arg)))
7344 (newargs (cdr newcmd))
7345 (inhibit-read-only t)
7346 org-agenda-sticky)
7347 (if (not (org-agenda-check-type t 'agenda))
7348 (error "Not available in non-agenda blocks")
7349 (add-text-properties (point-min) (point-max)
7350 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7351 (org-agenda-redo)
7352 (setq org-agenda-sticky org-agenda-sticky-orig
7353 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7355 (defun org-agenda-goto-today ()
7356 "Go to today."
7357 (interactive)
7358 (org-agenda-check-type t 'timeline 'agenda)
7359 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7360 (curspan (nth 2 args))
7361 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7362 (cond
7363 (tdpos (goto-char tdpos))
7364 ((eq org-agenda-type 'agenda)
7365 (let* ((sd (org-agenda-compute-starting-span
7366 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7367 (org-agenda-overriding-arguments args))
7368 (setf (nth 1 org-agenda-overriding-arguments) sd)
7369 (org-agenda-redo)
7370 (org-agenda-find-same-or-today-or-agenda)))
7371 (t (error "Cannot find today")))))
7373 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7374 (goto-char
7375 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7376 (text-property-any (point-min) (point-max) 'org-today t)
7377 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7378 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7379 (org-agenda-goto-block-beginning))
7380 (point-min))))
7382 (defun org-agenda-goto-block-beginning ()
7383 "Go the agenda block beginning."
7384 (interactive)
7385 (if (not (derived-mode-p 'org-agenda-mode))
7386 (error "Cannot execute this command outside of org-agenda-mode buffers")
7387 (let (dest)
7388 (save-excursion
7389 (unless (looking-at "\\'")
7390 (forward-char))
7391 (let* ((prop 'org-agenda-structural-header)
7392 (p (previous-single-property-change (point) prop))
7393 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7394 (1- (point))) prop)))
7395 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7396 (if (not dest)
7397 (error "Cannot find the beginning of the blog")
7398 (goto-char dest)
7399 (move-beginning-of-line 1)))))
7401 (defun org-agenda-later (arg)
7402 "Go forward in time by the current span.
7403 With prefix ARG, go forward that many times the current span."
7404 (interactive "p")
7405 (org-agenda-check-type t 'agenda)
7406 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7407 (span (or (nth 2 args) org-agenda-current-span))
7408 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7409 (greg (calendar-gregorian-from-absolute sd))
7410 (cnt (org-get-at-bol 'org-day-cnt))
7411 greg2)
7412 (cond
7413 ((numberp span)
7414 (setq sd (+ (* span arg) sd)))
7415 ((eq span 'day)
7416 (setq sd (+ arg sd)))
7417 ((eq span 'week)
7418 (setq sd (+ (* 7 arg) sd)))
7419 ((eq span 'month)
7420 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7421 sd (calendar-absolute-from-gregorian greg2))
7422 (setcar greg2 (1+ (car greg2))))
7423 ((eq span 'year)
7424 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7425 sd (calendar-absolute-from-gregorian greg2))
7426 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7428 (setq sd (+ (* span arg) sd))))
7429 (let ((org-agenda-overriding-cmd
7430 ;; `cmd' may have been set by `org-agenda-run-series' which
7431 ;; uses `org-agenda-overriding-cmd' to decide whether
7432 ;; overriding is allowed for `cmd'
7433 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7434 (org-agenda-overriding-arguments
7435 (list (car args) sd span)))
7436 (org-agenda-redo)
7437 (org-agenda-find-same-or-today-or-agenda cnt))))
7439 (defun org-agenda-earlier (arg)
7440 "Go backward in time by the current span.
7441 With prefix ARG, go backward that many times the current span."
7442 (interactive "p")
7443 (org-agenda-later (- arg)))
7445 (defun org-agenda-view-mode-dispatch ()
7446 "Call one of the view mode commands."
7447 (interactive)
7448 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7449 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7450 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7451 (let ((a (read-char-exclusive)))
7452 (case a
7453 (?\ (call-interactively 'org-agenda-reset-view))
7454 (?d (call-interactively 'org-agenda-day-view))
7455 (?w (call-interactively 'org-agenda-week-view))
7456 (?m (call-interactively 'org-agenda-month-view))
7457 (?y (call-interactively 'org-agenda-year-view))
7458 (?l (call-interactively 'org-agenda-log-mode))
7459 (?L (org-agenda-log-mode '(4)))
7460 (?c (org-agenda-log-mode 'clockcheck))
7461 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7462 (?a (call-interactively 'org-agenda-archives-mode))
7463 (?A (org-agenda-archives-mode 'files))
7464 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7465 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7466 (?G (call-interactively 'org-agenda-toggle-time-grid))
7467 (?D (call-interactively 'org-agenda-toggle-diary))
7468 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7469 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7470 (org-agenda-check-type t 'timeline 'agenda)
7471 (org-agenda-redo))
7472 (message "Display now includes inactive timestamps as well"))
7473 (?q (message "Abort"))
7474 (otherwise (error "Invalid key" )))))
7476 (defun org-agenda-reset-view ()
7477 "Switch to default view for agenda."
7478 (interactive)
7479 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7480 (defun org-agenda-day-view (&optional day-of-year)
7481 "Switch to daily view for agenda.
7482 With argument DAY-OF-YEAR, switch to that day of the year."
7483 (interactive "P")
7484 (org-agenda-change-time-span 'day day-of-year))
7485 (defun org-agenda-week-view (&optional iso-week)
7486 "Switch to daily view for agenda.
7487 With argument ISO-WEEK, switch to the corresponding ISO week.
7488 If ISO-WEEK has more then 2 digits, only the last two encode the
7489 week. Any digits before this encode a year. So 200712 means
7490 week 12 of year 2007. Years in the range 1938-2037 can also be
7491 written as 2-digit years."
7492 (interactive "P")
7493 (org-agenda-change-time-span 'week iso-week))
7494 (defun org-agenda-month-view (&optional month)
7495 "Switch to monthly view for agenda.
7496 With argument MONTH, switch to that month."
7497 (interactive "P")
7498 (org-agenda-change-time-span 'month month))
7499 (defun org-agenda-year-view (&optional year)
7500 "Switch to yearly view for agenda.
7501 With argument YEAR, switch to that year.
7502 If MONTH has more then 2 digits, only the last two encode the
7503 month. Any digits before this encode a year. So 200712 means
7504 December year 2007. Years in the range 1938-2037 can also be
7505 written as 2-digit years."
7506 (interactive "P")
7507 (when year
7508 (setq year (org-small-year-to-year year)))
7509 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7510 (org-agenda-change-time-span 'year year)
7511 (error "Abort")))
7513 (defun org-agenda-change-time-span (span &optional n)
7514 "Change the agenda view to SPAN.
7515 SPAN may be `day', `week', `month', `year'."
7516 (org-agenda-check-type t 'agenda)
7517 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7518 (curspan (nth 2 args)))
7519 (if (and (not n) (equal curspan span))
7520 (error "Viewing span is already \"%s\"" span))
7521 (let* ((sd (or (org-get-at-bol 'day)
7522 (nth 1 args)
7523 org-starting-day))
7524 (sd (org-agenda-compute-starting-span sd span n))
7525 (org-agenda-overriding-cmd
7526 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7527 (org-agenda-overriding-arguments
7528 (list (car args) sd span)))
7529 (org-agenda-redo)
7530 (org-agenda-find-same-or-today-or-agenda))
7531 (org-agenda-set-mode-name)
7532 (message "Switched to %s view" span)))
7534 (defun org-agenda-compute-starting-span (sd span &optional n)
7535 "Compute starting date for agenda.
7536 SPAN may be `day', `week', `month', `year'. The return value
7537 is a cons cell with the starting date and the number of days,
7538 so that the date SD will be in that range."
7539 (let* ((greg (calendar-gregorian-from-absolute sd))
7540 (dg (nth 1 greg))
7541 (mg (car greg))
7542 (yg (nth 2 greg)))
7543 (cond
7544 ((eq span 'day)
7545 (when n
7546 (setq sd (+ (calendar-absolute-from-gregorian
7547 (list mg 1 yg))
7548 n -1))))
7549 ((eq span 'week)
7550 (let* ((nt (calendar-day-of-week
7551 (calendar-gregorian-from-absolute sd)))
7552 (d (if org-agenda-start-on-weekday
7553 (- nt org-agenda-start-on-weekday)
7556 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7557 (when n
7558 (require 'cal-iso)
7559 (when (> n 99)
7560 (setq y1 (org-small-year-to-year (/ n 100))
7561 n (mod n 100)))
7562 (setq sd
7563 (calendar-absolute-from-iso
7564 (list n 1
7565 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7566 ((eq span 'month)
7567 (let (y1)
7568 (when (and n (> n 99))
7569 (setq y1 (org-small-year-to-year (/ n 100))
7570 n (mod n 100)))
7571 (setq sd (calendar-absolute-from-gregorian
7572 (list (or n mg) 1 (or y1 yg))))))
7573 ((eq span 'year)
7574 (setq sd (calendar-absolute-from-gregorian
7575 (list 1 1 (or n yg))))))
7576 sd))
7578 (defun org-agenda-next-date-line (&optional arg)
7579 "Jump to the next line indicating a date in agenda buffer."
7580 (interactive "p")
7581 (org-agenda-check-type t 'agenda 'timeline)
7582 (beginning-of-line 1)
7583 ;; This does not work if user makes date format that starts with a blank
7584 (if (looking-at "^\\S-") (forward-char 1))
7585 (if (not (re-search-forward "^\\S-" nil t arg))
7586 (progn
7587 (backward-char 1)
7588 (error "No next date after this line in this buffer")))
7589 (goto-char (match-beginning 0)))
7591 (defun org-agenda-previous-date-line (&optional arg)
7592 "Jump to the previous line indicating a date in agenda buffer."
7593 (interactive "p")
7594 (org-agenda-check-type t 'agenda 'timeline)
7595 (beginning-of-line 1)
7596 (if (not (re-search-backward "^\\S-" nil t arg))
7597 (error "No previous date before this line in this buffer")))
7599 ;; Initialize the highlight
7600 (defvar org-hl (make-overlay 1 1))
7601 (overlay-put org-hl 'face 'highlight)
7603 (defun org-highlight (begin end &optional buffer)
7604 "Highlight a region with overlay."
7605 (move-overlay org-hl begin end (or buffer (current-buffer))))
7607 (defun org-unhighlight ()
7608 "Detach overlay INDEX."
7609 (org-detach-overlay org-hl))
7611 (defun org-unhighlight-once ()
7612 "Remove the highlight from its position, and this function from the hook."
7613 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7614 (org-unhighlight))
7616 (defvar org-agenda-pre-follow-window-conf nil)
7617 (defun org-agenda-follow-mode ()
7618 "Toggle follow mode in an agenda buffer."
7619 (interactive)
7620 (unless org-agenda-follow-mode
7621 (setq org-agenda-pre-follow-window-conf
7622 (current-window-configuration)))
7623 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7624 (unless org-agenda-follow-mode
7625 (set-window-configuration org-agenda-pre-follow-window-conf))
7626 (org-agenda-set-mode-name)
7627 (org-agenda-do-context-action)
7628 (message "Follow mode is %s"
7629 (if org-agenda-follow-mode "on" "off")))
7631 (defun org-agenda-entry-text-mode (&optional arg)
7632 "Toggle entry text mode in an agenda buffer."
7633 (interactive "P")
7634 (setq org-agenda-entry-text-mode (or (integerp arg)
7635 (not org-agenda-entry-text-mode)))
7636 (org-agenda-entry-text-hide)
7637 (and org-agenda-entry-text-mode
7638 (let ((org-agenda-entry-text-maxlines
7639 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7640 (org-agenda-entry-text-show)))
7641 (org-agenda-set-mode-name)
7642 (message "Entry text mode is %s. Maximum number of lines is %d"
7643 (if org-agenda-entry-text-mode "on" "off")
7644 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7646 (defun org-agenda-clockreport-mode (&optional with-filter)
7647 "Toggle clocktable mode in an agenda buffer.
7648 With prefix arg WITH-FILTER, make the clocktable respect the current
7649 agenda filter."
7650 (interactive "P")
7651 (org-agenda-check-type t 'agenda)
7652 (if with-filter
7653 (setq org-agenda-clockreport-mode 'with-filter)
7654 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7655 (org-agenda-set-mode-name)
7656 (org-agenda-redo)
7657 (message "Clocktable mode is %s"
7658 (if org-agenda-clockreport-mode "on" "off")))
7660 (defun org-agenda-log-mode (&optional special)
7661 "Toggle log mode in an agenda buffer.
7662 With argument SPECIAL, show all possible log items, not only the ones
7663 configured in `org-agenda-log-mode-items'.
7664 With a double `C-u' prefix arg, show *only* log items, nothing else."
7665 (interactive "P")
7666 (org-agenda-check-type t 'agenda 'timeline)
7667 (setq org-agenda-show-log
7668 (cond
7669 ((equal special '(16)) 'only)
7670 ((eq special 'clockcheck)
7671 (if (eq org-agenda-show-log 'clockcheck)
7672 nil 'clockcheck))
7673 (special '(closed clock state))
7674 (t (not org-agenda-show-log))))
7675 (org-agenda-set-mode-name)
7676 (org-agenda-redo)
7677 (message "Log mode is %s"
7678 (if org-agenda-show-log "on" "off")))
7680 (defun org-agenda-archives-mode (&optional with-files)
7681 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7682 When called with a prefix argument, include all archive files as well."
7683 (interactive "P")
7684 (setq org-agenda-archives-mode
7685 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7686 (org-agenda-set-mode-name)
7687 (org-agenda-redo)
7688 (message
7689 "%s"
7690 (cond
7691 ((eq org-agenda-archives-mode nil)
7692 "No archives are included")
7693 ((eq org-agenda-archives-mode 'trees)
7694 (format "Trees with :%s: tag are included" org-archive-tag))
7695 ((eq org-agenda-archives-mode t)
7696 (format "Trees with :%s: tag and all active archive files are included"
7697 org-archive-tag)))))
7699 (defun org-agenda-toggle-diary ()
7700 "Toggle diary inclusion in an agenda buffer."
7701 (interactive)
7702 (org-agenda-check-type t 'agenda)
7703 (setq org-agenda-include-diary (not org-agenda-include-diary))
7704 (org-agenda-redo)
7705 (org-agenda-set-mode-name)
7706 (message "Diary inclusion turned %s"
7707 (if org-agenda-include-diary "on" "off")))
7709 (defun org-agenda-toggle-deadlines ()
7710 "Toggle inclusion of entries with a deadline in an agenda buffer."
7711 (interactive)
7712 (org-agenda-check-type t 'agenda)
7713 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7714 (org-agenda-redo)
7715 (org-agenda-set-mode-name)
7716 (message "Deadlines inclusion turned %s"
7717 (if org-agenda-include-deadlines "on" "off")))
7719 (defun org-agenda-toggle-time-grid ()
7720 "Toggle time grid in an agenda buffer."
7721 (interactive)
7722 (org-agenda-check-type t 'agenda)
7723 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7724 (org-agenda-redo)
7725 (org-agenda-set-mode-name)
7726 (message "Time-grid turned %s"
7727 (if org-agenda-use-time-grid "on" "off")))
7729 (defun org-agenda-set-mode-name ()
7730 "Set the mode name to indicate all the small mode settings."
7731 (setq mode-name
7732 (list "Org-Agenda"
7733 (if (get 'org-agenda-files 'org-restrict) " []" "")
7735 '(:eval (org-agenda-span-name org-agenda-current-span))
7736 (if org-agenda-follow-mode " Follow" "")
7737 (if org-agenda-entry-text-mode " ETxt" "")
7738 (if org-agenda-include-diary " Diary" "")
7739 (if org-agenda-include-deadlines " Ddl" "")
7740 (if org-agenda-use-time-grid " Grid" "")
7741 (if (and (boundp 'org-habit-show-habits)
7742 org-habit-show-habits) " Habit" "")
7743 (cond
7744 ((consp org-agenda-show-log) " LogAll")
7745 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7746 (org-agenda-show-log " Log")
7747 (t ""))
7748 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7749 :preset-filter))
7750 '(:eval (org-propertize
7751 (concat " <"
7752 (mapconcat
7753 'identity
7754 (append
7755 (get 'org-agenda-category-filter :preset-filter)
7756 org-agenda-category-filter)
7758 ">")
7759 'face 'org-agenda-filter-category
7760 'help-echo "Category used in filtering"))
7762 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7763 :preset-filter))
7764 '(:eval (org-propertize
7765 (concat " {"
7766 (mapconcat
7767 'identity
7768 (append
7769 (get 'org-agenda-tag-filter :preset-filter)
7770 org-agenda-tag-filter)
7772 "}")
7773 'face 'org-agenda-filter-tags
7774 'help-echo "Tags used in filtering"))
7776 (if org-agenda-archives-mode
7777 (if (eq org-agenda-archives-mode t)
7778 " Archives"
7779 (format " :%s:" org-archive-tag))
7781 (if org-agenda-clockreport-mode
7782 (if (eq org-agenda-clockreport-mode 'with-filter)
7783 " Clock{}" " Clock")
7784 "")))
7785 (force-mode-line-update))
7787 (org-define-obsolete-function-alias
7788 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7790 (defun org-agenda-update-agenda-type ()
7791 "Update the agenda type after each command."
7792 (setq org-agenda-type
7793 (or (get-text-property (point) 'org-agenda-type)
7794 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7796 (defun org-agenda-next-line ()
7797 "Move cursor to the next line, and show if follow mode is active."
7798 (interactive)
7799 (call-interactively 'next-line)
7800 (org-agenda-do-context-action))
7802 (defun org-agenda-previous-line ()
7803 "Move cursor to the previous line, and show if follow-mode is active."
7804 (interactive)
7805 (call-interactively 'previous-line)
7806 (org-agenda-do-context-action))
7808 (defun org-agenda-next-item (n)
7809 "Move cursor to next agenda item."
7810 (interactive "p")
7811 (let ((col (current-column)))
7812 (dotimes (c n)
7813 (when (next-single-property-change (point-at-eol) 'org-marker)
7814 (move-end-of-line 1)
7815 (goto-char (next-single-property-change (point) 'org-marker))))
7816 (org-move-to-column col))
7817 (org-agenda-do-context-action))
7819 (defun org-agenda-previous-item (n)
7820 "Move cursor to next agenda item."
7821 (interactive "p")
7822 (dotimes (c n)
7823 (let ((col (current-column))
7824 (goto (save-excursion
7825 (move-end-of-line 0)
7826 (previous-single-property-change (point) 'org-marker))))
7827 (if goto (goto-char goto))
7828 (org-move-to-column col)))
7829 (org-agenda-do-context-action))
7831 (defun org-agenda-do-context-action ()
7832 "Show outline path and, maybe, follow mode window."
7833 (let ((m (org-get-at-bol 'org-marker)))
7834 (when (and (markerp m) (marker-buffer m))
7835 (and org-agenda-follow-mode
7836 (if org-agenda-follow-indirect
7837 (org-agenda-tree-to-indirect-buffer nil)
7838 (org-agenda-show)))
7839 (and org-agenda-show-outline-path
7840 (org-with-point-at m (org-display-outline-path t))))))
7842 (defun org-agenda-show-tags ()
7843 "Show the tags applicable to the current item."
7844 (interactive)
7845 (let* ((tags (org-get-at-bol 'tags)))
7846 (if tags
7847 (message "Tags are :%s:"
7848 (org-no-properties (mapconcat 'identity tags ":")))
7849 (message "No tags associated with this line"))))
7851 (defun org-agenda-goto (&optional highlight)
7852 "Go to the Org-mode file which contains the item at point."
7853 (interactive)
7854 (let* ((marker (or (org-get-at-bol 'org-marker)
7855 (org-agenda-error)))
7856 (buffer (marker-buffer marker))
7857 (pos (marker-position marker)))
7858 (switch-to-buffer-other-window buffer)
7859 (widen)
7860 (push-mark)
7861 (goto-char pos)
7862 (when (derived-mode-p 'org-mode)
7863 (org-show-context 'agenda)
7864 (save-excursion
7865 (and (outline-next-heading)
7866 (org-flag-heading nil)))) ; show the next heading
7867 (when (outline-invisible-p)
7868 (show-entry)) ; display invisible text
7869 (recenter (/ (window-height) 2))
7870 (run-hooks 'org-agenda-after-show-hook)
7871 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7873 (defvar org-agenda-after-show-hook nil
7874 "Normal hook run after an item has been shown from the agenda.
7875 Point is in the buffer where the item originated.")
7877 (defun org-agenda-kill ()
7878 "Kill the entry or subtree belonging to the current agenda entry."
7879 (interactive)
7880 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7881 (let* ((bufname-orig (buffer-name))
7882 (marker (or (org-get-at-bol 'org-marker)
7883 (org-agenda-error)))
7884 (buffer (marker-buffer marker))
7885 (pos (marker-position marker))
7886 (type (org-get-at-bol 'type))
7887 dbeg dend (n 0) conf)
7888 (org-with-remote-undo buffer
7889 (with-current-buffer buffer
7890 (save-excursion
7891 (goto-char pos)
7892 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7893 (setq dbeg (progn (org-back-to-heading t) (point))
7894 dend (org-end-of-subtree t t))
7895 (setq dbeg (point-at-bol)
7896 dend (min (point-max) (1+ (point-at-eol)))))
7897 (goto-char dbeg)
7898 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7899 (setq conf (or (eq t org-agenda-confirm-kill)
7900 (and (numberp org-agenda-confirm-kill)
7901 (> n org-agenda-confirm-kill))))
7902 (and conf
7903 (not (y-or-n-p
7904 (format "Delete entry with %d lines in buffer \"%s\"? "
7905 n (buffer-name buffer))))
7906 (error "Abort"))
7907 (let ((org-agenda-buffer-name bufname-orig))
7908 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7909 (with-current-buffer buffer (delete-region dbeg dend))
7910 (message "Agenda item and source killed"))))
7912 (defvar org-archive-default-command) ; defined in org-archive.el
7913 (defun org-agenda-archive-default ()
7914 "Archive the entry or subtree belonging to the current agenda entry."
7915 (interactive)
7916 (require 'org-archive)
7917 (org-agenda-archive-with org-archive-default-command))
7919 (defun org-agenda-archive-default-with-confirmation ()
7920 "Archive the entry or subtree belonging to the current agenda entry."
7921 (interactive)
7922 (require 'org-archive)
7923 (org-agenda-archive-with org-archive-default-command 'confirm))
7925 (defun org-agenda-archive ()
7926 "Archive the entry or subtree belonging to the current agenda entry."
7927 (interactive)
7928 (org-agenda-archive-with 'org-archive-subtree))
7930 (defun org-agenda-archive-to-archive-sibling ()
7931 "Move the entry to the archive sibling."
7932 (interactive)
7933 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7935 (defun org-agenda-archive-with (cmd &optional confirm)
7936 "Move the entry to the archive sibling."
7937 (interactive)
7938 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7939 (let* ((bufname-orig (buffer-name))
7940 (marker (or (org-get-at-bol 'org-marker)
7941 (org-agenda-error)))
7942 (buffer (marker-buffer marker))
7943 (pos (marker-position marker)))
7944 (org-with-remote-undo buffer
7945 (with-current-buffer buffer
7946 (if (derived-mode-p 'org-mode)
7947 (if (and confirm
7948 (not (y-or-n-p "Archive this subtree or entry? ")))
7949 (error "Abort")
7950 (save-excursion
7951 (goto-char pos)
7952 (let ((org-agenda-buffer-name bufname-orig))
7953 (org-remove-subtree-entries-from-agenda))
7954 (org-back-to-heading t)
7955 (funcall cmd)))
7956 (error "Archiving works only in Org-mode files"))))))
7958 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7959 "Remove all lines in the agenda that correspond to a given subtree.
7960 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7961 If this information is not given, the function uses the tree at point."
7962 (let ((buf (or buf (current-buffer))) m p)
7963 (save-excursion
7964 (unless (and beg end)
7965 (org-back-to-heading t)
7966 (setq beg (point))
7967 (org-end-of-subtree t)
7968 (setq end (point)))
7969 (set-buffer (get-buffer org-agenda-buffer-name))
7970 (save-excursion
7971 (goto-char (point-max))
7972 (beginning-of-line 1)
7973 (while (not (bobp))
7974 (when (and (setq m (org-get-at-bol 'org-marker))
7975 (equal buf (marker-buffer m))
7976 (setq p (marker-position m))
7977 (>= p beg)
7978 (< p end))
7979 (let ((inhibit-read-only t))
7980 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7981 (beginning-of-line 0))))))
7983 (defun org-agenda-refile (&optional goto rfloc no-update)
7984 "Refile the item at point."
7985 (interactive "P")
7986 (if (equal goto '(16))
7987 (org-refile-goto-last-stored)
7988 (let* ((buffer-orig (buffer-name))
7989 (marker (or (org-get-at-bol 'org-hd-marker)
7990 (org-agenda-error)))
7991 (buffer (marker-buffer marker))
7992 (pos (marker-position marker))
7993 (rfloc (or rfloc
7994 (org-refile-get-location
7995 (if goto "Goto" "Refile to") buffer
7996 org-refile-allow-creating-parent-nodes))))
7997 (with-current-buffer buffer
7998 (save-excursion
7999 (save-restriction
8000 (widen)
8001 (goto-char marker)
8002 (let ((org-agenda-buffer-name buffer-orig))
8003 (org-remove-subtree-entries-from-agenda))
8004 (org-refile goto buffer rfloc)))))
8005 (unless no-update (org-agenda-redo))))
8007 (defun org-agenda-open-link (&optional arg)
8008 "Open the link(s) in the current entry, if any.
8009 This looks for a link in the displayed line in the agenda.
8010 It also looks at the text of the entry itself."
8011 (interactive "P")
8012 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8013 (org-get-at-bol 'org-marker)))
8014 (buffer (and marker (marker-buffer marker)))
8015 (prefix (buffer-substring
8016 (point-at-bol) (point-at-eol)))
8017 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8018 (lk (car lkall))
8019 (lkend (cdr lkall))
8020 trg)
8021 (cond
8022 ((and buffer (stringp lk))
8023 (with-current-buffer buffer
8024 (setq trg (and (string-match org-bracket-link-regexp lk)
8025 (match-string 1 lk)))
8026 (if (or (not trg) (string-match org-any-link-re trg))
8027 (save-excursion
8028 (save-restriction
8029 (widen)
8030 (goto-char marker)
8031 (when (search-forward lk nil lkend)
8032 (goto-char (match-beginning 0))
8033 (org-open-at-point))))
8034 ;; This is an internal link, widen the buffer
8035 (switch-to-buffer-other-window buffer)
8036 (widen)
8037 (goto-char marker)
8038 (when (search-forward lk nil lkend)
8039 (goto-char (match-beginning 0))
8040 (org-open-at-point)))))
8041 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8042 (save-excursion
8043 (beginning-of-line 1)
8044 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8045 (org-open-link-from-string (match-string 1)))
8046 (t (message "No link to open here")))))
8048 (defun org-agenda-copy-local-variable (var)
8049 "Get a variable from a referenced buffer and install it here."
8050 (let ((m (org-get-at-bol 'org-marker)))
8051 (when (and m (buffer-live-p (marker-buffer m)))
8052 (org-set-local var (with-current-buffer (marker-buffer m)
8053 (symbol-value var))))))
8055 (defun org-agenda-switch-to (&optional delete-other-windows)
8056 "Go to the Org-mode file which contains the item at point."
8057 (interactive)
8058 (if (and org-return-follows-link
8059 (not (org-get-at-bol 'org-marker))
8060 (org-in-regexp org-bracket-link-regexp))
8061 (org-open-link-from-string (match-string 0))
8062 (let* ((marker (or (org-get-at-bol 'org-marker)
8063 (org-agenda-error)))
8064 (buffer (marker-buffer marker))
8065 (pos (marker-position marker)))
8066 (org-pop-to-buffer-same-window buffer)
8067 (and delete-other-windows (delete-other-windows))
8068 (widen)
8069 (goto-char pos)
8070 (when (derived-mode-p 'org-mode)
8071 (org-show-context 'agenda)
8072 (save-excursion
8073 (and (outline-next-heading)
8074 (org-flag-heading nil))) ; show the next heading
8075 (when (outline-invisible-p)
8076 (show-entry)) ; display invisible text
8077 (run-hooks 'org-agenda-after-show-hook)))))
8079 (defun org-agenda-goto-mouse (ev)
8080 "Go to the Org-mode file which contains the item at the mouse click."
8081 (interactive "e")
8082 (mouse-set-point ev)
8083 (org-agenda-goto))
8085 (defun org-agenda-show (&optional full-entry)
8086 "Display the Org-mode file which contains the item at point.
8087 With prefix argument FULL-ENTRY, make the entire entry visible
8088 if it was hidden in the outline."
8089 (interactive "P")
8090 (let ((win (selected-window)))
8091 (if full-entry
8092 (let ((org-show-entry-below t))
8093 (org-agenda-goto t))
8094 (org-agenda-goto t))
8095 (select-window win)))
8097 (defvar org-agenda-show-window nil)
8098 (defun org-agenda-show-and-scroll-up (&optional arg)
8099 "Display the Org-mode file which contains the item at point.
8100 When called repeatedly, scroll the window that is displaying the buffer.
8101 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8102 `show-subtree' to display the item, so that drawers and logbooks stay
8103 folded."
8104 (interactive "P")
8105 (let ((win (selected-window)))
8106 (if (and (window-live-p org-agenda-show-window)
8107 (eq this-command last-command))
8108 (progn
8109 (select-window org-agenda-show-window)
8110 (ignore-errors (scroll-up)))
8111 (org-agenda-goto t)
8112 (if arg (org-show-entry) (show-subtree))
8113 (setq org-agenda-show-window (selected-window)))
8114 (select-window win)))
8116 (defun org-agenda-show-scroll-down ()
8117 "Scroll down the window showing the agenda."
8118 (interactive)
8119 (let ((win (selected-window)))
8120 (when (window-live-p org-agenda-show-window)
8121 (select-window org-agenda-show-window)
8122 (ignore-errors (scroll-down))
8123 (select-window win))))
8125 (defun org-agenda-show-1 (&optional more)
8126 "Display the Org-mode file which contains the item at point.
8127 The prefix arg selects the amount of information to display:
8129 0 hide the subtree
8130 1 just show the entry according to defaults.
8131 2 show the children view
8132 3 show the subtree view
8133 4 show the entire subtree and any LOGBOOK drawers
8134 5 show the entire subtree and any drawers
8135 With prefix argument FULL-ENTRY, make the entire entry visible
8136 if it was hidden in the outline."
8137 (interactive "p")
8138 (let ((win (selected-window)))
8139 (org-agenda-goto t)
8140 (org-recenter-heading 1)
8141 (cond
8142 ((= more 0)
8143 (hide-subtree)
8144 (save-excursion
8145 (org-back-to-heading)
8146 (run-hook-with-args 'org-cycle-hook 'folded))
8147 (message "Remote: FOLDED"))
8148 ((and (org-called-interactively-p 'any) (= more 1))
8149 (message "Remote: show with default settings"))
8150 ((= more 2)
8151 (show-entry)
8152 (show-children)
8153 (save-excursion
8154 (org-back-to-heading)
8155 (run-hook-with-args 'org-cycle-hook 'children))
8156 (message "Remote: CHILDREN"))
8157 ((= more 3)
8158 (show-subtree)
8159 (save-excursion
8160 (org-back-to-heading)
8161 (run-hook-with-args 'org-cycle-hook 'subtree))
8162 (message "Remote: SUBTREE"))
8163 ((= more 4)
8164 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8165 (org-drawer-regexp
8166 (concat "^[ \t]*:\\("
8167 (mapconcat 'regexp-quote org-drawers "\\|")
8168 "\\):[ \t]*$")))
8169 (show-subtree)
8170 (save-excursion
8171 (org-back-to-heading)
8172 (org-cycle-hide-drawers 'subtree)))
8173 (message "Remote: SUBTREE AND LOGBOOK"))
8174 ((> more 4)
8175 (show-subtree)
8176 (message "Remote: SUBTREE AND ALL DRAWERS")))
8177 (select-window win)))
8179 (defun org-recenter-heading (n)
8180 (save-excursion
8181 (org-back-to-heading)
8182 (recenter n)))
8184 (defvar org-agenda-cycle-counter nil)
8185 (defun org-agenda-cycle-show (&optional n)
8186 "Show the current entry in another window, with default settings.
8187 Default settings are taken from `org-show-hierarchy-above' and siblings.
8188 When use repeatedly in immediate succession, the remote entry will cycle
8189 through visibility
8191 children -> subtree -> folded
8193 When called with a numeric prefix arg, that arg will be passed through to
8194 `org-agenda-show-1'. For the interpretation of that argument, see the
8195 docstring of `org-agenda-show-1'."
8196 (interactive "P")
8197 (if (integerp n)
8198 (setq org-agenda-cycle-counter n)
8199 (if (not (eq last-command this-command))
8200 (setq org-agenda-cycle-counter 1)
8201 (if (equal org-agenda-cycle-counter 0)
8202 (setq org-agenda-cycle-counter 2)
8203 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8204 (if (> org-agenda-cycle-counter 3)
8205 (setq org-agenda-cycle-counter 0)))))
8206 (org-agenda-show-1 org-agenda-cycle-counter))
8208 (defun org-agenda-recenter (arg)
8209 "Display the Org-mode file which contains the item at point and recenter."
8210 (interactive "P")
8211 (let ((win (selected-window)))
8212 (org-agenda-goto t)
8213 (recenter arg)
8214 (select-window win)))
8216 (defun org-agenda-show-mouse (ev)
8217 "Display the Org-mode file which contains the item at the mouse click."
8218 (interactive "e")
8219 (mouse-set-point ev)
8220 (org-agenda-show))
8222 (defun org-agenda-check-no-diary ()
8223 "Check if the entry is a diary link and abort if yes."
8224 (if (org-get-at-bol 'org-agenda-diary-link)
8225 (org-agenda-error)))
8227 (defun org-agenda-error ()
8228 (error "Command not allowed in this line"))
8230 (defun org-agenda-tree-to-indirect-buffer (arg)
8231 "Show the subtree corresponding to the current entry in an indirect buffer.
8232 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8234 With a numerical prefix ARG, go up to this level and then take that tree.
8235 With a negative numeric ARG, go up by this number of levels.
8236 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8237 use the dedicated frame)."
8238 (interactive "P")
8239 (if current-prefix-arg
8240 (org-agenda-do-tree-to-indirect-buffer arg)
8241 (let ((agenda-buffer (buffer-name))
8242 (agenda-window (selected-window))
8243 (indirect-window
8244 (and org-last-indirect-buffer
8245 (get-buffer-window org-last-indirect-buffer))))
8246 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8247 (unless (or (eq org-indirect-buffer-display 'new-frame)
8248 (eq org-indirect-buffer-display 'dedicated-frame))
8249 (unwind-protect
8250 (unless (and indirect-window (window-live-p indirect-window))
8251 (setq indirect-window (split-window agenda-window)))
8252 (and indirect-window (select-window indirect-window))
8253 (switch-to-buffer org-last-indirect-buffer :norecord)
8254 (fit-window-to-buffer indirect-window)))
8255 (select-window (get-buffer-window agenda-buffer)))))
8257 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8258 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8259 (org-agenda-check-no-diary)
8260 (let* ((marker (or (org-get-at-bol 'org-marker)
8261 (org-agenda-error)))
8262 (buffer (marker-buffer marker))
8263 (pos (marker-position marker)))
8264 (with-current-buffer buffer
8265 (save-excursion
8266 (goto-char pos)
8267 (funcall 'org-tree-to-indirect-buffer arg)))))
8269 (defvar org-last-heading-marker (make-marker)
8270 "Marker pointing to the headline that last changed its TODO state
8271 by a remote command from the agenda.")
8273 (defun org-agenda-todo-nextset ()
8274 "Switch TODO entry to next sequence."
8275 (interactive)
8276 (org-agenda-todo 'nextset))
8278 (defun org-agenda-todo-previousset ()
8279 "Switch TODO entry to previous sequence."
8280 (interactive)
8281 (org-agenda-todo 'previousset))
8283 (defun org-agenda-todo (&optional arg)
8284 "Cycle TODO state of line at point, also in Org-mode file.
8285 This changes the line at point, all other lines in the agenda referring to
8286 the same tree node, and the headline of the tree node in the Org-mode file."
8287 (interactive "P")
8288 (org-agenda-check-no-diary)
8289 (let* ((col (current-column))
8290 (marker (or (org-get-at-bol 'org-marker)
8291 (org-agenda-error)))
8292 (buffer (marker-buffer marker))
8293 (pos (marker-position marker))
8294 (hdmarker (org-get-at-bol 'org-hd-marker))
8295 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8296 (inhibit-read-only t)
8297 org-agenda-headline-snapshot-before-repeat newhead just-one)
8298 (org-with-remote-undo buffer
8299 (with-current-buffer buffer
8300 (widen)
8301 (goto-char pos)
8302 (org-show-context 'agenda)
8303 (save-excursion
8304 (and (outline-next-heading)
8305 (org-flag-heading nil))) ; show the next heading
8306 (let ((current-prefix-arg arg))
8307 (call-interactively 'org-todo))
8308 (and (bolp) (forward-char 1))
8309 (setq newhead (org-get-heading))
8310 (when (and (org-bound-and-true-p
8311 org-agenda-headline-snapshot-before-repeat)
8312 (not (equal org-agenda-headline-snapshot-before-repeat
8313 newhead))
8314 todayp)
8315 (setq newhead org-agenda-headline-snapshot-before-repeat
8316 just-one t))
8317 (save-excursion
8318 (org-back-to-heading)
8319 (move-marker org-last-heading-marker (point))))
8320 (beginning-of-line 1)
8321 (save-excursion
8322 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8323 (org-move-to-column col))))
8325 (defun org-agenda-add-note (&optional arg)
8326 "Add a time-stamped note to the entry at point."
8327 (interactive "P")
8328 (org-agenda-check-no-diary)
8329 (let* ((marker (or (org-get-at-bol 'org-marker)
8330 (org-agenda-error)))
8331 (buffer (marker-buffer marker))
8332 (pos (marker-position marker))
8333 (hdmarker (org-get-at-bol 'org-hd-marker))
8334 (inhibit-read-only t))
8335 (with-current-buffer buffer
8336 (widen)
8337 (goto-char pos)
8338 (org-show-context 'agenda)
8339 (save-excursion
8340 (and (outline-next-heading)
8341 (org-flag-heading nil))) ; show the next heading
8342 (org-add-note))))
8344 (defun org-agenda-change-all-lines (newhead hdmarker
8345 &optional fixface just-this)
8346 "Change all lines in the agenda buffer which match HDMARKER.
8347 The new content of the line will be NEWHEAD (as modified by
8348 `org-agenda-format-item'). HDMARKER is checked with
8349 `equal' against all `org-hd-marker' text properties in the file.
8350 If FIXFACE is non-nil, the face of each item is modified according to
8351 the new TODO state.
8352 If JUST-THIS is non-nil, change just the current line, not all.
8353 If FORCE-TAGS is non nil, the car of it returns the new tags."
8354 (let* ((inhibit-read-only t)
8355 (line (org-current-line))
8356 (org-agenda-buffer (current-buffer))
8357 (thetags (with-current-buffer (marker-buffer hdmarker)
8358 (save-excursion (save-restriction (widen)
8359 (goto-char hdmarker)
8360 (org-get-tags-at)))))
8361 props m pl undone-face done-face finish new dotime cat tags)
8362 (save-excursion
8363 (goto-char (point-max))
8364 (beginning-of-line 1)
8365 (while (not finish)
8366 (setq finish (bobp))
8367 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8368 (or (not just-this) (= (org-current-line) line))
8369 (equal m hdmarker))
8370 (setq props (text-properties-at (point))
8371 dotime (org-get-at-bol 'dotime)
8372 cat (org-get-at-bol 'org-category)
8373 tags thetags
8375 (let ((org-prefix-format-compiled
8376 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8377 org-prefix-format-compiled))
8378 (extra (org-get-at-bol 'extra)))
8379 (with-current-buffer (marker-buffer hdmarker)
8380 (save-excursion
8381 (save-restriction
8382 (widen)
8383 (org-agenda-format-item extra newhead cat tags dotime)))))
8384 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8385 undone-face (org-get-at-bol 'undone-face)
8386 done-face (org-get-at-bol 'done-face))
8387 (beginning-of-line 1)
8388 (cond
8389 ((equal new "")
8390 (and (looking-at ".*\n?") (replace-match "")))
8391 ((looking-at ".*")
8392 (replace-match new t t)
8393 (beginning-of-line 1)
8394 (add-text-properties (point-at-bol) (point-at-eol) props)
8395 (when fixface
8396 (add-text-properties
8397 (point-at-bol) (point-at-eol)
8398 (list 'face
8399 (if org-last-todo-state-is-todo
8400 undone-face done-face))))
8401 (org-agenda-highlight-todo 'line)
8402 (beginning-of-line 1))
8403 (t (error "Line update did not work")))
8404 (save-restriction
8405 (narrow-to-region (point-at-bol) (point-at-eol))
8406 (org-agenda-finalize)))
8407 (beginning-of-line 0)))))
8409 (defun org-agenda-align-tags (&optional line)
8410 "Align all tags in agenda items to `org-agenda-tags-column'."
8411 (let ((inhibit-read-only t) l c)
8412 (save-excursion
8413 (goto-char (if line (point-at-bol) (point-min)))
8414 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8415 (if line (point-at-eol) nil) t)
8416 (add-text-properties
8417 (match-beginning 2) (match-end 2)
8418 (list 'face (delq nil (let ((prop (get-text-property
8419 (match-beginning 2) 'face)))
8420 (or (listp prop) (setq prop (list prop)))
8421 (if (memq 'org-tag prop)
8422 prop
8423 (cons 'org-tag prop))))))
8424 (setq l (- (match-end 2) (match-beginning 2))
8425 c (if (< org-agenda-tags-column 0)
8426 (- (abs org-agenda-tags-column) l)
8427 org-agenda-tags-column))
8428 (delete-region (match-beginning 1) (match-end 1))
8429 (goto-char (match-beginning 1))
8430 (insert (org-add-props
8431 (make-string (max 1 (- c (current-column))) ?\ )
8432 (plist-put (copy-sequence (text-properties-at (point)))
8433 'face nil))))
8434 (goto-char (point-min))
8435 (org-font-lock-add-tag-faces (point-max)))))
8437 (defun org-agenda-priority-up ()
8438 "Increase the priority of line at point, also in Org-mode file."
8439 (interactive)
8440 (org-agenda-priority 'up))
8442 (defun org-agenda-priority-down ()
8443 "Decrease the priority of line at point, also in Org-mode file."
8444 (interactive)
8445 (org-agenda-priority 'down))
8447 (defun org-agenda-priority (&optional force-direction)
8448 "Set the priority of line at point, also in Org-mode file.
8449 This changes the line at point, all other lines in the agenda referring to
8450 the same tree node, and the headline of the tree node in the Org-mode file.
8451 Called with a universal prefix arg, show the priority instead of setting it."
8452 (interactive "P")
8453 (if (equal force-direction '(4))
8454 (org-show-priority)
8455 (unless org-enable-priority-commands
8456 (error "Priority commands are disabled"))
8457 (org-agenda-check-no-diary)
8458 (let* ((marker (or (org-get-at-bol 'org-marker)
8459 (org-agenda-error)))
8460 (hdmarker (org-get-at-bol 'org-hd-marker))
8461 (buffer (marker-buffer hdmarker))
8462 (pos (marker-position hdmarker))
8463 (inhibit-read-only t)
8464 newhead)
8465 (org-with-remote-undo buffer
8466 (with-current-buffer buffer
8467 (widen)
8468 (goto-char pos)
8469 (org-show-context 'agenda)
8470 (save-excursion
8471 (and (outline-next-heading)
8472 (org-flag-heading nil))) ; show the next heading
8473 (funcall 'org-priority force-direction)
8474 (end-of-line 1)
8475 (setq newhead (org-get-heading)))
8476 (org-agenda-change-all-lines newhead hdmarker)
8477 (beginning-of-line 1)))))
8479 ;; FIXME: should fix the tags property of the agenda line.
8480 (defun org-agenda-set-tags (&optional tag onoff)
8481 "Set tags for the current headline."
8482 (interactive)
8483 (org-agenda-check-no-diary)
8484 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8485 (call-interactively 'org-change-tag-in-region)
8486 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8487 (org-agenda-error)))
8488 (buffer (marker-buffer hdmarker))
8489 (pos (marker-position hdmarker))
8490 (inhibit-read-only t)
8491 newhead)
8492 (org-with-remote-undo buffer
8493 (with-current-buffer buffer
8494 (widen)
8495 (goto-char pos)
8496 (save-excursion
8497 (org-show-context 'agenda))
8498 (save-excursion
8499 (and (outline-next-heading)
8500 (org-flag-heading nil))) ; show the next heading
8501 (goto-char pos)
8502 (if tag
8503 (org-toggle-tag tag onoff)
8504 (call-interactively 'org-set-tags))
8505 (end-of-line 1)
8506 (setq newhead (org-get-heading)))
8507 (org-agenda-change-all-lines newhead hdmarker)
8508 (beginning-of-line 1)))))
8510 (defun org-agenda-set-property ()
8511 "Set a property for the current headline."
8512 (interactive)
8513 (org-agenda-check-no-diary)
8514 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8515 (org-agenda-error)))
8516 (buffer (marker-buffer hdmarker))
8517 (pos (marker-position hdmarker))
8518 (inhibit-read-only t)
8519 newhead)
8520 (org-with-remote-undo buffer
8521 (with-current-buffer buffer
8522 (widen)
8523 (goto-char pos)
8524 (save-excursion
8525 (org-show-context 'agenda))
8526 (save-excursion
8527 (and (outline-next-heading)
8528 (org-flag-heading nil))) ; show the next heading
8529 (goto-char pos)
8530 (call-interactively 'org-set-property)))))
8532 (defun org-agenda-set-effort ()
8533 "Set the effort property for the current headline."
8534 (interactive)
8535 (org-agenda-check-no-diary)
8536 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8537 (org-agenda-error)))
8538 (buffer (marker-buffer hdmarker))
8539 (pos (marker-position hdmarker))
8540 (inhibit-read-only t)
8541 newhead)
8542 (org-with-remote-undo buffer
8543 (with-current-buffer buffer
8544 (widen)
8545 (goto-char pos)
8546 (save-excursion
8547 (org-show-context 'agenda))
8548 (save-excursion
8549 (and (outline-next-heading)
8550 (org-flag-heading nil))) ; show the next heading
8551 (goto-char pos)
8552 (call-interactively 'org-set-effort)
8553 (end-of-line 1)
8554 (setq newhead (org-get-heading)))
8555 (org-agenda-change-all-lines newhead hdmarker))))
8557 (defun org-agenda-toggle-archive-tag ()
8558 "Toggle the archive tag for the current entry."
8559 (interactive)
8560 (org-agenda-check-no-diary)
8561 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8562 (org-agenda-error)))
8563 (buffer (marker-buffer hdmarker))
8564 (pos (marker-position hdmarker))
8565 (inhibit-read-only t)
8566 newhead)
8567 (org-with-remote-undo buffer
8568 (with-current-buffer buffer
8569 (widen)
8570 (goto-char pos)
8571 (org-show-context 'agenda)
8572 (save-excursion
8573 (and (outline-next-heading)
8574 (org-flag-heading nil))) ; show the next heading
8575 (call-interactively 'org-toggle-archive-tag)
8576 (end-of-line 1)
8577 (setq newhead (org-get-heading)))
8578 (org-agenda-change-all-lines newhead hdmarker)
8579 (beginning-of-line 1))))
8581 (defun org-agenda-do-date-later (arg)
8582 (interactive "P")
8583 (cond
8584 ((or (equal arg '(16))
8585 (memq last-command
8586 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8587 (setq this-command 'org-agenda-date-later-minutes)
8588 (org-agenda-date-later-minutes 1))
8589 ((or (equal arg '(4))
8590 (memq last-command
8591 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8592 (setq this-command 'org-agenda-date-later-hours)
8593 (org-agenda-date-later-hours 1))
8595 (org-agenda-date-later (prefix-numeric-value arg)))))
8597 (defun org-agenda-do-date-earlier (arg)
8598 (interactive "P")
8599 (cond
8600 ((or (equal arg '(16))
8601 (memq last-command
8602 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8603 (setq this-command 'org-agenda-date-earlier-minutes)
8604 (org-agenda-date-earlier-minutes 1))
8605 ((or (equal arg '(4))
8606 (memq last-command
8607 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8608 (setq this-command 'org-agenda-date-earlier-hours)
8609 (org-agenda-date-earlier-hours 1))
8611 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8613 (defun org-agenda-date-later (arg &optional what)
8614 "Change the date of this item to ARG day(s) later."
8615 (interactive "p")
8616 (org-agenda-check-type t 'agenda 'timeline)
8617 (org-agenda-check-no-diary)
8618 (let* ((marker (or (org-get-at-bol 'org-marker)
8619 (org-agenda-error)))
8620 (buffer (marker-buffer marker))
8621 (pos (marker-position marker))
8622 cdate today)
8623 (org-with-remote-undo buffer
8624 (with-current-buffer buffer
8625 (widen)
8626 (goto-char pos)
8627 (if (not (org-at-timestamp-p))
8628 (error "Cannot find time stamp"))
8629 (when (and org-agenda-move-date-from-past-immediately-to-today
8630 (equal arg 1)
8631 (or (not what) (eq what 'day))
8632 (not (save-match-data (org-at-date-range-p))))
8633 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8634 cdate (calendar-absolute-from-gregorian
8635 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8636 today (org-today))
8637 (if (> today cdate)
8638 ;; immediately shift to today
8639 (setq arg (- today cdate))))
8640 (org-timestamp-change arg (or what 'day))
8641 (when (and (org-at-date-range-p)
8642 (re-search-backward org-tr-regexp-both (point-at-bol)))
8643 (let ((end org-last-changed-timestamp))
8644 (org-timestamp-change arg (or what 'day))
8645 (setq org-last-changed-timestamp
8646 (concat org-last-changed-timestamp "--" end)))))
8647 (org-agenda-show-new-time marker org-last-changed-timestamp))
8648 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8650 (defun org-agenda-date-earlier (arg &optional what)
8651 "Change the date of this item to ARG day(s) earlier."
8652 (interactive "p")
8653 (org-agenda-date-later (- arg) what))
8655 (defun org-agenda-date-later-minutes (arg)
8656 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8657 (interactive "p")
8658 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8659 (org-agenda-date-later arg 'minute))
8661 (defun org-agenda-date-earlier-minutes (arg)
8662 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8663 (interactive "p")
8664 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8665 (org-agenda-date-earlier arg 'minute))
8667 (defun org-agenda-date-later-hours (arg)
8668 "Change the time of this item, in hour steps."
8669 (interactive "p")
8670 (org-agenda-date-later arg 'hour))
8672 (defun org-agenda-date-earlier-hours (arg)
8673 "Change the time of this item, in hour steps."
8674 (interactive "p")
8675 (org-agenda-date-earlier arg 'hour))
8677 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8678 "Show new date stamp via text properties."
8679 ;; We use text properties to make this undoable
8680 (let ((inhibit-read-only t)
8681 (buffer-invisibility-spec))
8682 (setq stamp (concat " " prefix " => " stamp))
8683 (save-excursion
8684 (goto-char (point-max))
8685 (while (not (bobp))
8686 (when (equal marker (org-get-at-bol 'org-marker))
8687 (org-move-to-column (- (window-width) (length stamp)) t)
8688 (org-agenda-fix-tags-filter-overlays-at (point))
8689 (if (featurep 'xemacs)
8690 ;; Use `duplicable' property to trigger undo recording
8691 (let ((ex (make-extent nil nil))
8692 (gl (make-glyph stamp)))
8693 (set-glyph-face gl 'secondary-selection)
8694 (set-extent-properties
8695 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8696 (insert-extent ex (1- (point)) (point-at-eol)))
8697 (add-text-properties
8698 (1- (point)) (point-at-eol)
8699 (list 'display (org-add-props stamp nil
8700 'face 'secondary-selection))))
8701 (beginning-of-line 1))
8702 (beginning-of-line 0)))))
8704 (defun org-agenda-date-prompt (arg)
8705 "Change the date of this item. Date is prompted for, with default today.
8706 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8707 be used to request time specification in the time stamp."
8708 (interactive "P")
8709 (org-agenda-check-type t 'agenda 'timeline)
8710 (org-agenda-check-no-diary)
8711 (let* ((marker (or (org-get-at-bol 'org-marker)
8712 (org-agenda-error)))
8713 (buffer (marker-buffer marker))
8714 (pos (marker-position marker)))
8715 (org-with-remote-undo buffer
8716 (with-current-buffer buffer
8717 (widen)
8718 (goto-char pos)
8719 (if (not (org-at-timestamp-p t))
8720 (error "Cannot find time stamp"))
8721 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8722 (org-agenda-show-new-time marker org-last-changed-timestamp))
8723 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8725 (defun org-agenda-schedule (arg &optional time)
8726 "Schedule the item at point.
8727 ARG is passed through to `org-schedule'."
8728 (interactive "P")
8729 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8730 (org-agenda-check-no-diary)
8731 (let* ((marker (or (org-get-at-bol 'org-marker)
8732 (org-agenda-error)))
8733 (type (marker-insertion-type marker))
8734 (buffer (marker-buffer marker))
8735 (pos (marker-position marker))
8736 (org-insert-labeled-timestamps-at-point nil)
8738 (set-marker-insertion-type marker t)
8739 (org-with-remote-undo buffer
8740 (with-current-buffer buffer
8741 (widen)
8742 (goto-char pos)
8743 (setq ts (org-schedule arg time)))
8744 (org-agenda-show-new-time marker ts "S"))
8745 (message "%s" ts)))
8747 (defun org-agenda-deadline (arg &optional time)
8748 "Schedule the item at point.
8749 ARG is passed through to `org-deadline'."
8750 (interactive "P")
8751 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8752 (org-agenda-check-no-diary)
8753 (let* ((marker (or (org-get-at-bol 'org-marker)
8754 (org-agenda-error)))
8755 (buffer (marker-buffer marker))
8756 (pos (marker-position marker))
8757 (org-insert-labeled-timestamps-at-point nil)
8759 (org-with-remote-undo buffer
8760 (with-current-buffer buffer
8761 (widen)
8762 (goto-char pos)
8763 (setq ts (org-deadline arg time)))
8764 (org-agenda-show-new-time marker ts "D"))
8765 (message "%s" ts)))
8767 (defun org-agenda-clock-in (&optional arg)
8768 "Start the clock on the currently selected item."
8769 (interactive "P")
8770 (org-agenda-check-no-diary)
8771 (if (equal arg '(4))
8772 (org-clock-in arg)
8773 (let* ((marker (or (org-get-at-bol 'org-marker)
8774 (org-agenda-error)))
8775 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8776 marker))
8777 (pos (marker-position marker))
8778 newhead)
8779 (org-with-remote-undo (marker-buffer marker)
8780 (with-current-buffer (marker-buffer marker)
8781 (widen)
8782 (goto-char pos)
8783 (org-show-context 'agenda)
8784 (org-show-entry)
8785 (org-cycle-hide-drawers 'children)
8786 (org-clock-in arg)
8787 (setq newhead (org-get-heading)))
8788 (org-agenda-change-all-lines newhead hdmarker)))))
8790 (defun org-agenda-clock-out ()
8791 "Stop the currently running clock."
8792 (interactive)
8793 (unless (marker-buffer org-clock-marker)
8794 (error "No running clock"))
8795 (let ((marker (make-marker)) newhead)
8796 (org-with-remote-undo (marker-buffer org-clock-marker)
8797 (with-current-buffer (marker-buffer org-clock-marker)
8798 (save-excursion
8799 (save-restriction
8800 (widen)
8801 (goto-char org-clock-marker)
8802 (org-back-to-heading t)
8803 (move-marker marker (point))
8804 (org-clock-out)
8805 (setq newhead (org-get-heading))))))
8806 (org-agenda-change-all-lines newhead marker)
8807 (move-marker marker nil)))
8809 (defun org-agenda-clock-cancel (&optional arg)
8810 "Cancel the currently running clock."
8811 (interactive "P")
8812 (unless (marker-buffer org-clock-marker)
8813 (error "No running clock"))
8814 (org-with-remote-undo (marker-buffer org-clock-marker)
8815 (org-clock-cancel)))
8817 (defun org-agenda-clock-goto ()
8818 "Jump to the currently clocked in task within the agenda.
8819 If the currently clocked in task is not listed in the agenda
8820 buffer, display it in another window."
8821 (interactive)
8822 (let (pos)
8823 (mapc (lambda (o)
8824 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8825 (setq pos (overlay-start o))))
8826 (overlays-in (point-min) (point-max)))
8827 (cond (pos (goto-char pos))
8828 ;; If the currently clocked entry is not in the agenda
8829 ;; buffer, we visit it in another window:
8830 (org-clock-current-task
8831 (org-switch-to-buffer-other-window (org-clock-goto)))
8832 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8834 (defun org-agenda-diary-entry-in-org-file ()
8835 "Make a diary entry in the file `org-agenda-diary-file'."
8836 (let (d1 d2 char (text "") dp1 dp2)
8837 (if (equal (buffer-name) "*Calendar*")
8838 (setq d1 (calendar-cursor-to-date t)
8839 d2 (car calendar-mark-ring))
8840 (setq dp1 (get-text-property (point-at-bol) 'day))
8841 (unless dp1 (error "No date defined in current line"))
8842 (setq d1 (calendar-gregorian-from-absolute dp1)
8843 d2 (and (ignore-errors (mark))
8844 (save-excursion
8845 (goto-char (mark))
8846 (setq dp2 (get-text-property (point-at-bol) 'day)))
8847 (calendar-gregorian-from-absolute dp2))))
8848 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8849 (setq char (read-char-exclusive))
8850 (cond
8851 ((equal char ?d)
8852 (setq text (read-string "Day entry: "))
8853 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8854 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8855 ((equal char ?a)
8856 (setq d1 (list (car d1) (nth 1 d1)
8857 (read-number (format "Reference year [%d]: " (nth 2 d1))
8858 (nth 2 d1))))
8859 (setq text (read-string "Anniversary (use %d to show years): "))
8860 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8861 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8862 ((equal char ?b)
8863 (setq text (read-string "Block entry: "))
8864 (unless (and d1 d2 (not (equal d1 d2)))
8865 (error "No block of days selected"))
8866 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8867 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8868 ((equal char ?j)
8869 (org-switch-to-buffer-other-window
8870 (find-file-noselect org-agenda-diary-file))
8871 (require 'org-datetree)
8872 (org-datetree-find-date-create d1)
8873 (org-reveal t))
8874 (t (error "Invalid selection character `%c'" char)))))
8876 (defcustom org-agenda-insert-diary-strategy 'date-tree
8877 "Where in `org-agenda-diary-file' should new entries be added?
8878 Valid values:
8880 date-tree in the date tree, as child of the date
8881 top-level as top-level entries at the end of the file."
8882 :group 'org-agenda
8883 :type '(choice
8884 (const :tag "in a date tree" date-tree)
8885 (const :tag "as top level at end of file" top-level)))
8887 (defcustom org-agenda-insert-diary-extract-time nil
8888 "Non-nil means extract any time specification from the diary entry."
8889 :group 'org-agenda
8890 :version "24.1"
8891 :type 'boolean)
8893 (defcustom org-agenda-bulk-mark-char ">"
8894 "A single-character string to be used as the bulk mark."
8895 :group 'org-agenda
8896 :version "24.1"
8897 :type 'string)
8899 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8900 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8901 If TEXT is not empty, it will become the headline of the new entry, and
8902 the resulting entry will not be shown. When TEXT is empty, switch to
8903 `org-agenda-diary-file' and let the user finish the entry there."
8904 (let ((cw (current-window-configuration)))
8905 (org-switch-to-buffer-other-window
8906 (find-file-noselect org-agenda-diary-file))
8907 (widen)
8908 (goto-char (point-min))
8909 (cond
8910 ((eq type 'anniversary)
8911 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8912 (progn
8913 (or (org-at-heading-p t)
8914 (progn
8915 (outline-next-heading)
8916 (insert "* Anniversaries\n\n")
8917 (beginning-of-line -1)))))
8918 (outline-next-heading)
8919 (org-back-over-empty-lines)
8920 (backward-char 1)
8921 (insert "\n")
8922 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8923 (nth 2 d1) (car d1) (nth 1 d1) text)))
8924 ((eq type 'day)
8925 (let ((org-prefix-has-time t)
8926 (org-agenda-time-leading-zero t)
8927 fmt time time2)
8928 (if org-agenda-insert-diary-extract-time
8929 ;; Use org-agenda-format-item to parse text for a time-range and
8930 ;; remove it. FIXME: This is a hack, we should refactor
8931 ;; that function to make time extraction available separately
8932 (setq fmt (org-agenda-format-item nil text nil nil t)
8933 time (get-text-property 0 'time fmt)
8934 time2 (if (> (length time) 0)
8935 ;; split-string removes trailing ...... if
8936 ;; no end time given. First space
8937 ;; separates time from date.
8938 (concat " " (car (split-string time "\\.")))
8939 nil)
8940 text (get-text-property 0 'txt fmt)))
8941 (if (eq org-agenda-insert-diary-strategy 'top-level)
8942 (org-agenda-insert-diary-as-top-level text)
8943 (require 'org-datetree)
8944 (org-datetree-find-date-create d1)
8945 (org-agenda-insert-diary-make-new-entry text))
8946 (org-insert-time-stamp (org-time-from-absolute
8947 (calendar-absolute-from-gregorian d1))
8948 nil nil nil nil time2))
8949 (end-of-line 0))
8950 ((eq type 'block)
8951 (if (> (calendar-absolute-from-gregorian d1)
8952 (calendar-absolute-from-gregorian d2))
8953 (setq d1 (prog1 d2 (setq d2 d1))))
8954 (if (eq org-agenda-insert-diary-strategy 'top-level)
8955 (org-agenda-insert-diary-as-top-level text)
8956 (require 'org-datetree)
8957 (org-datetree-find-date-create d1)
8958 (org-agenda-insert-diary-make-new-entry text))
8959 (org-insert-time-stamp (org-time-from-absolute
8960 (calendar-absolute-from-gregorian d1)))
8961 (insert "--")
8962 (org-insert-time-stamp (org-time-from-absolute
8963 (calendar-absolute-from-gregorian d2)))
8964 (end-of-line 0)))
8965 (if (string-match "\\S-" text)
8966 (progn
8967 (set-window-configuration cw)
8968 (message "%s entry added to %s"
8969 (capitalize (symbol-name type))
8970 (abbreviate-file-name org-agenda-diary-file)))
8971 (org-reveal t)
8972 (message "Please finish entry here"))))
8974 (defun org-agenda-insert-diary-as-top-level (text)
8975 "Make new entry as a top-level entry at the end of the file.
8976 Add TEXT as headline, and position the cursor in the second line so that
8977 a timestamp can be added there."
8978 (widen)
8979 (goto-char (point-max))
8980 (or (bolp) (insert "\n"))
8981 (insert "* " text "\n")
8982 (if org-adapt-indentation (org-indent-to-column 2)))
8984 (defun org-agenda-insert-diary-make-new-entry (text)
8985 "Make new entry as last child of current entry.
8986 Add TEXT as headline, and position the cursor in the second line so that
8987 a timestamp can be added there."
8988 (let ((org-show-following-heading t)
8989 (org-show-siblings t)
8990 (org-show-hierarchy-above t)
8991 (org-show-entry-below t)
8992 col)
8993 (outline-next-heading)
8994 (org-back-over-empty-lines)
8995 (or (looking-at "[ \t]*$")
8996 (progn (insert "\n") (backward-char 1)))
8997 (org-insert-heading nil t)
8998 (org-do-demote)
8999 (setq col (current-column))
9000 (insert text "\n")
9001 (if org-adapt-indentation (org-indent-to-column col))
9002 (let ((org-show-following-heading t)
9003 (org-show-siblings t)
9004 (org-show-hierarchy-above t)
9005 (org-show-entry-below t))
9006 (org-show-context))))
9008 (defun org-agenda-diary-entry ()
9009 "Make a diary entry, like the `i' command from the calendar.
9010 All the standard commands work: block, weekly etc.
9011 When `org-agenda-diary-file' points to a file,
9012 `org-agenda-diary-entry-in-org-file' is called instead to create
9013 entries in that Org-mode file."
9014 (interactive)
9015 (if (not (eq org-agenda-diary-file 'diary-file))
9016 (org-agenda-diary-entry-in-org-file)
9017 (require 'diary-lib)
9018 (let* ((char (progn
9019 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9020 (read-char-exclusive)))
9021 (cmd (cdr (assoc char
9022 '((?d . insert-diary-entry)
9023 (?w . insert-weekly-diary-entry)
9024 (?m . insert-monthly-diary-entry)
9025 (?y . insert-yearly-diary-entry)
9026 (?a . insert-anniversary-diary-entry)
9027 (?b . insert-block-diary-entry)
9028 (?c . insert-cyclic-diary-entry)))))
9029 (oldf (symbol-function 'calendar-cursor-to-date))
9030 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9031 (point (point))
9032 (mark (or (mark t) (point))))
9033 (unless cmd
9034 (error "No command associated with <%c>" char))
9035 (unless (and (get-text-property point 'day)
9036 (or (not (equal ?b char))
9037 (get-text-property mark 'day)))
9038 (error "Don't know which date to use for diary entry"))
9039 ;; We implement this by hacking the `calendar-cursor-to-date' function
9040 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9041 (let ((calendar-mark-ring
9042 (list (calendar-gregorian-from-absolute
9043 (or (get-text-property mark 'day)
9044 (get-text-property point 'day))))))
9045 (unwind-protect
9046 (progn
9047 (fset 'calendar-cursor-to-date
9048 (lambda (&optional error dummy)
9049 (calendar-gregorian-from-absolute
9050 (get-text-property point 'day))))
9051 (call-interactively cmd))
9052 (fset 'calendar-cursor-to-date oldf))))))
9054 (defun org-agenda-execute-calendar-command (cmd)
9055 "Execute a calendar command from the agenda with date from cursor."
9056 (org-agenda-check-type t 'agenda 'timeline)
9057 (require 'diary-lib)
9058 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9059 (error "Don't know which date to use for the calendar command"))
9060 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9061 (point (point))
9062 (date (calendar-gregorian-from-absolute
9063 (get-text-property point 'day)))
9064 ;; the following 2 vars are needed in the calendar
9065 (displayed-month (car date))
9066 (displayed-year (nth 2 date)))
9067 (unwind-protect
9068 (progn
9069 (fset 'calendar-cursor-to-date
9070 (lambda (&optional error dummy)
9071 (calendar-gregorian-from-absolute
9072 (get-text-property point 'day))))
9073 (call-interactively cmd))
9074 (fset 'calendar-cursor-to-date oldf))))
9076 (defun org-agenda-phases-of-moon ()
9077 "Display the phases of the moon for the 3 months around the cursor date."
9078 (interactive)
9079 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9081 (defun org-agenda-holidays ()
9082 "Display the holidays for the 3 months around the cursor date."
9083 (interactive)
9084 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9086 (defvar calendar-longitude) ; defined in calendar.el
9087 (defvar calendar-latitude) ; defined in calendar.el
9088 (defvar calendar-location-name) ; defined in calendar.el
9090 (defun org-agenda-sunrise-sunset (arg)
9091 "Display sunrise and sunset for the cursor date.
9092 Latitude and longitude can be specified with the variables
9093 `calendar-latitude' and `calendar-longitude'. When called with prefix
9094 argument, latitude and longitude will be prompted for."
9095 (interactive "P")
9096 (require 'solar)
9097 (let ((calendar-longitude (if arg nil calendar-longitude))
9098 (calendar-latitude (if arg nil calendar-latitude))
9099 (calendar-location-name
9100 (if arg "the given coordinates" calendar-location-name)))
9101 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9103 (defun org-agenda-goto-calendar ()
9104 "Open the Emacs calendar with the date at the cursor."
9105 (interactive)
9106 (org-agenda-check-type t 'agenda 'timeline)
9107 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9108 (error "Don't know which date to open in calendar")))
9109 (date (calendar-gregorian-from-absolute day))
9110 (calendar-move-hook nil)
9111 (calendar-view-holidays-initially-flag nil)
9112 (calendar-view-diary-initially-flag nil))
9113 (calendar)
9114 (calendar-goto-date date)))
9116 ;;;###autoload
9117 (defun org-calendar-goto-agenda ()
9118 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9119 This is a command that has to be installed in `calendar-mode-map'."
9120 (interactive)
9121 (org-agenda-list nil (calendar-absolute-from-gregorian
9122 (calendar-cursor-to-date))
9123 nil))
9125 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9126 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9127 This is a command that has to be installed in `calendar-mode-map'.
9129 \(fn)" t nil)
9131 (defun org-agenda-convert-date ()
9132 (interactive)
9133 (org-agenda-check-type t 'agenda 'timeline)
9134 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9135 date s)
9136 (unless day
9137 (error "Don't know which date to convert"))
9138 (setq date (calendar-gregorian-from-absolute day))
9139 (setq s (concat
9140 "Gregorian: " (calendar-date-string date) "\n"
9141 "ISO: " (calendar-iso-date-string date) "\n"
9142 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9143 "Julian: " (calendar-julian-date-string date) "\n"
9144 "Astron. JD: " (calendar-astro-date-string date)
9145 " (Julian date number at noon UTC)\n"
9146 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9147 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9148 "French: " (calendar-french-date-string date) "\n"
9149 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9150 "Mayan: " (calendar-mayan-date-string date) "\n"
9151 "Coptic: " (calendar-coptic-date-string date) "\n"
9152 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9153 "Persian: " (calendar-persian-date-string date) "\n"
9154 "Chinese: " (calendar-chinese-date-string date) "\n"))
9155 (with-output-to-temp-buffer "*Dates*"
9156 (princ s))
9157 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9159 ;;; Bulk commands
9161 (defun org-agenda-bulk-marked-p ()
9162 (eq (get-char-property (point-at-bol) 'type)
9163 'org-marked-entry-overlay))
9165 (defun org-agenda-bulk-mark (&optional arg)
9166 "Mark the entry at point for future bulk action."
9167 (interactive "p")
9168 (dotimes (i (or arg 1))
9169 (unless (org-get-at-bol 'org-agenda-diary-link)
9170 (let* ((m (org-get-at-bol 'org-hd-marker))
9172 (unless (org-agenda-bulk-marked-p)
9173 (unless m (error "Nothing to mark at point"))
9174 (push m org-agenda-bulk-marked-entries)
9175 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9176 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9177 (org-get-todo-face "TODO")
9178 'evaporate)
9179 (overlay-put ov 'type 'org-marked-entry-overlay))
9180 (beginning-of-line 2)
9181 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9182 (beginning-of-line 2))
9183 (message "%d entries marked for bulk action"
9184 (length org-agenda-bulk-marked-entries))))))
9186 (defun org-agenda-bulk-mark-all ()
9187 "Mark all entries for future agenda bulk action."
9188 (interactive)
9189 (org-agenda-bulk-mark-regexp "."))
9191 (defun org-agenda-bulk-mark-regexp (regexp)
9192 "Mark entries matching REGEXP for future agenda bulk action."
9193 (interactive "sMark entries matching regexp: ")
9194 (let ((entries-marked 0))
9195 (save-excursion
9196 (goto-char (point-min))
9197 (goto-char (next-single-property-change (point) 'txt))
9198 (while (re-search-forward regexp nil t)
9199 (when (string-match regexp (get-text-property (point) 'txt))
9200 (setq entries-marked (1+ entries-marked))
9201 (call-interactively 'org-agenda-bulk-mark))))
9202 (if (not entries-marked)
9203 (message "No entry matching this regexp."))))
9205 (defun org-agenda-bulk-unmark (&optional arg)
9206 "Unmark the entry at point for future bulk action."
9207 (interactive "P")
9208 (if arg
9209 (org-agenda-bulk-unmark-all)
9210 (cond ((org-agenda-bulk-marked-p)
9211 (org-agenda-bulk-remove-overlays
9212 (point-at-bol) (+ 2 (point-at-bol)))
9213 (setq org-agenda-bulk-marked-entries
9214 (delete (org-get-at-bol 'org-hd-marker)
9215 org-agenda-bulk-marked-entries))
9216 (beginning-of-line 2)
9217 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9218 (beginning-of-line 2))
9219 (message "%d entries left marked for bulk action"
9220 (length org-agenda-bulk-marked-entries)))
9221 (t (message "No entry to unmark here")))))
9223 (defun org-agenda-bulk-toggle ()
9224 "Toggle marking the entry at point for bulk action."
9225 (interactive)
9226 (if (org-agenda-bulk-marked-p)
9227 (org-agenda-bulk-unmark)
9228 (org-agenda-bulk-mark)))
9230 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9231 "Remove the mark overlays between BEG and END in the agenda buffer.
9232 BEG and END default to the buffer limits.
9234 This only removes the overlays, it does not remove the markers
9235 from the list in `org-agenda-bulk-marked-entries'."
9236 (interactive)
9237 (mapc (lambda (ov)
9238 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9239 (delete-overlay ov)))
9240 (overlays-in (or beg (point-min)) (or end (point-max)))))
9242 (defun org-agenda-bulk-unmark-all ()
9243 "Remove all marks in the agenda buffer.
9244 This will remove the markers and the overlays."
9245 (interactive)
9246 (if (null org-agenda-bulk-marked-entries)
9247 (message "No entry to unmark")
9248 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9249 (setq org-agenda-bulk-marked-entries nil)
9250 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9252 (defcustom org-agenda-persistent-marks nil
9253 "Non-nil means marked items will stay marked after a bulk action.
9254 You can toggle this interactively by typing `p' when prompted for a
9255 bulk action."
9256 :group 'org-agenda
9257 :version "24.1"
9258 :type 'boolean)
9260 (defun org-agenda-bulk-action (&optional arg)
9261 "Execute an remote-editing action on all marked entries.
9262 The prefix arg is passed through to the command if possible."
9263 (interactive "P")
9264 ;; Make sure we have markers, and only valid ones
9265 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9266 (mapc
9267 (lambda (m)
9268 (unless (and (markerp m)
9269 (marker-buffer m)
9270 (buffer-live-p (marker-buffer m))
9271 (marker-position m))
9272 (error "Marker %s for bulk command is invalid" m)))
9273 org-agenda-bulk-marked-entries)
9275 ;; Prompt for the bulk command
9276 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9277 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9278 "[S]catter [f]unction "
9279 (when org-agenda-bulk-custom-functions
9280 (concat " Custom: ["
9281 (mapconcat (lambda(f) (char-to-string (car f)))
9282 org-agenda-bulk-custom-functions "")
9283 "]"))))
9284 (catch 'exit
9285 (let* ((action (read-char-exclusive))
9286 (org-log-refile (if org-log-refile 'time nil))
9287 (entries (reverse org-agenda-bulk-marked-entries))
9288 (org-overriding-default-time
9289 (if (get-text-property (point) 'org-agenda-date-header)
9290 (org-get-cursor-date)))
9291 redo-at-end
9292 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9293 (cond
9294 ((equal action ?p)
9295 (let ((org-agenda-persistent-marks
9296 (not org-agenda-persistent-marks)))
9297 (org-agenda-bulk-action)
9298 (throw 'exit nil)))
9300 ((equal action ?$)
9301 (setq cmd '(org-agenda-archive)))
9303 ((equal action ?A)
9304 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9306 ((member action '(?r ?w))
9307 (setq rfloc (org-refile-get-location
9308 "Refile to"
9309 (marker-buffer (car entries))
9310 org-refile-allow-creating-parent-nodes))
9311 (if (nth 3 rfloc)
9312 (setcar (nthcdr 3 rfloc)
9313 (move-marker (make-marker) (nth 3 rfloc)
9314 (or (get-file-buffer (nth 1 rfloc))
9315 (find-buffer-visiting (nth 1 rfloc))
9316 (error "This should not happen")))))
9318 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9319 redo-at-end t))
9321 ((equal action ?t)
9322 (setq state (org-icompleting-read
9323 "Todo state: "
9324 (with-current-buffer (marker-buffer (car entries))
9325 (mapcar 'list org-todo-keywords-1))))
9326 (setq cmd `(let ((org-inhibit-blocking t)
9327 (org-inhibit-logging 'note))
9328 (org-agenda-todo ,state))))
9330 ((memq action '(?- ?+))
9331 (setq tag (org-icompleting-read
9332 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9333 (with-current-buffer (marker-buffer (car entries))
9334 (delq nil
9335 (mapcar (lambda (x)
9336 (if (stringp (car x)) x)) org-tag-alist)))))
9337 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9339 ((memq action '(?s ?d))
9340 (let* ((time
9341 (unless arg
9342 (org-read-date
9343 nil nil nil
9344 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9345 org-overriding-default-time)))
9346 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9347 (setq cmd `(eval '(,c1 arg ,time)))))
9349 ((equal action ?S)
9350 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9351 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9352 (let ((days (read-number
9353 (format "Scatter tasks across how many %sdays: "
9354 (if arg "week" "")) 7)))
9355 (setq cmd
9356 `(let ((distance (1+ (random ,days))))
9357 (if arg
9358 (let ((dist distance)
9359 (day-of-week
9360 (calendar-day-of-week
9361 (calendar-gregorian-from-absolute (org-today)))))
9362 (dotimes (i (1+ dist))
9363 (while (member day-of-week org-agenda-weekend-days)
9364 (incf distance)
9365 (incf day-of-week)
9366 (if (= day-of-week 7)
9367 (setq day-of-week 0)))
9368 (incf day-of-week)
9369 (if (= day-of-week 7)
9370 (setq day-of-week 0)))))
9371 ;; silently fail when try to replan a sexp entry
9372 (condition-case nil
9373 (let* ((date (calendar-gregorian-from-absolute
9374 (+ (org-today) distance)))
9375 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9376 (nth 2 date))))
9377 (org-agenda-schedule nil time))
9378 (error nil)))))))
9380 ((assoc action org-agenda-bulk-custom-functions)
9381 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9382 redo-at-end t))
9384 ((equal action ?f)
9385 (setq cmd (list (intern
9386 (org-icompleting-read "Function: "
9387 obarray 'fboundp t nil nil)))))
9389 (t (error "Invalid bulk action")))
9391 ;; Sort the markers, to make sure that parents are handled before children
9392 (setq entries (sort entries
9393 (lambda (a b)
9394 (cond
9395 ((equal (marker-buffer a) (marker-buffer b))
9396 (< (marker-position a) (marker-position b)))
9398 (string< (buffer-name (marker-buffer a))
9399 (buffer-name (marker-buffer b))))))))
9401 ;; Now loop over all markers and apply cmd
9402 (while (setq e (pop entries))
9403 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9404 (if (not pos)
9405 (progn (message "Skipping removed entry at %s" e)
9406 (setq cntskip (1+ cntskip)))
9407 (goto-char pos)
9408 (let (org-loop-over-headlines-in-active-region)
9409 (eval cmd))
9410 (setq cnt (1+ cnt))))
9411 (when redo-at-end (org-agenda-redo))
9412 (unless org-agenda-persistent-marks
9413 (org-agenda-bulk-unmark-all))
9414 (message "Acted on %d entries%s%s"
9416 (if (= cntskip 0)
9418 (format ", skipped %d (disappeared before their turn)"
9419 cntskip))
9420 (if (not org-agenda-persistent-marks)
9421 "" " (kept marked)"))))))
9423 (defun org-agenda-capture ()
9424 "Call `org-capture' with the date at point."
9425 (interactive)
9426 (if (not (eq major-mode 'org-agenda-mode))
9427 (error "You cannot do this outside of agenda buffers")
9428 (let ((org-overriding-default-time
9429 (org-get-cursor-date)))
9430 (call-interactively 'org-capture))))
9432 ;;; Flagging notes
9434 (defun org-agenda-show-the-flagging-note ()
9435 "Display the flagging note in the other window.
9436 When called a second time in direct sequence, offer to remove the FLAGGING
9437 tag and (if present) the flagging note."
9438 (interactive)
9439 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9440 (win (selected-window))
9441 note heading newhead)
9442 (unless hdmarker
9443 (error "No linked entry at point"))
9444 (if (and (eq this-command last-command)
9445 (y-or-n-p "Unflag and remove any flagging note? "))
9446 (progn
9447 (org-agenda-remove-flag hdmarker)
9448 (let ((win (get-buffer-window "*Flagging Note*")))
9449 (and win (delete-window win)))
9450 (message "Entry unflagged"))
9451 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9452 (unless note
9453 (error "No flagging note"))
9454 (org-kill-new note)
9455 (org-switch-to-buffer-other-window "*Flagging Note*")
9456 (erase-buffer)
9457 (insert note)
9458 (goto-char (point-min))
9459 (while (re-search-forward "\\\\n" nil t)
9460 (replace-match "\n" t t))
9461 (goto-char (point-min))
9462 (select-window win)
9463 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9465 (defun org-agenda-remove-flag (marker)
9466 "Remove the FLAGGED tag and any flagging note in the entry."
9467 (let (newhead)
9468 (org-with-point-at marker
9469 (org-toggle-tag "FLAGGED" 'off)
9470 (org-entry-delete nil "THEFLAGGINGNOTE")
9471 (setq newhead (org-get-heading)))
9472 (org-agenda-change-all-lines newhead marker)
9473 (message "Entry unflagged")))
9475 (defun org-agenda-get-any-marker (&optional pos)
9476 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9477 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9479 ;;; Appointment reminders
9481 (defvar appt-time-msg-list) ; defined in appt.el
9483 ;;;###autoload
9484 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9485 "Activate appointments found in `org-agenda-files'.
9486 With a \\[universal-argument] prefix, refresh the list of
9487 appointments.
9489 If FILTER is t, interactively prompt the user for a regular
9490 expression, and filter out entries that don't match it.
9492 If FILTER is a string, use this string as a regular expression
9493 for filtering entries out.
9495 If FILTER is a function, filter out entries against which
9496 calling the function returns nil. This function takes one
9497 argument: an entry from `org-agenda-get-day-entries'.
9499 FILTER can also be an alist with the car of each cell being
9500 either 'headline or 'category. For example:
9502 '((headline \"IMPORTANT\")
9503 (category \"Work\"))
9505 will only add headlines containing IMPORTANT or headlines
9506 belonging to the \"Work\" category.
9508 ARGS are symbols indicating what kind of entries to consider.
9509 By default `org-agenda-to-appt' will use :deadline, :scheduled
9510 and :timestamp entries. See the docstring of `org-diary' for
9511 details and examples.
9513 If an entry as a APPT_WARNTIME property, its value will be used
9514 to override `appt-message-warning-time'."
9515 (interactive "P")
9516 (if refresh (setq appt-time-msg-list nil))
9517 (if (eq filter t)
9518 (setq filter (read-from-minibuffer "Regexp filter: ")))
9519 (let* ((cnt 0) ; count added events
9520 (scope (or args '(:deadline :scheduled :timestamp)))
9521 (org-agenda-new-buffers nil)
9522 (org-deadline-warning-days 0)
9523 ;; Do not use `org-today' here because appt only takes
9524 ;; time and without date as argument, so it may pass wrong
9525 ;; information otherwise
9526 (today (org-date-to-gregorian
9527 (time-to-days (current-time))))
9528 (org-agenda-restrict nil)
9529 (files (org-agenda-files 'unrestricted)) entries file
9530 (org-agenda-buffer nil))
9531 ;; Get all entries which may contain an appt
9532 (org-agenda-prepare-buffers files)
9533 (while (setq file (pop files))
9534 (setq entries
9535 (delq nil
9536 (append entries
9537 (apply 'org-agenda-get-day-entries
9538 file today scope)))))
9539 ;; Map thru entries and find if we should filter them out
9540 (mapc
9541 (lambda(x)
9542 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9543 (cat (get-text-property 1 'org-category x))
9544 (tod (get-text-property 1 'time-of-day x))
9545 (ok (or (null filter)
9546 (and (stringp filter) (string-match filter evt))
9547 (and (functionp filter) (funcall filter x))
9548 (and (listp filter)
9549 (let ((cat-filter (cadr (assoc 'category filter)))
9550 (evt-filter (cadr (assoc 'headline filter))))
9551 (or (and (stringp cat-filter)
9552 (string-match cat-filter cat))
9553 (and (stringp evt-filter)
9554 (string-match evt-filter evt)))))))
9555 (wrn (get-text-property 1 'warntime x)))
9556 ;; FIXME: Shall we remove text-properties for the appt text?
9557 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9558 (when (and ok tod)
9559 (setq tod (concat "00" (number-to-string tod))
9560 tod (when (string-match
9561 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9562 (concat (match-string 1 tod) ":"
9563 (match-string 2 tod))))
9564 (if (version< emacs-version "23.3")
9565 (appt-add tod evt)
9566 (appt-add tod evt wrn))
9567 (setq cnt (1+ cnt))))) entries)
9568 (org-release-buffers org-agenda-new-buffers)
9569 (if (eq cnt 0)
9570 (message "No event to add")
9571 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9573 (autoload 'org-agenda-to-appt "org-agenda" "\
9574 Activate appointments found in `org-agenda-files'.
9575 With a \\[universal-argument] prefix, refresh the list of
9576 appointments.
9578 If FILTER is t, interactively prompt the user for a regular
9579 expression, and filter out entries that don't match it.
9581 If FILTER is a string, use this string as a regular expression
9582 for filtering entries out.
9584 If FILTER is a function, filter out entries against which
9585 calling the function returns nil. This function takes one
9586 argument: an entry from `org-agenda-get-day-entries'.
9588 FILTER can also be an alist with the car of each cell being
9589 either 'headline or 'category. For example:
9591 '((headline \"IMPORTANT\")
9592 (category \"Work\"))
9594 will only add headlines containing IMPORTANT or headlines
9595 belonging to the \"Work\" category.
9597 ARGS are symbols indicating what kind of entries to consider.
9598 By default `org-agenda-to-appt' will use :deadline, :scheduled
9599 and :timestamp entries. See the docstring of `org-diary' for
9600 details and examples.
9602 If an entry as a APPT_WARNTIME property, its value will be used
9603 to override `appt-message-warning-time'.
9605 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9607 (defun org-agenda-todayp (date)
9608 "Does DATE mean today, when considering `org-extend-today-until'?"
9609 (let ((today (org-today))
9610 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9611 date)))
9612 (eq date today)))
9614 (defun org-agenda-todo-yesterday (&optional arg)
9615 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9616 (interactive "P")
9617 (let* ((hour (third (decode-time
9618 (org-current-time))))
9619 (org-extend-today-until (1+ hour)))
9620 (org-agenda-todo arg)))
9622 (provide 'org-agenda)
9624 ;;; org-agenda.el ends here