org.el (org-insert-heading, org-insert-todo-heading): C-u C-u inserts at the end...
[org-mode.git] / lisp / org-agenda.el
blobfce98f69ef66946e37ec95995030eb89d720e61b
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, the symbol `pre-scheduled',
831 or a number which will then give the number of days before the actual
832 deadline when the prewarnings should resume. The symbol `pre-scheduled'
833 eliminates the deadline prewarning only prior to the scheduled date.
834 This can be used in a workflow where the first showing of the deadline will
835 trigger you to schedule it, and then you don't want to be reminded of it
836 because you will take care of it on the day when scheduled."
837 :group 'org-agenda-skip
838 :group 'org-agenda-daily/weekly
839 :version "24.1"
840 :type '(choice
841 (const :tag "Always show prewarning" nil)
842 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
843 (const :tag "Remove prewarning if entry is scheduled" t)
844 (integer :tag "Restart prewarning N days before deadline")))
846 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
847 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
848 When non-nil, after the search for timestamps has matched once in an
849 entry, the rest of the entry will not be searched."
850 :group 'org-agenda-skip
851 :type 'boolean)
853 (defcustom org-agenda-skip-timestamp-if-done nil
854 "Non-nil means don't select item by timestamp or -range if it is DONE."
855 :group 'org-agenda-skip
856 :group 'org-agenda-daily/weekly
857 :type 'boolean)
859 (defcustom org-agenda-dim-blocked-tasks t
860 "Non-nil means dim blocked tasks in the agenda display.
861 This causes some overhead during agenda construction, but if you
862 have turned on `org-enforce-todo-dependencies',
863 `org-enforce-todo-checkbox-dependencies', or any other blocking
864 mechanism, this will create useful feedback in the agenda.
866 Instead of t, this variable can also have the value `invisible'.
867 Then blocked tasks will be invisible and only become visible when
868 they become unblocked. An exemption to this behavior is when a task is
869 blocked because of unchecked checkboxes below it. Since checkboxes do
870 not show up in the agenda views, making this task invisible you remove any
871 trace from agenda views that there is something to do. Therefore, a task
872 that is blocked because of checkboxes will never be made invisible, it
873 will only be dimmed."
874 :group 'org-agenda-daily/weekly
875 :group 'org-agenda-todo-list
876 :type '(choice
877 (const :tag "Do not dim" nil)
878 (const :tag "Dim to a gray face" t)
879 (const :tag "Make invisible" invisible)))
881 (defcustom org-timeline-show-empty-dates 3
882 "Non-nil means `org-timeline' also shows dates without an entry.
883 When nil, only the days which actually have entries are shown.
884 When t, all days between the first and the last date are shown.
885 When an integer, show also empty dates, but if there is a gap of more than
886 N days, just insert a special line indicating the size of the gap."
887 :group 'org-agenda-skip
888 :type '(choice
889 (const :tag "None" nil)
890 (const :tag "All" t)
891 (integer :tag "at most")))
893 (defgroup org-agenda-startup nil
894 "Options concerning initial settings in the Agenda in Org Mode."
895 :tag "Org Agenda Startup"
896 :group 'org-agenda)
898 (defcustom org-agenda-menu-show-matcher t
899 "Non-nil means show the match string in the agenda dispatcher menu.
900 When nil, the matcher string is not shown, but is put into the help-echo
901 property so than moving the mouse over the command shows it.
902 Setting it to nil is good if matcher strings are very long and/or if
903 you want to use two-columns display (see `org-agenda-menu-two-columns')."
904 :group 'org-agenda
905 :version "24.1"
906 :type 'boolean)
908 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
910 (defcustom org-agenda-menu-two-columns nil
911 "Non-nil means, use two columns to show custom commands in the dispatcher.
912 If you use this, you probably want to set `org-agenda-menu-show-matcher'
913 to nil."
914 :group 'org-agenda
915 :version "24.1"
916 :type 'boolean)
918 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
919 (defcustom org-agenda-finalize-hook nil
920 "Hook run just before displaying an agenda buffer.
921 The buffer is still writable when the hook is called.
923 You can modify some of the buffer substrings but you should be
924 extra careful not to modify the text properties of the agenda
925 headlines as the agenda display heavily relies on them."
926 :group 'org-agenda-startup
927 :type 'hook)
929 (defcustom org-agenda-mouse-1-follows-link nil
930 "Non-nil means mouse-1 on a link will follow the link in the agenda.
931 A longer mouse click will still set point. Does not work on XEmacs.
932 Needs to be set before org.el is loaded."
933 :group 'org-agenda-startup
934 :type 'boolean)
936 (defcustom org-agenda-start-with-follow-mode nil
937 "The initial value of follow mode in a newly created agenda window."
938 :group 'org-agenda-startup
939 :type 'boolean)
941 (defcustom org-agenda-follow-indirect nil
942 "Non-nil means `org-agenda-follow-mode' displays only the
943 current item's tree, in an indirect buffer."
944 :group 'org-agenda
945 :version "24.1"
946 :type 'boolean)
948 (defcustom org-agenda-show-outline-path t
949 "Non-nil means show outline path in echo area after line motion."
950 :group 'org-agenda-startup
951 :type 'boolean)
953 (defcustom org-agenda-start-with-entry-text-mode nil
954 "The initial value of entry-text-mode in a newly created agenda window."
955 :group 'org-agenda-startup
956 :type 'boolean)
958 (defcustom org-agenda-entry-text-maxlines 5
959 "Number of text lines to be added when `E' is pressed in the agenda.
961 Note that this variable only used during agenda display. Add add entry text
962 when exporting the agenda, configure the variable
963 `org-agenda-add-entry-ext-maxlines'."
964 :group 'org-agenda
965 :type 'integer)
967 (defcustom org-agenda-entry-text-exclude-regexps nil
968 "List of regular expressions to clean up entry text.
969 The complete matches of all regular expressions in this list will be
970 removed from entry text before it is shown in the agenda."
971 :group 'org-agenda
972 :type '(repeat (regexp)))
974 (defvar org-agenda-entry-text-cleanup-hook nil
975 "Hook that is run after basic cleanup of entry text to be shown in agenda.
976 This cleanup is done in a temporary buffer, so the function may inspect and
977 change the entire buffer.
978 Some default stuff like drawers and scheduling/deadline dates will already
979 have been removed when this is called, as will any matches for regular
980 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
982 (defvar org-agenda-include-inactive-timestamps nil
983 "Non-nil means include inactive time stamps in agenda and timeline.
984 Dynamically scoped.")
986 (defgroup org-agenda-windows nil
987 "Options concerning the windows used by the Agenda in Org Mode."
988 :tag "Org Agenda Windows"
989 :group 'org-agenda)
991 (defcustom org-agenda-window-setup 'reorganize-frame
992 "How the agenda buffer should be displayed.
993 Possible values for this option are:
995 current-window Show agenda in the current window, keeping all other windows.
996 other-window Use `switch-to-buffer-other-window' to display agenda.
997 reorganize-frame Show only two windows on the current frame, the current
998 window and the agenda.
999 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1000 Also, when exiting the agenda, kill that frame.
1001 See also the variable `org-agenda-restore-windows-after-quit'."
1002 :group 'org-agenda-windows
1003 :type '(choice
1004 (const current-window)
1005 (const other-frame)
1006 (const other-window)
1007 (const reorganize-frame)))
1009 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1010 "The min and max height of the agenda window as a fraction of frame height.
1011 The value of the variable is a cons cell with two numbers between 0 and 1.
1012 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1013 :group 'org-agenda-windows
1014 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1016 (defcustom org-agenda-restore-windows-after-quit nil
1017 "Non-nil means restore window configuration upon exiting agenda.
1018 Before the window configuration is changed for displaying the agenda,
1019 the current status is recorded. When the agenda is exited with
1020 `q' or `x' and this option is set, the old state is restored. If
1021 `org-agenda-window-setup' is `other-frame', the value of this
1022 option will be ignored."
1023 :group 'org-agenda-windows
1024 :type 'boolean)
1026 (defcustom org-agenda-ndays nil
1027 "Number of days to include in overview display.
1028 Should be 1 or 7.
1029 Obsolete, see `org-agenda-span'."
1030 :group 'org-agenda-daily/weekly
1031 :type 'integer)
1033 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1035 (defcustom org-agenda-span 'week
1036 "Number of days to include in overview display.
1037 Can be day, week, month, year, or any number of days.
1038 Custom commands can set this variable in the options section."
1039 :group 'org-agenda-daily/weekly
1040 :type '(choice (const :tag "Day" day)
1041 (const :tag "Week" week)
1042 (const :tag "Month" month)
1043 (const :tag "Year" year)
1044 (integer :tag "Custom")))
1046 (defcustom org-agenda-start-on-weekday 1
1047 "Non-nil means start the overview always on the specified weekday.
1048 0 denotes Sunday, 1 denotes Monday etc.
1049 When nil, always start on the current day.
1050 Custom commands can set this variable in the options section."
1051 :group 'org-agenda-daily/weekly
1052 :type '(choice (const :tag "Today" nil)
1053 (integer :tag "Weekday No.")))
1055 (defcustom org-agenda-show-all-dates t
1056 "Non-nil means `org-agenda' shows every day in the selected range.
1057 When nil, only the days which actually have entries are shown."
1058 :group 'org-agenda-daily/weekly
1059 :type 'boolean)
1061 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1062 "Format string for displaying dates in the agenda.
1063 Used by the daily/weekly agenda and by the timeline. This should be
1064 a format string understood by `format-time-string', or a function returning
1065 the formatted date as a string. The function must take a single argument,
1066 a calendar-style date list like (month day year)."
1067 :group 'org-agenda-daily/weekly
1068 :type '(choice
1069 (string :tag "Format string")
1070 (function :tag "Function")))
1072 (defun org-agenda-format-date-aligned (date)
1073 "Format a date string for display in the daily/weekly agenda, or timeline.
1074 This function makes sure that dates are aligned for easy reading."
1075 (require 'cal-iso)
1076 (let* ((dayname (calendar-day-name date))
1077 (day (cadr date))
1078 (day-of-week (calendar-day-of-week date))
1079 (month (car date))
1080 (monthname (calendar-month-name month))
1081 (year (nth 2 date))
1082 (iso-week (org-days-to-iso-week
1083 (calendar-absolute-from-gregorian date)))
1084 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1085 (1- year))
1086 ((and (= month 12) (<= iso-week 1))
1087 (1+ year))
1088 (t year)))
1089 (weekstring (if (= day-of-week 1)
1090 (format " W%02d" iso-week)
1091 "")))
1092 (format "%-10s %2d %s %4d%s"
1093 dayname day monthname year weekstring)))
1095 (defcustom org-agenda-time-leading-zero nil
1096 "Non-nil means use leading zero for military times in agenda.
1097 For example, 9:30am would become 09:30 rather than 9:30."
1098 :group 'org-agenda-daily/weekly
1099 :version "24.1"
1100 :type 'boolean)
1102 (defcustom org-agenda-timegrid-use-ampm nil
1103 "When set, show AM/PM style timestamps on the timegrid."
1104 :group 'org-agenda
1105 :version "24.1"
1106 :type 'boolean)
1108 (defun org-agenda-time-of-day-to-ampm (time)
1109 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1110 (let* ((hour-number (string-to-number (substring time 0 -3)))
1111 (minute (substring time -2))
1112 (ampm "am"))
1113 (cond
1114 ((equal hour-number 12)
1115 (setq ampm "pm"))
1116 ((> hour-number 12)
1117 (setq ampm "pm")
1118 (setq hour-number (- hour-number 12))))
1119 (concat
1120 (if org-agenda-time-leading-zero
1121 (format "%02d" hour-number)
1122 (format "%02s" (number-to-string hour-number)))
1123 ":" minute ampm)))
1125 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1126 "Conditionally convert TIME to AM/PM format
1127 based on `org-agenda-timegrid-use-ampm'"
1128 (if org-agenda-timegrid-use-ampm
1129 (org-agenda-time-of-day-to-ampm time)
1130 time))
1132 (defcustom org-agenda-weekend-days '(6 0)
1133 "Which days are weekend?
1134 These days get the special face `org-agenda-date-weekend' in the agenda
1135 and timeline buffers."
1136 :group 'org-agenda-daily/weekly
1137 :type '(set :greedy t
1138 (const :tag "Monday" 1)
1139 (const :tag "Tuesday" 2)
1140 (const :tag "Wednesday" 3)
1141 (const :tag "Thursday" 4)
1142 (const :tag "Friday" 5)
1143 (const :tag "Saturday" 6)
1144 (const :tag "Sunday" 0)))
1146 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1147 "Non-nil means jump to today when moving a past date forward in time.
1148 When using S-right in the agenda to move a a date forward, and the date
1149 stamp currently points to the past, the first key press will move it
1150 to today. WHen nil, just move one day forward even if the date stays
1151 in the past."
1152 :group 'org-agenda-daily/weekly
1153 :version "24.1"
1154 :type 'boolean)
1156 (defcustom org-agenda-include-diary nil
1157 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1158 Custom commands can set this variable in the options section."
1159 :group 'org-agenda-daily/weekly
1160 :type 'boolean)
1162 (defcustom org-agenda-include-deadlines t
1163 "If non-nil, include entries within their deadline warning period.
1164 Custom commands can set this variable in the options section."
1165 :group 'org-agenda-daily/weekly
1166 :version "24.1"
1167 :type 'boolean)
1169 (defcustom org-agenda-repeating-timestamp-show-all t
1170 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1171 When set to a list of strings, only show occurrences of repeating
1172 stamps for these TODO keywords. When nil, only one occurrence is
1173 shown, either today or the nearest into the future."
1174 :group 'org-agenda-daily/weekly
1175 :type '(choice
1176 (const :tag "Show repeating stamps" t)
1177 (repeat :tag "Show repeating stamps for these TODO keywords"
1178 (string :tag "TODO Keyword"))
1179 (const :tag "Don't show repeating stamps" nil)))
1181 (defcustom org-scheduled-past-days 10000
1182 "No. of days to continue listing scheduled items that are not marked DONE.
1183 When an item is scheduled on a date, it shows up in the agenda on this
1184 day and will be listed until it is marked done for the number of days
1185 given here."
1186 :group 'org-agenda-daily/weekly
1187 :type 'integer)
1189 (defcustom org-agenda-log-mode-items '(closed clock)
1190 "List of items that should be shown in agenda log mode.
1191 This list may contain the following symbols:
1193 closed Show entries that have been closed on that day.
1194 clock Show entries that have received clocked time on that day.
1195 state Show all logged state changes.
1196 Note that instead of changing this variable, you can also press `C-u l' in
1197 the agenda to display all available LOG items temporarily."
1198 :group 'org-agenda-daily/weekly
1199 :type '(set :greedy t (const closed) (const clock) (const state)))
1201 (defcustom org-agenda-clock-consistency-checks
1202 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1203 :gap-ok-around ("4:00")
1204 :default-face ((:background "DarkRed") (:foreground "white"))
1205 :overlap-face nil :gap-face nil :no-end-time-face nil
1206 :long-face nil :short-face nil)
1207 "This is a property list, with the following keys:
1209 :max-duration Mark clocking chunks that are longer than this time.
1210 This is a time string like \"HH:MM\", or the number
1211 of minutes as an integer.
1213 :min-duration Mark clocking chunks that are shorter that this.
1214 This is a time string like \"HH:MM\", or the number
1215 of minutes as an integer.
1217 :max-gap Mark gaps between clocking chunks that are longer than
1218 this duration. A number of minutes, or a string
1219 like \"HH:MM\".
1221 :gap-ok-around List of times during the day which are usually not working
1222 times. When a gap is detected, but the gap contains any
1223 of these times, the gap is *not* reported. For example,
1224 if this is (\"4:00\" \"13:00\") then gaps that contain
1225 4:00 in the morning (i.e. the night) and 13:00
1226 (i.e. a typical lunch time) do not cause a warning.
1227 You should have at least one time during the night in this
1228 list, or otherwise the first task each morning will trigger
1229 a warning because it follows a long gap.
1231 Furthermore, the following properties can be used to define faces for
1232 issue display.
1234 :default-face the default face, if the specific face is undefined
1235 :overlap-face face for overlapping clocks
1236 :gap-face face for gaps between clocks
1237 :no-end-time-face face for incomplete clocks
1238 :long-face face for clock intervals that are too long
1239 :short-face face for clock intervals that are too short"
1240 :group 'org-agenda-daily/weekly
1241 :group 'org-clock
1242 :version "24.1"
1243 :type 'plist)
1245 (defcustom org-agenda-log-mode-add-notes t
1246 "Non-nil means add first line of notes to log entries in agenda views.
1247 If a log item like a state change or a clock entry is associated with
1248 notes, the first line of these notes will be added to the entry in the
1249 agenda display."
1250 :group 'org-agenda-daily/weekly
1251 :type 'boolean)
1253 (defcustom org-agenda-start-with-log-mode nil
1254 "The initial value of log-mode in a newly created agenda window.
1255 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1256 explanations on the possible values."
1257 :group 'org-agenda-startup
1258 :group 'org-agenda-daily/weekly
1259 :type '(choice (const :tag "Don't show log items" nil)
1260 (const :tag "Show only log items" 'only)
1261 (const :tag "Show all possible log items" 'clockcheck)
1262 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1263 (choice (const :tag "Show closed log items" 'closed)
1264 (const :tag "Show clocked log items" 'clock)
1265 (const :tag "Show all logged state changes" 'state)))))
1267 (defcustom org-agenda-start-with-clockreport-mode nil
1268 "The initial value of clockreport-mode in a newly created agenda window."
1269 :group 'org-agenda-startup
1270 :group 'org-agenda-daily/weekly
1271 :type 'boolean)
1273 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1274 "Property list with parameters for the clocktable in clockreport mode.
1275 This is the display mode that shows a clock table in the daily/weekly
1276 agenda, the properties for this dynamic block can be set here.
1277 The usual clocktable parameters are allowed here, but you cannot set
1278 the properties :name, :tstart, :tend, :block, and :scope - these will
1279 be overwritten to make sure the content accurately reflects the
1280 current display in the agenda."
1281 :group 'org-agenda-daily/weekly
1282 :type 'plist)
1284 (defcustom org-agenda-search-view-always-boolean nil
1285 "Non-nil means the search string is interpreted as individual parts.
1287 The search string for search view can either be interpreted as a phrase,
1288 or as a list of snippets that define a boolean search for a number of
1289 strings.
1291 When this is non-nil, the string will be split on whitespace, and each
1292 snippet will be searched individually, and all must match in order to
1293 select an entry. A snippet is then a single string of non-white
1294 characters, or a string in double quotes, or a regexp in {} braces.
1295 If a snippet is preceded by \"-\", the snippet must *not* match.
1296 \"+\" is syntactic sugar for positive selection. Each snippet may
1297 be found as a full word or a partial word, but see the variable
1298 `org-agenda-search-view-force-full-words'.
1300 When this is nil, search will look for the entire search phrase as one,
1301 with each space character matching any amount of whitespace, including
1302 line breaks.
1304 Even when this is nil, you can still switch to Boolean search dynamically
1305 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1306 is a regexp marked with braces like \"{abc}\", this will also switch to
1307 boolean search."
1308 :group 'org-agenda-search-view
1309 :version "24.1"
1310 :type 'boolean)
1312 (if (fboundp 'defvaralias)
1313 (defvaralias 'org-agenda-search-view-search-words-only
1314 'org-agenda-search-view-always-boolean))
1316 (defcustom org-agenda-search-view-force-full-words nil
1317 "Non-nil means, search words must be matches as complete words.
1318 When nil, they may also match part of a word."
1319 :group 'org-agenda-search-view
1320 :version "24.1"
1321 :type 'boolean)
1323 (defgroup org-agenda-time-grid nil
1324 "Options concerning the time grid in the Org-mode Agenda."
1325 :tag "Org Agenda Time Grid"
1326 :group 'org-agenda)
1328 (defcustom org-agenda-search-headline-for-time t
1329 "Non-nil means search headline for a time-of-day.
1330 If the headline contains a time-of-day in one format or another, it will
1331 be used to sort the entry into the time sequence of items for a day.
1332 Some people have time stamps in the headline that refer to the creation
1333 time or so, and then this produces an unwanted side effect. If this is
1334 the case for your, use this variable to turn off searching the headline
1335 for a time."
1336 :group 'org-agenda-time-grid
1337 :type 'boolean)
1339 (defcustom org-agenda-use-time-grid t
1340 "Non-nil means show a time grid in the agenda schedule.
1341 A time grid is a set of lines for specific times (like every two hours between
1342 8:00 and 20:00). The items scheduled for a day at specific times are
1343 sorted in between these lines.
1344 For details about when the grid will be shown, and what it will look like, see
1345 the variable `org-agenda-time-grid'."
1346 :group 'org-agenda-time-grid
1347 :type 'boolean)
1349 (defcustom org-agenda-time-grid
1350 '((daily today require-timed)
1351 "----------------"
1352 (800 1000 1200 1400 1600 1800 2000))
1354 "The settings for time grid for agenda display.
1355 This is a list of three items. The first item is again a list. It contains
1356 symbols specifying conditions when the grid should be displayed:
1358 daily if the agenda shows a single day
1359 weekly if the agenda shows an entire week
1360 today show grid on current date, independent of daily/weekly display
1361 require-timed show grid only if at least one item has a time specification
1363 The second item is a string which will be placed behind the grid time.
1365 The third item is a list of integers, indicating the times that should have
1366 a grid line."
1367 :group 'org-agenda-time-grid
1368 :type
1369 '(list
1370 (set :greedy t :tag "Grid Display Options"
1371 (const :tag "Show grid in single day agenda display" daily)
1372 (const :tag "Show grid in weekly agenda display" weekly)
1373 (const :tag "Always show grid for today" today)
1374 (const :tag "Show grid only if any timed entries are present"
1375 require-timed)
1376 (const :tag "Skip grid times already present in an entry"
1377 remove-match))
1378 (string :tag "Grid String")
1379 (repeat :tag "Grid Times" (integer :tag "Time"))))
1381 (defcustom org-agenda-show-current-time-in-grid t
1382 "Non-nil means show the current time in the time grid."
1383 :group 'org-agenda-time-grid
1384 :version "24.1"
1385 :type 'boolean)
1387 (defcustom org-agenda-current-time-string
1388 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1389 "The string for the current time marker in the agenda."
1390 :group 'org-agenda-time-grid
1391 :version "24.1"
1392 :type 'string)
1394 (defgroup org-agenda-sorting nil
1395 "Options concerning sorting in the Org-mode Agenda."
1396 :tag "Org Agenda Sorting"
1397 :group 'org-agenda)
1399 (defcustom org-agenda-sorting-strategy
1400 '((agenda habit-down time-up priority-down category-keep)
1401 (todo priority-down category-keep)
1402 (tags priority-down category-keep)
1403 (search category-keep))
1404 "Sorting structure for the agenda items of a single day.
1405 This is a list of symbols which will be used in sequence to determine
1406 if an entry should be listed before another entry. The following
1407 symbols are recognized:
1409 time-up Put entries with time-of-day indications first, early first
1410 time-down Put entries with time-of-day indications first, late first
1411 category-keep Keep the default order of categories, corresponding to the
1412 sequence in `org-agenda-files'.
1413 category-up Sort alphabetically by category, A-Z.
1414 category-down Sort alphabetically by category, Z-A.
1415 tag-up Sort alphabetically by last tag, A-Z.
1416 tag-down Sort alphabetically by last tag, Z-A.
1417 priority-up Sort numerically by priority, high priority last.
1418 priority-down Sort numerically by priority, high priority first.
1419 todo-state-up Sort by todo state, tasks that are done last.
1420 todo-state-down Sort by todo state, tasks that are done first.
1421 effort-up Sort numerically by estimated effort, high effort last.
1422 effort-down Sort numerically by estimated effort, high effort first.
1423 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1424 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1425 habit-up Put entries that are habits first
1426 habit-down Put entries that are habits last
1427 alpha-up Sort headlines alphabetically
1428 alpha-down Sort headlines alphabetically, reversed
1430 The different possibilities will be tried in sequence, and testing stops
1431 if one comparison returns a \"not-equal\". For example, the default
1432 '(time-up category-keep priority-down)
1433 means: Pull out all entries having a specified time of day and sort them,
1434 in order to make a time schedule for the current day the first thing in the
1435 agenda listing for the day. Of the entries without a time indication, keep
1436 the grouped in categories, don't sort the categories, but keep them in
1437 the sequence given in `org-agenda-files'. Within each category sort by
1438 priority.
1440 Leaving out `category-keep' would mean that items will be sorted across
1441 categories by priority.
1443 Instead of a single list, this can also be a set of list for specific
1444 contents, with a context symbol in the car of the list, any of
1445 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1447 Custom commands can bind this variable in the options section."
1448 :group 'org-agenda-sorting
1449 :type `(choice
1450 (repeat :tag "General" ,org-sorting-choice)
1451 (list :tag "Individually"
1452 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1453 (repeat ,org-sorting-choice))
1454 (cons (const :tag "Strategy for TODO lists" todo)
1455 (repeat ,org-sorting-choice))
1456 (cons (const :tag "Strategy for Tags matches" tags)
1457 (repeat ,org-sorting-choice))
1458 (cons (const :tag "Strategy for search matches" search)
1459 (repeat ,org-sorting-choice)))))
1461 (defcustom org-agenda-cmp-user-defined nil
1462 "A function to define the comparison `user-defined'.
1463 This function must receive two arguments, agenda entry a and b.
1464 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1465 the user comparison, return nil.
1466 When this is defined, you can make `user-defined-up' and `user-defined-down'
1467 part of an agenda sorting strategy."
1468 :group 'org-agenda-sorting
1469 :type 'symbol)
1471 (defcustom org-sort-agenda-notime-is-late t
1472 "Non-nil means items without time are considered late.
1473 This is only relevant for sorting. When t, items which have no explicit
1474 time like 15:30 will be considered as 99:01, i.e. later than any items which
1475 do have a time. When nil, the default time is before 0:00. You can use this
1476 option to decide if the schedule for today should come before or after timeless
1477 agenda entries."
1478 :group 'org-agenda-sorting
1479 :type 'boolean)
1481 (defcustom org-sort-agenda-noeffort-is-high t
1482 "Non-nil means items without effort estimate are sorted as high effort.
1483 This also applies when filtering an agenda view with respect to the
1484 < or > effort operator. Then, tasks with no effort defined will be treated
1485 as tasks with high effort.
1486 When nil, such items are sorted as 0 minutes effort."
1487 :group 'org-agenda-sorting
1488 :type 'boolean)
1490 (defgroup org-agenda-line-format nil
1491 "Options concerning the entry prefix in the Org-mode agenda display."
1492 :tag "Org Agenda Line Format"
1493 :group 'org-agenda)
1495 (defcustom org-agenda-prefix-format
1496 '((agenda . " %i %-12:c%?-12t% s")
1497 (timeline . " % s")
1498 (todo . " %i %-12:c")
1499 (tags . " %i %-12:c")
1500 (search . " %i %-12:c"))
1501 "Format specifications for the prefix of items in the agenda views.
1502 An alist with five entries, each for the different agenda types. The
1503 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1504 The values are format strings.
1506 This format works similar to a printf format, with the following meaning:
1508 %c the category of the item, \"Diary\" for entries from the diary,
1509 or as given by the CATEGORY keyword or derived from the file name
1510 %e the effort required by the item
1511 %l the level of the item (insert X space(s) if item is of level X)
1512 %i the icon category of the item, see `org-agenda-category-icon-alist'
1513 %T the last tag of the item (ignore inherited tags, which come first)
1514 %t the HH:MM time-of-day specification if one applies to the entry
1515 %s Scheduling/Deadline information, a short string
1516 %(expression) Eval EXPRESSION and replace the control string
1517 by the result
1519 All specifiers work basically like the standard `%s' of printf, but may
1520 contain two additional characters: a question mark just after the `%'
1521 and a whitespace/punctuation character just before the final letter.
1523 If the first character after `%' is a question mark, the entire field
1524 will only be included if the corresponding value applies to the current
1525 entry. This is useful for fields which should have fixed width when
1526 present, but zero width when absent. For example, \"%?-12t\" will
1527 result in a 12 character time field if a time of the day is specified,
1528 but will completely disappear in entries which do not contain a time.
1530 If there is punctuation or whitespace character just before the final
1531 format letter, this character will be appended to the field value if
1532 the value is not empty. For example, the format \"%-12:c\" leads to
1533 \"Diary: \" if the category is \"Diary\". If the category were be
1534 empty, no additional colon would be inserted.
1536 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1537 which means:
1539 - Indent the line with two space characters
1540 - Give the category a 12 chars wide field, padded with whitespace on
1541 the right (because of `-'). Append a colon if there is a category
1542 (because of `:').
1543 - If there is a time-of-day, put it into a 12 chars wide field. If no
1544 time, don't put in an empty field, just skip it (because of '?').
1545 - Finally, put the scheduling information.
1547 See also the variables `org-agenda-remove-times-when-in-prefix' and
1548 `org-agenda-remove-tags'.
1550 Custom commands can set this variable in the options section."
1551 :type '(choice
1552 (string :tag "General format")
1553 (list :greedy t :tag "View dependent"
1554 (cons (const agenda) (string :tag "Format"))
1555 (cons (const timeline) (string :tag "Format"))
1556 (cons (const todo) (string :tag "Format"))
1557 (cons (const tags) (string :tag "Format"))
1558 (cons (const search) (string :tag "Format"))))
1559 :group 'org-agenda-line-format)
1561 (defvar org-prefix-format-compiled nil
1562 "The compiled prefix format and associated variables.
1563 This is a list where first element is a list of variable bindings, and second
1564 element is the compiled format expression. See the variable
1565 `org-agenda-prefix-format'.")
1567 (defcustom org-agenda-todo-keyword-format "%-1s"
1568 "Format for the TODO keyword in agenda lines.
1569 Set this to something like \"%-12s\" if you want all TODO keywords
1570 to occupy a fixed space in the agenda display."
1571 :group 'org-agenda-line-format
1572 :type 'string)
1574 (defcustom org-agenda-diary-sexp-prefix nil
1575 "A regexp that matches part of a diary sexp entry
1576 which should be treated as scheduling/deadline information in
1577 `org-agenda'.
1579 For example, you can use this to extract the `diary-remind-message' from
1580 `diary-remind' entries."
1581 :group 'org-agenda-line-format
1582 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1584 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1585 "Text preceding timerange entries in the agenda view.
1586 This is a list with two strings. The first applies when the range
1587 is entirely on one day. The second applies if the range spans several days.
1588 The strings may have two \"%d\" format specifiers which will be filled
1589 with the sequence number of the days, and the total number of days in the
1590 range, respectively."
1591 :group 'org-agenda-line-format
1592 :type '(list
1593 (string :tag "Deadline today ")
1594 (choice :tag "Deadline relative"
1595 (string :tag "Format string")
1596 (function))))
1598 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1599 "Text preceding scheduled items in the agenda view.
1600 This is a list with two strings. The first applies when the item is
1601 scheduled on the current day. The second applies when it has been scheduled
1602 previously, it may contain a %d indicating that this is the nth time that
1603 this item is scheduled, due to automatic rescheduling of unfinished items
1604 for the following day. So this number is one larger than the number of days
1605 that passed since this item was scheduled first."
1606 :group 'org-agenda-line-format
1607 :type '(list
1608 (string :tag "Scheduled today ")
1609 (string :tag "Scheduled previously")))
1611 (defcustom org-agenda-inactive-leader "["
1612 "Text preceding item pulled into the agenda by inactive time stamps.
1613 These entries are added to the agenda when pressing \"[\"."
1614 :group 'org-agenda-line-format
1615 :version "24.1"
1616 :type '(list
1617 (string :tag "Scheduled today ")
1618 (string :tag "Scheduled previously")))
1620 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1621 "Text preceding deadline items in the agenda view.
1622 This is a list with two strings. The first applies when the item has its
1623 deadline on the current day. The second applies when it is in the past or
1624 in the future, it may contain %d to capture how many days away the deadline
1625 is (was)."
1626 :group 'org-agenda-line-format
1627 :type '(list
1628 (string :tag "Deadline today ")
1629 (choice :tag "Deadline relative"
1630 (string :tag "Format string")
1631 (function))))
1633 (defcustom org-agenda-remove-times-when-in-prefix t
1634 "Non-nil means remove duplicate time specifications in agenda items.
1635 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1636 time-of-day specification in a headline or diary entry is extracted and
1637 placed into the prefix. If this option is non-nil, the original specification
1638 \(a timestamp or -range, or just a plain time(range) specification like
1639 11:30-4pm) will be removed for agenda display. This makes the agenda less
1640 cluttered.
1641 The option can be t or nil. It may also be the symbol `beg', indicating
1642 that the time should only be removed when it is located at the beginning of
1643 the headline/diary entry."
1644 :group 'org-agenda-line-format
1645 :type '(choice
1646 (const :tag "Always" t)
1647 (const :tag "Never" nil)
1648 (const :tag "When at beginning of entry" beg)))
1650 (defcustom org-agenda-remove-timeranges-from-blocks nil
1651 "Non-nil means remove time ranges specifications in agenda
1652 items that span on several days."
1653 :group 'org-agenda-line-format
1654 :version "24.1"
1655 :type 'boolean)
1657 (defcustom org-agenda-default-appointment-duration nil
1658 "Default duration for appointments that only have a starting time.
1659 When nil, no duration is specified in such cases.
1660 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1661 :group 'org-agenda-line-format
1662 :type '(choice
1663 (integer :tag "Minutes")
1664 (const :tag "No default duration")))
1666 (defcustom org-agenda-show-inherited-tags t
1667 "Non-nil means show inherited tags in each agenda line."
1668 :group 'org-agenda-line-format
1669 :type 'boolean)
1671 (defcustom org-agenda-hide-tags-regexp nil
1672 "Regular expression used to filter away specific tags in agenda views.
1673 This means that these tags will be present, but not be shown in the agenda
1674 line. Secondary filtering will still work on the hidden tags.
1675 Nil means don't hide any tags."
1676 :group 'org-agenda-line-format
1677 :type '(choice
1678 (const :tag "Hide none" nil)
1679 (string :tag "Regexp ")))
1681 (defcustom org-agenda-remove-tags nil
1682 "Non-nil means remove the tags from the headline copy in the agenda.
1683 When this is the symbol `prefix', only remove tags when
1684 `org-agenda-prefix-format' contains a `%T' specifier."
1685 :group 'org-agenda-line-format
1686 :type '(choice
1687 (const :tag "Always" t)
1688 (const :tag "Never" nil)
1689 (const :tag "When prefix format contains %T" prefix)))
1691 (if (fboundp 'defvaralias)
1692 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1693 'org-agenda-remove-tags))
1695 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1696 "Shift tags in agenda items to this column.
1697 If this number is positive, it specifies the column. If it is negative,
1698 it means that the tags should be flushright to that column. For example,
1699 -80 works well for a normal 80 character screen."
1700 :group 'org-agenda-line-format
1701 :type 'integer)
1703 (if (fboundp 'defvaralias)
1704 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1706 (defcustom org-agenda-fontify-priorities 'cookies
1707 "Non-nil means highlight low and high priorities in agenda.
1708 When t, the highest priority entries are bold, lowest priority italic.
1709 However, settings in `org-priority-faces' will overrule these faces.
1710 When this variable is the symbol `cookies', only fontify the
1711 cookies, not the entire task.
1712 This may also be an association list of priority faces, whose
1713 keys are the character values of `org-highest-priority',
1714 `org-default-priority', and `org-lowest-priority' (the default values
1715 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1716 color as a string, or a list like `(:background \"Red\")'.
1717 If it is a color, the variable `org-faces-easy-properties'
1718 determines if it is a foreground or a background color."
1719 :group 'org-agenda-line-format
1720 :type '(choice
1721 (const :tag "Never" nil)
1722 (const :tag "Defaults" t)
1723 (const :tag "Cookies only" cookies)
1724 (repeat :tag "Specify"
1725 (list (character :tag "Priority" :value ?A)
1726 (choice :tag "Face "
1727 (string :tag "Color")
1728 (sexp :tag "Face"))))))
1730 (defcustom org-agenda-day-face-function nil
1731 "Function called to determine what face should be used to display a day.
1732 The only argument passed to that function is the day. It should
1733 returns a face, or nil if does not want to specify a face and let
1734 the normal rules apply."
1735 :group 'org-agenda-line-format
1736 :version "24.1"
1737 :type 'function)
1739 (defcustom org-agenda-category-icon-alist nil
1740 "Alist of category icon to be displayed in agenda views.
1742 Each entry should have the following format:
1744 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1746 Where CATEGORY-REGEXP is a regexp matching the categories where
1747 the icon should be displayed.
1748 FILE-OR-DATA either a file path or a string containing image data.
1750 The other fields can be omitted safely if not needed:
1751 TYPE indicates the image type.
1752 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1753 image data.
1754 PROPS are additional image attributes to assign to the image,
1755 like, e.g. `:ascent center'.
1757 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1759 If you want to set the display properties yourself, just put a
1760 list as second element:
1762 (CATEGORY-REGEXP (MY PROPERTY LIST))
1764 For example, to display a 16px horizontal space for Emacs
1765 category, you can use:
1767 (\"Emacs\" '(space . (:width (16))))"
1768 :group 'org-agenda-line-format
1769 :version "24.1"
1770 :type '(alist :key-type (string :tag "Regexp matching category")
1771 :value-type (choice (list :tag "Icon"
1772 (string :tag "File or data")
1773 (symbol :tag "Type")
1774 (boolean :tag "Data?")
1775 (repeat :tag "Extra image properties" :inline t symbol))
1776 (list :tag "Display properties" sexp))))
1778 (defgroup org-agenda-column-view nil
1779 "Options concerning column view in the agenda."
1780 :tag "Org Agenda Column View"
1781 :group 'org-agenda)
1783 (defcustom org-agenda-columns-show-summaries t
1784 "Non-nil means show summaries for columns displayed in the agenda view."
1785 :group 'org-agenda-column-view
1786 :type 'boolean)
1788 (defcustom org-agenda-columns-compute-summary-properties t
1789 "Non-nil means recompute all summary properties before column view.
1790 When column view in the agenda is listing properties that have a summary
1791 operator, it can go to all relevant buffers and recompute the summaries
1792 there. This can mean overhead for the agenda column view, but is necessary
1793 to have thing up to date.
1794 As a special case, a CLOCKSUM property also makes sure that the clock
1795 computations are current."
1796 :group 'org-agenda-column-view
1797 :type 'boolean)
1799 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1800 "Non-nil means the duration of an appointment will add to day effort.
1801 The property to which appointment durations will be added is the one given
1802 in the option `org-effort-property'. If an appointment does not have
1803 an end time, `org-agenda-default-appointment-duration' will be used. If that
1804 is not set, an appointment without end time will not contribute to the time
1805 estimate."
1806 :group 'org-agenda-column-view
1807 :type 'boolean)
1809 (defcustom org-agenda-auto-exclude-function nil
1810 "A function called with a tag to decide if it is filtered on '/ RET'.
1811 The sole argument to the function, which is called once for each
1812 possible tag, is a string giving the name of the tag. The
1813 function should return either nil if the tag should be included
1814 as normal, or \"-<TAG>\" to exclude the tag.
1815 Note that for the purpose of tag filtering, only the lower-case version of
1816 all tags will be considered, so that this function will only ever see
1817 the lower-case version of all tags."
1818 :group 'org-agenda
1819 :type 'function)
1821 (defcustom org-agenda-bulk-custom-functions nil
1822 "Alist of characters and custom functions for bulk actions.
1823 For example, this value makes those two functions available:
1825 '((?R set-category)
1826 (?C bulk-cut))
1828 With selected entries in an agenda buffer, `B R' will call
1829 the custom function `set-category' on the selected entries.
1830 Note that functions in this alist don't need to be quoted."
1831 :type 'alist
1832 :version "24.1"
1833 :group 'org-agenda)
1835 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1836 "Execute BODY with point at location given by `org-hd-marker' property.
1837 If STRING is non-nil, the text property will be fetched from position 0
1838 in that string. If STRING is nil, it will be fetched from the beginning
1839 of the current line."
1840 (org-with-gensyms (marker)
1841 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1842 'org-hd-marker ,string)))
1843 (with-current-buffer (marker-buffer ,marker)
1844 (save-excursion
1845 (goto-char ,marker)
1846 ,@body)))))
1847 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1849 (defun org-add-agenda-custom-command (entry)
1850 "Replace or add a command in `org-agenda-custom-commands'.
1851 This is mostly for hacking and trying a new command - once the command
1852 works you probably want to add it to `org-agenda-custom-commands' for good."
1853 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1854 (if ass
1855 (setcdr ass (cdr entry))
1856 (push entry org-agenda-custom-commands))))
1858 ;;; Define the org-agenda-mode
1860 (defvar org-agenda-mode-map (make-sparse-keymap)
1861 "Keymap for `org-agenda-mode'.")
1862 (if (fboundp 'defvaralias)
1863 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1865 (defvar org-agenda-menu) ; defined later in this file.
1866 (defvar org-agenda-restrict nil) ; defined later in this file.
1867 (defvar org-agenda-follow-mode nil)
1868 (defvar org-agenda-entry-text-mode nil)
1869 (defvar org-agenda-clockreport-mode nil)
1870 (defvar org-agenda-show-log nil)
1871 (defvar org-agenda-redo-command nil)
1872 (defvar org-agenda-query-string nil)
1873 (defvar org-agenda-mode-hook nil
1874 "Hook run after `org-agenda-mode' is turned on.
1875 The buffer is still writable when this hook is called.")
1876 (defvar org-agenda-type nil)
1877 (defvar org-agenda-force-single-file nil)
1878 (defvar org-agenda-bulk-marked-entries nil
1879 "List of markers that refer to marked entries in the agenda.")
1881 ;;; Multiple agenda buffers support
1883 (defcustom org-agenda-sticky nil
1884 "Non-nil means agenda q key will bury agenda buffers.
1885 Agenda commands will then show existing buffer instead of generating new ones.
1886 When nil, `q' will kill the single agenda buffer."
1887 :group 'org-agenda
1888 :version "24.3"
1889 :type 'boolean)
1892 ;;;###autoload
1893 (defun org-toggle-sticky-agenda (&optional arg)
1894 "Toggle `org-agenda-sticky'."
1895 (interactive "P")
1896 (let ((new-value (if arg
1897 (> (prefix-numeric-value arg) 0)
1898 (not org-agenda-sticky))))
1899 (if (equal new-value org-agenda-sticky)
1900 (and (org-called-interactively-p 'interactive)
1901 (message "Sticky agenda was already %s"
1902 (if org-agenda-sticky "enabled" "disabled")))
1903 (setq org-agenda-sticky new-value)
1904 (org-agenda-kill-all-agenda-buffers)
1905 (and (org-called-interactively-p 'interactive)
1906 (message "Sticky agenda was %s"
1907 (if org-agenda-sticky "enabled" "disabled"))))))
1909 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1910 Toggle `org-agenda-sticky'.
1912 \(fn &optional ARG)" t nil)
1914 (defvar org-agenda-buffer nil
1915 "Agenda buffer currently being generated.")
1917 (defvar org-agenda-last-prefix-arg nil)
1918 (defvar org-agenda-this-buffer-name nil)
1919 (defvar org-agenda-doing-sticky-redo nil)
1920 (defvar org-agenda-this-buffer-is-sticky nil)
1922 (defconst org-agenda-local-vars
1923 '(org-agenda-this-buffer-name
1924 org-agenda-undo-list
1925 org-agenda-pending-undo-list
1926 org-agenda-follow-mode
1927 org-agenda-entry-text-mode
1928 org-agenda-clockreport-mode
1929 org-agenda-show-log
1930 org-agenda-redo-command
1931 org-agenda-query-string
1932 org-agenda-type
1933 org-agenda-bulk-marked-entries
1934 org-agenda-undo-has-started-in
1935 org-agenda-info
1936 org-agenda-tag-filter-overlays
1937 org-agenda-cat-filter-overlays
1938 org-agenda-pre-window-conf
1939 org-agenda-columns-active
1940 org-agenda-tag-filter
1941 org-agenda-category-filter
1942 org-agenda-markers
1943 org-agenda-last-search-view-search-was-boolean
1944 org-agenda-filtered-by-category
1945 org-agenda-filter-form
1946 org-agenda-show-window
1947 org-agenda-cycle-counter
1948 org-agenda-last-prefix-arg)
1949 "Variables that must be local in agenda buffers to allow multiple buffers.")
1951 (defun org-agenda-mode ()
1952 "Mode for time-sorted view on action items in Org-mode files.
1954 The following commands are available:
1956 \\{org-agenda-mode-map}"
1957 (interactive)
1958 (cond (org-agenda-doing-sticky-redo
1959 ;; Refreshing sticky agenda-buffer
1961 ;; Preserve the value of `org-agenda-local-vars' variables,
1962 ;; while letting `kill-all-local-variables' kill the rest
1963 (let ((save (buffer-local-variables)))
1964 (kill-all-local-variables)
1965 (mapc 'make-local-variable org-agenda-local-vars)
1966 (dolist (elem save)
1967 (let ((var (car elem))
1968 (val (cdr elem)))
1969 (when (and val
1970 (member var org-agenda-local-vars))
1971 (set var val)))))
1972 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1973 (org-agenda-sticky
1974 ;; Creating a sticky Agenda buffer for the first time
1975 (kill-all-local-variables)
1976 (mapc 'make-local-variable org-agenda-local-vars)
1977 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1979 ;; Creating a non-sticky agenda buffer
1980 (kill-all-local-variables)
1981 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1982 (setq org-agenda-undo-list nil
1983 org-agenda-pending-undo-list nil
1984 org-agenda-bulk-marked-entries nil)
1985 (setq major-mode 'org-agenda-mode)
1986 ;; Keep global-font-lock-mode from turning on font-lock-mode
1987 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1988 (setq mode-name "Org-Agenda")
1989 (use-local-map org-agenda-mode-map)
1990 (easy-menu-add org-agenda-menu)
1991 (if org-startup-truncated (setq truncate-lines t))
1992 (org-set-local 'line-move-visual nil)
1993 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1994 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1995 ;; Make sure properties are removed when copying text
1996 (make-local-variable 'filter-buffer-substring-functions)
1997 (add-hook 'filter-buffer-substring-functions
1998 (lambda (fun start end delete)
1999 (substring-no-properties (funcall fun start end delete))))
2000 (unless org-agenda-keep-modes
2001 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2002 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2003 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2004 org-agenda-show-log org-agenda-start-with-log-mode))
2006 (easy-menu-change
2007 '("Agenda") "Agenda Files"
2008 (append
2009 (list
2010 (vector
2011 (if (get 'org-agenda-files 'org-restrict)
2012 "Restricted to single file"
2013 "Edit File List")
2014 '(org-edit-agenda-file-list)
2015 (not (get 'org-agenda-files 'org-restrict)))
2016 "--")
2017 (mapcar 'org-file-menu-entry (org-agenda-files))))
2018 (org-agenda-set-mode-name)
2019 (apply
2020 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2021 (list 'org-agenda-mode-hook)))
2023 (substitute-key-definition 'undo 'org-agenda-undo
2024 org-agenda-mode-map global-map)
2025 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2026 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2027 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2028 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2029 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2030 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2031 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2032 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2033 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2034 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2035 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2036 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2037 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2038 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2039 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2040 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2041 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2042 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2043 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2044 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2045 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2046 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2047 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2048 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2049 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2050 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2051 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2052 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2053 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2054 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2055 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2056 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2057 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2058 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2059 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2060 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2061 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2062 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2063 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2064 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2065 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2066 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2067 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2068 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2069 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2071 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2072 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2073 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2074 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2075 (while l (org-defkey org-agenda-mode-map
2076 (int-to-string (pop l)) 'digit-argument)))
2078 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2079 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2080 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2081 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2082 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2083 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2084 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2085 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2086 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2087 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2088 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2089 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2090 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2091 'org-clock-modify-effort-estimate)
2092 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2093 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2094 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2095 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2096 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2097 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2098 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2099 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2100 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2101 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2102 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2103 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2104 (substitute-key-definition 'next-line 'org-agenda-next-line
2105 org-agenda-mode-map global-map)
2106 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2107 org-agenda-mode-map global-map)
2108 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2109 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2110 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2111 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2112 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2113 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2114 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2115 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2116 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2117 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2118 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2119 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2120 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2121 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2123 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2125 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2126 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2127 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2128 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2129 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2130 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2131 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2132 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2133 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2134 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2135 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2136 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2137 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2139 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2140 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2141 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2142 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2143 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2144 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2145 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2146 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2147 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2148 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2149 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2150 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2152 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2153 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2154 (when org-agenda-mouse-1-follows-link
2155 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2156 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2157 '("Agenda"
2158 ("Agenda Files")
2159 "--"
2160 ("Agenda Dates"
2161 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2162 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2163 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2164 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2165 "--"
2166 ("View"
2167 ["Day View" org-agenda-day-view
2168 :active (org-agenda-check-type nil 'agenda)
2169 :style radio :selected (eq org-agenda-current-span 'day)
2170 :keys "v d (or just d)"]
2171 ["Week View" org-agenda-week-view
2172 :active (org-agenda-check-type nil 'agenda)
2173 :style radio :selected (eq org-agenda-current-span 'week)
2174 :keys "v w (or just w)"]
2175 ["Month View" org-agenda-month-view
2176 :active (org-agenda-check-type nil 'agenda)
2177 :style radio :selected (eq org-agenda-current-span 'month)
2178 :keys "v m"]
2179 ["Year View" org-agenda-year-view
2180 :active (org-agenda-check-type nil 'agenda)
2181 :style radio :selected (eq org-agenda-current-span 'year)
2182 :keys "v y"]
2183 "--"
2184 ["Include Diary" org-agenda-toggle-diary
2185 :style toggle :selected org-agenda-include-diary
2186 :active (org-agenda-check-type nil 'agenda)]
2187 ["Include Deadlines" org-agenda-toggle-deadlines
2188 :style toggle :selected org-agenda-include-deadlines
2189 :active (org-agenda-check-type nil 'agenda)]
2190 ["Use Time Grid" org-agenda-toggle-time-grid
2191 :style toggle :selected org-agenda-use-time-grid
2192 :active (org-agenda-check-type nil 'agenda)]
2193 "--"
2194 ["Show clock report" org-agenda-clockreport-mode
2195 :style toggle :selected org-agenda-clockreport-mode
2196 :active (org-agenda-check-type nil 'agenda)]
2197 ["Show some entry text" org-agenda-entry-text-mode
2198 :style toggle :selected org-agenda-entry-text-mode
2199 :active t]
2200 "--"
2201 ["Show Logbook entries" org-agenda-log-mode
2202 :style toggle :selected org-agenda-show-log
2203 :active (org-agenda-check-type nil 'agenda 'timeline)
2204 :keys "v l (or just l)"]
2205 ["Include archived trees" org-agenda-archives-mode
2206 :style toggle :selected org-agenda-archives-mode :active t
2207 :keys "v a"]
2208 ["Include archive files" (org-agenda-archives-mode t)
2209 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2210 :keys "v A"]
2211 "--"
2212 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2213 ["Write view to file" org-agenda-write t]
2214 ["Rebuild buffer" org-agenda-redo t]
2215 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2216 "--"
2217 ["Show original entry" org-agenda-show t]
2218 ["Go To (other window)" org-agenda-goto t]
2219 ["Go To (this window)" org-agenda-switch-to t]
2220 ["Capture with cursor date" org-agenda-capture t]
2221 ["Follow Mode" org-agenda-follow-mode
2222 :style toggle :selected org-agenda-follow-mode :active t]
2223 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2224 "--"
2225 ("TODO"
2226 ["Cycle TODO" org-agenda-todo t]
2227 ["Next TODO set" org-agenda-todo-nextset t]
2228 ["Previous TODO set" org-agenda-todo-previousset t]
2229 ["Add note" org-agenda-add-note t])
2230 ("Archive/Refile/Delete"
2231 ["Archive default" org-agenda-archive-default t]
2232 ["Archive default" org-agenda-archive-default-with-confirmation t]
2233 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2234 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2235 ["Archive subtree" org-agenda-archive t]
2236 "--"
2237 ["Refile" org-agenda-refile t]
2238 "--"
2239 ["Delete subtree" org-agenda-kill t])
2240 ("Bulk action"
2241 ["Mark entry" org-agenda-bulk-mark t]
2242 ["Mark all" org-agenda-bulk-mark-all t]
2243 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2244 ["Unmark entry" org-agenda-bulk-unmark t]
2245 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2246 ["Act on all marked" org-agenda-bulk-action t]
2247 "--"
2248 ("Tags and Properties"
2249 ["Show all Tags" org-agenda-show-tags t]
2250 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2251 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2252 "--"
2253 ["Column View" org-columns t])
2254 ("Deadline/Schedule"
2255 ["Schedule" org-agenda-schedule t]
2256 ["Set Deadline" org-agenda-deadline t]
2257 "--"
2258 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2259 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2260 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2261 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2262 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2263 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2264 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2265 ("Clock and Effort"
2266 ["Clock in" org-agenda-clock-in t]
2267 ["Clock out" org-agenda-clock-out t]
2268 ["Clock cancel" org-agenda-clock-cancel t]
2269 ["Goto running clock" org-clock-goto t]
2270 "--"
2271 ["Set Effort" org-agenda-set-effort t]
2272 ["Change clocked effort" org-clock-modify-effort-estimate
2273 (org-clock-is-active)])
2274 ("Priority"
2275 ["Set Priority" org-agenda-priority t]
2276 ["Increase Priority" org-agenda-priority-up t]
2277 ["Decrease Priority" org-agenda-priority-down t]
2278 ["Show Priority" org-show-priority t])
2279 ("Calendar/Diary"
2280 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2281 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2282 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2283 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2284 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2285 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2286 "--"
2287 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2288 "--"
2289 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2290 "--"
2291 ("MobileOrg"
2292 ["Push Files and Views" org-mobile-push t]
2293 ["Get Captured and Flagged" org-mobile-pull t]
2294 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2295 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2296 "--"
2297 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2298 "--"
2299 ["Quit" org-agenda-quit t]
2300 ["Exit and Release Buffers" org-agenda-exit t]
2303 ;;; Agenda undo
2305 (defvar org-agenda-allow-remote-undo t
2306 "Non-nil means allow remote undo from the agenda buffer.")
2307 (defvar org-agenda-undo-has-started-in nil
2308 "Buffers that have already seen `undo-start' in the current undo sequence.")
2310 (defun org-agenda-undo ()
2311 "Undo a remote editing step in the agenda.
2312 This undoes changes both in the agenda buffer and in the remote buffer
2313 that have been changed along."
2314 (interactive)
2315 (or org-agenda-allow-remote-undo
2316 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2317 (if (not (eq this-command last-command))
2318 (setq org-agenda-undo-has-started-in nil
2319 org-agenda-pending-undo-list org-agenda-undo-list))
2320 (if (not org-agenda-pending-undo-list)
2321 (error "No further undo information"))
2322 (let* ((entry (pop org-agenda-pending-undo-list))
2323 buf line cmd rembuf)
2324 (setq cmd (pop entry) line (pop entry))
2325 (setq rembuf (nth 2 entry))
2326 (org-with-remote-undo rembuf
2327 (while (bufferp (setq buf (pop entry)))
2328 (if (pop entry)
2329 (with-current-buffer buf
2330 (let ((last-undo-buffer buf)
2331 (inhibit-read-only t))
2332 (unless (memq buf org-agenda-undo-has-started-in)
2333 (push buf org-agenda-undo-has-started-in)
2334 (make-local-variable 'pending-undo-list)
2335 (undo-start))
2336 (while (and pending-undo-list
2337 (listp pending-undo-list)
2338 (not (car pending-undo-list)))
2339 (pop pending-undo-list))
2340 (undo-more 1))))))
2341 (org-goto-line line)
2342 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2344 (defun org-verify-change-for-undo (l1 l2)
2345 "Verify that a real change occurred between the undo lists L1 and L2."
2346 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2347 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2348 (not (eq l1 l2)))
2350 ;;; Agenda dispatch
2352 (defvar org-agenda-restrict-begin (make-marker))
2353 (defvar org-agenda-restrict-end (make-marker))
2354 (defvar org-agenda-last-dispatch-buffer nil)
2355 (defvar org-agenda-overriding-restriction nil)
2357 (defcustom org-agenda-custom-commands-contexts nil
2358 "Alist of custom agenda keys and contextual rules.
2360 For example, if you have a custom agenda command \"p\" and you
2361 want this command to be accessible only from plain text files,
2362 use this:
2364 '((\"p\" (in-file . \"\\.txt\")))
2366 Here are the available contexts definitions:
2368 in-file: command displayed only in matching files
2369 in-mode: command displayed only in matching modes
2370 not-in-file: command not displayed in matching files
2371 not-in-mode: command not displayed in matching modes
2372 [function]: a custom function taking no argument
2374 If you define several checks, the agenda command will be
2375 accessible if there is at least one valid check.
2377 You can also bind a key to another agenda custom command
2378 depending on contextual rules.
2380 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2382 Here it means: in .txt files, use \"p\" as the key for the
2383 agenda command otherwise associated with \"q\". (The command
2384 originally associated with \"q\" is not displayed to avoid
2385 duplicates.)"
2386 :version "24.3"
2387 :group 'org-agenda-custom-commands
2388 :type '(repeat (list :tag "Rule"
2389 (string :tag " Agenda key")
2390 (string :tag "Replace by command")
2391 (repeat :tag "Available when"
2392 (choice
2393 (cons :tag "Condition"
2394 (choice
2395 (const :tag "In file" in-file)
2396 (const :tag "Not in file" not-in-file)
2397 (const :tag "In mode" in-mode)
2398 (const :tag "Not in mode" not-in-mode))
2399 (regexp))
2400 (function :tag "Custom function"))))))
2402 (defvar org-keys nil)
2403 (defvar org-match nil)
2404 ;;;###autoload
2405 (defun org-agenda (&optional arg org-keys restriction)
2406 "Dispatch agenda commands to collect entries to the agenda buffer.
2407 Prompts for a command to execute. Any prefix arg will be passed
2408 on to the selected command. The default selections are:
2410 a Call `org-agenda-list' to display the agenda for current day or week.
2411 t Call `org-todo-list' to display the global todo list.
2412 T Call `org-todo-list' to display the global todo list, select only
2413 entries with a specific TODO keyword (the user gets a prompt).
2414 m Call `org-tags-view' to display headlines with tags matching
2415 a condition (the user is prompted for the condition).
2416 M Like `m', but select only TODO entries, no ordinary headlines.
2417 L Create a timeline for the current buffer.
2418 e Export views to associated files.
2419 s Search entries for keywords.
2420 S Search entries for keywords, only with TODO keywords.
2421 / Multi occur across all agenda files and also files listed
2422 in `org-agenda-text-search-extra-files'.
2423 < Restrict agenda commands to buffer, subtree, or region.
2424 Press several times to get the desired effect.
2425 > Remove a previous restriction.
2426 # List \"stuck\" projects.
2427 ! Configure what \"stuck\" means.
2428 C Configure custom agenda commands.
2430 More commands can be added by configuring the variable
2431 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2432 searches can be pre-defined in this way.
2434 If the current buffer is in Org-mode and visiting a file, you can also
2435 first press `<' once to indicate that the agenda should be temporarily
2436 \(until the next use of \\[org-agenda]) restricted to the current file.
2437 Pressing `<' twice means to restrict to the current subtree or region
2438 \(if active)."
2439 (interactive "P")
2440 (catch 'exit
2441 (let* ((prefix-descriptions nil)
2442 (org-agenda-buffer-name org-agenda-buffer-name)
2443 (org-agenda-window-setup (if (equal (buffer-name)
2444 org-agenda-buffer-name)
2445 'current-window
2446 org-agenda-window-setup))
2447 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2448 (org-agenda-custom-commands
2449 ;; normalize different versions
2450 (delq nil
2451 (mapcar
2452 (lambda (x)
2453 (cond ((stringp (cdr x))
2454 (push x prefix-descriptions)
2455 nil)
2456 ((stringp (nth 1 x)) x)
2457 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2458 (t (cons (car x) (cons "" (cdr x))))))
2459 org-agenda-custom-commands)))
2460 (org-agenda-custom-commands
2461 (org-contextualize-keys
2462 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2463 (buf (current-buffer))
2464 (bfn (buffer-file-name (buffer-base-buffer)))
2465 entry key type org-match lprops ans)
2466 ;; Turn off restriction unless there is an overriding one,
2467 (unless org-agenda-overriding-restriction
2468 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2469 ;; There is a request to keep the file list in place
2470 (put 'org-agenda-files 'org-restrict nil))
2471 (setq org-agenda-restrict nil)
2472 (move-marker org-agenda-restrict-begin nil)
2473 (move-marker org-agenda-restrict-end nil))
2474 ;; Delete old local properties
2475 (put 'org-agenda-redo-command 'org-lprops nil)
2476 ;; Delete previously set last-arguments
2477 (put 'org-agenda-redo-command 'last-args nil)
2478 ;; Remember where this call originated
2479 (setq org-agenda-last-dispatch-buffer (current-buffer))
2480 (unless org-keys
2481 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2482 org-keys (car ans)
2483 restriction (cdr ans)))
2484 ;; If we have sticky agenda buffers, set a name for the buffer,
2485 ;; depending on the invoking keys. The user may still set this
2486 ;; as a command option, which will overwrite what we do here.
2487 (if org-agenda-sticky
2488 (setq org-agenda-buffer-name
2489 (format "*Org Agenda(%s)*" org-keys)))
2490 ;; Establish the restriction, if any
2491 (when (and (not org-agenda-overriding-restriction) restriction)
2492 (put 'org-agenda-files 'org-restrict (list bfn))
2493 (cond
2494 ((eq restriction 'region)
2495 (setq org-agenda-restrict t)
2496 (move-marker org-agenda-restrict-begin (region-beginning))
2497 (move-marker org-agenda-restrict-end (region-end)))
2498 ((eq restriction 'subtree)
2499 (save-excursion
2500 (setq org-agenda-restrict t)
2501 (org-back-to-heading t)
2502 (move-marker org-agenda-restrict-begin (point))
2503 (move-marker org-agenda-restrict-end
2504 (progn (org-end-of-subtree t)))))))
2506 ;; For example the todo list should not need it (but does...)
2507 (cond
2508 ((setq entry (assoc org-keys org-agenda-custom-commands))
2509 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2510 (progn
2511 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2512 lprops (nth 4 entry))
2513 (if org-agenda-sticky
2514 (setq org-agenda-buffer-name
2515 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2516 (format "*Org Agenda(%s)*" org-keys))))
2517 (put 'org-agenda-redo-command 'org-lprops lprops)
2518 (cond
2519 ((eq type 'agenda)
2520 (org-let lprops '(org-agenda-list current-prefix-arg)))
2521 ((eq type 'alltodo)
2522 (org-let lprops '(org-todo-list current-prefix-arg)))
2523 ((eq type 'search)
2524 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2525 ((eq type 'stuck)
2526 (org-let lprops '(org-agenda-list-stuck-projects
2527 current-prefix-arg)))
2528 ((eq type 'tags)
2529 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2530 ((eq type 'tags-todo)
2531 (org-let lprops '(org-tags-view '(4) org-match)))
2532 ((eq type 'todo)
2533 (org-let lprops '(org-todo-list org-match)))
2534 ((eq type 'tags-tree)
2535 (org-check-for-org-mode)
2536 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2537 ((eq type 'todo-tree)
2538 (org-check-for-org-mode)
2539 (org-let lprops
2540 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2541 (regexp-quote org-match) "\\>"))))
2542 ((eq type 'occur-tree)
2543 (org-check-for-org-mode)
2544 (org-let lprops '(org-occur org-match)))
2545 ((functionp type)
2546 (org-let lprops '(funcall type org-match)))
2547 ((fboundp type)
2548 (org-let lprops '(funcall type org-match)))
2549 (t (error "Invalid custom agenda command type %s" type))))
2550 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2551 ((equal org-keys "C")
2552 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2553 (customize-variable 'org-agenda-custom-commands))
2554 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2555 ((equal org-keys "s") (call-interactively 'org-search-view))
2556 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2557 ((equal org-keys "t") (call-interactively 'org-todo-list))
2558 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2559 ((equal org-keys "m") (call-interactively 'org-tags-view))
2560 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2561 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2562 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2563 (org-add-hook
2564 'post-command-hook
2565 (lambda ()
2566 (unless (current-message)
2567 (let* ((m (org-agenda-get-any-marker))
2568 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2569 (when note
2570 (message (concat
2571 "FLAGGING-NOTE ([?] for more info): "
2572 (org-add-props
2573 (replace-regexp-in-string
2574 "\\\\n" "//"
2575 (copy-sequence note))
2576 nil 'face 'org-warning)))))))
2577 t t))
2578 ((equal org-keys "L")
2579 (unless (derived-mode-p 'org-mode)
2580 (error "This is not an Org-mode file"))
2581 (unless restriction
2582 (put 'org-agenda-files 'org-restrict (list bfn))
2583 (org-call-with-arg 'org-timeline arg)))
2584 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2585 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2586 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2587 (t (error "Invalid agenda key"))))))
2589 (autoload 'org-agenda "org-agenda" "\
2590 Dispatch agenda commands to collect entries to the agenda buffer.
2591 Prompts for a command to execute. Any prefix arg will be passed
2592 on to the selected command. The default selections are:
2594 a Call `org-agenda-list' to display the agenda for current day or week.
2595 t Call `org-todo-list' to display the global todo list.
2596 T Call `org-todo-list' to display the global todo list, select only
2597 entries with a specific TODO keyword (the user gets a prompt).
2598 m Call `org-tags-view' to display headlines with tags matching
2599 a condition (the user is prompted for the condition).
2600 M Like `m', but select only TODO entries, no ordinary headlines.
2601 L Create a timeline for the current buffer.
2602 e Export views to associated files.
2603 s Search entries for keywords.
2604 S Search entries for keywords, only with TODO keywords.
2605 / Multi occur across all agenda files and also files listed
2606 in `org-agenda-text-search-extra-files'.
2607 < Restrict agenda commands to buffer, subtree, or region.
2608 Press several times to get the desired effect.
2609 > Remove a previous restriction.
2610 # List \"stuck\" projects.
2611 ! Configure what \"stuck\" means.
2612 C Configure custom agenda commands.
2614 More commands can be added by configuring the variable
2615 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2616 searches can be pre-defined in this way.
2618 If the current buffer is in Org-mode and visiting a file, you can also
2619 first press `<' once to indicate that the agenda should be temporarily
2620 \(until the next use of \\[org-agenda]) restricted to the current file.
2621 Pressing `<' twice means to restrict to the current subtree or region
2622 \(if active).
2624 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2626 (defun org-agenda-append-agenda ()
2627 "Append another agenda view to the current one.
2628 This function allows interactive building of block agendas.
2629 Agenda views are separated by `org-agenda-block-separator'."
2630 (interactive)
2631 (unless (derived-mode-p 'org-agenda-mode)
2632 (error "Can only append from within agenda buffer"))
2633 (let ((org-agenda-multi t))
2634 (org-agenda)
2635 (widen)
2636 (org-agenda-finalize)
2637 (org-agenda-fit-window-to-buffer)))
2639 (defun org-agenda-normalize-custom-commands (cmds)
2640 (delq nil
2641 (mapcar
2642 (lambda (x)
2643 (cond ((stringp (cdr x)) nil)
2644 ((stringp (nth 1 x)) x)
2645 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2646 (t (cons (car x) (cons "" (cdr x))))))
2647 cmds)))
2649 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2650 "The user interface for selecting an agenda command."
2651 (catch 'exit
2652 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2653 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2654 (region-p (org-region-active-p))
2655 (custom org-agenda-custom-commands)
2656 (selstring "")
2657 restriction second-time
2658 c entry key type match prefixes rmheader header-end custom1 desc
2659 line lines left right n n1)
2660 (save-window-excursion
2661 (delete-other-windows)
2662 (org-switch-to-buffer-other-window " *Agenda Commands*")
2663 (erase-buffer)
2664 (insert (eval-when-compile
2665 (let ((header
2666 "Press key for an agenda command: < Buffer, subtree/region restriction
2667 -------------------------------- > Remove restriction
2668 a Agenda for current week or day e Export agenda views
2669 t List of all TODO entries T Entries with special TODO kwd
2670 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2671 s Search for keywords S Like s, but only TODO entries
2672 L Timeline for current buffer # List stuck projects (!=configure)
2673 / Multi-occur C Configure custom agenda commands
2674 ? Find :FLAGGED: entries * Toggle sticky agenda views
2676 (start 0))
2677 (while (string-match
2678 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2679 header start)
2680 (setq start (match-end 0))
2681 (add-text-properties (match-beginning 2) (match-end 2)
2682 '(face bold) header))
2683 header)))
2684 (setq header-end (point-marker))
2685 (while t
2686 (setq custom1 custom)
2687 (when (eq rmheader t)
2688 (org-goto-line 1)
2689 (re-search-forward ":" nil t)
2690 (delete-region (match-end 0) (point-at-eol))
2691 (forward-char 1)
2692 (looking-at "-+")
2693 (delete-region (match-end 0) (point-at-eol))
2694 (move-marker header-end (match-end 0)))
2695 (goto-char header-end)
2696 (delete-region (point) (point-max))
2698 ;; Produce all the lines that describe custom commands and prefixes
2699 (setq lines nil)
2700 (while (setq entry (pop custom1))
2701 (setq key (car entry) desc (nth 1 entry)
2702 type (nth 2 entry)
2703 match (nth 3 entry))
2704 (if (> (length key) 1)
2705 (add-to-list 'prefixes (string-to-char key))
2706 (setq line
2707 (format
2708 "%-4s%-14s"
2709 (org-add-props (copy-sequence key)
2710 '(face bold))
2711 (cond
2712 ((string-match "\\S-" desc) desc)
2713 ((eq type 'agenda) "Agenda for current week or day")
2714 ((eq type 'alltodo) "List of all TODO entries")
2715 ((eq type 'search) "Word search")
2716 ((eq type 'stuck) "List of stuck projects")
2717 ((eq type 'todo) "TODO keyword")
2718 ((eq type 'tags) "Tags query")
2719 ((eq type 'tags-todo) "Tags (TODO)")
2720 ((eq type 'tags-tree) "Tags tree")
2721 ((eq type 'todo-tree) "TODO kwd tree")
2722 ((eq type 'occur-tree) "Occur tree")
2723 ((functionp type) (if (symbolp type)
2724 (symbol-name type)
2725 "Lambda expression"))
2726 (t "???"))))
2727 (if org-agenda-menu-show-matcher
2728 (setq line
2729 (concat line ": "
2730 (cond
2731 ((stringp match)
2732 (setq match (copy-sequence match))
2733 (org-add-props match nil 'face 'org-warning))
2734 ((listp type)
2735 (format "set of %d commands" (length type))))))
2736 (if (org-string-nw-p match)
2737 (add-text-properties
2738 0 (length line) (list 'help-echo
2739 (concat "Matcher: " match)) line)))
2740 (push line lines)))
2741 (setq lines (nreverse lines))
2742 (when prefixes
2743 (mapc (lambda (x)
2744 (push
2745 (format "%s %s"
2746 (org-add-props (char-to-string x)
2747 nil 'face 'bold)
2748 (or (cdr (assoc (concat selstring
2749 (char-to-string x))
2750 prefix-descriptions))
2751 "Prefix key"))
2752 lines))
2753 prefixes))
2755 ;; Check if we should display in two columns
2756 (if org-agenda-menu-two-columns
2757 (progn
2758 (setq n (length lines)
2759 n1 (+ (/ n 2) (mod n 2))
2760 right (nthcdr n1 lines)
2761 left (copy-sequence lines))
2762 (setcdr (nthcdr (1- n1) left) nil))
2763 (setq left lines right nil))
2764 (while left
2765 (insert "\n" (pop left))
2766 (when right
2767 (if (< (current-column) 40)
2768 (move-to-column 40 t)
2769 (insert " "))
2770 (insert (pop right))))
2772 ;; Make the window the right size
2773 (goto-char (point-min))
2774 (if second-time
2775 (if (not (pos-visible-in-window-p (point-max)))
2776 (org-fit-window-to-buffer))
2777 (setq second-time t)
2778 (org-fit-window-to-buffer))
2780 ;; Ask for selection
2781 (message "Press key for agenda command%s:"
2782 (if (or restrict-ok org-agenda-overriding-restriction)
2783 (if org-agenda-overriding-restriction
2784 " (restriction lock active)"
2785 (if restriction
2786 (format " (restricted to %s)" restriction)
2787 " (unrestricted)"))
2788 ""))
2789 (setq c (read-char-exclusive))
2790 (message "")
2791 (cond
2792 ((assoc (char-to-string c) custom)
2793 (setq selstring (concat selstring (char-to-string c)))
2794 (throw 'exit (cons selstring restriction)))
2795 ((memq c prefixes)
2796 (setq selstring (concat selstring (char-to-string c))
2797 prefixes nil
2798 rmheader (or rmheader t)
2799 custom (delq nil (mapcar
2800 (lambda (x)
2801 (if (or (= (length (car x)) 1)
2802 (/= (string-to-char (car x)) c))
2804 (cons (substring (car x) 1) (cdr x))))
2805 custom))))
2806 ((eq c ?*)
2807 (call-interactively 'org-toggle-sticky-agenda)
2808 (sit-for 2))
2809 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2810 (message "Restriction is only possible in Org-mode buffers")
2811 (ding) (sit-for 1))
2812 ((eq c ?1)
2813 (org-agenda-remove-restriction-lock 'noupdate)
2814 (setq restriction 'buffer))
2815 ((eq c ?0)
2816 (org-agenda-remove-restriction-lock 'noupdate)
2817 (setq restriction (if region-p 'region 'subtree)))
2818 ((eq c ?<)
2819 (org-agenda-remove-restriction-lock 'noupdate)
2820 (setq restriction
2821 (cond
2822 ((eq restriction 'buffer)
2823 (if region-p 'region 'subtree))
2824 ((memq restriction '(subtree region))
2825 nil)
2826 (t 'buffer))))
2827 ((eq c ?>)
2828 (org-agenda-remove-restriction-lock 'noupdate)
2829 (setq restriction nil))
2830 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2831 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2832 ((and (> (length selstring) 0) (eq c ?\d))
2833 (delete-window)
2834 (org-agenda-get-restriction-and-command prefix-descriptions))
2836 ((equal c ?q) (error "Abort"))
2837 (t (error "Invalid key %c" c))))))))
2839 (defun org-agenda-fit-window-to-buffer ()
2840 "Fit the window to the buffer size."
2841 (and (memq org-agenda-window-setup '(reorganize-frame))
2842 (fboundp 'fit-window-to-buffer)
2843 (org-fit-window-to-buffer
2845 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2846 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2848 (defvar org-cmd nil)
2849 (defvar org-agenda-overriding-cmd nil)
2850 (defvar org-agenda-overriding-arguments nil)
2851 (defvar org-agenda-overriding-cmd-arguments nil)
2852 (defun org-agenda-run-series (name series)
2853 (org-let (nth 1 series) '(org-agenda-prepare name))
2854 ;; We need to reset agenda markers here, because when constructing a
2855 ;; block agenda, the individual blocks do not do that.
2856 (org-agenda-reset-markers)
2857 (let* ((org-agenda-multi t)
2858 (redo (list 'org-agenda-run-series name (list 'quote series)))
2859 (cmds (car series))
2860 (gprops (nth 1 series))
2861 match ;; The byte compiler incorrectly complains about this. Keep it!
2862 org-cmd type lprops)
2863 (while (setq org-cmd (pop cmds))
2864 (setq type (car org-cmd)
2865 match (eval (nth 1 org-cmd))
2866 lprops (nth 2 org-cmd))
2867 (let ((org-agenda-overriding-arguments
2868 (if (eq org-agenda-overriding-cmd org-cmd)
2869 (or org-agenda-overriding-arguments
2870 org-agenda-overriding-cmd-arguments))))
2871 (cond
2872 ((eq type 'agenda)
2873 (org-let2 gprops lprops
2874 '(call-interactively 'org-agenda-list)))
2875 ((eq type 'alltodo)
2876 (org-let2 gprops lprops
2877 '(call-interactively 'org-todo-list)))
2878 ((eq type 'search)
2879 (org-let2 gprops lprops
2880 '(org-search-view current-prefix-arg match nil)))
2881 ((eq type 'stuck)
2882 (org-let2 gprops lprops
2883 '(call-interactively 'org-agenda-list-stuck-projects)))
2884 ((eq type 'tags)
2885 (org-let2 gprops lprops
2886 '(org-tags-view current-prefix-arg match)))
2887 ((eq type 'tags-todo)
2888 (org-let2 gprops lprops
2889 '(org-tags-view '(4) match)))
2890 ((eq type 'todo)
2891 (org-let2 gprops lprops
2892 '(org-todo-list match)))
2893 ((fboundp type)
2894 (org-let2 gprops lprops
2895 '(funcall type match)))
2896 (t (error "Invalid type in command series")))))
2897 (widen)
2898 (let ((inhibit-read-only t))
2899 (add-text-properties (point-min) (point-max)
2900 `(org-series t org-series-redo-cmd ,redo)))
2901 (setq org-agenda-redo-command redo)
2902 (goto-char (point-min)))
2903 (org-agenda-fit-window-to-buffer)
2904 (org-let (nth 1 series) '(org-agenda-finalize)))
2906 ;;;###autoload
2907 (defmacro org-batch-agenda (cmd-key &rest parameters)
2908 "Run an agenda command in batch mode and send the result to STDOUT.
2909 If CMD-KEY is a string of length 1, it is used as a key in
2910 `org-agenda-custom-commands' and triggers this command. If it is a
2911 longer string it is used as a tags/todo match string.
2912 Parameters are alternating variable names and values that will be bound
2913 before running the agenda command."
2914 (org-eval-in-environment (org-make-parameter-alist parameters)
2915 (if (> (length cmd-key) 2)
2916 (org-tags-view nil cmd-key)
2917 (org-agenda nil cmd-key)))
2918 (set-buffer org-agenda-buffer-name)
2919 (princ (buffer-string)))
2921 (autoload 'org-batch-agenda "org-agenda" "\
2922 Run an agenda command in batch mode and send the result to STDOUT.
2923 If CMD-KEY is a string of length 1, it is used as a key in
2924 `org-agenda-custom-commands' and triggers this command. If it is a
2925 longer string it is used as a tags/todo match string.
2926 Parameters are alternating variable names and values that will be bound
2927 before running the agenda command.
2929 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2930 (def-edebug-spec org-batch-agenda (form &rest sexp))
2932 (defvar org-agenda-info nil)
2934 ;;;###autoload
2935 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2936 "Run an agenda command in batch mode and send the result to STDOUT.
2937 If CMD-KEY is a string of length 1, it is used as a key in
2938 `org-agenda-custom-commands' and triggers this command. If it is a
2939 longer string it is used as a tags/todo match string.
2940 Parameters are alternating variable names and values that will be bound
2941 before running the agenda command.
2943 The output gives a line for each selected agenda item. Each
2944 item is a list of comma-separated values, like this:
2946 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2948 category The category of the item
2949 head The headline, without TODO kwd, TAGS and PRIORITY
2950 type The type of the agenda entry, can be
2951 todo selected in TODO match
2952 tagsmatch selected in tags match
2953 diary imported from diary
2954 deadline a deadline on given date
2955 scheduled scheduled on given date
2956 timestamp entry has timestamp on given date
2957 closed entry was closed on given date
2958 upcoming-deadline warning about deadline
2959 past-scheduled forwarded scheduled item
2960 block entry has date block including g. date
2961 todo The todo keyword, if any
2962 tags All tags including inherited ones, separated by colons
2963 date The relevant date, like 2007-2-14
2964 time The time, like 15:00-16:50
2965 extra Sting with extra planning info
2966 priority-l The priority letter if any was given
2967 priority-n The computed numerical priority
2968 agenda-day The day in the agenda where this is listed"
2969 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2970 (org-make-parameter-alist parameters))
2971 (if (> (length cmd-key) 2)
2972 (org-tags-view nil cmd-key)
2973 (org-agenda nil cmd-key)))
2974 (set-buffer org-agenda-buffer-name)
2975 (let* ((lines (org-split-string (buffer-string) "\n"))
2976 line)
2977 (while (setq line (pop lines))
2978 (catch 'next
2979 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2980 (setq org-agenda-info
2981 (org-fix-agenda-info (text-properties-at 0 line)))
2982 (princ
2983 (mapconcat 'org-agenda-export-csv-mapper
2984 '(org-category txt type todo tags date time extra
2985 priority-letter priority agenda-day)
2986 ","))
2987 (princ "\n")))))
2989 (autoload 'org-batch-agenda-csv "org-agenda" "\
2990 Run an agenda command in batch mode and send the result to STDOUT.
2991 If CMD-KEY is a string of length 1, it is used as a key in
2992 `org-agenda-custom-commands' and triggers this command. If it is a
2993 longer string it is used as a tags/todo match string.
2994 Parameters are alternating variable names and values that will be bound
2995 before running the agenda command.
2997 The output gives a line for each selected agenda item. Each
2998 item is a list of comma-separated values, like this:
3000 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3002 category The category of the item
3003 head The headline, without TODO kwd, TAGS and PRIORITY
3004 type The type of the agenda entry, can be
3005 todo selected in TODO match
3006 tagsmatch selected in tags match
3007 diary imported from diary
3008 deadline a deadline on given date
3009 scheduled scheduled on given date
3010 timestamp entry has timestamp on given date
3011 closed entry was closed on given date
3012 upcoming-deadline warning about deadline
3013 past-scheduled forwarded scheduled item
3014 block entry has date block including g. date
3015 todo The todo keyword, if any
3016 tags All tags including inherited ones, separated by colons
3017 date The relevant date, like 2007-2-14
3018 time The time, like 15:00-16:50
3019 extra Sting with extra planning info
3020 priority-l The priority letter if any was given
3021 priority-n The computed numerical priority
3022 agenda-day The day in the agenda where this is listed
3024 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3025 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3027 (defun org-fix-agenda-info (props)
3028 "Make sure all properties on an agenda item have a canonical form.
3029 This ensures the export commands can easily use it."
3030 (let (tmp re)
3031 (when (setq tmp (plist-get props 'tags))
3032 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3033 (when (setq tmp (plist-get props 'date))
3034 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3035 (let ((calendar-date-display-form '(year "-" month "-" day)))
3036 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3038 (setq tmp (calendar-date-string tmp)))
3039 (setq props (plist-put props 'date tmp)))
3040 (when (setq tmp (plist-get props 'day))
3041 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3042 (let ((calendar-date-display-form '(year "-" month "-" day)))
3043 (setq tmp (calendar-date-string tmp)))
3044 (setq props (plist-put props 'day tmp))
3045 (setq props (plist-put props 'agenda-day tmp)))
3046 (when (setq tmp (plist-get props 'txt))
3047 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3048 (plist-put props 'priority-letter (match-string 1 tmp))
3049 (setq tmp (replace-match "" t t tmp)))
3050 (when (and (setq re (plist-get props 'org-todo-regexp))
3051 (setq re (concat "\\`\\.*" re " ?"))
3052 (string-match re tmp))
3053 (plist-put props 'todo (match-string 1 tmp))
3054 (setq tmp (replace-match "" t t tmp)))
3055 (plist-put props 'txt tmp)))
3056 props)
3058 (defun org-agenda-export-csv-mapper (prop)
3059 (let ((res (plist-get org-agenda-info prop)))
3060 (setq res
3061 (cond
3062 ((not res) "")
3063 ((stringp res) res)
3064 (t (prin1-to-string res))))
3065 (while (string-match "," res)
3066 (setq res (replace-match ";" t t res)))
3067 (org-trim res)))
3069 ;;;###autoload
3070 (defun org-store-agenda-views (&rest parameters)
3071 (interactive)
3072 (eval (list 'org-batch-store-agenda-views)))
3074 (autoload 'org-store-agenda-views "org-agenda" "\
3077 \(fn &rest PARAMETERS)" t nil)
3079 ;;;###autoload
3080 (defmacro org-batch-store-agenda-views (&rest parameters)
3081 "Run all custom agenda commands that have a file argument."
3082 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3083 (pop-up-frames nil)
3084 (dir default-directory)
3085 (pars (org-make-parameter-alist parameters))
3086 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3087 (save-window-excursion
3088 (while cmds
3089 (setq cmd (pop cmds)
3090 thiscmdkey (car cmd)
3091 thiscmdcmd (cdr cmd)
3092 match (nth 2 thiscmdcmd)
3093 bufname (if org-agenda-sticky
3094 (or (and (stringp match)
3095 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3096 (format "*Org Agenda(%s)*" thiscmdkey))
3097 org-agenda-buffer-name)
3098 cmd-or-set (nth 2 cmd)
3099 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3100 files (nth (if (listp cmd-or-set) 4 5) cmd))
3101 (if (stringp files) (setq files (list files)))
3102 (when files
3103 (org-eval-in-environment (append org-agenda-exporter-settings
3104 opts pars)
3105 (org-agenda nil thiscmdkey))
3106 (set-buffer bufname)
3107 (while files
3108 (org-eval-in-environment (append org-agenda-exporter-settings
3109 opts pars)
3110 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3111 (and (get-buffer bufname)
3112 (kill-buffer bufname)))))))
3114 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3115 Run all custom agenda commands that have a file argument.
3117 \(fn &rest PARAMETERS)" nil t)
3118 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3120 (defvar org-agenda-current-span nil
3121 "The current span used in the agenda view.") ; local variable in the agenda buffer
3122 (defun org-agenda-mark-header-line (pos)
3123 "Mark the line at POS as an agenda structure header."
3124 (save-excursion
3125 (goto-char pos)
3126 (put-text-property (point-at-bol) (point-at-eol)
3127 'org-agenda-structural-header t)
3128 (when org-agenda-title-append
3129 (put-text-property (point-at-bol) (point-at-eol)
3130 'org-agenda-title-append org-agenda-title-append))))
3132 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3133 (defvar org-agenda-write-buffer-name "Agenda View")
3134 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3135 "Write the current buffer (an agenda view) as a file.
3136 Depending on the extension of the file name, plain text (.txt),
3137 HTML (.html or .htm) or Postscript (.ps) is produced.
3138 If the extension is .ics, run icalendar export over all files used
3139 to construct the agenda and limit the export to entries listed in the
3140 agenda now.
3141 With prefix argument OPEN, open the new file immediately.
3142 If NOSETTINGS is given, do not scope the settings of
3143 `org-agenda-exporter-settings' into the export commands. This is used when
3144 the settings have already been scoped and we do not wish to overrule other,
3145 higher priority settings.
3146 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3147 (interactive "FWrite agenda to file: \nP")
3148 (if (not (file-writable-p file))
3149 (error "Cannot write agenda to file %s" file))
3150 (org-let (if nosettings nil org-agenda-exporter-settings)
3151 '(save-excursion
3152 (save-window-excursion
3153 (org-agenda-mark-filtered-text)
3154 (let ((bs (copy-sequence (buffer-string))) beg)
3155 (org-agenda-unmark-filtered-text)
3156 (with-temp-buffer
3157 (rename-buffer org-agenda-write-buffer-name t)
3158 (set-buffer-modified-p nil)
3159 (insert bs)
3160 (org-agenda-remove-marked-text 'org-filtered)
3161 (while (setq beg (text-property-any (point-min) (point-max)
3162 'org-filtered t))
3163 (delete-region
3164 beg (or (next-single-property-change beg 'org-filtered)
3165 (point-max))))
3166 (run-hooks 'org-agenda-before-write-hook)
3167 (cond
3168 ((org-bound-and-true-p org-mobile-creating-agendas)
3169 (org-mobile-write-agenda-for-mobile file))
3170 ((string-match "\\.html?\\'" file)
3171 (require 'htmlize)
3172 (set-buffer (htmlize-buffer (current-buffer)))
3173 (when org-agenda-export-html-style
3174 ;; replace <style> section with org-agenda-export-html-style
3175 (goto-char (point-min))
3176 (kill-region (- (search-forward "<style") 6)
3177 (search-forward "</style>"))
3178 (insert org-agenda-export-html-style))
3179 (write-file file)
3180 (kill-buffer (current-buffer))
3181 (message "HTML written to %s" file))
3182 ((string-match "\\.ps\\'" file)
3183 (require 'ps-print)
3184 (ps-print-buffer-with-faces file)
3185 (message "Postscript written to %s" file))
3186 ((string-match "\\.pdf\\'" file)
3187 (require 'ps-print)
3188 (ps-print-buffer-with-faces
3189 (concat (file-name-sans-extension file) ".ps"))
3190 (call-process "ps2pdf" nil nil nil
3191 (expand-file-name
3192 (concat (file-name-sans-extension file) ".ps"))
3193 (expand-file-name file))
3194 (delete-file (concat (file-name-sans-extension file) ".ps"))
3195 (message "PDF written to %s" file))
3196 ((string-match "\\.ics\\'" file)
3197 (require 'org-icalendar)
3198 (let ((org-agenda-marker-table
3199 (org-create-marker-find-array
3200 (org-agenda-collect-markers)))
3201 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3202 (org-combined-agenda-icalendar-file file))
3203 (apply 'org-export-icalendar 'combine
3204 (org-agenda-files nil 'ifmode))))
3206 (let ((bs (buffer-string)))
3207 (find-file file)
3208 (erase-buffer)
3209 (insert bs)
3210 (save-buffer 0)
3211 (kill-buffer (current-buffer))
3212 (message "Plain text written to %s" file))))))))
3213 (set-buffer (or agenda-bufname
3214 (and (org-called-interactively-p 'any) (buffer-name))
3215 org-agenda-buffer-name)))
3216 (when open (org-open-file file)))
3218 (defvar org-agenda-tag-filter-overlays nil)
3219 (defvar org-agenda-cat-filter-overlays nil)
3221 (defun org-agenda-mark-filtered-text ()
3222 "Mark all text hidden by filtering with a text property."
3223 (let ((inhibit-read-only t))
3224 (mapc
3225 (lambda (o)
3226 (when (equal (overlay-buffer o) (current-buffer))
3227 (put-text-property
3228 (overlay-start o) (overlay-end o)
3229 'org-filtered t)))
3230 (append org-agenda-tag-filter-overlays
3231 org-agenda-cat-filter-overlays))))
3233 (defun org-agenda-unmark-filtered-text ()
3234 "Remove the filtering text property."
3235 (let ((inhibit-read-only t))
3236 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3238 (defun org-agenda-remove-marked-text (property &optional value)
3239 "Delete all text marked with VALUE of PROPERTY.
3240 VALUE defaults to t."
3241 (let (beg)
3242 (setq value (or value t))
3243 (while (setq beg (text-property-any (point-min) (point-max)
3244 property value))
3245 (delete-region
3246 beg (or (next-single-property-change beg 'org-filtered)
3247 (point-max))))))
3249 (defun org-agenda-add-entry-text ()
3250 "Add entry text to agenda lines.
3251 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3252 entry text following headings shown in the agenda.
3253 Drawers will be excluded, also the line with scheduling/deadline info."
3254 (when (and (> org-agenda-add-entry-text-maxlines 0)
3255 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3256 (let (m txt)
3257 (goto-char (point-min))
3258 (while (not (eobp))
3259 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3260 (beginning-of-line 2)
3261 (setq txt (org-agenda-get-some-entry-text
3262 m org-agenda-add-entry-text-maxlines " > "))
3263 (end-of-line 1)
3264 (if (string-match "\\S-" txt)
3265 (insert "\n" txt)
3266 (or (eobp) (forward-char 1))))))))
3268 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3269 &rest keep)
3270 "Extract entry text from MARKER, at most N-LINES lines.
3271 This will ignore drawers etc, just get the text.
3272 If INDENT is given, prefix every line with this string. If KEEP is
3273 given, it is a list of symbols, defining stuff that should not be
3274 removed from the entry content. Currently only `planning' is allowed here."
3275 (let (txt drawer-re kwd-time-re ind)
3276 (save-excursion
3277 (with-current-buffer (marker-buffer marker)
3278 (if (not (derived-mode-p 'org-mode))
3279 (setq txt "")
3280 (save-excursion
3281 (save-restriction
3282 (widen)
3283 (goto-char marker)
3284 (end-of-line 1)
3285 (setq txt (buffer-substring
3286 (min (1+ (point)) (point-max))
3287 (progn (outline-next-heading) (point)))
3288 drawer-re org-drawer-regexp
3289 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3290 ".*\n?"))
3291 (with-temp-buffer
3292 (insert txt)
3293 (when org-agenda-add-entry-text-descriptive-links
3294 (goto-char (point-min))
3295 (while (org-activate-bracket-links (point-max))
3296 (add-text-properties (match-beginning 0) (match-end 0)
3297 '(face org-link))))
3298 (goto-char (point-min))
3299 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3300 (set-text-properties (match-beginning 0) (match-end 0)
3301 nil))
3302 (goto-char (point-min))
3303 (while (re-search-forward drawer-re nil t)
3304 (delete-region
3305 (match-beginning 0)
3306 (progn (re-search-forward
3307 "^[ \t]*:END:.*\n?" nil 'move)
3308 (point))))
3309 (unless (member 'planning keep)
3310 (goto-char (point-min))
3311 (while (re-search-forward kwd-time-re nil t)
3312 (replace-match "")))
3313 (goto-char (point-min))
3314 (when org-agenda-entry-text-exclude-regexps
3315 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3316 (while (setq re (pop re-list))
3317 (goto-char (point-min))
3318 (while (re-search-forward re nil t)
3319 (replace-match "")))))
3320 (goto-char (point-max))
3321 (skip-chars-backward " \t\n")
3322 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3324 ;; find and remove min common indentation
3325 (goto-char (point-min))
3326 (untabify (point-min) (point-max))
3327 (setq ind (org-get-indentation))
3328 (while (not (eobp))
3329 (unless (looking-at "[ \t]*$")
3330 (setq ind (min ind (org-get-indentation))))
3331 (beginning-of-line 2))
3332 (goto-char (point-min))
3333 (while (not (eobp))
3334 (unless (looking-at "[ \t]*$")
3335 (move-to-column ind)
3336 (delete-region (point-at-bol) (point)))
3337 (beginning-of-line 2))
3339 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3341 (goto-char (point-min))
3342 (when indent
3343 (while (and (not (eobp)) (re-search-forward "^" nil t))
3344 (replace-match indent t t)))
3345 (goto-char (point-min))
3346 (while (looking-at "[ \t]*\n") (replace-match ""))
3347 (goto-char (point-max))
3348 (when (> (org-current-line)
3349 n-lines)
3350 (org-goto-line (1+ n-lines))
3351 (backward-char 1))
3352 (setq txt (buffer-substring (point-min) (point)))))))))
3353 txt))
3355 (defun org-agenda-collect-markers ()
3356 "Collect the markers pointing to entries in the agenda buffer."
3357 (let (m markers)
3358 (save-excursion
3359 (goto-char (point-min))
3360 (while (not (eobp))
3361 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3362 (org-get-at-bol 'org-marker)))
3363 (push m markers))
3364 (beginning-of-line 2)))
3365 (nreverse markers)))
3367 (defun org-create-marker-find-array (marker-list)
3368 "Create a alist of files names with all marker positions in that file."
3369 (let (f tbl m a p)
3370 (while (setq m (pop marker-list))
3371 (setq p (marker-position m)
3372 f (buffer-file-name (or (buffer-base-buffer
3373 (marker-buffer m))
3374 (marker-buffer m))))
3375 (if (setq a (assoc f tbl))
3376 (push (marker-position m) (cdr a))
3377 (push (list f p) tbl)))
3378 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3379 tbl)))
3381 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3382 (defun org-check-agenda-marker-table ()
3383 "Check of the current entry is on the marker list."
3384 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3386 (and (setq a (assoc file org-agenda-marker-table))
3387 (save-match-data
3388 (save-excursion
3389 (org-back-to-heading t)
3390 (member (point) (cdr a)))))))
3392 (defun org-check-for-org-mode ()
3393 "Make sure current buffer is in org-mode. Error if not."
3394 (or (derived-mode-p 'org-mode)
3395 (error "Cannot execute org-mode agenda command on buffer in %s"
3396 major-mode)))
3398 ;;; Agenda prepare and finalize
3400 (defvar org-agenda-multi nil) ; dynamically scoped
3401 (defvar org-agenda-pre-window-conf nil)
3402 (defvar org-agenda-columns-active nil)
3403 (defvar org-agenda-name nil)
3404 (defvar org-agenda-tag-filter nil)
3405 (defvar org-agenda-category-filter nil)
3406 (defvar org-agenda-top-category-filter nil)
3407 (defvar org-agenda-tag-filter-while-redo nil)
3408 (defvar org-agenda-tag-filter-preset nil
3409 "A preset of the tags filter used for secondary agenda filtering.
3410 This must be a list of strings, each string must be a single tag preceded
3411 by \"+\" or \"-\".
3412 This variable should not be set directly, but agenda custom commands can
3413 bind it in the options section. The preset filter is a global property of
3414 the entire agenda view. In a block agenda, it will not work reliably to
3415 define a filter for one of the individual blocks. You need to set it in
3416 the global options and expect it to be applied to the entire view.")
3418 (defvar org-agenda-category-filter-preset nil
3419 "A preset of the category filter used for secondary agenda filtering.
3420 This must be a list of strings, each string must be a single category
3421 preceded by \"+\" or \"-\".
3422 This variable should not be set directly, but agenda custom commands can
3423 bind it in the options section. The preset filter is a global property of
3424 the entire agenda view. In a block agenda, it will not work reliably to
3425 define a filter for one of the individual blocks. You need to set it in
3426 the global options and expect it to be applied to the entire view.")
3429 (defun org-agenda-use-sticky-p ()
3430 "Return non-nil if an agenda buffer named
3431 `org-agenda-buffer-name' exists and should be shown instead of
3432 generating a new one."
3433 (and
3434 ;; turned off by user
3435 org-agenda-sticky
3436 ;; For multi-agenda buffer already exists
3437 (not org-agenda-multi)
3438 ;; buffer found
3439 (get-buffer org-agenda-buffer-name)
3440 ;; C-u parameter is same as last call
3441 (with-current-buffer (get-buffer org-agenda-buffer-name)
3442 (and
3443 (equal current-prefix-arg
3444 org-agenda-last-prefix-arg)
3445 ;; In case user turned stickiness on, while having existing
3446 ;; Agenda buffer active, don't reuse that buffer, because it
3447 ;; does not have org variables local
3448 org-agenda-this-buffer-is-sticky))))
3450 (defun org-agenda-prepare-window (abuf)
3451 "Setup agenda buffer in the window."
3452 (let* ((awin (get-buffer-window abuf))
3453 wconf)
3454 (cond
3455 ((equal (current-buffer) abuf) nil)
3456 (awin (select-window awin))
3457 ((not (setq wconf (current-window-configuration))))
3458 ((equal org-agenda-window-setup 'current-window)
3459 (org-pop-to-buffer-same-window abuf))
3460 ((equal org-agenda-window-setup 'other-window)
3461 (org-switch-to-buffer-other-window abuf))
3462 ((equal org-agenda-window-setup 'other-frame)
3463 (switch-to-buffer-other-frame abuf))
3464 ((equal org-agenda-window-setup 'reorganize-frame)
3465 (delete-other-windows)
3466 (org-switch-to-buffer-other-window abuf)))
3467 ;; additional test in case agenda is invoked from within agenda
3468 ;; buffer via elisp link
3469 (unless (equal (current-buffer) abuf)
3470 (org-pop-to-buffer-same-window abuf))
3471 (setq org-agenda-pre-window-conf
3472 (or org-agenda-pre-window-conf wconf))))
3474 (defun org-agenda-prepare (&optional name)
3475 (if (org-agenda-use-sticky-p)
3476 (progn
3477 ;; Popup existing buffer
3478 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3479 (message "Sticky Agenda buffer, use `r' to refresh")
3480 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3481 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3482 (setq org-todo-keywords-for-agenda nil)
3483 (setq org-drawers-for-agenda nil)
3484 (unless org-agenda-persistent-filter
3485 (setq org-agenda-tag-filter nil
3486 org-agenda-category-filter nil))
3487 (put 'org-agenda-tag-filter :preset-filter
3488 org-agenda-tag-filter-preset)
3489 (put 'org-agenda-category-filter :preset-filter
3490 org-agenda-category-filter-preset)
3491 (if org-agenda-multi
3492 (progn
3493 (setq buffer-read-only nil)
3494 (goto-char (point-max))
3495 (unless (or (bobp) org-agenda-compact-blocks
3496 (not org-agenda-block-separator))
3497 (insert "\n"
3498 (if (stringp org-agenda-block-separator)
3499 org-agenda-block-separator
3500 (make-string (window-width) org-agenda-block-separator))
3501 "\n"))
3502 (narrow-to-region (point) (point-max)))
3503 (setq org-done-keywords-for-agenda nil)
3505 ;; Setting any org variables that are in org-agenda-local-vars
3506 ;; list need to be done after the prepare call
3507 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3508 (setq buffer-read-only nil)
3509 (org-agenda-reset-markers)
3510 (let ((inhibit-read-only t)) (erase-buffer))
3511 (org-agenda-mode)
3512 (setq org-agenda-buffer (current-buffer))
3513 (setq org-agenda-contributing-files nil)
3514 (setq org-agenda-columns-active nil)
3515 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3516 (setq org-todo-keywords-for-agenda
3517 (org-uniquify org-todo-keywords-for-agenda))
3518 (setq org-done-keywords-for-agenda
3519 (org-uniquify org-done-keywords-for-agenda))
3520 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3521 (setq org-agenda-last-prefix-arg current-prefix-arg)
3522 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3523 (and name (not org-agenda-name)
3524 (org-set-local 'org-agenda-name name)))
3525 (setq buffer-read-only nil)))
3527 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3528 (defun org-agenda-finalize ()
3529 "Finishing touch for the agenda buffer, called just before displaying it."
3530 (unless org-agenda-multi
3531 (save-excursion
3532 (let ((inhibit-read-only t))
3533 (goto-char (point-min))
3534 (save-excursion
3535 (while (org-activate-bracket-links (point-max))
3536 (add-text-properties (match-beginning 0) (match-end 0)
3537 '(face org-link))))
3538 (save-excursion
3539 (while (org-activate-plain-links (point-max))
3540 (add-text-properties (match-beginning 0) (match-end 0)
3541 '(face org-link))))
3542 (org-agenda-align-tags)
3543 (unless org-agenda-with-colors
3544 (remove-text-properties (point-min) (point-max) '(face nil))))
3545 (if (and (boundp 'org-agenda-overriding-columns-format)
3546 org-agenda-overriding-columns-format)
3547 (org-set-local 'org-agenda-overriding-columns-format
3548 org-agenda-overriding-columns-format))
3549 (if (and (boundp 'org-agenda-view-columns-initially)
3550 org-agenda-view-columns-initially)
3551 (org-agenda-columns))
3552 (when org-agenda-fontify-priorities
3553 (org-agenda-fontify-priorities))
3554 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3555 (org-agenda-dim-blocked-tasks))
3556 ;; We need to widen when `org-agenda-finalize' is called from
3557 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3558 (save-restriction
3559 (widen)
3560 (org-agenda-mark-clocking-task))
3561 (when org-agenda-entry-text-mode
3562 (org-agenda-entry-text-hide)
3563 (org-agenda-entry-text-show))
3564 (if (functionp 'org-habit-insert-consistency-graphs)
3565 (org-habit-insert-consistency-graphs))
3566 (let ((inhibit-read-only t))
3567 (run-hooks 'org-agenda-finalize-hook))
3568 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3569 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3570 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3571 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3572 (org-agenda-filter-apply org-agenda-category-filter 'category))
3573 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3575 (defun org-agenda-mark-clocking-task ()
3576 "Mark the current clock entry in the agenda if it is present."
3577 (mapc (lambda (o)
3578 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3579 (delete-overlay o)))
3580 (overlays-in (point-min) (point-max)))
3581 (when (marker-buffer org-clock-hd-marker)
3582 (save-excursion
3583 (goto-char (point-min))
3584 (let (s ov)
3585 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3586 (goto-char s)
3587 (when (equal (org-get-at-bol 'org-hd-marker)
3588 org-clock-hd-marker)
3589 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3590 (overlay-put ov 'type 'org-agenda-clocking)
3591 (overlay-put ov 'face 'org-agenda-clocking)
3592 (overlay-put ov 'help-echo
3593 "The clock is running in this item")))))))
3595 (defun org-agenda-fontify-priorities ()
3596 "Make highest priority lines bold, and lowest italic."
3597 (interactive)
3598 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3599 (delete-overlay o)))
3600 (overlays-in (point-min) (point-max)))
3601 (save-excursion
3602 (let ((inhibit-read-only t)
3603 b e p ov h l)
3604 (goto-char (point-min))
3605 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3606 (setq h (or (get-char-property (point) 'org-highest-priority)
3607 org-highest-priority)
3608 l (or (get-char-property (point) 'org-lowest-priority)
3609 org-lowest-priority)
3610 p (string-to-char (match-string 1))
3611 b (match-beginning 0)
3612 e (if (eq org-agenda-fontify-priorities 'cookies)
3613 (match-end 0)
3614 (point-at-eol))
3615 ov (make-overlay b e))
3616 (overlay-put
3617 ov 'face
3618 (cond ((org-face-from-face-or-color
3619 'priority nil
3620 (cdr (assoc p org-priority-faces))))
3621 ((and (listp org-agenda-fontify-priorities)
3622 (org-face-from-face-or-color
3623 'priority nil
3624 (cdr (assoc p org-agenda-fontify-priorities)))))
3625 ((equal p l) 'italic)
3626 ((equal p h) 'bold)))
3627 (overlay-put ov 'org-type 'org-priority)))))
3629 (defun org-agenda-dim-blocked-tasks ()
3630 "Dim currently blocked TODO's in the agenda display."
3631 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3632 (delete-overlay o)))
3633 (overlays-in (point-min) (point-max)))
3634 (save-excursion
3635 (let ((inhibit-read-only t)
3636 (org-depend-tag-blocked nil)
3637 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3638 org-blocked-by-checkboxes
3639 invis1 b e p ov h l)
3640 (goto-char (point-min))
3641 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3642 (and pos (goto-char (1+ pos))))
3643 (setq org-blocked-by-checkboxes nil invis1 invis)
3644 (let ((marker (org-get-at-bol 'org-hd-marker)))
3645 (when (and marker
3646 (with-current-buffer (marker-buffer marker)
3647 (save-excursion (goto-char marker)
3648 (org-entry-blocked-p))))
3649 (if org-blocked-by-checkboxes (setq invis1 nil))
3650 (setq b (if invis1
3651 (max (point-min) (1- (point-at-bol)))
3652 (point-at-bol))
3653 e (point-at-eol)
3654 ov (make-overlay b e))
3655 (if invis1
3656 (overlay-put ov 'invisible t)
3657 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3658 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3660 (defvar org-agenda-skip-function nil
3661 "Function to be called at each match during agenda construction.
3662 If this function returns nil, the current match should not be skipped.
3663 Otherwise, the function must return a position from where the search
3664 should be continued.
3665 This may also be a Lisp form, it will be evaluated.
3666 Never set this variable using `setq' or so, because then it will apply
3667 to all future agenda commands. If you do want a global skipping condition,
3668 use the option `org-agenda-skip-function-global' instead.
3669 The correct usage for `org-agenda-skip-function' is to bind it with
3670 `let' to scope it dynamically into the agenda-constructing command.
3671 A good way to set it is through options in `org-agenda-custom-commands'.")
3673 (defun org-agenda-skip ()
3674 "Throw to `:skip' in places that should be skipped.
3675 Also moves point to the end of the skipped region, so that search can
3676 continue from there."
3677 (let ((p (point-at-bol)) to)
3678 (when (org-in-src-block-p t) (throw :skip t))
3679 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3680 (get-text-property p :org-archived)
3681 (org-end-of-subtree t)
3682 (throw :skip t))
3683 (and org-agenda-skip-comment-trees
3684 (get-text-property p :org-comment)
3685 (org-end-of-subtree t)
3686 (throw :skip t))
3687 (if (equal (char-after p) ?#) (throw :skip t))
3688 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3689 (org-agenda-skip-eval org-agenda-skip-function)))
3690 (goto-char to)
3691 (throw :skip t))))
3693 (defun org-agenda-skip-eval (form)
3694 "If FORM is a function or a list, call (or eval) is and return result.
3695 `save-excursion' and `save-match-data' are wrapped around the call, so point
3696 and match data are returned to the previous state no matter what these
3697 functions do."
3698 (let (fp)
3699 (and form
3700 (or (setq fp (functionp form))
3701 (consp form))
3702 (save-excursion
3703 (save-match-data
3704 (if fp
3705 (funcall form)
3706 (eval form)))))))
3708 (defvar org-agenda-markers nil
3709 "List of all currently active markers created by `org-agenda'.")
3710 (defvar org-agenda-last-marker-time (org-float-time)
3711 "Creation time of the last agenda marker.")
3713 (defun org-agenda-new-marker (&optional pos)
3714 "Return a new agenda marker.
3715 Org-mode keeps a list of these markers and resets them when they are
3716 no longer in use."
3717 (let ((m (copy-marker (or pos (point)))))
3718 (setq org-agenda-last-marker-time (org-float-time))
3719 (if org-agenda-buffer
3720 (with-current-buffer org-agenda-buffer
3721 (push m org-agenda-markers))
3722 (push m org-agenda-markers))
3725 (defun org-agenda-reset-markers ()
3726 "Reset markers created by `org-agenda'."
3727 (while org-agenda-markers
3728 (move-marker (pop org-agenda-markers) nil)))
3730 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3731 "Save relative positions of markers in region.
3732 This check for agenda markers in all agenda buffers currently active."
3733 (dolist (buf (buffer-list))
3734 (with-current-buffer buf
3735 (when (eq major-mode 'org-agenda-mode)
3736 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3737 org-agenda-markers)))))
3739 ;;; Entry text mode
3741 (defun org-agenda-entry-text-show-here ()
3742 "Add some text from the entry as context to the current line."
3743 (let (m txt o)
3744 (setq m (org-get-at-bol 'org-hd-marker))
3745 (unless (marker-buffer m)
3746 (error "No marker points to an entry here"))
3747 (setq txt (concat "\n" (org-no-properties
3748 (org-agenda-get-some-entry-text
3749 m org-agenda-entry-text-maxlines " > "))))
3750 (when (string-match "\\S-" txt)
3751 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3752 (overlay-put o 'evaporate t)
3753 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3754 (overlay-put o 'after-string txt))))
3756 (defun org-agenda-entry-text-show ()
3757 "Add entry context for all agenda lines."
3758 (interactive)
3759 (save-excursion
3760 (goto-char (point-max))
3761 (beginning-of-line 1)
3762 (while (not (bobp))
3763 (when (org-get-at-bol 'org-hd-marker)
3764 (org-agenda-entry-text-show-here))
3765 (beginning-of-line 0))))
3767 (defun org-agenda-entry-text-hide ()
3768 "Remove any shown entry context."
3769 (delq nil
3770 (mapcar (lambda (o)
3771 (if (eq (overlay-get o 'org-overlay-type)
3772 'agenda-entry-content)
3773 (progn (delete-overlay o) t)))
3774 (overlays-in (point-min) (point-max)))))
3776 (defun org-agenda-get-day-face (date)
3777 "Return the face DATE should be displayed with."
3778 (or (and (functionp org-agenda-day-face-function)
3779 (funcall org-agenda-day-face-function date))
3780 (cond ((org-agenda-todayp date)
3781 'org-agenda-date-today)
3782 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3783 'org-agenda-date-weekend)
3784 (t 'org-agenda-date))))
3786 ;;; Agenda timeline
3788 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3790 (defun org-timeline (&optional dotodo)
3791 "Show a time-sorted view of the entries in the current org file.
3792 Only entries with a time stamp of today or later will be listed. With
3793 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3794 under the current date.
3795 If the buffer contains an active region, only check the region for
3796 dates."
3797 (interactive "P")
3798 (let* ((dopast t)
3799 (org-agenda-show-log-scoped org-agenda-show-log)
3800 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3801 (current-buffer))))
3802 (date (calendar-current-date))
3803 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3804 (end (if (org-region-active-p) (region-end) (point-max)))
3805 (day-numbers (org-get-all-dates
3806 beg end 'no-ranges
3807 t org-agenda-show-log-scoped ; always include today
3808 org-timeline-show-empty-dates))
3809 (org-deadline-warning-days 0)
3810 (org-agenda-only-exact-dates t)
3811 (today (org-today))
3812 (past t)
3813 args
3814 s e rtn d emptyp)
3815 (setq org-agenda-redo-command
3816 (list 'progn
3817 (list 'org-switch-to-buffer-other-window (current-buffer))
3818 (list 'org-timeline (list 'quote dotodo))))
3819 (if (not dopast)
3820 ;; Remove past dates from the list of dates.
3821 (setq day-numbers (delq nil (mapcar (lambda(x)
3822 (if (>= x today) x nil))
3823 day-numbers))))
3824 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3825 (org-compile-prefix-format 'timeline)
3826 (org-set-sorting-strategy 'timeline)
3827 (if org-agenda-show-log-scoped (push :closed args))
3828 (push :timestamp args)
3829 (push :deadline args)
3830 (push :scheduled args)
3831 (push :sexp args)
3832 (if dotodo (push :todo args))
3833 (insert "Timeline of file " entry "\n")
3834 (add-text-properties (point-min) (point)
3835 (list 'face 'org-agenda-structure))
3836 (org-agenda-mark-header-line (point-min))
3837 (while (setq d (pop day-numbers))
3838 (if (and (listp d) (eq (car d) :omitted))
3839 (progn
3840 (setq s (point))
3841 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3842 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3843 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3844 (if (and (>= d today)
3845 dopast
3846 past)
3847 (progn
3848 (setq past nil)
3849 (insert (make-string 79 ?-) "\n")))
3850 (setq date (calendar-gregorian-from-absolute d))
3851 (setq s (point))
3852 (setq rtn (and (not emptyp)
3853 (apply 'org-agenda-get-day-entries entry
3854 date args)))
3855 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3856 (progn
3857 (insert
3858 (if (stringp org-agenda-format-date)
3859 (format-time-string org-agenda-format-date
3860 (org-time-from-absolute date))
3861 (funcall org-agenda-format-date date))
3862 "\n")
3863 (put-text-property s (1- (point)) 'face
3864 (org-agenda-get-day-face date))
3865 (put-text-property s (1- (point)) 'org-date-line t)
3866 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3867 (if (equal d today)
3868 (put-text-property s (1- (point)) 'org-today t))
3869 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3870 (put-text-property s (1- (point)) 'day d)))))
3871 (goto-char (point-min))
3872 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3873 (point-min)))
3874 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3875 (org-agenda-finalize)
3876 (setq buffer-read-only t)))
3878 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3879 "Return a list of all relevant day numbers from BEG to END buffer positions.
3880 If NO-RANGES is non-nil, include only the start and end dates of a range,
3881 not every single day in the range. If FORCE-TODAY is non-nil, make
3882 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3883 inactive time stamps (those in square brackets) are included.
3884 When EMPTY is non-nil, also include days without any entries."
3885 (let ((re (concat
3886 (if pre-re pre-re "")
3887 (if inactive org-ts-regexp-both org-ts-regexp)))
3888 dates dates1 date day day1 day2 ts1 ts2 pos)
3889 (if force-today
3890 (setq dates (list (org-today))))
3891 (save-excursion
3892 (goto-char beg)
3893 (while (re-search-forward re end t)
3894 (setq day (time-to-days (org-time-string-to-time
3895 (substring (match-string 1) 0 10)
3896 (current-buffer) (match-beginning 0))))
3897 (or (memq day dates) (push day dates)))
3898 (unless no-ranges
3899 (goto-char beg)
3900 (while (re-search-forward org-tr-regexp end t)
3901 (setq pos (match-beginning 0))
3902 (setq ts1 (substring (match-string 1) 0 10)
3903 ts2 (substring (match-string 2) 0 10)
3904 day1 (time-to-days (org-time-string-to-time
3905 ts1 (current-buffer) pos))
3906 day2 (time-to-days (org-time-string-to-time
3907 ts2 (current-buffer) pos)))
3908 (while (< (setq day1 (1+ day1)) day2)
3909 (or (memq day1 dates) (push day1 dates)))))
3910 (setq dates (sort dates '<))
3911 (when empty
3912 (while (setq day (pop dates))
3913 (setq day2 (car dates))
3914 (push day dates1)
3915 (when (and day2 empty)
3916 (if (or (eq empty t)
3917 (and (numberp empty) (<= (- day2 day) empty)))
3918 (while (< (setq day (1+ day)) day2)
3919 (push (list day) dates1))
3920 (push (cons :omitted (- day2 day)) dates1))))
3921 (setq dates (nreverse dates1)))
3922 dates)))
3924 ;;; Agenda Daily/Weekly
3926 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3927 "Start day for the agenda view.
3928 Custom commands can set this variable in the options section.")
3929 (defvar org-starting-day nil) ; local variable in the agenda buffer
3930 (defvar org-arg-loc nil) ; local variable
3932 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3933 "List of types searched for when creating the daily/weekly agenda.
3934 This variable is a list of symbols that controls the types of
3935 items that appear in the daily/weekly agenda. Allowed symbols in this
3936 list are are
3938 :timestamp List items containing a date stamp or date range matching
3939 the selected date. This includes sexp entries in
3940 angular brackets.
3942 :sexp List entries resulting from plain diary-like sexps.
3944 :deadline List deadline due on that date. When the date is today,
3945 also list any deadlines past due, or due within
3946 `org-deadline-warning-days'. `:deadline' must appear before
3947 `:scheduled' if the setting of
3948 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3949 any effect.
3951 :scheduled List all items which are scheduled for the given date.
3952 The diary for *today* also contains items which were
3953 scheduled earlier and are not yet marked DONE.
3955 By default, all four types are turned on.
3957 Never set this variable globally using `setq', because then it
3958 will apply to all future agenda commands. Instead, bind it with
3959 `let' to scope it dynamically into the agenda-constructing
3960 command. A good way to set it is through options in
3961 `org-agenda-custom-commands'. For a more flexible (though
3962 somewhat less efficient) way of determining what is included in
3963 the daily/weekly agenda, see `org-agenda-skip-function'.")
3965 (defvar org-agenda-buffer-tmp-name nil)
3966 ;;;###autoload
3967 (defun org-agenda-list (&optional arg start-day span)
3968 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3969 The view will be for the current day or week, but from the overview buffer
3970 you will be able to go to other days/weeks.
3972 With a numeric prefix argument in an interactive call, the agenda will
3973 span ARG days. Lisp programs should instead specify SPAN to change
3974 the number of days. SPAN defaults to `org-agenda-span'.
3976 START-DAY defaults to TODAY, or to the most recent match for the weekday
3977 given in `org-agenda-start-on-weekday'."
3978 (interactive "P")
3979 (if org-agenda-overriding-arguments
3980 (setq arg (car org-agenda-overriding-arguments)
3981 start-day (nth 1 org-agenda-overriding-arguments)
3982 span (nth 2 org-agenda-overriding-arguments)))
3983 (if (and (integerp arg) (> arg 0))
3984 (setq span arg arg nil))
3985 (catch 'exit
3986 (setq org-agenda-buffer-name
3987 (or org-agenda-buffer-tmp-name
3988 (if org-agenda-sticky
3989 (cond ((and org-keys (stringp org-match))
3990 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3991 (org-keys
3992 (format "*Org Agenda(%s)*" org-keys))
3993 (t "*Org Agenda(a)*")))
3994 org-agenda-buffer-name))
3995 (org-agenda-prepare "Day/Week")
3996 (setq start-day (or start-day org-agenda-start-day))
3997 (if (stringp start-day)
3998 ;; Convert to an absolute day number
3999 (setq start-day (time-to-days (org-read-date nil t start-day))))
4000 (org-compile-prefix-format 'agenda)
4001 (org-set-sorting-strategy 'agenda)
4002 (let* ((span (org-agenda-ndays-to-span
4003 (or span org-agenda-ndays org-agenda-span)))
4004 (today (org-today))
4005 (sd (or start-day today))
4006 (ndays (org-agenda-span-to-ndays span sd))
4007 (org-agenda-start-on-weekday
4008 (if (eq ndays 7)
4009 org-agenda-start-on-weekday))
4010 (thefiles (org-agenda-files nil 'ifmode))
4011 (files thefiles)
4012 (start (if (or (null org-agenda-start-on-weekday)
4013 (< ndays 7))
4015 (let* ((nt (calendar-day-of-week
4016 (calendar-gregorian-from-absolute sd)))
4017 (n1 org-agenda-start-on-weekday)
4018 (d (- nt n1)))
4019 (- sd (+ (if (< d 0) 7 0) d)))))
4020 (day-numbers (list start))
4021 (day-cnt 0)
4022 (inhibit-redisplay (not debug-on-error))
4023 (org-agenda-show-log-scoped org-agenda-show-log)
4024 s e rtn rtnall file date d start-pos end-pos todayp
4025 clocktable-start clocktable-end filter)
4026 (setq org-agenda-redo-command
4027 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4028 (dotimes (n (1- ndays))
4029 (push (1+ (car day-numbers)) day-numbers))
4030 (setq day-numbers (nreverse day-numbers))
4031 (setq clocktable-start (car day-numbers)
4032 clocktable-end (1+ (or (org-last day-numbers) 0)))
4033 (org-set-local 'org-starting-day (car day-numbers))
4034 (org-set-local 'org-arg-loc arg)
4035 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4036 (unless org-agenda-compact-blocks
4037 (let* ((d1 (car day-numbers))
4038 (d2 (org-last day-numbers))
4039 (w1 (org-days-to-iso-week d1))
4040 (w2 (org-days-to-iso-week d2)))
4041 (setq s (point))
4042 (if org-agenda-overriding-header
4043 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4044 nil 'face 'org-agenda-structure) "\n")
4045 (insert (org-agenda-span-name span)
4046 "-agenda"
4047 (if (< (- d2 d1) 350)
4048 (if (= w1 w2)
4049 (format " (W%02d)" w1)
4050 (format " (W%02d-W%02d)" w1 w2))
4052 ":\n")))
4053 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4054 'org-date-line t))
4055 (org-agenda-mark-header-line s))
4056 (while (setq d (pop day-numbers))
4057 (setq date (calendar-gregorian-from-absolute d)
4058 s (point))
4059 (if (or (setq todayp (= d today))
4060 (and (not start-pos) (= d sd)))
4061 (setq start-pos (point))
4062 (if (and start-pos (not end-pos))
4063 (setq end-pos (point))))
4064 (setq files thefiles
4065 rtnall nil)
4066 (while (setq file (pop files))
4067 (catch 'nextfile
4068 (org-check-agenda-file file)
4069 (let ((org-agenda-entry-types org-agenda-entry-types))
4070 (unless org-agenda-include-deadlines
4071 (setq org-agenda-entry-types
4072 (delq :deadline org-agenda-entry-types)))
4073 (cond
4074 ((memq org-agenda-show-log-scoped '(only clockcheck))
4075 (setq rtn (org-agenda-get-day-entries
4076 file date :closed)))
4077 (org-agenda-show-log-scoped
4078 (setq rtn (apply 'org-agenda-get-day-entries
4079 file date
4080 (append '(:closed) org-agenda-entry-types))))
4082 (setq rtn (apply 'org-agenda-get-day-entries
4083 file date
4084 org-agenda-entry-types)))))
4085 (setq rtnall (append rtnall rtn)))) ;; all entries
4086 (if org-agenda-include-diary
4087 (let ((org-agenda-search-headline-for-time t))
4088 (require 'diary-lib)
4089 (setq rtn (org-get-entries-from-diary date))
4090 (setq rtnall (append rtnall rtn))))
4091 (if (or rtnall org-agenda-show-all-dates)
4092 (progn
4093 (setq day-cnt (1+ day-cnt))
4094 (insert
4095 (if (stringp org-agenda-format-date)
4096 (format-time-string org-agenda-format-date
4097 (org-time-from-absolute date))
4098 (funcall org-agenda-format-date date))
4099 "\n")
4100 (put-text-property s (1- (point)) 'face
4101 (org-agenda-get-day-face date))
4102 (put-text-property s (1- (point)) 'org-date-line t)
4103 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4104 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4105 (when todayp
4106 (put-text-property s (1- (point)) 'org-today t))
4107 (setq rtnall
4108 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4109 (if rtnall (insert ;; all entries
4110 (org-agenda-finalize-entries rtnall)
4111 "\n"))
4112 (put-text-property s (1- (point)) 'day d)
4113 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4114 (when (and org-agenda-clockreport-mode clocktable-start)
4115 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4116 ;; the above line is to ensure the restricted range!
4117 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4118 tbl)
4119 (setq p (org-plist-delete p :block))
4120 (setq p (plist-put p :tstart clocktable-start))
4121 (setq p (plist-put p :tend clocktable-end))
4122 (setq p (plist-put p :scope 'agenda))
4123 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4124 (setq filter (or org-agenda-tag-filter-while-redo
4125 (get 'org-agenda-tag-filter :preset-filter))))
4126 (setq p (plist-put p :tags (mapconcat (lambda (x)
4127 (if (string-match "[<>=]" x)
4130 filter ""))))
4131 (setq tbl (apply 'org-clock-get-clocktable p))
4132 (insert tbl)))
4133 (goto-char (point-min))
4134 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4135 (unless (and (pos-visible-in-window-p (point-min))
4136 (pos-visible-in-window-p (point-max)))
4137 (goto-char (1- (point-max)))
4138 (recenter -1)
4139 (if (not (pos-visible-in-window-p (or start-pos 1)))
4140 (progn
4141 (goto-char (or start-pos 1))
4142 (recenter 1))))
4143 (goto-char (or start-pos 1))
4144 (add-text-properties (point-min) (point-max)
4145 `(org-agenda-type agenda
4146 org-last-args (,arg ,start-day ,span)
4147 org-redo-cmd ,org-agenda-redo-command
4148 org-series-cmd ,org-cmd))
4149 (if (eq org-agenda-show-log-scoped 'clockcheck)
4150 (org-agenda-show-clocking-issues))
4151 (org-agenda-finalize)
4152 (setq buffer-read-only t)
4153 (message ""))))
4155 (autoload 'org-agenda-list "org-agenda" "\
4156 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4157 The view will be for the current day or week, but from the overview buffer
4158 you will be able to go to other days/weeks.
4160 With a numeric prefix argument in an interactive call, the agenda will
4161 span ARG days. Lisp programs should instead specify SPAN to change
4162 the number of days. SPAN defaults to `org-agenda-span'.
4164 START-DAY defaults to TODAY, or to the most recent match for the weekday
4165 given in `org-agenda-start-on-weekday'.
4167 \(fn &optional ARG START-DAY SPAN)" t nil)
4169 (defun org-agenda-ndays-to-span (n)
4170 "Return a span symbol for a span of N days, or N if none matches."
4171 (cond ((symbolp n) n)
4172 ((= n 1) 'day)
4173 ((= n 7) 'week)
4174 (t n)))
4176 (defun org-agenda-span-to-ndays (span &optional start-day)
4177 "Return ndays from SPAN, possibly starting at START-DAY."
4178 (cond ((numberp span) span)
4179 ((eq span 'day) 1)
4180 ((eq span 'week) 7)
4181 ((eq span 'month)
4182 (let ((date (calendar-gregorian-from-absolute start-day)))
4183 (calendar-last-day-of-month (car date) (caddr date))))
4184 ((eq span 'year)
4185 (let ((date (calendar-gregorian-from-absolute start-day)))
4186 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4188 (defun org-agenda-span-name (span)
4189 "Return a SPAN name."
4190 (if (null span)
4192 (if (symbolp span)
4193 (capitalize (symbol-name span))
4194 (format "%d days" span))))
4196 ;;; Agenda word search
4198 (defvar org-agenda-search-history nil)
4200 (defvar org-search-syntax-table nil
4201 "Special syntax table for org-mode search.
4202 In this table, we have single quotes not as word constituents, to
4203 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4205 (defvar org-mode-syntax-table) ; From org.el
4206 (defun org-search-syntax-table ()
4207 (unless org-search-syntax-table
4208 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4209 (modify-syntax-entry ?' "." org-search-syntax-table)
4210 (modify-syntax-entry ?` "." org-search-syntax-table))
4211 org-search-syntax-table)
4213 (defvar org-agenda-last-search-view-search-was-boolean nil)
4215 ;;;###autoload
4216 (defun org-search-view (&optional todo-only string edit-at)
4217 "Show all entries that contain a phrase or words or regular expressions.
4219 With optional prefix argument TODO-ONLY, only consider entries that are
4220 TODO entries. The argument STRING can be used to pass a default search
4221 string into this function. If EDIT-AT is non-nil, it means that the
4222 user should get a chance to edit this string, with cursor at position
4223 EDIT-AT.
4225 The search string can be viewed either as a phrase that should be found as
4226 is, or it can be broken into a number of snippets, each of which must match
4227 in a Boolean way to select an entry. The default depends on the variable
4228 `org-agenda-search-view-always-boolean'.
4229 Even if this is turned off (the default) you can always switch to
4230 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4232 The default is a direct search of the whole phrase, where each space in
4233 the search string can expand to an arbitrary amount of whitespace,
4234 including newlines.
4236 If using a Boolean search, the search string is split on whitespace and
4237 each snippet is searched separately, with logical AND to select an entry.
4238 Words prefixed with a minus must *not* occur in the entry. Words without
4239 a prefix or prefixed with a plus must occur in the entry. Matching is
4240 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4241 match whole words, not parts of a word) if
4242 `org-agenda-search-view-force-full-words' is set (default is nil).
4244 Boolean search snippets enclosed by curly braces are interpreted as
4245 regular expressions that must or (when preceded with \"-\") must not
4246 match in the entry. Snippets enclosed into double quotes will be taken
4247 as a whole, to include whitespace.
4249 - If the search string starts with an asterisk, search only in headlines.
4250 - If (possibly after the leading star) the search string starts with an
4251 exclamation mark, this also means to look at TODO entries only, an effect
4252 that can also be achieved with a prefix argument.
4253 - If (possibly after star and exclamation mark) the search string starts
4254 with a colon, this will mean that the (non-regexp) snippets of the
4255 Boolean search must match as full words.
4257 This command searches the agenda files, and in addition the files listed
4258 in `org-agenda-text-search-extra-files'."
4259 (interactive "P")
4260 (if org-agenda-overriding-arguments
4261 (setq todo-only (car org-agenda-overriding-arguments)
4262 string (nth 1 org-agenda-overriding-arguments)
4263 edit-at (nth 2 org-agenda-overriding-arguments)))
4264 (let* ((props (list 'face nil
4265 'done-face 'org-agenda-done
4266 'org-not-done-regexp org-not-done-regexp
4267 'org-todo-regexp org-todo-regexp
4268 'org-complex-heading-regexp org-complex-heading-regexp
4269 'mouse-face 'highlight
4270 'help-echo (format "mouse-2 or RET jump to location")))
4271 (full-words org-agenda-search-view-force-full-words)
4272 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4273 regexp rtn rtnall files file pos
4274 marker category category-pos level tags c neg re boolean
4275 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4276 (unless (and (not edit-at)
4277 (stringp string)
4278 (string-match "\\S-" string))
4279 (setq string (read-string
4280 (if org-agenda-search-view-always-boolean
4281 "[+-]Word/{Regexp} ...: "
4282 "Phrase or [+-]Word/{Regexp} ...: ")
4283 (cond
4284 ((integerp edit-at) (cons string edit-at))
4285 (edit-at string))
4286 'org-agenda-search-history)))
4287 (catch 'exit
4288 (if org-agenda-sticky
4289 (setq org-agenda-buffer-name
4290 (if (stringp string)
4291 (format "*Org Agenda(%s:%s)*"
4292 (or org-keys (or (and todo-only "S") "s")) string)
4293 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4294 (org-agenda-prepare "SEARCH")
4295 (org-compile-prefix-format 'search)
4296 (org-set-sorting-strategy 'search)
4297 (setq org-agenda-redo-command
4298 (list 'org-search-view (if todo-only t nil)
4299 (list 'if 'current-prefix-arg nil string)))
4300 (setq org-agenda-query-string string)
4301 (if (equal (string-to-char string) ?*)
4302 (setq hdl-only t
4303 words (substring string 1))
4304 (setq words string))
4305 (when (equal (string-to-char words) ?!)
4306 (setq todo-only t
4307 words (substring words 1)))
4308 (when (equal (string-to-char words) ?:)
4309 (setq full-words t
4310 words (substring words 1)))
4311 (if (or org-agenda-search-view-always-boolean
4312 (member (string-to-char words) '(?- ?+ ?\{)))
4313 (setq boolean t))
4314 (setq words (org-split-string words))
4315 (let (www w)
4316 (while (setq w (pop words))
4317 (while (and (string-match "\\\\\\'" w) words)
4318 (setq w (concat (substring w 0 -1) " " (pop words))))
4319 (push w www))
4320 (setq words (nreverse www) www nil)
4321 (while (setq w (pop words))
4322 (when (and (string-match "\\`[-+]?{" w)
4323 (not (string-match "}\\'" w)))
4324 (while (and words (not (string-match "}\\'" (car words))))
4325 (setq w (concat w " " (pop words))))
4326 (setq w (concat w " " (pop words))))
4327 (push w www))
4328 (setq words (nreverse www)))
4329 (setq org-agenda-last-search-view-search-was-boolean boolean)
4330 (when boolean
4331 (let (wds w)
4332 (while (setq w (pop words))
4333 (if (or (equal (substring w 0 1) "\"")
4334 (and (> (length w) 1)
4335 (member (substring w 0 1) '("+" "-"))
4336 (equal (substring w 1 2) "\"")))
4337 (while (and words (not (equal (substring w -1) "\"")))
4338 (setq w (concat w " " (pop words)))))
4339 (and (string-match "\\`\\([-+]?\\)\"" w)
4340 (setq w (replace-match "\\1" nil nil w)))
4341 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4342 (push w wds))
4343 (setq words (nreverse wds))))
4344 (if boolean
4345 (mapc (lambda (w)
4346 (setq c (string-to-char w))
4347 (if (equal c ?-)
4348 (setq neg t w (substring w 1))
4349 (if (equal c ?+)
4350 (setq neg nil w (substring w 1))
4351 (setq neg nil)))
4352 (if (string-match "\\`{.*}\\'" w)
4353 (setq re (substring w 1 -1))
4354 (if full-words
4355 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4356 (setq re (regexp-quote (downcase w)))))
4357 (if neg (push re regexps-) (push re regexps+)))
4358 words)
4359 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4360 regexps+))
4361 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4362 (if (not regexps+)
4363 (setq regexp org-outline-regexp-bol)
4364 (setq regexp (pop regexps+))
4365 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4366 regexp))))
4367 (setq files (org-agenda-files nil 'ifmode))
4368 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4369 (pop org-agenda-text-search-extra-files)
4370 (setq files (org-add-archive-files files)))
4371 (setq files (append files org-agenda-text-search-extra-files)
4372 rtnall nil)
4373 (while (setq file (pop files))
4374 (setq ee nil)
4375 (catch 'nextfile
4376 (org-check-agenda-file file)
4377 (setq buffer (if (file-exists-p file)
4378 (org-get-agenda-file-buffer file)
4379 (error "No such file %s" file)))
4380 (if (not buffer)
4381 ;; If file does not exist, make sure an error message is sent
4382 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4383 file))))
4384 (with-current-buffer buffer
4385 (with-syntax-table (org-search-syntax-table)
4386 (unless (derived-mode-p 'org-mode)
4387 (error "Agenda file %s is not in `org-mode'" file))
4388 (let ((case-fold-search t))
4389 (save-excursion
4390 (save-restriction
4391 (if org-agenda-restrict
4392 (narrow-to-region org-agenda-restrict-begin
4393 org-agenda-restrict-end)
4394 (widen))
4395 (goto-char (point-min))
4396 (unless (or (org-at-heading-p)
4397 (outline-next-heading))
4398 (throw 'nextfile t))
4399 (goto-char (max (point-min) (1- (point))))
4400 (while (re-search-forward regexp nil t)
4401 (org-back-to-heading t)
4402 (skip-chars-forward "* ")
4403 (setq beg (point-at-bol)
4404 beg1 (point)
4405 end (progn (outline-next-heading) (point)))
4406 (catch :skip
4407 (goto-char beg)
4408 (org-agenda-skip)
4409 (setq str (buffer-substring-no-properties
4410 (point-at-bol)
4411 (if hdl-only (point-at-eol) end)))
4412 (mapc (lambda (wr) (when (string-match wr str)
4413 (goto-char (1- end))
4414 (throw :skip t)))
4415 regexps-)
4416 (mapc (lambda (wr) (unless (string-match wr str)
4417 (goto-char (1- end))
4418 (throw :skip t)))
4419 (if todo-only
4420 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4421 regexps+)
4422 regexps+))
4423 (goto-char beg)
4424 (setq marker (org-agenda-new-marker (point))
4425 category (org-get-category)
4426 level (make-string (org-reduced-level (org-outline-level)) ? )
4427 category-pos (get-text-property (point) 'org-category-position)
4428 tags (org-get-tags-at (point))
4429 txt (org-agenda-format-item
4431 (buffer-substring-no-properties
4432 beg1 (point-at-eol))
4433 level category tags t))
4434 (org-add-props txt props
4435 'org-marker marker 'org-hd-marker marker
4436 'org-todo-regexp org-todo-regexp
4437 'level level
4438 'org-complex-heading-regexp org-complex-heading-regexp
4439 'priority 1000 'org-category category
4440 'org-category-position category-pos
4441 'type "search")
4442 (push txt ee)
4443 (goto-char (1- end))))))))))
4444 (setq rtn (nreverse ee))
4445 (setq rtnall (append rtnall rtn)))
4446 (if org-agenda-overriding-header
4447 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4448 nil 'face 'org-agenda-structure) "\n")
4449 (insert "Search words: ")
4450 (add-text-properties (point-min) (1- (point))
4451 (list 'face 'org-agenda-structure))
4452 (setq pos (point))
4453 (insert string "\n")
4454 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4455 (setq pos (point))
4456 (unless org-agenda-multi
4457 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4458 (add-text-properties pos (1- (point))
4459 (list 'face 'org-agenda-structure))))
4460 (org-agenda-mark-header-line (point-min))
4461 (when rtnall
4462 (insert (org-agenda-finalize-entries rtnall) "\n"))
4463 (goto-char (point-min))
4464 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4465 (add-text-properties (point-min) (point-max)
4466 `(org-agenda-type search
4467 org-last-args (,todo-only ,string ,edit-at)
4468 org-redo-cmd ,org-agenda-redo-command
4469 org-series-cmd ,org-cmd))
4470 (org-agenda-finalize)
4471 (setq buffer-read-only t))))
4473 (autoload 'org-search-view "org-agenda" "\
4474 Show all entries that contain a phrase or words or regular expressions.
4476 With optional prefix argument TODO-ONLY, only consider entries that are
4477 TODO entries. The argument STRING can be used to pass a default search
4478 string into this function. If EDIT-AT is non-nil, it means that the
4479 user should get a chance to edit this string, with cursor at position
4480 EDIT-AT.
4482 The search string can be viewed either as a phrase that should be found as
4483 is, or it can be broken into a number of snippets, each of which must match
4484 in a Boolean way to select an entry. The default depends on the variable
4485 `org-agenda-search-view-always-boolean'.
4486 Even if this is turned off (the default) you can always switch to
4487 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4489 The default is a direct search of the whole phrase, where each space in
4490 the search string can expand to an arbitrary amount of whitespace,
4491 including newlines.
4493 If using a Boolean search, the search string is split on whitespace and
4494 each snippet is searched separately, with logical AND to select an entry.
4495 Words prefixed with a minus must *not* occur in the entry. Words without
4496 a prefix or prefixed with a plus must occur in the entry. Matching is
4497 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4498 match whole words, not parts of a word) if
4499 `org-agenda-search-view-force-full-words' is set (default is nil).
4501 Boolean search snippets enclosed by curly braces are interpreted as
4502 regular expressions that must or (when preceded with \"-\") must not
4503 match in the entry. Snippets enclosed into double quotes will be taken
4504 as a whole, to include whitespace.
4506 - If the search string starts with an asterisk, search only in headlines.
4507 - If (possibly after the leading star) the search string starts with an
4508 exclamation mark, this also means to look at TODO entries only, an effect
4509 that can also be achieved with a prefix argument.
4510 - If (possibly after star and exclamation mark) the search string starts
4511 with a colon, this will mean that the (non-regexp) snippets of the
4512 Boolean search must match as full words.
4514 This command searches the agenda files, and in addition the files listed
4515 in `org-agenda-text-search-extra-files'.
4517 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4519 ;;; Agenda TODO list
4521 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4522 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4523 (concat
4524 (if (or (equal keywords "ALL") (not keywords))
4525 (propertize "ALL" 'face 'warning)
4526 (mapconcat
4527 (lambda (kw)
4528 (propertize kw 'face (org-get-todo-face kw)))
4529 (org-split-string keywords "|")
4530 "|"))
4531 "\n"))
4533 (defvar org-select-this-todo-keyword nil)
4534 (defvar org-last-arg nil)
4536 ;;;###autoload
4537 (defun org-todo-list (&optional arg)
4538 "Show all (not done) TODO entries from all agenda file in a single list.
4539 The prefix arg can be used to select a specific TODO keyword and limit
4540 the list to these. When using \\[universal-argument], you will be prompted
4541 for a keyword. A numeric prefix directly selects the Nth keyword in
4542 `org-todo-keywords-1'."
4543 (interactive "P")
4544 (if org-agenda-overriding-arguments
4545 (setq arg org-agenda-overriding-arguments))
4546 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4547 (let* ((today (org-today))
4548 (date (calendar-gregorian-from-absolute today))
4549 (kwds org-todo-keywords-for-agenda)
4550 (completion-ignore-case t)
4551 (org-select-this-todo-keyword
4552 (if (stringp arg) arg
4553 (and arg (integerp arg) (> arg 0)
4554 (nth (1- arg) kwds))))
4555 rtn rtnall files file pos)
4556 (when (equal arg '(4))
4557 (setq org-select-this-todo-keyword
4558 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4559 (mapcar 'list kwds) nil nil)))
4560 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4561 (catch 'exit
4562 (if org-agenda-sticky
4563 (setq org-agenda-buffer-name
4564 (if (stringp org-select-this-todo-keyword)
4565 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4566 org-select-this-todo-keyword)
4567 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4568 (org-agenda-prepare "TODO")
4569 (org-compile-prefix-format 'todo)
4570 (org-set-sorting-strategy 'todo)
4571 (setq org-agenda-redo-command
4572 `(org-todo-list (or (and (numberp current-prefix-arg)
4573 current-prefix-arg)
4574 ,org-select-this-todo-keyword
4575 current-prefix-arg ,arg)))
4576 (setq files (org-agenda-files nil 'ifmode)
4577 rtnall nil)
4578 (while (setq file (pop files))
4579 (catch 'nextfile
4580 (org-check-agenda-file file)
4581 (setq rtn (org-agenda-get-day-entries file date :todo))
4582 (setq rtnall (append rtnall rtn))))
4583 (if org-agenda-overriding-header
4584 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4585 nil 'face 'org-agenda-structure) "\n")
4586 (insert "Global list of TODO items of type: ")
4587 (add-text-properties (point-min) (1- (point))
4588 (list 'face 'org-agenda-structure
4589 'short-heading
4590 (concat "ToDo: "
4591 (or org-select-this-todo-keyword "ALL"))))
4592 (org-agenda-mark-header-line (point-min))
4593 (insert (org-agenda-propertize-selected-todo-keywords
4594 org-select-this-todo-keyword))
4595 (setq pos (point))
4596 (unless org-agenda-multi
4597 (insert "Available with `N r': (0)[ALL]")
4598 (let ((n 0) s)
4599 (mapc (lambda (x)
4600 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4601 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4602 (insert "\n "))
4603 (insert " " s))
4604 kwds))
4605 (insert "\n"))
4606 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4607 (org-agenda-mark-header-line (point-min))
4608 (when rtnall
4609 (insert (org-agenda-finalize-entries rtnall) "\n"))
4610 (goto-char (point-min))
4611 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4612 (add-text-properties (point-min) (point-max)
4613 `(org-agenda-type todo
4614 org-last-args ,arg
4615 org-redo-cmd ,org-agenda-redo-command
4616 org-series-cmd ,org-cmd))
4617 (org-agenda-finalize)
4618 (setq buffer-read-only t))))
4620 (autoload 'org-todo-list "org-agenda" "\
4621 Show all (not done) TODO entries from all agenda file in a single list.
4622 The prefix arg can be used to select a specific TODO keyword and limit
4623 the list to these. When using \\[universal-argument], you will be prompted
4624 for a keyword. A numeric prefix directly selects the Nth keyword in
4625 `org-todo-keywords-1'.
4627 \(fn &optional ARG)" t nil)
4629 ;;; Agenda tags match
4631 ;;;###autoload
4632 (defun org-tags-view (&optional todo-only match)
4633 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4634 The prefix arg TODO-ONLY limits the search to TODO entries."
4635 (interactive "P")
4636 (if org-agenda-overriding-arguments
4637 (setq todo-only (car org-agenda-overriding-arguments)
4638 match (nth 1 org-agenda-overriding-arguments)))
4639 (let* ((org-tags-match-list-sublevels
4640 org-tags-match-list-sublevels)
4641 (completion-ignore-case t)
4642 rtn rtnall files file pos matcher
4643 buffer)
4644 (when (and (stringp match) (not (string-match "\\S-" match)))
4645 (setq match nil))
4646 (setq matcher (org-make-tags-matcher match)
4647 match (car matcher) matcher (cdr matcher))
4648 (catch 'exit
4649 (if org-agenda-sticky
4650 (setq org-agenda-buffer-name
4651 (if (stringp match)
4652 (format "*Org Agenda(%s:%s)*"
4653 (or org-keys (or (and todo-only "M") "m")) match)
4654 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4655 (org-agenda-prepare (concat "TAGS " match))
4656 (org-compile-prefix-format 'tags)
4657 (org-set-sorting-strategy 'tags)
4658 (setq org-agenda-query-string match)
4659 (setq org-agenda-redo-command
4660 (list 'org-tags-view `(quote ,todo-only)
4661 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4662 (setq files (org-agenda-files nil 'ifmode)
4663 rtnall nil)
4664 (while (setq file (pop files))
4665 (catch 'nextfile
4666 (org-check-agenda-file file)
4667 (setq buffer (if (file-exists-p file)
4668 (org-get-agenda-file-buffer file)
4669 (error "No such file %s" file)))
4670 (if (not buffer)
4671 ;; If file does not exist, error message to agenda
4672 (setq rtn (list
4673 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4674 rtnall (append rtnall rtn))
4675 (with-current-buffer buffer
4676 (unless (derived-mode-p 'org-mode)
4677 (error "Agenda file %s is not in `org-mode'" file))
4678 (save-excursion
4679 (save-restriction
4680 (if org-agenda-restrict
4681 (narrow-to-region org-agenda-restrict-begin
4682 org-agenda-restrict-end)
4683 (widen))
4684 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4685 (setq rtnall (append rtnall rtn))))))))
4686 (if org-agenda-overriding-header
4687 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4688 nil 'face 'org-agenda-structure) "\n")
4689 (insert "Headlines with TAGS match: ")
4690 (add-text-properties (point-min) (1- (point))
4691 (list 'face 'org-agenda-structure
4692 'short-heading
4693 (concat "Match: " match)))
4694 (setq pos (point))
4695 (insert match "\n")
4696 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4697 (setq pos (point))
4698 (unless org-agenda-multi
4699 (insert "Press `C-u r' to search again with new search string\n"))
4700 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4701 (org-agenda-mark-header-line (point-min))
4702 (when rtnall
4703 (insert (org-agenda-finalize-entries rtnall) "\n"))
4704 (goto-char (point-min))
4705 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4706 (add-text-properties (point-min) (point-max)
4707 `(org-agenda-type tags
4708 org-last-args (,todo-only ,match)
4709 org-redo-cmd ,org-agenda-redo-command
4710 org-series-cmd ,org-cmd))
4711 (org-agenda-finalize)
4712 (setq buffer-read-only t))))
4714 (autoload 'org-tags-view "org-agenda" "\
4715 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4716 The prefix arg TODO-ONLY limits the search to TODO entries.
4718 \(fn &optional TODO-ONLY MATCH)" t nil)
4720 ;;; Agenda Finding stuck projects
4722 (defvar org-agenda-skip-regexp nil
4723 "Regular expression used in skipping subtrees for the agenda.
4724 This is basically a temporary global variable that can be set and then
4725 used by user-defined selections using `org-agenda-skip-function'.")
4727 (defvar org-agenda-overriding-header nil
4728 "When set during agenda, todo and tags searches it replaces the header.
4729 This variable should not be set directly, but custom commands can bind it
4730 in the options section.")
4732 (defun org-agenda-skip-entry-when-regexp-matches ()
4733 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4734 If yes, it returns the end position of this entry, causing agenda commands
4735 to skip the entry but continuing the search in the subtree. This is a
4736 function that can be put into `org-agenda-skip-function' for the duration
4737 of a command."
4738 (let ((end (save-excursion (org-end-of-subtree t)))
4739 skip)
4740 (save-excursion
4741 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4742 (and skip end)))
4744 (defun org-agenda-skip-subtree-when-regexp-matches ()
4745 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4746 If yes, it returns the end position of this tree, causing agenda commands
4747 to skip this subtree. This is a function that can be put into
4748 `org-agenda-skip-function' for the duration of a command."
4749 (let ((end (save-excursion (org-end-of-subtree t)))
4750 skip)
4751 (save-excursion
4752 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4753 (and skip end)))
4755 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4756 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4757 If yes, it returns the end position of the current entry (NOT the tree),
4758 causing agenda commands to skip the entry but continuing the search in
4759 the subtree. This is a function that can be put into
4760 `org-agenda-skip-function' for the duration of a command. An important
4761 use of this function is for the stuck project list."
4762 (let ((end (save-excursion (org-end-of-subtree t)))
4763 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4764 skip)
4765 (save-excursion
4766 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4767 (and skip entry-end)))
4769 (defun org-agenda-skip-entry-if (&rest conditions)
4770 "Skip entry if any of CONDITIONS is true.
4771 See `org-agenda-skip-if' for details."
4772 (org-agenda-skip-if nil conditions))
4774 (defun org-agenda-skip-subtree-if (&rest conditions)
4775 "Skip entry if any of CONDITIONS is true.
4776 See `org-agenda-skip-if' for details."
4777 (org-agenda-skip-if t conditions))
4779 (defun org-agenda-skip-if (subtree conditions)
4780 "Checks current entity for CONDITIONS.
4781 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4782 the entry (i.e. the text before the next heading) is checked.
4784 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4785 from different tests. Valid conditions are:
4787 scheduled Check if there is a scheduled cookie
4788 notscheduled Check if there is no scheduled cookie
4789 deadline Check if there is a deadline
4790 notdeadline Check if there is no deadline
4791 timestamp Check if there is a timestamp (also deadline or scheduled)
4792 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4793 regexp Check if regexp matches
4794 notregexp Check if regexp does not match.
4795 todo Check if TODO keyword matches
4796 nottodo Check if TODO keyword does not match
4798 The regexp is taken from the conditions list, it must come right after
4799 the `regexp' or `notregexp' element.
4801 `todo' and `nottodo' accept as an argument a list of todo
4802 keywords, which may include \"*\" to match any todo keyword.
4804 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4806 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4808 Instead of a list, a keyword class may be given. For example:
4810 (org-agenda-skip-entry-if 'nottodo 'done)
4812 would skip entries that haven't been marked with any of \"DONE\"
4813 keywords. Possible classes are: `todo', `done', `any'.
4815 If any of these conditions is met, this function returns the end point of
4816 the entity, causing the search to continue from there. This is a function
4817 that can be put into `org-agenda-skip-function' for the duration of a command."
4818 (let (beg end m)
4819 (org-back-to-heading t)
4820 (setq beg (point)
4821 end (if subtree
4822 (progn (org-end-of-subtree t) (point))
4823 (progn (outline-next-heading) (1- (point)))))
4824 (goto-char beg)
4825 (and
4827 (and (memq 'scheduled conditions)
4828 (re-search-forward org-scheduled-time-regexp end t))
4829 (and (memq 'notscheduled conditions)
4830 (not (re-search-forward org-scheduled-time-regexp end t)))
4831 (and (memq 'deadline conditions)
4832 (re-search-forward org-deadline-time-regexp end t))
4833 (and (memq 'notdeadline conditions)
4834 (not (re-search-forward org-deadline-time-regexp end t)))
4835 (and (memq 'timestamp conditions)
4836 (re-search-forward org-ts-regexp end t))
4837 (and (memq 'nottimestamp conditions)
4838 (not (re-search-forward org-ts-regexp end t)))
4839 (and (setq m (memq 'regexp conditions))
4840 (stringp (nth 1 m))
4841 (re-search-forward (nth 1 m) end t))
4842 (and (setq m (memq 'notregexp conditions))
4843 (stringp (nth 1 m))
4844 (not (re-search-forward (nth 1 m) end t)))
4845 (and (or
4846 (setq m (memq 'nottodo conditions))
4847 (setq m (memq 'todo-unblocked conditions))
4848 (setq m (memq 'nottodo-unblocked conditions))
4849 (setq m (memq 'todo conditions)))
4850 (org-agenda-skip-if-todo m end)))
4851 end)))
4853 (defun org-agenda-skip-if-todo (args end)
4854 "Helper function for `org-agenda-skip-if', do not use it directly.
4855 ARGS is a list with first element either `todo', `nottodo',
4856 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4857 a list of TODO keywords, or a state symbol `todo' or `done' or
4858 `any'."
4859 (let ((kw (car args))
4860 (arg (cadr args))
4861 todo-wds todo-re)
4862 (setq todo-wds
4863 (org-uniquify
4864 (cond
4865 ((listp arg) ;; list of keywords
4866 (if (member "*" arg)
4867 (mapcar 'substring-no-properties org-todo-keywords-1)
4868 arg))
4869 ((symbolp arg) ;; keyword class name
4870 (cond
4871 ((eq arg 'todo)
4872 (org-delete-all org-done-keywords
4873 (mapcar 'substring-no-properties
4874 org-todo-keywords-1)))
4875 ((eq arg 'done) org-done-keywords)
4876 ((eq arg 'any)
4877 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4878 (setq todo-re
4879 (concat "^\\*+[ \t]+\\<\\("
4880 (mapconcat 'identity todo-wds "\\|")
4881 "\\)\\>"))
4882 (cond
4883 ((eq kw 'todo) (re-search-forward todo-re end t))
4884 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4885 ((eq kw 'todo-unblocked)
4886 (catch 'unblocked
4887 (while (re-search-forward todo-re end t)
4888 (or (org-entry-blocked-p) (throw 'unblocked t)))
4889 nil))
4890 ((eq kw 'nottodo-unblocked)
4891 (catch 'unblocked
4892 (while (re-search-forward todo-re end t)
4893 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4897 ;;;###autoload
4898 (defun org-agenda-list-stuck-projects (&rest ignore)
4899 "Create agenda view for projects that are stuck.
4900 Stuck projects are project that have no next actions. For the definitions
4901 of what a project is and how to check if it stuck, customize the variable
4902 `org-stuck-projects'."
4903 (interactive)
4904 (let* ((org-agenda-skip-function
4905 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4906 ;; We could have used org-agenda-skip-if here.
4907 (org-agenda-overriding-header
4908 (or org-agenda-overriding-header "List of stuck projects: "))
4909 (matcher (nth 0 org-stuck-projects))
4910 (todo (nth 1 org-stuck-projects))
4911 (todo-wds (if (member "*" todo)
4912 (progn
4913 (org-agenda-prepare-buffers (org-agenda-files
4914 nil 'ifmode))
4915 (org-delete-all
4916 org-done-keywords-for-agenda
4917 (copy-sequence org-todo-keywords-for-agenda)))
4918 todo))
4919 (todo-re (concat "^\\*+[ \t]+\\("
4920 (mapconcat 'identity todo-wds "\\|")
4921 "\\)\\>"))
4922 (tags (nth 2 org-stuck-projects))
4923 (tags-re (if (member "*" tags)
4924 (concat org-outline-regexp-bol
4925 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4926 (if tags
4927 (concat org-outline-regexp-bol
4928 ".*:\\("
4929 (mapconcat 'identity tags "\\|")
4930 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4931 (gen-re (nth 3 org-stuck-projects))
4932 (re-list
4933 (delq nil
4934 (list
4935 (if todo todo-re)
4936 (if tags tags-re)
4937 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4938 gen-re)))))
4939 (setq org-agenda-skip-regexp
4940 (if re-list
4941 (mapconcat 'identity re-list "\\|")
4942 (error "No information how to identify unstuck projects")))
4943 (org-tags-view nil matcher)
4944 (with-current-buffer org-agenda-buffer-name
4945 (setq org-agenda-redo-command
4946 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4948 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4949 Create agenda view for projects that are stuck.
4950 Stuck projects are project that have no next actions. For the definitions
4951 of what a project is and how to check if it stuck, customize the variable
4952 `org-stuck-projects'.
4954 \(fn &rest IGNORE)" t nil)
4956 ;;; Diary integration
4958 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4959 (defvar diary-list-entries-hook)
4960 (defvar diary-time-regexp)
4961 (defun org-get-entries-from-diary (date)
4962 "Get the (Emacs Calendar) diary entries for DATE."
4963 (require 'diary-lib)
4964 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4965 (diary-display-hook '(fancy-diary-display))
4966 (diary-display-function 'fancy-diary-display)
4967 (pop-up-frames nil)
4968 (diary-list-entries-hook
4969 (cons 'org-diary-default-entry diary-list-entries-hook))
4970 (diary-file-name-prefix-function nil) ; turn this feature off
4971 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4972 entries
4973 (org-disable-agenda-to-diary t))
4974 (save-excursion
4975 (save-window-excursion
4976 (funcall (if (fboundp 'diary-list-entries)
4977 'diary-list-entries 'list-diary-entries)
4978 date 1)))
4979 (if (not (get-buffer diary-fancy-buffer))
4980 (setq entries nil)
4981 (with-current-buffer diary-fancy-buffer
4982 (setq buffer-read-only nil)
4983 (if (zerop (buffer-size))
4984 ;; No entries
4985 (setq entries nil)
4986 ;; Omit the date and other unnecessary stuff
4987 (org-agenda-cleanup-fancy-diary)
4988 ;; Add prefix to each line and extend the text properties
4989 (if (zerop (buffer-size))
4990 (setq entries nil)
4991 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4992 (setq entries
4993 (with-temp-buffer
4994 (insert entries) (goto-char (point-min))
4995 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4996 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4997 (replace-match (concat "; " (match-string 1)))))
4998 (buffer-string)))))
4999 (set-buffer-modified-p nil)
5000 (kill-buffer diary-fancy-buffer)))
5001 (when entries
5002 (setq entries (org-split-string entries "\n"))
5003 (setq entries
5004 (mapcar
5005 (lambda (x)
5006 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5007 ;; Extend the text properties to the beginning of the line
5008 (org-add-props x (text-properties-at (1- (length x)) x)
5009 'type "diary" 'date date 'face 'org-agenda-diary))
5010 entries)))))
5012 (defvar org-agenda-cleanup-fancy-diary-hook nil
5013 "Hook run when the fancy diary buffer is cleaned up.")
5015 (defun org-agenda-cleanup-fancy-diary ()
5016 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5017 This gets rid of the date, the underline under the date, and
5018 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5019 date. It also removes lines that contain only whitespace."
5020 (goto-char (point-min))
5021 (if (looking-at ".*?:[ \t]*")
5022 (progn
5023 (replace-match "")
5024 (re-search-forward "\n=+$" nil t)
5025 (replace-match "")
5026 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5027 (re-search-forward "\n=+$" nil t)
5028 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5029 (goto-char (point-min))
5030 (while (re-search-forward "^ +\n" nil t)
5031 (replace-match ""))
5032 (goto-char (point-min))
5033 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5034 (replace-match ""))
5035 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5037 ;; Make sure entries from the diary have the right text properties.
5038 (eval-after-load "diary-lib"
5039 '(if (boundp 'diary-modify-entry-list-string-function)
5040 ;; We can rely on the hook, nothing to do
5042 ;; Hook not available, must use advice to make this work
5043 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5044 "Make the position visible."
5045 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5046 (stringp string)
5047 buffer-file-name)
5048 (setq string (org-modify-diary-entry-string string))))))
5050 (defun org-modify-diary-entry-string (string)
5051 "Add text properties to string, allowing org-mode to act on it."
5052 (org-add-props string nil
5053 'mouse-face 'highlight
5054 'help-echo (if buffer-file-name
5055 (format "mouse-2 or RET jump to diary file %s"
5056 (abbreviate-file-name buffer-file-name))
5058 'org-agenda-diary-link t
5059 'org-marker (org-agenda-new-marker (point-at-bol))))
5061 (defun org-diary-default-entry ()
5062 "Add a dummy entry to the diary.
5063 Needed to avoid empty dates which mess up holiday display."
5064 ;; Catch the error if dealing with the new add-to-diary-alist
5065 (when org-disable-agenda-to-diary
5066 (condition-case nil
5067 (org-add-to-diary-list original-date "Org-mode dummy" "")
5068 (error
5069 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5071 (defun org-add-to-diary-list (&rest args)
5072 (if (fboundp 'diary-add-to-list)
5073 (apply 'diary-add-to-list args)
5074 (apply 'add-to-diary-list args)))
5076 (defvar org-diary-last-run-time nil)
5078 ;;;###autoload
5079 (defun org-diary (&rest args)
5080 "Return diary information from org files.
5081 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5082 It accesses org files and extracts information from those files to be
5083 listed in the diary. The function accepts arguments specifying what
5084 items should be listed. For a list of arguments allowed here, see the
5085 variable `org-agenda-entry-types'.
5087 The call in the diary file should look like this:
5089 &%%(org-diary) ~/path/to/some/orgfile.org
5091 Use a separate line for each org file to check. Or, if you omit the file name,
5092 all files listed in `org-agenda-files' will be checked automatically:
5094 &%%(org-diary)
5096 If you don't give any arguments (as in the example above), the default
5097 arguments (:deadline :scheduled :timestamp :sexp) are used.
5098 So the example above may also be written as
5100 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5102 The function expects the lisp variables `entry' and `date' to be provided
5103 by the caller, because this is how the calendar works. Don't use this
5104 function from a program - use `org-agenda-get-day-entries' instead."
5105 (when (> (- (org-float-time)
5106 org-agenda-last-marker-time)
5108 ;; I am not sure if this works with sticky agendas, because the marker
5109 ;; list is then no longer a global variable.
5110 (org-agenda-reset-markers))
5111 (org-compile-prefix-format 'agenda)
5112 (org-set-sorting-strategy 'agenda)
5113 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5114 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5115 (list entry)
5116 (org-agenda-files t)))
5117 (time (org-float-time))
5118 file rtn results)
5119 (when (or (not org-diary-last-run-time)
5120 (> (- time
5121 org-diary-last-run-time)
5123 (org-agenda-prepare-buffers files))
5124 (setq org-diary-last-run-time time)
5125 ;; If this is called during org-agenda, don't return any entries to
5126 ;; the calendar. Org Agenda will list these entries itself.
5127 (if org-disable-agenda-to-diary (setq files nil))
5128 (while (setq file (pop files))
5129 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5130 (setq results (append results rtn)))
5131 (if results
5132 (concat (org-agenda-finalize-entries results) "\n"))))
5134 (autoload 'org-diary "org-agenda" "\
5135 Return diary information from org files.
5136 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5137 It accesses org files and extracts information from those files to be
5138 listed in the diary. The function accepts arguments specifying what
5139 items should be listed. For a list of arguments allowed here, see the
5140 variable `org-agenda-entry-types'.
5142 The call in the diary file should look like this:
5144 &%%(org-diary) ~/path/to/some/orgfile.org
5146 Use a separate line for each org file to check. Or, if you omit the file name,
5147 all files listed in `org-agenda-files' will be checked automatically:
5149 &%%(org-diary)
5151 If you don't give any arguments (as in the example above), the default
5152 arguments (:deadline :scheduled :timestamp :sexp) are used.
5153 So the example above may also be written as
5155 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5157 The function expects the lisp variables `entry' and `date' to be provided
5158 by the caller, because this is how the calendar works. Don't use this
5159 function from a program - use `org-agenda-get-day-entries' instead.
5161 \(fn &rest ARGS)" nil nil)
5163 ;;; Agenda entry finders
5165 (defun org-agenda-get-day-entries (file date &rest args)
5166 "Does the work for `org-diary' and `org-agenda'.
5167 FILE is the path to a file to be checked for entries. DATE is date like
5168 the one returned by `calendar-current-date'. ARGS are symbols indicating
5169 which kind of entries should be extracted. For details about these, see
5170 the documentation of `org-diary'."
5171 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5172 (let* ((org-startup-folded nil)
5173 (org-startup-align-all-tables nil)
5174 (buffer (if (file-exists-p file)
5175 (org-get-agenda-file-buffer file)
5176 (error "No such file %s" file)))
5177 arg results rtn deadline-results)
5178 (if (not buffer)
5179 ;; If file does not exist, make sure an error message ends up in diary
5180 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5181 (with-current-buffer buffer
5182 (unless (derived-mode-p 'org-mode)
5183 (error "Agenda file %s is not in `org-mode'" file))
5184 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5185 (let ((case-fold-search nil))
5186 (save-excursion
5187 (save-restriction
5188 (if org-agenda-restrict
5189 (narrow-to-region org-agenda-restrict-begin
5190 org-agenda-restrict-end)
5191 (widen))
5192 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5193 (while (setq arg (pop args))
5194 (cond
5195 ((and (eq arg :todo)
5196 (equal date (calendar-gregorian-from-absolute
5197 (org-today))))
5198 (setq rtn (org-agenda-get-todos))
5199 (setq results (append results rtn)))
5200 ((eq arg :timestamp)
5201 (setq rtn (org-agenda-get-blocks))
5202 (setq results (append results rtn))
5203 (setq rtn (org-agenda-get-timestamps deadline-results))
5204 (setq results (append results rtn)))
5205 ((eq arg :sexp)
5206 (setq rtn (org-agenda-get-sexps))
5207 (setq results (append results rtn)))
5208 ((eq arg :scheduled)
5209 (setq rtn (org-agenda-get-scheduled deadline-results))
5210 (setq results (append results rtn)))
5211 ((eq arg :closed)
5212 (setq rtn (org-agenda-get-progress))
5213 (setq results (append results rtn)))
5214 ((eq arg :deadline)
5215 (setq rtn (org-agenda-get-deadlines))
5216 (setq deadline-results (copy-sequence rtn))
5217 (setq results (append results rtn))))))))
5218 results))))
5220 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5221 (defun org-agenda-get-todos ()
5222 "Return the TODO information for agenda display."
5223 (let* ((props (list 'face nil
5224 'done-face 'org-agenda-done
5225 'org-not-done-regexp org-not-done-regexp
5226 'org-todo-regexp org-todo-regexp
5227 'org-complex-heading-regexp org-complex-heading-regexp
5228 'mouse-face 'highlight
5229 'help-echo
5230 (format "mouse-2 or RET jump to org file %s"
5231 (abbreviate-file-name buffer-file-name))))
5232 (regexp (format org-heading-keyword-regexp-format
5233 (cond
5234 ((and org-select-this-todo-keyword
5235 (equal org-select-this-todo-keyword "*"))
5236 org-todo-regexp)
5237 (org-select-this-todo-keyword
5238 (concat "\\("
5239 (mapconcat 'identity
5240 (org-split-string
5241 org-select-this-todo-keyword
5242 "|")
5243 "\\|") "\\)"))
5244 (t org-not-done-regexp))))
5245 marker priority category category-pos level tags todo-state
5246 ee txt beg end)
5247 (goto-char (point-min))
5248 (while (re-search-forward regexp nil t)
5249 (catch :skip
5250 (save-match-data
5251 (beginning-of-line)
5252 (org-agenda-skip)
5253 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5254 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5255 (goto-char (1+ beg))
5256 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5257 (throw :skip nil)))
5258 (goto-char (match-beginning 2))
5259 (setq marker (org-agenda-new-marker (match-beginning 0))
5260 category (org-get-category)
5261 category-pos (get-text-property (point) 'org-category-position)
5262 txt (org-trim
5263 (buffer-substring (match-beginning 2) (match-end 0)))
5264 tags (org-get-tags-at (point))
5265 level (make-string (org-reduced-level (org-outline-level)) ? )
5266 txt (org-agenda-format-item "" txt level category tags t)
5267 priority (1+ (org-get-priority txt))
5268 todo-state (org-get-todo-state))
5269 (org-add-props txt props
5270 'org-marker marker 'org-hd-marker marker
5271 'priority priority 'org-category category
5272 'level level
5273 'org-category-position category-pos
5274 'type "todo" 'todo-state todo-state)
5275 (push txt ee)
5276 (if org-agenda-todo-list-sublevels
5277 (goto-char (match-end 2))
5278 (org-end-of-subtree 'invisible))))
5279 (nreverse ee)))
5281 (defun org-agenda-todo-custom-ignore-p (time n)
5282 "Check whether timestamp is farther away than n number of days.
5283 This function is invoked if `org-agenda-todo-ignore-deadlines',
5284 `org-agenda-todo-ignore-scheduled' or
5285 `org-agenda-todo-ignore-timestamp' is set to an integer."
5286 (let ((days (org-time-stamp-to-now
5287 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5288 (if (>= n 0)
5289 (>= days n)
5290 (<= days n))))
5292 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5293 (&optional end)
5294 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5295 (when (or org-agenda-todo-ignore-with-date
5296 org-agenda-todo-ignore-scheduled
5297 org-agenda-todo-ignore-deadlines
5298 org-agenda-todo-ignore-timestamp)
5299 (setq end (or end (save-excursion (outline-next-heading) (point))))
5300 (save-excursion
5301 (or (and org-agenda-todo-ignore-with-date
5302 (re-search-forward org-ts-regexp end t))
5303 (and org-agenda-todo-ignore-scheduled
5304 (re-search-forward org-scheduled-time-regexp end t)
5305 (cond
5306 ((eq org-agenda-todo-ignore-scheduled 'future)
5307 (> (org-time-stamp-to-now
5308 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5309 ((eq org-agenda-todo-ignore-scheduled 'past)
5310 (<= (org-time-stamp-to-now
5311 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5312 ((numberp org-agenda-todo-ignore-scheduled)
5313 (org-agenda-todo-custom-ignore-p
5314 (match-string 1) org-agenda-todo-ignore-scheduled))
5315 (t)))
5316 (and org-agenda-todo-ignore-deadlines
5317 (re-search-forward org-deadline-time-regexp end t)
5318 (cond
5319 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5320 ((eq org-agenda-todo-ignore-deadlines 'far)
5321 (not (org-deadline-close (match-string 1))))
5322 ((eq org-agenda-todo-ignore-deadlines 'future)
5323 (> (org-time-stamp-to-now
5324 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5325 ((eq org-agenda-todo-ignore-deadlines 'past)
5326 (<= (org-time-stamp-to-now
5327 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5328 ((numberp org-agenda-todo-ignore-deadlines)
5329 (org-agenda-todo-custom-ignore-p
5330 (match-string 1) org-agenda-todo-ignore-deadlines))
5331 (t (org-deadline-close (match-string 1)))))
5332 (and org-agenda-todo-ignore-timestamp
5333 (let ((buffer (current-buffer))
5334 (regexp
5335 (concat
5336 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5337 (start (point)))
5338 ;; Copy current buffer into a temporary one
5339 (with-temp-buffer
5340 (insert-buffer-substring buffer start end)
5341 (goto-char (point-min))
5342 ;; Delete SCHEDULED and DEADLINE items
5343 (while (re-search-forward regexp end t)
5344 (delete-region (match-beginning 0) (match-end 0)))
5345 (goto-char (point-min))
5346 ;; No search for timestamp left
5347 (when (re-search-forward org-ts-regexp nil t)
5348 (cond
5349 ((eq org-agenda-todo-ignore-timestamp 'future)
5350 (> (org-time-stamp-to-now
5351 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5352 ((eq org-agenda-todo-ignore-timestamp 'past)
5353 (<= (org-time-stamp-to-now
5354 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5355 ((numberp org-agenda-todo-ignore-timestamp)
5356 (org-agenda-todo-custom-ignore-p
5357 (match-string 1) org-agenda-todo-ignore-timestamp))
5358 (t))))))))))
5360 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5361 Do we have a reason to ignore this TODO entry because it has a time stamp?
5363 \(fn &optional END)" nil nil)
5365 (defconst org-agenda-no-heading-message
5366 "No heading for this item in buffer or region.")
5368 (defun org-agenda-get-timestamps (&optional deadline-results)
5369 "Return the date stamp information for agenda display."
5370 (let* ((props (list 'face 'org-agenda-calendar-event
5371 'org-not-done-regexp org-not-done-regexp
5372 'org-todo-regexp org-todo-regexp
5373 'org-complex-heading-regexp org-complex-heading-regexp
5374 'mouse-face 'highlight
5375 'help-echo
5376 (format "mouse-2 or RET jump to org file %s"
5377 (abbreviate-file-name buffer-file-name))))
5378 (d1 (calendar-absolute-from-gregorian date))
5380 (deadline-position-alist
5381 (mapcar (lambda (a) (and (setq mm (get-text-property
5382 0 'org-hd-marker a))
5383 (cons (marker-position mm) a)))
5384 deadline-results))
5385 (remove-re org-ts-regexp)
5386 (regexp
5387 (concat
5388 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5389 (regexp-quote
5390 (substring
5391 (format-time-string
5392 (car org-time-stamp-formats)
5393 (apply 'encode-time ; DATE bound by calendar
5394 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5395 1 11))
5396 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5397 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5398 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5399 donep tmp priority category category-pos level ee txt timestr tags
5400 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5401 (goto-char (point-min))
5402 (while (setq end-of-match (re-search-forward regexp nil t))
5403 (setq b0 (match-beginning 0)
5404 b3 (match-beginning 3) e3 (match-end 3)
5405 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5406 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5407 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5408 (member todo-state
5409 org-agenda-repeating-timestamp-show-all)))
5410 (catch :skip
5411 (and (org-at-date-range-p) (throw :skip nil))
5412 (org-agenda-skip)
5413 (if (and (match-end 1)
5414 (not (= d1 (org-time-string-to-absolute
5415 (match-string 1) d1 nil show-all
5416 (current-buffer) b0))))
5417 (throw :skip nil))
5418 (if (and e3
5419 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5420 (throw :skip nil))
5421 (setq tmp (buffer-substring (max (point-min)
5422 (- b0 org-ds-keyword-length))
5424 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5425 inactivep (= (char-after b0) ?\[)
5426 deadlinep (string-match org-deadline-regexp tmp)
5427 scheduledp (string-match org-scheduled-regexp tmp)
5428 closedp (and org-agenda-include-inactive-timestamps
5429 (string-match org-closed-string tmp))
5430 clockp (and org-agenda-include-inactive-timestamps
5431 (or (string-match org-clock-string tmp)
5432 (string-match "]-+\\'" tmp)))
5433 warntime (org-entry-get (point) "APPT_WARNTIME")
5434 donep (member todo-state org-done-keywords))
5435 (if (or scheduledp deadlinep closedp clockp
5436 (and donep org-agenda-skip-timestamp-if-done))
5437 (throw :skip t))
5438 (if (string-match ">" timestr)
5439 ;; substring should only run to end of time stamp
5440 (setq timestr (substring timestr 0 (match-end 0))))
5441 (setq marker (org-agenda-new-marker b0)
5442 category (org-get-category b0)
5443 category-pos (get-text-property b0 'org-category-position))
5444 (save-excursion
5445 (if (not (re-search-backward org-outline-regexp-bol nil t))
5446 (setq txt org-agenda-no-heading-message)
5447 (goto-char (match-beginning 0))
5448 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5449 (assoc (point) deadline-position-alist))
5450 (throw :skip nil))
5451 (setq hdmarker (org-agenda-new-marker)
5452 tags (org-get-tags-at)
5453 level (make-string (org-reduced-level (org-outline-level)) ? ))
5454 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5455 (setq head (or (match-string 1) ""))
5456 (setq txt (org-agenda-format-item
5457 (if inactivep org-agenda-inactive-leader nil)
5458 head level category tags timestr
5459 remove-re habitp)))
5460 (setq priority (org-get-priority txt))
5461 (org-add-props txt props 'priority priority
5462 'org-marker marker 'org-hd-marker hdmarker
5463 'org-category category 'date date
5464 'level level
5465 'org-category-position category-pos
5466 'todo-state todo-state
5467 'warntime warntime
5468 'type "timestamp")
5469 (push txt ee))
5470 (if org-agenda-skip-additional-timestamps-same-entry
5471 (outline-next-heading)
5472 (goto-char end-of-match))))
5473 (nreverse ee)))
5475 (defun org-agenda-get-sexps ()
5476 "Return the sexp information for agenda display."
5477 (require 'diary-lib)
5478 (let* ((props (list 'face 'org-agenda-calendar-sexp
5479 'mouse-face 'highlight
5480 'help-echo
5481 (format "mouse-2 or RET jump to org file %s"
5482 (abbreviate-file-name buffer-file-name))))
5483 (regexp "^&?%%(")
5484 marker category extra category-pos level ee txt tags entry
5485 result beg b sexp sexp-entry todo-state warntime)
5486 (goto-char (point-min))
5487 (while (re-search-forward regexp nil t)
5488 (catch :skip
5489 (org-agenda-skip)
5490 (setq beg (match-beginning 0))
5491 (goto-char (1- (match-end 0)))
5492 (setq b (point))
5493 (forward-sexp 1)
5494 (setq sexp (buffer-substring b (point)))
5495 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5496 (org-trim (match-string 1))
5497 ""))
5498 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5499 (when result
5500 (setq marker (org-agenda-new-marker beg)
5501 level (make-string (org-reduced-level (org-outline-level)) ? )
5502 category (org-get-category beg)
5503 category-pos (get-text-property beg 'org-category-position)
5504 tags (save-excursion (org-backward-heading-same-level 0)
5505 (org-get-tags-at))
5506 todo-state (org-get-todo-state)
5507 warntime (org-entry-get (point) "APPT_WARNTIME")
5508 extra nil)
5510 (dolist (r (if (stringp result)
5511 (list result)
5512 result)) ;; we expect a list here
5513 (when (and org-agenda-diary-sexp-prefix
5514 (string-match org-agenda-diary-sexp-prefix r))
5515 (setq extra (match-string 0 r)
5516 r (replace-match "" nil nil r)))
5517 (if (string-match "\\S-" r)
5518 (setq txt r)
5519 (setq txt "SEXP entry returned empty string"))
5520 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5521 (org-add-props txt props 'org-marker marker
5522 'org-category category 'date date 'todo-state todo-state
5523 'org-category-position category-pos 'tags tags
5524 'level level
5525 'type "sexp" 'warntime warntime)
5526 (push txt ee)))))
5527 (nreverse ee)))
5529 ;; Calendar sanity: define some functions that are independent of
5530 ;; `calendar-date-style'.
5531 ;; Normally I would like to use ISO format when calling the diary functions,
5532 ;; but to make sure we still have Emacs 22 compatibility we bind
5533 ;; also `european-calendar-style' and use european format
5534 (defun org-anniversary (year month day &optional mark)
5535 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5536 (org-no-warnings
5537 (let ((calendar-date-style 'european) (european-calendar-style t))
5538 (diary-anniversary day month year mark))))
5539 (defun org-cyclic (N year month day &optional mark)
5540 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5541 (org-no-warnings
5542 (let ((calendar-date-style 'european) (european-calendar-style t))
5543 (diary-cyclic N day month year mark))))
5544 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5545 "Like `diary-block', but with fixed (ISO) order of arguments."
5546 (org-no-warnings
5547 (let ((calendar-date-style 'european) (european-calendar-style t))
5548 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5549 (defun org-date (year month day &optional mark)
5550 "Like `diary-date', but with fixed (ISO) order of arguments."
5551 (org-no-warnings
5552 (let ((calendar-date-style 'european) (european-calendar-style t))
5553 (diary-date day month year mark))))
5554 (defalias 'org-float 'diary-float)
5556 ;; Define the` org-class' function
5557 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5558 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5559 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5560 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5561 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5562 `holidays', then any date that is known by the Emacs calendar to be a
5563 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5564 then those holidays will be skipped."
5565 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5566 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5567 (d (calendar-absolute-from-gregorian date))
5568 (h (when skip-weeks (calendar-check-holidays date))))
5569 (and
5570 (<= date1 d)
5571 (<= d date2)
5572 (= (calendar-day-of-week date) dayname)
5573 (or (not skip-weeks)
5574 (progn
5575 (require 'cal-iso)
5576 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5577 (not (or (and h (memq 'holidays skip-weeks))
5578 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5579 entry)))
5581 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5582 "Like `org-class', but honor `calendar-date-style'.
5583 The order of the first 2 times 3 arguments depends on the variable
5584 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5585 So for American calendars, give this as MONTH DAY YEAR, for European as
5586 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5587 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5588 is any number of ISO weeks in the block period for which the item should
5589 be skipped.
5591 This function is here only for backward compatibility and it is deprecated,
5592 please use `org-class' instead."
5593 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5594 (date2 (org-order-calendar-date-args m2 d2 y2)))
5595 (org-class
5596 (nth 2 date1) (car date1) (nth 1 date1)
5597 (nth 2 date2) (car date2) (nth 1 date2)
5598 dayname skip-weeks)))
5599 (make-obsolete 'org-diary-class 'org-class "")
5601 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5602 (defalias 'org-get-closed 'org-agenda-get-progress)
5603 (defun org-agenda-get-progress ()
5604 "Return the logged TODO entries for agenda display."
5605 (let* ((props (list 'mouse-face 'highlight
5606 'org-not-done-regexp org-not-done-regexp
5607 'org-todo-regexp org-todo-regexp
5608 'org-complex-heading-regexp org-complex-heading-regexp
5609 'help-echo
5610 (format "mouse-2 or RET jump to org file %s"
5611 (abbreviate-file-name buffer-file-name))))
5612 (items (if (consp org-agenda-show-log-scoped)
5613 org-agenda-show-log-scoped
5614 (if (eq org-agenda-show-log-scoped 'clockcheck)
5615 '(clock)
5616 org-agenda-log-mode-items)))
5617 (parts
5618 (delq nil
5619 (list
5620 (if (memq 'closed items) (concat "\\<" org-closed-string))
5621 (if (memq 'clock items) (concat "\\<" org-clock-string))
5622 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5623 (parts-re (if parts (mapconcat 'identity parts "\\|")
5624 (error "`org-agenda-log-mode-items' is empty")))
5625 (regexp (concat
5626 "\\(" parts-re "\\)"
5627 " *\\["
5628 (regexp-quote
5629 (substring
5630 (format-time-string
5631 (car org-time-stamp-formats)
5632 (apply 'encode-time ; DATE bound by calendar
5633 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5634 1 11))))
5635 (org-agenda-search-headline-for-time nil)
5636 marker hdmarker priority category category-pos level tags closedp
5637 statep clockp state ee txt extra timestr rest clocked)
5638 (goto-char (point-min))
5639 (while (re-search-forward regexp nil t)
5640 (catch :skip
5641 (org-agenda-skip)
5642 (setq marker (org-agenda-new-marker (match-beginning 0))
5643 closedp (equal (match-string 1) org-closed-string)
5644 statep (equal (string-to-char (match-string 1)) ?-)
5645 clockp (not (or closedp statep))
5646 state (and statep (match-string 2))
5647 category (org-get-category (match-beginning 0))
5648 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5649 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5650 (when (string-match "\\]" timestr)
5651 ;; substring should only run to end of time stamp
5652 (setq rest (substring timestr (match-end 0))
5653 timestr (substring timestr 0 (match-end 0)))
5654 (if (and (not closedp) (not statep)
5655 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5656 rest))
5657 (progn (setq timestr (concat (substring timestr 0 -1)
5658 "-" (match-string 1 rest) "]"))
5659 (setq clocked (match-string 2 rest)))
5660 (setq clocked "-")))
5661 (save-excursion
5662 (setq extra
5663 (cond
5664 ((not org-agenda-log-mode-add-notes) nil)
5665 (statep
5666 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5667 (match-string 1)))
5668 (clockp
5669 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5670 (match-string 1)))))
5671 (if (not (re-search-backward org-outline-regexp-bol nil t))
5672 (setq txt org-agenda-no-heading-message)
5673 (goto-char (match-beginning 0))
5674 (setq hdmarker (org-agenda-new-marker)
5675 tags (org-get-tags-at)
5676 level (make-string (org-reduced-level (org-outline-level)) ? ))
5677 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5678 (setq txt (match-string 1))
5679 (when extra
5680 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5681 (setq txt (concat (substring txt 0 (match-beginning 1))
5682 " - " extra " " (match-string 2 txt)))
5683 (setq txt (concat txt " - " extra))))
5684 (setq txt (org-agenda-format-item
5685 (cond
5686 (closedp "Closed: ")
5687 (statep (concat "State: (" state ")"))
5688 (t (concat "Clocked: (" clocked ")")))
5689 txt level category tags timestr)))
5690 (setq priority 100000)
5691 (org-add-props txt props
5692 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5693 'priority priority 'org-category category
5694 'org-category-position category-pos
5695 'level level
5696 'type "closed" 'date date
5697 'undone-face 'org-warning 'done-face 'org-agenda-done)
5698 (push txt ee))
5699 (goto-char (point-at-eol))))
5700 (nreverse ee)))
5702 (defun org-agenda-show-clocking-issues ()
5703 "Add overlays, showing issues with clocking.
5704 See also the user option `org-agenda-clock-consistency-checks'."
5705 (interactive)
5706 (let* ((pl org-agenda-clock-consistency-checks)
5707 (re (concat "^[ \t]*"
5708 org-clock-string
5709 "[ \t]+"
5710 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5711 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5712 (tlstart 0.)
5713 (tlend 0.)
5714 (maxtime (org-hh:mm-string-to-minutes
5715 (or (plist-get pl :max-duration) "24:00")))
5716 (mintime (org-hh:mm-string-to-minutes
5717 (or (plist-get pl :min-duration) 0)))
5718 (maxgap (org-hh:mm-string-to-minutes
5719 ;; default 30:00 means never complain
5720 (or (plist-get pl :max-gap) "30:00")))
5721 (gapok (mapcar 'org-hh:mm-string-to-minutes
5722 (plist-get pl :gap-ok-around)))
5723 (def-face (or (plist-get pl :default-face)
5724 '((:background "DarkRed") (:foreground "white"))))
5725 issue face m te ts dt ov)
5726 (goto-char (point-min))
5727 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5728 (setq issue nil face def-face)
5729 (catch 'next
5730 (setq m (org-get-at-bol 'org-marker)
5731 te nil ts nil)
5732 (unless (and m (markerp m))
5733 (setq issue "No valid clock line") (throw 'next t))
5734 (org-with-point-at m
5735 (save-excursion
5736 (goto-char (point-at-bol))
5737 (unless (looking-at re)
5738 (error "No valid Clock line")
5739 (throw 'next t))
5740 (unless (match-end 3)
5741 (setq issue "No end time"
5742 face (or (plist-get pl :no-end-time-face) face))
5743 (throw 'next t))
5744 (setq ts (match-string 1)
5745 te (match-string 3)
5746 ts (org-float-time
5747 (apply 'encode-time (org-parse-time-string ts)))
5748 te (org-float-time
5749 (apply 'encode-time (org-parse-time-string te)))
5750 dt (- te ts))))
5751 (cond
5752 ((> dt (* 60 maxtime))
5753 ;; a very long clocking chunk
5754 (setq issue (format "Clocking interval is very long: %s"
5755 (org-minutes-to-clocksum-string
5756 (floor (/ (float dt) 60.))))
5757 face (or (plist-get pl :long-face) face)))
5758 ((< dt (* 60 mintime))
5759 ;; a very short clocking chunk
5760 (setq issue (format "Clocking interval is very short: %s"
5761 (org-minutes-to-clocksum-string
5762 (floor (/ (float dt) 60.))))
5763 face (or (plist-get pl :short-face) face)))
5764 ((and (> tlend 0) (< ts tlend))
5765 ;; Two clock entries are overlapping
5766 (setq issue (format "Clocking overlap: %d minutes"
5767 (/ (- tlend ts) 60))
5768 face (or (plist-get pl :overlap-face) face)))
5769 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5770 ;; There is a gap, lets see if we need to report it
5771 (unless (org-agenda-check-clock-gap tlend ts gapok)
5772 (setq issue (format "Clocking gap: %d minutes"
5773 (/ (- ts tlend) 60))
5774 face (or (plist-get pl :gap-face) face))))
5775 (t nil)))
5776 (setq tlend (or te tlend) tlstart (or ts tlstart))
5777 (when issue
5778 ;; OK, there was some issue, add an overlay to show the issue
5779 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5780 (overlay-put ov 'before-string
5781 (concat
5782 (org-add-props
5783 (format "%-43s" (concat " " issue))
5785 'face face)
5786 "\n"))
5787 (overlay-put ov 'evaporate t)))))
5789 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5790 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5791 (catch 'exit
5792 (unless ok-list
5793 ;; there are no OK times for gaps...
5794 (throw 'exit nil))
5795 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5796 ;; This is more than 24 hours, so it is OK.
5797 ;; because we have at least one OK time, that must be in the
5798 ;; 24 hour interval.
5799 (throw 'exit t))
5800 ;; We have a shorter gap.
5801 ;; Now we have to get the minute of the day when these times are
5802 (let* ((t1dec (decode-time (seconds-to-time t1)))
5803 (t2dec (decode-time (seconds-to-time t2)))
5804 ;; compute the minute on the day
5805 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5806 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5807 (when (< min2 min1)
5808 ;; if min2 is smaller than min1, this means it is on the next day.
5809 ;; Wrap it to after midnight.
5810 (setq min2 (+ min2 1440)))
5811 ;; Now check if any of the OK times is in the gap
5812 (mapc (lambda (x)
5813 ;; Wrap the time to after midnight if necessary
5814 (if (< x min1) (setq x (+ x 1440)))
5815 ;; Check if in interval
5816 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5817 ok-list)
5818 ;; Nope, this gap is not OK
5819 nil)))
5821 (defun org-agenda-get-deadlines ()
5822 "Return the deadline information for agenda display."
5823 (let* ((props (list 'mouse-face 'highlight
5824 'org-not-done-regexp org-not-done-regexp
5825 'org-todo-regexp org-todo-regexp
5826 'org-complex-heading-regexp org-complex-heading-regexp
5827 'help-echo
5828 (format "mouse-2 or RET jump to org file %s"
5829 (abbreviate-file-name buffer-file-name))))
5830 (regexp org-deadline-time-regexp)
5831 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5832 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5833 d2 diff dfrac wdays pos pos1 category category-pos level
5834 tags suppress-prewarning ee txt head face s todo-state
5835 show-all upcomingp donep timestr warntime)
5836 (goto-char (point-min))
5837 (while (re-search-forward regexp nil t)
5838 (catch :skip
5839 (org-agenda-skip)
5840 (setq s (match-string 1)
5841 txt nil
5842 pos (1- (match-beginning 1))
5843 todo-state (save-match-data (org-get-todo-state))
5844 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5845 (member todo-state
5846 org-agenda-repeating-timestamp-show-all))
5847 d2 (org-time-string-to-absolute
5848 (match-string 1) d1 'past show-all
5849 (current-buffer) pos)
5850 diff (- d2 d1))
5851 (setq suppress-prewarning
5852 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5853 (let ((item (buffer-substring (point-at-bol)
5854 (point-at-eol))))
5855 (save-match-data
5856 (and (string-match
5857 org-scheduled-time-regexp item)
5858 (match-string 1 item)))))))
5859 (cond
5860 ((not ds) nil)
5861 ;; The current item has a scheduled date (in ds), so
5862 ;; evaluate its prewarning lead time.
5863 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5864 ;; Use global prewarning-restart lead time.
5865 org-agenda-skip-deadline-prewarning-if-scheduled)
5866 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5867 'pre-scheduled)
5868 ;; Set prewarning to no earlier than scheduled.
5869 (min (- d2 (org-time-string-to-absolute
5870 ds d1 'past show-all (current-buffer) pos))
5871 org-deadline-warning-days))
5872 ;; Set prewarning to deadline.
5873 (t 0))))
5874 (setq wdays (if suppress-prewarning
5875 (let ((org-deadline-warning-days suppress-prewarning))
5876 (org-get-wdays s))
5877 (org-get-wdays s))
5878 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5879 upcomingp (and todayp (> diff 0)))
5880 ;; When to show a deadline in the calendar:
5881 ;; If the expiration is within wdays warning time.
5882 ;; Past-due deadlines are only shown on the current date
5883 (if (and (or (and (<= diff wdays)
5884 (and todayp (not org-agenda-only-exact-dates)))
5885 (= diff 0)))
5886 (save-excursion
5887 ;; (setq todo-state (org-get-todo-state))
5888 (setq donep (member todo-state org-done-keywords))
5889 (if (and donep
5890 (or org-agenda-skip-deadline-if-done
5891 (not (= diff 0))))
5892 (setq txt nil)
5893 (setq category (org-get-category)
5894 warntime (org-entry-get (point) "APPT_WARNTIME")
5895 category-pos (get-text-property (point) 'org-category-position))
5896 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5897 (setq txt org-agenda-no-heading-message)
5898 (goto-char (match-end 0))
5899 (setq pos1 (match-beginning 0))
5900 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5901 (setq tags (org-get-tags-at pos1))
5902 (setq head (buffer-substring-no-properties
5903 (point)
5904 (progn (skip-chars-forward "^\r\n")
5905 (point))))
5906 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5907 (setq timestr
5908 (concat (substring s (match-beginning 1)) " "))
5909 (setq timestr 'time))
5910 (setq txt (org-agenda-format-item
5911 (if (= diff 0)
5912 (car org-agenda-deadline-leaders)
5913 (if (functionp
5914 (nth 1 org-agenda-deadline-leaders))
5915 (funcall
5916 (nth 1 org-agenda-deadline-leaders)
5917 diff date)
5918 (format (nth 1 org-agenda-deadline-leaders)
5919 diff)))
5920 head level category tags
5921 (if (not (= diff 0)) nil timestr)))))
5922 (when txt
5923 (setq face (org-agenda-deadline-face dfrac))
5924 (org-add-props txt props
5925 'org-marker (org-agenda-new-marker pos)
5926 'warntime warntime
5927 'level level
5928 'org-hd-marker (org-agenda-new-marker pos1)
5929 'priority (+ (- diff)
5930 (org-get-priority txt))
5931 'org-category category
5932 'org-category-position category-pos
5933 'todo-state todo-state
5934 'type (if upcomingp "upcoming-deadline" "deadline")
5935 'date (if upcomingp date d2)
5936 'face (if donep 'org-agenda-done face)
5937 'undone-face face 'done-face 'org-agenda-done)
5938 (push txt ee))))))
5939 (nreverse ee)))
5941 (defun org-agenda-deadline-face (fraction)
5942 "Return the face to displaying a deadline item.
5943 FRACTION is what fraction of the head-warning time has passed."
5944 (let ((faces org-agenda-deadline-faces) f)
5945 (catch 'exit
5946 (while (setq f (pop faces))
5947 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5949 (defun org-agenda-get-scheduled (&optional deadline-results)
5950 "Return the scheduled information for agenda display."
5951 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5952 'org-todo-regexp org-todo-regexp
5953 'org-complex-heading-regexp org-complex-heading-regexp
5954 'done-face 'org-agenda-done
5955 'mouse-face 'highlight
5956 'help-echo
5957 (format "mouse-2 or RET jump to org file %s"
5958 (abbreviate-file-name buffer-file-name))))
5959 (regexp org-scheduled-time-regexp)
5960 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5961 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5963 (deadline-position-alist
5964 (mapcar (lambda (a) (and (setq mm (get-text-property
5965 0 'org-hd-marker a))
5966 (cons (marker-position mm) a)))
5967 deadline-results))
5968 d2 diff pos pos1 category category-pos level tags donep
5969 ee txt head pastschedp todo-state face timestr s habitp show-all
5970 did-habit-check-p warntime)
5971 (goto-char (point-min))
5972 (while (re-search-forward regexp nil t)
5973 (catch :skip
5974 (org-agenda-skip)
5975 (setq s (match-string 1)
5976 txt nil
5977 pos (1- (match-beginning 1))
5978 todo-state (save-match-data (org-get-todo-state))
5979 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5980 (member todo-state
5981 org-agenda-repeating-timestamp-show-all))
5982 d2 (org-time-string-to-absolute
5983 (match-string 1) d1 'past show-all
5984 (current-buffer) pos)
5985 diff (- d2 d1)
5986 warntime (org-entry-get (point) "APPT_WARNTIME"))
5987 (setq pastschedp (and todayp (< diff 0)))
5988 (setq did-habit-check-p nil)
5989 ;; When to show a scheduled item in the calendar:
5990 ;; If it is on or past the date.
5991 (when (or (and (< diff 0)
5992 (< (abs diff) org-scheduled-past-days)
5993 (and todayp (not org-agenda-only-exact-dates)))
5994 (= diff 0)
5995 ;; org-is-habit-p uses org-entry-get, which is expansive
5996 ;; so we go extra mile to only call it once
5997 (and todayp
5998 (boundp 'org-habit-show-all-today)
5999 org-habit-show-all-today
6000 (setq did-habit-check-p t)
6001 (setq habitp (and (functionp 'org-is-habit-p)
6002 (org-is-habit-p)))))
6003 (save-excursion
6004 (setq donep (member todo-state org-done-keywords))
6005 (if (and donep
6006 (or org-agenda-skip-scheduled-if-done
6007 (not (= diff 0))
6008 (and (functionp 'org-is-habit-p)
6009 (org-is-habit-p))))
6010 (setq txt nil)
6011 (setq habitp (if did-habit-check-p habitp
6012 (and (functionp 'org-is-habit-p)
6013 (org-is-habit-p))))
6014 (setq category (org-get-category)
6015 category-pos (get-text-property (point) 'org-category-position))
6016 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6017 (setq txt org-agenda-no-heading-message)
6018 (goto-char (match-end 0))
6019 (setq pos1 (match-beginning 0))
6020 (if habitp
6021 (if (or (not org-habit-show-habits)
6022 (and (not todayp)
6023 (boundp 'org-habit-show-habits-only-for-today)
6024 org-habit-show-habits-only-for-today))
6025 (throw :skip nil))
6026 (if (and
6027 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6028 (and org-agenda-skip-scheduled-if-deadline-is-shown
6029 pastschedp))
6030 (setq mm (assoc pos1 deadline-position-alist)))
6031 (throw :skip nil)))
6032 (setq tags (org-get-tags-at))
6033 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6034 (setq head (buffer-substring-no-properties
6035 (point)
6036 (progn (skip-chars-forward "^\r\n") (point))))
6037 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6038 (setq timestr
6039 (concat (substring s (match-beginning 1)) " "))
6040 (setq timestr 'time))
6041 (setq txt (org-agenda-format-item
6042 (if (= diff 0)
6043 (car org-agenda-scheduled-leaders)
6044 (format (nth 1 org-agenda-scheduled-leaders)
6045 (- 1 diff)))
6046 head level category tags
6047 (if (not (= diff 0)) nil timestr)
6048 nil habitp))))
6049 (when txt
6050 (setq face
6051 (cond
6052 ((and (not habitp) pastschedp)
6053 'org-scheduled-previously)
6054 (todayp 'org-scheduled-today)
6055 (t 'org-scheduled))
6056 habitp (and habitp (org-habit-parse-todo)))
6057 (org-add-props txt props
6058 'undone-face face
6059 'face (if donep 'org-agenda-done face)
6060 'org-marker (org-agenda-new-marker pos)
6061 'org-hd-marker (org-agenda-new-marker pos1)
6062 'type (if pastschedp "past-scheduled" "scheduled")
6063 'date (if pastschedp d2 date)
6064 'warntime warntime
6065 'level level
6066 'priority (if habitp
6067 (org-habit-get-priority habitp)
6068 (+ 94 (- 5 diff) (org-get-priority txt)))
6069 'org-category category
6070 'category-position category-pos
6071 'org-habit-p habitp
6072 'todo-state todo-state)
6073 (push txt ee))))))
6074 (nreverse ee)))
6076 (defun org-agenda-get-blocks ()
6077 "Return the date-range information for agenda display."
6078 (let* ((props (list 'face nil
6079 'org-not-done-regexp org-not-done-regexp
6080 'org-todo-regexp org-todo-regexp
6081 'org-complex-heading-regexp org-complex-heading-regexp
6082 'mouse-face 'highlight
6083 'help-echo
6084 (format "mouse-2 or RET jump to org file %s"
6085 (abbreviate-file-name buffer-file-name))))
6086 (regexp org-tr-regexp)
6087 (d0 (calendar-absolute-from-gregorian date))
6088 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6089 level todo-state tags pos head donep)
6090 (goto-char (point-min))
6091 (while (re-search-forward regexp nil t)
6092 (catch :skip
6093 (org-agenda-skip)
6094 (setq pos (point))
6095 (let ((start-time (match-string 1))
6096 (end-time (match-string 2)))
6097 (setq s1 (match-string 1)
6098 s2 (match-string 2)
6099 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6100 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6101 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6102 ;; Only allow days between the limits, because the normal
6103 ;; date stamps will catch the limits.
6104 (save-excursion
6105 (setq todo-state (org-get-todo-state))
6106 (setq donep (member todo-state org-done-keywords))
6107 (if (and donep org-agenda-skip-timestamp-if-done)
6108 (throw :skip t))
6109 (setq marker (org-agenda-new-marker (point)))
6110 (setq category (org-get-category)
6111 category-pos (get-text-property (point) 'org-category-position))
6112 (if (not (re-search-backward org-outline-regexp-bol nil t))
6113 (setq txt org-agenda-no-heading-message)
6114 (goto-char (match-beginning 0))
6115 (setq hdmarker (org-agenda-new-marker (point)))
6116 (setq tags (org-get-tags-at))
6117 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6118 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6119 (setq head (match-string 1))
6120 (let ((remove-re
6121 (if org-agenda-remove-timeranges-from-blocks
6122 (concat
6123 "<" (regexp-quote s1) ".*?>"
6124 "--"
6125 "<" (regexp-quote s2) ".*?>")
6126 nil)))
6127 (setq txt (org-agenda-format-item
6128 (format
6129 (nth (if (= d1 d2) 0 1)
6130 org-agenda-timerange-leaders)
6131 (1+ (- d0 d1)) (1+ (- d2 d1)))
6132 head level category tags
6133 (cond ((and (= d1 d0) (= d2 d0))
6134 (concat "<" start-time ">--<" end-time ">"))
6135 ((= d1 d0)
6136 (concat "<" start-time ">"))
6137 ((= d2 d0)
6138 (concat "<" end-time ">")))
6139 remove-re))))
6140 (org-add-props txt props
6141 'org-marker marker 'org-hd-marker hdmarker
6142 'type "block" 'date date
6143 'level level
6144 'todo-state todo-state
6145 'priority (org-get-priority txt) 'org-category category
6146 'org-category-position category-pos)
6147 (push txt ee))))
6148 (goto-char pos)))
6149 ;; Sort the entries by expiration date.
6150 (nreverse ee)))
6152 ;;; Agenda presentation and sorting
6154 (defvar org-prefix-has-time nil
6155 "A flag, set by `org-compile-prefix-format'.
6156 The flag is set if the currently compiled format contains a `%t'.")
6157 (defvar org-prefix-has-tag nil
6158 "A flag, set by `org-compile-prefix-format'.
6159 The flag is set if the currently compiled format contains a `%T'.")
6160 (defvar org-prefix-has-effort nil
6161 "A flag, set by `org-compile-prefix-format'.
6162 The flag is set if the currently compiled format contains a `%e'.")
6163 (defvar org-prefix-category-length nil
6164 "Used by `org-compile-prefix-format' to remember the category field width.")
6165 (defvar org-prefix-category-max-length nil
6166 "Used by `org-compile-prefix-format' to remember the category field width.")
6168 (defun org-agenda-get-category-icon (category)
6169 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6170 (dolist (entry org-agenda-category-icon-alist)
6171 (when (org-string-match-p (car entry) category)
6172 (if (listp (cadr entry))
6173 (return (cadr entry))
6174 (return (apply 'create-image (cdr entry)))))))
6176 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6177 remove-re habitp)
6178 "Format TXT to be inserted into the agenda buffer.
6179 In particular, add the prefix and corresponding text properties.
6181 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6182 LEVEL may be a string to replace the `%l' specifier.
6183 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6184 category taken from local variable or file name. It will replace the `%c'
6185 specifier in the format.
6186 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6187 TXT for sorting of this entry, and for the `%t' specifier in the format.
6188 When DOTIME is a string, this string is searched for a time before TXT is.
6189 TAGS can be the tags of the headline.
6190 Any match of REMOVE-RE will be removed from TXT."
6191 ;; We keep the org-prefix-* variable values along with a compiled
6192 ;; formatter, so that multiple agendas existing at the same time do
6193 ;; not step on each other toes.
6195 ;; It was inconvenient to make these variables buffer local in
6196 ;; Agenda buffers, because this function expects to be called with
6197 ;; the buffer where item comes from being current, and not agenda
6198 ;; buffer
6199 (let* ((bindings (car org-prefix-format-compiled))
6200 (formatter (cadr org-prefix-format-compiled)))
6201 (loop for (var value) in bindings
6202 do (set var value))
6203 (save-match-data
6204 ;; Diary entries sometimes have extra whitespace at the beginning
6205 (setq txt (org-trim txt))
6207 ;; Fix the tags part in txt
6208 (setq txt (org-agenda-fix-displayed-tags
6209 txt tags
6210 org-agenda-show-inherited-tags
6211 org-agenda-hide-tags-regexp))
6213 (let* ((category (or category
6214 (if (stringp org-category)
6215 org-category
6216 (and org-category (symbol-name org-category)))
6217 (if buffer-file-name
6218 (file-name-sans-extension
6219 (file-name-nondirectory buffer-file-name))
6220 "")))
6221 (category-icon (org-agenda-get-category-icon category))
6222 (category-icon (if category-icon
6223 (propertize " " 'display category-icon)
6224 ""))
6225 ;; time, tag, effort are needed for the eval of the prefix format
6226 (tag (if tags (nth (1- (length tags)) tags) ""))
6227 time effort neffort
6228 (ts (if dotime (concat
6229 (if (stringp dotime) dotime "")
6230 (and org-agenda-search-headline-for-time txt))))
6231 (time-of-day (and dotime (org-get-time-of-day ts)))
6232 stamp plain s0 s1 s2 rtn srp l
6233 duration thecategory)
6234 (and (derived-mode-p 'org-mode) buffer-file-name
6235 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6236 (when (and dotime time-of-day)
6237 ;; Extract starting and ending time and move them to prefix
6238 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6239 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6240 (setq s0 (match-string 0 ts)
6241 srp (and stamp (match-end 3))
6242 s1 (match-string (if plain 1 2) ts)
6243 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6245 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6246 ;; them, we might want to remove them there to avoid duplication.
6247 ;; The user can turn this off with a variable.
6248 (if (and org-prefix-has-time
6249 org-agenda-remove-times-when-in-prefix (or stamp plain)
6250 (string-match (concat (regexp-quote s0) " *") txt)
6251 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6252 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6253 (= (match-beginning 0) 0)
6255 (setq txt (replace-match "" nil nil txt))))
6256 ;; Normalize the time(s) to 24 hour
6257 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6258 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6260 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6261 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6262 (setq s2
6263 (org-minutes-to-clocksum-string
6264 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6266 ;; Compute the duration
6267 (when s2
6268 (setq duration (- (org-hh:mm-string-to-minutes s2)
6269 (org-hh:mm-string-to-minutes s1)))))
6271 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6272 txt)
6273 ;; Tags are in the string
6274 (if (or (eq org-agenda-remove-tags t)
6275 (and org-agenda-remove-tags
6276 org-prefix-has-tag))
6277 (setq txt (replace-match "" t t txt))
6278 (setq txt (replace-match
6279 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6280 (match-string 2 txt))
6281 t t txt))))
6282 (when (derived-mode-p 'org-mode)
6283 (setq effort
6284 (condition-case nil
6285 (org-get-effort
6286 (or (get-text-property 0 'org-hd-marker txt)
6287 (get-text-property 0 'org-marker txt)))
6288 (error nil)))
6289 (when effort
6290 (setq neffort (org-duration-string-to-minutes effort)
6291 effort (setq effort (concat "[" effort "]")))))
6292 ;; prevent erroring out with %e format when there is no effort
6293 (or effort (setq effort ""))
6295 (when remove-re
6296 (while (string-match remove-re txt)
6297 (setq txt (replace-match "" t t txt))))
6299 ;; Set org-heading property on `txt' to mark the start of the
6300 ;; heading.
6301 (add-text-properties 0 (length txt) '(org-heading t) txt)
6303 ;; Prepare the variables needed in the eval of the compiled format
6304 (setq time (cond (s2 (concat
6305 (org-agenda-time-of-day-to-ampm-maybe s1)
6306 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6307 (if org-agenda-timegrid-use-ampm " ")))
6308 (s1 (concat
6309 (org-agenda-time-of-day-to-ampm-maybe s1)
6310 (if org-agenda-timegrid-use-ampm
6311 "........ "
6312 "......")))
6313 (t ""))
6314 extra (or (and (not habitp) extra) "")
6315 category (if (symbolp category) (symbol-name category) category)
6316 thecategory (copy-sequence category)
6317 level (or level ""))
6318 (if (string-match org-bracket-link-regexp category)
6319 (progn
6320 (setq l (if (match-end 3)
6321 (- (match-end 3) (match-beginning 3))
6322 (- (match-end 1) (match-beginning 1))))
6323 (when (< l (or org-prefix-category-length 0))
6324 (setq category (copy-sequence category))
6325 (org-add-props category nil
6326 'extra-space (make-string
6327 (- org-prefix-category-length l 1) ?\ ))))
6328 (if (and org-prefix-category-max-length
6329 (>= (length category) org-prefix-category-max-length))
6330 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6331 ;; Evaluate the compiled format
6332 (setq rtn (concat (eval formatter) txt))
6334 ;; And finally add the text properties
6335 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6336 (org-add-props rtn nil
6337 'org-category (if thecategory (downcase thecategory) category)
6338 'tags (mapcar 'org-downcase-keep-props tags)
6339 'org-highest-priority org-highest-priority
6340 'org-lowest-priority org-lowest-priority
6341 'time-of-day time-of-day
6342 'duration duration
6343 'effort effort
6344 'effort-minutes neffort
6345 'txt txt
6346 'level level
6347 'time time
6348 'extra extra
6349 'format org-prefix-format-compiled
6350 'dotime dotime)))))
6352 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6353 "Remove tags string from TXT, and add a modified list of tags.
6354 The modified list may contain inherited tags, and tags matched by
6355 `org-agenda-hide-tags-regexp' will be removed."
6356 (when (or add-inherited hide-re)
6357 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6358 (setq txt (substring txt 0 (match-beginning 0))))
6359 (setq tags
6360 (delq nil
6361 (mapcar (lambda (tg)
6362 (if (or (and hide-re (string-match hide-re tg))
6363 (and (not add-inherited)
6364 (get-text-property 0 'inherited tg)))
6366 tg))
6367 tags)))
6368 (when tags
6369 (let ((have-i (get-text-property 0 'inherited (car tags)))
6371 (setq txt (concat txt " :"
6372 (mapconcat
6373 (lambda (x)
6374 (setq i (get-text-property 0 'inherited x))
6375 (if (and have-i (not i))
6376 (progn
6377 (setq have-i nil)
6378 (concat ":" x))
6380 tags ":")
6381 (if have-i "::" ":"))))))
6382 txt)
6384 (defun org-downcase-keep-props (s)
6385 (let ((props (text-properties-at 0 s)))
6386 (setq s (downcase s))
6387 (add-text-properties 0 (length s) props s)
6390 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6391 (defvar org-agenda-sorting-strategy-selected nil)
6393 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6394 "Add a time-grid for agenda items which need it.
6396 LIST is the list of agenda items formatted by `org-agenda-list'.
6397 NDAYS is the span of the current agenda view.
6398 TODAYP is `t' when the current agenda view is on today."
6399 (catch 'exit
6400 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6401 ((and todayp (member 'today (car org-agenda-time-grid))))
6402 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6403 ((member 'weekly (car org-agenda-time-grid)))
6404 (t (throw 'exit list)))
6405 (let* ((have (delq nil (mapcar
6406 (lambda (x) (get-text-property 1 'time-of-day x))
6407 list)))
6408 (string (nth 1 org-agenda-time-grid))
6409 (gridtimes (nth 2 org-agenda-time-grid))
6410 (req (car org-agenda-time-grid))
6411 (remove (member 'remove-match req))
6412 new time)
6413 (if (and (member 'require-timed req) (not have))
6414 ;; don't show empty grid
6415 (throw 'exit list))
6416 (while (setq time (pop gridtimes))
6417 (unless (and remove (member time have))
6418 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6419 (push (org-agenda-format-item
6420 nil string nil "" nil
6421 (concat (substring time 0 -2) ":" (substring time -2)))
6422 new)
6423 (put-text-property
6424 2 (length (car new)) 'face 'org-time-grid (car new))))
6425 (when (and todayp org-agenda-show-current-time-in-grid)
6426 (push (org-agenda-format-item
6427 nil org-agenda-current-time-string nil "" nil
6428 (format-time-string "%H:%M "))
6429 new)
6430 (put-text-property
6431 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6433 (if (member 'time-up org-agenda-sorting-strategy-selected)
6434 (append new list)
6435 (append list new)))))
6437 (defun org-compile-prefix-format (key)
6438 "Compile the prefix format into a Lisp form that can be evaluated.
6439 The resulting form and associated variable bindings is returned
6440 and stored in the variable `org-prefix-format-compiled'."
6441 (setq org-prefix-has-time nil
6442 org-prefix-has-tag nil
6443 org-prefix-category-length nil
6444 org-prefix-has-effort nil)
6445 (let ((s (cond
6446 ((stringp org-agenda-prefix-format)
6447 org-agenda-prefix-format)
6448 ((assq key org-agenda-prefix-format)
6449 (cdr (assq key org-agenda-prefix-format)))
6450 (t " %-12:c%?-12t% s")))
6451 (start 0)
6452 varform vars var e c f opt)
6453 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6454 s start)
6455 (setq var (or (cdr (assoc (match-string 4 s)
6456 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6457 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6458 'eval)
6459 c (or (match-string 3 s) "")
6460 opt (match-beginning 1)
6461 start (1+ (match-beginning 0)))
6462 (if (equal var 'time) (setq org-prefix-has-time t))
6463 (if (equal var 'tag) (setq org-prefix-has-tag t))
6464 (if (equal var 'effort) (setq org-prefix-has-effort t))
6465 (setq f (concat "%" (match-string 2 s) "s"))
6466 (when (equal var 'category)
6467 (setq org-prefix-category-length
6468 (floor (abs (string-to-number (match-string 2 s)))))
6469 (setq org-prefix-category-max-length
6470 (let ((x (match-string 2 s)))
6471 (save-match-data
6472 (if (string-match "\\.[0-9]+" x)
6473 (string-to-number (substring (match-string 0 x) 1)))))))
6474 (if (eq var 'eval)
6475 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6476 (if opt
6477 (setq varform
6478 `(if (equal "" ,var)
6480 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6481 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6482 (setq s (replace-match "%s" t nil s))
6483 (push varform vars))
6484 (setq vars (nreverse vars))
6485 (with-current-buffer (or org-agenda-buffer (current-buffer))
6486 (setq org-prefix-format-compiled
6487 (list
6488 `((org-prefix-has-time ,org-prefix-has-time)
6489 (org-prefix-has-tag ,org-prefix-has-tag)
6490 (org-prefix-category-length ,org-prefix-category-length)
6491 (org-prefix-has-effort ,org-prefix-has-effort))
6492 `(format ,s ,@vars))))))
6494 (defun org-set-sorting-strategy (key)
6495 (if (symbolp (car org-agenda-sorting-strategy))
6496 ;; the old format
6497 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6498 (setq org-agenda-sorting-strategy-selected
6499 (or (cdr (assq key org-agenda-sorting-strategy))
6500 (cdr (assq 'agenda org-agenda-sorting-strategy))
6501 '(time-up category-keep priority-down)))))
6503 (defun org-get-time-of-day (s &optional string mod24)
6504 "Check string S for a time of day.
6505 If found, return it as a military time number between 0 and 2400.
6506 If not found, return nil.
6507 The optional STRING argument forces conversion into a 5 character wide string
6508 HH:MM."
6509 (save-match-data
6510 (when
6511 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6512 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6513 (let* ((h (string-to-number (match-string 1 s)))
6514 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6515 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6516 (am-p (equal ampm "am"))
6517 (h1 (cond ((not ampm) h)
6518 ((= h 12) (if am-p 0 12))
6519 (t (+ h (if am-p 0 12)))))
6520 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6521 (mod h1 24) h1))
6522 (t0 (+ (* 100 h2) m))
6523 (t1 (concat (if (>= h1 24) "+" " ")
6524 (if (and org-agenda-time-leading-zero
6525 (< t0 1000)) "0" "")
6526 (if (< t0 100) "0" "")
6527 (if (< t0 10) "0" "")
6528 (int-to-string t0))))
6529 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6531 (defvar org-agenda-before-sorting-filter-function nil
6532 "Function to be applied to agenda items prior to sorting.
6533 Prior to sorting also means just before they are inserted into the agenda.
6535 To aid sorting, you may revisit the original entries and add more text
6536 properties which will later be used by the sorting functions.
6538 The function should take a string argument, an agenda line.
6539 It has access to the text properties in that line, which contain among
6540 other things, the property `org-hd-marker' that points to the entry
6541 where the line comes from. Note that not all lines going into the agenda
6542 have this property, only most.
6544 The function should return the modified string. It is probably best
6545 to ONLY change text properties.
6547 You can also use this function as a filter, by returning nil for lines
6548 you don't want to have in the agenda at all. For this application, you
6549 could bind the variable in the options section of a custom command.")
6551 (defun org-agenda-finalize-entries (list &optional nosort)
6552 "Sort and concatenate the agenda items."
6553 (setq list (mapcar 'org-agenda-highlight-todo list))
6554 (if nosort
6555 list
6556 (when org-agenda-before-sorting-filter-function
6557 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6558 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6560 (defun org-agenda-highlight-todo (x)
6561 (let ((org-done-keywords org-done-keywords-for-agenda)
6562 (case-fold-search nil)
6564 (if (eq x 'line)
6565 (save-excursion
6566 (beginning-of-line 1)
6567 (setq re (org-get-at-bol 'org-todo-regexp))
6568 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6569 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6570 (add-text-properties (match-beginning 0) (match-end 1)
6571 (list 'face (org-get-todo-face 1)))
6572 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6573 (delete-region (match-beginning 1) (1- (match-end 0)))
6574 (goto-char (match-beginning 1))
6575 (insert (format org-agenda-todo-keyword-format s)))))
6576 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6577 (setq re (get-text-property 0 'org-todo-regexp x))
6578 (when (and re
6579 ;; Test `pl' because if there's no heading content,
6580 ;; there's no point matching to highlight. Note
6581 ;; that if we didn't test `pl' first, and there
6582 ;; happened to be no keyword from `org-todo-regexp'
6583 ;; on this heading line, then the `equal' comparison
6584 ;; afterwards would spuriously succeed in the case
6585 ;; where `pl' is nil -- causing an args-out-of-range
6586 ;; error when we try to add text properties to text
6587 ;; that isn't there.
6589 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6590 x pl) pl))
6591 (add-text-properties
6592 (or (match-end 1) (match-end 0)) (match-end 0)
6593 (list 'face (org-get-todo-face (match-string 2 x)))
6595 (when (match-end 1)
6596 (setq x (concat (substring x 0 (match-end 1))
6597 (format org-agenda-todo-keyword-format
6598 (match-string 2 x))
6599 (org-add-props " " (text-properties-at 0 x))
6600 (substring x (match-end 3)))))))
6601 x)))
6603 (defsubst org-cmp-priority (a b)
6604 "Compare the priorities of string A and B."
6605 (let ((pa (or (get-text-property 1 'priority a) 0))
6606 (pb (or (get-text-property 1 'priority b) 0)))
6607 (cond ((> pa pb) +1)
6608 ((< pa pb) -1))))
6610 (defsubst org-cmp-effort (a b)
6611 "Compare the effort values of string A and B."
6612 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6613 (ea (or (get-text-property 1 'effort-minutes a) def))
6614 (eb (or (get-text-property 1 'effort-minutes b) def)))
6615 (cond ((> ea eb) +1)
6616 ((< ea eb) -1))))
6618 (defsubst org-cmp-category (a b)
6619 "Compare the string values of categories of strings A and B."
6620 (let ((ca (or (get-text-property 1 'org-category a) ""))
6621 (cb (or (get-text-property 1 'org-category b) "")))
6622 (cond ((string-lessp ca cb) -1)
6623 ((string-lessp cb ca) +1))))
6625 (defsubst org-cmp-todo-state (a b)
6626 "Compare the todo states of strings A and B."
6627 (let* ((ma (or (get-text-property 1 'org-marker a)
6628 (get-text-property 1 'org-hd-marker a)))
6629 (mb (or (get-text-property 1 'org-marker b)
6630 (get-text-property 1 'org-hd-marker b)))
6631 (fa (and ma (marker-buffer ma)))
6632 (fb (and mb (marker-buffer mb)))
6633 (todo-kwds
6634 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6635 (and fb (with-current-buffer fb org-todo-keywords-1))))
6636 (ta (or (get-text-property 1 'todo-state a) ""))
6637 (tb (or (get-text-property 1 'todo-state b) ""))
6638 (la (- (length (member ta todo-kwds))))
6639 (lb (- (length (member tb todo-kwds))))
6640 (donepa (member ta org-done-keywords-for-agenda))
6641 (donepb (member tb org-done-keywords-for-agenda)))
6642 (cond ((and donepa (not donepb)) -1)
6643 ((and (not donepa) donepb) +1)
6644 ((< la lb) -1)
6645 ((< lb la) +1))))
6647 (defsubst org-cmp-alpha (a b)
6648 "Compare the headlines, alphabetically."
6649 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6650 (plb (text-property-any 0 (length b) 'org-heading t b))
6651 (ta (and pla (substring a pla)))
6652 (tb (and plb (substring b plb))))
6653 (when pla
6654 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6655 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6656 (setq ta (substring ta (match-end 0))))
6657 (setq ta (downcase ta)))
6658 (when plb
6659 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6660 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6661 (setq tb (substring tb (match-end 0))))
6662 (setq tb (downcase tb)))
6663 (cond ((not ta) +1)
6664 ((not tb) -1)
6665 ((string-lessp ta tb) -1)
6666 ((string-lessp tb ta) +1))))
6668 (defsubst org-cmp-tag (a b)
6669 "Compare the string values of the first tags of A and B."
6670 (let ((ta (car (last (get-text-property 1 'tags a))))
6671 (tb (car (last (get-text-property 1 'tags b)))))
6672 (cond ((not ta) +1)
6673 ((not tb) -1)
6674 ((string-lessp ta tb) -1)
6675 ((string-lessp tb ta) +1))))
6677 (defsubst org-cmp-time (a b)
6678 "Compare the time-of-day values of strings A and B."
6679 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6680 (ta (or (get-text-property 1 'time-of-day a) def))
6681 (tb (or (get-text-property 1 'time-of-day b) def)))
6682 (cond ((< ta tb) -1)
6683 ((< tb ta) +1))))
6685 (defsubst org-cmp-habit-p (a b)
6686 "Compare the todo states of strings A and B."
6687 (let ((ha (get-text-property 1 'org-habit-p a))
6688 (hb (get-text-property 1 'org-habit-p b)))
6689 (cond ((and ha (not hb)) -1)
6690 ((and (not ha) hb) +1))))
6692 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6694 (defun org-entries-lessp (a b)
6695 "Predicate for sorting agenda entries."
6696 ;; The following variables will be used when the form is evaluated.
6697 ;; So even though the compiler complains, keep them.
6698 (let* ((ss org-agenda-sorting-strategy-selected)
6699 (time-up (and (org-em 'time-up 'time-down ss)
6700 (org-cmp-time a b)))
6701 (time-down (if time-up (- time-up) nil))
6702 (priority-up (and (org-em 'priority-up 'priority-down ss)
6703 (org-cmp-priority a b)))
6704 (priority-down (if priority-up (- priority-up) nil))
6705 (effort-up (and (org-em 'effort-up 'effort-down ss)
6706 (org-cmp-effort a b)))
6707 (effort-down (if effort-up (- effort-up) nil))
6708 (category-up (and (or (org-em 'category-up 'category-down ss)
6709 (memq 'category-keep ss))
6710 (org-cmp-category a b)))
6711 (category-down (if category-up (- category-up) nil))
6712 (category-keep (if category-up +1 nil))
6713 (tag-up (and (org-em 'tag-up 'tag-down ss)
6714 (org-cmp-tag a b)))
6715 (tag-down (if tag-up (- tag-up) nil))
6716 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6717 (org-cmp-todo-state a b)))
6718 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6719 (habit-up (and (org-em 'habit-up 'habit-down ss)
6720 (org-cmp-habit-p a b)))
6721 (habit-down (if habit-up (- habit-up) nil))
6722 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6723 (org-cmp-alpha a b)))
6724 (alpha-down (if alpha-up (- alpha-up) nil))
6725 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6726 user-defined-up user-defined-down)
6727 (if (and need-user-cmp org-agenda-cmp-user-defined
6728 (functionp org-agenda-cmp-user-defined))
6729 (setq user-defined-up
6730 (funcall org-agenda-cmp-user-defined a b)
6731 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6732 (cdr (assoc
6733 (eval (cons 'or org-agenda-sorting-strategy-selected))
6734 '((-1 . t) (1 . nil) (nil . nil))))))
6736 ;;; Agenda restriction lock
6738 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6739 "Overlay to mark the headline to which agenda commands are restricted.")
6740 (overlay-put org-agenda-restriction-lock-overlay
6741 'face 'org-agenda-restriction-lock)
6742 (overlay-put org-agenda-restriction-lock-overlay
6743 'help-echo "Agendas are currently limited to this subtree.")
6744 (org-detach-overlay org-agenda-restriction-lock-overlay)
6746 (defun org-agenda-set-restriction-lock (&optional type)
6747 "Set restriction lock for agenda, to current subtree or file.
6748 Restriction will be the file if TYPE is `file', or if type is the
6749 universal prefix '(4), or if the cursor is before the first headline
6750 in the file. Otherwise, restriction will be to the current subtree."
6751 (interactive "P")
6752 (and (equal type '(4)) (setq type 'file))
6753 (setq type (cond
6754 (type type)
6755 ((org-at-heading-p) 'subtree)
6756 ((condition-case nil (org-back-to-heading t) (error nil))
6757 'subtree)
6758 (t 'file)))
6759 (if (eq type 'subtree)
6760 (progn
6761 (setq org-agenda-restrict t)
6762 (setq org-agenda-overriding-restriction 'subtree)
6763 (put 'org-agenda-files 'org-restrict
6764 (list (buffer-file-name (buffer-base-buffer))))
6765 (org-back-to-heading t)
6766 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6767 (move-marker org-agenda-restrict-begin (point))
6768 (move-marker org-agenda-restrict-end
6769 (save-excursion (org-end-of-subtree t)))
6770 (message "Locking agenda restriction to subtree"))
6771 (put 'org-agenda-files 'org-restrict
6772 (list (buffer-file-name (buffer-base-buffer))))
6773 (setq org-agenda-restrict nil)
6774 (setq org-agenda-overriding-restriction 'file)
6775 (move-marker org-agenda-restrict-begin nil)
6776 (move-marker org-agenda-restrict-end nil)
6777 (message "Locking agenda restriction to file"))
6778 (setq current-prefix-arg nil)
6779 (org-agenda-maybe-redo))
6781 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6782 "Remove the agenda restriction lock."
6783 (interactive "P")
6784 (org-detach-overlay org-agenda-restriction-lock-overlay)
6785 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6786 (setq org-agenda-overriding-restriction nil)
6787 (setq org-agenda-restrict nil)
6788 (put 'org-agenda-files 'org-restrict nil)
6789 (move-marker org-agenda-restrict-begin nil)
6790 (move-marker org-agenda-restrict-end nil)
6791 (setq current-prefix-arg nil)
6792 (message "Agenda restriction lock removed")
6793 (or noupdate (org-agenda-maybe-redo)))
6795 (defun org-agenda-maybe-redo ()
6796 "If there is any window showing the agenda view, update it."
6797 (let ((w (get-buffer-window org-agenda-buffer-name t))
6798 (w0 (selected-window)))
6799 (when w
6800 (select-window w)
6801 (org-agenda-redo)
6802 (select-window w0)
6803 (if org-agenda-overriding-restriction
6804 (message "Agenda view shifted to new %s restriction"
6805 org-agenda-overriding-restriction)
6806 (message "Agenda restriction lock removed")))))
6808 ;;; Agenda commands
6810 (defun org-agenda-check-type (error &rest types)
6811 "Check if agenda buffer is of allowed type.
6812 If ERROR is non-nil, throw an error, otherwise just return nil."
6813 (if (not org-agenda-type)
6814 (error "No Org agenda currently displayed")
6815 (if (memq org-agenda-type types)
6817 (if error
6818 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6819 nil))))
6821 (defun org-agenda-Quit (&optional arg)
6822 "Exit agenda by removing the window or the buffer."
6823 (interactive)
6824 (if org-agenda-columns-active
6825 (org-columns-quit)
6826 (let ((buf (current-buffer)))
6827 (if (eq org-agenda-window-setup 'other-frame)
6828 (progn
6829 (org-agenda-reset-markers)
6830 (kill-buffer buf)
6831 (org-columns-remove-overlays)
6832 (setq org-agenda-archives-mode nil)
6833 (delete-frame))
6834 (and (not (eq org-agenda-window-setup 'current-window))
6835 (not (one-window-p))
6836 (delete-window))
6837 (org-agenda-reset-markers)
6838 (kill-buffer buf)
6839 (org-columns-remove-overlays)
6840 (setq org-agenda-archives-mode nil)))
6841 ;; Maybe restore the pre-agenda window configuration.
6842 (and org-agenda-restore-windows-after-quit
6843 (not (eq org-agenda-window-setup 'other-frame))
6844 org-agenda-pre-window-conf
6845 (set-window-configuration org-agenda-pre-window-conf)
6846 (setq org-agenda-pre-window-conf nil))))
6848 (defun org-agenda-quit ()
6849 "Exit agenda by killing agenda buffer or burying it when
6850 `org-agenda-sticky' is non-NIL"
6851 (interactive)
6852 (if (and (eq org-indirect-buffer-display 'other-window)
6853 org-last-indirect-buffer)
6854 (delete-window (get-buffer-window org-last-indirect-buffer)))
6855 (if org-agenda-columns-active
6856 (org-columns-quit)
6857 (if org-agenda-sticky
6858 (let ((buf (current-buffer)))
6859 (if (eq org-agenda-window-setup 'other-frame)
6860 (progn
6861 (delete-frame))
6862 (and (not (eq org-agenda-window-setup 'current-window))
6863 (not (one-window-p))
6864 (delete-window)))
6865 (with-current-buffer buf
6866 (bury-buffer)
6867 ;; Maybe restore the pre-agenda window configuration.
6868 (and org-agenda-restore-windows-after-quit
6869 (not (eq org-agenda-window-setup 'other-frame))
6870 org-agenda-pre-window-conf
6871 (set-window-configuration org-agenda-pre-window-conf)
6872 (setq org-agenda-pre-window-conf nil))))
6873 (org-agenda-Quit))))
6875 (defun org-agenda-exit ()
6876 "Exit agenda by removing the window or the buffer.
6877 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6878 Org-mode buffers visited directly by the user will not be touched."
6879 (interactive)
6880 (org-release-buffers org-agenda-new-buffers)
6881 (setq org-agenda-new-buffers nil)
6882 (org-agenda-Quit))
6884 (defun org-agenda-kill-all-agenda-buffers ()
6885 "Kill all buffers in `org-agenda-mode'.
6886 This is used when toggling sticky agendas. You can also explicitly invoke it
6887 with `C-c a C-k'."
6888 (interactive)
6889 (let (blist)
6890 (dolist (buf (buffer-list))
6891 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6892 (push buf blist)))
6893 (mapc 'kill-buffer blist)))
6895 (defun org-agenda-execute (arg)
6896 "Execute another agenda command, keeping same window.
6897 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6898 in the agenda."
6899 (interactive "P")
6900 (let ((org-agenda-window-setup 'current-window))
6901 (org-agenda arg)))
6903 (defun org-agenda-redo (&optional all)
6904 "Rebuild possibly ALL agenda view(s) in the current buffer."
6905 (interactive "P")
6906 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6907 (cpa (unless (eq all t) current-prefix-arg))
6908 (org-agenda-doing-sticky-redo org-agenda-sticky)
6909 (org-agenda-sticky nil)
6910 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6911 org-agenda-buffer-name))
6912 (org-agenda-keep-modes t)
6913 (tag-filter org-agenda-tag-filter)
6914 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6915 (top-cat-filter org-agenda-top-category-filter)
6916 (cat-filter org-agenda-category-filter)
6917 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6918 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6919 (cols org-agenda-columns-active)
6920 (line (org-current-line))
6921 (window-line (- line (org-current-line (window-start))))
6922 (lprops (get 'org-agenda-redo-command 'org-lprops))
6923 (redo-cmd (get-text-property p 'org-redo-cmd))
6924 (last-args (get-text-property p 'org-last-args))
6925 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6926 (org-agenda-overriding-cmd-arguments
6927 (unless (eq all t)
6928 (cond ((listp last-args)
6929 (cons (or cpa (car last-args)) (cdr last-args)))
6930 ((stringp last-args)
6931 last-args))))
6932 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6933 (put 'org-agenda-tag-filter :preset-filter nil)
6934 (put 'org-agenda-category-filter :preset-filter nil)
6935 (and cols (org-columns-quit))
6936 (message "Rebuilding agenda buffer...")
6937 (if series-redo-cmd
6938 (eval series-redo-cmd)
6939 (org-let lprops '(eval redo-cmd)))
6940 (setq org-agenda-undo-list nil
6941 org-agenda-pending-undo-list nil)
6942 (message "Rebuilding agenda buffer...done")
6943 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6944 (put 'org-agenda-category-filter :preset-filter cat-preset)
6945 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6946 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6947 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6948 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6949 (org-goto-line line)
6950 (recenter window-line)))
6952 (defvar org-global-tags-completion-table nil)
6953 (defvar org-agenda-filter-form nil)
6954 (defvar org-agenda-filtered-by-category nil)
6956 (defun org-agenda-filter-by-category (strip)
6957 "Keep only those lines in the agenda buffer that have a specific category.
6958 The category is that of the current line."
6959 (interactive "P")
6960 (if (and org-agenda-filtered-by-category
6961 org-agenda-category-filter)
6962 (org-agenda-filter-show-all-cat)
6963 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6964 (if cat (org-agenda-filter-apply
6965 (list (concat (if strip "-" "+") cat)) 'category)
6966 (error "No category at point")))))
6968 (defun org-find-top-category (&optional pos)
6969 (save-excursion
6970 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6971 (if pos (goto-char pos))
6972 ;; Skip up to the topmost parent
6973 (while (ignore-errors (outline-up-heading 1) t))
6974 (ignore-errors
6975 (nth 4 (org-heading-components))))))
6977 (defvar org-agenda-filtered-by-top-category nil)
6979 (defun org-agenda-filter-by-top-category (strip)
6980 "Keep only those lines in the agenda buffer that have a specific category.
6981 The category is that of the current line."
6982 (interactive "P")
6983 (if org-agenda-filtered-by-top-category
6984 (progn
6985 (setq org-agenda-filtered-by-top-category nil
6986 org-agenda-top-category-filter nil)
6987 (org-agenda-filter-show-all-cat))
6988 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6989 (if cat (org-agenda-filter-top-category-apply cat strip)
6990 (error "No top-level category at point")))))
6992 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6993 "Keep only those lines in the agenda buffer that have a specific tag.
6994 The tag is selected with its fast selection letter, as configured.
6995 With prefix argument STRIP, remove all lines that do have the tag.
6996 A lisp caller can specify CHAR. NARROW means that the new tag should be
6997 used to narrow the search - the interactive user can also press `-' or `+'
6998 to switch to narrowing."
6999 (interactive "P")
7000 (let* ((alist org-tag-alist-for-agenda)
7001 (tag-chars (mapconcat
7002 (lambda (x) (if (and (not (symbolp (car x)))
7003 (cdr x))
7004 (char-to-string (cdr x))
7005 ""))
7006 alist ""))
7007 (efforts (org-split-string
7008 (or (cdr (assoc (concat org-effort-property "_ALL")
7009 org-global-properties))
7010 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7011 "")))
7012 (effort-op org-agenda-filter-effort-default-operator)
7013 (effort-prompt "")
7014 (inhibit-read-only t)
7015 (current org-agenda-tag-filter)
7016 maybe-refresh a n tag)
7017 (unless char
7018 (message
7019 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7020 (if narrow "Narrow" "Filter") tag-chars
7021 (if org-agenda-auto-exclude-function "[RET], " ""))
7022 (setq char (read-char-exclusive)))
7023 (when (member char '(?+ ?-))
7024 ;; Narrowing down
7025 (cond ((equal char ?-) (setq strip t narrow t))
7026 ((equal char ?+) (setq strip nil narrow t)))
7027 (message
7028 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7029 (setq char (read-char-exclusive)))
7030 (when (member char '(?< ?> ?= ??))
7031 ;; An effort operator
7032 (setq effort-op (char-to-string char))
7033 (setq alist nil) ; to make sure it will be interpreted as effort.
7034 (unless (equal char ??)
7035 (loop for i from 0 to 9 do
7036 (setq effort-prompt
7037 (concat
7038 effort-prompt " ["
7039 (if (= i 9) "0" (int-to-string (1+ i)))
7040 "]" (nth i efforts))))
7041 (message "Effort%s: %s " effort-op effort-prompt)
7042 (setq char (read-char-exclusive))
7043 (when (or (< char ?0) (> char ?9))
7044 (error "Need 1-9,0 to select effort"))))
7045 (when (equal char ?\t)
7046 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7047 (org-set-local 'org-global-tags-completion-table
7048 (org-global-tags-completion-table)))
7049 (let ((completion-ignore-case t))
7050 (setq tag (org-icompleting-read
7051 "Tag: " org-global-tags-completion-table))))
7052 (cond
7053 ((equal char ?\r)
7054 (org-agenda-filter-show-all-tag)
7055 (when org-agenda-auto-exclude-function
7056 (setq org-agenda-tag-filter '())
7057 (dolist (tag (org-agenda-get-represented-tags))
7058 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7059 (if modifier
7060 (push modifier org-agenda-tag-filter))))
7061 (if (not (null org-agenda-tag-filter))
7062 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7063 (setq maybe-refresh t))
7064 ((equal char ?/)
7065 (org-agenda-filter-show-all-tag)
7066 (when (get 'org-agenda-tag-filter :preset-filter)
7067 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7068 (setq maybe-refresh t))
7069 ((equal char ?. )
7070 (setq org-agenda-tag-filter
7071 (mapcar (lambda(tag) (concat "+" tag))
7072 (org-get-at-bol 'tags)))
7073 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7074 (setq maybe-refresh t))
7075 ((or (equal char ?\ )
7076 (setq a (rassoc char alist))
7077 (and (>= char ?0) (<= char ?9)
7078 (setq n (if (= char ?0) 9 (- char ?0 1))
7079 tag (concat effort-op (nth n efforts))
7080 a (cons tag nil)))
7081 (and (= char ??)
7082 (setq tag "?eff")
7083 a (cons tag nil))
7084 (and tag (setq a (cons tag nil))))
7085 (org-agenda-filter-show-all-tag)
7086 (setq tag (car a))
7087 (setq org-agenda-tag-filter
7088 (cons (concat (if strip "-" "+") tag)
7089 (if narrow current nil)))
7090 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7091 (setq maybe-refresh t))
7092 (t (error "Invalid tag selection character %c" char)))
7093 (when (and maybe-refresh
7094 (eq org-agenda-clockreport-mode 'with-filter))
7095 (org-agenda-redo))))
7097 (defun org-agenda-get-represented-tags ()
7098 "Get a list of all tags currently represented in the agenda."
7099 (let (p tags)
7100 (save-excursion
7101 (goto-char (point-min))
7102 (while (setq p (next-single-property-change (point) 'tags))
7103 (goto-char p)
7104 (mapc (lambda (x) (add-to-list 'tags x))
7105 (get-text-property (point) 'tags))))
7106 tags))
7108 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7109 "Refine the current filter. See `org-agenda-filter-by-tag'."
7110 (interactive "P")
7111 (org-agenda-filter-by-tag strip char 'refine))
7113 (defun org-agenda-filter-make-matcher ()
7114 "Create the form that tests a line for agenda filter."
7115 (let (f f1)
7116 ;; first compute the tag-filter matcher
7117 (dolist (x (delete-dups
7118 (append (get 'org-agenda-tag-filter
7119 :preset-filter) org-agenda-tag-filter)))
7120 (if (member x '("-" "+"))
7121 (setq f1 (if (equal x "-") 'tags '(not tags)))
7122 (if (string-match "[<=>?]" x)
7123 (setq f1 (org-agenda-filter-effort-form x))
7124 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7125 (if (equal (string-to-char x) ?-)
7126 (setq f1 (list 'not f1))))
7127 (push f1 f))
7128 ;; then compute the category-filter matcher
7129 (dolist (x (delete-dups
7130 (append (get 'org-agenda-category-filter
7131 :preset-filter) org-agenda-category-filter)))
7132 (if (equal "-" (substring x 0 1))
7133 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7134 (setq f1 (list 'equal (substring x 1) 'cat)))
7135 (push f1 f))
7136 (cons 'and (nreverse f))))
7138 (defun org-agenda-filter-effort-form (e)
7139 "Return the form to compare the effort of the current line with what E says.
7140 E looks like \"+<2:25\"."
7141 (let (op)
7142 (setq e (substring e 1))
7143 (setq op (string-to-char e) e (substring e 1))
7144 (setq op (cond ((equal op ?<) '<=)
7145 ((equal op ?>) '>=)
7146 ((equal op ??) op)
7147 (t '=)))
7148 (list 'org-agenda-compare-effort (list 'quote op)
7149 (org-duration-string-to-minutes e))))
7151 (defun org-agenda-compare-effort (op value)
7152 "Compare the effort of the current line with VALUE, using OP.
7153 If the line does not have an effort defined, return nil."
7154 (let ((eff (org-get-at-bol 'effort-minutes)))
7155 (if (equal op ??)
7156 (not eff)
7157 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7158 value))))
7160 (defun org-agenda-filter-apply (filter type)
7161 "Set FILTER as the new agenda filter and apply it."
7162 (let (tags cat)
7163 (if (eq type 'tag)
7164 (setq org-agenda-tag-filter filter)
7165 (setq org-agenda-category-filter filter))
7166 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7167 (if (and (eq type 'category)
7168 (not (equal (substring (car filter) 0 1) "-")))
7169 ;; Only set `org-agenda-filtered-by-category' to t
7170 ;; when a unique category is used as the filter
7171 (setq org-agenda-filtered-by-category t))
7172 (org-agenda-set-mode-name)
7173 (save-excursion
7174 (goto-char (point-min))
7175 (while (not (eobp))
7176 (if (org-get-at-bol 'org-marker)
7177 (progn
7178 (setq tags (org-get-at-bol 'tags) ; used in eval
7179 cat (get-text-property (point) 'org-category))
7180 (if (not (eval org-agenda-filter-form))
7181 (org-agenda-filter-hide-line type))
7182 (beginning-of-line 2))
7183 (beginning-of-line 2))))
7184 (if (get-char-property (point) 'invisible)
7185 (ignore-errors (org-agenda-previous-line)))))
7187 (defun org-agenda-filter-top-category-apply (category &optional negative)
7188 "Set FILTER as the new agenda filter and apply it."
7189 (org-agenda-set-mode-name)
7190 (save-excursion
7191 (goto-char (point-min))
7192 (while (not (eobp))
7193 (let* ((pos (org-get-at-bol 'org-hd-marker))
7194 (topcat (and pos (org-find-top-category pos))))
7195 (if (and topcat (funcall (if negative 'identity 'not)
7196 (string= category topcat)))
7197 (org-agenda-filter-hide-line 'category)))
7198 (beginning-of-line 2)))
7199 (if (get-char-property (point) 'invisible)
7200 (org-agenda-previous-line))
7201 (setq org-agenda-top-category-filter category
7202 org-agenda-filtered-by-top-category t))
7204 (defun org-agenda-filter-hide-line (type)
7205 (let (ov)
7206 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7207 (point-at-eol)))
7208 (overlay-put ov 'invisible t)
7209 (overlay-put ov 'type type)
7210 (if (eq type 'tag)
7211 (push ov org-agenda-tag-filter-overlays)
7212 (push ov org-agenda-cat-filter-overlays))))
7214 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7215 (setq pos (or pos (point)))
7216 (save-excursion
7217 (dolist (ov (overlays-at pos))
7218 (when (and (overlay-get ov 'invisible)
7219 (eq (overlay-get ov 'type) 'tag))
7220 (goto-char pos)
7221 (if (< (overlay-start ov) (point-at-eol))
7222 (move-overlay ov (point-at-eol)
7223 (overlay-end ov)))))))
7225 (defun org-agenda-filter-show-all-tag nil
7226 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7227 (setq org-agenda-tag-filter-overlays nil
7228 org-agenda-tag-filter nil
7229 org-agenda-filter-form nil)
7230 (org-agenda-set-mode-name))
7232 (defun org-agenda-filter-show-all-cat nil
7233 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7234 (setq org-agenda-cat-filter-overlays nil
7235 org-agenda-filtered-by-category nil
7236 org-agenda-category-filter nil
7237 org-agenda-filter-form nil)
7238 (org-agenda-set-mode-name))
7240 (defun org-agenda-manipulate-query-add ()
7241 "Manipulate the query by adding a search term with positive selection.
7242 Positive selection means the term must be matched for selection of an entry."
7243 (interactive)
7244 (org-agenda-manipulate-query ?\[))
7245 (defun org-agenda-manipulate-query-subtract ()
7246 "Manipulate the query by adding a search term with negative selection.
7247 Negative selection means term must not be matched for selection of an entry."
7248 (interactive)
7249 (org-agenda-manipulate-query ?\]))
7250 (defun org-agenda-manipulate-query-add-re ()
7251 "Manipulate the query by adding a search regexp with positive selection.
7252 Positive selection means the regexp must match for selection of an entry."
7253 (interactive)
7254 (org-agenda-manipulate-query ?\{))
7255 (defun org-agenda-manipulate-query-subtract-re ()
7256 "Manipulate the query by adding a search regexp with negative selection.
7257 Negative selection means regexp must not match for selection of an entry."
7258 (interactive)
7259 (org-agenda-manipulate-query ?\}))
7260 (defun org-agenda-manipulate-query (char)
7261 (cond
7262 ((memq org-agenda-type '(timeline agenda))
7263 (let ((org-agenda-include-inactive-timestamps t))
7264 (org-agenda-redo))
7265 (message "Display now includes inactive timestamps as well"))
7266 ((eq org-agenda-type 'search)
7267 (org-add-to-string
7268 'org-agenda-query-string
7269 (if org-agenda-last-search-view-search-was-boolean
7270 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7271 (?\{ . " +{}") (?\} . " -{}"))))
7272 " "))
7273 (setq org-agenda-redo-command
7274 (list 'org-search-view
7275 (car (get-text-property (min (1- (point-max)) (point))
7276 'org-last-args))
7277 org-agenda-query-string
7278 (+ (length org-agenda-query-string)
7279 (if (member char '(?\{ ?\})) 0 1))))
7280 (set-register org-agenda-query-register org-agenda-query-string)
7281 (let ((org-agenda-overriding-arguments
7282 (cdr org-agenda-redo-command)))
7283 (org-agenda-redo)))
7284 (t (error "Cannot manipulate query for %s-type agenda buffers"
7285 org-agenda-type))))
7287 (defun org-add-to-string (var string)
7288 (set var (concat (symbol-value var) string)))
7290 (defun org-agenda-goto-date (span)
7291 "Jump to DATE in agenda."
7292 (interactive "P")
7293 (let* ((org-read-date-prefer-future
7294 (eval org-agenda-jump-prefer-future))
7295 (date (org-read-date))
7296 (org-agenda-sticky-orig org-agenda-sticky)
7297 (org-agenda-buffer-tmp-name (buffer-name))
7298 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7299 (0-arg (or current-prefix-arg (car args)))
7300 (2-arg (nth 2 args))
7301 (newcmd (list 'org-agenda-list 0-arg date
7302 (org-agenda-span-to-ndays 2-arg)))
7303 (newargs (cdr newcmd))
7304 (inhibit-read-only t)
7305 org-agenda-sticky)
7306 (if (not (org-agenda-check-type t 'agenda))
7307 (error "Not available in non-agenda blocks")
7308 (add-text-properties (point-min) (point-max)
7309 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7310 (org-agenda-redo)
7311 (setq org-agenda-sticky org-agenda-sticky-orig
7312 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7314 (defun org-agenda-goto-today ()
7315 "Go to today."
7316 (interactive)
7317 (org-agenda-check-type t 'timeline 'agenda)
7318 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7319 (curspan (nth 2 args))
7320 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7321 (cond
7322 (tdpos (goto-char tdpos))
7323 ((eq org-agenda-type 'agenda)
7324 (let* ((sd (org-agenda-compute-starting-span
7325 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7326 (org-agenda-overriding-arguments args))
7327 (setf (nth 1 org-agenda-overriding-arguments) sd)
7328 (org-agenda-redo)
7329 (org-agenda-find-same-or-today-or-agenda)))
7330 (t (error "Cannot find today")))))
7332 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7333 (goto-char
7334 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7335 (text-property-any (point-min) (point-max) 'org-today t)
7336 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7337 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7338 (org-agenda-goto-block-beginning))
7339 (point-min))))
7341 (defun org-agenda-goto-block-beginning ()
7342 "Go the agenda block beginning."
7343 (interactive)
7344 (if (not (derived-mode-p 'org-agenda-mode))
7345 (error "Cannot execute this command outside of org-agenda-mode buffers")
7346 (let (dest)
7347 (save-excursion
7348 (unless (looking-at "\\'")
7349 (forward-char))
7350 (let* ((prop 'org-agenda-structural-header)
7351 (p (previous-single-property-change (point) prop))
7352 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7353 (1- (point))) prop)))
7354 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7355 (if (not dest)
7356 (error "Cannot find the beginning of the blog")
7357 (goto-char dest)
7358 (move-beginning-of-line 1)))))
7360 (defun org-agenda-later (arg)
7361 "Go forward in time by the current span.
7362 With prefix ARG, go forward that many times the current span."
7363 (interactive "p")
7364 (org-agenda-check-type t 'agenda)
7365 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7366 (span (or (nth 2 args) org-agenda-current-span))
7367 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7368 (greg (calendar-gregorian-from-absolute sd))
7369 (cnt (org-get-at-bol 'org-day-cnt))
7370 greg2)
7371 (cond
7372 ((numberp span)
7373 (setq sd (+ (* span arg) sd)))
7374 ((eq span 'day)
7375 (setq sd (+ arg sd)))
7376 ((eq span 'week)
7377 (setq sd (+ (* 7 arg) sd)))
7378 ((eq span 'month)
7379 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7380 sd (calendar-absolute-from-gregorian greg2))
7381 (setcar greg2 (1+ (car greg2))))
7382 ((eq span 'year)
7383 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7384 sd (calendar-absolute-from-gregorian greg2))
7385 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7387 (setq sd (+ (* span arg) sd))))
7388 (let ((org-agenda-overriding-cmd
7389 ;; `cmd' may have been set by `org-agenda-run-series' which
7390 ;; uses `org-agenda-overriding-cmd' to decide whether
7391 ;; overriding is allowed for `cmd'
7392 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7393 (org-agenda-overriding-arguments
7394 (list (car args) sd span)))
7395 (org-agenda-redo)
7396 (org-agenda-find-same-or-today-or-agenda cnt))))
7398 (defun org-agenda-earlier (arg)
7399 "Go backward in time by the current span.
7400 With prefix ARG, go backward that many times the current span."
7401 (interactive "p")
7402 (org-agenda-later (- arg)))
7404 (defun org-agenda-view-mode-dispatch ()
7405 "Call one of the view mode commands."
7406 (interactive)
7407 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7408 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7409 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7410 (let ((a (read-char-exclusive)))
7411 (case a
7412 (?\ (call-interactively 'org-agenda-reset-view))
7413 (?d (call-interactively 'org-agenda-day-view))
7414 (?w (call-interactively 'org-agenda-week-view))
7415 (?m (call-interactively 'org-agenda-month-view))
7416 (?y (call-interactively 'org-agenda-year-view))
7417 (?l (call-interactively 'org-agenda-log-mode))
7418 (?L (org-agenda-log-mode '(4)))
7419 (?c (org-agenda-log-mode 'clockcheck))
7420 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7421 (?a (call-interactively 'org-agenda-archives-mode))
7422 (?A (org-agenda-archives-mode 'files))
7423 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7424 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7425 (?G (call-interactively 'org-agenda-toggle-time-grid))
7426 (?D (call-interactively 'org-agenda-toggle-diary))
7427 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7428 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7429 (org-agenda-check-type t 'timeline 'agenda)
7430 (org-agenda-redo))
7431 (message "Display now includes inactive timestamps as well"))
7432 (?q (message "Abort"))
7433 (otherwise (error "Invalid key" )))))
7435 (defun org-agenda-reset-view ()
7436 "Switch to default view for agenda."
7437 (interactive)
7438 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7439 (defun org-agenda-day-view (&optional day-of-year)
7440 "Switch to daily view for agenda.
7441 With argument DAY-OF-YEAR, switch to that day of the year."
7442 (interactive "P")
7443 (org-agenda-change-time-span 'day day-of-year))
7444 (defun org-agenda-week-view (&optional iso-week)
7445 "Switch to daily view for agenda.
7446 With argument ISO-WEEK, switch to the corresponding ISO week.
7447 If ISO-WEEK has more then 2 digits, only the last two encode the
7448 week. Any digits before this encode a year. So 200712 means
7449 week 12 of year 2007. Years in the range 1938-2037 can also be
7450 written as 2-digit years."
7451 (interactive "P")
7452 (org-agenda-change-time-span 'week iso-week))
7453 (defun org-agenda-month-view (&optional month)
7454 "Switch to monthly view for agenda.
7455 With argument MONTH, switch to that month."
7456 (interactive "P")
7457 (org-agenda-change-time-span 'month month))
7458 (defun org-agenda-year-view (&optional year)
7459 "Switch to yearly view for agenda.
7460 With argument YEAR, switch to that year.
7461 If MONTH has more then 2 digits, only the last two encode the
7462 month. Any digits before this encode a year. So 200712 means
7463 December year 2007. Years in the range 1938-2037 can also be
7464 written as 2-digit years."
7465 (interactive "P")
7466 (when year
7467 (setq year (org-small-year-to-year year)))
7468 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7469 (org-agenda-change-time-span 'year year)
7470 (error "Abort")))
7472 (defun org-agenda-change-time-span (span &optional n)
7473 "Change the agenda view to SPAN.
7474 SPAN may be `day', `week', `month', `year'."
7475 (org-agenda-check-type t 'agenda)
7476 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7477 (curspan (nth 2 args)))
7478 (if (and (not n) (equal curspan span))
7479 (error "Viewing span is already \"%s\"" span))
7480 (let* ((sd (or (org-get-at-bol 'day)
7481 (nth 1 args)
7482 org-starting-day))
7483 (sd (org-agenda-compute-starting-span sd span n))
7484 (org-agenda-overriding-cmd
7485 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7486 (org-agenda-overriding-arguments
7487 (list (car args) sd span)))
7488 (org-agenda-redo)
7489 (org-agenda-find-same-or-today-or-agenda))
7490 (org-agenda-set-mode-name)
7491 (message "Switched to %s view" span)))
7493 (defun org-agenda-compute-starting-span (sd span &optional n)
7494 "Compute starting date for agenda.
7495 SPAN may be `day', `week', `month', `year'. The return value
7496 is a cons cell with the starting date and the number of days,
7497 so that the date SD will be in that range."
7498 (let* ((greg (calendar-gregorian-from-absolute sd))
7499 (dg (nth 1 greg))
7500 (mg (car greg))
7501 (yg (nth 2 greg)))
7502 (cond
7503 ((eq span 'day)
7504 (when n
7505 (setq sd (+ (calendar-absolute-from-gregorian
7506 (list mg 1 yg))
7507 n -1))))
7508 ((eq span 'week)
7509 (let* ((nt (calendar-day-of-week
7510 (calendar-gregorian-from-absolute sd)))
7511 (d (if org-agenda-start-on-weekday
7512 (- nt org-agenda-start-on-weekday)
7515 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7516 (when n
7517 (require 'cal-iso)
7518 (when (> n 99)
7519 (setq y1 (org-small-year-to-year (/ n 100))
7520 n (mod n 100)))
7521 (setq sd
7522 (calendar-absolute-from-iso
7523 (list n 1
7524 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7525 ((eq span 'month)
7526 (let (y1)
7527 (when (and n (> n 99))
7528 (setq y1 (org-small-year-to-year (/ n 100))
7529 n (mod n 100)))
7530 (setq sd (calendar-absolute-from-gregorian
7531 (list (or n mg) 1 (or y1 yg))))))
7532 ((eq span 'year)
7533 (setq sd (calendar-absolute-from-gregorian
7534 (list 1 1 (or n yg))))))
7535 sd))
7537 (defun org-agenda-next-date-line (&optional arg)
7538 "Jump to the next line indicating a date in agenda buffer."
7539 (interactive "p")
7540 (org-agenda-check-type t 'agenda 'timeline)
7541 (beginning-of-line 1)
7542 ;; This does not work if user makes date format that starts with a blank
7543 (if (looking-at "^\\S-") (forward-char 1))
7544 (if (not (re-search-forward "^\\S-" nil t arg))
7545 (progn
7546 (backward-char 1)
7547 (error "No next date after this line in this buffer")))
7548 (goto-char (match-beginning 0)))
7550 (defun org-agenda-previous-date-line (&optional arg)
7551 "Jump to the previous line indicating a date in agenda buffer."
7552 (interactive "p")
7553 (org-agenda-check-type t 'agenda 'timeline)
7554 (beginning-of-line 1)
7555 (if (not (re-search-backward "^\\S-" nil t arg))
7556 (error "No previous date before this line in this buffer")))
7558 ;; Initialize the highlight
7559 (defvar org-hl (make-overlay 1 1))
7560 (overlay-put org-hl 'face 'highlight)
7562 (defun org-highlight (begin end &optional buffer)
7563 "Highlight a region with overlay."
7564 (move-overlay org-hl begin end (or buffer (current-buffer))))
7566 (defun org-unhighlight ()
7567 "Detach overlay INDEX."
7568 (org-detach-overlay org-hl))
7570 (defun org-unhighlight-once ()
7571 "Remove the highlight from its position, and this function from the hook."
7572 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7573 (org-unhighlight))
7575 (defvar org-agenda-pre-follow-window-conf nil)
7576 (defun org-agenda-follow-mode ()
7577 "Toggle follow mode in an agenda buffer."
7578 (interactive)
7579 (unless org-agenda-follow-mode
7580 (setq org-agenda-pre-follow-window-conf
7581 (current-window-configuration)))
7582 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7583 (unless org-agenda-follow-mode
7584 (set-window-configuration org-agenda-pre-follow-window-conf))
7585 (org-agenda-set-mode-name)
7586 (org-agenda-do-context-action)
7587 (message "Follow mode is %s"
7588 (if org-agenda-follow-mode "on" "off")))
7590 (defun org-agenda-entry-text-mode (&optional arg)
7591 "Toggle entry text mode in an agenda buffer."
7592 (interactive "P")
7593 (setq org-agenda-entry-text-mode (or (integerp arg)
7594 (not org-agenda-entry-text-mode)))
7595 (org-agenda-entry-text-hide)
7596 (and org-agenda-entry-text-mode
7597 (let ((org-agenda-entry-text-maxlines
7598 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7599 (org-agenda-entry-text-show)))
7600 (org-agenda-set-mode-name)
7601 (message "Entry text mode is %s. Maximum number of lines is %d"
7602 (if org-agenda-entry-text-mode "on" "off")
7603 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7605 (defun org-agenda-clockreport-mode (&optional with-filter)
7606 "Toggle clocktable mode in an agenda buffer.
7607 With prefix arg WITH-FILTER, make the clocktable respect the current
7608 agenda filter."
7609 (interactive "P")
7610 (org-agenda-check-type t 'agenda)
7611 (if with-filter
7612 (setq org-agenda-clockreport-mode 'with-filter)
7613 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7614 (org-agenda-set-mode-name)
7615 (org-agenda-redo)
7616 (message "Clocktable mode is %s"
7617 (if org-agenda-clockreport-mode "on" "off")))
7619 (defun org-agenda-log-mode (&optional special)
7620 "Toggle log mode in an agenda buffer.
7621 With argument SPECIAL, show all possible log items, not only the ones
7622 configured in `org-agenda-log-mode-items'.
7623 With a double `C-u' prefix arg, show *only* log items, nothing else."
7624 (interactive "P")
7625 (org-agenda-check-type t 'agenda 'timeline)
7626 (setq org-agenda-show-log
7627 (cond
7628 ((equal special '(16)) 'only)
7629 ((eq special 'clockcheck)
7630 (if (eq org-agenda-show-log 'clockcheck)
7631 nil 'clockcheck))
7632 (special '(closed clock state))
7633 (t (not org-agenda-show-log))))
7634 (org-agenda-set-mode-name)
7635 (org-agenda-redo)
7636 (message "Log mode is %s"
7637 (if org-agenda-show-log "on" "off")))
7639 (defun org-agenda-archives-mode (&optional with-files)
7640 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7641 When called with a prefix argument, include all archive files as well."
7642 (interactive "P")
7643 (setq org-agenda-archives-mode
7644 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7645 (org-agenda-set-mode-name)
7646 (org-agenda-redo)
7647 (message
7648 "%s"
7649 (cond
7650 ((eq org-agenda-archives-mode nil)
7651 "No archives are included")
7652 ((eq org-agenda-archives-mode 'trees)
7653 (format "Trees with :%s: tag are included" org-archive-tag))
7654 ((eq org-agenda-archives-mode t)
7655 (format "Trees with :%s: tag and all active archive files are included"
7656 org-archive-tag)))))
7658 (defun org-agenda-toggle-diary ()
7659 "Toggle diary inclusion in an agenda buffer."
7660 (interactive)
7661 (org-agenda-check-type t 'agenda)
7662 (setq org-agenda-include-diary (not org-agenda-include-diary))
7663 (org-agenda-redo)
7664 (org-agenda-set-mode-name)
7665 (message "Diary inclusion turned %s"
7666 (if org-agenda-include-diary "on" "off")))
7668 (defun org-agenda-toggle-deadlines ()
7669 "Toggle inclusion of entries with a deadline in an agenda buffer."
7670 (interactive)
7671 (org-agenda-check-type t 'agenda)
7672 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7673 (org-agenda-redo)
7674 (org-agenda-set-mode-name)
7675 (message "Deadlines inclusion turned %s"
7676 (if org-agenda-include-deadlines "on" "off")))
7678 (defun org-agenda-toggle-time-grid ()
7679 "Toggle time grid in an agenda buffer."
7680 (interactive)
7681 (org-agenda-check-type t 'agenda)
7682 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7683 (org-agenda-redo)
7684 (org-agenda-set-mode-name)
7685 (message "Time-grid turned %s"
7686 (if org-agenda-use-time-grid "on" "off")))
7688 (defun org-agenda-set-mode-name ()
7689 "Set the mode name to indicate all the small mode settings."
7690 (setq mode-name
7691 (list "Org-Agenda"
7692 (if (get 'org-agenda-files 'org-restrict) " []" "")
7694 '(:eval (org-agenda-span-name org-agenda-current-span))
7695 (if org-agenda-follow-mode " Follow" "")
7696 (if org-agenda-entry-text-mode " ETxt" "")
7697 (if org-agenda-include-diary " Diary" "")
7698 (if org-agenda-include-deadlines " Ddl" "")
7699 (if org-agenda-use-time-grid " Grid" "")
7700 (if (and (boundp 'org-habit-show-habits)
7701 org-habit-show-habits) " Habit" "")
7702 (cond
7703 ((consp org-agenda-show-log) " LogAll")
7704 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7705 (org-agenda-show-log " Log")
7706 (t ""))
7707 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7708 :preset-filter))
7709 '(:eval (org-propertize
7710 (concat " <"
7711 (mapconcat
7712 'identity
7713 (append
7714 (get 'org-agenda-category-filter :preset-filter)
7715 org-agenda-category-filter)
7717 ">")
7718 'face 'org-agenda-filter-category
7719 'help-echo "Category used in filtering"))
7721 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7722 :preset-filter))
7723 '(:eval (org-propertize
7724 (concat " {"
7725 (mapconcat
7726 'identity
7727 (append
7728 (get 'org-agenda-tag-filter :preset-filter)
7729 org-agenda-tag-filter)
7731 "}")
7732 'face 'org-agenda-filter-tags
7733 'help-echo "Tags used in filtering"))
7735 (if org-agenda-archives-mode
7736 (if (eq org-agenda-archives-mode t)
7737 " Archives"
7738 (format " :%s:" org-archive-tag))
7740 (if org-agenda-clockreport-mode
7741 (if (eq org-agenda-clockreport-mode 'with-filter)
7742 " Clock{}" " Clock")
7743 "")))
7744 (force-mode-line-update))
7746 (define-obsolete-function-alias
7747 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7749 (defun org-agenda-update-agenda-type ()
7750 "Update the agenda type after each command."
7751 (setq org-agenda-type
7752 (or (get-text-property (point) 'org-agenda-type)
7753 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7755 (defun org-agenda-next-line ()
7756 "Move cursor to the next line, and show if follow mode is active."
7757 (interactive)
7758 (call-interactively 'next-line)
7759 (org-agenda-do-context-action))
7761 (defun org-agenda-previous-line ()
7762 "Move cursor to the previous line, and show if follow-mode is active."
7763 (interactive)
7764 (call-interactively 'previous-line)
7765 (org-agenda-do-context-action))
7767 (defun org-agenda-next-item (n)
7768 "Move cursor to next agenda item."
7769 (interactive "p")
7770 (let ((col (current-column)))
7771 (dotimes (c n)
7772 (when (next-single-property-change (point-at-eol) 'org-marker)
7773 (move-end-of-line 1)
7774 (goto-char (next-single-property-change (point) 'org-marker))))
7775 (org-move-to-column col))
7776 (org-agenda-do-context-action))
7778 (defun org-agenda-previous-item (n)
7779 "Move cursor to next agenda item."
7780 (interactive "p")
7781 (dotimes (c n)
7782 (let ((col (current-column))
7783 (goto (save-excursion
7784 (move-end-of-line 0)
7785 (previous-single-property-change (point) 'org-marker))))
7786 (if goto (goto-char goto))
7787 (org-move-to-column col)))
7788 (org-agenda-do-context-action))
7790 (defun org-agenda-do-context-action ()
7791 "Show outline path and, maybe, follow mode window."
7792 (let ((m (org-get-at-bol 'org-marker)))
7793 (when (and (markerp m) (marker-buffer m))
7794 (and org-agenda-follow-mode
7795 (if org-agenda-follow-indirect
7796 (org-agenda-tree-to-indirect-buffer nil)
7797 (org-agenda-show)))
7798 (and org-agenda-show-outline-path
7799 (org-with-point-at m (org-display-outline-path t))))))
7801 (defun org-agenda-show-tags ()
7802 "Show the tags applicable to the current item."
7803 (interactive)
7804 (let* ((tags (org-get-at-bol 'tags)))
7805 (if tags
7806 (message "Tags are :%s:"
7807 (org-no-properties (mapconcat 'identity tags ":")))
7808 (message "No tags associated with this line"))))
7810 (defun org-agenda-goto (&optional highlight)
7811 "Go to the Org-mode file which contains the item at point."
7812 (interactive)
7813 (let* ((marker (or (org-get-at-bol 'org-marker)
7814 (org-agenda-error)))
7815 (buffer (marker-buffer marker))
7816 (pos (marker-position marker)))
7817 (switch-to-buffer-other-window buffer)
7818 (widen)
7819 (push-mark)
7820 (goto-char pos)
7821 (when (derived-mode-p 'org-mode)
7822 (org-show-context 'agenda)
7823 (save-excursion
7824 (and (outline-next-heading)
7825 (org-flag-heading nil)))) ; show the next heading
7826 (when (outline-invisible-p)
7827 (show-entry)) ; display invisible text
7828 (recenter (/ (window-height) 2))
7829 (run-hooks 'org-agenda-after-show-hook)
7830 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7832 (defvar org-agenda-after-show-hook nil
7833 "Normal hook run after an item has been shown from the agenda.
7834 Point is in the buffer where the item originated.")
7836 (defun org-agenda-kill ()
7837 "Kill the entry or subtree belonging to the current agenda entry."
7838 (interactive)
7839 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7840 (let* ((bufname-orig (buffer-name))
7841 (marker (or (org-get-at-bol 'org-marker)
7842 (org-agenda-error)))
7843 (buffer (marker-buffer marker))
7844 (pos (marker-position marker))
7845 (type (org-get-at-bol 'type))
7846 dbeg dend (n 0) conf)
7847 (org-with-remote-undo buffer
7848 (with-current-buffer buffer
7849 (save-excursion
7850 (goto-char pos)
7851 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7852 (setq dbeg (progn (org-back-to-heading t) (point))
7853 dend (org-end-of-subtree t t))
7854 (setq dbeg (point-at-bol)
7855 dend (min (point-max) (1+ (point-at-eol)))))
7856 (goto-char dbeg)
7857 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7858 (setq conf (or (eq t org-agenda-confirm-kill)
7859 (and (numberp org-agenda-confirm-kill)
7860 (> n org-agenda-confirm-kill))))
7861 (and conf
7862 (not (y-or-n-p
7863 (format "Delete entry with %d lines in buffer \"%s\"? "
7864 n (buffer-name buffer))))
7865 (error "Abort"))
7866 (let ((org-agenda-buffer-name bufname-orig))
7867 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7868 (with-current-buffer buffer (delete-region dbeg dend))
7869 (message "Agenda item and source killed"))))
7871 (defvar org-archive-default-command) ; defined in org-archive.el
7872 (defun org-agenda-archive-default ()
7873 "Archive the entry or subtree belonging to the current agenda entry."
7874 (interactive)
7875 (require 'org-archive)
7876 (org-agenda-archive-with org-archive-default-command))
7878 (defun org-agenda-archive-default-with-confirmation ()
7879 "Archive the entry or subtree belonging to the current agenda entry."
7880 (interactive)
7881 (require 'org-archive)
7882 (org-agenda-archive-with org-archive-default-command 'confirm))
7884 (defun org-agenda-archive ()
7885 "Archive the entry or subtree belonging to the current agenda entry."
7886 (interactive)
7887 (org-agenda-archive-with 'org-archive-subtree))
7889 (defun org-agenda-archive-to-archive-sibling ()
7890 "Move the entry to the archive sibling."
7891 (interactive)
7892 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7894 (defun org-agenda-archive-with (cmd &optional confirm)
7895 "Move the entry to the archive sibling."
7896 (interactive)
7897 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7898 (let* ((bufname-orig (buffer-name))
7899 (marker (or (org-get-at-bol 'org-marker)
7900 (org-agenda-error)))
7901 (buffer (marker-buffer marker))
7902 (pos (marker-position marker)))
7903 (org-with-remote-undo buffer
7904 (with-current-buffer buffer
7905 (if (derived-mode-p 'org-mode)
7906 (if (and confirm
7907 (not (y-or-n-p "Archive this subtree or entry? ")))
7908 (error "Abort")
7909 (save-excursion
7910 (goto-char pos)
7911 (let ((org-agenda-buffer-name bufname-orig))
7912 (org-remove-subtree-entries-from-agenda))
7913 (org-back-to-heading t)
7914 (funcall cmd)))
7915 (error "Archiving works only in Org-mode files"))))))
7917 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7918 "Remove all lines in the agenda that correspond to a given subtree.
7919 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7920 If this information is not given, the function uses the tree at point."
7921 (let ((buf (or buf (current-buffer))) m p)
7922 (save-excursion
7923 (unless (and beg end)
7924 (org-back-to-heading t)
7925 (setq beg (point))
7926 (org-end-of-subtree t)
7927 (setq end (point)))
7928 (set-buffer (get-buffer org-agenda-buffer-name))
7929 (save-excursion
7930 (goto-char (point-max))
7931 (beginning-of-line 1)
7932 (while (not (bobp))
7933 (when (and (setq m (org-get-at-bol 'org-marker))
7934 (equal buf (marker-buffer m))
7935 (setq p (marker-position m))
7936 (>= p beg)
7937 (< p end))
7938 (let ((inhibit-read-only t))
7939 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7940 (beginning-of-line 0))))))
7942 (defun org-agenda-refile (&optional goto rfloc no-update)
7943 "Refile the item at point."
7944 (interactive "P")
7945 (if (equal goto '(16))
7946 (org-refile-goto-last-stored)
7947 (let* ((buffer-orig (buffer-name))
7948 (marker (or (org-get-at-bol 'org-hd-marker)
7949 (org-agenda-error)))
7950 (buffer (marker-buffer marker))
7951 (pos (marker-position marker))
7952 (rfloc (or rfloc
7953 (org-refile-get-location
7954 (if goto "Goto" "Refile to") buffer
7955 org-refile-allow-creating-parent-nodes))))
7956 (with-current-buffer buffer
7957 (save-excursion
7958 (save-restriction
7959 (widen)
7960 (goto-char marker)
7961 (let ((org-agenda-buffer-name buffer-orig))
7962 (org-remove-subtree-entries-from-agenda))
7963 (org-refile goto buffer rfloc)))))
7964 (unless no-update (org-agenda-redo))))
7966 (defun org-agenda-open-link (&optional arg)
7967 "Follow the link in the current line, if any.
7968 This looks for a link in the displayed line in the agenda. It also looks
7969 at the text of the entry itself."
7970 (interactive "P")
7971 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7972 (org-get-at-bol 'org-marker)))
7973 (buffer (and marker (marker-buffer marker)))
7974 (prefix (buffer-substring
7975 (point-at-bol) (point-at-eol))))
7976 (cond
7977 (buffer
7978 (with-current-buffer buffer
7979 (save-excursion
7980 (save-restriction
7981 (widen)
7982 (goto-char marker)
7983 (org-offer-links-in-entry arg prefix)))))
7984 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7985 (save-excursion
7986 (beginning-of-line 1)
7987 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7988 (org-open-link-from-string (match-string 1)))
7989 (t (error "No link to open here")))))
7991 (defun org-agenda-copy-local-variable (var)
7992 "Get a variable from a referenced buffer and install it here."
7993 (let ((m (org-get-at-bol 'org-marker)))
7994 (when (and m (buffer-live-p (marker-buffer m)))
7995 (org-set-local var (with-current-buffer (marker-buffer m)
7996 (symbol-value var))))))
7998 (defun org-agenda-switch-to (&optional delete-other-windows)
7999 "Go to the Org-mode file which contains the item at point."
8000 (interactive)
8001 (if (and org-return-follows-link
8002 (not (org-get-at-bol 'org-marker))
8003 (org-in-regexp org-bracket-link-regexp))
8004 (org-open-link-from-string (match-string 0))
8005 (let* ((marker (or (org-get-at-bol 'org-marker)
8006 (org-agenda-error)))
8007 (buffer (marker-buffer marker))
8008 (pos (marker-position marker)))
8009 (org-pop-to-buffer-same-window buffer)
8010 (and delete-other-windows (delete-other-windows))
8011 (widen)
8012 (goto-char pos)
8013 (when (derived-mode-p 'org-mode)
8014 (org-show-context 'agenda)
8015 (save-excursion
8016 (and (outline-next-heading)
8017 (org-flag-heading nil))) ; show the next heading
8018 (when (outline-invisible-p)
8019 (show-entry)) ; display invisible text
8020 (run-hooks 'org-agenda-after-show-hook)))))
8022 (defun org-agenda-goto-mouse (ev)
8023 "Go to the Org-mode file which contains the item at the mouse click."
8024 (interactive "e")
8025 (mouse-set-point ev)
8026 (org-agenda-goto))
8028 (defun org-agenda-show (&optional full-entry)
8029 "Display the Org-mode file which contains the item at point.
8030 With prefix argument FULL-ENTRY, make the entire entry visible
8031 if it was hidden in the outline."
8032 (interactive "P")
8033 (let ((win (selected-window)))
8034 (if full-entry
8035 (let ((org-show-entry-below t))
8036 (org-agenda-goto t))
8037 (org-agenda-goto t))
8038 (select-window win)))
8040 (defvar org-agenda-show-window nil)
8041 (defun org-agenda-show-and-scroll-up (&optional arg)
8042 "Display the Org-mode file which contains the item at point.
8043 When called repeatedly, scroll the window that is displaying the buffer.
8044 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8045 `show-subtree' to display the item, so that drawers and logbooks stay
8046 folded."
8047 (interactive "P")
8048 (let ((win (selected-window)))
8049 (if (and (window-live-p org-agenda-show-window)
8050 (eq this-command last-command))
8051 (progn
8052 (select-window org-agenda-show-window)
8053 (ignore-errors (scroll-up)))
8054 (org-agenda-goto t)
8055 (if arg (org-show-entry) (show-subtree))
8056 (setq org-agenda-show-window (selected-window)))
8057 (select-window win)))
8059 (defun org-agenda-show-scroll-down ()
8060 "Scroll down the window showing the agenda."
8061 (interactive)
8062 (let ((win (selected-window)))
8063 (when (window-live-p org-agenda-show-window)
8064 (select-window org-agenda-show-window)
8065 (ignore-errors (scroll-down))
8066 (select-window win))))
8068 (defun org-agenda-show-1 (&optional more)
8069 "Display the Org-mode file which contains the item at point.
8070 The prefix arg selects the amount of information to display:
8072 0 hide the subtree
8073 1 just show the entry according to defaults.
8074 2 show the children view
8075 3 show the subtree view
8076 4 show the entire subtree and any LOGBOOK drawers
8077 5 show the entire subtree and any drawers
8078 With prefix argument FULL-ENTRY, make the entire entry visible
8079 if it was hidden in the outline."
8080 (interactive "p")
8081 (let ((win (selected-window)))
8082 (org-agenda-goto t)
8083 (org-recenter-heading 1)
8084 (cond
8085 ((= more 0)
8086 (hide-subtree)
8087 (save-excursion
8088 (org-back-to-heading)
8089 (run-hook-with-args 'org-cycle-hook 'folded))
8090 (message "Remote: FOLDED"))
8091 ((and (org-called-interactively-p 'any) (= more 1))
8092 (message "Remote: show with default settings"))
8093 ((= more 2)
8094 (show-entry)
8095 (show-children)
8096 (save-excursion
8097 (org-back-to-heading)
8098 (run-hook-with-args 'org-cycle-hook 'children))
8099 (message "Remote: CHILDREN"))
8100 ((= more 3)
8101 (show-subtree)
8102 (save-excursion
8103 (org-back-to-heading)
8104 (run-hook-with-args 'org-cycle-hook 'subtree))
8105 (message "Remote: SUBTREE"))
8106 ((= more 4)
8107 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8108 (org-drawer-regexp
8109 (concat "^[ \t]*:\\("
8110 (mapconcat 'regexp-quote org-drawers "\\|")
8111 "\\):[ \t]*$")))
8112 (show-subtree)
8113 (save-excursion
8114 (org-back-to-heading)
8115 (org-cycle-hide-drawers 'subtree)))
8116 (message "Remote: SUBTREE AND LOGBOOK"))
8117 ((> more 4)
8118 (show-subtree)
8119 (message "Remote: SUBTREE AND ALL DRAWERS")))
8120 (select-window win)))
8122 (defun org-recenter-heading (n)
8123 (save-excursion
8124 (org-back-to-heading)
8125 (recenter n)))
8127 (defvar org-agenda-cycle-counter nil)
8128 (defun org-agenda-cycle-show (&optional n)
8129 "Show the current entry in another window, with default settings.
8130 Default settings are taken from `org-show-hierarchy-above' and siblings.
8131 When use repeatedly in immediate succession, the remote entry will cycle
8132 through visibility
8134 children -> subtree -> folded
8136 When called with a numeric prefix arg, that arg will be passed through to
8137 `org-agenda-show-1'. For the interpretation of that argument, see the
8138 docstring of `org-agenda-show-1'."
8139 (interactive "P")
8140 (if (integerp n)
8141 (setq org-agenda-cycle-counter n)
8142 (if (not (eq last-command this-command))
8143 (setq org-agenda-cycle-counter 1)
8144 (if (equal org-agenda-cycle-counter 0)
8145 (setq org-agenda-cycle-counter 2)
8146 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8147 (if (> org-agenda-cycle-counter 3)
8148 (setq org-agenda-cycle-counter 0)))))
8149 (org-agenda-show-1 org-agenda-cycle-counter))
8151 (defun org-agenda-recenter (arg)
8152 "Display the Org-mode file which contains the item at point and recenter."
8153 (interactive "P")
8154 (let ((win (selected-window)))
8155 (org-agenda-goto t)
8156 (recenter arg)
8157 (select-window win)))
8159 (defun org-agenda-show-mouse (ev)
8160 "Display the Org-mode file which contains the item at the mouse click."
8161 (interactive "e")
8162 (mouse-set-point ev)
8163 (org-agenda-show))
8165 (defun org-agenda-check-no-diary ()
8166 "Check if the entry is a diary link and abort if yes."
8167 (if (org-get-at-bol 'org-agenda-diary-link)
8168 (org-agenda-error)))
8170 (defun org-agenda-error ()
8171 (error "Command not allowed in this line"))
8173 (defun org-agenda-tree-to-indirect-buffer (arg)
8174 "Show the subtree corresponding to the current entry in an indirect buffer.
8175 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8177 With a numerical prefix ARG, go up to this level and then take that tree.
8178 With a negative numeric ARG, go up by this number of levels.
8179 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8180 use the dedicated frame)."
8181 (interactive "P")
8182 (if current-prefix-arg
8183 (org-agenda-do-tree-to-indirect-buffer arg)
8184 (let ((agenda-buffer (buffer-name))
8185 (agenda-window (selected-window))
8186 (indirect-window
8187 (and org-last-indirect-buffer
8188 (get-buffer-window org-last-indirect-buffer))))
8189 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8190 (unless (or (eq org-indirect-buffer-display 'new-frame)
8191 (eq org-indirect-buffer-display 'dedicated-frame))
8192 (unwind-protect
8193 (unless (and indirect-window (window-live-p indirect-window))
8194 (setq indirect-window (split-window agenda-window)))
8195 (and indirect-window (select-window indirect-window))
8196 (switch-to-buffer org-last-indirect-buffer :norecord)
8197 (fit-window-to-buffer indirect-window)))
8198 (select-window (get-buffer-window agenda-buffer)))))
8200 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8201 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8202 (org-agenda-check-no-diary)
8203 (let* ((marker (or (org-get-at-bol 'org-marker)
8204 (org-agenda-error)))
8205 (buffer (marker-buffer marker))
8206 (pos (marker-position marker)))
8207 (with-current-buffer buffer
8208 (save-excursion
8209 (goto-char pos)
8210 (funcall 'org-tree-to-indirect-buffer arg)))))
8212 (defvar org-last-heading-marker (make-marker)
8213 "Marker pointing to the headline that last changed its TODO state
8214 by a remote command from the agenda.")
8216 (defun org-agenda-todo-nextset ()
8217 "Switch TODO entry to next sequence."
8218 (interactive)
8219 (org-agenda-todo 'nextset))
8221 (defun org-agenda-todo-previousset ()
8222 "Switch TODO entry to previous sequence."
8223 (interactive)
8224 (org-agenda-todo 'previousset))
8226 (defun org-agenda-todo (&optional arg)
8227 "Cycle TODO state of line at point, also in Org-mode file.
8228 This changes the line at point, all other lines in the agenda referring to
8229 the same tree node, and the headline of the tree node in the Org-mode file."
8230 (interactive "P")
8231 (org-agenda-check-no-diary)
8232 (let* ((col (current-column))
8233 (marker (or (org-get-at-bol 'org-marker)
8234 (org-agenda-error)))
8235 (buffer (marker-buffer marker))
8236 (pos (marker-position marker))
8237 (hdmarker (org-get-at-bol 'org-hd-marker))
8238 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8239 (inhibit-read-only t)
8240 org-agenda-headline-snapshot-before-repeat newhead just-one)
8241 (org-with-remote-undo buffer
8242 (with-current-buffer buffer
8243 (widen)
8244 (goto-char pos)
8245 (org-show-context 'agenda)
8246 (save-excursion
8247 (and (outline-next-heading)
8248 (org-flag-heading nil))) ; show the next heading
8249 (let ((current-prefix-arg arg))
8250 (call-interactively 'org-todo))
8251 (and (bolp) (forward-char 1))
8252 (setq newhead (org-get-heading))
8253 (when (and (org-bound-and-true-p
8254 org-agenda-headline-snapshot-before-repeat)
8255 (not (equal org-agenda-headline-snapshot-before-repeat
8256 newhead))
8257 todayp)
8258 (setq newhead org-agenda-headline-snapshot-before-repeat
8259 just-one t))
8260 (save-excursion
8261 (org-back-to-heading)
8262 (move-marker org-last-heading-marker (point))))
8263 (beginning-of-line 1)
8264 (save-excursion
8265 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8266 (org-move-to-column col))))
8268 (defun org-agenda-add-note (&optional arg)
8269 "Add a time-stamped note to the entry at point."
8270 (interactive "P")
8271 (org-agenda-check-no-diary)
8272 (let* ((marker (or (org-get-at-bol 'org-marker)
8273 (org-agenda-error)))
8274 (buffer (marker-buffer marker))
8275 (pos (marker-position marker))
8276 (hdmarker (org-get-at-bol 'org-hd-marker))
8277 (inhibit-read-only t))
8278 (with-current-buffer buffer
8279 (widen)
8280 (goto-char pos)
8281 (org-show-context 'agenda)
8282 (save-excursion
8283 (and (outline-next-heading)
8284 (org-flag-heading nil))) ; show the next heading
8285 (org-add-note))))
8287 (defun org-agenda-change-all-lines (newhead hdmarker
8288 &optional fixface just-this)
8289 "Change all lines in the agenda buffer which match HDMARKER.
8290 The new content of the line will be NEWHEAD (as modified by
8291 `org-agenda-format-item'). HDMARKER is checked with
8292 `equal' against all `org-hd-marker' text properties in the file.
8293 If FIXFACE is non-nil, the face of each item is modified according to
8294 the new TODO state.
8295 If JUST-THIS is non-nil, change just the current line, not all.
8296 If FORCE-TAGS is non nil, the car of it returns the new tags."
8297 (let* ((inhibit-read-only t)
8298 (line (org-current-line))
8299 (org-agenda-buffer (current-buffer))
8300 (thetags (with-current-buffer (marker-buffer hdmarker)
8301 (save-excursion (save-restriction (widen)
8302 (goto-char hdmarker)
8303 (org-get-tags-at)))))
8304 props m pl undone-face done-face finish new dotime level cat tags)
8305 (save-excursion
8306 (goto-char (point-max))
8307 (beginning-of-line 1)
8308 (while (not finish)
8309 (setq finish (bobp))
8310 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8311 (or (not just-this) (= (org-current-line) line))
8312 (equal m hdmarker))
8313 (setq props (text-properties-at (point))
8314 dotime (org-get-at-bol 'dotime)
8315 cat (org-get-at-bol 'org-category)
8316 level (org-get-at-bol 'level)
8317 tags thetags
8319 (let ((org-prefix-format-compiled
8320 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8321 org-prefix-format-compiled))
8322 (extra (org-get-at-bol 'extra)))
8323 (with-current-buffer (marker-buffer hdmarker)
8324 (save-excursion
8325 (save-restriction
8326 (widen)
8327 (org-agenda-format-item extra newhead level cat tags dotime)))))
8328 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8329 undone-face (org-get-at-bol 'undone-face)
8330 done-face (org-get-at-bol 'done-face))
8331 (beginning-of-line 1)
8332 (cond
8333 ((equal new "")
8334 (and (looking-at ".*\n?") (replace-match "")))
8335 ((looking-at ".*")
8336 (replace-match new t t)
8337 (beginning-of-line 1)
8338 (add-text-properties (point-at-bol) (point-at-eol) props)
8339 (when fixface
8340 (add-text-properties
8341 (point-at-bol) (point-at-eol)
8342 (list 'face
8343 (if org-last-todo-state-is-todo
8344 undone-face done-face))))
8345 (org-agenda-highlight-todo 'line)
8346 (beginning-of-line 1))
8347 (t (error "Line update did not work")))
8348 (save-restriction
8349 (narrow-to-region (point-at-bol) (point-at-eol))
8350 (org-agenda-finalize)))
8351 (beginning-of-line 0)))))
8353 (defun org-agenda-align-tags (&optional line)
8354 "Align all tags in agenda items to `org-agenda-tags-column'."
8355 (let ((inhibit-read-only t) l c)
8356 (save-excursion
8357 (goto-char (if line (point-at-bol) (point-min)))
8358 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8359 (if line (point-at-eol) nil) t)
8360 (add-text-properties
8361 (match-beginning 2) (match-end 2)
8362 (list 'face (delq nil (let ((prop (get-text-property
8363 (match-beginning 2) 'face)))
8364 (or (listp prop) (setq prop (list prop)))
8365 (if (memq 'org-tag prop)
8366 prop
8367 (cons 'org-tag prop))))))
8368 (setq l (- (match-end 2) (match-beginning 2))
8369 c (if (< org-agenda-tags-column 0)
8370 (- (abs org-agenda-tags-column) l)
8371 org-agenda-tags-column))
8372 (delete-region (match-beginning 1) (match-end 1))
8373 (goto-char (match-beginning 1))
8374 (insert (org-add-props
8375 (make-string (max 1 (- c (current-column))) ?\ )
8376 (plist-put (copy-sequence (text-properties-at (point)))
8377 'face nil))))
8378 (goto-char (point-min))
8379 (org-font-lock-add-tag-faces (point-max)))))
8381 (defun org-agenda-priority-up ()
8382 "Increase the priority of line at point, also in Org-mode file."
8383 (interactive)
8384 (org-agenda-priority 'up))
8386 (defun org-agenda-priority-down ()
8387 "Decrease the priority of line at point, also in Org-mode file."
8388 (interactive)
8389 (org-agenda-priority 'down))
8391 (defun org-agenda-priority (&optional force-direction show)
8392 "Set the priority of line at point, also in Org-mode file.
8393 This changes the line at point, all other lines in the agenda referring to
8394 the same tree node, and the headline of the tree node in the Org-mode file."
8395 (interactive "P")
8396 (if (equal force-direction '(4)) (setq show t))
8397 (unless org-enable-priority-commands
8398 (error "Priority commands are disabled"))
8399 (org-agenda-check-no-diary)
8400 (let* ((marker (or (org-get-at-bol 'org-marker)
8401 (org-agenda-error)))
8402 (hdmarker (org-get-at-bol 'org-hd-marker))
8403 (buffer (marker-buffer hdmarker))
8404 (pos (marker-position hdmarker))
8405 (inhibit-read-only t)
8406 newhead)
8407 (org-with-remote-undo buffer
8408 (with-current-buffer buffer
8409 (widen)
8410 (goto-char pos)
8411 (org-show-context 'agenda)
8412 (save-excursion
8413 (and (outline-next-heading)
8414 (org-flag-heading nil))) ; show the next heading
8415 (funcall 'org-priority force-direction show)
8416 (end-of-line 1)
8417 (setq newhead (org-get-heading)))
8418 (org-agenda-change-all-lines newhead hdmarker)
8419 (beginning-of-line 1))))
8421 ;; FIXME: should fix the tags property of the agenda line.
8422 (defun org-agenda-set-tags (&optional tag onoff)
8423 "Set tags for the current headline."
8424 (interactive)
8425 (org-agenda-check-no-diary)
8426 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8427 (call-interactively 'org-change-tag-in-region)
8428 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8429 (org-agenda-error)))
8430 (buffer (marker-buffer hdmarker))
8431 (pos (marker-position hdmarker))
8432 (inhibit-read-only t)
8433 newhead)
8434 (org-with-remote-undo buffer
8435 (with-current-buffer buffer
8436 (widen)
8437 (goto-char pos)
8438 (save-excursion
8439 (org-show-context 'agenda))
8440 (save-excursion
8441 (and (outline-next-heading)
8442 (org-flag-heading nil))) ; show the next heading
8443 (goto-char pos)
8444 (if tag
8445 (org-toggle-tag tag onoff)
8446 (call-interactively 'org-set-tags))
8447 (end-of-line 1)
8448 (setq newhead (org-get-heading)))
8449 (org-agenda-change-all-lines newhead hdmarker)
8450 (beginning-of-line 1)))))
8452 (defun org-agenda-set-property ()
8453 "Set a property for the current headline."
8454 (interactive)
8455 (org-agenda-check-no-diary)
8456 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8457 (org-agenda-error)))
8458 (buffer (marker-buffer hdmarker))
8459 (pos (marker-position hdmarker))
8460 (inhibit-read-only t)
8461 newhead)
8462 (org-with-remote-undo buffer
8463 (with-current-buffer buffer
8464 (widen)
8465 (goto-char pos)
8466 (save-excursion
8467 (org-show-context 'agenda))
8468 (save-excursion
8469 (and (outline-next-heading)
8470 (org-flag-heading nil))) ; show the next heading
8471 (goto-char pos)
8472 (call-interactively 'org-set-property)))))
8474 (defun org-agenda-set-effort ()
8475 "Set the effort property for the current headline."
8476 (interactive)
8477 (org-agenda-check-no-diary)
8478 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8479 (org-agenda-error)))
8480 (buffer (marker-buffer hdmarker))
8481 (pos (marker-position hdmarker))
8482 (inhibit-read-only t)
8483 newhead)
8484 (org-with-remote-undo buffer
8485 (with-current-buffer buffer
8486 (widen)
8487 (goto-char pos)
8488 (save-excursion
8489 (org-show-context 'agenda))
8490 (save-excursion
8491 (and (outline-next-heading)
8492 (org-flag-heading nil))) ; show the next heading
8493 (goto-char pos)
8494 (call-interactively 'org-set-effort)
8495 (end-of-line 1)
8496 (setq newhead (org-get-heading)))
8497 (org-agenda-change-all-lines newhead hdmarker))))
8499 (defun org-agenda-toggle-archive-tag ()
8500 "Toggle the archive tag for the current entry."
8501 (interactive)
8502 (org-agenda-check-no-diary)
8503 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8504 (org-agenda-error)))
8505 (buffer (marker-buffer hdmarker))
8506 (pos (marker-position hdmarker))
8507 (inhibit-read-only t)
8508 newhead)
8509 (org-with-remote-undo buffer
8510 (with-current-buffer buffer
8511 (widen)
8512 (goto-char pos)
8513 (org-show-context 'agenda)
8514 (save-excursion
8515 (and (outline-next-heading)
8516 (org-flag-heading nil))) ; show the next heading
8517 (call-interactively 'org-toggle-archive-tag)
8518 (end-of-line 1)
8519 (setq newhead (org-get-heading)))
8520 (org-agenda-change-all-lines newhead hdmarker)
8521 (beginning-of-line 1))))
8523 (defun org-agenda-do-date-later (arg)
8524 (interactive "P")
8525 (cond
8526 ((or (equal arg '(16))
8527 (memq last-command
8528 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8529 (setq this-command 'org-agenda-date-later-minutes)
8530 (org-agenda-date-later-minutes 1))
8531 ((or (equal arg '(4))
8532 (memq last-command
8533 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8534 (setq this-command 'org-agenda-date-later-hours)
8535 (org-agenda-date-later-hours 1))
8537 (org-agenda-date-later (prefix-numeric-value arg)))))
8539 (defun org-agenda-do-date-earlier (arg)
8540 (interactive "P")
8541 (cond
8542 ((or (equal arg '(16))
8543 (memq last-command
8544 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8545 (setq this-command 'org-agenda-date-earlier-minutes)
8546 (org-agenda-date-earlier-minutes 1))
8547 ((or (equal arg '(4))
8548 (memq last-command
8549 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8550 (setq this-command 'org-agenda-date-earlier-hours)
8551 (org-agenda-date-earlier-hours 1))
8553 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8555 (defun org-agenda-date-later (arg &optional what)
8556 "Change the date of this item to ARG day(s) later."
8557 (interactive "p")
8558 (org-agenda-check-type t 'agenda 'timeline)
8559 (org-agenda-check-no-diary)
8560 (let* ((marker (or (org-get-at-bol 'org-marker)
8561 (org-agenda-error)))
8562 (buffer (marker-buffer marker))
8563 (pos (marker-position marker))
8564 cdate today)
8565 (org-with-remote-undo buffer
8566 (with-current-buffer buffer
8567 (widen)
8568 (goto-char pos)
8569 (if (not (org-at-timestamp-p))
8570 (error "Cannot find time stamp"))
8571 (when (and org-agenda-move-date-from-past-immediately-to-today
8572 (equal arg 1)
8573 (or (not what) (eq what 'day))
8574 (not (save-match-data (org-at-date-range-p))))
8575 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8576 cdate (calendar-absolute-from-gregorian
8577 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8578 today (org-today))
8579 (if (> today cdate)
8580 ;; immediately shift to today
8581 (setq arg (- today cdate))))
8582 (org-timestamp-change arg (or what 'day))
8583 (when (and (org-at-date-range-p)
8584 (re-search-backward org-tr-regexp-both (point-at-bol)))
8585 (let ((end org-last-changed-timestamp))
8586 (org-timestamp-change arg (or what 'day))
8587 (setq org-last-changed-timestamp
8588 (concat org-last-changed-timestamp "--" end)))))
8589 (org-agenda-show-new-time marker org-last-changed-timestamp))
8590 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8592 (defun org-agenda-date-earlier (arg &optional what)
8593 "Change the date of this item to ARG day(s) earlier."
8594 (interactive "p")
8595 (org-agenda-date-later (- arg) what))
8597 (defun org-agenda-date-later-minutes (arg)
8598 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8599 (interactive "p")
8600 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8601 (org-agenda-date-later arg 'minute))
8603 (defun org-agenda-date-earlier-minutes (arg)
8604 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8605 (interactive "p")
8606 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8607 (org-agenda-date-earlier arg 'minute))
8609 (defun org-agenda-date-later-hours (arg)
8610 "Change the time of this item, in hour steps."
8611 (interactive "p")
8612 (org-agenda-date-later arg 'hour))
8614 (defun org-agenda-date-earlier-hours (arg)
8615 "Change the time of this item, in hour steps."
8616 (interactive "p")
8617 (org-agenda-date-earlier arg 'hour))
8619 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8620 "Show new date stamp via text properties."
8621 ;; We use text properties to make this undoable
8622 (let ((inhibit-read-only t)
8623 (buffer-invisibility-spec))
8624 (setq stamp (concat " " prefix " => " stamp))
8625 (save-excursion
8626 (goto-char (point-max))
8627 (while (not (bobp))
8628 (when (equal marker (org-get-at-bol 'org-marker))
8629 (org-move-to-column (- (window-width) (length stamp)) t)
8630 (org-agenda-fix-tags-filter-overlays-at (point))
8631 (if (featurep 'xemacs)
8632 ;; Use `duplicable' property to trigger undo recording
8633 (let ((ex (make-extent nil nil))
8634 (gl (make-glyph stamp)))
8635 (set-glyph-face gl 'secondary-selection)
8636 (set-extent-properties
8637 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8638 (insert-extent ex (1- (point)) (point-at-eol)))
8639 (add-text-properties
8640 (1- (point)) (point-at-eol)
8641 (list 'display (org-add-props stamp nil
8642 'face 'secondary-selection))))
8643 (beginning-of-line 1))
8644 (beginning-of-line 0)))))
8646 (defun org-agenda-date-prompt (arg)
8647 "Change the date of this item. Date is prompted for, with default today.
8648 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8649 be used to request time specification in the time stamp."
8650 (interactive "P")
8651 (org-agenda-check-type t 'agenda 'timeline)
8652 (org-agenda-check-no-diary)
8653 (let* ((marker (or (org-get-at-bol 'org-marker)
8654 (org-agenda-error)))
8655 (buffer (marker-buffer marker))
8656 (pos (marker-position marker)))
8657 (org-with-remote-undo buffer
8658 (with-current-buffer buffer
8659 (widen)
8660 (goto-char pos)
8661 (if (not (org-at-timestamp-p t))
8662 (error "Cannot find time stamp"))
8663 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8664 (org-agenda-show-new-time marker org-last-changed-timestamp))
8665 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8667 (defun org-agenda-schedule (arg &optional time)
8668 "Schedule the item at point.
8669 ARG is passed through to `org-schedule'."
8670 (interactive "P")
8671 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8672 (org-agenda-check-no-diary)
8673 (let* ((marker (or (org-get-at-bol 'org-marker)
8674 (org-agenda-error)))
8675 (type (marker-insertion-type marker))
8676 (buffer (marker-buffer marker))
8677 (pos (marker-position marker))
8678 (org-insert-labeled-timestamps-at-point nil)
8680 (set-marker-insertion-type marker t)
8681 (org-with-remote-undo buffer
8682 (with-current-buffer buffer
8683 (widen)
8684 (goto-char pos)
8685 (setq ts (org-schedule arg time)))
8686 (org-agenda-show-new-time marker ts "S"))
8687 (message "%s" ts)))
8689 (defun org-agenda-deadline (arg &optional time)
8690 "Schedule the item at point.
8691 ARG is passed through to `org-deadline'."
8692 (interactive "P")
8693 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8694 (org-agenda-check-no-diary)
8695 (let* ((marker (or (org-get-at-bol 'org-marker)
8696 (org-agenda-error)))
8697 (buffer (marker-buffer marker))
8698 (pos (marker-position marker))
8699 (org-insert-labeled-timestamps-at-point nil)
8701 (org-with-remote-undo buffer
8702 (with-current-buffer buffer
8703 (widen)
8704 (goto-char pos)
8705 (setq ts (org-deadline arg time)))
8706 (org-agenda-show-new-time marker ts "D"))
8707 (message "%s" ts)))
8709 (defun org-agenda-clock-in (&optional arg)
8710 "Start the clock on the currently selected item."
8711 (interactive "P")
8712 (org-agenda-check-no-diary)
8713 (if (equal arg '(4))
8714 (org-clock-in arg)
8715 (let* ((marker (or (org-get-at-bol 'org-marker)
8716 (org-agenda-error)))
8717 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8718 marker))
8719 (pos (marker-position marker))
8720 newhead)
8721 (org-with-remote-undo (marker-buffer marker)
8722 (with-current-buffer (marker-buffer marker)
8723 (widen)
8724 (goto-char pos)
8725 (org-show-context 'agenda)
8726 (org-show-entry)
8727 (org-cycle-hide-drawers 'children)
8728 (org-clock-in arg)
8729 (setq newhead (org-get-heading)))
8730 (org-agenda-change-all-lines newhead hdmarker)))))
8732 (defun org-agenda-clock-out ()
8733 "Stop the currently running clock."
8734 (interactive)
8735 (unless (marker-buffer org-clock-marker)
8736 (error "No running clock"))
8737 (let ((marker (make-marker)) newhead)
8738 (org-with-remote-undo (marker-buffer org-clock-marker)
8739 (with-current-buffer (marker-buffer org-clock-marker)
8740 (save-excursion
8741 (save-restriction
8742 (widen)
8743 (goto-char org-clock-marker)
8744 (org-back-to-heading t)
8745 (move-marker marker (point))
8746 (org-clock-out)
8747 (setq newhead (org-get-heading))))))
8748 (org-agenda-change-all-lines newhead marker)
8749 (move-marker marker nil)))
8751 (defun org-agenda-clock-cancel (&optional arg)
8752 "Cancel the currently running clock."
8753 (interactive "P")
8754 (unless (marker-buffer org-clock-marker)
8755 (error "No running clock"))
8756 (org-with-remote-undo (marker-buffer org-clock-marker)
8757 (org-clock-cancel)))
8759 (defun org-agenda-clock-goto ()
8760 "Jump to the currently clocked in task within the agenda.
8761 If the currently clocked in task is not listed in the agenda
8762 buffer, display it in another window."
8763 (interactive)
8764 (let (pos)
8765 (mapc (lambda (o)
8766 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8767 (setq pos (overlay-start o))))
8768 (overlays-in (point-min) (point-max)))
8769 (cond (pos (goto-char pos))
8770 ;; If the currently clocked entry is not in the agenda
8771 ;; buffer, we visit it in another window:
8772 (org-clock-current-task
8773 (org-switch-to-buffer-other-window (org-clock-goto)))
8774 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8776 (defun org-agenda-diary-entry-in-org-file ()
8777 "Make a diary entry in the file `org-agenda-diary-file'."
8778 (let (d1 d2 char (text "") dp1 dp2)
8779 (if (equal (buffer-name) "*Calendar*")
8780 (setq d1 (calendar-cursor-to-date t)
8781 d2 (car calendar-mark-ring))
8782 (setq dp1 (get-text-property (point-at-bol) 'day))
8783 (unless dp1 (error "No date defined in current line"))
8784 (setq d1 (calendar-gregorian-from-absolute dp1)
8785 d2 (and (ignore-errors (mark))
8786 (save-excursion
8787 (goto-char (mark))
8788 (setq dp2 (get-text-property (point-at-bol) 'day)))
8789 (calendar-gregorian-from-absolute dp2))))
8790 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8791 (setq char (read-char-exclusive))
8792 (cond
8793 ((equal char ?d)
8794 (setq text (read-string "Day entry: "))
8795 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8796 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8797 ((equal char ?a)
8798 (setq d1 (list (car d1) (nth 1 d1)
8799 (read-number (format "Reference year [%d]: " (nth 2 d1))
8800 (nth 2 d1))))
8801 (setq text (read-string "Anniversary (use %d to show years): "))
8802 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8803 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8804 ((equal char ?b)
8805 (setq text (read-string "Block entry: "))
8806 (unless (and d1 d2 (not (equal d1 d2)))
8807 (error "No block of days selected"))
8808 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8809 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8810 ((equal char ?j)
8811 (org-switch-to-buffer-other-window
8812 (find-file-noselect org-agenda-diary-file))
8813 (require 'org-datetree)
8814 (org-datetree-find-date-create d1)
8815 (org-reveal t))
8816 (t (error "Invalid selection character `%c'" char)))))
8818 (defcustom org-agenda-insert-diary-strategy 'date-tree
8819 "Where in `org-agenda-diary-file' should new entries be added?
8820 Valid values:
8822 date-tree in the date tree, as child of the date
8823 top-level as top-level entries at the end of the file."
8824 :group 'org-agenda
8825 :type '(choice
8826 (const :tag "in a date tree" date-tree)
8827 (const :tag "as top level at end of file" top-level)))
8829 (defcustom org-agenda-insert-diary-extract-time nil
8830 "Non-nil means extract any time specification from the diary entry."
8831 :group 'org-agenda
8832 :version "24.1"
8833 :type 'boolean)
8835 (defcustom org-agenda-bulk-mark-char ">"
8836 "A single-character string to be used as the bulk mark."
8837 :group 'org-agenda
8838 :version "24.1"
8839 :type 'string)
8841 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8842 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8843 If TEXT is not empty, it will become the headline of the new entry, and
8844 the resulting entry will not be shown. When TEXT is empty, switch to
8845 `org-agenda-diary-file' and let the user finish the entry there."
8846 (let ((cw (current-window-configuration)))
8847 (org-switch-to-buffer-other-window
8848 (find-file-noselect org-agenda-diary-file))
8849 (widen)
8850 (goto-char (point-min))
8851 (cond
8852 ((eq type 'anniversary)
8853 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8854 (progn
8855 (or (org-at-heading-p t)
8856 (progn
8857 (outline-next-heading)
8858 (insert "* Anniversaries\n\n")
8859 (beginning-of-line -1)))))
8860 (outline-next-heading)
8861 (org-back-over-empty-lines)
8862 (backward-char 1)
8863 (insert "\n")
8864 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8865 (nth 2 d1) (car d1) (nth 1 d1) text)))
8866 ((eq type 'day)
8867 (let ((org-prefix-has-time t)
8868 (org-agenda-time-leading-zero t)
8869 fmt time time2)
8870 (if org-agenda-insert-diary-extract-time
8871 ;; Use org-agenda-format-item to parse text for a time-range and
8872 ;; remove it. FIXME: This is a hack, we should refactor
8873 ;; that function to make time extraction available separately
8874 (setq fmt (org-agenda-format-item nil text nil nil nil t)
8875 time (get-text-property 0 'time fmt)
8876 time2 (if (> (length time) 0)
8877 ;; split-string removes trailing ...... if
8878 ;; no end time given. First space
8879 ;; separates time from date.
8880 (concat " " (car (split-string time "\\.")))
8881 nil)
8882 text (get-text-property 0 'txt fmt)))
8883 (if (eq org-agenda-insert-diary-strategy 'top-level)
8884 (org-agenda-insert-diary-as-top-level text)
8885 (require 'org-datetree)
8886 (org-datetree-find-date-create d1)
8887 (org-agenda-insert-diary-make-new-entry text))
8888 (org-insert-time-stamp (org-time-from-absolute
8889 (calendar-absolute-from-gregorian d1))
8890 nil nil nil nil time2))
8891 (end-of-line 0))
8892 ((eq type 'block)
8893 (if (> (calendar-absolute-from-gregorian d1)
8894 (calendar-absolute-from-gregorian d2))
8895 (setq d1 (prog1 d2 (setq d2 d1))))
8896 (if (eq org-agenda-insert-diary-strategy 'top-level)
8897 (org-agenda-insert-diary-as-top-level text)
8898 (require 'org-datetree)
8899 (org-datetree-find-date-create d1)
8900 (org-agenda-insert-diary-make-new-entry text))
8901 (org-insert-time-stamp (org-time-from-absolute
8902 (calendar-absolute-from-gregorian d1)))
8903 (insert "--")
8904 (org-insert-time-stamp (org-time-from-absolute
8905 (calendar-absolute-from-gregorian d2)))
8906 (end-of-line 0)))
8907 (if (string-match "\\S-" text)
8908 (progn
8909 (set-window-configuration cw)
8910 (message "%s entry added to %s"
8911 (capitalize (symbol-name type))
8912 (abbreviate-file-name org-agenda-diary-file)))
8913 (org-reveal t)
8914 (message "Please finish entry here"))))
8916 (defun org-agenda-insert-diary-as-top-level (text)
8917 "Make new entry as a top-level entry at the end of the file.
8918 Add TEXT as headline, and position the cursor in the second line so that
8919 a timestamp can be added there."
8920 (widen)
8921 (goto-char (point-max))
8922 (or (bolp) (insert "\n"))
8923 (insert "* " text "\n")
8924 (if org-adapt-indentation (org-indent-to-column 2)))
8926 (defun org-agenda-insert-diary-make-new-entry (text)
8927 "Make new entry as last child of current entry.
8928 Add TEXT as headline, and position the cursor in the second line so that
8929 a timestamp can be added there."
8930 (let ((org-show-following-heading t)
8931 (org-show-siblings t)
8932 (org-show-hierarchy-above t)
8933 (org-show-entry-below t)
8934 col)
8935 (outline-next-heading)
8936 (org-back-over-empty-lines)
8937 (or (looking-at "[ \t]*$")
8938 (progn (insert "\n") (backward-char 1)))
8939 (org-insert-heading nil t)
8940 (org-do-demote)
8941 (setq col (current-column))
8942 (insert text "\n")
8943 (if org-adapt-indentation (org-indent-to-column col))
8944 (let ((org-show-following-heading t)
8945 (org-show-siblings t)
8946 (org-show-hierarchy-above t)
8947 (org-show-entry-below t))
8948 (org-show-context))))
8950 (defun org-agenda-diary-entry ()
8951 "Make a diary entry, like the `i' command from the calendar.
8952 All the standard commands work: block, weekly etc.
8953 When `org-agenda-diary-file' points to a file,
8954 `org-agenda-diary-entry-in-org-file' is called instead to create
8955 entries in that Org-mode file."
8956 (interactive)
8957 (if (not (eq org-agenda-diary-file 'diary-file))
8958 (org-agenda-diary-entry-in-org-file)
8959 (require 'diary-lib)
8960 (let* ((char (progn
8961 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8962 (read-char-exclusive)))
8963 (cmd (cdr (assoc char
8964 '((?d . insert-diary-entry)
8965 (?w . insert-weekly-diary-entry)
8966 (?m . insert-monthly-diary-entry)
8967 (?y . insert-yearly-diary-entry)
8968 (?a . insert-anniversary-diary-entry)
8969 (?b . insert-block-diary-entry)
8970 (?c . insert-cyclic-diary-entry)))))
8971 (oldf (symbol-function 'calendar-cursor-to-date))
8972 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8973 (point (point))
8974 (mark (or (mark t) (point))))
8975 (unless cmd
8976 (error "No command associated with <%c>" char))
8977 (unless (and (get-text-property point 'day)
8978 (or (not (equal ?b char))
8979 (get-text-property mark 'day)))
8980 (error "Don't know which date to use for diary entry"))
8981 ;; We implement this by hacking the `calendar-cursor-to-date' function
8982 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8983 (let ((calendar-mark-ring
8984 (list (calendar-gregorian-from-absolute
8985 (or (get-text-property mark 'day)
8986 (get-text-property point 'day))))))
8987 (unwind-protect
8988 (progn
8989 (fset 'calendar-cursor-to-date
8990 (lambda (&optional error dummy)
8991 (calendar-gregorian-from-absolute
8992 (get-text-property point 'day))))
8993 (call-interactively cmd))
8994 (fset 'calendar-cursor-to-date oldf))))))
8996 (defun org-agenda-execute-calendar-command (cmd)
8997 "Execute a calendar command from the agenda with date from cursor."
8998 (org-agenda-check-type t 'agenda 'timeline)
8999 (require 'diary-lib)
9000 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9001 (error "Don't know which date to use for the calendar command"))
9002 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9003 (point (point))
9004 (date (calendar-gregorian-from-absolute
9005 (get-text-property point 'day)))
9006 ;; the following 2 vars are needed in the calendar
9007 (displayed-month (car date))
9008 (displayed-year (nth 2 date)))
9009 (unwind-protect
9010 (progn
9011 (fset 'calendar-cursor-to-date
9012 (lambda (&optional error dummy)
9013 (calendar-gregorian-from-absolute
9014 (get-text-property point 'day))))
9015 (call-interactively cmd))
9016 (fset 'calendar-cursor-to-date oldf))))
9018 (defun org-agenda-phases-of-moon ()
9019 "Display the phases of the moon for the 3 months around the cursor date."
9020 (interactive)
9021 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9023 (defun org-agenda-holidays ()
9024 "Display the holidays for the 3 months around the cursor date."
9025 (interactive)
9026 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9028 (defvar calendar-longitude) ; defined in calendar.el
9029 (defvar calendar-latitude) ; defined in calendar.el
9030 (defvar calendar-location-name) ; defined in calendar.el
9032 (defun org-agenda-sunrise-sunset (arg)
9033 "Display sunrise and sunset for the cursor date.
9034 Latitude and longitude can be specified with the variables
9035 `calendar-latitude' and `calendar-longitude'. When called with prefix
9036 argument, latitude and longitude will be prompted for."
9037 (interactive "P")
9038 (require 'solar)
9039 (let ((calendar-longitude (if arg nil calendar-longitude))
9040 (calendar-latitude (if arg nil calendar-latitude))
9041 (calendar-location-name
9042 (if arg "the given coordinates" calendar-location-name)))
9043 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9045 (defun org-agenda-goto-calendar ()
9046 "Open the Emacs calendar with the date at the cursor."
9047 (interactive)
9048 (org-agenda-check-type t 'agenda 'timeline)
9049 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9050 (error "Don't know which date to open in calendar")))
9051 (date (calendar-gregorian-from-absolute day))
9052 (calendar-move-hook nil)
9053 (calendar-view-holidays-initially-flag nil)
9054 (calendar-view-diary-initially-flag nil))
9055 (calendar)
9056 (calendar-goto-date date)))
9058 ;;;###autoload
9059 (defun org-calendar-goto-agenda ()
9060 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9061 This is a command that has to be installed in `calendar-mode-map'."
9062 (interactive)
9063 (org-agenda-list nil (calendar-absolute-from-gregorian
9064 (calendar-cursor-to-date))
9065 nil))
9067 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9068 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9069 This is a command that has to be installed in `calendar-mode-map'.
9071 \(fn)" t nil)
9073 (defun org-agenda-convert-date ()
9074 (interactive)
9075 (org-agenda-check-type t 'agenda 'timeline)
9076 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9077 date s)
9078 (unless day
9079 (error "Don't know which date to convert"))
9080 (setq date (calendar-gregorian-from-absolute day))
9081 (setq s (concat
9082 "Gregorian: " (calendar-date-string date) "\n"
9083 "ISO: " (calendar-iso-date-string date) "\n"
9084 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9085 "Julian: " (calendar-julian-date-string date) "\n"
9086 "Astron. JD: " (calendar-astro-date-string date)
9087 " (Julian date number at noon UTC)\n"
9088 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9089 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9090 "French: " (calendar-french-date-string date) "\n"
9091 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9092 "Mayan: " (calendar-mayan-date-string date) "\n"
9093 "Coptic: " (calendar-coptic-date-string date) "\n"
9094 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9095 "Persian: " (calendar-persian-date-string date) "\n"
9096 "Chinese: " (calendar-chinese-date-string date) "\n"))
9097 (with-output-to-temp-buffer "*Dates*"
9098 (princ s))
9099 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9101 ;;; Bulk commands
9103 (defun org-agenda-bulk-marked-p ()
9104 (eq (get-char-property (point-at-bol) 'type)
9105 'org-marked-entry-overlay))
9107 (defun org-agenda-bulk-mark (&optional arg)
9108 "Mark the entry at point for future bulk action."
9109 (interactive "p")
9110 (dotimes (i (or arg 1))
9111 (unless (org-get-at-bol 'org-agenda-diary-link)
9112 (let* ((m (org-get-at-bol 'org-hd-marker))
9114 (unless (org-agenda-bulk-marked-p)
9115 (unless m (error "Nothing to mark at point"))
9116 (push m org-agenda-bulk-marked-entries)
9117 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9118 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9119 (org-get-todo-face "TODO")
9120 'evaporate)
9121 (overlay-put ov 'type 'org-marked-entry-overlay))
9122 (beginning-of-line 2)
9123 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9124 (beginning-of-line 2))
9125 (message "%d entries marked for bulk action"
9126 (length org-agenda-bulk-marked-entries))))))
9128 (defun org-agenda-bulk-mark-all ()
9129 "Mark all entries for future agenda bulk action."
9130 (interactive)
9131 (org-agenda-bulk-mark-regexp "."))
9133 (defun org-agenda-bulk-mark-regexp (regexp)
9134 "Mark entries matching REGEXP for future agenda bulk action."
9135 (interactive "sMark entries matching regexp: ")
9136 (let ((entries-marked 0))
9137 (save-excursion
9138 (goto-char (point-min))
9139 (goto-char (next-single-property-change (point) 'txt))
9140 (while (re-search-forward regexp nil t)
9141 (when (string-match regexp (get-text-property (point) 'txt))
9142 (setq entries-marked (1+ entries-marked))
9143 (call-interactively 'org-agenda-bulk-mark))))
9144 (if (not entries-marked)
9145 (message "No entry matching this regexp."))))
9147 (defun org-agenda-bulk-unmark (&optional arg)
9148 "Unmark the entry at point for future bulk action."
9149 (interactive "P")
9150 (if arg
9151 (org-agenda-bulk-unmark-all)
9152 (cond ((org-agenda-bulk-marked-p)
9153 (org-agenda-bulk-remove-overlays
9154 (point-at-bol) (+ 2 (point-at-bol)))
9155 (setq org-agenda-bulk-marked-entries
9156 (delete (org-get-at-bol 'org-hd-marker)
9157 org-agenda-bulk-marked-entries))
9158 (beginning-of-line 2)
9159 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9160 (beginning-of-line 2))
9161 (message "%d entries left marked for bulk action"
9162 (length org-agenda-bulk-marked-entries)))
9163 (t (message "No entry to unmark here")))))
9165 (defun org-agenda-bulk-toggle ()
9166 "Toggle marking the entry at point for bulk action."
9167 (interactive)
9168 (if (org-agenda-bulk-marked-p)
9169 (org-agenda-bulk-unmark)
9170 (org-agenda-bulk-mark)))
9172 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9173 "Remove the mark overlays between BEG and END in the agenda buffer.
9174 BEG and END default to the buffer limits.
9176 This only removes the overlays, it does not remove the markers
9177 from the list in `org-agenda-bulk-marked-entries'."
9178 (interactive)
9179 (mapc (lambda (ov)
9180 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9181 (delete-overlay ov)))
9182 (overlays-in (or beg (point-min)) (or end (point-max)))))
9184 (defun org-agenda-bulk-unmark-all ()
9185 "Remove all marks in the agenda buffer.
9186 This will remove the markers and the overlays."
9187 (interactive)
9188 (if (null org-agenda-bulk-marked-entries)
9189 (message "No entry to unmark")
9190 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9191 (setq org-agenda-bulk-marked-entries nil)
9192 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9194 (defcustom org-agenda-persistent-marks nil
9195 "Non-nil means marked items will stay marked after a bulk action.
9196 You can toggle this interactively by typing `p' when prompted for a
9197 bulk action."
9198 :group 'org-agenda
9199 :version "24.1"
9200 :type 'boolean)
9202 (defun org-agenda-bulk-action (&optional arg)
9203 "Execute an remote-editing action on all marked entries.
9204 The prefix arg is passed through to the command if possible."
9205 (interactive "P")
9206 ;; Make sure we have markers, and only valid ones
9207 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9208 (mapc
9209 (lambda (m)
9210 (unless (and (markerp m)
9211 (marker-buffer m)
9212 (buffer-live-p (marker-buffer m))
9213 (marker-position m))
9214 (error "Marker %s for bulk command is invalid" m)))
9215 org-agenda-bulk-marked-entries)
9217 ;; Prompt for the bulk command
9218 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9219 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9220 "[S]catter [f]unction "
9221 (when org-agenda-bulk-custom-functions
9222 (concat " Custom: ["
9223 (mapconcat (lambda(f) (char-to-string (car f)))
9224 org-agenda-bulk-custom-functions "")
9225 "]"))))
9226 (catch 'exit
9227 (let* ((action (read-char-exclusive))
9228 (org-log-refile (if org-log-refile 'time nil))
9229 (entries (reverse org-agenda-bulk-marked-entries))
9230 (org-overriding-default-time
9231 (if (get-text-property (point) 'org-agenda-date-header)
9232 (org-get-cursor-date)))
9233 redo-at-end
9234 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9235 (cond
9236 ((equal action ?p)
9237 (let ((org-agenda-persistent-marks
9238 (not org-agenda-persistent-marks)))
9239 (org-agenda-bulk-action)
9240 (throw 'exit nil)))
9242 ((equal action ?$)
9243 (setq cmd '(org-agenda-archive)))
9245 ((equal action ?A)
9246 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9248 ((member action '(?r ?w))
9249 (setq rfloc (org-refile-get-location
9250 "Refile to"
9251 (marker-buffer (car entries))
9252 org-refile-allow-creating-parent-nodes))
9253 (if (nth 3 rfloc)
9254 (setcar (nthcdr 3 rfloc)
9255 (move-marker (make-marker) (nth 3 rfloc)
9256 (or (get-file-buffer (nth 1 rfloc))
9257 (find-buffer-visiting (nth 1 rfloc))
9258 (error "This should not happen")))))
9260 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9261 redo-at-end t))
9263 ((equal action ?t)
9264 (setq state (org-icompleting-read
9265 "Todo state: "
9266 (with-current-buffer (marker-buffer (car entries))
9267 (mapcar 'list org-todo-keywords-1))))
9268 (setq cmd `(let ((org-inhibit-blocking t)
9269 (org-inhibit-logging 'note))
9270 (org-agenda-todo ,state))))
9272 ((memq action '(?- ?+))
9273 (setq tag (org-icompleting-read
9274 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9275 (with-current-buffer (marker-buffer (car entries))
9276 (delq nil
9277 (mapcar (lambda (x)
9278 (if (stringp (car x)) x)) org-tag-alist)))))
9279 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9281 ((memq action '(?s ?d))
9282 (let* ((time
9283 (unless arg
9284 (org-read-date
9285 nil nil nil
9286 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9287 org-overriding-default-time)))
9288 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9289 (setq cmd `(eval '(,c1 arg ,time)))))
9291 ((equal action ?S)
9292 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9293 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9294 (let ((days (read-number
9295 (format "Scatter tasks across how many %sdays: "
9296 (if arg "week" "")) 7)))
9297 (setq cmd
9298 `(let ((distance (1+ (random ,days))))
9299 (if arg
9300 (let ((dist distance)
9301 (day-of-week
9302 (calendar-day-of-week
9303 (calendar-gregorian-from-absolute (org-today)))))
9304 (dotimes (i (1+ dist))
9305 (while (member day-of-week org-agenda-weekend-days)
9306 (incf distance)
9307 (incf day-of-week)
9308 (if (= day-of-week 7)
9309 (setq day-of-week 0)))
9310 (incf day-of-week)
9311 (if (= day-of-week 7)
9312 (setq day-of-week 0)))))
9313 ;; silently fail when try to replan a sexp entry
9314 (condition-case nil
9315 (let* ((date (calendar-gregorian-from-absolute
9316 (+ (org-today) distance)))
9317 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9318 (nth 2 date))))
9319 (org-agenda-schedule nil time))
9320 (error nil)))))))
9322 ((assoc action org-agenda-bulk-custom-functions)
9323 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9324 redo-at-end t))
9326 ((equal action ?f)
9327 (setq cmd (list (intern
9328 (org-icompleting-read "Function: "
9329 obarray 'fboundp t nil nil)))))
9331 (t (error "Invalid bulk action")))
9333 ;; Sort the markers, to make sure that parents are handled before children
9334 (setq entries (sort entries
9335 (lambda (a b)
9336 (cond
9337 ((equal (marker-buffer a) (marker-buffer b))
9338 (< (marker-position a) (marker-position b)))
9340 (string< (buffer-name (marker-buffer a))
9341 (buffer-name (marker-buffer b))))))))
9343 ;; Now loop over all markers and apply cmd
9344 (while (setq e (pop entries))
9345 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9346 (if (not pos)
9347 (progn (message "Skipping removed entry at %s" e)
9348 (setq cntskip (1+ cntskip)))
9349 (goto-char pos)
9350 (let (org-loop-over-headlines-in-active-region)
9351 (eval cmd))
9352 (setq cnt (1+ cnt))))
9353 (when redo-at-end (org-agenda-redo))
9354 (unless org-agenda-persistent-marks
9355 (org-agenda-bulk-unmark-all))
9356 (message "Acted on %d entries%s%s"
9358 (if (= cntskip 0)
9360 (format ", skipped %d (disappeared before their turn)"
9361 cntskip))
9362 (if (not org-agenda-persistent-marks)
9363 "" " (kept marked)"))))))
9365 (defun org-agenda-capture (&optional with-time)
9366 "Call `org-capture' with the date at point.
9367 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9368 current HH:MM time."
9369 (interactive "P")
9370 (if (not (eq major-mode 'org-agenda-mode))
9371 (user-error "You cannot do this outside of agenda buffers")
9372 (let ((org-overriding-default-time
9373 (org-get-cursor-date (equal with-time 1))))
9374 (call-interactively 'org-capture))))
9376 ;;; Flagging notes
9378 (defun org-agenda-show-the-flagging-note ()
9379 "Display the flagging note in the other window.
9380 When called a second time in direct sequence, offer to remove the FLAGGING
9381 tag and (if present) the flagging note."
9382 (interactive)
9383 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9384 (win (selected-window))
9385 note heading newhead)
9386 (unless hdmarker
9387 (error "No linked entry at point"))
9388 (if (and (eq this-command last-command)
9389 (y-or-n-p "Unflag and remove any flagging note? "))
9390 (progn
9391 (org-agenda-remove-flag hdmarker)
9392 (let ((win (get-buffer-window "*Flagging Note*")))
9393 (and win (delete-window win)))
9394 (message "Entry unflagged"))
9395 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9396 (unless note
9397 (error "No flagging note"))
9398 (org-kill-new note)
9399 (org-switch-to-buffer-other-window "*Flagging Note*")
9400 (erase-buffer)
9401 (insert note)
9402 (goto-char (point-min))
9403 (while (re-search-forward "\\\\n" nil t)
9404 (replace-match "\n" t t))
9405 (goto-char (point-min))
9406 (select-window win)
9407 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9409 (defun org-agenda-remove-flag (marker)
9410 "Remove the FLAGGED tag and any flagging note in the entry."
9411 (let (newhead)
9412 (org-with-point-at marker
9413 (org-toggle-tag "FLAGGED" 'off)
9414 (org-entry-delete nil "THEFLAGGINGNOTE")
9415 (setq newhead (org-get-heading)))
9416 (org-agenda-change-all-lines newhead marker)
9417 (message "Entry unflagged")))
9419 (defun org-agenda-get-any-marker (&optional pos)
9420 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9421 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9423 ;;; Appointment reminders
9425 (defvar appt-time-msg-list) ; defined in appt.el
9427 ;;;###autoload
9428 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9429 "Activate appointments found in `org-agenda-files'.
9430 With a \\[universal-argument] prefix, refresh the list of
9431 appointments.
9433 If FILTER is t, interactively prompt the user for a regular
9434 expression, and filter out entries that don't match it.
9436 If FILTER is a string, use this string as a regular expression
9437 for filtering entries out.
9439 If FILTER is a function, filter out entries against which
9440 calling the function returns nil. This function takes one
9441 argument: an entry from `org-agenda-get-day-entries'.
9443 FILTER can also be an alist with the car of each cell being
9444 either 'headline or 'category. For example:
9446 '((headline \"IMPORTANT\")
9447 (category \"Work\"))
9449 will only add headlines containing IMPORTANT or headlines
9450 belonging to the \"Work\" category.
9452 ARGS are symbols indicating what kind of entries to consider.
9453 By default `org-agenda-to-appt' will use :deadline, :scheduled
9454 and :timestamp entries. See the docstring of `org-diary' for
9455 details and examples.
9457 If an entry as a APPT_WARNTIME property, its value will be used
9458 to override `appt-message-warning-time'."
9459 (interactive "P")
9460 (if refresh (setq appt-time-msg-list nil))
9461 (if (eq filter t)
9462 (setq filter (read-from-minibuffer "Regexp filter: ")))
9463 (let* ((cnt 0) ; count added events
9464 (scope (or args '(:deadline :scheduled :timestamp)))
9465 (org-agenda-new-buffers nil)
9466 (org-deadline-warning-days 0)
9467 ;; Do not use `org-today' here because appt only takes
9468 ;; time and without date as argument, so it may pass wrong
9469 ;; information otherwise
9470 (today (org-date-to-gregorian
9471 (time-to-days (current-time))))
9472 (org-agenda-restrict nil)
9473 (files (org-agenda-files 'unrestricted)) entries file
9474 (org-agenda-buffer nil))
9475 ;; Get all entries which may contain an appt
9476 (org-agenda-prepare-buffers files)
9477 (while (setq file (pop files))
9478 (setq entries
9479 (delq nil
9480 (append entries
9481 (apply 'org-agenda-get-day-entries
9482 file today scope)))))
9483 ;; Map thru entries and find if we should filter them out
9484 (mapc
9485 (lambda(x)
9486 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9487 (cat (get-text-property 1 'org-category x))
9488 (tod (get-text-property 1 'time-of-day x))
9489 (ok (or (null filter)
9490 (and (stringp filter) (string-match filter evt))
9491 (and (functionp filter) (funcall filter x))
9492 (and (listp filter)
9493 (let ((cat-filter (cadr (assoc 'category filter)))
9494 (evt-filter (cadr (assoc 'headline filter))))
9495 (or (and (stringp cat-filter)
9496 (string-match cat-filter cat))
9497 (and (stringp evt-filter)
9498 (string-match evt-filter evt)))))))
9499 (wrn (get-text-property 1 'warntime x)))
9500 ;; FIXME: Shall we remove text-properties for the appt text?
9501 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9502 (when (and ok tod)
9503 (setq tod (concat "00" (number-to-string tod))
9504 tod (when (string-match
9505 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9506 (concat (match-string 1 tod) ":"
9507 (match-string 2 tod))))
9508 (if (version< emacs-version "23.3")
9509 (appt-add tod evt)
9510 (appt-add tod evt wrn))
9511 (setq cnt (1+ cnt))))) entries)
9512 (org-release-buffers org-agenda-new-buffers)
9513 (if (eq cnt 0)
9514 (message "No event to add")
9515 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9517 (autoload 'org-agenda-to-appt "org-agenda" "\
9518 Activate appointments found in `org-agenda-files'.
9519 With a \\[universal-argument] prefix, refresh the list of
9520 appointments.
9522 If FILTER is t, interactively prompt the user for a regular
9523 expression, and filter out entries that don't match it.
9525 If FILTER is a string, use this string as a regular expression
9526 for filtering entries out.
9528 If FILTER is a function, filter out entries against which
9529 calling the function returns nil. This function takes one
9530 argument: an entry from `org-agenda-get-day-entries'.
9532 FILTER can also be an alist with the car of each cell being
9533 either 'headline or 'category. For example:
9535 '((headline \"IMPORTANT\")
9536 (category \"Work\"))
9538 will only add headlines containing IMPORTANT or headlines
9539 belonging to the \"Work\" category.
9541 ARGS are symbols indicating what kind of entries to consider.
9542 By default `org-agenda-to-appt' will use :deadline, :scheduled
9543 and :timestamp entries. See the docstring of `org-diary' for
9544 details and examples.
9546 If an entry as a APPT_WARNTIME property, its value will be used
9547 to override `appt-message-warning-time'.
9549 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9551 (defun org-agenda-todayp (date)
9552 "Does DATE mean today, when considering `org-extend-today-until'?"
9553 (let ((today (org-today))
9554 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9555 date)))
9556 (eq date today)))
9558 (defun org-agenda-todo-yesterday (&optional arg)
9559 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9560 (interactive "P")
9561 (let* ((hour (third (decode-time
9562 (org-current-time))))
9563 (org-extend-today-until (1+ hour)))
9564 (org-agenda-todo arg)))
9566 (provide 'org-agenda)
9568 ;;; org-agenda.el ends here