Add ERTs for basic spreadsheet functionality
[org-mode.git] / lisp / org-agenda.el
blobef95f5002e6a8f69c6a234c8674b74703625e170
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 (defcustom org-agenda-search-view-max-outline-level nil
1324 "Maximum outline level to display in search view.
1325 E.g. when this is set to 1, the search view will only
1326 show headlines of level 1."
1327 :group 'org-agenda-search-view
1328 :version "24.3"
1329 :type 'integer)
1331 (defgroup org-agenda-time-grid nil
1332 "Options concerning the time grid in the Org-mode Agenda."
1333 :tag "Org Agenda Time Grid"
1334 :group 'org-agenda)
1336 (defcustom org-agenda-search-headline-for-time t
1337 "Non-nil means search headline for a time-of-day.
1338 If the headline contains a time-of-day in one format or another, it will
1339 be used to sort the entry into the time sequence of items for a day.
1340 Some people have time stamps in the headline that refer to the creation
1341 time or so, and then this produces an unwanted side effect. If this is
1342 the case for your, use this variable to turn off searching the headline
1343 for a time."
1344 :group 'org-agenda-time-grid
1345 :type 'boolean)
1347 (defcustom org-agenda-use-time-grid t
1348 "Non-nil means show a time grid in the agenda schedule.
1349 A time grid is a set of lines for specific times (like every two hours between
1350 8:00 and 20:00). The items scheduled for a day at specific times are
1351 sorted in between these lines.
1352 For details about when the grid will be shown, and what it will look like, see
1353 the variable `org-agenda-time-grid'."
1354 :group 'org-agenda-time-grid
1355 :type 'boolean)
1357 (defcustom org-agenda-time-grid
1358 '((daily today require-timed)
1359 "----------------"
1360 (800 1000 1200 1400 1600 1800 2000))
1362 "The settings for time grid for agenda display.
1363 This is a list of three items. The first item is again a list. It contains
1364 symbols specifying conditions when the grid should be displayed:
1366 daily if the agenda shows a single day
1367 weekly if the agenda shows an entire week
1368 today show grid on current date, independent of daily/weekly display
1369 require-timed show grid only if at least one item has a time specification
1371 The second item is a string which will be placed behind the grid time.
1373 The third item is a list of integers, indicating the times that should have
1374 a grid line."
1375 :group 'org-agenda-time-grid
1376 :type
1377 '(list
1378 (set :greedy t :tag "Grid Display Options"
1379 (const :tag "Show grid in single day agenda display" daily)
1380 (const :tag "Show grid in weekly agenda display" weekly)
1381 (const :tag "Always show grid for today" today)
1382 (const :tag "Show grid only if any timed entries are present"
1383 require-timed)
1384 (const :tag "Skip grid times already present in an entry"
1385 remove-match))
1386 (string :tag "Grid String")
1387 (repeat :tag "Grid Times" (integer :tag "Time"))))
1389 (defcustom org-agenda-show-current-time-in-grid t
1390 "Non-nil means show the current time in the time grid."
1391 :group 'org-agenda-time-grid
1392 :version "24.1"
1393 :type 'boolean)
1395 (defcustom org-agenda-current-time-string
1396 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1397 "The string for the current time marker in the agenda."
1398 :group 'org-agenda-time-grid
1399 :version "24.1"
1400 :type 'string)
1402 (defgroup org-agenda-sorting nil
1403 "Options concerning sorting in the Org-mode Agenda."
1404 :tag "Org Agenda Sorting"
1405 :group 'org-agenda)
1407 (defcustom org-agenda-sorting-strategy
1408 '((agenda habit-down time-up priority-down category-keep)
1409 (todo priority-down category-keep)
1410 (tags priority-down category-keep)
1411 (search category-keep))
1412 "Sorting structure for the agenda items of a single day.
1413 This is a list of symbols which will be used in sequence to determine
1414 if an entry should be listed before another entry. The following
1415 symbols are recognized:
1417 time-up Put entries with time-of-day indications first, early first
1418 time-down Put entries with time-of-day indications first, late first
1419 category-keep Keep the default order of categories, corresponding to the
1420 sequence in `org-agenda-files'.
1421 category-up Sort alphabetically by category, A-Z.
1422 category-down Sort alphabetically by category, Z-A.
1423 tag-up Sort alphabetically by last tag, A-Z.
1424 tag-down Sort alphabetically by last tag, Z-A.
1425 priority-up Sort numerically by priority, high priority last.
1426 priority-down Sort numerically by priority, high priority first.
1427 todo-state-up Sort by todo state, tasks that are done last.
1428 todo-state-down Sort by todo state, tasks that are done first.
1429 effort-up Sort numerically by estimated effort, high effort last.
1430 effort-down Sort numerically by estimated effort, high effort first.
1431 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1432 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1433 habit-up Put entries that are habits first
1434 habit-down Put entries that are habits last
1435 alpha-up Sort headlines alphabetically
1436 alpha-down Sort headlines alphabetically, reversed
1438 The different possibilities will be tried in sequence, and testing stops
1439 if one comparison returns a \"not-equal\". For example, the default
1440 '(time-up category-keep priority-down)
1441 means: Pull out all entries having a specified time of day and sort them,
1442 in order to make a time schedule for the current day the first thing in the
1443 agenda listing for the day. Of the entries without a time indication, keep
1444 the grouped in categories, don't sort the categories, but keep them in
1445 the sequence given in `org-agenda-files'. Within each category sort by
1446 priority.
1448 Leaving out `category-keep' would mean that items will be sorted across
1449 categories by priority.
1451 Instead of a single list, this can also be a set of list for specific
1452 contents, with a context symbol in the car of the list, any of
1453 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1455 Custom commands can bind this variable in the options section."
1456 :group 'org-agenda-sorting
1457 :type `(choice
1458 (repeat :tag "General" ,org-sorting-choice)
1459 (list :tag "Individually"
1460 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1461 (repeat ,org-sorting-choice))
1462 (cons (const :tag "Strategy for TODO lists" todo)
1463 (repeat ,org-sorting-choice))
1464 (cons (const :tag "Strategy for Tags matches" tags)
1465 (repeat ,org-sorting-choice))
1466 (cons (const :tag "Strategy for search matches" search)
1467 (repeat ,org-sorting-choice)))))
1469 (defcustom org-agenda-cmp-user-defined nil
1470 "A function to define the comparison `user-defined'.
1471 This function must receive two arguments, agenda entry a and b.
1472 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1473 the user comparison, return nil.
1474 When this is defined, you can make `user-defined-up' and `user-defined-down'
1475 part of an agenda sorting strategy."
1476 :group 'org-agenda-sorting
1477 :type 'symbol)
1479 (defcustom org-sort-agenda-notime-is-late t
1480 "Non-nil means items without time are considered late.
1481 This is only relevant for sorting. When t, items which have no explicit
1482 time like 15:30 will be considered as 99:01, i.e. later than any items which
1483 do have a time. When nil, the default time is before 0:00. You can use this
1484 option to decide if the schedule for today should come before or after timeless
1485 agenda entries."
1486 :group 'org-agenda-sorting
1487 :type 'boolean)
1489 (defcustom org-sort-agenda-noeffort-is-high t
1490 "Non-nil means items without effort estimate are sorted as high effort.
1491 This also applies when filtering an agenda view with respect to the
1492 < or > effort operator. Then, tasks with no effort defined will be treated
1493 as tasks with high effort.
1494 When nil, such items are sorted as 0 minutes effort."
1495 :group 'org-agenda-sorting
1496 :type 'boolean)
1498 (defgroup org-agenda-line-format nil
1499 "Options concerning the entry prefix in the Org-mode agenda display."
1500 :tag "Org Agenda Line Format"
1501 :group 'org-agenda)
1503 (defcustom org-agenda-prefix-format
1504 '((agenda . " %i %-12:c%?-12t% s")
1505 (timeline . " % s")
1506 (todo . " %i %-12:c")
1507 (tags . " %i %-12:c")
1508 (search . " %i %-12:c"))
1509 "Format specifications for the prefix of items in the agenda views.
1510 An alist with five entries, each for the different agenda types. The
1511 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1512 The values are format strings.
1514 This format works similar to a printf format, with the following meaning:
1516 %c the category of the item, \"Diary\" for entries from the diary,
1517 or as given by the CATEGORY keyword or derived from the file name
1518 %e the effort required by the item
1519 %l the level of the item (insert X space(s) if item is of level X)
1520 %i the icon category of the item, see `org-agenda-category-icon-alist'
1521 %T the last tag of the item (ignore inherited tags, which come first)
1522 %t the HH:MM time-of-day specification if one applies to the entry
1523 %s Scheduling/Deadline information, a short string
1524 %(expression) Eval EXPRESSION and replace the control string
1525 by the result
1527 All specifiers work basically like the standard `%s' of printf, but may
1528 contain two additional characters: a question mark just after the `%'
1529 and a whitespace/punctuation character just before the final letter.
1531 If the first character after `%' is a question mark, the entire field
1532 will only be included if the corresponding value applies to the current
1533 entry. This is useful for fields which should have fixed width when
1534 present, but zero width when absent. For example, \"%?-12t\" will
1535 result in a 12 character time field if a time of the day is specified,
1536 but will completely disappear in entries which do not contain a time.
1538 If there is punctuation or whitespace character just before the final
1539 format letter, this character will be appended to the field value if
1540 the value is not empty. For example, the format \"%-12:c\" leads to
1541 \"Diary: \" if the category is \"Diary\". If the category were be
1542 empty, no additional colon would be inserted.
1544 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1545 which means:
1547 - Indent the line with two space characters
1548 - Give the category a 12 chars wide field, padded with whitespace on
1549 the right (because of `-'). Append a colon if there is a category
1550 (because of `:').
1551 - If there is a time-of-day, put it into a 12 chars wide field. If no
1552 time, don't put in an empty field, just skip it (because of '?').
1553 - Finally, put the scheduling information.
1555 See also the variables `org-agenda-remove-times-when-in-prefix' and
1556 `org-agenda-remove-tags'.
1558 Custom commands can set this variable in the options section."
1559 :type '(choice
1560 (string :tag "General format")
1561 (list :greedy t :tag "View dependent"
1562 (cons (const agenda) (string :tag "Format"))
1563 (cons (const timeline) (string :tag "Format"))
1564 (cons (const todo) (string :tag "Format"))
1565 (cons (const tags) (string :tag "Format"))
1566 (cons (const search) (string :tag "Format"))))
1567 :group 'org-agenda-line-format)
1569 (defvar org-prefix-format-compiled nil
1570 "The compiled prefix format and associated variables.
1571 This is a list where first element is a list of variable bindings, and second
1572 element is the compiled format expression. See the variable
1573 `org-agenda-prefix-format'.")
1575 (defcustom org-agenda-todo-keyword-format "%-1s"
1576 "Format for the TODO keyword in agenda lines.
1577 Set this to something like \"%-12s\" if you want all TODO keywords
1578 to occupy a fixed space in the agenda display."
1579 :group 'org-agenda-line-format
1580 :type 'string)
1582 (defcustom org-agenda-diary-sexp-prefix nil
1583 "A regexp that matches part of a diary sexp entry
1584 which should be treated as scheduling/deadline information in
1585 `org-agenda'.
1587 For example, you can use this to extract the `diary-remind-message' from
1588 `diary-remind' entries."
1589 :group 'org-agenda-line-format
1590 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1592 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1593 "Text preceding timerange entries in the agenda view.
1594 This is a list with two strings. The first applies when the range
1595 is entirely on one day. The second applies if the range spans several days.
1596 The strings may have two \"%d\" format specifiers which will be filled
1597 with the sequence number of the days, and the total number of days in the
1598 range, respectively."
1599 :group 'org-agenda-line-format
1600 :type '(list
1601 (string :tag "Deadline today ")
1602 (choice :tag "Deadline relative"
1603 (string :tag "Format string")
1604 (function))))
1606 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1607 "Text preceding scheduled items in the agenda view.
1608 This is a list with two strings. The first applies when the item is
1609 scheduled on the current day. The second applies when it has been scheduled
1610 previously, it may contain a %d indicating that this is the nth time that
1611 this item is scheduled, due to automatic rescheduling of unfinished items
1612 for the following day. So this number is one larger than the number of days
1613 that passed since this item was scheduled first."
1614 :group 'org-agenda-line-format
1615 :type '(list
1616 (string :tag "Scheduled today ")
1617 (string :tag "Scheduled previously")))
1619 (defcustom org-agenda-inactive-leader "["
1620 "Text preceding item pulled into the agenda by inactive time stamps.
1621 These entries are added to the agenda when pressing \"[\"."
1622 :group 'org-agenda-line-format
1623 :version "24.1"
1624 :type '(list
1625 (string :tag "Scheduled today ")
1626 (string :tag "Scheduled previously")))
1628 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1629 "Text preceding deadline items in the agenda view.
1630 This is a list with two strings. The first applies when the item has its
1631 deadline on the current day. The second applies when it is in the past or
1632 in the future, it may contain %d to capture how many days away the deadline
1633 is (was)."
1634 :group 'org-agenda-line-format
1635 :type '(list
1636 (string :tag "Deadline today ")
1637 (choice :tag "Deadline relative"
1638 (string :tag "Format string")
1639 (function))))
1641 (defcustom org-agenda-remove-times-when-in-prefix t
1642 "Non-nil means remove duplicate time specifications in agenda items.
1643 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1644 time-of-day specification in a headline or diary entry is extracted and
1645 placed into the prefix. If this option is non-nil, the original specification
1646 \(a timestamp or -range, or just a plain time(range) specification like
1647 11:30-4pm) will be removed for agenda display. This makes the agenda less
1648 cluttered.
1649 The option can be t or nil. It may also be the symbol `beg', indicating
1650 that the time should only be removed when it is located at the beginning of
1651 the headline/diary entry."
1652 :group 'org-agenda-line-format
1653 :type '(choice
1654 (const :tag "Always" t)
1655 (const :tag "Never" nil)
1656 (const :tag "When at beginning of entry" beg)))
1658 (defcustom org-agenda-remove-timeranges-from-blocks nil
1659 "Non-nil means remove time ranges specifications in agenda
1660 items that span on several days."
1661 :group 'org-agenda-line-format
1662 :version "24.1"
1663 :type 'boolean)
1665 (defcustom org-agenda-default-appointment-duration nil
1666 "Default duration for appointments that only have a starting time.
1667 When nil, no duration is specified in such cases.
1668 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1669 :group 'org-agenda-line-format
1670 :type '(choice
1671 (integer :tag "Minutes")
1672 (const :tag "No default duration")))
1674 (defcustom org-agenda-show-inherited-tags t
1675 "Non-nil means show inherited tags in each agenda line."
1676 :group 'org-agenda-line-format
1677 :type 'boolean)
1679 (defcustom org-agenda-hide-tags-regexp nil
1680 "Regular expression used to filter away specific tags in agenda views.
1681 This means that these tags will be present, but not be shown in the agenda
1682 line. Secondary filtering will still work on the hidden tags.
1683 Nil means don't hide any tags."
1684 :group 'org-agenda-line-format
1685 :type '(choice
1686 (const :tag "Hide none" nil)
1687 (string :tag "Regexp ")))
1689 (defcustom org-agenda-remove-tags nil
1690 "Non-nil means remove the tags from the headline copy in the agenda.
1691 When this is the symbol `prefix', only remove tags when
1692 `org-agenda-prefix-format' contains a `%T' specifier."
1693 :group 'org-agenda-line-format
1694 :type '(choice
1695 (const :tag "Always" t)
1696 (const :tag "Never" nil)
1697 (const :tag "When prefix format contains %T" prefix)))
1699 (if (fboundp 'defvaralias)
1700 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1701 'org-agenda-remove-tags))
1703 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1704 "Shift tags in agenda items to this column.
1705 If this number is positive, it specifies the column. If it is negative,
1706 it means that the tags should be flushright to that column. For example,
1707 -80 works well for a normal 80 character screen."
1708 :group 'org-agenda-line-format
1709 :type 'integer)
1711 (if (fboundp 'defvaralias)
1712 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1714 (defcustom org-agenda-fontify-priorities 'cookies
1715 "Non-nil means highlight low and high priorities in agenda.
1716 When t, the highest priority entries are bold, lowest priority italic.
1717 However, settings in `org-priority-faces' will overrule these faces.
1718 When this variable is the symbol `cookies', only fontify the
1719 cookies, not the entire task.
1720 This may also be an association list of priority faces, whose
1721 keys are the character values of `org-highest-priority',
1722 `org-default-priority', and `org-lowest-priority' (the default values
1723 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1724 color as a string, or a list like `(:background \"Red\")'.
1725 If it is a color, the variable `org-faces-easy-properties'
1726 determines if it is a foreground or a background color."
1727 :group 'org-agenda-line-format
1728 :type '(choice
1729 (const :tag "Never" nil)
1730 (const :tag "Defaults" t)
1731 (const :tag "Cookies only" cookies)
1732 (repeat :tag "Specify"
1733 (list (character :tag "Priority" :value ?A)
1734 (choice :tag "Face "
1735 (string :tag "Color")
1736 (sexp :tag "Face"))))))
1738 (defcustom org-agenda-day-face-function nil
1739 "Function called to determine what face should be used to display a day.
1740 The only argument passed to that function is the day. It should
1741 returns a face, or nil if does not want to specify a face and let
1742 the normal rules apply."
1743 :group 'org-agenda-line-format
1744 :version "24.1"
1745 :type 'function)
1747 (defcustom org-agenda-category-icon-alist nil
1748 "Alist of category icon to be displayed in agenda views.
1750 Each entry should have the following format:
1752 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1754 Where CATEGORY-REGEXP is a regexp matching the categories where
1755 the icon should be displayed.
1756 FILE-OR-DATA either a file path or a string containing image data.
1758 The other fields can be omitted safely if not needed:
1759 TYPE indicates the image type.
1760 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1761 image data.
1762 PROPS are additional image attributes to assign to the image,
1763 like, e.g. `:ascent center'.
1765 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1767 If you want to set the display properties yourself, just put a
1768 list as second element:
1770 (CATEGORY-REGEXP (MY PROPERTY LIST))
1772 For example, to display a 16px horizontal space for Emacs
1773 category, you can use:
1775 (\"Emacs\" '(space . (:width (16))))"
1776 :group 'org-agenda-line-format
1777 :version "24.1"
1778 :type '(alist :key-type (string :tag "Regexp matching category")
1779 :value-type (choice (list :tag "Icon"
1780 (string :tag "File or data")
1781 (symbol :tag "Type")
1782 (boolean :tag "Data?")
1783 (repeat :tag "Extra image properties" :inline t symbol))
1784 (list :tag "Display properties" sexp))))
1786 (defgroup org-agenda-column-view nil
1787 "Options concerning column view in the agenda."
1788 :tag "Org Agenda Column View"
1789 :group 'org-agenda)
1791 (defcustom org-agenda-columns-show-summaries t
1792 "Non-nil means show summaries for columns displayed in the agenda view."
1793 :group 'org-agenda-column-view
1794 :type 'boolean)
1796 (defcustom org-agenda-columns-compute-summary-properties t
1797 "Non-nil means recompute all summary properties before column view.
1798 When column view in the agenda is listing properties that have a summary
1799 operator, it can go to all relevant buffers and recompute the summaries
1800 there. This can mean overhead for the agenda column view, but is necessary
1801 to have thing up to date.
1802 As a special case, a CLOCKSUM property also makes sure that the clock
1803 computations are current."
1804 :group 'org-agenda-column-view
1805 :type 'boolean)
1807 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1808 "Non-nil means the duration of an appointment will add to day effort.
1809 The property to which appointment durations will be added is the one given
1810 in the option `org-effort-property'. If an appointment does not have
1811 an end time, `org-agenda-default-appointment-duration' will be used. If that
1812 is not set, an appointment without end time will not contribute to the time
1813 estimate."
1814 :group 'org-agenda-column-view
1815 :type 'boolean)
1817 (defcustom org-agenda-auto-exclude-function nil
1818 "A function called with a tag to decide if it is filtered on '/ RET'.
1819 The sole argument to the function, which is called once for each
1820 possible tag, is a string giving the name of the tag. The
1821 function should return either nil if the tag should be included
1822 as normal, or \"-<TAG>\" to exclude the tag.
1823 Note that for the purpose of tag filtering, only the lower-case version of
1824 all tags will be considered, so that this function will only ever see
1825 the lower-case version of all tags."
1826 :group 'org-agenda
1827 :type 'function)
1829 (defcustom org-agenda-bulk-custom-functions nil
1830 "Alist of characters and custom functions for bulk actions.
1831 For example, this value makes those two functions available:
1833 '((?R set-category)
1834 (?C bulk-cut))
1836 With selected entries in an agenda buffer, `B R' will call
1837 the custom function `set-category' on the selected entries.
1838 Note that functions in this alist don't need to be quoted."
1839 :type 'alist
1840 :version "24.1"
1841 :group 'org-agenda)
1843 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1844 "Execute BODY with point at location given by `org-hd-marker' property.
1845 If STRING is non-nil, the text property will be fetched from position 0
1846 in that string. If STRING is nil, it will be fetched from the beginning
1847 of the current line."
1848 (org-with-gensyms (marker)
1849 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1850 'org-hd-marker ,string)))
1851 (with-current-buffer (marker-buffer ,marker)
1852 (save-excursion
1853 (goto-char ,marker)
1854 ,@body)))))
1855 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1857 (defun org-add-agenda-custom-command (entry)
1858 "Replace or add a command in `org-agenda-custom-commands'.
1859 This is mostly for hacking and trying a new command - once the command
1860 works you probably want to add it to `org-agenda-custom-commands' for good."
1861 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1862 (if ass
1863 (setcdr ass (cdr entry))
1864 (push entry org-agenda-custom-commands))))
1866 ;;; Define the org-agenda-mode
1868 (defvar org-agenda-mode-map (make-sparse-keymap)
1869 "Keymap for `org-agenda-mode'.")
1870 (if (fboundp 'defvaralias)
1871 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1873 (defvar org-agenda-menu) ; defined later in this file.
1874 (defvar org-agenda-restrict nil) ; defined later in this file.
1875 (defvar org-agenda-follow-mode nil)
1876 (defvar org-agenda-entry-text-mode nil)
1877 (defvar org-agenda-clockreport-mode nil)
1878 (defvar org-agenda-show-log nil)
1879 (defvar org-agenda-redo-command nil)
1880 (defvar org-agenda-query-string nil)
1881 (defvar org-agenda-mode-hook nil
1882 "Hook run after `org-agenda-mode' is turned on.
1883 The buffer is still writable when this hook is called.")
1884 (defvar org-agenda-type nil)
1885 (defvar org-agenda-force-single-file nil)
1886 (defvar org-agenda-bulk-marked-entries nil
1887 "List of markers that refer to marked entries in the agenda.")
1889 ;;; Multiple agenda buffers support
1891 (defcustom org-agenda-sticky nil
1892 "Non-nil means agenda q key will bury agenda buffers.
1893 Agenda commands will then show existing buffer instead of generating new ones.
1894 When nil, `q' will kill the single agenda buffer."
1895 :group 'org-agenda
1896 :version "24.3"
1897 :type 'boolean)
1900 ;;;###autoload
1901 (defun org-toggle-sticky-agenda (&optional arg)
1902 "Toggle `org-agenda-sticky'."
1903 (interactive "P")
1904 (let ((new-value (if arg
1905 (> (prefix-numeric-value arg) 0)
1906 (not org-agenda-sticky))))
1907 (if (equal new-value org-agenda-sticky)
1908 (and (org-called-interactively-p 'interactive)
1909 (message "Sticky agenda was already %s"
1910 (if org-agenda-sticky "enabled" "disabled")))
1911 (setq org-agenda-sticky new-value)
1912 (org-agenda-kill-all-agenda-buffers)
1913 (and (org-called-interactively-p 'interactive)
1914 (message "Sticky agenda was %s"
1915 (if org-agenda-sticky "enabled" "disabled"))))))
1917 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1918 Toggle `org-agenda-sticky'.
1920 \(fn &optional ARG)" t nil)
1922 (defvar org-agenda-buffer nil
1923 "Agenda buffer currently being generated.")
1925 (defvar org-agenda-last-prefix-arg nil)
1926 (defvar org-agenda-this-buffer-name nil)
1927 (defvar org-agenda-doing-sticky-redo nil)
1928 (defvar org-agenda-this-buffer-is-sticky nil)
1930 (defconst org-agenda-local-vars
1931 '(org-agenda-this-buffer-name
1932 org-agenda-undo-list
1933 org-agenda-pending-undo-list
1934 org-agenda-follow-mode
1935 org-agenda-entry-text-mode
1936 org-agenda-clockreport-mode
1937 org-agenda-show-log
1938 org-agenda-redo-command
1939 org-agenda-query-string
1940 org-agenda-type
1941 org-agenda-bulk-marked-entries
1942 org-agenda-undo-has-started-in
1943 org-agenda-info
1944 org-agenda-tag-filter-overlays
1945 org-agenda-cat-filter-overlays
1946 org-agenda-pre-window-conf
1947 org-agenda-columns-active
1948 org-agenda-tag-filter
1949 org-agenda-category-filter
1950 org-agenda-markers
1951 org-agenda-last-search-view-search-was-boolean
1952 org-agenda-filtered-by-category
1953 org-agenda-filter-form
1954 org-agenda-show-window
1955 org-agenda-cycle-counter
1956 org-agenda-last-prefix-arg)
1957 "Variables that must be local in agenda buffers to allow multiple buffers.")
1959 (defun org-agenda-mode ()
1960 "Mode for time-sorted view on action items in Org-mode files.
1962 The following commands are available:
1964 \\{org-agenda-mode-map}"
1965 (interactive)
1966 (cond (org-agenda-doing-sticky-redo
1967 ;; Refreshing sticky agenda-buffer
1969 ;; Preserve the value of `org-agenda-local-vars' variables,
1970 ;; while letting `kill-all-local-variables' kill the rest
1971 (let ((save (buffer-local-variables)))
1972 (kill-all-local-variables)
1973 (mapc 'make-local-variable org-agenda-local-vars)
1974 (dolist (elem save)
1975 (let ((var (car elem))
1976 (val (cdr elem)))
1977 (when (and val
1978 (member var org-agenda-local-vars))
1979 (set var val)))))
1980 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1981 (org-agenda-sticky
1982 ;; Creating a sticky Agenda buffer for the first time
1983 (kill-all-local-variables)
1984 (mapc 'make-local-variable org-agenda-local-vars)
1985 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1987 ;; Creating a non-sticky agenda buffer
1988 (kill-all-local-variables)
1989 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1990 (setq org-agenda-undo-list nil
1991 org-agenda-pending-undo-list nil
1992 org-agenda-bulk-marked-entries nil)
1993 (setq major-mode 'org-agenda-mode)
1994 ;; Keep global-font-lock-mode from turning on font-lock-mode
1995 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1996 (setq mode-name "Org-Agenda")
1997 (use-local-map org-agenda-mode-map)
1998 (easy-menu-add org-agenda-menu)
1999 (if org-startup-truncated (setq truncate-lines t))
2000 (org-set-local 'line-move-visual nil)
2001 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2002 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2003 ;; Make sure properties are removed when copying text
2004 (make-local-variable 'filter-buffer-substring-functions)
2005 (add-hook 'filter-buffer-substring-functions
2006 (lambda (fun start end delete)
2007 (substring-no-properties (funcall fun start end delete))))
2008 (unless org-agenda-keep-modes
2009 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2010 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2011 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2012 org-agenda-show-log org-agenda-start-with-log-mode))
2014 (easy-menu-change
2015 '("Agenda") "Agenda Files"
2016 (append
2017 (list
2018 (vector
2019 (if (get 'org-agenda-files 'org-restrict)
2020 "Restricted to single file"
2021 "Edit File List")
2022 '(org-edit-agenda-file-list)
2023 (not (get 'org-agenda-files 'org-restrict)))
2024 "--")
2025 (mapcar 'org-file-menu-entry (org-agenda-files))))
2026 (org-agenda-set-mode-name)
2027 (apply
2028 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2029 (list 'org-agenda-mode-hook)))
2031 (substitute-key-definition 'undo 'org-agenda-undo
2032 org-agenda-mode-map global-map)
2033 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2034 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2035 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2036 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2037 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2038 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2039 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2040 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2041 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2042 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2043 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2044 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2045 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2046 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2047 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2048 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2049 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2050 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2051 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2052 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2053 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2054 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2055 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2056 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2057 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2058 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2059 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2060 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2061 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2062 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2063 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2064 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2065 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2066 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2067 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2068 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2069 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2070 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2071 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2072 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2073 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2074 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2075 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2076 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2077 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2079 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2080 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2081 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2082 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2083 (while l (org-defkey org-agenda-mode-map
2084 (int-to-string (pop l)) 'digit-argument)))
2086 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2087 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2088 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2089 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2090 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2091 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2092 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2093 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2094 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2095 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2096 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2097 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2098 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2099 'org-clock-modify-effort-estimate)
2100 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2101 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2102 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2103 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2104 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2105 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2106 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2107 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2108 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2109 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2110 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2111 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2112 (substitute-key-definition 'next-line 'org-agenda-next-line
2113 org-agenda-mode-map global-map)
2114 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2115 org-agenda-mode-map global-map)
2116 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2117 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2118 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2119 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2120 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2121 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2122 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2123 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2124 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2125 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2126 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2127 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2128 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2129 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2130 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2131 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2132 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2133 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2134 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2135 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2136 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2137 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2138 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2139 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2140 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2141 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2142 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2143 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2144 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2145 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2147 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2148 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2149 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2150 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2151 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2152 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2153 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2154 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2155 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2156 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2157 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2158 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2160 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2161 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2162 (when org-agenda-mouse-1-follows-link
2163 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2164 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2165 '("Agenda"
2166 ("Agenda Files")
2167 "--"
2168 ("Agenda Dates"
2169 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2170 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2171 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2172 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2173 "--"
2174 ("View"
2175 ["Day View" org-agenda-day-view
2176 :active (org-agenda-check-type nil 'agenda)
2177 :style radio :selected (eq org-agenda-current-span 'day)
2178 :keys "v d (or just d)"]
2179 ["Week View" org-agenda-week-view
2180 :active (org-agenda-check-type nil 'agenda)
2181 :style radio :selected (eq org-agenda-current-span 'week)
2182 :keys "v w (or just w)"]
2183 ["Month View" org-agenda-month-view
2184 :active (org-agenda-check-type nil 'agenda)
2185 :style radio :selected (eq org-agenda-current-span 'month)
2186 :keys "v m"]
2187 ["Year View" org-agenda-year-view
2188 :active (org-agenda-check-type nil 'agenda)
2189 :style radio :selected (eq org-agenda-current-span 'year)
2190 :keys "v y"]
2191 "--"
2192 ["Include Diary" org-agenda-toggle-diary
2193 :style toggle :selected org-agenda-include-diary
2194 :active (org-agenda-check-type nil 'agenda)]
2195 ["Include Deadlines" org-agenda-toggle-deadlines
2196 :style toggle :selected org-agenda-include-deadlines
2197 :active (org-agenda-check-type nil 'agenda)]
2198 ["Use Time Grid" org-agenda-toggle-time-grid
2199 :style toggle :selected org-agenda-use-time-grid
2200 :active (org-agenda-check-type nil 'agenda)]
2201 "--"
2202 ["Show clock report" org-agenda-clockreport-mode
2203 :style toggle :selected org-agenda-clockreport-mode
2204 :active (org-agenda-check-type nil 'agenda)]
2205 ["Show some entry text" org-agenda-entry-text-mode
2206 :style toggle :selected org-agenda-entry-text-mode
2207 :active t]
2208 "--"
2209 ["Show Logbook entries" org-agenda-log-mode
2210 :style toggle :selected org-agenda-show-log
2211 :active (org-agenda-check-type nil 'agenda 'timeline)
2212 :keys "v l (or just l)"]
2213 ["Include archived trees" org-agenda-archives-mode
2214 :style toggle :selected org-agenda-archives-mode :active t
2215 :keys "v a"]
2216 ["Include archive files" (org-agenda-archives-mode t)
2217 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2218 :keys "v A"]
2219 "--"
2220 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2221 ["Write view to file" org-agenda-write t]
2222 ["Rebuild buffer" org-agenda-redo t]
2223 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2224 "--"
2225 ["Show original entry" org-agenda-show t]
2226 ["Go To (other window)" org-agenda-goto t]
2227 ["Go To (this window)" org-agenda-switch-to t]
2228 ["Capture with cursor date" org-agenda-capture t]
2229 ["Follow Mode" org-agenda-follow-mode
2230 :style toggle :selected org-agenda-follow-mode :active t]
2231 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2232 "--"
2233 ("TODO"
2234 ["Cycle TODO" org-agenda-todo t]
2235 ["Next TODO set" org-agenda-todo-nextset t]
2236 ["Previous TODO set" org-agenda-todo-previousset t]
2237 ["Add note" org-agenda-add-note t])
2238 ("Archive/Refile/Delete"
2239 ["Archive default" org-agenda-archive-default t]
2240 ["Archive default" org-agenda-archive-default-with-confirmation t]
2241 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2242 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2243 ["Archive subtree" org-agenda-archive t]
2244 "--"
2245 ["Refile" org-agenda-refile t]
2246 "--"
2247 ["Delete subtree" org-agenda-kill t])
2248 ("Bulk action"
2249 ["Mark entry" org-agenda-bulk-mark t]
2250 ["Mark all" org-agenda-bulk-mark-all t]
2251 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2252 ["Unmark entry" org-agenda-bulk-unmark t]
2253 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2254 ["Act on all marked" org-agenda-bulk-action t]
2255 "--"
2256 ("Tags and Properties"
2257 ["Show all Tags" org-agenda-show-tags t]
2258 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2259 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2260 "--"
2261 ["Column View" org-columns t])
2262 ("Deadline/Schedule"
2263 ["Schedule" org-agenda-schedule t]
2264 ["Set Deadline" org-agenda-deadline t]
2265 "--"
2266 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2267 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2268 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2269 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2270 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2271 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2272 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2273 ("Clock and Effort"
2274 ["Clock in" org-agenda-clock-in t]
2275 ["Clock out" org-agenda-clock-out t]
2276 ["Clock cancel" org-agenda-clock-cancel t]
2277 ["Goto running clock" org-clock-goto t]
2278 "--"
2279 ["Set Effort" org-agenda-set-effort t]
2280 ["Change clocked effort" org-clock-modify-effort-estimate
2281 (org-clock-is-active)])
2282 ("Priority"
2283 ["Set Priority" org-agenda-priority t]
2284 ["Increase Priority" org-agenda-priority-up t]
2285 ["Decrease Priority" org-agenda-priority-down t]
2286 ["Show Priority" org-show-priority t])
2287 ("Calendar/Diary"
2288 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2289 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2290 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2291 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2292 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2293 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2294 "--"
2295 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2296 "--"
2297 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2298 "--"
2299 ("MobileOrg"
2300 ["Push Files and Views" org-mobile-push t]
2301 ["Get Captured and Flagged" org-mobile-pull t]
2302 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2303 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2304 "--"
2305 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2306 "--"
2307 ["Quit" org-agenda-quit t]
2308 ["Exit and Release Buffers" org-agenda-exit t]
2311 ;;; Agenda undo
2313 (defvar org-agenda-allow-remote-undo t
2314 "Non-nil means allow remote undo from the agenda buffer.")
2315 (defvar org-agenda-undo-has-started-in nil
2316 "Buffers that have already seen `undo-start' in the current undo sequence.")
2318 (defun org-agenda-undo ()
2319 "Undo a remote editing step in the agenda.
2320 This undoes changes both in the agenda buffer and in the remote buffer
2321 that have been changed along."
2322 (interactive)
2323 (or org-agenda-allow-remote-undo
2324 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2325 (if (not (eq this-command last-command))
2326 (setq org-agenda-undo-has-started-in nil
2327 org-agenda-pending-undo-list org-agenda-undo-list))
2328 (if (not org-agenda-pending-undo-list)
2329 (error "No further undo information"))
2330 (let* ((entry (pop org-agenda-pending-undo-list))
2331 buf line cmd rembuf)
2332 (setq cmd (pop entry) line (pop entry))
2333 (setq rembuf (nth 2 entry))
2334 (org-with-remote-undo rembuf
2335 (while (bufferp (setq buf (pop entry)))
2336 (if (pop entry)
2337 (with-current-buffer buf
2338 (let ((last-undo-buffer buf)
2339 (inhibit-read-only t))
2340 (unless (memq buf org-agenda-undo-has-started-in)
2341 (push buf org-agenda-undo-has-started-in)
2342 (make-local-variable 'pending-undo-list)
2343 (undo-start))
2344 (while (and pending-undo-list
2345 (listp pending-undo-list)
2346 (not (car pending-undo-list)))
2347 (pop pending-undo-list))
2348 (undo-more 1))))))
2349 (org-goto-line line)
2350 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2352 (defun org-verify-change-for-undo (l1 l2)
2353 "Verify that a real change occurred between the undo lists L1 and L2."
2354 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2355 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2356 (not (eq l1 l2)))
2358 ;;; Agenda dispatch
2360 (defvar org-agenda-restrict-begin (make-marker))
2361 (defvar org-agenda-restrict-end (make-marker))
2362 (defvar org-agenda-last-dispatch-buffer nil)
2363 (defvar org-agenda-overriding-restriction nil)
2365 (defcustom org-agenda-custom-commands-contexts nil
2366 "Alist of custom agenda keys and contextual rules.
2368 For example, if you have a custom agenda command \"p\" and you
2369 want this command to be accessible only from plain text files,
2370 use this:
2372 '((\"p\" (in-file . \"\\.txt\")))
2374 Here are the available contexts definitions:
2376 in-file: command displayed only in matching files
2377 in-mode: command displayed only in matching modes
2378 not-in-file: command not displayed in matching files
2379 not-in-mode: command not displayed in matching modes
2380 [function]: a custom function taking no argument
2382 If you define several checks, the agenda command will be
2383 accessible if there is at least one valid check.
2385 You can also bind a key to another agenda custom command
2386 depending on contextual rules.
2388 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2390 Here it means: in .txt files, use \"p\" as the key for the
2391 agenda command otherwise associated with \"q\". (The command
2392 originally associated with \"q\" is not displayed to avoid
2393 duplicates.)"
2394 :version "24.3"
2395 :group 'org-agenda-custom-commands
2396 :type '(repeat (list :tag "Rule"
2397 (string :tag " Agenda key")
2398 (string :tag "Replace by command")
2399 (repeat :tag "Available when"
2400 (choice
2401 (cons :tag "Condition"
2402 (choice
2403 (const :tag "In file" in-file)
2404 (const :tag "Not in file" not-in-file)
2405 (const :tag "In mode" in-mode)
2406 (const :tag "Not in mode" not-in-mode))
2407 (regexp))
2408 (function :tag "Custom function"))))))
2410 (defvar org-keys nil)
2411 (defvar org-match nil)
2412 ;;;###autoload
2413 (defun org-agenda (&optional arg org-keys restriction)
2414 "Dispatch agenda commands to collect entries to the agenda buffer.
2415 Prompts for a command to execute. Any prefix arg will be passed
2416 on to the selected command. The default selections are:
2418 a Call `org-agenda-list' to display the agenda for current day or week.
2419 t Call `org-todo-list' to display the global todo list.
2420 T Call `org-todo-list' to display the global todo list, select only
2421 entries with a specific TODO keyword (the user gets a prompt).
2422 m Call `org-tags-view' to display headlines with tags matching
2423 a condition (the user is prompted for the condition).
2424 M Like `m', but select only TODO entries, no ordinary headlines.
2425 L Create a timeline for the current buffer.
2426 e Export views to associated files.
2427 s Search entries for keywords.
2428 S Search entries for keywords, only with TODO keywords.
2429 / Multi occur across all agenda files and also files listed
2430 in `org-agenda-text-search-extra-files'.
2431 < Restrict agenda commands to buffer, subtree, or region.
2432 Press several times to get the desired effect.
2433 > Remove a previous restriction.
2434 # List \"stuck\" projects.
2435 ! Configure what \"stuck\" means.
2436 C Configure custom agenda commands.
2438 More commands can be added by configuring the variable
2439 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2440 searches can be pre-defined in this way.
2442 If the current buffer is in Org-mode and visiting a file, you can also
2443 first press `<' once to indicate that the agenda should be temporarily
2444 \(until the next use of \\[org-agenda]) restricted to the current file.
2445 Pressing `<' twice means to restrict to the current subtree or region
2446 \(if active)."
2447 (interactive "P")
2448 (catch 'exit
2449 (let* ((prefix-descriptions nil)
2450 (org-agenda-buffer-name org-agenda-buffer-name)
2451 (org-agenda-window-setup (if (equal (buffer-name)
2452 org-agenda-buffer-name)
2453 'current-window
2454 org-agenda-window-setup))
2455 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2456 (org-agenda-custom-commands
2457 ;; normalize different versions
2458 (delq nil
2459 (mapcar
2460 (lambda (x)
2461 (cond ((stringp (cdr x))
2462 (push x prefix-descriptions)
2463 nil)
2464 ((stringp (nth 1 x)) x)
2465 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2466 (t (cons (car x) (cons "" (cdr x))))))
2467 org-agenda-custom-commands)))
2468 (org-agenda-custom-commands
2469 (org-contextualize-keys
2470 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2471 (buf (current-buffer))
2472 (bfn (buffer-file-name (buffer-base-buffer)))
2473 entry key type org-match lprops ans)
2474 ;; Turn off restriction unless there is an overriding one,
2475 (unless org-agenda-overriding-restriction
2476 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2477 ;; There is a request to keep the file list in place
2478 (put 'org-agenda-files 'org-restrict nil))
2479 (setq org-agenda-restrict nil)
2480 (move-marker org-agenda-restrict-begin nil)
2481 (move-marker org-agenda-restrict-end nil))
2482 ;; Delete old local properties
2483 (put 'org-agenda-redo-command 'org-lprops nil)
2484 ;; Delete previously set last-arguments
2485 (put 'org-agenda-redo-command 'last-args nil)
2486 ;; Remember where this call originated
2487 (setq org-agenda-last-dispatch-buffer (current-buffer))
2488 (unless org-keys
2489 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2490 org-keys (car ans)
2491 restriction (cdr ans)))
2492 ;; If we have sticky agenda buffers, set a name for the buffer,
2493 ;; depending on the invoking keys. The user may still set this
2494 ;; as a command option, which will overwrite what we do here.
2495 (if org-agenda-sticky
2496 (setq org-agenda-buffer-name
2497 (format "*Org Agenda(%s)*" org-keys)))
2498 ;; Establish the restriction, if any
2499 (when (and (not org-agenda-overriding-restriction) restriction)
2500 (put 'org-agenda-files 'org-restrict (list bfn))
2501 (cond
2502 ((eq restriction 'region)
2503 (setq org-agenda-restrict t)
2504 (move-marker org-agenda-restrict-begin (region-beginning))
2505 (move-marker org-agenda-restrict-end (region-end)))
2506 ((eq restriction 'subtree)
2507 (save-excursion
2508 (setq org-agenda-restrict t)
2509 (org-back-to-heading t)
2510 (move-marker org-agenda-restrict-begin (point))
2511 (move-marker org-agenda-restrict-end
2512 (progn (org-end-of-subtree t)))))))
2514 ;; For example the todo list should not need it (but does...)
2515 (cond
2516 ((setq entry (assoc org-keys org-agenda-custom-commands))
2517 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2518 (progn
2519 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2520 lprops (nth 4 entry))
2521 (if org-agenda-sticky
2522 (setq org-agenda-buffer-name
2523 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2524 (format "*Org Agenda(%s)*" org-keys))))
2525 (put 'org-agenda-redo-command 'org-lprops lprops)
2526 (cond
2527 ((eq type 'agenda)
2528 (org-let lprops '(org-agenda-list current-prefix-arg)))
2529 ((eq type 'alltodo)
2530 (org-let lprops '(org-todo-list current-prefix-arg)))
2531 ((eq type 'search)
2532 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2533 ((eq type 'stuck)
2534 (org-let lprops '(org-agenda-list-stuck-projects
2535 current-prefix-arg)))
2536 ((eq type 'tags)
2537 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2538 ((eq type 'tags-todo)
2539 (org-let lprops '(org-tags-view '(4) org-match)))
2540 ((eq type 'todo)
2541 (org-let lprops '(org-todo-list org-match)))
2542 ((eq type 'tags-tree)
2543 (org-check-for-org-mode)
2544 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2545 ((eq type 'todo-tree)
2546 (org-check-for-org-mode)
2547 (org-let lprops
2548 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2549 (regexp-quote org-match) "\\>"))))
2550 ((eq type 'occur-tree)
2551 (org-check-for-org-mode)
2552 (org-let lprops '(org-occur org-match)))
2553 ((functionp type)
2554 (org-let lprops '(funcall type org-match)))
2555 ((fboundp type)
2556 (org-let lprops '(funcall type org-match)))
2557 (t (error "Invalid custom agenda command type %s" type))))
2558 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2559 ((equal org-keys "C")
2560 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2561 (customize-variable 'org-agenda-custom-commands))
2562 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2563 ((equal org-keys "s") (call-interactively 'org-search-view))
2564 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2565 ((equal org-keys "t") (call-interactively 'org-todo-list))
2566 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2567 ((equal org-keys "m") (call-interactively 'org-tags-view))
2568 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2569 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2570 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2571 (org-add-hook
2572 'post-command-hook
2573 (lambda ()
2574 (unless (current-message)
2575 (let* ((m (org-agenda-get-any-marker))
2576 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2577 (when note
2578 (message (concat
2579 "FLAGGING-NOTE ([?] for more info): "
2580 (org-add-props
2581 (replace-regexp-in-string
2582 "\\\\n" "//"
2583 (copy-sequence note))
2584 nil 'face 'org-warning)))))))
2585 t t))
2586 ((equal org-keys "L")
2587 (unless (derived-mode-p 'org-mode)
2588 (error "This is not an Org-mode file"))
2589 (unless restriction
2590 (put 'org-agenda-files 'org-restrict (list bfn))
2591 (org-call-with-arg 'org-timeline arg)))
2592 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2593 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2594 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2595 (t (error "Invalid agenda key"))))))
2597 (autoload 'org-agenda "org-agenda" "\
2598 Dispatch agenda commands to collect entries to the agenda buffer.
2599 Prompts for a command to execute. Any prefix arg will be passed
2600 on to the selected command. The default selections are:
2602 a Call `org-agenda-list' to display the agenda for current day or week.
2603 t Call `org-todo-list' to display the global todo list.
2604 T Call `org-todo-list' to display the global todo list, select only
2605 entries with a specific TODO keyword (the user gets a prompt).
2606 m Call `org-tags-view' to display headlines with tags matching
2607 a condition (the user is prompted for the condition).
2608 M Like `m', but select only TODO entries, no ordinary headlines.
2609 L Create a timeline for the current buffer.
2610 e Export views to associated files.
2611 s Search entries for keywords.
2612 S Search entries for keywords, only with TODO keywords.
2613 / Multi occur across all agenda files and also files listed
2614 in `org-agenda-text-search-extra-files'.
2615 < Restrict agenda commands to buffer, subtree, or region.
2616 Press several times to get the desired effect.
2617 > Remove a previous restriction.
2618 # List \"stuck\" projects.
2619 ! Configure what \"stuck\" means.
2620 C Configure custom agenda commands.
2622 More commands can be added by configuring the variable
2623 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2624 searches can be pre-defined in this way.
2626 If the current buffer is in Org-mode and visiting a file, you can also
2627 first press `<' once to indicate that the agenda should be temporarily
2628 \(until the next use of \\[org-agenda]) restricted to the current file.
2629 Pressing `<' twice means to restrict to the current subtree or region
2630 \(if active).
2632 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2634 (defun org-agenda-append-agenda ()
2635 "Append another agenda view to the current one.
2636 This function allows interactive building of block agendas.
2637 Agenda views are separated by `org-agenda-block-separator'."
2638 (interactive)
2639 (unless (derived-mode-p 'org-agenda-mode)
2640 (error "Can only append from within agenda buffer"))
2641 (let ((org-agenda-multi t))
2642 (org-agenda)
2643 (widen)
2644 (org-agenda-finalize)
2645 (org-agenda-fit-window-to-buffer)))
2647 (defun org-agenda-normalize-custom-commands (cmds)
2648 (delq nil
2649 (mapcar
2650 (lambda (x)
2651 (cond ((stringp (cdr x)) nil)
2652 ((stringp (nth 1 x)) x)
2653 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2654 (t (cons (car x) (cons "" (cdr x))))))
2655 cmds)))
2657 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2658 "The user interface for selecting an agenda command."
2659 (catch 'exit
2660 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2661 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2662 (region-p (org-region-active-p))
2663 (custom org-agenda-custom-commands)
2664 (selstring "")
2665 restriction second-time
2666 c entry key type match prefixes rmheader header-end custom1 desc
2667 line lines left right n n1)
2668 (save-window-excursion
2669 (delete-other-windows)
2670 (org-switch-to-buffer-other-window " *Agenda Commands*")
2671 (erase-buffer)
2672 (insert (eval-when-compile
2673 (let ((header
2674 "Press key for an agenda command: < Buffer, subtree/region restriction
2675 -------------------------------- > Remove restriction
2676 a Agenda for current week or day e Export agenda views
2677 t List of all TODO entries T Entries with special TODO kwd
2678 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2679 s Search for keywords S Like s, but only TODO entries
2680 L Timeline for current buffer # List stuck projects (!=configure)
2681 / Multi-occur C Configure custom agenda commands
2682 ? Find :FLAGGED: entries * Toggle sticky agenda views
2684 (start 0))
2685 (while (string-match
2686 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2687 header start)
2688 (setq start (match-end 0))
2689 (add-text-properties (match-beginning 2) (match-end 2)
2690 '(face bold) header))
2691 header)))
2692 (setq header-end (point-marker))
2693 (while t
2694 (setq custom1 custom)
2695 (when (eq rmheader t)
2696 (org-goto-line 1)
2697 (re-search-forward ":" nil t)
2698 (delete-region (match-end 0) (point-at-eol))
2699 (forward-char 1)
2700 (looking-at "-+")
2701 (delete-region (match-end 0) (point-at-eol))
2702 (move-marker header-end (match-end 0)))
2703 (goto-char header-end)
2704 (delete-region (point) (point-max))
2706 ;; Produce all the lines that describe custom commands and prefixes
2707 (setq lines nil)
2708 (while (setq entry (pop custom1))
2709 (setq key (car entry) desc (nth 1 entry)
2710 type (nth 2 entry)
2711 match (nth 3 entry))
2712 (if (> (length key) 1)
2713 (add-to-list 'prefixes (string-to-char key))
2714 (setq line
2715 (format
2716 "%-4s%-14s"
2717 (org-add-props (copy-sequence key)
2718 '(face bold))
2719 (cond
2720 ((string-match "\\S-" desc) desc)
2721 ((eq type 'agenda) "Agenda for current week or day")
2722 ((eq type 'alltodo) "List of all TODO entries")
2723 ((eq type 'search) "Word search")
2724 ((eq type 'stuck) "List of stuck projects")
2725 ((eq type 'todo) "TODO keyword")
2726 ((eq type 'tags) "Tags query")
2727 ((eq type 'tags-todo) "Tags (TODO)")
2728 ((eq type 'tags-tree) "Tags tree")
2729 ((eq type 'todo-tree) "TODO kwd tree")
2730 ((eq type 'occur-tree) "Occur tree")
2731 ((functionp type) (if (symbolp type)
2732 (symbol-name type)
2733 "Lambda expression"))
2734 (t "???"))))
2735 (if org-agenda-menu-show-matcher
2736 (setq line
2737 (concat line ": "
2738 (cond
2739 ((stringp match)
2740 (setq match (copy-sequence match))
2741 (org-add-props match nil 'face 'org-warning))
2742 ((listp type)
2743 (format "set of %d commands" (length type))))))
2744 (if (org-string-nw-p match)
2745 (add-text-properties
2746 0 (length line) (list 'help-echo
2747 (concat "Matcher: " match)) line)))
2748 (push line lines)))
2749 (setq lines (nreverse lines))
2750 (when prefixes
2751 (mapc (lambda (x)
2752 (push
2753 (format "%s %s"
2754 (org-add-props (char-to-string x)
2755 nil 'face 'bold)
2756 (or (cdr (assoc (concat selstring
2757 (char-to-string x))
2758 prefix-descriptions))
2759 "Prefix key"))
2760 lines))
2761 prefixes))
2763 ;; Check if we should display in two columns
2764 (if org-agenda-menu-two-columns
2765 (progn
2766 (setq n (length lines)
2767 n1 (+ (/ n 2) (mod n 2))
2768 right (nthcdr n1 lines)
2769 left (copy-sequence lines))
2770 (setcdr (nthcdr (1- n1) left) nil))
2771 (setq left lines right nil))
2772 (while left
2773 (insert "\n" (pop left))
2774 (when right
2775 (if (< (current-column) 40)
2776 (move-to-column 40 t)
2777 (insert " "))
2778 (insert (pop right))))
2780 ;; Make the window the right size
2781 (goto-char (point-min))
2782 (if second-time
2783 (if (not (pos-visible-in-window-p (point-max)))
2784 (org-fit-window-to-buffer))
2785 (setq second-time t)
2786 (org-fit-window-to-buffer))
2788 ;; Ask for selection
2789 (message "Press key for agenda command%s:"
2790 (if (or restrict-ok org-agenda-overriding-restriction)
2791 (if org-agenda-overriding-restriction
2792 " (restriction lock active)"
2793 (if restriction
2794 (format " (restricted to %s)" restriction)
2795 " (unrestricted)"))
2796 ""))
2797 (setq c (read-char-exclusive))
2798 (message "")
2799 (cond
2800 ((assoc (char-to-string c) custom)
2801 (setq selstring (concat selstring (char-to-string c)))
2802 (throw 'exit (cons selstring restriction)))
2803 ((memq c prefixes)
2804 (setq selstring (concat selstring (char-to-string c))
2805 prefixes nil
2806 rmheader (or rmheader t)
2807 custom (delq nil (mapcar
2808 (lambda (x)
2809 (if (or (= (length (car x)) 1)
2810 (/= (string-to-char (car x)) c))
2812 (cons (substring (car x) 1) (cdr x))))
2813 custom))))
2814 ((eq c ?*)
2815 (call-interactively 'org-toggle-sticky-agenda)
2816 (sit-for 2))
2817 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2818 (message "Restriction is only possible in Org-mode buffers")
2819 (ding) (sit-for 1))
2820 ((eq c ?1)
2821 (org-agenda-remove-restriction-lock 'noupdate)
2822 (setq restriction 'buffer))
2823 ((eq c ?0)
2824 (org-agenda-remove-restriction-lock 'noupdate)
2825 (setq restriction (if region-p 'region 'subtree)))
2826 ((eq c ?<)
2827 (org-agenda-remove-restriction-lock 'noupdate)
2828 (setq restriction
2829 (cond
2830 ((eq restriction 'buffer)
2831 (if region-p 'region 'subtree))
2832 ((memq restriction '(subtree region))
2833 nil)
2834 (t 'buffer))))
2835 ((eq c ?>)
2836 (org-agenda-remove-restriction-lock 'noupdate)
2837 (setq restriction nil))
2838 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2839 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2840 ((and (> (length selstring) 0) (eq c ?\d))
2841 (delete-window)
2842 (org-agenda-get-restriction-and-command prefix-descriptions))
2844 ((equal c ?q) (error "Abort"))
2845 (t (error "Invalid key %c" c))))))))
2847 (defun org-agenda-fit-window-to-buffer ()
2848 "Fit the window to the buffer size."
2849 (and (memq org-agenda-window-setup '(reorganize-frame))
2850 (fboundp 'fit-window-to-buffer)
2851 (org-fit-window-to-buffer
2853 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2854 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2856 (defvar org-cmd nil)
2857 (defvar org-agenda-overriding-cmd nil)
2858 (defvar org-agenda-overriding-arguments nil)
2859 (defvar org-agenda-overriding-cmd-arguments nil)
2860 (defun org-agenda-run-series (name series)
2861 (org-let (nth 1 series) '(org-agenda-prepare name))
2862 ;; We need to reset agenda markers here, because when constructing a
2863 ;; block agenda, the individual blocks do not do that.
2864 (org-agenda-reset-markers)
2865 (let* ((org-agenda-multi t)
2866 (redo (list 'org-agenda-run-series name (list 'quote series)))
2867 (cmds (car series))
2868 (gprops (nth 1 series))
2869 match ;; The byte compiler incorrectly complains about this. Keep it!
2870 org-cmd type lprops)
2871 (while (setq org-cmd (pop cmds))
2872 (setq type (car org-cmd)
2873 match (eval (nth 1 org-cmd))
2874 lprops (nth 2 org-cmd))
2875 (let ((org-agenda-overriding-arguments
2876 (if (eq org-agenda-overriding-cmd org-cmd)
2877 (or org-agenda-overriding-arguments
2878 org-agenda-overriding-cmd-arguments))))
2879 (cond
2880 ((eq type 'agenda)
2881 (org-let2 gprops lprops
2882 '(call-interactively 'org-agenda-list)))
2883 ((eq type 'alltodo)
2884 (org-let2 gprops lprops
2885 '(call-interactively 'org-todo-list)))
2886 ((eq type 'search)
2887 (org-let2 gprops lprops
2888 '(org-search-view current-prefix-arg match nil)))
2889 ((eq type 'stuck)
2890 (org-let2 gprops lprops
2891 '(call-interactively 'org-agenda-list-stuck-projects)))
2892 ((eq type 'tags)
2893 (org-let2 gprops lprops
2894 '(org-tags-view current-prefix-arg match)))
2895 ((eq type 'tags-todo)
2896 (org-let2 gprops lprops
2897 '(org-tags-view '(4) match)))
2898 ((eq type 'todo)
2899 (org-let2 gprops lprops
2900 '(org-todo-list match)))
2901 ((fboundp type)
2902 (org-let2 gprops lprops
2903 '(funcall type match)))
2904 (t (error "Invalid type in command series")))))
2905 (widen)
2906 (let ((inhibit-read-only t))
2907 (add-text-properties (point-min) (point-max)
2908 `(org-series t org-series-redo-cmd ,redo)))
2909 (setq org-agenda-redo-command redo)
2910 (goto-char (point-min)))
2911 (org-agenda-fit-window-to-buffer)
2912 (org-let (nth 1 series) '(org-agenda-finalize)))
2914 ;;;###autoload
2915 (defmacro org-batch-agenda (cmd-key &rest parameters)
2916 "Run an agenda command in batch mode and send the result to STDOUT.
2917 If CMD-KEY is a string of length 1, it is used as a key in
2918 `org-agenda-custom-commands' and triggers this command. If it is a
2919 longer string it is used as a tags/todo match string.
2920 Parameters are alternating variable names and values that will be bound
2921 before running the agenda command."
2922 (org-eval-in-environment (org-make-parameter-alist parameters)
2923 (if (> (length cmd-key) 2)
2924 (org-tags-view nil cmd-key)
2925 (org-agenda nil cmd-key)))
2926 (set-buffer org-agenda-buffer-name)
2927 (princ (buffer-string)))
2929 (autoload 'org-batch-agenda "org-agenda" "\
2930 Run an agenda command in batch mode and send the result to STDOUT.
2931 If CMD-KEY is a string of length 1, it is used as a key in
2932 `org-agenda-custom-commands' and triggers this command. If it is a
2933 longer string it is used as a tags/todo match string.
2934 Parameters are alternating variable names and values that will be bound
2935 before running the agenda command.
2937 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2938 (def-edebug-spec org-batch-agenda (form &rest sexp))
2940 (defvar org-agenda-info nil)
2942 ;;;###autoload
2943 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2944 "Run an agenda command in batch mode and send the result to STDOUT.
2945 If CMD-KEY is a string of length 1, it is used as a key in
2946 `org-agenda-custom-commands' and triggers this command. If it is a
2947 longer string it is used as a tags/todo match string.
2948 Parameters are alternating variable names and values that will be bound
2949 before running the agenda command.
2951 The output gives a line for each selected agenda item. Each
2952 item is a list of comma-separated values, like this:
2954 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2956 category The category of the item
2957 head The headline, without TODO kwd, TAGS and PRIORITY
2958 type The type of the agenda entry, can be
2959 todo selected in TODO match
2960 tagsmatch selected in tags match
2961 diary imported from diary
2962 deadline a deadline on given date
2963 scheduled scheduled on given date
2964 timestamp entry has timestamp on given date
2965 closed entry was closed on given date
2966 upcoming-deadline warning about deadline
2967 past-scheduled forwarded scheduled item
2968 block entry has date block including g. date
2969 todo The todo keyword, if any
2970 tags All tags including inherited ones, separated by colons
2971 date The relevant date, like 2007-2-14
2972 time The time, like 15:00-16:50
2973 extra Sting with extra planning info
2974 priority-l The priority letter if any was given
2975 priority-n The computed numerical priority
2976 agenda-day The day in the agenda where this is listed"
2977 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2978 (org-make-parameter-alist parameters))
2979 (if (> (length cmd-key) 2)
2980 (org-tags-view nil cmd-key)
2981 (org-agenda nil cmd-key)))
2982 (set-buffer org-agenda-buffer-name)
2983 (let* ((lines (org-split-string (buffer-string) "\n"))
2984 line)
2985 (while (setq line (pop lines))
2986 (catch 'next
2987 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2988 (setq org-agenda-info
2989 (org-fix-agenda-info (text-properties-at 0 line)))
2990 (princ
2991 (mapconcat 'org-agenda-export-csv-mapper
2992 '(org-category txt type todo tags date time extra
2993 priority-letter priority agenda-day)
2994 ","))
2995 (princ "\n")))))
2997 (autoload 'org-batch-agenda-csv "org-agenda" "\
2998 Run an agenda command in batch mode and send the result to STDOUT.
2999 If CMD-KEY is a string of length 1, it is used as a key in
3000 `org-agenda-custom-commands' and triggers this command. If it is a
3001 longer string it is used as a tags/todo match string.
3002 Parameters are alternating variable names and values that will be bound
3003 before running the agenda command.
3005 The output gives a line for each selected agenda item. Each
3006 item is a list of comma-separated values, like this:
3008 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3010 category The category of the item
3011 head The headline, without TODO kwd, TAGS and PRIORITY
3012 type The type of the agenda entry, can be
3013 todo selected in TODO match
3014 tagsmatch selected in tags match
3015 diary imported from diary
3016 deadline a deadline on given date
3017 scheduled scheduled on given date
3018 timestamp entry has timestamp on given date
3019 closed entry was closed on given date
3020 upcoming-deadline warning about deadline
3021 past-scheduled forwarded scheduled item
3022 block entry has date block including g. date
3023 todo The todo keyword, if any
3024 tags All tags including inherited ones, separated by colons
3025 date The relevant date, like 2007-2-14
3026 time The time, like 15:00-16:50
3027 extra Sting with extra planning info
3028 priority-l The priority letter if any was given
3029 priority-n The computed numerical priority
3030 agenda-day The day in the agenda where this is listed
3032 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3033 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3035 (defun org-fix-agenda-info (props)
3036 "Make sure all properties on an agenda item have a canonical form.
3037 This ensures the export commands can easily use it."
3038 (let (tmp re)
3039 (when (setq tmp (plist-get props 'tags))
3040 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3041 (when (setq tmp (plist-get props 'date))
3042 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3043 (let ((calendar-date-display-form '(year "-" month "-" day)))
3044 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3046 (setq tmp (calendar-date-string tmp)))
3047 (setq props (plist-put props 'date tmp)))
3048 (when (setq tmp (plist-get props 'day))
3049 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3050 (let ((calendar-date-display-form '(year "-" month "-" day)))
3051 (setq tmp (calendar-date-string tmp)))
3052 (setq props (plist-put props 'day tmp))
3053 (setq props (plist-put props 'agenda-day tmp)))
3054 (when (setq tmp (plist-get props 'txt))
3055 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3056 (plist-put props 'priority-letter (match-string 1 tmp))
3057 (setq tmp (replace-match "" t t tmp)))
3058 (when (and (setq re (plist-get props 'org-todo-regexp))
3059 (setq re (concat "\\`\\.*" re " ?"))
3060 (string-match re tmp))
3061 (plist-put props 'todo (match-string 1 tmp))
3062 (setq tmp (replace-match "" t t tmp)))
3063 (plist-put props 'txt tmp)))
3064 props)
3066 (defun org-agenda-export-csv-mapper (prop)
3067 (let ((res (plist-get org-agenda-info prop)))
3068 (setq res
3069 (cond
3070 ((not res) "")
3071 ((stringp res) res)
3072 (t (prin1-to-string res))))
3073 (while (string-match "," res)
3074 (setq res (replace-match ";" t t res)))
3075 (org-trim res)))
3077 ;;;###autoload
3078 (defun org-store-agenda-views (&rest parameters)
3079 (interactive)
3080 (eval (list 'org-batch-store-agenda-views)))
3082 (autoload 'org-store-agenda-views "org-agenda" "\
3085 \(fn &rest PARAMETERS)" t nil)
3087 ;;;###autoload
3088 (defmacro org-batch-store-agenda-views (&rest parameters)
3089 "Run all custom agenda commands that have a file argument."
3090 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3091 (pop-up-frames nil)
3092 (dir default-directory)
3093 (pars (org-make-parameter-alist parameters))
3094 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3095 (save-window-excursion
3096 (while cmds
3097 (setq cmd (pop cmds)
3098 thiscmdkey (car cmd)
3099 thiscmdcmd (cdr cmd)
3100 match (nth 2 thiscmdcmd)
3101 bufname (if org-agenda-sticky
3102 (or (and (stringp match)
3103 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3104 (format "*Org Agenda(%s)*" thiscmdkey))
3105 org-agenda-buffer-name)
3106 cmd-or-set (nth 2 cmd)
3107 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3108 files (nth (if (listp cmd-or-set) 4 5) cmd))
3109 (if (stringp files) (setq files (list files)))
3110 (when files
3111 (org-eval-in-environment (append org-agenda-exporter-settings
3112 opts pars)
3113 (org-agenda nil thiscmdkey))
3114 (set-buffer bufname)
3115 (while files
3116 (org-eval-in-environment (append org-agenda-exporter-settings
3117 opts pars)
3118 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3119 (and (get-buffer bufname)
3120 (kill-buffer bufname)))))))
3122 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3123 Run all custom agenda commands that have a file argument.
3125 \(fn &rest PARAMETERS)" nil t)
3126 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3128 (defvar org-agenda-current-span nil
3129 "The current span used in the agenda view.") ; local variable in the agenda buffer
3130 (defun org-agenda-mark-header-line (pos)
3131 "Mark the line at POS as an agenda structure header."
3132 (save-excursion
3133 (goto-char pos)
3134 (put-text-property (point-at-bol) (point-at-eol)
3135 'org-agenda-structural-header t)
3136 (when org-agenda-title-append
3137 (put-text-property (point-at-bol) (point-at-eol)
3138 'org-agenda-title-append org-agenda-title-append))))
3140 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3141 (defvar org-agenda-write-buffer-name "Agenda View")
3142 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3143 "Write the current buffer (an agenda view) as a file.
3144 Depending on the extension of the file name, plain text (.txt),
3145 HTML (.html or .htm) or Postscript (.ps) is produced.
3146 If the extension is .ics, run icalendar export over all files used
3147 to construct the agenda and limit the export to entries listed in the
3148 agenda now.
3149 With prefix argument OPEN, open the new file immediately.
3150 If NOSETTINGS is given, do not scope the settings of
3151 `org-agenda-exporter-settings' into the export commands. This is used when
3152 the settings have already been scoped and we do not wish to overrule other,
3153 higher priority settings.
3154 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3155 (interactive "FWrite agenda to file: \nP")
3156 (if (not (file-writable-p file))
3157 (error "Cannot write agenda to file %s" file))
3158 (org-let (if nosettings nil org-agenda-exporter-settings)
3159 '(save-excursion
3160 (save-window-excursion
3161 (org-agenda-mark-filtered-text)
3162 (let ((bs (copy-sequence (buffer-string))) beg)
3163 (org-agenda-unmark-filtered-text)
3164 (with-temp-buffer
3165 (rename-buffer org-agenda-write-buffer-name t)
3166 (set-buffer-modified-p nil)
3167 (insert bs)
3168 (org-agenda-remove-marked-text 'org-filtered)
3169 (while (setq beg (text-property-any (point-min) (point-max)
3170 'org-filtered t))
3171 (delete-region
3172 beg (or (next-single-property-change beg 'org-filtered)
3173 (point-max))))
3174 (run-hooks 'org-agenda-before-write-hook)
3175 (cond
3176 ((org-bound-and-true-p org-mobile-creating-agendas)
3177 (org-mobile-write-agenda-for-mobile file))
3178 ((string-match "\\.html?\\'" file)
3179 (require 'htmlize)
3180 (set-buffer (htmlize-buffer (current-buffer)))
3181 (when org-agenda-export-html-style
3182 ;; replace <style> section with org-agenda-export-html-style
3183 (goto-char (point-min))
3184 (kill-region (- (search-forward "<style") 6)
3185 (search-forward "</style>"))
3186 (insert org-agenda-export-html-style))
3187 (write-file file)
3188 (kill-buffer (current-buffer))
3189 (message "HTML written to %s" file))
3190 ((string-match "\\.ps\\'" file)
3191 (require 'ps-print)
3192 (ps-print-buffer-with-faces file)
3193 (message "Postscript written to %s" file))
3194 ((string-match "\\.pdf\\'" file)
3195 (require 'ps-print)
3196 (ps-print-buffer-with-faces
3197 (concat (file-name-sans-extension file) ".ps"))
3198 (call-process "ps2pdf" nil nil nil
3199 (expand-file-name
3200 (concat (file-name-sans-extension file) ".ps"))
3201 (expand-file-name file))
3202 (delete-file (concat (file-name-sans-extension file) ".ps"))
3203 (message "PDF written to %s" file))
3204 ((string-match "\\.ics\\'" file)
3205 (require 'org-icalendar)
3206 (let ((org-agenda-marker-table
3207 (org-create-marker-find-array
3208 (org-agenda-collect-markers)))
3209 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3210 (org-combined-agenda-icalendar-file file))
3211 (apply 'org-export-icalendar 'combine
3212 (org-agenda-files nil 'ifmode))))
3214 (let ((bs (buffer-string)))
3215 (find-file file)
3216 (erase-buffer)
3217 (insert bs)
3218 (save-buffer 0)
3219 (kill-buffer (current-buffer))
3220 (message "Plain text written to %s" file))))))))
3221 (set-buffer (or agenda-bufname
3222 (and (org-called-interactively-p 'any) (buffer-name))
3223 org-agenda-buffer-name)))
3224 (when open (org-open-file file)))
3226 (defvar org-agenda-tag-filter-overlays nil)
3227 (defvar org-agenda-cat-filter-overlays nil)
3229 (defun org-agenda-mark-filtered-text ()
3230 "Mark all text hidden by filtering with a text property."
3231 (let ((inhibit-read-only t))
3232 (mapc
3233 (lambda (o)
3234 (when (equal (overlay-buffer o) (current-buffer))
3235 (put-text-property
3236 (overlay-start o) (overlay-end o)
3237 'org-filtered t)))
3238 (append org-agenda-tag-filter-overlays
3239 org-agenda-cat-filter-overlays))))
3241 (defun org-agenda-unmark-filtered-text ()
3242 "Remove the filtering text property."
3243 (let ((inhibit-read-only t))
3244 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3246 (defun org-agenda-remove-marked-text (property &optional value)
3247 "Delete all text marked with VALUE of PROPERTY.
3248 VALUE defaults to t."
3249 (let (beg)
3250 (setq value (or value t))
3251 (while (setq beg (text-property-any (point-min) (point-max)
3252 property value))
3253 (delete-region
3254 beg (or (next-single-property-change beg 'org-filtered)
3255 (point-max))))))
3257 (defun org-agenda-add-entry-text ()
3258 "Add entry text to agenda lines.
3259 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3260 entry text following headings shown in the agenda.
3261 Drawers will be excluded, also the line with scheduling/deadline info."
3262 (when (and (> org-agenda-add-entry-text-maxlines 0)
3263 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3264 (let (m txt)
3265 (goto-char (point-min))
3266 (while (not (eobp))
3267 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3268 (beginning-of-line 2)
3269 (setq txt (org-agenda-get-some-entry-text
3270 m org-agenda-add-entry-text-maxlines " > "))
3271 (end-of-line 1)
3272 (if (string-match "\\S-" txt)
3273 (insert "\n" txt)
3274 (or (eobp) (forward-char 1))))))))
3276 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3277 &rest keep)
3278 "Extract entry text from MARKER, at most N-LINES lines.
3279 This will ignore drawers etc, just get the text.
3280 If INDENT is given, prefix every line with this string. If KEEP is
3281 given, it is a list of symbols, defining stuff that should not be
3282 removed from the entry content. Currently only `planning' is allowed here."
3283 (let (txt drawer-re kwd-time-re ind)
3284 (save-excursion
3285 (with-current-buffer (marker-buffer marker)
3286 (if (not (derived-mode-p 'org-mode))
3287 (setq txt "")
3288 (save-excursion
3289 (save-restriction
3290 (widen)
3291 (goto-char marker)
3292 (end-of-line 1)
3293 (setq txt (buffer-substring
3294 (min (1+ (point)) (point-max))
3295 (progn (outline-next-heading) (point)))
3296 drawer-re org-drawer-regexp
3297 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3298 ".*\n?"))
3299 (with-temp-buffer
3300 (insert txt)
3301 (when org-agenda-add-entry-text-descriptive-links
3302 (goto-char (point-min))
3303 (while (org-activate-bracket-links (point-max))
3304 (add-text-properties (match-beginning 0) (match-end 0)
3305 '(face org-link))))
3306 (goto-char (point-min))
3307 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3308 (set-text-properties (match-beginning 0) (match-end 0)
3309 nil))
3310 (goto-char (point-min))
3311 (while (re-search-forward drawer-re nil t)
3312 (delete-region
3313 (match-beginning 0)
3314 (progn (re-search-forward
3315 "^[ \t]*:END:.*\n?" nil 'move)
3316 (point))))
3317 (unless (member 'planning keep)
3318 (goto-char (point-min))
3319 (while (re-search-forward kwd-time-re nil t)
3320 (replace-match "")))
3321 (goto-char (point-min))
3322 (when org-agenda-entry-text-exclude-regexps
3323 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3324 (while (setq re (pop re-list))
3325 (goto-char (point-min))
3326 (while (re-search-forward re nil t)
3327 (replace-match "")))))
3328 (goto-char (point-max))
3329 (skip-chars-backward " \t\n")
3330 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3332 ;; find and remove min common indentation
3333 (goto-char (point-min))
3334 (untabify (point-min) (point-max))
3335 (setq ind (org-get-indentation))
3336 (while (not (eobp))
3337 (unless (looking-at "[ \t]*$")
3338 (setq ind (min ind (org-get-indentation))))
3339 (beginning-of-line 2))
3340 (goto-char (point-min))
3341 (while (not (eobp))
3342 (unless (looking-at "[ \t]*$")
3343 (move-to-column ind)
3344 (delete-region (point-at-bol) (point)))
3345 (beginning-of-line 2))
3347 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3349 (goto-char (point-min))
3350 (when indent
3351 (while (and (not (eobp)) (re-search-forward "^" nil t))
3352 (replace-match indent t t)))
3353 (goto-char (point-min))
3354 (while (looking-at "[ \t]*\n") (replace-match ""))
3355 (goto-char (point-max))
3356 (when (> (org-current-line)
3357 n-lines)
3358 (org-goto-line (1+ n-lines))
3359 (backward-char 1))
3360 (setq txt (buffer-substring (point-min) (point)))))))))
3361 txt))
3363 (defun org-agenda-collect-markers ()
3364 "Collect the markers pointing to entries in the agenda buffer."
3365 (let (m markers)
3366 (save-excursion
3367 (goto-char (point-min))
3368 (while (not (eobp))
3369 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3370 (org-get-at-bol 'org-marker)))
3371 (push m markers))
3372 (beginning-of-line 2)))
3373 (nreverse markers)))
3375 (defun org-create-marker-find-array (marker-list)
3376 "Create a alist of files names with all marker positions in that file."
3377 (let (f tbl m a p)
3378 (while (setq m (pop marker-list))
3379 (setq p (marker-position m)
3380 f (buffer-file-name (or (buffer-base-buffer
3381 (marker-buffer m))
3382 (marker-buffer m))))
3383 (if (setq a (assoc f tbl))
3384 (push (marker-position m) (cdr a))
3385 (push (list f p) tbl)))
3386 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3387 tbl)))
3389 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3390 (defun org-check-agenda-marker-table ()
3391 "Check of the current entry is on the marker list."
3392 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3394 (and (setq a (assoc file org-agenda-marker-table))
3395 (save-match-data
3396 (save-excursion
3397 (org-back-to-heading t)
3398 (member (point) (cdr a)))))))
3400 (defun org-check-for-org-mode ()
3401 "Make sure current buffer is in org-mode. Error if not."
3402 (or (derived-mode-p 'org-mode)
3403 (error "Cannot execute org-mode agenda command on buffer in %s"
3404 major-mode)))
3406 ;;; Agenda prepare and finalize
3408 (defvar org-agenda-multi nil) ; dynamically scoped
3409 (defvar org-agenda-pre-window-conf nil)
3410 (defvar org-agenda-columns-active nil)
3411 (defvar org-agenda-name nil)
3412 (defvar org-agenda-tag-filter nil)
3413 (defvar org-agenda-category-filter nil)
3414 (defvar org-agenda-top-category-filter nil)
3415 (defvar org-agenda-tag-filter-while-redo nil)
3416 (defvar org-agenda-tag-filter-preset nil
3417 "A preset of the tags filter used for secondary agenda filtering.
3418 This must be a list of strings, each string must be a single tag preceded
3419 by \"+\" or \"-\".
3420 This variable should not be set directly, but agenda custom commands can
3421 bind it in the options section. The preset filter is a global property of
3422 the entire agenda view. In a block agenda, it will not work reliably to
3423 define a filter for one of the individual blocks. You need to set it in
3424 the global options and expect it to be applied to the entire view.")
3426 (defvar org-agenda-category-filter-preset nil
3427 "A preset of the category filter used for secondary agenda filtering.
3428 This must be a list of strings, each string must be a single category
3429 preceded by \"+\" or \"-\".
3430 This variable should not be set directly, but agenda custom commands can
3431 bind it in the options section. The preset filter is a global property of
3432 the entire agenda view. In a block agenda, it will not work reliably to
3433 define a filter for one of the individual blocks. You need to set it in
3434 the global options and expect it to be applied to the entire view.")
3437 (defun org-agenda-use-sticky-p ()
3438 "Return non-nil if an agenda buffer named
3439 `org-agenda-buffer-name' exists and should be shown instead of
3440 generating a new one."
3441 (and
3442 ;; turned off by user
3443 org-agenda-sticky
3444 ;; For multi-agenda buffer already exists
3445 (not org-agenda-multi)
3446 ;; buffer found
3447 (get-buffer org-agenda-buffer-name)
3448 ;; C-u parameter is same as last call
3449 (with-current-buffer (get-buffer org-agenda-buffer-name)
3450 (and
3451 (equal current-prefix-arg
3452 org-agenda-last-prefix-arg)
3453 ;; In case user turned stickiness on, while having existing
3454 ;; Agenda buffer active, don't reuse that buffer, because it
3455 ;; does not have org variables local
3456 org-agenda-this-buffer-is-sticky))))
3458 (defun org-agenda-prepare-window (abuf)
3459 "Setup agenda buffer in the window."
3460 (let* ((awin (get-buffer-window abuf))
3461 wconf)
3462 (cond
3463 ((equal (current-buffer) abuf) nil)
3464 (awin (select-window awin))
3465 ((not (setq wconf (current-window-configuration))))
3466 ((equal org-agenda-window-setup 'current-window)
3467 (org-pop-to-buffer-same-window abuf))
3468 ((equal org-agenda-window-setup 'other-window)
3469 (org-switch-to-buffer-other-window abuf))
3470 ((equal org-agenda-window-setup 'other-frame)
3471 (switch-to-buffer-other-frame abuf))
3472 ((equal org-agenda-window-setup 'reorganize-frame)
3473 (delete-other-windows)
3474 (org-switch-to-buffer-other-window abuf)))
3475 ;; additional test in case agenda is invoked from within agenda
3476 ;; buffer via elisp link
3477 (unless (equal (current-buffer) abuf)
3478 (org-pop-to-buffer-same-window abuf))
3479 (setq org-agenda-pre-window-conf
3480 (or org-agenda-pre-window-conf wconf))))
3482 (defun org-agenda-prepare (&optional name)
3483 (if (org-agenda-use-sticky-p)
3484 (progn
3485 ;; Popup existing buffer
3486 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3487 (message "Sticky Agenda buffer, use `r' to refresh")
3488 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3489 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3490 (setq org-todo-keywords-for-agenda nil)
3491 (setq org-drawers-for-agenda nil)
3492 (unless org-agenda-persistent-filter
3493 (setq org-agenda-tag-filter nil
3494 org-agenda-category-filter nil))
3495 (put 'org-agenda-tag-filter :preset-filter
3496 org-agenda-tag-filter-preset)
3497 (put 'org-agenda-category-filter :preset-filter
3498 org-agenda-category-filter-preset)
3499 (if org-agenda-multi
3500 (progn
3501 (setq buffer-read-only nil)
3502 (goto-char (point-max))
3503 (unless (or (bobp) org-agenda-compact-blocks
3504 (not org-agenda-block-separator))
3505 (insert "\n"
3506 (if (stringp org-agenda-block-separator)
3507 org-agenda-block-separator
3508 (make-string (window-width) org-agenda-block-separator))
3509 "\n"))
3510 (narrow-to-region (point) (point-max)))
3511 (setq org-done-keywords-for-agenda nil)
3513 ;; Setting any org variables that are in org-agenda-local-vars
3514 ;; list need to be done after the prepare call
3515 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3516 (setq buffer-read-only nil)
3517 (org-agenda-reset-markers)
3518 (let ((inhibit-read-only t)) (erase-buffer))
3519 (org-agenda-mode)
3520 (setq org-agenda-buffer (current-buffer))
3521 (setq org-agenda-contributing-files nil)
3522 (setq org-agenda-columns-active nil)
3523 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3524 (setq org-todo-keywords-for-agenda
3525 (org-uniquify org-todo-keywords-for-agenda))
3526 (setq org-done-keywords-for-agenda
3527 (org-uniquify org-done-keywords-for-agenda))
3528 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3529 (setq org-agenda-last-prefix-arg current-prefix-arg)
3530 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3531 (and name (not org-agenda-name)
3532 (org-set-local 'org-agenda-name name)))
3533 (setq buffer-read-only nil)))
3535 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3536 (defun org-agenda-finalize ()
3537 "Finishing touch for the agenda buffer, called just before displaying it."
3538 (unless org-agenda-multi
3539 (save-excursion
3540 (let ((inhibit-read-only t))
3541 (goto-char (point-min))
3542 (save-excursion
3543 (while (org-activate-bracket-links (point-max))
3544 (add-text-properties (match-beginning 0) (match-end 0)
3545 '(face org-link))))
3546 (save-excursion
3547 (while (org-activate-plain-links (point-max))
3548 (add-text-properties (match-beginning 0) (match-end 0)
3549 '(face org-link))))
3550 (org-agenda-align-tags)
3551 (unless org-agenda-with-colors
3552 (remove-text-properties (point-min) (point-max) '(face nil))))
3553 (if (and (boundp 'org-agenda-overriding-columns-format)
3554 org-agenda-overriding-columns-format)
3555 (org-set-local 'org-agenda-overriding-columns-format
3556 org-agenda-overriding-columns-format))
3557 (if (and (boundp 'org-agenda-view-columns-initially)
3558 org-agenda-view-columns-initially)
3559 (org-agenda-columns))
3560 (when org-agenda-fontify-priorities
3561 (org-agenda-fontify-priorities))
3562 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3563 (org-agenda-dim-blocked-tasks))
3564 ;; We need to widen when `org-agenda-finalize' is called from
3565 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3566 (save-restriction
3567 (widen)
3568 (org-agenda-mark-clocking-task))
3569 (when org-agenda-entry-text-mode
3570 (org-agenda-entry-text-hide)
3571 (org-agenda-entry-text-show))
3572 (if (functionp 'org-habit-insert-consistency-graphs)
3573 (org-habit-insert-consistency-graphs))
3574 (let ((inhibit-read-only t))
3575 (run-hooks 'org-agenda-finalize-hook))
3576 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3577 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3578 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3579 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3580 (org-agenda-filter-apply org-agenda-category-filter 'category))
3581 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3583 (defun org-agenda-mark-clocking-task ()
3584 "Mark the current clock entry in the agenda if it is present."
3585 (mapc (lambda (o)
3586 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3587 (delete-overlay o)))
3588 (overlays-in (point-min) (point-max)))
3589 (when (marker-buffer org-clock-hd-marker)
3590 (save-excursion
3591 (goto-char (point-min))
3592 (let (s ov)
3593 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3594 (goto-char s)
3595 (when (equal (org-get-at-bol 'org-hd-marker)
3596 org-clock-hd-marker)
3597 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3598 (overlay-put ov 'type 'org-agenda-clocking)
3599 (overlay-put ov 'face 'org-agenda-clocking)
3600 (overlay-put ov 'help-echo
3601 "The clock is running in this item")))))))
3603 (defun org-agenda-fontify-priorities ()
3604 "Make highest priority lines bold, and lowest italic."
3605 (interactive)
3606 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3607 (delete-overlay o)))
3608 (overlays-in (point-min) (point-max)))
3609 (save-excursion
3610 (let ((inhibit-read-only t)
3611 b e p ov h l)
3612 (goto-char (point-min))
3613 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3614 (setq h (or (get-char-property (point) 'org-highest-priority)
3615 org-highest-priority)
3616 l (or (get-char-property (point) 'org-lowest-priority)
3617 org-lowest-priority)
3618 p (string-to-char (match-string 1))
3619 b (match-beginning 0)
3620 e (if (eq org-agenda-fontify-priorities 'cookies)
3621 (match-end 0)
3622 (point-at-eol))
3623 ov (make-overlay b e))
3624 (overlay-put
3625 ov 'face
3626 (cond ((org-face-from-face-or-color
3627 'priority nil
3628 (cdr (assoc p org-priority-faces))))
3629 ((and (listp org-agenda-fontify-priorities)
3630 (org-face-from-face-or-color
3631 'priority nil
3632 (cdr (assoc p org-agenda-fontify-priorities)))))
3633 ((equal p l) 'italic)
3634 ((equal p h) 'bold)))
3635 (overlay-put ov 'org-type 'org-priority)))))
3637 (defun org-agenda-dim-blocked-tasks ()
3638 "Dim currently blocked TODO's in the agenda display."
3639 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3640 (delete-overlay o)))
3641 (overlays-in (point-min) (point-max)))
3642 (save-excursion
3643 (let ((inhibit-read-only t)
3644 (org-depend-tag-blocked nil)
3645 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3646 org-blocked-by-checkboxes
3647 invis1 b e p ov h l)
3648 (goto-char (point-min))
3649 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3650 (and pos (goto-char (1+ pos))))
3651 (setq org-blocked-by-checkboxes nil invis1 invis)
3652 (let ((marker (org-get-at-bol 'org-hd-marker)))
3653 (when (and marker
3654 (with-current-buffer (marker-buffer marker)
3655 (save-excursion (goto-char marker)
3656 (org-entry-blocked-p))))
3657 (if org-blocked-by-checkboxes (setq invis1 nil))
3658 (setq b (if invis1
3659 (max (point-min) (1- (point-at-bol)))
3660 (point-at-bol))
3661 e (point-at-eol)
3662 ov (make-overlay b e))
3663 (if invis1
3664 (overlay-put ov 'invisible t)
3665 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3666 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3668 (defvar org-agenda-skip-function nil
3669 "Function to be called at each match during agenda construction.
3670 If this function returns nil, the current match should not be skipped.
3671 Otherwise, the function must return a position from where the search
3672 should be continued.
3673 This may also be a Lisp form, it will be evaluated.
3674 Never set this variable using `setq' or so, because then it will apply
3675 to all future agenda commands. If you do want a global skipping condition,
3676 use the option `org-agenda-skip-function-global' instead.
3677 The correct usage for `org-agenda-skip-function' is to bind it with
3678 `let' to scope it dynamically into the agenda-constructing command.
3679 A good way to set it is through options in `org-agenda-custom-commands'.")
3681 (defun org-agenda-skip ()
3682 "Throw to `:skip' in places that should be skipped.
3683 Also moves point to the end of the skipped region, so that search can
3684 continue from there."
3685 (let ((p (point-at-bol)) to)
3686 (when (org-in-src-block-p t) (throw :skip t))
3687 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3688 (get-text-property p :org-archived)
3689 (org-end-of-subtree t)
3690 (throw :skip t))
3691 (and org-agenda-skip-comment-trees
3692 (get-text-property p :org-comment)
3693 (org-end-of-subtree t)
3694 (throw :skip t))
3695 (if (equal (char-after p) ?#) (throw :skip t))
3696 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3697 (org-agenda-skip-eval org-agenda-skip-function)))
3698 (goto-char to)
3699 (throw :skip t))))
3701 (defun org-agenda-skip-eval (form)
3702 "If FORM is a function or a list, call (or eval) is and return result.
3703 `save-excursion' and `save-match-data' are wrapped around the call, so point
3704 and match data are returned to the previous state no matter what these
3705 functions do."
3706 (let (fp)
3707 (and form
3708 (or (setq fp (functionp form))
3709 (consp form))
3710 (save-excursion
3711 (save-match-data
3712 (if fp
3713 (funcall form)
3714 (eval form)))))))
3716 (defvar org-agenda-markers nil
3717 "List of all currently active markers created by `org-agenda'.")
3718 (defvar org-agenda-last-marker-time (org-float-time)
3719 "Creation time of the last agenda marker.")
3721 (defun org-agenda-new-marker (&optional pos)
3722 "Return a new agenda marker.
3723 Org-mode keeps a list of these markers and resets them when they are
3724 no longer in use."
3725 (let ((m (copy-marker (or pos (point)))))
3726 (setq org-agenda-last-marker-time (org-float-time))
3727 (if org-agenda-buffer
3728 (with-current-buffer org-agenda-buffer
3729 (push m org-agenda-markers))
3730 (push m org-agenda-markers))
3733 (defun org-agenda-reset-markers ()
3734 "Reset markers created by `org-agenda'."
3735 (while org-agenda-markers
3736 (move-marker (pop org-agenda-markers) nil)))
3738 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3739 "Save relative positions of markers in region.
3740 This check for agenda markers in all agenda buffers currently active."
3741 (dolist (buf (buffer-list))
3742 (with-current-buffer buf
3743 (when (eq major-mode 'org-agenda-mode)
3744 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3745 org-agenda-markers)))))
3747 ;;; Entry text mode
3749 (defun org-agenda-entry-text-show-here ()
3750 "Add some text from the entry as context to the current line."
3751 (let (m txt o)
3752 (setq m (org-get-at-bol 'org-hd-marker))
3753 (unless (marker-buffer m)
3754 (error "No marker points to an entry here"))
3755 (setq txt (concat "\n" (org-no-properties
3756 (org-agenda-get-some-entry-text
3757 m org-agenda-entry-text-maxlines " > "))))
3758 (when (string-match "\\S-" txt)
3759 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3760 (overlay-put o 'evaporate t)
3761 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3762 (overlay-put o 'after-string txt))))
3764 (defun org-agenda-entry-text-show ()
3765 "Add entry context for all agenda lines."
3766 (interactive)
3767 (save-excursion
3768 (goto-char (point-max))
3769 (beginning-of-line 1)
3770 (while (not (bobp))
3771 (when (org-get-at-bol 'org-hd-marker)
3772 (org-agenda-entry-text-show-here))
3773 (beginning-of-line 0))))
3775 (defun org-agenda-entry-text-hide ()
3776 "Remove any shown entry context."
3777 (delq nil
3778 (mapcar (lambda (o)
3779 (if (eq (overlay-get o 'org-overlay-type)
3780 'agenda-entry-content)
3781 (progn (delete-overlay o) t)))
3782 (overlays-in (point-min) (point-max)))))
3784 (defun org-agenda-get-day-face (date)
3785 "Return the face DATE should be displayed with."
3786 (or (and (functionp org-agenda-day-face-function)
3787 (funcall org-agenda-day-face-function date))
3788 (cond ((org-agenda-todayp date)
3789 'org-agenda-date-today)
3790 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3791 'org-agenda-date-weekend)
3792 (t 'org-agenda-date))))
3794 ;;; Agenda timeline
3796 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3798 (defun org-timeline (&optional dotodo)
3799 "Show a time-sorted view of the entries in the current org file.
3800 Only entries with a time stamp of today or later will be listed. With
3801 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3802 under the current date.
3803 If the buffer contains an active region, only check the region for
3804 dates."
3805 (interactive "P")
3806 (let* ((dopast t)
3807 (org-agenda-show-log-scoped org-agenda-show-log)
3808 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3809 (current-buffer))))
3810 (date (calendar-current-date))
3811 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3812 (end (if (org-region-active-p) (region-end) (point-max)))
3813 (day-numbers (org-get-all-dates
3814 beg end 'no-ranges
3815 t org-agenda-show-log-scoped ; always include today
3816 org-timeline-show-empty-dates))
3817 (org-deadline-warning-days 0)
3818 (org-agenda-only-exact-dates t)
3819 (today (org-today))
3820 (past t)
3821 args
3822 s e rtn d emptyp)
3823 (setq org-agenda-redo-command
3824 (list 'progn
3825 (list 'org-switch-to-buffer-other-window (current-buffer))
3826 (list 'org-timeline (list 'quote dotodo))))
3827 (if (not dopast)
3828 ;; Remove past dates from the list of dates.
3829 (setq day-numbers (delq nil (mapcar (lambda(x)
3830 (if (>= x today) x nil))
3831 day-numbers))))
3832 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3833 (org-compile-prefix-format 'timeline)
3834 (org-set-sorting-strategy 'timeline)
3835 (if org-agenda-show-log-scoped (push :closed args))
3836 (push :timestamp args)
3837 (push :deadline args)
3838 (push :scheduled args)
3839 (push :sexp args)
3840 (if dotodo (push :todo args))
3841 (insert "Timeline of file " entry "\n")
3842 (add-text-properties (point-min) (point)
3843 (list 'face 'org-agenda-structure))
3844 (org-agenda-mark-header-line (point-min))
3845 (while (setq d (pop day-numbers))
3846 (if (and (listp d) (eq (car d) :omitted))
3847 (progn
3848 (setq s (point))
3849 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3850 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3851 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3852 (if (and (>= d today)
3853 dopast
3854 past)
3855 (progn
3856 (setq past nil)
3857 (insert (make-string 79 ?-) "\n")))
3858 (setq date (calendar-gregorian-from-absolute d))
3859 (setq s (point))
3860 (setq rtn (and (not emptyp)
3861 (apply 'org-agenda-get-day-entries entry
3862 date args)))
3863 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3864 (progn
3865 (insert
3866 (if (stringp org-agenda-format-date)
3867 (format-time-string org-agenda-format-date
3868 (org-time-from-absolute date))
3869 (funcall org-agenda-format-date date))
3870 "\n")
3871 (put-text-property s (1- (point)) 'face
3872 (org-agenda-get-day-face date))
3873 (put-text-property s (1- (point)) 'org-date-line t)
3874 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3875 (if (equal d today)
3876 (put-text-property s (1- (point)) 'org-today t))
3877 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3878 (put-text-property s (1- (point)) 'day d)))))
3879 (goto-char (point-min))
3880 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3881 (point-min)))
3882 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3883 (org-agenda-finalize)
3884 (setq buffer-read-only t)))
3886 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3887 "Return a list of all relevant day numbers from BEG to END buffer positions.
3888 If NO-RANGES is non-nil, include only the start and end dates of a range,
3889 not every single day in the range. If FORCE-TODAY is non-nil, make
3890 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3891 inactive time stamps (those in square brackets) are included.
3892 When EMPTY is non-nil, also include days without any entries."
3893 (let ((re (concat
3894 (if pre-re pre-re "")
3895 (if inactive org-ts-regexp-both org-ts-regexp)))
3896 dates dates1 date day day1 day2 ts1 ts2 pos)
3897 (if force-today
3898 (setq dates (list (org-today))))
3899 (save-excursion
3900 (goto-char beg)
3901 (while (re-search-forward re end t)
3902 (setq day (time-to-days (org-time-string-to-time
3903 (substring (match-string 1) 0 10)
3904 (current-buffer) (match-beginning 0))))
3905 (or (memq day dates) (push day dates)))
3906 (unless no-ranges
3907 (goto-char beg)
3908 (while (re-search-forward org-tr-regexp end t)
3909 (setq pos (match-beginning 0))
3910 (setq ts1 (substring (match-string 1) 0 10)
3911 ts2 (substring (match-string 2) 0 10)
3912 day1 (time-to-days (org-time-string-to-time
3913 ts1 (current-buffer) pos))
3914 day2 (time-to-days (org-time-string-to-time
3915 ts2 (current-buffer) pos)))
3916 (while (< (setq day1 (1+ day1)) day2)
3917 (or (memq day1 dates) (push day1 dates)))))
3918 (setq dates (sort dates '<))
3919 (when empty
3920 (while (setq day (pop dates))
3921 (setq day2 (car dates))
3922 (push day dates1)
3923 (when (and day2 empty)
3924 (if (or (eq empty t)
3925 (and (numberp empty) (<= (- day2 day) empty)))
3926 (while (< (setq day (1+ day)) day2)
3927 (push (list day) dates1))
3928 (push (cons :omitted (- day2 day)) dates1))))
3929 (setq dates (nreverse dates1)))
3930 dates)))
3932 ;;; Agenda Daily/Weekly
3934 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3935 "Start day for the agenda view.
3936 Custom commands can set this variable in the options section.")
3937 (defvar org-starting-day nil) ; local variable in the agenda buffer
3938 (defvar org-arg-loc nil) ; local variable
3940 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3941 "List of types searched for when creating the daily/weekly agenda.
3942 This variable is a list of symbols that controls the types of
3943 items that appear in the daily/weekly agenda. Allowed symbols in this
3944 list are are
3946 :timestamp List items containing a date stamp or date range matching
3947 the selected date. This includes sexp entries in
3948 angular brackets.
3950 :sexp List entries resulting from plain diary-like sexps.
3952 :deadline List deadline due on that date. When the date is today,
3953 also list any deadlines past due, or due within
3954 `org-deadline-warning-days'. `:deadline' must appear before
3955 `:scheduled' if the setting of
3956 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3957 any effect.
3959 :scheduled List all items which are scheduled for the given date.
3960 The diary for *today* also contains items which were
3961 scheduled earlier and are not yet marked DONE.
3963 By default, all four types are turned on.
3965 Never set this variable globally using `setq', because then it
3966 will apply to all future agenda commands. Instead, bind it with
3967 `let' to scope it dynamically into the agenda-constructing
3968 command. A good way to set it is through options in
3969 `org-agenda-custom-commands'. For a more flexible (though
3970 somewhat less efficient) way of determining what is included in
3971 the daily/weekly agenda, see `org-agenda-skip-function'.")
3973 (defvar org-agenda-buffer-tmp-name nil)
3974 ;;;###autoload
3975 (defun org-agenda-list (&optional arg start-day span)
3976 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3977 The view will be for the current day or week, but from the overview buffer
3978 you will be able to go to other days/weeks.
3980 With a numeric prefix argument in an interactive call, the agenda will
3981 span ARG days. Lisp programs should instead specify SPAN to change
3982 the number of days. SPAN defaults to `org-agenda-span'.
3984 START-DAY defaults to TODAY, or to the most recent match for the weekday
3985 given in `org-agenda-start-on-weekday'."
3986 (interactive "P")
3987 (if org-agenda-overriding-arguments
3988 (setq arg (car org-agenda-overriding-arguments)
3989 start-day (nth 1 org-agenda-overriding-arguments)
3990 span (nth 2 org-agenda-overriding-arguments)))
3991 (if (and (integerp arg) (> arg 0))
3992 (setq span arg arg nil))
3993 (catch 'exit
3994 (setq org-agenda-buffer-name
3995 (or org-agenda-buffer-tmp-name
3996 (if org-agenda-sticky
3997 (cond ((and org-keys (stringp org-match))
3998 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3999 (org-keys
4000 (format "*Org Agenda(%s)*" org-keys))
4001 (t "*Org Agenda(a)*")))
4002 org-agenda-buffer-name))
4003 (org-agenda-prepare "Day/Week")
4004 (setq start-day (or start-day org-agenda-start-day))
4005 (if (stringp start-day)
4006 ;; Convert to an absolute day number
4007 (setq start-day (time-to-days (org-read-date nil t start-day))))
4008 (org-compile-prefix-format 'agenda)
4009 (org-set-sorting-strategy 'agenda)
4010 (let* ((span (org-agenda-ndays-to-span
4011 (or span org-agenda-ndays org-agenda-span)))
4012 (today (org-today))
4013 (sd (or start-day today))
4014 (ndays (org-agenda-span-to-ndays span sd))
4015 (org-agenda-start-on-weekday
4016 (if (eq ndays 7)
4017 org-agenda-start-on-weekday))
4018 (thefiles (org-agenda-files nil 'ifmode))
4019 (files thefiles)
4020 (start (if (or (null org-agenda-start-on-weekday)
4021 (< ndays 7))
4023 (let* ((nt (calendar-day-of-week
4024 (calendar-gregorian-from-absolute sd)))
4025 (n1 org-agenda-start-on-weekday)
4026 (d (- nt n1)))
4027 (- sd (+ (if (< d 0) 7 0) d)))))
4028 (day-numbers (list start))
4029 (day-cnt 0)
4030 (inhibit-redisplay (not debug-on-error))
4031 (org-agenda-show-log-scoped org-agenda-show-log)
4032 s e rtn rtnall file date d start-pos end-pos todayp
4033 clocktable-start clocktable-end filter)
4034 (setq org-agenda-redo-command
4035 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4036 (dotimes (n (1- ndays))
4037 (push (1+ (car day-numbers)) day-numbers))
4038 (setq day-numbers (nreverse day-numbers))
4039 (setq clocktable-start (car day-numbers)
4040 clocktable-end (1+ (or (org-last day-numbers) 0)))
4041 (org-set-local 'org-starting-day (car day-numbers))
4042 (org-set-local 'org-arg-loc arg)
4043 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4044 (unless org-agenda-compact-blocks
4045 (let* ((d1 (car day-numbers))
4046 (d2 (org-last day-numbers))
4047 (w1 (org-days-to-iso-week d1))
4048 (w2 (org-days-to-iso-week d2)))
4049 (setq s (point))
4050 (if org-agenda-overriding-header
4051 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4052 nil 'face 'org-agenda-structure) "\n")
4053 (insert (org-agenda-span-name span)
4054 "-agenda"
4055 (if (< (- d2 d1) 350)
4056 (if (= w1 w2)
4057 (format " (W%02d)" w1)
4058 (format " (W%02d-W%02d)" w1 w2))
4060 ":\n")))
4061 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4062 'org-date-line t))
4063 (org-agenda-mark-header-line s))
4064 (while (setq d (pop day-numbers))
4065 (setq date (calendar-gregorian-from-absolute d)
4066 s (point))
4067 (if (or (setq todayp (= d today))
4068 (and (not start-pos) (= d sd)))
4069 (setq start-pos (point))
4070 (if (and start-pos (not end-pos))
4071 (setq end-pos (point))))
4072 (setq files thefiles
4073 rtnall nil)
4074 (while (setq file (pop files))
4075 (catch 'nextfile
4076 (org-check-agenda-file file)
4077 (let ((org-agenda-entry-types org-agenda-entry-types))
4078 (unless org-agenda-include-deadlines
4079 (setq org-agenda-entry-types
4080 (delq :deadline org-agenda-entry-types)))
4081 (cond
4082 ((memq org-agenda-show-log-scoped '(only clockcheck))
4083 (setq rtn (org-agenda-get-day-entries
4084 file date :closed)))
4085 (org-agenda-show-log-scoped
4086 (setq rtn (apply 'org-agenda-get-day-entries
4087 file date
4088 (append '(:closed) org-agenda-entry-types))))
4090 (setq rtn (apply 'org-agenda-get-day-entries
4091 file date
4092 org-agenda-entry-types)))))
4093 (setq rtnall (append rtnall rtn)))) ;; all entries
4094 (if org-agenda-include-diary
4095 (let ((org-agenda-search-headline-for-time t))
4096 (require 'diary-lib)
4097 (setq rtn (org-get-entries-from-diary date))
4098 (setq rtnall (append rtnall rtn))))
4099 (if (or rtnall org-agenda-show-all-dates)
4100 (progn
4101 (setq day-cnt (1+ day-cnt))
4102 (insert
4103 (if (stringp org-agenda-format-date)
4104 (format-time-string org-agenda-format-date
4105 (org-time-from-absolute date))
4106 (funcall org-agenda-format-date date))
4107 "\n")
4108 (put-text-property s (1- (point)) 'face
4109 (org-agenda-get-day-face date))
4110 (put-text-property s (1- (point)) 'org-date-line t)
4111 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4112 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4113 (when todayp
4114 (put-text-property s (1- (point)) 'org-today t))
4115 (setq rtnall
4116 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4117 (if rtnall (insert ;; all entries
4118 (org-agenda-finalize-entries rtnall)
4119 "\n"))
4120 (put-text-property s (1- (point)) 'day d)
4121 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4122 (when (and org-agenda-clockreport-mode clocktable-start)
4123 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4124 ;; the above line is to ensure the restricted range!
4125 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4126 tbl)
4127 (setq p (org-plist-delete p :block))
4128 (setq p (plist-put p :tstart clocktable-start))
4129 (setq p (plist-put p :tend clocktable-end))
4130 (setq p (plist-put p :scope 'agenda))
4131 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4132 (setq filter (or org-agenda-tag-filter-while-redo
4133 (get 'org-agenda-tag-filter :preset-filter))))
4134 (setq p (plist-put p :tags (mapconcat (lambda (x)
4135 (if (string-match "[<>=]" x)
4138 filter ""))))
4139 (setq tbl (apply 'org-clock-get-clocktable p))
4140 (insert tbl)))
4141 (goto-char (point-min))
4142 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4143 (unless (and (pos-visible-in-window-p (point-min))
4144 (pos-visible-in-window-p (point-max)))
4145 (goto-char (1- (point-max)))
4146 (recenter -1)
4147 (if (not (pos-visible-in-window-p (or start-pos 1)))
4148 (progn
4149 (goto-char (or start-pos 1))
4150 (recenter 1))))
4151 (goto-char (or start-pos 1))
4152 (add-text-properties (point-min) (point-max)
4153 `(org-agenda-type agenda
4154 org-last-args (,arg ,start-day ,span)
4155 org-redo-cmd ,org-agenda-redo-command
4156 org-series-cmd ,org-cmd))
4157 (if (eq org-agenda-show-log-scoped 'clockcheck)
4158 (org-agenda-show-clocking-issues))
4159 (org-agenda-finalize)
4160 (setq buffer-read-only t)
4161 (message ""))))
4163 (autoload 'org-agenda-list "org-agenda" "\
4164 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4165 The view will be for the current day or week, but from the overview buffer
4166 you will be able to go to other days/weeks.
4168 With a numeric prefix argument in an interactive call, the agenda will
4169 span ARG days. Lisp programs should instead specify SPAN to change
4170 the number of days. SPAN defaults to `org-agenda-span'.
4172 START-DAY defaults to TODAY, or to the most recent match for the weekday
4173 given in `org-agenda-start-on-weekday'.
4175 \(fn &optional ARG START-DAY SPAN)" t nil)
4177 (defun org-agenda-ndays-to-span (n)
4178 "Return a span symbol for a span of N days, or N if none matches."
4179 (cond ((symbolp n) n)
4180 ((= n 1) 'day)
4181 ((= n 7) 'week)
4182 (t n)))
4184 (defun org-agenda-span-to-ndays (span &optional start-day)
4185 "Return ndays from SPAN, possibly starting at START-DAY."
4186 (cond ((numberp span) span)
4187 ((eq span 'day) 1)
4188 ((eq span 'week) 7)
4189 ((eq span 'month)
4190 (let ((date (calendar-gregorian-from-absolute start-day)))
4191 (calendar-last-day-of-month (car date) (caddr date))))
4192 ((eq span 'year)
4193 (let ((date (calendar-gregorian-from-absolute start-day)))
4194 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4196 (defun org-agenda-span-name (span)
4197 "Return a SPAN name."
4198 (if (null span)
4200 (if (symbolp span)
4201 (capitalize (symbol-name span))
4202 (format "%d days" span))))
4204 ;;; Agenda word search
4206 (defvar org-agenda-search-history nil)
4208 (defvar org-search-syntax-table nil
4209 "Special syntax table for org-mode search.
4210 In this table, we have single quotes not as word constituents, to
4211 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4213 (defvar org-mode-syntax-table) ; From org.el
4214 (defun org-search-syntax-table ()
4215 (unless org-search-syntax-table
4216 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4217 (modify-syntax-entry ?' "." org-search-syntax-table)
4218 (modify-syntax-entry ?` "." org-search-syntax-table))
4219 org-search-syntax-table)
4221 (defvar org-agenda-last-search-view-search-was-boolean nil)
4223 ;;;###autoload
4224 (defun org-search-view (&optional todo-only string edit-at)
4225 "Show all entries that contain a phrase or words or regular expressions.
4227 With optional prefix argument TODO-ONLY, only consider entries that are
4228 TODO entries. The argument STRING can be used to pass a default search
4229 string into this function. If EDIT-AT is non-nil, it means that the
4230 user should get a chance to edit this string, with cursor at position
4231 EDIT-AT.
4233 The search string can be viewed either as a phrase that should be found as
4234 is, or it can be broken into a number of snippets, each of which must match
4235 in a Boolean way to select an entry. The default depends on the variable
4236 `org-agenda-search-view-always-boolean'.
4237 Even if this is turned off (the default) you can always switch to
4238 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4240 The default is a direct search of the whole phrase, where each space in
4241 the search string can expand to an arbitrary amount of whitespace,
4242 including newlines.
4244 If using a Boolean search, the search string is split on whitespace and
4245 each snippet is searched separately, with logical AND to select an entry.
4246 Words prefixed with a minus must *not* occur in the entry. Words without
4247 a prefix or prefixed with a plus must occur in the entry. Matching is
4248 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4249 match whole words, not parts of a word) if
4250 `org-agenda-search-view-force-full-words' is set (default is nil).
4252 Boolean search snippets enclosed by curly braces are interpreted as
4253 regular expressions that must or (when preceded with \"-\") must not
4254 match in the entry. Snippets enclosed into double quotes will be taken
4255 as a whole, to include whitespace.
4257 - If the search string starts with an asterisk, search only in headlines.
4258 - If (possibly after the leading star) the search string starts with an
4259 exclamation mark, this also means to look at TODO entries only, an effect
4260 that can also be achieved with a prefix argument.
4261 - If (possibly after star and exclamation mark) the search string starts
4262 with a colon, this will mean that the (non-regexp) snippets of the
4263 Boolean search must match as full words.
4265 This command searches the agenda files, and in addition the files listed
4266 in `org-agenda-text-search-extra-files'."
4267 (interactive "P")
4268 (if org-agenda-overriding-arguments
4269 (setq todo-only (car org-agenda-overriding-arguments)
4270 string (nth 1 org-agenda-overriding-arguments)
4271 edit-at (nth 2 org-agenda-overriding-arguments)))
4272 (let* ((props (list 'face nil
4273 'done-face 'org-agenda-done
4274 'org-not-done-regexp org-not-done-regexp
4275 'org-todo-regexp org-todo-regexp
4276 'org-complex-heading-regexp org-complex-heading-regexp
4277 'mouse-face 'highlight
4278 'help-echo (format "mouse-2 or RET jump to location")))
4279 (full-words org-agenda-search-view-force-full-words)
4280 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4281 regexp rtn rtnall files file pos
4282 marker category category-pos level tags c neg re boolean
4283 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4284 (unless (and (not edit-at)
4285 (stringp string)
4286 (string-match "\\S-" string))
4287 (setq string (read-string
4288 (if org-agenda-search-view-always-boolean
4289 "[+-]Word/{Regexp} ...: "
4290 "Phrase or [+-]Word/{Regexp} ...: ")
4291 (cond
4292 ((integerp edit-at) (cons string edit-at))
4293 (edit-at string))
4294 'org-agenda-search-history)))
4295 (catch 'exit
4296 (if org-agenda-sticky
4297 (setq org-agenda-buffer-name
4298 (if (stringp string)
4299 (format "*Org Agenda(%s:%s)*"
4300 (or org-keys (or (and todo-only "S") "s")) string)
4301 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4302 (org-agenda-prepare "SEARCH")
4303 (org-compile-prefix-format 'search)
4304 (org-set-sorting-strategy 'search)
4305 (setq org-agenda-redo-command
4306 (list 'org-search-view (if todo-only t nil)
4307 (list 'if 'current-prefix-arg nil string)))
4308 (setq org-agenda-query-string string)
4309 (if (equal (string-to-char string) ?*)
4310 (setq hdl-only t
4311 words (substring string 1))
4312 (setq words string))
4313 (when (equal (string-to-char words) ?!)
4314 (setq todo-only t
4315 words (substring words 1)))
4316 (when (equal (string-to-char words) ?:)
4317 (setq full-words t
4318 words (substring words 1)))
4319 (if (or org-agenda-search-view-always-boolean
4320 (member (string-to-char words) '(?- ?+ ?\{)))
4321 (setq boolean t))
4322 (setq words (org-split-string words))
4323 (let (www w)
4324 (while (setq w (pop words))
4325 (while (and (string-match "\\\\\\'" w) words)
4326 (setq w (concat (substring w 0 -1) " " (pop words))))
4327 (push w www))
4328 (setq words (nreverse www) www nil)
4329 (while (setq w (pop words))
4330 (when (and (string-match "\\`[-+]?{" w)
4331 (not (string-match "}\\'" w)))
4332 (while (and words (not (string-match "}\\'" (car words))))
4333 (setq w (concat w " " (pop words))))
4334 (setq w (concat w " " (pop words))))
4335 (push w www))
4336 (setq words (nreverse www)))
4337 (setq org-agenda-last-search-view-search-was-boolean boolean)
4338 (when boolean
4339 (let (wds w)
4340 (while (setq w (pop words))
4341 (if (or (equal (substring w 0 1) "\"")
4342 (and (> (length w) 1)
4343 (member (substring w 0 1) '("+" "-"))
4344 (equal (substring w 1 2) "\"")))
4345 (while (and words (not (equal (substring w -1) "\"")))
4346 (setq w (concat w " " (pop words)))))
4347 (and (string-match "\\`\\([-+]?\\)\"" w)
4348 (setq w (replace-match "\\1" nil nil w)))
4349 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4350 (push w wds))
4351 (setq words (nreverse wds))))
4352 (if boolean
4353 (mapc (lambda (w)
4354 (setq c (string-to-char w))
4355 (if (equal c ?-)
4356 (setq neg t w (substring w 1))
4357 (if (equal c ?+)
4358 (setq neg nil w (substring w 1))
4359 (setq neg nil)))
4360 (if (string-match "\\`{.*}\\'" w)
4361 (setq re (substring w 1 -1))
4362 (if full-words
4363 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4364 (setq re (regexp-quote (downcase w)))))
4365 (if neg (push re regexps-) (push re regexps+)))
4366 words)
4367 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4368 regexps+))
4369 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4370 (if (not regexps+)
4371 (setq regexp org-outline-regexp-bol)
4372 (setq regexp (pop regexps+))
4373 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4374 regexp))))
4375 (setq files (org-agenda-files nil 'ifmode))
4376 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4377 (pop org-agenda-text-search-extra-files)
4378 (setq files (org-add-archive-files files)))
4379 (setq files (append files org-agenda-text-search-extra-files)
4380 rtnall nil)
4381 (while (setq file (pop files))
4382 (setq ee nil)
4383 (catch 'nextfile
4384 (org-check-agenda-file file)
4385 (setq buffer (if (file-exists-p file)
4386 (org-get-agenda-file-buffer file)
4387 (error "No such file %s" file)))
4388 (if (not buffer)
4389 ;; If file does not exist, make sure an error message is sent
4390 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4391 file))))
4392 (with-current-buffer buffer
4393 (with-syntax-table (org-search-syntax-table)
4394 (unless (derived-mode-p 'org-mode)
4395 (error "Agenda file %s is not in `org-mode'" file))
4396 (let ((case-fold-search t))
4397 (save-excursion
4398 (save-restriction
4399 (if org-agenda-restrict
4400 (narrow-to-region org-agenda-restrict-begin
4401 org-agenda-restrict-end)
4402 (widen))
4403 (goto-char (point-min))
4404 (unless (or (org-at-heading-p)
4405 (outline-next-heading))
4406 (throw 'nextfile t))
4407 (goto-char (max (point-min) (1- (point))))
4408 (while (re-search-forward regexp nil t)
4409 (org-back-to-heading t)
4410 (while (and org-agenda-search-view-max-outline-level
4411 (> (org-reduced-level (org-outline-level))
4412 org-agenda-search-view-max-outline-level)
4413 (forward-line -1)
4414 (outline-back-to-heading t)))
4415 (skip-chars-forward "* ")
4416 (setq beg (point-at-bol)
4417 beg1 (point)
4418 end (progn
4419 (outline-next-heading)
4420 (while (and org-agenda-search-view-max-outline-level
4421 (> (org-reduced-level (org-outline-level))
4422 org-agenda-search-view-max-outline-level)
4423 (forward-line 1)
4424 (outline-next-heading)))
4425 (point)))
4427 (catch :skip
4428 (goto-char beg)
4429 (org-agenda-skip)
4430 (setq str (buffer-substring-no-properties
4431 (point-at-bol)
4432 (if hdl-only (point-at-eol) end)))
4433 (mapc (lambda (wr) (when (string-match wr str)
4434 (goto-char (1- end))
4435 (throw :skip t)))
4436 regexps-)
4437 (mapc (lambda (wr) (unless (string-match wr str)
4438 (goto-char (1- end))
4439 (throw :skip t)))
4440 (if todo-only
4441 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4442 regexps+)
4443 regexps+))
4444 (goto-char beg)
4445 (setq marker (org-agenda-new-marker (point))
4446 category (org-get-category)
4447 level (make-string (org-reduced-level (org-outline-level)) ? )
4448 category-pos (get-text-property (point) 'org-category-position)
4449 tags (org-get-tags-at (point))
4450 txt (org-agenda-format-item
4452 (buffer-substring-no-properties
4453 beg1 (point-at-eol))
4454 level category tags t))
4455 (org-add-props txt props
4456 'org-marker marker 'org-hd-marker marker
4457 'org-todo-regexp org-todo-regexp
4458 'level level
4459 'org-complex-heading-regexp org-complex-heading-regexp
4460 'priority 1000 'org-category category
4461 'org-category-position category-pos
4462 'type "search")
4463 (push txt ee)
4464 (goto-char (1- end))))))))))
4465 (setq rtn (nreverse ee))
4466 (setq rtnall (append rtnall rtn)))
4467 (if org-agenda-overriding-header
4468 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4469 nil 'face 'org-agenda-structure) "\n")
4470 (insert "Search words: ")
4471 (add-text-properties (point-min) (1- (point))
4472 (list 'face 'org-agenda-structure))
4473 (setq pos (point))
4474 (insert string "\n")
4475 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4476 (setq pos (point))
4477 (unless org-agenda-multi
4478 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4479 (add-text-properties pos (1- (point))
4480 (list 'face 'org-agenda-structure))))
4481 (org-agenda-mark-header-line (point-min))
4482 (when rtnall
4483 (insert (org-agenda-finalize-entries rtnall) "\n"))
4484 (goto-char (point-min))
4485 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4486 (add-text-properties (point-min) (point-max)
4487 `(org-agenda-type search
4488 org-last-args (,todo-only ,string ,edit-at)
4489 org-redo-cmd ,org-agenda-redo-command
4490 org-series-cmd ,org-cmd))
4491 (org-agenda-finalize)
4492 (setq buffer-read-only t))))
4494 (autoload 'org-search-view "org-agenda" "\
4495 Show all entries that contain a phrase or words or regular expressions.
4497 With optional prefix argument TODO-ONLY, only consider entries that are
4498 TODO entries. The argument STRING can be used to pass a default search
4499 string into this function. If EDIT-AT is non-nil, it means that the
4500 user should get a chance to edit this string, with cursor at position
4501 EDIT-AT.
4503 The search string can be viewed either as a phrase that should be found as
4504 is, or it can be broken into a number of snippets, each of which must match
4505 in a Boolean way to select an entry. The default depends on the variable
4506 `org-agenda-search-view-always-boolean'.
4507 Even if this is turned off (the default) you can always switch to
4508 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4510 The default is a direct search of the whole phrase, where each space in
4511 the search string can expand to an arbitrary amount of whitespace,
4512 including newlines.
4514 If using a Boolean search, the search string is split on whitespace and
4515 each snippet is searched separately, with logical AND to select an entry.
4516 Words prefixed with a minus must *not* occur in the entry. Words without
4517 a prefix or prefixed with a plus must occur in the entry. Matching is
4518 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4519 match whole words, not parts of a word) if
4520 `org-agenda-search-view-force-full-words' is set (default is nil).
4522 Boolean search snippets enclosed by curly braces are interpreted as
4523 regular expressions that must or (when preceded with \"-\") must not
4524 match in the entry. Snippets enclosed into double quotes will be taken
4525 as a whole, to include whitespace.
4527 - If the search string starts with an asterisk, search only in headlines.
4528 - If (possibly after the leading star) the search string starts with an
4529 exclamation mark, this also means to look at TODO entries only, an effect
4530 that can also be achieved with a prefix argument.
4531 - If (possibly after star and exclamation mark) the search string starts
4532 with a colon, this will mean that the (non-regexp) snippets of the
4533 Boolean search must match as full words.
4535 This command searches the agenda files, and in addition the files listed
4536 in `org-agenda-text-search-extra-files'.
4538 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4540 ;;; Agenda TODO list
4542 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4543 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4544 (concat
4545 (if (or (equal keywords "ALL") (not keywords))
4546 (propertize "ALL" 'face 'warning)
4547 (mapconcat
4548 (lambda (kw)
4549 (propertize kw 'face (org-get-todo-face kw)))
4550 (org-split-string keywords "|")
4551 "|"))
4552 "\n"))
4554 (defvar org-select-this-todo-keyword nil)
4555 (defvar org-last-arg nil)
4557 ;;;###autoload
4558 (defun org-todo-list (&optional arg)
4559 "Show all (not done) TODO entries from all agenda file in a single list.
4560 The prefix arg can be used to select a specific TODO keyword and limit
4561 the list to these. When using \\[universal-argument], you will be prompted
4562 for a keyword. A numeric prefix directly selects the Nth keyword in
4563 `org-todo-keywords-1'."
4564 (interactive "P")
4565 (if org-agenda-overriding-arguments
4566 (setq arg org-agenda-overriding-arguments))
4567 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4568 (let* ((today (org-today))
4569 (date (calendar-gregorian-from-absolute today))
4570 (kwds org-todo-keywords-for-agenda)
4571 (completion-ignore-case t)
4572 (org-select-this-todo-keyword
4573 (if (stringp arg) arg
4574 (and arg (integerp arg) (> arg 0)
4575 (nth (1- arg) kwds))))
4576 rtn rtnall files file pos)
4577 (when (equal arg '(4))
4578 (setq org-select-this-todo-keyword
4579 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4580 (mapcar 'list kwds) nil nil)))
4581 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4582 (catch 'exit
4583 (if org-agenda-sticky
4584 (setq org-agenda-buffer-name
4585 (if (stringp org-select-this-todo-keyword)
4586 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4587 org-select-this-todo-keyword)
4588 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4589 (org-agenda-prepare "TODO")
4590 (org-compile-prefix-format 'todo)
4591 (org-set-sorting-strategy 'todo)
4592 (setq org-agenda-redo-command
4593 `(org-todo-list (or (and (numberp current-prefix-arg)
4594 current-prefix-arg)
4595 ,org-select-this-todo-keyword
4596 current-prefix-arg ,arg)))
4597 (setq files (org-agenda-files nil 'ifmode)
4598 rtnall nil)
4599 (while (setq file (pop files))
4600 (catch 'nextfile
4601 (org-check-agenda-file file)
4602 (setq rtn (org-agenda-get-day-entries file date :todo))
4603 (setq rtnall (append rtnall rtn))))
4604 (if org-agenda-overriding-header
4605 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4606 nil 'face 'org-agenda-structure) "\n")
4607 (insert "Global list of TODO items of type: ")
4608 (add-text-properties (point-min) (1- (point))
4609 (list 'face 'org-agenda-structure
4610 'short-heading
4611 (concat "ToDo: "
4612 (or org-select-this-todo-keyword "ALL"))))
4613 (org-agenda-mark-header-line (point-min))
4614 (insert (org-agenda-propertize-selected-todo-keywords
4615 org-select-this-todo-keyword))
4616 (setq pos (point))
4617 (unless org-agenda-multi
4618 (insert "Available with `N r': (0)[ALL]")
4619 (let ((n 0) s)
4620 (mapc (lambda (x)
4621 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4622 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4623 (insert "\n "))
4624 (insert " " s))
4625 kwds))
4626 (insert "\n"))
4627 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4628 (org-agenda-mark-header-line (point-min))
4629 (when rtnall
4630 (insert (org-agenda-finalize-entries rtnall) "\n"))
4631 (goto-char (point-min))
4632 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4633 (add-text-properties (point-min) (point-max)
4634 `(org-agenda-type todo
4635 org-last-args ,arg
4636 org-redo-cmd ,org-agenda-redo-command
4637 org-series-cmd ,org-cmd))
4638 (org-agenda-finalize)
4639 (setq buffer-read-only t))))
4641 (autoload 'org-todo-list "org-agenda" "\
4642 Show all (not done) TODO entries from all agenda file in a single list.
4643 The prefix arg can be used to select a specific TODO keyword and limit
4644 the list to these. When using \\[universal-argument], you will be prompted
4645 for a keyword. A numeric prefix directly selects the Nth keyword in
4646 `org-todo-keywords-1'.
4648 \(fn &optional ARG)" t nil)
4650 ;;; Agenda tags match
4652 ;;;###autoload
4653 (defun org-tags-view (&optional todo-only match)
4654 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4655 The prefix arg TODO-ONLY limits the search to TODO entries."
4656 (interactive "P")
4657 (if org-agenda-overriding-arguments
4658 (setq todo-only (car org-agenda-overriding-arguments)
4659 match (nth 1 org-agenda-overriding-arguments)))
4660 (let* ((org-tags-match-list-sublevels
4661 org-tags-match-list-sublevels)
4662 (completion-ignore-case t)
4663 rtn rtnall files file pos matcher
4664 buffer)
4665 (when (and (stringp match) (not (string-match "\\S-" match)))
4666 (setq match nil))
4667 (setq matcher (org-make-tags-matcher match)
4668 match (car matcher) matcher (cdr matcher))
4669 (catch 'exit
4670 (if org-agenda-sticky
4671 (setq org-agenda-buffer-name
4672 (if (stringp match)
4673 (format "*Org Agenda(%s:%s)*"
4674 (or org-keys (or (and todo-only "M") "m")) match)
4675 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4676 (org-agenda-prepare (concat "TAGS " match))
4677 (org-compile-prefix-format 'tags)
4678 (org-set-sorting-strategy 'tags)
4679 (setq org-agenda-query-string match)
4680 (setq org-agenda-redo-command
4681 (list 'org-tags-view `(quote ,todo-only)
4682 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4683 (setq files (org-agenda-files nil 'ifmode)
4684 rtnall nil)
4685 (while (setq file (pop files))
4686 (catch 'nextfile
4687 (org-check-agenda-file file)
4688 (setq buffer (if (file-exists-p file)
4689 (org-get-agenda-file-buffer file)
4690 (error "No such file %s" file)))
4691 (if (not buffer)
4692 ;; If file does not exist, error message to agenda
4693 (setq rtn (list
4694 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4695 rtnall (append rtnall rtn))
4696 (with-current-buffer buffer
4697 (unless (derived-mode-p 'org-mode)
4698 (error "Agenda file %s is not in `org-mode'" file))
4699 (save-excursion
4700 (save-restriction
4701 (if org-agenda-restrict
4702 (narrow-to-region org-agenda-restrict-begin
4703 org-agenda-restrict-end)
4704 (widen))
4705 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4706 (setq rtnall (append rtnall rtn))))))))
4707 (if org-agenda-overriding-header
4708 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4709 nil 'face 'org-agenda-structure) "\n")
4710 (insert "Headlines with TAGS match: ")
4711 (add-text-properties (point-min) (1- (point))
4712 (list 'face 'org-agenda-structure
4713 'short-heading
4714 (concat "Match: " match)))
4715 (setq pos (point))
4716 (insert match "\n")
4717 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4718 (setq pos (point))
4719 (unless org-agenda-multi
4720 (insert "Press `C-u r' to search again with new search string\n"))
4721 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4722 (org-agenda-mark-header-line (point-min))
4723 (when rtnall
4724 (insert (org-agenda-finalize-entries rtnall) "\n"))
4725 (goto-char (point-min))
4726 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4727 (add-text-properties (point-min) (point-max)
4728 `(org-agenda-type tags
4729 org-last-args (,todo-only ,match)
4730 org-redo-cmd ,org-agenda-redo-command
4731 org-series-cmd ,org-cmd))
4732 (org-agenda-finalize)
4733 (setq buffer-read-only t))))
4735 (autoload 'org-tags-view "org-agenda" "\
4736 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4737 The prefix arg TODO-ONLY limits the search to TODO entries.
4739 \(fn &optional TODO-ONLY MATCH)" t nil)
4741 ;;; Agenda Finding stuck projects
4743 (defvar org-agenda-skip-regexp nil
4744 "Regular expression used in skipping subtrees for the agenda.
4745 This is basically a temporary global variable that can be set and then
4746 used by user-defined selections using `org-agenda-skip-function'.")
4748 (defvar org-agenda-overriding-header nil
4749 "When set during agenda, todo and tags searches it replaces the header.
4750 This variable should not be set directly, but custom commands can bind it
4751 in the options section.")
4753 (defun org-agenda-skip-entry-when-regexp-matches ()
4754 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4755 If yes, it returns the end position of this entry, causing agenda commands
4756 to skip the entry but continuing the search in the subtree. This is a
4757 function that can be put into `org-agenda-skip-function' for the duration
4758 of a command."
4759 (let ((end (save-excursion (org-end-of-subtree t)))
4760 skip)
4761 (save-excursion
4762 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4763 (and skip end)))
4765 (defun org-agenda-skip-subtree-when-regexp-matches ()
4766 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4767 If yes, it returns the end position of this tree, causing agenda commands
4768 to skip this subtree. This is a function that can be put into
4769 `org-agenda-skip-function' for the duration of a command."
4770 (let ((end (save-excursion (org-end-of-subtree t)))
4771 skip)
4772 (save-excursion
4773 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4774 (and skip end)))
4776 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4777 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4778 If yes, it returns the end position of the current entry (NOT the tree),
4779 causing agenda commands to skip the entry but continuing the search in
4780 the subtree. This is a function that can be put into
4781 `org-agenda-skip-function' for the duration of a command. An important
4782 use of this function is for the stuck project list."
4783 (let ((end (save-excursion (org-end-of-subtree t)))
4784 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4785 skip)
4786 (save-excursion
4787 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4788 (and skip entry-end)))
4790 (defun org-agenda-skip-entry-if (&rest conditions)
4791 "Skip entry if any of CONDITIONS is true.
4792 See `org-agenda-skip-if' for details."
4793 (org-agenda-skip-if nil conditions))
4795 (defun org-agenda-skip-subtree-if (&rest conditions)
4796 "Skip entry if any of CONDITIONS is true.
4797 See `org-agenda-skip-if' for details."
4798 (org-agenda-skip-if t conditions))
4800 (defun org-agenda-skip-if (subtree conditions)
4801 "Checks current entity for CONDITIONS.
4802 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4803 the entry (i.e. the text before the next heading) is checked.
4805 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4806 from different tests. Valid conditions are:
4808 scheduled Check if there is a scheduled cookie
4809 notscheduled Check if there is no scheduled cookie
4810 deadline Check if there is a deadline
4811 notdeadline Check if there is no deadline
4812 timestamp Check if there is a timestamp (also deadline or scheduled)
4813 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4814 regexp Check if regexp matches
4815 notregexp Check if regexp does not match.
4816 todo Check if TODO keyword matches
4817 nottodo Check if TODO keyword does not match
4819 The regexp is taken from the conditions list, it must come right after
4820 the `regexp' or `notregexp' element.
4822 `todo' and `nottodo' accept as an argument a list of todo
4823 keywords, which may include \"*\" to match any todo keyword.
4825 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4827 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4829 Instead of a list, a keyword class may be given. For example:
4831 (org-agenda-skip-entry-if 'nottodo 'done)
4833 would skip entries that haven't been marked with any of \"DONE\"
4834 keywords. Possible classes are: `todo', `done', `any'.
4836 If any of these conditions is met, this function returns the end point of
4837 the entity, causing the search to continue from there. This is a function
4838 that can be put into `org-agenda-skip-function' for the duration of a command."
4839 (let (beg end m)
4840 (org-back-to-heading t)
4841 (setq beg (point)
4842 end (if subtree
4843 (progn (org-end-of-subtree t) (point))
4844 (progn (outline-next-heading) (1- (point)))))
4845 (goto-char beg)
4846 (and
4848 (and (memq 'scheduled conditions)
4849 (re-search-forward org-scheduled-time-regexp end t))
4850 (and (memq 'notscheduled conditions)
4851 (not (re-search-forward org-scheduled-time-regexp end t)))
4852 (and (memq 'deadline conditions)
4853 (re-search-forward org-deadline-time-regexp end t))
4854 (and (memq 'notdeadline conditions)
4855 (not (re-search-forward org-deadline-time-regexp end t)))
4856 (and (memq 'timestamp conditions)
4857 (re-search-forward org-ts-regexp end t))
4858 (and (memq 'nottimestamp conditions)
4859 (not (re-search-forward org-ts-regexp end t)))
4860 (and (setq m (memq 'regexp conditions))
4861 (stringp (nth 1 m))
4862 (re-search-forward (nth 1 m) end t))
4863 (and (setq m (memq 'notregexp conditions))
4864 (stringp (nth 1 m))
4865 (not (re-search-forward (nth 1 m) end t)))
4866 (and (or
4867 (setq m (memq 'nottodo conditions))
4868 (setq m (memq 'todo-unblocked conditions))
4869 (setq m (memq 'nottodo-unblocked conditions))
4870 (setq m (memq 'todo conditions)))
4871 (org-agenda-skip-if-todo m end)))
4872 end)))
4874 (defun org-agenda-skip-if-todo (args end)
4875 "Helper function for `org-agenda-skip-if', do not use it directly.
4876 ARGS is a list with first element either `todo', `nottodo',
4877 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4878 a list of TODO keywords, or a state symbol `todo' or `done' or
4879 `any'."
4880 (let ((kw (car args))
4881 (arg (cadr args))
4882 todo-wds todo-re)
4883 (setq todo-wds
4884 (org-uniquify
4885 (cond
4886 ((listp arg) ;; list of keywords
4887 (if (member "*" arg)
4888 (mapcar 'substring-no-properties org-todo-keywords-1)
4889 arg))
4890 ((symbolp arg) ;; keyword class name
4891 (cond
4892 ((eq arg 'todo)
4893 (org-delete-all org-done-keywords
4894 (mapcar 'substring-no-properties
4895 org-todo-keywords-1)))
4896 ((eq arg 'done) org-done-keywords)
4897 ((eq arg 'any)
4898 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4899 (setq todo-re
4900 (concat "^\\*+[ \t]+\\<\\("
4901 (mapconcat 'identity todo-wds "\\|")
4902 "\\)\\>"))
4903 (cond
4904 ((eq kw 'todo) (re-search-forward todo-re end t))
4905 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4906 ((eq kw 'todo-unblocked)
4907 (catch 'unblocked
4908 (while (re-search-forward todo-re end t)
4909 (or (org-entry-blocked-p) (throw 'unblocked t)))
4910 nil))
4911 ((eq kw 'nottodo-unblocked)
4912 (catch 'unblocked
4913 (while (re-search-forward todo-re end t)
4914 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4918 ;;;###autoload
4919 (defun org-agenda-list-stuck-projects (&rest ignore)
4920 "Create agenda view for projects that are stuck.
4921 Stuck projects are project that have no next actions. For the definitions
4922 of what a project is and how to check if it stuck, customize the variable
4923 `org-stuck-projects'."
4924 (interactive)
4925 (let* ((org-agenda-skip-function
4926 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4927 ;; We could have used org-agenda-skip-if here.
4928 (org-agenda-overriding-header
4929 (or org-agenda-overriding-header "List of stuck projects: "))
4930 (matcher (nth 0 org-stuck-projects))
4931 (todo (nth 1 org-stuck-projects))
4932 (todo-wds (if (member "*" todo)
4933 (progn
4934 (org-agenda-prepare-buffers (org-agenda-files
4935 nil 'ifmode))
4936 (org-delete-all
4937 org-done-keywords-for-agenda
4938 (copy-sequence org-todo-keywords-for-agenda)))
4939 todo))
4940 (todo-re (concat "^\\*+[ \t]+\\("
4941 (mapconcat 'identity todo-wds "\\|")
4942 "\\)\\>"))
4943 (tags (nth 2 org-stuck-projects))
4944 (tags-re (if (member "*" tags)
4945 (concat org-outline-regexp-bol
4946 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4947 (if tags
4948 (concat org-outline-regexp-bol
4949 ".*:\\("
4950 (mapconcat 'identity tags "\\|")
4951 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4952 (gen-re (nth 3 org-stuck-projects))
4953 (re-list
4954 (delq nil
4955 (list
4956 (if todo todo-re)
4957 (if tags tags-re)
4958 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4959 gen-re)))))
4960 (setq org-agenda-skip-regexp
4961 (if re-list
4962 (mapconcat 'identity re-list "\\|")
4963 (error "No information how to identify unstuck projects")))
4964 (org-tags-view nil matcher)
4965 (with-current-buffer org-agenda-buffer-name
4966 (setq org-agenda-redo-command
4967 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4969 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4970 Create agenda view for projects that are stuck.
4971 Stuck projects are project that have no next actions. For the definitions
4972 of what a project is and how to check if it stuck, customize the variable
4973 `org-stuck-projects'.
4975 \(fn &rest IGNORE)" t nil)
4977 ;;; Diary integration
4979 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4980 (defvar diary-list-entries-hook)
4981 (defvar diary-time-regexp)
4982 (defun org-get-entries-from-diary (date)
4983 "Get the (Emacs Calendar) diary entries for DATE."
4984 (require 'diary-lib)
4985 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4986 (diary-display-hook '(fancy-diary-display))
4987 (diary-display-function 'fancy-diary-display)
4988 (pop-up-frames nil)
4989 (diary-list-entries-hook
4990 (cons 'org-diary-default-entry diary-list-entries-hook))
4991 (diary-file-name-prefix-function nil) ; turn this feature off
4992 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4993 entries
4994 (org-disable-agenda-to-diary t))
4995 (save-excursion
4996 (save-window-excursion
4997 (funcall (if (fboundp 'diary-list-entries)
4998 'diary-list-entries 'list-diary-entries)
4999 date 1)))
5000 (if (not (get-buffer diary-fancy-buffer))
5001 (setq entries nil)
5002 (with-current-buffer diary-fancy-buffer
5003 (setq buffer-read-only nil)
5004 (if (zerop (buffer-size))
5005 ;; No entries
5006 (setq entries nil)
5007 ;; Omit the date and other unnecessary stuff
5008 (org-agenda-cleanup-fancy-diary)
5009 ;; Add prefix to each line and extend the text properties
5010 (if (zerop (buffer-size))
5011 (setq entries nil)
5012 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5013 (setq entries
5014 (with-temp-buffer
5015 (insert entries) (goto-char (point-min))
5016 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5017 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5018 (replace-match (concat "; " (match-string 1)))))
5019 (buffer-string)))))
5020 (set-buffer-modified-p nil)
5021 (kill-buffer diary-fancy-buffer)))
5022 (when entries
5023 (setq entries (org-split-string entries "\n"))
5024 (setq entries
5025 (mapcar
5026 (lambda (x)
5027 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5028 ;; Extend the text properties to the beginning of the line
5029 (org-add-props x (text-properties-at (1- (length x)) x)
5030 'type "diary" 'date date 'face 'org-agenda-diary))
5031 entries)))))
5033 (defvar org-agenda-cleanup-fancy-diary-hook nil
5034 "Hook run when the fancy diary buffer is cleaned up.")
5036 (defun org-agenda-cleanup-fancy-diary ()
5037 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5038 This gets rid of the date, the underline under the date, and
5039 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5040 date. It also removes lines that contain only whitespace."
5041 (goto-char (point-min))
5042 (if (looking-at ".*?:[ \t]*")
5043 (progn
5044 (replace-match "")
5045 (re-search-forward "\n=+$" nil t)
5046 (replace-match "")
5047 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5048 (re-search-forward "\n=+$" nil t)
5049 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5050 (goto-char (point-min))
5051 (while (re-search-forward "^ +\n" nil t)
5052 (replace-match ""))
5053 (goto-char (point-min))
5054 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5055 (replace-match ""))
5056 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5058 ;; Make sure entries from the diary have the right text properties.
5059 (eval-after-load "diary-lib"
5060 '(if (boundp 'diary-modify-entry-list-string-function)
5061 ;; We can rely on the hook, nothing to do
5063 ;; Hook not available, must use advice to make this work
5064 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5065 "Make the position visible."
5066 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5067 (stringp string)
5068 buffer-file-name)
5069 (setq string (org-modify-diary-entry-string string))))))
5071 (defun org-modify-diary-entry-string (string)
5072 "Add text properties to string, allowing org-mode to act on it."
5073 (org-add-props string nil
5074 'mouse-face 'highlight
5075 'help-echo (if buffer-file-name
5076 (format "mouse-2 or RET jump to diary file %s"
5077 (abbreviate-file-name buffer-file-name))
5079 'org-agenda-diary-link t
5080 'org-marker (org-agenda-new-marker (point-at-bol))))
5082 (defun org-diary-default-entry ()
5083 "Add a dummy entry to the diary.
5084 Needed to avoid empty dates which mess up holiday display."
5085 ;; Catch the error if dealing with the new add-to-diary-alist
5086 (when org-disable-agenda-to-diary
5087 (condition-case nil
5088 (org-add-to-diary-list original-date "Org-mode dummy" "")
5089 (error
5090 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5092 (defun org-add-to-diary-list (&rest args)
5093 (if (fboundp 'diary-add-to-list)
5094 (apply 'diary-add-to-list args)
5095 (apply 'add-to-diary-list args)))
5097 (defvar org-diary-last-run-time nil)
5099 ;;;###autoload
5100 (defun org-diary (&rest args)
5101 "Return diary information from org files.
5102 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5103 It accesses org files and extracts information from those files to be
5104 listed in the diary. The function accepts arguments specifying what
5105 items should be listed. For a list of arguments allowed here, see the
5106 variable `org-agenda-entry-types'.
5108 The call in the diary file should look like this:
5110 &%%(org-diary) ~/path/to/some/orgfile.org
5112 Use a separate line for each org file to check. Or, if you omit the file name,
5113 all files listed in `org-agenda-files' will be checked automatically:
5115 &%%(org-diary)
5117 If you don't give any arguments (as in the example above), the default
5118 arguments (:deadline :scheduled :timestamp :sexp) are used.
5119 So the example above may also be written as
5121 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5123 The function expects the lisp variables `entry' and `date' to be provided
5124 by the caller, because this is how the calendar works. Don't use this
5125 function from a program - use `org-agenda-get-day-entries' instead."
5126 (when (> (- (org-float-time)
5127 org-agenda-last-marker-time)
5129 ;; I am not sure if this works with sticky agendas, because the marker
5130 ;; list is then no longer a global variable.
5131 (org-agenda-reset-markers))
5132 (org-compile-prefix-format 'agenda)
5133 (org-set-sorting-strategy 'agenda)
5134 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5135 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5136 (list entry)
5137 (org-agenda-files t)))
5138 (time (org-float-time))
5139 file rtn results)
5140 (when (or (not org-diary-last-run-time)
5141 (> (- time
5142 org-diary-last-run-time)
5144 (org-agenda-prepare-buffers files))
5145 (setq org-diary-last-run-time time)
5146 ;; If this is called during org-agenda, don't return any entries to
5147 ;; the calendar. Org Agenda will list these entries itself.
5148 (if org-disable-agenda-to-diary (setq files nil))
5149 (while (setq file (pop files))
5150 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5151 (setq results (append results rtn)))
5152 (if results
5153 (concat (org-agenda-finalize-entries results) "\n"))))
5155 (autoload 'org-diary "org-agenda" "\
5156 Return diary information from org files.
5157 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5158 It accesses org files and extracts information from those files to be
5159 listed in the diary. The function accepts arguments specifying what
5160 items should be listed. For a list of arguments allowed here, see the
5161 variable `org-agenda-entry-types'.
5163 The call in the diary file should look like this:
5165 &%%(org-diary) ~/path/to/some/orgfile.org
5167 Use a separate line for each org file to check. Or, if you omit the file name,
5168 all files listed in `org-agenda-files' will be checked automatically:
5170 &%%(org-diary)
5172 If you don't give any arguments (as in the example above), the default
5173 arguments (:deadline :scheduled :timestamp :sexp) are used.
5174 So the example above may also be written as
5176 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5178 The function expects the lisp variables `entry' and `date' to be provided
5179 by the caller, because this is how the calendar works. Don't use this
5180 function from a program - use `org-agenda-get-day-entries' instead.
5182 \(fn &rest ARGS)" nil nil)
5184 ;;; Agenda entry finders
5186 (defun org-agenda-get-day-entries (file date &rest args)
5187 "Does the work for `org-diary' and `org-agenda'.
5188 FILE is the path to a file to be checked for entries. DATE is date like
5189 the one returned by `calendar-current-date'. ARGS are symbols indicating
5190 which kind of entries should be extracted. For details about these, see
5191 the documentation of `org-diary'."
5192 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5193 (let* ((org-startup-folded nil)
5194 (org-startup-align-all-tables nil)
5195 (buffer (if (file-exists-p file)
5196 (org-get-agenda-file-buffer file)
5197 (error "No such file %s" file)))
5198 arg results rtn deadline-results)
5199 (if (not buffer)
5200 ;; If file does not exist, make sure an error message ends up in diary
5201 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5202 (with-current-buffer buffer
5203 (unless (derived-mode-p 'org-mode)
5204 (error "Agenda file %s is not in `org-mode'" file))
5205 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5206 (let ((case-fold-search nil))
5207 (save-excursion
5208 (save-restriction
5209 (if org-agenda-restrict
5210 (narrow-to-region org-agenda-restrict-begin
5211 org-agenda-restrict-end)
5212 (widen))
5213 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5214 (while (setq arg (pop args))
5215 (cond
5216 ((and (eq arg :todo)
5217 (equal date (calendar-gregorian-from-absolute
5218 (org-today))))
5219 (setq rtn (org-agenda-get-todos))
5220 (setq results (append results rtn)))
5221 ((eq arg :timestamp)
5222 (setq rtn (org-agenda-get-blocks))
5223 (setq results (append results rtn))
5224 (setq rtn (org-agenda-get-timestamps deadline-results))
5225 (setq results (append results rtn)))
5226 ((eq arg :sexp)
5227 (setq rtn (org-agenda-get-sexps))
5228 (setq results (append results rtn)))
5229 ((eq arg :scheduled)
5230 (setq rtn (org-agenda-get-scheduled deadline-results))
5231 (setq results (append results rtn)))
5232 ((eq arg :closed)
5233 (setq rtn (org-agenda-get-progress))
5234 (setq results (append results rtn)))
5235 ((eq arg :deadline)
5236 (setq rtn (org-agenda-get-deadlines))
5237 (setq deadline-results (copy-sequence rtn))
5238 (setq results (append results rtn))))))))
5239 results))))
5241 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5242 (defun org-agenda-get-todos ()
5243 "Return the TODO information for agenda display."
5244 (let* ((props (list 'face nil
5245 'done-face 'org-agenda-done
5246 'org-not-done-regexp org-not-done-regexp
5247 'org-todo-regexp org-todo-regexp
5248 'org-complex-heading-regexp org-complex-heading-regexp
5249 'mouse-face 'highlight
5250 'help-echo
5251 (format "mouse-2 or RET jump to org file %s"
5252 (abbreviate-file-name buffer-file-name))))
5253 (regexp (format org-heading-keyword-regexp-format
5254 (cond
5255 ((and org-select-this-todo-keyword
5256 (equal org-select-this-todo-keyword "*"))
5257 org-todo-regexp)
5258 (org-select-this-todo-keyword
5259 (concat "\\("
5260 (mapconcat 'identity
5261 (org-split-string
5262 org-select-this-todo-keyword
5263 "|")
5264 "\\|") "\\)"))
5265 (t org-not-done-regexp))))
5266 marker priority category category-pos level tags todo-state
5267 ee txt beg end)
5268 (goto-char (point-min))
5269 (while (re-search-forward regexp nil t)
5270 (catch :skip
5271 (save-match-data
5272 (beginning-of-line)
5273 (org-agenda-skip)
5274 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5275 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5276 (goto-char (1+ beg))
5277 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5278 (throw :skip nil)))
5279 (goto-char (match-beginning 2))
5280 (setq marker (org-agenda-new-marker (match-beginning 0))
5281 category (org-get-category)
5282 category-pos (get-text-property (point) 'org-category-position)
5283 txt (org-trim
5284 (buffer-substring (match-beginning 2) (match-end 0)))
5285 tags (org-get-tags-at (point))
5286 level (make-string (org-reduced-level (org-outline-level)) ? )
5287 txt (org-agenda-format-item "" txt level category tags t)
5288 priority (1+ (org-get-priority txt))
5289 todo-state (org-get-todo-state))
5290 (org-add-props txt props
5291 'org-marker marker 'org-hd-marker marker
5292 'priority priority 'org-category category
5293 'level level
5294 'org-category-position category-pos
5295 'type "todo" 'todo-state todo-state)
5296 (push txt ee)
5297 (if org-agenda-todo-list-sublevels
5298 (goto-char (match-end 2))
5299 (org-end-of-subtree 'invisible))))
5300 (nreverse ee)))
5302 (defun org-agenda-todo-custom-ignore-p (time n)
5303 "Check whether timestamp is farther away than n number of days.
5304 This function is invoked if `org-agenda-todo-ignore-deadlines',
5305 `org-agenda-todo-ignore-scheduled' or
5306 `org-agenda-todo-ignore-timestamp' is set to an integer."
5307 (let ((days (org-time-stamp-to-now
5308 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5309 (if (>= n 0)
5310 (>= days n)
5311 (<= days n))))
5313 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5314 (&optional end)
5315 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5316 (when (or org-agenda-todo-ignore-with-date
5317 org-agenda-todo-ignore-scheduled
5318 org-agenda-todo-ignore-deadlines
5319 org-agenda-todo-ignore-timestamp)
5320 (setq end (or end (save-excursion (outline-next-heading) (point))))
5321 (save-excursion
5322 (or (and org-agenda-todo-ignore-with-date
5323 (re-search-forward org-ts-regexp end t))
5324 (and org-agenda-todo-ignore-scheduled
5325 (re-search-forward org-scheduled-time-regexp end t)
5326 (cond
5327 ((eq org-agenda-todo-ignore-scheduled 'future)
5328 (> (org-time-stamp-to-now
5329 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5330 ((eq org-agenda-todo-ignore-scheduled 'past)
5331 (<= (org-time-stamp-to-now
5332 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5333 ((numberp org-agenda-todo-ignore-scheduled)
5334 (org-agenda-todo-custom-ignore-p
5335 (match-string 1) org-agenda-todo-ignore-scheduled))
5336 (t)))
5337 (and org-agenda-todo-ignore-deadlines
5338 (re-search-forward org-deadline-time-regexp end t)
5339 (cond
5340 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5341 ((eq org-agenda-todo-ignore-deadlines 'far)
5342 (not (org-deadline-close (match-string 1))))
5343 ((eq org-agenda-todo-ignore-deadlines 'future)
5344 (> (org-time-stamp-to-now
5345 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5346 ((eq org-agenda-todo-ignore-deadlines 'past)
5347 (<= (org-time-stamp-to-now
5348 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5349 ((numberp org-agenda-todo-ignore-deadlines)
5350 (org-agenda-todo-custom-ignore-p
5351 (match-string 1) org-agenda-todo-ignore-deadlines))
5352 (t (org-deadline-close (match-string 1)))))
5353 (and org-agenda-todo-ignore-timestamp
5354 (let ((buffer (current-buffer))
5355 (regexp
5356 (concat
5357 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5358 (start (point)))
5359 ;; Copy current buffer into a temporary one
5360 (with-temp-buffer
5361 (insert-buffer-substring buffer start end)
5362 (goto-char (point-min))
5363 ;; Delete SCHEDULED and DEADLINE items
5364 (while (re-search-forward regexp end t)
5365 (delete-region (match-beginning 0) (match-end 0)))
5366 (goto-char (point-min))
5367 ;; No search for timestamp left
5368 (when (re-search-forward org-ts-regexp nil t)
5369 (cond
5370 ((eq org-agenda-todo-ignore-timestamp 'future)
5371 (> (org-time-stamp-to-now
5372 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5373 ((eq org-agenda-todo-ignore-timestamp 'past)
5374 (<= (org-time-stamp-to-now
5375 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5376 ((numberp org-agenda-todo-ignore-timestamp)
5377 (org-agenda-todo-custom-ignore-p
5378 (match-string 1) org-agenda-todo-ignore-timestamp))
5379 (t))))))))))
5381 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5382 Do we have a reason to ignore this TODO entry because it has a time stamp?
5384 \(fn &optional END)" nil nil)
5386 (defconst org-agenda-no-heading-message
5387 "No heading for this item in buffer or region.")
5389 (defun org-agenda-get-timestamps (&optional deadline-results)
5390 "Return the date stamp information for agenda display."
5391 (let* ((props (list 'face 'org-agenda-calendar-event
5392 'org-not-done-regexp org-not-done-regexp
5393 'org-todo-regexp org-todo-regexp
5394 'org-complex-heading-regexp org-complex-heading-regexp
5395 'mouse-face 'highlight
5396 'help-echo
5397 (format "mouse-2 or RET jump to org file %s"
5398 (abbreviate-file-name buffer-file-name))))
5399 (d1 (calendar-absolute-from-gregorian date))
5401 (deadline-position-alist
5402 (mapcar (lambda (a) (and (setq mm (get-text-property
5403 0 'org-hd-marker a))
5404 (cons (marker-position mm) a)))
5405 deadline-results))
5406 (remove-re org-ts-regexp)
5407 (regexp
5408 (concat
5409 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5410 (regexp-quote
5411 (substring
5412 (format-time-string
5413 (car org-time-stamp-formats)
5414 (apply 'encode-time ; DATE bound by calendar
5415 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5416 1 11))
5417 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5418 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5419 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5420 donep tmp priority category category-pos level ee txt timestr tags
5421 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5422 (goto-char (point-min))
5423 (while (setq end-of-match (re-search-forward regexp nil t))
5424 (setq b0 (match-beginning 0)
5425 b3 (match-beginning 3) e3 (match-end 3)
5426 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5427 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5428 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5429 (member todo-state
5430 org-agenda-repeating-timestamp-show-all)))
5431 (catch :skip
5432 (and (org-at-date-range-p) (throw :skip nil))
5433 (org-agenda-skip)
5434 (if (and (match-end 1)
5435 (not (= d1 (org-time-string-to-absolute
5436 (match-string 1) d1 nil show-all
5437 (current-buffer) b0))))
5438 (throw :skip nil))
5439 (if (and e3
5440 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5441 (throw :skip nil))
5442 (setq tmp (buffer-substring (max (point-min)
5443 (- b0 org-ds-keyword-length))
5445 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5446 inactivep (= (char-after b0) ?\[)
5447 deadlinep (string-match org-deadline-regexp tmp)
5448 scheduledp (string-match org-scheduled-regexp tmp)
5449 closedp (and org-agenda-include-inactive-timestamps
5450 (string-match org-closed-string tmp))
5451 clockp (and org-agenda-include-inactive-timestamps
5452 (or (string-match org-clock-string tmp)
5453 (string-match "]-+\\'" tmp)))
5454 warntime (org-entry-get (point) "APPT_WARNTIME")
5455 donep (member todo-state org-done-keywords))
5456 (if (or scheduledp deadlinep closedp clockp
5457 (and donep org-agenda-skip-timestamp-if-done))
5458 (throw :skip t))
5459 (if (string-match ">" timestr)
5460 ;; substring should only run to end of time stamp
5461 (setq timestr (substring timestr 0 (match-end 0))))
5462 (setq marker (org-agenda-new-marker b0)
5463 category (org-get-category b0)
5464 category-pos (get-text-property b0 'org-category-position))
5465 (save-excursion
5466 (if (not (re-search-backward org-outline-regexp-bol nil t))
5467 (setq txt org-agenda-no-heading-message)
5468 (goto-char (match-beginning 0))
5469 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5470 (assoc (point) deadline-position-alist))
5471 (throw :skip nil))
5472 (setq hdmarker (org-agenda-new-marker)
5473 tags (org-get-tags-at)
5474 level (make-string (org-reduced-level (org-outline-level)) ? ))
5475 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5476 (setq head (or (match-string 1) ""))
5477 (setq txt (org-agenda-format-item
5478 (if inactivep org-agenda-inactive-leader nil)
5479 head level category tags timestr
5480 remove-re habitp)))
5481 (setq priority (org-get-priority txt))
5482 (org-add-props txt props 'priority priority
5483 'org-marker marker 'org-hd-marker hdmarker
5484 'org-category category 'date date
5485 'level level
5486 'org-category-position category-pos
5487 'todo-state todo-state
5488 'warntime warntime
5489 'type "timestamp")
5490 (push txt ee))
5491 (if org-agenda-skip-additional-timestamps-same-entry
5492 (outline-next-heading)
5493 (goto-char end-of-match))))
5494 (nreverse ee)))
5496 (defun org-agenda-get-sexps ()
5497 "Return the sexp information for agenda display."
5498 (require 'diary-lib)
5499 (let* ((props (list 'face 'org-agenda-calendar-sexp
5500 'mouse-face 'highlight
5501 'help-echo
5502 (format "mouse-2 or RET jump to org file %s"
5503 (abbreviate-file-name buffer-file-name))))
5504 (regexp "^&?%%(")
5505 marker category extra category-pos level ee txt tags entry
5506 result beg b sexp sexp-entry todo-state warntime)
5507 (goto-char (point-min))
5508 (while (re-search-forward regexp nil t)
5509 (catch :skip
5510 (org-agenda-skip)
5511 (setq beg (match-beginning 0))
5512 (goto-char (1- (match-end 0)))
5513 (setq b (point))
5514 (forward-sexp 1)
5515 (setq sexp (buffer-substring b (point)))
5516 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5517 (org-trim (match-string 1))
5518 ""))
5519 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5520 (when result
5521 (setq marker (org-agenda-new-marker beg)
5522 level (make-string (org-reduced-level (org-outline-level)) ? )
5523 category (org-get-category beg)
5524 category-pos (get-text-property beg 'org-category-position)
5525 tags (save-excursion (org-backward-heading-same-level 0)
5526 (org-get-tags-at))
5527 todo-state (org-get-todo-state)
5528 warntime (org-entry-get (point) "APPT_WARNTIME")
5529 extra nil)
5531 (dolist (r (if (stringp result)
5532 (list result)
5533 result)) ;; we expect a list here
5534 (when (and org-agenda-diary-sexp-prefix
5535 (string-match org-agenda-diary-sexp-prefix r))
5536 (setq extra (match-string 0 r)
5537 r (replace-match "" nil nil r)))
5538 (if (string-match "\\S-" r)
5539 (setq txt r)
5540 (setq txt "SEXP entry returned empty string"))
5541 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5542 (org-add-props txt props 'org-marker marker
5543 'org-category category 'date date 'todo-state todo-state
5544 'org-category-position category-pos 'tags tags
5545 'level level
5546 'type "sexp" 'warntime warntime)
5547 (push txt ee)))))
5548 (nreverse ee)))
5550 ;; Calendar sanity: define some functions that are independent of
5551 ;; `calendar-date-style'.
5552 ;; Normally I would like to use ISO format when calling the diary functions,
5553 ;; but to make sure we still have Emacs 22 compatibility we bind
5554 ;; also `european-calendar-style' and use european format
5555 (defun org-anniversary (year month day &optional mark)
5556 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5557 (org-no-warnings
5558 (let ((calendar-date-style 'european) (european-calendar-style t))
5559 (diary-anniversary day month year mark))))
5560 (defun org-cyclic (N year month day &optional mark)
5561 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5562 (org-no-warnings
5563 (let ((calendar-date-style 'european) (european-calendar-style t))
5564 (diary-cyclic N day month year mark))))
5565 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5566 "Like `diary-block', but with fixed (ISO) order of arguments."
5567 (org-no-warnings
5568 (let ((calendar-date-style 'european) (european-calendar-style t))
5569 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5570 (defun org-date (year month day &optional mark)
5571 "Like `diary-date', but with fixed (ISO) order of arguments."
5572 (org-no-warnings
5573 (let ((calendar-date-style 'european) (european-calendar-style t))
5574 (diary-date day month year mark))))
5575 (defalias 'org-float 'diary-float)
5577 ;; Define the` org-class' function
5578 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5579 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5580 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5581 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5582 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5583 `holidays', then any date that is known by the Emacs calendar to be a
5584 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5585 then those holidays will be skipped."
5586 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5587 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5588 (d (calendar-absolute-from-gregorian date))
5589 (h (when skip-weeks (calendar-check-holidays date))))
5590 (and
5591 (<= date1 d)
5592 (<= d date2)
5593 (= (calendar-day-of-week date) dayname)
5594 (or (not skip-weeks)
5595 (progn
5596 (require 'cal-iso)
5597 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5598 (not (or (and h (memq 'holidays skip-weeks))
5599 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5600 entry)))
5602 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5603 "Like `org-class', but honor `calendar-date-style'.
5604 The order of the first 2 times 3 arguments depends on the variable
5605 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5606 So for American calendars, give this as MONTH DAY YEAR, for European as
5607 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5608 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5609 is any number of ISO weeks in the block period for which the item should
5610 be skipped.
5612 This function is here only for backward compatibility and it is deprecated,
5613 please use `org-class' instead."
5614 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5615 (date2 (org-order-calendar-date-args m2 d2 y2)))
5616 (org-class
5617 (nth 2 date1) (car date1) (nth 1 date1)
5618 (nth 2 date2) (car date2) (nth 1 date2)
5619 dayname skip-weeks)))
5620 (make-obsolete 'org-diary-class 'org-class "")
5622 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5623 (defalias 'org-get-closed 'org-agenda-get-progress)
5624 (defun org-agenda-get-progress ()
5625 "Return the logged TODO entries for agenda display."
5626 (let* ((props (list 'mouse-face 'highlight
5627 'org-not-done-regexp org-not-done-regexp
5628 'org-todo-regexp org-todo-regexp
5629 'org-complex-heading-regexp org-complex-heading-regexp
5630 'help-echo
5631 (format "mouse-2 or RET jump to org file %s"
5632 (abbreviate-file-name buffer-file-name))))
5633 (items (if (consp org-agenda-show-log-scoped)
5634 org-agenda-show-log-scoped
5635 (if (eq org-agenda-show-log-scoped 'clockcheck)
5636 '(clock)
5637 org-agenda-log-mode-items)))
5638 (parts
5639 (delq nil
5640 (list
5641 (if (memq 'closed items) (concat "\\<" org-closed-string))
5642 (if (memq 'clock items) (concat "\\<" org-clock-string))
5643 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5644 (parts-re (if parts (mapconcat 'identity parts "\\|")
5645 (error "`org-agenda-log-mode-items' is empty")))
5646 (regexp (concat
5647 "\\(" parts-re "\\)"
5648 " *\\["
5649 (regexp-quote
5650 (substring
5651 (format-time-string
5652 (car org-time-stamp-formats)
5653 (apply 'encode-time ; DATE bound by calendar
5654 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5655 1 11))))
5656 (org-agenda-search-headline-for-time nil)
5657 marker hdmarker priority category category-pos level tags closedp
5658 statep clockp state ee txt extra timestr rest clocked)
5659 (goto-char (point-min))
5660 (while (re-search-forward regexp nil t)
5661 (catch :skip
5662 (org-agenda-skip)
5663 (setq marker (org-agenda-new-marker (match-beginning 0))
5664 closedp (equal (match-string 1) org-closed-string)
5665 statep (equal (string-to-char (match-string 1)) ?-)
5666 clockp (not (or closedp statep))
5667 state (and statep (match-string 2))
5668 category (org-get-category (match-beginning 0))
5669 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5670 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5671 (when (string-match "\\]" timestr)
5672 ;; substring should only run to end of time stamp
5673 (setq rest (substring timestr (match-end 0))
5674 timestr (substring timestr 0 (match-end 0)))
5675 (if (and (not closedp) (not statep)
5676 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5677 rest))
5678 (progn (setq timestr (concat (substring timestr 0 -1)
5679 "-" (match-string 1 rest) "]"))
5680 (setq clocked (match-string 2 rest)))
5681 (setq clocked "-")))
5682 (save-excursion
5683 (setq extra
5684 (cond
5685 ((not org-agenda-log-mode-add-notes) nil)
5686 (statep
5687 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5688 (match-string 1)))
5689 (clockp
5690 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5691 (match-string 1)))))
5692 (if (not (re-search-backward org-outline-regexp-bol nil t))
5693 (setq txt org-agenda-no-heading-message)
5694 (goto-char (match-beginning 0))
5695 (setq hdmarker (org-agenda-new-marker)
5696 tags (org-get-tags-at)
5697 level (make-string (org-reduced-level (org-outline-level)) ? ))
5698 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5699 (setq txt (match-string 1))
5700 (when extra
5701 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5702 (setq txt (concat (substring txt 0 (match-beginning 1))
5703 " - " extra " " (match-string 2 txt)))
5704 (setq txt (concat txt " - " extra))))
5705 (setq txt (org-agenda-format-item
5706 (cond
5707 (closedp "Closed: ")
5708 (statep (concat "State: (" state ")"))
5709 (t (concat "Clocked: (" clocked ")")))
5710 txt level category tags timestr)))
5711 (setq priority 100000)
5712 (org-add-props txt props
5713 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5714 'priority priority 'org-category category
5715 'org-category-position category-pos
5716 'level level
5717 'type "closed" 'date date
5718 'undone-face 'org-warning 'done-face 'org-agenda-done)
5719 (push txt ee))
5720 (goto-char (point-at-eol))))
5721 (nreverse ee)))
5723 (defun org-agenda-show-clocking-issues ()
5724 "Add overlays, showing issues with clocking.
5725 See also the user option `org-agenda-clock-consistency-checks'."
5726 (interactive)
5727 (let* ((pl org-agenda-clock-consistency-checks)
5728 (re (concat "^[ \t]*"
5729 org-clock-string
5730 "[ \t]+"
5731 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5732 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5733 (tlstart 0.)
5734 (tlend 0.)
5735 (maxtime (org-hh:mm-string-to-minutes
5736 (or (plist-get pl :max-duration) "24:00")))
5737 (mintime (org-hh:mm-string-to-minutes
5738 (or (plist-get pl :min-duration) 0)))
5739 (maxgap (org-hh:mm-string-to-minutes
5740 ;; default 30:00 means never complain
5741 (or (plist-get pl :max-gap) "30:00")))
5742 (gapok (mapcar 'org-hh:mm-string-to-minutes
5743 (plist-get pl :gap-ok-around)))
5744 (def-face (or (plist-get pl :default-face)
5745 '((:background "DarkRed") (:foreground "white"))))
5746 issue face m te ts dt ov)
5747 (goto-char (point-min))
5748 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5749 (setq issue nil face def-face)
5750 (catch 'next
5751 (setq m (org-get-at-bol 'org-marker)
5752 te nil ts nil)
5753 (unless (and m (markerp m))
5754 (setq issue "No valid clock line") (throw 'next t))
5755 (org-with-point-at m
5756 (save-excursion
5757 (goto-char (point-at-bol))
5758 (unless (looking-at re)
5759 (error "No valid Clock line")
5760 (throw 'next t))
5761 (unless (match-end 3)
5762 (setq issue "No end time"
5763 face (or (plist-get pl :no-end-time-face) face))
5764 (throw 'next t))
5765 (setq ts (match-string 1)
5766 te (match-string 3)
5767 ts (org-float-time
5768 (apply 'encode-time (org-parse-time-string ts)))
5769 te (org-float-time
5770 (apply 'encode-time (org-parse-time-string te)))
5771 dt (- te ts))))
5772 (cond
5773 ((> dt (* 60 maxtime))
5774 ;; a very long clocking chunk
5775 (setq issue (format "Clocking interval is very long: %s"
5776 (org-minutes-to-clocksum-string
5777 (floor (/ (float dt) 60.))))
5778 face (or (plist-get pl :long-face) face)))
5779 ((< dt (* 60 mintime))
5780 ;; a very short clocking chunk
5781 (setq issue (format "Clocking interval is very short: %s"
5782 (org-minutes-to-clocksum-string
5783 (floor (/ (float dt) 60.))))
5784 face (or (plist-get pl :short-face) face)))
5785 ((and (> tlend 0) (< ts tlend))
5786 ;; Two clock entries are overlapping
5787 (setq issue (format "Clocking overlap: %d minutes"
5788 (/ (- tlend ts) 60))
5789 face (or (plist-get pl :overlap-face) face)))
5790 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5791 ;; There is a gap, lets see if we need to report it
5792 (unless (org-agenda-check-clock-gap tlend ts gapok)
5793 (setq issue (format "Clocking gap: %d minutes"
5794 (/ (- ts tlend) 60))
5795 face (or (plist-get pl :gap-face) face))))
5796 (t nil)))
5797 (setq tlend (or te tlend) tlstart (or ts tlstart))
5798 (when issue
5799 ;; OK, there was some issue, add an overlay to show the issue
5800 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5801 (overlay-put ov 'before-string
5802 (concat
5803 (org-add-props
5804 (format "%-43s" (concat " " issue))
5806 'face face)
5807 "\n"))
5808 (overlay-put ov 'evaporate t)))))
5810 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5811 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5812 (catch 'exit
5813 (unless ok-list
5814 ;; there are no OK times for gaps...
5815 (throw 'exit nil))
5816 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5817 ;; This is more than 24 hours, so it is OK.
5818 ;; because we have at least one OK time, that must be in the
5819 ;; 24 hour interval.
5820 (throw 'exit t))
5821 ;; We have a shorter gap.
5822 ;; Now we have to get the minute of the day when these times are
5823 (let* ((t1dec (decode-time (seconds-to-time t1)))
5824 (t2dec (decode-time (seconds-to-time t2)))
5825 ;; compute the minute on the day
5826 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5827 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5828 (when (< min2 min1)
5829 ;; if min2 is smaller than min1, this means it is on the next day.
5830 ;; Wrap it to after midnight.
5831 (setq min2 (+ min2 1440)))
5832 ;; Now check if any of the OK times is in the gap
5833 (mapc (lambda (x)
5834 ;; Wrap the time to after midnight if necessary
5835 (if (< x min1) (setq x (+ x 1440)))
5836 ;; Check if in interval
5837 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5838 ok-list)
5839 ;; Nope, this gap is not OK
5840 nil)))
5842 (defun org-agenda-get-deadlines ()
5843 "Return the deadline information for agenda display."
5844 (let* ((props (list 'mouse-face 'highlight
5845 'org-not-done-regexp org-not-done-regexp
5846 'org-todo-regexp org-todo-regexp
5847 'org-complex-heading-regexp org-complex-heading-regexp
5848 'help-echo
5849 (format "mouse-2 or RET jump to org file %s"
5850 (abbreviate-file-name buffer-file-name))))
5851 (regexp org-deadline-time-regexp)
5852 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5853 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5854 d2 diff dfrac wdays pos pos1 category category-pos level
5855 tags suppress-prewarning ee txt head face s todo-state
5856 show-all upcomingp donep timestr warntime)
5857 (goto-char (point-min))
5858 (while (re-search-forward regexp nil t)
5859 (catch :skip
5860 (org-agenda-skip)
5861 (setq s (match-string 1)
5862 txt nil
5863 pos (1- (match-beginning 1))
5864 todo-state (save-match-data (org-get-todo-state))
5865 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5866 (member todo-state
5867 org-agenda-repeating-timestamp-show-all))
5868 d2 (org-time-string-to-absolute
5869 (match-string 1) d1 'past show-all
5870 (current-buffer) pos)
5871 diff (- d2 d1))
5872 (setq suppress-prewarning
5873 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5874 (let ((item (buffer-substring (point-at-bol)
5875 (point-at-eol))))
5876 (save-match-data
5877 (and (string-match
5878 org-scheduled-time-regexp item)
5879 (match-string 1 item)))))))
5880 (cond
5881 ((not ds) nil)
5882 ;; The current item has a scheduled date (in ds), so
5883 ;; evaluate its prewarning lead time.
5884 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5885 ;; Use global prewarning-restart lead time.
5886 org-agenda-skip-deadline-prewarning-if-scheduled)
5887 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5888 'pre-scheduled)
5889 ;; Set prewarning to no earlier than scheduled.
5890 (min (- d2 (org-time-string-to-absolute
5891 ds d1 'past show-all (current-buffer) pos))
5892 org-deadline-warning-days))
5893 ;; Set prewarning to deadline.
5894 (t 0))))
5895 (setq wdays (if suppress-prewarning
5896 (let ((org-deadline-warning-days suppress-prewarning))
5897 (org-get-wdays s))
5898 (org-get-wdays s))
5899 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5900 upcomingp (and todayp (> diff 0)))
5901 ;; When to show a deadline in the calendar:
5902 ;; If the expiration is within wdays warning time.
5903 ;; Past-due deadlines are only shown on the current date
5904 (if (and (or (and (<= diff wdays)
5905 (and todayp (not org-agenda-only-exact-dates)))
5906 (= diff 0)))
5907 (save-excursion
5908 ;; (setq todo-state (org-get-todo-state))
5909 (setq donep (member todo-state org-done-keywords))
5910 (if (and donep
5911 (or org-agenda-skip-deadline-if-done
5912 (not (= diff 0))))
5913 (setq txt nil)
5914 (setq category (org-get-category)
5915 warntime (org-entry-get (point) "APPT_WARNTIME")
5916 category-pos (get-text-property (point) 'org-category-position))
5917 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5918 (setq txt org-agenda-no-heading-message)
5919 (goto-char (match-end 0))
5920 (setq pos1 (match-beginning 0))
5921 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5922 (setq tags (org-get-tags-at pos1))
5923 (setq head (buffer-substring-no-properties
5924 (point)
5925 (progn (skip-chars-forward "^\r\n")
5926 (point))))
5927 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5928 (setq timestr
5929 (concat (substring s (match-beginning 1)) " "))
5930 (setq timestr 'time))
5931 (setq txt (org-agenda-format-item
5932 (if (= diff 0)
5933 (car org-agenda-deadline-leaders)
5934 (if (functionp
5935 (nth 1 org-agenda-deadline-leaders))
5936 (funcall
5937 (nth 1 org-agenda-deadline-leaders)
5938 diff date)
5939 (format (nth 1 org-agenda-deadline-leaders)
5940 diff)))
5941 head level category tags
5942 (if (not (= diff 0)) nil timestr)))))
5943 (when txt
5944 (setq face (org-agenda-deadline-face dfrac))
5945 (org-add-props txt props
5946 'org-marker (org-agenda-new-marker pos)
5947 'warntime warntime
5948 'level level
5949 'org-hd-marker (org-agenda-new-marker pos1)
5950 'priority (+ (- diff)
5951 (org-get-priority txt))
5952 'org-category category
5953 'org-category-position category-pos
5954 'todo-state todo-state
5955 'type (if upcomingp "upcoming-deadline" "deadline")
5956 'date (if upcomingp date d2)
5957 'face (if donep 'org-agenda-done face)
5958 'undone-face face 'done-face 'org-agenda-done)
5959 (push txt ee))))))
5960 (nreverse ee)))
5962 (defun org-agenda-deadline-face (fraction)
5963 "Return the face to displaying a deadline item.
5964 FRACTION is what fraction of the head-warning time has passed."
5965 (let ((faces org-agenda-deadline-faces) f)
5966 (catch 'exit
5967 (while (setq f (pop faces))
5968 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5970 (defun org-agenda-get-scheduled (&optional deadline-results)
5971 "Return the scheduled information for agenda display."
5972 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5973 'org-todo-regexp org-todo-regexp
5974 'org-complex-heading-regexp org-complex-heading-regexp
5975 'done-face 'org-agenda-done
5976 'mouse-face 'highlight
5977 'help-echo
5978 (format "mouse-2 or RET jump to org file %s"
5979 (abbreviate-file-name buffer-file-name))))
5980 (regexp org-scheduled-time-regexp)
5981 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5982 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5984 (deadline-position-alist
5985 (mapcar (lambda (a) (and (setq mm (get-text-property
5986 0 'org-hd-marker a))
5987 (cons (marker-position mm) a)))
5988 deadline-results))
5989 d2 diff pos pos1 category category-pos level tags donep
5990 ee txt head pastschedp todo-state face timestr s habitp show-all
5991 did-habit-check-p warntime)
5992 (goto-char (point-min))
5993 (while (re-search-forward regexp nil t)
5994 (catch :skip
5995 (org-agenda-skip)
5996 (setq s (match-string 1)
5997 txt nil
5998 pos (1- (match-beginning 1))
5999 todo-state (save-match-data (org-get-todo-state))
6000 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6001 (member todo-state
6002 org-agenda-repeating-timestamp-show-all))
6003 d2 (org-time-string-to-absolute
6004 (match-string 1) d1 'past show-all
6005 (current-buffer) pos)
6006 diff (- d2 d1)
6007 warntime (org-entry-get (point) "APPT_WARNTIME"))
6008 (setq pastschedp (and todayp (< diff 0)))
6009 (setq did-habit-check-p nil)
6010 ;; When to show a scheduled item in the calendar:
6011 ;; If it is on or past the date.
6012 (when (or (and (< diff 0)
6013 (< (abs diff) org-scheduled-past-days)
6014 (and todayp (not org-agenda-only-exact-dates)))
6015 (= diff 0)
6016 ;; org-is-habit-p uses org-entry-get, which is expansive
6017 ;; so we go extra mile to only call it once
6018 (and todayp
6019 (boundp 'org-habit-show-all-today)
6020 org-habit-show-all-today
6021 (setq did-habit-check-p t)
6022 (setq habitp (and (functionp 'org-is-habit-p)
6023 (org-is-habit-p)))))
6024 (save-excursion
6025 (setq donep (member todo-state org-done-keywords))
6026 (if (and donep
6027 (or org-agenda-skip-scheduled-if-done
6028 (not (= diff 0))
6029 (and (functionp 'org-is-habit-p)
6030 (org-is-habit-p))))
6031 (setq txt nil)
6032 (setq habitp (if did-habit-check-p habitp
6033 (and (functionp 'org-is-habit-p)
6034 (org-is-habit-p))))
6035 (setq category (org-get-category)
6036 category-pos (get-text-property (point) 'org-category-position))
6037 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6038 (setq txt org-agenda-no-heading-message)
6039 (goto-char (match-end 0))
6040 (setq pos1 (match-beginning 0))
6041 (if habitp
6042 (if (or (not org-habit-show-habits)
6043 (and (not todayp)
6044 (boundp 'org-habit-show-habits-only-for-today)
6045 org-habit-show-habits-only-for-today))
6046 (throw :skip nil))
6047 (if (and
6048 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6049 (and org-agenda-skip-scheduled-if-deadline-is-shown
6050 pastschedp))
6051 (setq mm (assoc pos1 deadline-position-alist)))
6052 (throw :skip nil)))
6053 (setq tags (org-get-tags-at))
6054 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6055 (setq head (buffer-substring-no-properties
6056 (point)
6057 (progn (skip-chars-forward "^\r\n") (point))))
6058 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6059 (setq timestr
6060 (concat (substring s (match-beginning 1)) " "))
6061 (setq timestr 'time))
6062 (setq txt (org-agenda-format-item
6063 (if (= diff 0)
6064 (car org-agenda-scheduled-leaders)
6065 (format (nth 1 org-agenda-scheduled-leaders)
6066 (- 1 diff)))
6067 head level category tags
6068 (if (not (= diff 0)) nil timestr)
6069 nil habitp))))
6070 (when txt
6071 (setq face
6072 (cond
6073 ((and (not habitp) pastschedp)
6074 'org-scheduled-previously)
6075 (todayp 'org-scheduled-today)
6076 (t 'org-scheduled))
6077 habitp (and habitp (org-habit-parse-todo)))
6078 (org-add-props txt props
6079 'undone-face face
6080 'face (if donep 'org-agenda-done face)
6081 'org-marker (org-agenda-new-marker pos)
6082 'org-hd-marker (org-agenda-new-marker pos1)
6083 'type (if pastschedp "past-scheduled" "scheduled")
6084 'date (if pastschedp d2 date)
6085 'warntime warntime
6086 'level level
6087 'priority (if habitp
6088 (org-habit-get-priority habitp)
6089 (+ 94 (- 5 diff) (org-get-priority txt)))
6090 'org-category category
6091 'category-position category-pos
6092 'org-habit-p habitp
6093 'todo-state todo-state)
6094 (push txt ee))))))
6095 (nreverse ee)))
6097 (defun org-agenda-get-blocks ()
6098 "Return the date-range information for agenda display."
6099 (let* ((props (list 'face nil
6100 'org-not-done-regexp org-not-done-regexp
6101 'org-todo-regexp org-todo-regexp
6102 'org-complex-heading-regexp org-complex-heading-regexp
6103 'mouse-face 'highlight
6104 'help-echo
6105 (format "mouse-2 or RET jump to org file %s"
6106 (abbreviate-file-name buffer-file-name))))
6107 (regexp org-tr-regexp)
6108 (d0 (calendar-absolute-from-gregorian date))
6109 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6110 level todo-state tags pos head donep)
6111 (goto-char (point-min))
6112 (while (re-search-forward regexp nil t)
6113 (catch :skip
6114 (org-agenda-skip)
6115 (setq pos (point))
6116 (let ((start-time (match-string 1))
6117 (end-time (match-string 2)))
6118 (setq s1 (match-string 1)
6119 s2 (match-string 2)
6120 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6121 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6122 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6123 ;; Only allow days between the limits, because the normal
6124 ;; date stamps will catch the limits.
6125 (save-excursion
6126 (setq todo-state (org-get-todo-state))
6127 (setq donep (member todo-state org-done-keywords))
6128 (if (and donep org-agenda-skip-timestamp-if-done)
6129 (throw :skip t))
6130 (setq marker (org-agenda-new-marker (point)))
6131 (setq category (org-get-category)
6132 category-pos (get-text-property (point) 'org-category-position))
6133 (if (not (re-search-backward org-outline-regexp-bol nil t))
6134 (setq txt org-agenda-no-heading-message)
6135 (goto-char (match-beginning 0))
6136 (setq hdmarker (org-agenda-new-marker (point)))
6137 (setq tags (org-get-tags-at))
6138 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6139 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6140 (setq head (match-string 1))
6141 (let ((remove-re
6142 (if org-agenda-remove-timeranges-from-blocks
6143 (concat
6144 "<" (regexp-quote s1) ".*?>"
6145 "--"
6146 "<" (regexp-quote s2) ".*?>")
6147 nil)))
6148 (setq txt (org-agenda-format-item
6149 (format
6150 (nth (if (= d1 d2) 0 1)
6151 org-agenda-timerange-leaders)
6152 (1+ (- d0 d1)) (1+ (- d2 d1)))
6153 head level category tags
6154 (cond ((and (= d1 d0) (= d2 d0))
6155 (concat "<" start-time ">--<" end-time ">"))
6156 ((= d1 d0)
6157 (concat "<" start-time ">"))
6158 ((= d2 d0)
6159 (concat "<" end-time ">")))
6160 remove-re))))
6161 (org-add-props txt props
6162 'org-marker marker 'org-hd-marker hdmarker
6163 'type "block" 'date date
6164 'level level
6165 'todo-state todo-state
6166 'priority (org-get-priority txt) 'org-category category
6167 'org-category-position category-pos)
6168 (push txt ee))))
6169 (goto-char pos)))
6170 ;; Sort the entries by expiration date.
6171 (nreverse ee)))
6173 ;;; Agenda presentation and sorting
6175 (defvar org-prefix-has-time nil
6176 "A flag, set by `org-compile-prefix-format'.
6177 The flag is set if the currently compiled format contains a `%t'.")
6178 (defvar org-prefix-has-tag nil
6179 "A flag, set by `org-compile-prefix-format'.
6180 The flag is set if the currently compiled format contains a `%T'.")
6181 (defvar org-prefix-has-effort nil
6182 "A flag, set by `org-compile-prefix-format'.
6183 The flag is set if the currently compiled format contains a `%e'.")
6184 (defvar org-prefix-category-length nil
6185 "Used by `org-compile-prefix-format' to remember the category field width.")
6186 (defvar org-prefix-category-max-length nil
6187 "Used by `org-compile-prefix-format' to remember the category field width.")
6189 (defun org-agenda-get-category-icon (category)
6190 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6191 (dolist (entry org-agenda-category-icon-alist)
6192 (when (org-string-match-p (car entry) category)
6193 (if (listp (cadr entry))
6194 (return (cadr entry))
6195 (return (apply 'create-image (cdr entry)))))))
6197 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6198 remove-re habitp)
6199 "Format TXT to be inserted into the agenda buffer.
6200 In particular, add the prefix and corresponding text properties.
6202 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6203 LEVEL may be a string to replace the `%l' specifier.
6204 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6205 category taken from local variable or file name. It will replace the `%c'
6206 specifier in the format.
6207 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6208 TXT for sorting of this entry, and for the `%t' specifier in the format.
6209 When DOTIME is a string, this string is searched for a time before TXT is.
6210 TAGS can be the tags of the headline.
6211 Any match of REMOVE-RE will be removed from TXT."
6212 ;; We keep the org-prefix-* variable values along with a compiled
6213 ;; formatter, so that multiple agendas existing at the same time do
6214 ;; not step on each other toes.
6216 ;; It was inconvenient to make these variables buffer local in
6217 ;; Agenda buffers, because this function expects to be called with
6218 ;; the buffer where item comes from being current, and not agenda
6219 ;; buffer
6220 (let* ((bindings (car org-prefix-format-compiled))
6221 (formatter (cadr org-prefix-format-compiled)))
6222 (loop for (var value) in bindings
6223 do (set var value))
6224 (save-match-data
6225 ;; Diary entries sometimes have extra whitespace at the beginning
6226 (setq txt (org-trim txt))
6228 ;; Fix the tags part in txt
6229 (setq txt (org-agenda-fix-displayed-tags
6230 txt tags
6231 org-agenda-show-inherited-tags
6232 org-agenda-hide-tags-regexp))
6234 (let* ((category (or category
6235 (if (stringp org-category)
6236 org-category
6237 (and org-category (symbol-name org-category)))
6238 (if buffer-file-name
6239 (file-name-sans-extension
6240 (file-name-nondirectory buffer-file-name))
6241 "")))
6242 (category-icon (org-agenda-get-category-icon category))
6243 (category-icon (if category-icon
6244 (propertize " " 'display category-icon)
6245 ""))
6246 ;; time, tag, effort are needed for the eval of the prefix format
6247 (tag (if tags (nth (1- (length tags)) tags) ""))
6248 time effort neffort
6249 (ts (if dotime (concat
6250 (if (stringp dotime) dotime "")
6251 (and org-agenda-search-headline-for-time txt))))
6252 (time-of-day (and dotime (org-get-time-of-day ts)))
6253 stamp plain s0 s1 s2 rtn srp l
6254 duration thecategory)
6255 (and (derived-mode-p 'org-mode) buffer-file-name
6256 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6257 (when (and dotime time-of-day)
6258 ;; Extract starting and ending time and move them to prefix
6259 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6260 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6261 (setq s0 (match-string 0 ts)
6262 srp (and stamp (match-end 3))
6263 s1 (match-string (if plain 1 2) ts)
6264 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6266 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6267 ;; them, we might want to remove them there to avoid duplication.
6268 ;; The user can turn this off with a variable.
6269 (if (and org-prefix-has-time
6270 org-agenda-remove-times-when-in-prefix (or stamp plain)
6271 (string-match (concat (regexp-quote s0) " *") txt)
6272 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6273 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6274 (= (match-beginning 0) 0)
6276 (setq txt (replace-match "" nil nil txt))))
6277 ;; Normalize the time(s) to 24 hour
6278 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6279 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6281 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6282 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6283 (setq s2
6284 (org-minutes-to-clocksum-string
6285 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6287 ;; Compute the duration
6288 (when s2
6289 (setq duration (- (org-hh:mm-string-to-minutes s2)
6290 (org-hh:mm-string-to-minutes s1)))))
6292 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6293 txt)
6294 ;; Tags are in the string
6295 (if (or (eq org-agenda-remove-tags t)
6296 (and org-agenda-remove-tags
6297 org-prefix-has-tag))
6298 (setq txt (replace-match "" t t txt))
6299 (setq txt (replace-match
6300 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6301 (match-string 2 txt))
6302 t t txt))))
6303 (when (derived-mode-p 'org-mode)
6304 (setq effort
6305 (condition-case nil
6306 (org-get-effort
6307 (or (get-text-property 0 'org-hd-marker txt)
6308 (get-text-property 0 'org-marker txt)))
6309 (error nil)))
6310 (when effort
6311 (setq neffort (org-duration-string-to-minutes effort)
6312 effort (setq effort (concat "[" effort "]")))))
6313 ;; prevent erroring out with %e format when there is no effort
6314 (or effort (setq effort ""))
6316 (when remove-re
6317 (while (string-match remove-re txt)
6318 (setq txt (replace-match "" t t txt))))
6320 ;; Set org-heading property on `txt' to mark the start of the
6321 ;; heading.
6322 (add-text-properties 0 (length txt) '(org-heading t) txt)
6324 ;; Prepare the variables needed in the eval of the compiled format
6325 (setq time (cond (s2 (concat
6326 (org-agenda-time-of-day-to-ampm-maybe s1)
6327 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6328 (if org-agenda-timegrid-use-ampm " ")))
6329 (s1 (concat
6330 (org-agenda-time-of-day-to-ampm-maybe s1)
6331 (if org-agenda-timegrid-use-ampm
6332 "........ "
6333 "......")))
6334 (t ""))
6335 extra (or (and (not habitp) extra) "")
6336 category (if (symbolp category) (symbol-name category) category)
6337 thecategory (copy-sequence category)
6338 level (or level ""))
6339 (if (string-match org-bracket-link-regexp category)
6340 (progn
6341 (setq l (if (match-end 3)
6342 (- (match-end 3) (match-beginning 3))
6343 (- (match-end 1) (match-beginning 1))))
6344 (when (< l (or org-prefix-category-length 0))
6345 (setq category (copy-sequence category))
6346 (org-add-props category nil
6347 'extra-space (make-string
6348 (- org-prefix-category-length l 1) ?\ ))))
6349 (if (and org-prefix-category-max-length
6350 (>= (length category) org-prefix-category-max-length))
6351 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6352 ;; Evaluate the compiled format
6353 (setq rtn (concat (eval formatter) txt))
6355 ;; And finally add the text properties
6356 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6357 (org-add-props rtn nil
6358 'org-category (if thecategory (downcase thecategory) category)
6359 'tags (mapcar 'org-downcase-keep-props tags)
6360 'org-highest-priority org-highest-priority
6361 'org-lowest-priority org-lowest-priority
6362 'time-of-day time-of-day
6363 'duration duration
6364 'effort effort
6365 'effort-minutes neffort
6366 'txt txt
6367 'level level
6368 'time time
6369 'extra extra
6370 'format org-prefix-format-compiled
6371 'dotime dotime)))))
6373 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6374 "Remove tags string from TXT, and add a modified list of tags.
6375 The modified list may contain inherited tags, and tags matched by
6376 `org-agenda-hide-tags-regexp' will be removed."
6377 (when (or add-inherited hide-re)
6378 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6379 (setq txt (substring txt 0 (match-beginning 0))))
6380 (setq tags
6381 (delq nil
6382 (mapcar (lambda (tg)
6383 (if (or (and hide-re (string-match hide-re tg))
6384 (and (not add-inherited)
6385 (get-text-property 0 'inherited tg)))
6387 tg))
6388 tags)))
6389 (when tags
6390 (let ((have-i (get-text-property 0 'inherited (car tags)))
6392 (setq txt (concat txt " :"
6393 (mapconcat
6394 (lambda (x)
6395 (setq i (get-text-property 0 'inherited x))
6396 (if (and have-i (not i))
6397 (progn
6398 (setq have-i nil)
6399 (concat ":" x))
6401 tags ":")
6402 (if have-i "::" ":"))))))
6403 txt)
6405 (defun org-downcase-keep-props (s)
6406 (let ((props (text-properties-at 0 s)))
6407 (setq s (downcase s))
6408 (add-text-properties 0 (length s) props s)
6411 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6412 (defvar org-agenda-sorting-strategy-selected nil)
6414 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6415 "Add a time-grid for agenda items which need it.
6417 LIST is the list of agenda items formatted by `org-agenda-list'.
6418 NDAYS is the span of the current agenda view.
6419 TODAYP is `t' when the current agenda view is on today."
6420 (catch 'exit
6421 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6422 ((and todayp (member 'today (car org-agenda-time-grid))))
6423 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6424 ((member 'weekly (car org-agenda-time-grid)))
6425 (t (throw 'exit list)))
6426 (let* ((have (delq nil (mapcar
6427 (lambda (x) (get-text-property 1 'time-of-day x))
6428 list)))
6429 (string (nth 1 org-agenda-time-grid))
6430 (gridtimes (nth 2 org-agenda-time-grid))
6431 (req (car org-agenda-time-grid))
6432 (remove (member 'remove-match req))
6433 new time)
6434 (if (and (member 'require-timed req) (not have))
6435 ;; don't show empty grid
6436 (throw 'exit list))
6437 (while (setq time (pop gridtimes))
6438 (unless (and remove (member time have))
6439 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6440 (push (org-agenda-format-item
6441 nil string nil "" nil
6442 (concat (substring time 0 -2) ":" (substring time -2)))
6443 new)
6444 (put-text-property
6445 2 (length (car new)) 'face 'org-time-grid (car new))))
6446 (when (and todayp org-agenda-show-current-time-in-grid)
6447 (push (org-agenda-format-item
6448 nil org-agenda-current-time-string nil "" nil
6449 (format-time-string "%H:%M "))
6450 new)
6451 (put-text-property
6452 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6454 (if (member 'time-up org-agenda-sorting-strategy-selected)
6455 (append new list)
6456 (append list new)))))
6458 (defun org-compile-prefix-format (key)
6459 "Compile the prefix format into a Lisp form that can be evaluated.
6460 The resulting form and associated variable bindings is returned
6461 and stored in the variable `org-prefix-format-compiled'."
6462 (setq org-prefix-has-time nil
6463 org-prefix-has-tag nil
6464 org-prefix-category-length nil
6465 org-prefix-has-effort nil)
6466 (let ((s (cond
6467 ((stringp org-agenda-prefix-format)
6468 org-agenda-prefix-format)
6469 ((assq key org-agenda-prefix-format)
6470 (cdr (assq key org-agenda-prefix-format)))
6471 (t " %-12:c%?-12t% s")))
6472 (start 0)
6473 varform vars var e c f opt)
6474 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6475 s start)
6476 (setq var (or (cdr (assoc (match-string 4 s)
6477 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6478 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6479 'eval)
6480 c (or (match-string 3 s) "")
6481 opt (match-beginning 1)
6482 start (1+ (match-beginning 0)))
6483 (if (equal var 'time) (setq org-prefix-has-time t))
6484 (if (equal var 'tag) (setq org-prefix-has-tag t))
6485 (if (equal var 'effort) (setq org-prefix-has-effort t))
6486 (setq f (concat "%" (match-string 2 s) "s"))
6487 (when (equal var 'category)
6488 (setq org-prefix-category-length
6489 (floor (abs (string-to-number (match-string 2 s)))))
6490 (setq org-prefix-category-max-length
6491 (let ((x (match-string 2 s)))
6492 (save-match-data
6493 (if (string-match "\\.[0-9]+" x)
6494 (string-to-number (substring (match-string 0 x) 1)))))))
6495 (if (eq var 'eval)
6496 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6497 (if opt
6498 (setq varform
6499 `(if (equal "" ,var)
6501 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6502 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6503 (setq s (replace-match "%s" t nil s))
6504 (push varform vars))
6505 (setq vars (nreverse vars))
6506 (with-current-buffer (or org-agenda-buffer (current-buffer))
6507 (setq org-prefix-format-compiled
6508 (list
6509 `((org-prefix-has-time ,org-prefix-has-time)
6510 (org-prefix-has-tag ,org-prefix-has-tag)
6511 (org-prefix-category-length ,org-prefix-category-length)
6512 (org-prefix-has-effort ,org-prefix-has-effort))
6513 `(format ,s ,@vars))))))
6515 (defun org-set-sorting-strategy (key)
6516 (if (symbolp (car org-agenda-sorting-strategy))
6517 ;; the old format
6518 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6519 (setq org-agenda-sorting-strategy-selected
6520 (or (cdr (assq key org-agenda-sorting-strategy))
6521 (cdr (assq 'agenda org-agenda-sorting-strategy))
6522 '(time-up category-keep priority-down)))))
6524 (defun org-get-time-of-day (s &optional string mod24)
6525 "Check string S for a time of day.
6526 If found, return it as a military time number between 0 and 2400.
6527 If not found, return nil.
6528 The optional STRING argument forces conversion into a 5 character wide string
6529 HH:MM."
6530 (save-match-data
6531 (when
6532 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6533 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6534 (let* ((h (string-to-number (match-string 1 s)))
6535 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6536 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6537 (am-p (equal ampm "am"))
6538 (h1 (cond ((not ampm) h)
6539 ((= h 12) (if am-p 0 12))
6540 (t (+ h (if am-p 0 12)))))
6541 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6542 (mod h1 24) h1))
6543 (t0 (+ (* 100 h2) m))
6544 (t1 (concat (if (>= h1 24) "+" " ")
6545 (if (and org-agenda-time-leading-zero
6546 (< t0 1000)) "0" "")
6547 (if (< t0 100) "0" "")
6548 (if (< t0 10) "0" "")
6549 (int-to-string t0))))
6550 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6552 (defvar org-agenda-before-sorting-filter-function nil
6553 "Function to be applied to agenda items prior to sorting.
6554 Prior to sorting also means just before they are inserted into the agenda.
6556 To aid sorting, you may revisit the original entries and add more text
6557 properties which will later be used by the sorting functions.
6559 The function should take a string argument, an agenda line.
6560 It has access to the text properties in that line, which contain among
6561 other things, the property `org-hd-marker' that points to the entry
6562 where the line comes from. Note that not all lines going into the agenda
6563 have this property, only most.
6565 The function should return the modified string. It is probably best
6566 to ONLY change text properties.
6568 You can also use this function as a filter, by returning nil for lines
6569 you don't want to have in the agenda at all. For this application, you
6570 could bind the variable in the options section of a custom command.")
6572 (defun org-agenda-finalize-entries (list &optional nosort)
6573 "Sort and concatenate the agenda items."
6574 (setq list (mapcar 'org-agenda-highlight-todo list))
6575 (if nosort
6576 list
6577 (when org-agenda-before-sorting-filter-function
6578 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6579 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6581 (defun org-agenda-highlight-todo (x)
6582 (let ((org-done-keywords org-done-keywords-for-agenda)
6583 (case-fold-search nil)
6585 (if (eq x 'line)
6586 (save-excursion
6587 (beginning-of-line 1)
6588 (setq re (org-get-at-bol 'org-todo-regexp))
6589 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6590 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6591 (add-text-properties (match-beginning 0) (match-end 1)
6592 (list 'face (org-get-todo-face 1)))
6593 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6594 (delete-region (match-beginning 1) (1- (match-end 0)))
6595 (goto-char (match-beginning 1))
6596 (insert (format org-agenda-todo-keyword-format s)))))
6597 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6598 (setq re (get-text-property 0 'org-todo-regexp x))
6599 (when (and re
6600 ;; Test `pl' because if there's no heading content,
6601 ;; there's no point matching to highlight. Note
6602 ;; that if we didn't test `pl' first, and there
6603 ;; happened to be no keyword from `org-todo-regexp'
6604 ;; on this heading line, then the `equal' comparison
6605 ;; afterwards would spuriously succeed in the case
6606 ;; where `pl' is nil -- causing an args-out-of-range
6607 ;; error when we try to add text properties to text
6608 ;; that isn't there.
6610 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6611 x pl) pl))
6612 (add-text-properties
6613 (or (match-end 1) (match-end 0)) (match-end 0)
6614 (list 'face (org-get-todo-face (match-string 2 x)))
6616 (when (match-end 1)
6617 (setq x (concat (substring x 0 (match-end 1))
6618 (format org-agenda-todo-keyword-format
6619 (match-string 2 x))
6620 (org-add-props " " (text-properties-at 0 x))
6621 (substring x (match-end 3)))))))
6622 x)))
6624 (defsubst org-cmp-priority (a b)
6625 "Compare the priorities of string A and B."
6626 (let ((pa (or (get-text-property 1 'priority a) 0))
6627 (pb (or (get-text-property 1 'priority b) 0)))
6628 (cond ((> pa pb) +1)
6629 ((< pa pb) -1))))
6631 (defsubst org-cmp-effort (a b)
6632 "Compare the effort values of string A and B."
6633 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6634 (ea (or (get-text-property 1 'effort-minutes a) def))
6635 (eb (or (get-text-property 1 'effort-minutes b) def)))
6636 (cond ((> ea eb) +1)
6637 ((< ea eb) -1))))
6639 (defsubst org-cmp-category (a b)
6640 "Compare the string values of categories of strings A and B."
6641 (let ((ca (or (get-text-property 1 'org-category a) ""))
6642 (cb (or (get-text-property 1 'org-category b) "")))
6643 (cond ((string-lessp ca cb) -1)
6644 ((string-lessp cb ca) +1))))
6646 (defsubst org-cmp-todo-state (a b)
6647 "Compare the todo states of strings A and B."
6648 (let* ((ma (or (get-text-property 1 'org-marker a)
6649 (get-text-property 1 'org-hd-marker a)))
6650 (mb (or (get-text-property 1 'org-marker b)
6651 (get-text-property 1 'org-hd-marker b)))
6652 (fa (and ma (marker-buffer ma)))
6653 (fb (and mb (marker-buffer mb)))
6654 (todo-kwds
6655 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6656 (and fb (with-current-buffer fb org-todo-keywords-1))))
6657 (ta (or (get-text-property 1 'todo-state a) ""))
6658 (tb (or (get-text-property 1 'todo-state b) ""))
6659 (la (- (length (member ta todo-kwds))))
6660 (lb (- (length (member tb todo-kwds))))
6661 (donepa (member ta org-done-keywords-for-agenda))
6662 (donepb (member tb org-done-keywords-for-agenda)))
6663 (cond ((and donepa (not donepb)) -1)
6664 ((and (not donepa) donepb) +1)
6665 ((< la lb) -1)
6666 ((< lb la) +1))))
6668 (defsubst org-cmp-alpha (a b)
6669 "Compare the headlines, alphabetically."
6670 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6671 (plb (text-property-any 0 (length b) 'org-heading t b))
6672 (ta (and pla (substring a pla)))
6673 (tb (and plb (substring b plb))))
6674 (when pla
6675 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6676 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6677 (setq ta (substring ta (match-end 0))))
6678 (setq ta (downcase ta)))
6679 (when plb
6680 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6681 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6682 (setq tb (substring tb (match-end 0))))
6683 (setq tb (downcase tb)))
6684 (cond ((not ta) +1)
6685 ((not tb) -1)
6686 ((string-lessp ta tb) -1)
6687 ((string-lessp tb ta) +1))))
6689 (defsubst org-cmp-tag (a b)
6690 "Compare the string values of the first tags of A and B."
6691 (let ((ta (car (last (get-text-property 1 'tags a))))
6692 (tb (car (last (get-text-property 1 'tags b)))))
6693 (cond ((not ta) +1)
6694 ((not tb) -1)
6695 ((string-lessp ta tb) -1)
6696 ((string-lessp tb ta) +1))))
6698 (defsubst org-cmp-time (a b)
6699 "Compare the time-of-day values of strings A and B."
6700 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6701 (ta (or (get-text-property 1 'time-of-day a) def))
6702 (tb (or (get-text-property 1 'time-of-day b) def)))
6703 (cond ((< ta tb) -1)
6704 ((< tb ta) +1))))
6706 (defsubst org-cmp-habit-p (a b)
6707 "Compare the todo states of strings A and B."
6708 (let ((ha (get-text-property 1 'org-habit-p a))
6709 (hb (get-text-property 1 'org-habit-p b)))
6710 (cond ((and ha (not hb)) -1)
6711 ((and (not ha) hb) +1))))
6713 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6715 (defun org-entries-lessp (a b)
6716 "Predicate for sorting agenda entries."
6717 ;; The following variables will be used when the form is evaluated.
6718 ;; So even though the compiler complains, keep them.
6719 (let* ((ss org-agenda-sorting-strategy-selected)
6720 (time-up (and (org-em 'time-up 'time-down ss)
6721 (org-cmp-time a b)))
6722 (time-down (if time-up (- time-up) nil))
6723 (priority-up (and (org-em 'priority-up 'priority-down ss)
6724 (org-cmp-priority a b)))
6725 (priority-down (if priority-up (- priority-up) nil))
6726 (effort-up (and (org-em 'effort-up 'effort-down ss)
6727 (org-cmp-effort a b)))
6728 (effort-down (if effort-up (- effort-up) nil))
6729 (category-up (and (or (org-em 'category-up 'category-down ss)
6730 (memq 'category-keep ss))
6731 (org-cmp-category a b)))
6732 (category-down (if category-up (- category-up) nil))
6733 (category-keep (if category-up +1 nil))
6734 (tag-up (and (org-em 'tag-up 'tag-down ss)
6735 (org-cmp-tag a b)))
6736 (tag-down (if tag-up (- tag-up) nil))
6737 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6738 (org-cmp-todo-state a b)))
6739 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6740 (habit-up (and (org-em 'habit-up 'habit-down ss)
6741 (org-cmp-habit-p a b)))
6742 (habit-down (if habit-up (- habit-up) nil))
6743 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6744 (org-cmp-alpha a b)))
6745 (alpha-down (if alpha-up (- alpha-up) nil))
6746 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6747 user-defined-up user-defined-down)
6748 (if (and need-user-cmp org-agenda-cmp-user-defined
6749 (functionp org-agenda-cmp-user-defined))
6750 (setq user-defined-up
6751 (funcall org-agenda-cmp-user-defined a b)
6752 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6753 (cdr (assoc
6754 (eval (cons 'or org-agenda-sorting-strategy-selected))
6755 '((-1 . t) (1 . nil) (nil . nil))))))
6757 ;;; Agenda restriction lock
6759 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6760 "Overlay to mark the headline to which agenda commands are restricted.")
6761 (overlay-put org-agenda-restriction-lock-overlay
6762 'face 'org-agenda-restriction-lock)
6763 (overlay-put org-agenda-restriction-lock-overlay
6764 'help-echo "Agendas are currently limited to this subtree.")
6765 (org-detach-overlay org-agenda-restriction-lock-overlay)
6767 (defun org-agenda-set-restriction-lock (&optional type)
6768 "Set restriction lock for agenda, to current subtree or file.
6769 Restriction will be the file if TYPE is `file', or if type is the
6770 universal prefix '(4), or if the cursor is before the first headline
6771 in the file. Otherwise, restriction will be to the current subtree."
6772 (interactive "P")
6773 (and (equal type '(4)) (setq type 'file))
6774 (setq type (cond
6775 (type type)
6776 ((org-at-heading-p) 'subtree)
6777 ((condition-case nil (org-back-to-heading t) (error nil))
6778 'subtree)
6779 (t 'file)))
6780 (if (eq type 'subtree)
6781 (progn
6782 (setq org-agenda-restrict t)
6783 (setq org-agenda-overriding-restriction 'subtree)
6784 (put 'org-agenda-files 'org-restrict
6785 (list (buffer-file-name (buffer-base-buffer))))
6786 (org-back-to-heading t)
6787 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6788 (move-marker org-agenda-restrict-begin (point))
6789 (move-marker org-agenda-restrict-end
6790 (save-excursion (org-end-of-subtree t)))
6791 (message "Locking agenda restriction to subtree"))
6792 (put 'org-agenda-files 'org-restrict
6793 (list (buffer-file-name (buffer-base-buffer))))
6794 (setq org-agenda-restrict nil)
6795 (setq org-agenda-overriding-restriction 'file)
6796 (move-marker org-agenda-restrict-begin nil)
6797 (move-marker org-agenda-restrict-end nil)
6798 (message "Locking agenda restriction to file"))
6799 (setq current-prefix-arg nil)
6800 (org-agenda-maybe-redo))
6802 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6803 "Remove the agenda restriction lock."
6804 (interactive "P")
6805 (org-detach-overlay org-agenda-restriction-lock-overlay)
6806 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6807 (setq org-agenda-overriding-restriction nil)
6808 (setq org-agenda-restrict nil)
6809 (put 'org-agenda-files 'org-restrict nil)
6810 (move-marker org-agenda-restrict-begin nil)
6811 (move-marker org-agenda-restrict-end nil)
6812 (setq current-prefix-arg nil)
6813 (message "Agenda restriction lock removed")
6814 (or noupdate (org-agenda-maybe-redo)))
6816 (defun org-agenda-maybe-redo ()
6817 "If there is any window showing the agenda view, update it."
6818 (let ((w (get-buffer-window org-agenda-buffer-name t))
6819 (w0 (selected-window)))
6820 (when w
6821 (select-window w)
6822 (org-agenda-redo)
6823 (select-window w0)
6824 (if org-agenda-overriding-restriction
6825 (message "Agenda view shifted to new %s restriction"
6826 org-agenda-overriding-restriction)
6827 (message "Agenda restriction lock removed")))))
6829 ;;; Agenda commands
6831 (defun org-agenda-check-type (error &rest types)
6832 "Check if agenda buffer is of allowed type.
6833 If ERROR is non-nil, throw an error, otherwise just return nil."
6834 (if (not org-agenda-type)
6835 (error "No Org agenda currently displayed")
6836 (if (memq org-agenda-type types)
6838 (if error
6839 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6840 nil))))
6842 (defun org-agenda-Quit ()
6843 "Exit the agenda and kill buffers loaded by `org-agenda'.
6844 Also restore the window configuration."
6845 (interactive)
6846 (if org-agenda-columns-active
6847 (org-columns-quit)
6848 (let ((buf (current-buffer)))
6849 (if (eq org-agenda-window-setup 'other-frame)
6850 (progn
6851 (org-agenda-reset-markers)
6852 (kill-buffer buf)
6853 (org-columns-remove-overlays)
6854 (setq org-agenda-archives-mode nil)
6855 (delete-frame))
6856 (and (not (eq org-agenda-window-setup 'current-window))
6857 (not (one-window-p))
6858 (delete-window))
6859 (org-agenda-reset-markers)
6860 (kill-buffer buf)
6861 (org-columns-remove-overlays)
6862 (setq org-agenda-archives-mode nil)))
6863 ;; Maybe restore the pre-agenda window configuration.
6864 (and org-agenda-restore-windows-after-quit
6865 (not (eq org-agenda-window-setup 'other-frame))
6866 org-agenda-pre-window-conf
6867 (set-window-configuration org-agenda-pre-window-conf)
6868 (setq org-agenda-pre-window-conf nil))))
6870 (defun org-agenda-quit ()
6871 "Exit the agenda and restore the window configuration.
6872 When `org-agenda-sticky' is non-nil, only bury the agenda."
6873 (interactive)
6874 (if (and (eq org-indirect-buffer-display 'other-window)
6875 org-last-indirect-buffer)
6876 (delete-window (get-buffer-window org-last-indirect-buffer)))
6877 (if org-agenda-columns-active
6878 (org-columns-quit)
6879 (if org-agenda-sticky
6880 (let ((buf (current-buffer)))
6881 (if (eq org-agenda-window-setup 'other-frame)
6882 (progn
6883 (delete-frame))
6884 (and (not (eq org-agenda-window-setup 'current-window))
6885 (not (one-window-p))
6886 (delete-window)))
6887 (with-current-buffer buf
6888 (bury-buffer)
6889 ;; Maybe restore the pre-agenda window configuration.
6890 (and org-agenda-restore-windows-after-quit
6891 (not (eq org-agenda-window-setup 'other-frame))
6892 org-agenda-pre-window-conf
6893 (set-window-configuration org-agenda-pre-window-conf)
6894 (setq org-agenda-pre-window-conf nil))))
6895 (org-agenda-Quit))))
6897 (defun org-agenda-exit ()
6898 "Exit the agenda and restore the window configuration.
6899 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
6900 buffers visited directly by the user will not be touched."
6901 (interactive)
6902 (org-release-buffers org-agenda-new-buffers)
6903 (setq org-agenda-new-buffers nil)
6904 (org-agenda-Quit))
6906 (defun org-agenda-kill-all-agenda-buffers ()
6907 "Kill all buffers in `org-agenda-mode'.
6908 This is used when toggling sticky agendas.
6909 You can also explicitly invoke it with `C-c a C-k'."
6910 (interactive)
6911 (let (blist)
6912 (dolist (buf (buffer-list))
6913 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6914 (push buf blist)))
6915 (mapc 'kill-buffer blist)))
6917 (defun org-agenda-execute (arg)
6918 "Execute another agenda command, keeping same window.
6919 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6920 in the agenda."
6921 (interactive "P")
6922 (let ((org-agenda-window-setup 'current-window))
6923 (org-agenda arg)))
6925 (defun org-agenda-redo (&optional all)
6926 "Rebuild possibly ALL agenda view(s) in the current buffer."
6927 (interactive "P")
6928 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6929 (cpa (unless (eq all t) current-prefix-arg))
6930 (org-agenda-doing-sticky-redo org-agenda-sticky)
6931 (org-agenda-sticky nil)
6932 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6933 org-agenda-buffer-name))
6934 (org-agenda-keep-modes t)
6935 (tag-filter org-agenda-tag-filter)
6936 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6937 (top-cat-filter org-agenda-top-category-filter)
6938 (cat-filter org-agenda-category-filter)
6939 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6940 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6941 (cols org-agenda-columns-active)
6942 (line (org-current-line))
6943 (window-line (- line (org-current-line (window-start))))
6944 (lprops (get 'org-agenda-redo-command 'org-lprops))
6945 (redo-cmd (get-text-property p 'org-redo-cmd))
6946 (last-args (get-text-property p 'org-last-args))
6947 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6948 (org-agenda-overriding-cmd-arguments
6949 (unless (eq all t)
6950 (cond ((listp last-args)
6951 (cons (or cpa (car last-args)) (cdr last-args)))
6952 ((stringp last-args)
6953 last-args))))
6954 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6955 (put 'org-agenda-tag-filter :preset-filter nil)
6956 (put 'org-agenda-category-filter :preset-filter nil)
6957 (and cols (org-columns-quit))
6958 (message "Rebuilding agenda buffer...")
6959 (if series-redo-cmd
6960 (eval series-redo-cmd)
6961 (org-let lprops '(eval redo-cmd)))
6962 (setq org-agenda-undo-list nil
6963 org-agenda-pending-undo-list nil)
6964 (message "Rebuilding agenda buffer...done")
6965 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6966 (put 'org-agenda-category-filter :preset-filter cat-preset)
6967 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6968 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6969 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6970 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6971 (org-goto-line line)
6972 (recenter window-line)))
6974 (defvar org-global-tags-completion-table nil)
6975 (defvar org-agenda-filter-form nil)
6976 (defvar org-agenda-filtered-by-category nil)
6978 (defun org-agenda-filter-by-category (strip)
6979 "Keep only those lines in the agenda buffer that have a specific category.
6980 The category is that of the current line."
6981 (interactive "P")
6982 (if (and org-agenda-filtered-by-category
6983 org-agenda-category-filter)
6984 (org-agenda-filter-show-all-cat)
6985 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6986 (if cat (org-agenda-filter-apply
6987 (list (concat (if strip "-" "+") cat)) 'category)
6988 (error "No category at point")))))
6990 (defun org-find-top-category (&optional pos)
6991 (save-excursion
6992 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6993 (if pos (goto-char pos))
6994 ;; Skip up to the topmost parent
6995 (while (ignore-errors (outline-up-heading 1) t))
6996 (ignore-errors
6997 (nth 4 (org-heading-components))))))
6999 (defvar org-agenda-filtered-by-top-category nil)
7001 (defun org-agenda-filter-by-top-category (strip)
7002 "Keep only those lines in the agenda buffer that have a specific category.
7003 The category is that of the current line."
7004 (interactive "P")
7005 (if org-agenda-filtered-by-top-category
7006 (progn
7007 (setq org-agenda-filtered-by-top-category nil
7008 org-agenda-top-category-filter nil)
7009 (org-agenda-filter-show-all-cat))
7010 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7011 (if cat (org-agenda-filter-top-category-apply cat strip)
7012 (error "No top-level category at point")))))
7014 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7015 "Keep only those lines in the agenda buffer that have a specific tag.
7016 The tag is selected with its fast selection letter, as configured.
7017 With prefix argument STRIP, remove all lines that do have the tag.
7018 A lisp caller can specify CHAR. NARROW means that the new tag should be
7019 used to narrow the search - the interactive user can also press `-' or `+'
7020 to switch to narrowing."
7021 (interactive "P")
7022 (let* ((alist org-tag-alist-for-agenda)
7023 (tag-chars (mapconcat
7024 (lambda (x) (if (and (not (symbolp (car x)))
7025 (cdr x))
7026 (char-to-string (cdr x))
7027 ""))
7028 alist ""))
7029 (efforts (org-split-string
7030 (or (cdr (assoc (concat org-effort-property "_ALL")
7031 org-global-properties))
7032 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7033 "")))
7034 (effort-op org-agenda-filter-effort-default-operator)
7035 (effort-prompt "")
7036 (inhibit-read-only t)
7037 (current org-agenda-tag-filter)
7038 maybe-refresh a n tag)
7039 (unless char
7040 (message
7041 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7042 (if narrow "Narrow" "Filter") tag-chars
7043 (if org-agenda-auto-exclude-function "[RET], " ""))
7044 (setq char (read-char-exclusive)))
7045 (when (member char '(?+ ?-))
7046 ;; Narrowing down
7047 (cond ((equal char ?-) (setq strip t narrow t))
7048 ((equal char ?+) (setq strip nil narrow t)))
7049 (message
7050 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7051 (setq char (read-char-exclusive)))
7052 (when (member char '(?< ?> ?= ??))
7053 ;; An effort operator
7054 (setq effort-op (char-to-string char))
7055 (setq alist nil) ; to make sure it will be interpreted as effort.
7056 (unless (equal char ??)
7057 (loop for i from 0 to 9 do
7058 (setq effort-prompt
7059 (concat
7060 effort-prompt " ["
7061 (if (= i 9) "0" (int-to-string (1+ i)))
7062 "]" (nth i efforts))))
7063 (message "Effort%s: %s " effort-op effort-prompt)
7064 (setq char (read-char-exclusive))
7065 (when (or (< char ?0) (> char ?9))
7066 (error "Need 1-9,0 to select effort"))))
7067 (when (equal char ?\t)
7068 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7069 (org-set-local 'org-global-tags-completion-table
7070 (org-global-tags-completion-table)))
7071 (let ((completion-ignore-case t))
7072 (setq tag (org-icompleting-read
7073 "Tag: " org-global-tags-completion-table))))
7074 (cond
7075 ((equal char ?\r)
7076 (org-agenda-filter-show-all-tag)
7077 (when org-agenda-auto-exclude-function
7078 (setq org-agenda-tag-filter '())
7079 (dolist (tag (org-agenda-get-represented-tags))
7080 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7081 (if modifier
7082 (push modifier org-agenda-tag-filter))))
7083 (if (not (null org-agenda-tag-filter))
7084 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7085 (setq maybe-refresh t))
7086 ((equal char ?/)
7087 (org-agenda-filter-show-all-tag)
7088 (when (get 'org-agenda-tag-filter :preset-filter)
7089 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7090 (setq maybe-refresh t))
7091 ((equal char ?. )
7092 (setq org-agenda-tag-filter
7093 (mapcar (lambda(tag) (concat "+" tag))
7094 (org-get-at-bol 'tags)))
7095 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7096 (setq maybe-refresh t))
7097 ((or (equal char ?\ )
7098 (setq a (rassoc char alist))
7099 (and (>= char ?0) (<= char ?9)
7100 (setq n (if (= char ?0) 9 (- char ?0 1))
7101 tag (concat effort-op (nth n efforts))
7102 a (cons tag nil)))
7103 (and (= char ??)
7104 (setq tag "?eff")
7105 a (cons tag nil))
7106 (and tag (setq a (cons tag nil))))
7107 (org-agenda-filter-show-all-tag)
7108 (setq tag (car a))
7109 (setq org-agenda-tag-filter
7110 (cons (concat (if strip "-" "+") tag)
7111 (if narrow current nil)))
7112 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7113 (setq maybe-refresh t))
7114 (t (error "Invalid tag selection character %c" char)))
7115 (when (and maybe-refresh
7116 (eq org-agenda-clockreport-mode 'with-filter))
7117 (org-agenda-redo))))
7119 (defun org-agenda-get-represented-tags ()
7120 "Get a list of all tags currently represented in the agenda."
7121 (let (p tags)
7122 (save-excursion
7123 (goto-char (point-min))
7124 (while (setq p (next-single-property-change (point) 'tags))
7125 (goto-char p)
7126 (mapc (lambda (x) (add-to-list 'tags x))
7127 (get-text-property (point) 'tags))))
7128 tags))
7130 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7131 "Refine the current filter. See `org-agenda-filter-by-tag'."
7132 (interactive "P")
7133 (org-agenda-filter-by-tag strip char 'refine))
7135 (defun org-agenda-filter-make-matcher ()
7136 "Create the form that tests a line for agenda filter."
7137 (let (f f1)
7138 ;; first compute the tag-filter matcher
7139 (dolist (x (delete-dups
7140 (append (get 'org-agenda-tag-filter
7141 :preset-filter) org-agenda-tag-filter)))
7142 (if (member x '("-" "+"))
7143 (setq f1 (if (equal x "-") 'tags '(not tags)))
7144 (if (string-match "[<=>?]" x)
7145 (setq f1 (org-agenda-filter-effort-form x))
7146 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7147 (if (equal (string-to-char x) ?-)
7148 (setq f1 (list 'not f1))))
7149 (push f1 f))
7150 ;; then compute the category-filter matcher
7151 (dolist (x (delete-dups
7152 (append (get 'org-agenda-category-filter
7153 :preset-filter) org-agenda-category-filter)))
7154 (if (equal "-" (substring x 0 1))
7155 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7156 (setq f1 (list 'equal (substring x 1) 'cat)))
7157 (push f1 f))
7158 (cons 'and (nreverse f))))
7160 (defun org-agenda-filter-effort-form (e)
7161 "Return the form to compare the effort of the current line with what E says.
7162 E looks like \"+<2:25\"."
7163 (let (op)
7164 (setq e (substring e 1))
7165 (setq op (string-to-char e) e (substring e 1))
7166 (setq op (cond ((equal op ?<) '<=)
7167 ((equal op ?>) '>=)
7168 ((equal op ??) op)
7169 (t '=)))
7170 (list 'org-agenda-compare-effort (list 'quote op)
7171 (org-duration-string-to-minutes e))))
7173 (defun org-agenda-compare-effort (op value)
7174 "Compare the effort of the current line with VALUE, using OP.
7175 If the line does not have an effort defined, return nil."
7176 (let ((eff (org-get-at-bol 'effort-minutes)))
7177 (if (equal op ??)
7178 (not eff)
7179 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7180 value))))
7182 (defun org-agenda-filter-apply (filter type)
7183 "Set FILTER as the new agenda filter and apply it."
7184 (let (tags cat)
7185 (if (eq type 'tag)
7186 (setq org-agenda-tag-filter filter)
7187 (setq org-agenda-category-filter filter))
7188 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7189 (if (and (eq type 'category)
7190 (not (equal (substring (car filter) 0 1) "-")))
7191 ;; Only set `org-agenda-filtered-by-category' to t
7192 ;; when a unique category is used as the filter
7193 (setq org-agenda-filtered-by-category t))
7194 (org-agenda-set-mode-name)
7195 (save-excursion
7196 (goto-char (point-min))
7197 (while (not (eobp))
7198 (if (org-get-at-bol 'org-marker)
7199 (progn
7200 (setq tags (org-get-at-bol 'tags) ; used in eval
7201 cat (get-text-property (point) 'org-category))
7202 (if (not (eval org-agenda-filter-form))
7203 (org-agenda-filter-hide-line type))
7204 (beginning-of-line 2))
7205 (beginning-of-line 2))))
7206 (if (get-char-property (point) 'invisible)
7207 (ignore-errors (org-agenda-previous-line)))))
7209 (defun org-agenda-filter-top-category-apply (category &optional negative)
7210 "Set FILTER as the new agenda filter and apply it."
7211 (org-agenda-set-mode-name)
7212 (save-excursion
7213 (goto-char (point-min))
7214 (while (not (eobp))
7215 (let* ((pos (org-get-at-bol 'org-hd-marker))
7216 (topcat (and pos (org-find-top-category pos))))
7217 (if (and topcat (funcall (if negative 'identity 'not)
7218 (string= category topcat)))
7219 (org-agenda-filter-hide-line 'category)))
7220 (beginning-of-line 2)))
7221 (if (get-char-property (point) 'invisible)
7222 (org-agenda-previous-line))
7223 (setq org-agenda-top-category-filter category
7224 org-agenda-filtered-by-top-category t))
7226 (defun org-agenda-filter-hide-line (type)
7227 (let (ov)
7228 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7229 (point-at-eol)))
7230 (overlay-put ov 'invisible t)
7231 (overlay-put ov 'type type)
7232 (if (eq type 'tag)
7233 (push ov org-agenda-tag-filter-overlays)
7234 (push ov org-agenda-cat-filter-overlays))))
7236 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7237 (setq pos (or pos (point)))
7238 (save-excursion
7239 (dolist (ov (overlays-at pos))
7240 (when (and (overlay-get ov 'invisible)
7241 (eq (overlay-get ov 'type) 'tag))
7242 (goto-char pos)
7243 (if (< (overlay-start ov) (point-at-eol))
7244 (move-overlay ov (point-at-eol)
7245 (overlay-end ov)))))))
7247 (defun org-agenda-filter-show-all-tag nil
7248 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7249 (setq org-agenda-tag-filter-overlays nil
7250 org-agenda-tag-filter nil
7251 org-agenda-filter-form nil)
7252 (org-agenda-set-mode-name))
7254 (defun org-agenda-filter-show-all-cat nil
7255 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7256 (setq org-agenda-cat-filter-overlays nil
7257 org-agenda-filtered-by-category nil
7258 org-agenda-category-filter nil
7259 org-agenda-filter-form nil)
7260 (org-agenda-set-mode-name))
7262 (defun org-agenda-manipulate-query-add ()
7263 "Manipulate the query by adding a search term with positive selection.
7264 Positive selection means the term must be matched for selection of an entry."
7265 (interactive)
7266 (org-agenda-manipulate-query ?\[))
7267 (defun org-agenda-manipulate-query-subtract ()
7268 "Manipulate the query by adding a search term with negative selection.
7269 Negative selection means term must not be matched for selection of an entry."
7270 (interactive)
7271 (org-agenda-manipulate-query ?\]))
7272 (defun org-agenda-manipulate-query-add-re ()
7273 "Manipulate the query by adding a search regexp with positive selection.
7274 Positive selection means the regexp must match for selection of an entry."
7275 (interactive)
7276 (org-agenda-manipulate-query ?\{))
7277 (defun org-agenda-manipulate-query-subtract-re ()
7278 "Manipulate the query by adding a search regexp with negative selection.
7279 Negative selection means regexp must not match for selection of an entry."
7280 (interactive)
7281 (org-agenda-manipulate-query ?\}))
7282 (defun org-agenda-manipulate-query (char)
7283 (cond
7284 ((memq org-agenda-type '(timeline agenda))
7285 (let ((org-agenda-include-inactive-timestamps t))
7286 (org-agenda-redo))
7287 (message "Display now includes inactive timestamps as well"))
7288 ((eq org-agenda-type 'search)
7289 (org-add-to-string
7290 'org-agenda-query-string
7291 (if org-agenda-last-search-view-search-was-boolean
7292 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7293 (?\{ . " +{}") (?\} . " -{}"))))
7294 " "))
7295 (setq org-agenda-redo-command
7296 (list 'org-search-view
7297 (car (get-text-property (min (1- (point-max)) (point))
7298 'org-last-args))
7299 org-agenda-query-string
7300 (+ (length org-agenda-query-string)
7301 (if (member char '(?\{ ?\})) 0 1))))
7302 (set-register org-agenda-query-register org-agenda-query-string)
7303 (let ((org-agenda-overriding-arguments
7304 (cdr org-agenda-redo-command)))
7305 (org-agenda-redo)))
7306 (t (error "Cannot manipulate query for %s-type agenda buffers"
7307 org-agenda-type))))
7309 (defun org-add-to-string (var string)
7310 (set var (concat (symbol-value var) string)))
7312 (defun org-agenda-goto-date (span)
7313 "Jump to DATE in agenda."
7314 (interactive "P")
7315 (let* ((org-read-date-prefer-future
7316 (eval org-agenda-jump-prefer-future))
7317 (date (org-read-date))
7318 (org-agenda-sticky-orig org-agenda-sticky)
7319 (org-agenda-buffer-tmp-name (buffer-name))
7320 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7321 (0-arg (or current-prefix-arg (car args)))
7322 (2-arg (nth 2 args))
7323 (newcmd (list 'org-agenda-list 0-arg date
7324 (org-agenda-span-to-ndays 2-arg)))
7325 (newargs (cdr newcmd))
7326 (inhibit-read-only t)
7327 org-agenda-sticky)
7328 (if (not (org-agenda-check-type t 'agenda))
7329 (error "Not available in non-agenda blocks")
7330 (add-text-properties (point-min) (point-max)
7331 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7332 (org-agenda-redo)
7333 (setq org-agenda-sticky org-agenda-sticky-orig
7334 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7336 (defun org-agenda-goto-today ()
7337 "Go to today."
7338 (interactive)
7339 (org-agenda-check-type t 'timeline 'agenda)
7340 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7341 (curspan (nth 2 args))
7342 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7343 (cond
7344 (tdpos (goto-char tdpos))
7345 ((eq org-agenda-type 'agenda)
7346 (let* ((sd (org-agenda-compute-starting-span
7347 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7348 (org-agenda-overriding-arguments args))
7349 (setf (nth 1 org-agenda-overriding-arguments) sd)
7350 (org-agenda-redo)
7351 (org-agenda-find-same-or-today-or-agenda)))
7352 (t (error "Cannot find today")))))
7354 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7355 (goto-char
7356 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7357 (text-property-any (point-min) (point-max) 'org-today t)
7358 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7359 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7360 (org-agenda-goto-block-beginning))
7361 (point-min))))
7363 (defun org-agenda-goto-block-beginning ()
7364 "Go the agenda block beginning."
7365 (interactive)
7366 (if (not (derived-mode-p 'org-agenda-mode))
7367 (error "Cannot execute this command outside of org-agenda-mode buffers")
7368 (let (dest)
7369 (save-excursion
7370 (unless (looking-at "\\'")
7371 (forward-char))
7372 (let* ((prop 'org-agenda-structural-header)
7373 (p (previous-single-property-change (point) prop))
7374 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7375 (1- (point))) prop)))
7376 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7377 (if (not dest)
7378 (error "Cannot find the beginning of the blog")
7379 (goto-char dest)
7380 (move-beginning-of-line 1)))))
7382 (defun org-agenda-later (arg)
7383 "Go forward in time by the current span.
7384 With prefix ARG, go forward that many times the current span."
7385 (interactive "p")
7386 (org-agenda-check-type t 'agenda)
7387 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7388 (span (or (nth 2 args) org-agenda-current-span))
7389 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7390 (greg (calendar-gregorian-from-absolute sd))
7391 (cnt (org-get-at-bol 'org-day-cnt))
7392 greg2)
7393 (cond
7394 ((numberp span)
7395 (setq sd (+ (* span arg) sd)))
7396 ((eq span 'day)
7397 (setq sd (+ arg sd)))
7398 ((eq span 'week)
7399 (setq sd (+ (* 7 arg) sd)))
7400 ((eq span 'month)
7401 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7402 sd (calendar-absolute-from-gregorian greg2))
7403 (setcar greg2 (1+ (car greg2))))
7404 ((eq span 'year)
7405 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7406 sd (calendar-absolute-from-gregorian greg2))
7407 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7409 (setq sd (+ (* span arg) sd))))
7410 (let ((org-agenda-overriding-cmd
7411 ;; `cmd' may have been set by `org-agenda-run-series' which
7412 ;; uses `org-agenda-overriding-cmd' to decide whether
7413 ;; overriding is allowed for `cmd'
7414 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7415 (org-agenda-overriding-arguments
7416 (list (car args) sd span)))
7417 (org-agenda-redo)
7418 (org-agenda-find-same-or-today-or-agenda cnt))))
7420 (defun org-agenda-earlier (arg)
7421 "Go backward in time by the current span.
7422 With prefix ARG, go backward that many times the current span."
7423 (interactive "p")
7424 (org-agenda-later (- arg)))
7426 (defun org-agenda-view-mode-dispatch ()
7427 "Call one of the view mode commands."
7428 (interactive)
7429 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7430 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7431 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7432 (let ((a (read-char-exclusive)))
7433 (case a
7434 (?\ (call-interactively 'org-agenda-reset-view))
7435 (?d (call-interactively 'org-agenda-day-view))
7436 (?w (call-interactively 'org-agenda-week-view))
7437 (?m (call-interactively 'org-agenda-month-view))
7438 (?y (call-interactively 'org-agenda-year-view))
7439 (?l (call-interactively 'org-agenda-log-mode))
7440 (?L (org-agenda-log-mode '(4)))
7441 (?c (org-agenda-log-mode 'clockcheck))
7442 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7443 (?a (call-interactively 'org-agenda-archives-mode))
7444 (?A (org-agenda-archives-mode 'files))
7445 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7446 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7447 (?G (call-interactively 'org-agenda-toggle-time-grid))
7448 (?D (call-interactively 'org-agenda-toggle-diary))
7449 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7450 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7451 (org-agenda-check-type t 'timeline 'agenda)
7452 (org-agenda-redo))
7453 (message "Display now includes inactive timestamps as well"))
7454 (?q (message "Abort"))
7455 (otherwise (error "Invalid key" )))))
7457 (defun org-agenda-reset-view ()
7458 "Switch to default view for agenda."
7459 (interactive)
7460 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7461 (defun org-agenda-day-view (&optional day-of-year)
7462 "Switch to daily view for agenda.
7463 With argument DAY-OF-YEAR, switch to that day of the year."
7464 (interactive "P")
7465 (org-agenda-change-time-span 'day day-of-year))
7466 (defun org-agenda-week-view (&optional iso-week)
7467 "Switch to daily view for agenda.
7468 With argument ISO-WEEK, switch to the corresponding ISO week.
7469 If ISO-WEEK has more then 2 digits, only the last two encode the
7470 week. Any digits before this encode a year. So 200712 means
7471 week 12 of year 2007. Years in the range 1938-2037 can also be
7472 written as 2-digit years."
7473 (interactive "P")
7474 (org-agenda-change-time-span 'week iso-week))
7475 (defun org-agenda-month-view (&optional month)
7476 "Switch to monthly view for agenda.
7477 With argument MONTH, switch to that month."
7478 (interactive "P")
7479 (org-agenda-change-time-span 'month month))
7480 (defun org-agenda-year-view (&optional year)
7481 "Switch to yearly view for agenda.
7482 With argument YEAR, switch to that year.
7483 If MONTH has more then 2 digits, only the last two encode the
7484 month. Any digits before this encode a year. So 200712 means
7485 December year 2007. Years in the range 1938-2037 can also be
7486 written as 2-digit years."
7487 (interactive "P")
7488 (when year
7489 (setq year (org-small-year-to-year year)))
7490 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7491 (org-agenda-change-time-span 'year year)
7492 (error "Abort")))
7494 (defun org-agenda-change-time-span (span &optional n)
7495 "Change the agenda view to SPAN.
7496 SPAN may be `day', `week', `month', `year'."
7497 (org-agenda-check-type t 'agenda)
7498 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7499 (curspan (nth 2 args)))
7500 (if (and (not n) (equal curspan span))
7501 (error "Viewing span is already \"%s\"" span))
7502 (let* ((sd (or (org-get-at-bol 'day)
7503 (nth 1 args)
7504 org-starting-day))
7505 (sd (org-agenda-compute-starting-span sd span n))
7506 (org-agenda-overriding-cmd
7507 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7508 (org-agenda-overriding-arguments
7509 (list (car args) sd span)))
7510 (org-agenda-redo)
7511 (org-agenda-find-same-or-today-or-agenda))
7512 (org-agenda-set-mode-name)
7513 (message "Switched to %s view" span)))
7515 (defun org-agenda-compute-starting-span (sd span &optional n)
7516 "Compute starting date for agenda.
7517 SPAN may be `day', `week', `month', `year'. The return value
7518 is a cons cell with the starting date and the number of days,
7519 so that the date SD will be in that range."
7520 (let* ((greg (calendar-gregorian-from-absolute sd))
7521 (dg (nth 1 greg))
7522 (mg (car greg))
7523 (yg (nth 2 greg)))
7524 (cond
7525 ((eq span 'day)
7526 (when n
7527 (setq sd (+ (calendar-absolute-from-gregorian
7528 (list mg 1 yg))
7529 n -1))))
7530 ((eq span 'week)
7531 (let* ((nt (calendar-day-of-week
7532 (calendar-gregorian-from-absolute sd)))
7533 (d (if org-agenda-start-on-weekday
7534 (- nt org-agenda-start-on-weekday)
7537 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7538 (when n
7539 (require 'cal-iso)
7540 (when (> n 99)
7541 (setq y1 (org-small-year-to-year (/ n 100))
7542 n (mod n 100)))
7543 (setq sd
7544 (calendar-absolute-from-iso
7545 (list n 1
7546 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7547 ((eq span 'month)
7548 (let (y1)
7549 (when (and n (> n 99))
7550 (setq y1 (org-small-year-to-year (/ n 100))
7551 n (mod n 100)))
7552 (setq sd (calendar-absolute-from-gregorian
7553 (list (or n mg) 1 (or y1 yg))))))
7554 ((eq span 'year)
7555 (setq sd (calendar-absolute-from-gregorian
7556 (list 1 1 (or n yg))))))
7557 sd))
7559 (defun org-agenda-next-date-line (&optional arg)
7560 "Jump to the next line indicating a date in agenda buffer."
7561 (interactive "p")
7562 (org-agenda-check-type t 'agenda 'timeline)
7563 (beginning-of-line 1)
7564 ;; This does not work if user makes date format that starts with a blank
7565 (if (looking-at "^\\S-") (forward-char 1))
7566 (if (not (re-search-forward "^\\S-" nil t arg))
7567 (progn
7568 (backward-char 1)
7569 (error "No next date after this line in this buffer")))
7570 (goto-char (match-beginning 0)))
7572 (defun org-agenda-previous-date-line (&optional arg)
7573 "Jump to the previous line indicating a date in agenda buffer."
7574 (interactive "p")
7575 (org-agenda-check-type t 'agenda 'timeline)
7576 (beginning-of-line 1)
7577 (if (not (re-search-backward "^\\S-" nil t arg))
7578 (error "No previous date before this line in this buffer")))
7580 ;; Initialize the highlight
7581 (defvar org-hl (make-overlay 1 1))
7582 (overlay-put org-hl 'face 'highlight)
7584 (defun org-highlight (begin end &optional buffer)
7585 "Highlight a region with overlay."
7586 (move-overlay org-hl begin end (or buffer (current-buffer))))
7588 (defun org-unhighlight ()
7589 "Detach overlay INDEX."
7590 (org-detach-overlay org-hl))
7592 (defun org-unhighlight-once ()
7593 "Remove the highlight from its position, and this function from the hook."
7594 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7595 (org-unhighlight))
7597 (defvar org-agenda-pre-follow-window-conf nil)
7598 (defun org-agenda-follow-mode ()
7599 "Toggle follow mode in an agenda buffer."
7600 (interactive)
7601 (unless org-agenda-follow-mode
7602 (setq org-agenda-pre-follow-window-conf
7603 (current-window-configuration)))
7604 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7605 (unless org-agenda-follow-mode
7606 (set-window-configuration org-agenda-pre-follow-window-conf))
7607 (org-agenda-set-mode-name)
7608 (org-agenda-do-context-action)
7609 (message "Follow mode is %s"
7610 (if org-agenda-follow-mode "on" "off")))
7612 (defun org-agenda-entry-text-mode (&optional arg)
7613 "Toggle entry text mode in an agenda buffer."
7614 (interactive "P")
7615 (setq org-agenda-entry-text-mode (or (integerp arg)
7616 (not org-agenda-entry-text-mode)))
7617 (org-agenda-entry-text-hide)
7618 (and org-agenda-entry-text-mode
7619 (let ((org-agenda-entry-text-maxlines
7620 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7621 (org-agenda-entry-text-show)))
7622 (org-agenda-set-mode-name)
7623 (message "Entry text mode is %s. Maximum number of lines is %d"
7624 (if org-agenda-entry-text-mode "on" "off")
7625 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7627 (defun org-agenda-clockreport-mode (&optional with-filter)
7628 "Toggle clocktable mode in an agenda buffer.
7629 With prefix arg WITH-FILTER, make the clocktable respect the current
7630 agenda filter."
7631 (interactive "P")
7632 (org-agenda-check-type t 'agenda)
7633 (if with-filter
7634 (setq org-agenda-clockreport-mode 'with-filter)
7635 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7636 (org-agenda-set-mode-name)
7637 (org-agenda-redo)
7638 (message "Clocktable mode is %s"
7639 (if org-agenda-clockreport-mode "on" "off")))
7641 (defun org-agenda-log-mode (&optional special)
7642 "Toggle log mode in an agenda buffer.
7643 With argument SPECIAL, show all possible log items, not only the ones
7644 configured in `org-agenda-log-mode-items'.
7645 With a double `C-u' prefix arg, show *only* log items, nothing else."
7646 (interactive "P")
7647 (org-agenda-check-type t 'agenda 'timeline)
7648 (setq org-agenda-show-log
7649 (cond
7650 ((equal special '(16)) 'only)
7651 ((eq special 'clockcheck)
7652 (if (eq org-agenda-show-log 'clockcheck)
7653 nil 'clockcheck))
7654 (special '(closed clock state))
7655 (t (not org-agenda-show-log))))
7656 (org-agenda-set-mode-name)
7657 (org-agenda-redo)
7658 (message "Log mode is %s"
7659 (if org-agenda-show-log "on" "off")))
7661 (defun org-agenda-archives-mode (&optional with-files)
7662 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7663 When called with a prefix argument, include all archive files as well."
7664 (interactive "P")
7665 (setq org-agenda-archives-mode
7666 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7667 (org-agenda-set-mode-name)
7668 (org-agenda-redo)
7669 (message
7670 "%s"
7671 (cond
7672 ((eq org-agenda-archives-mode nil)
7673 "No archives are included")
7674 ((eq org-agenda-archives-mode 'trees)
7675 (format "Trees with :%s: tag are included" org-archive-tag))
7676 ((eq org-agenda-archives-mode t)
7677 (format "Trees with :%s: tag and all active archive files are included"
7678 org-archive-tag)))))
7680 (defun org-agenda-toggle-diary ()
7681 "Toggle diary inclusion in an agenda buffer."
7682 (interactive)
7683 (org-agenda-check-type t 'agenda)
7684 (setq org-agenda-include-diary (not org-agenda-include-diary))
7685 (org-agenda-redo)
7686 (org-agenda-set-mode-name)
7687 (message "Diary inclusion turned %s"
7688 (if org-agenda-include-diary "on" "off")))
7690 (defun org-agenda-toggle-deadlines ()
7691 "Toggle inclusion of entries with a deadline in an agenda buffer."
7692 (interactive)
7693 (org-agenda-check-type t 'agenda)
7694 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7695 (org-agenda-redo)
7696 (org-agenda-set-mode-name)
7697 (message "Deadlines inclusion turned %s"
7698 (if org-agenda-include-deadlines "on" "off")))
7700 (defun org-agenda-toggle-time-grid ()
7701 "Toggle time grid in an agenda buffer."
7702 (interactive)
7703 (org-agenda-check-type t 'agenda)
7704 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7705 (org-agenda-redo)
7706 (org-agenda-set-mode-name)
7707 (message "Time-grid turned %s"
7708 (if org-agenda-use-time-grid "on" "off")))
7710 (defun org-agenda-set-mode-name ()
7711 "Set the mode name to indicate all the small mode settings."
7712 (setq mode-name
7713 (list "Org-Agenda"
7714 (if (get 'org-agenda-files 'org-restrict) " []" "")
7716 '(:eval (org-agenda-span-name org-agenda-current-span))
7717 (if org-agenda-follow-mode " Follow" "")
7718 (if org-agenda-entry-text-mode " ETxt" "")
7719 (if org-agenda-include-diary " Diary" "")
7720 (if org-agenda-include-deadlines " Ddl" "")
7721 (if org-agenda-use-time-grid " Grid" "")
7722 (if (and (boundp 'org-habit-show-habits)
7723 org-habit-show-habits) " Habit" "")
7724 (cond
7725 ((consp org-agenda-show-log) " LogAll")
7726 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7727 (org-agenda-show-log " Log")
7728 (t ""))
7729 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7730 :preset-filter))
7731 '(:eval (org-propertize
7732 (concat " <"
7733 (mapconcat
7734 'identity
7735 (append
7736 (get 'org-agenda-category-filter :preset-filter)
7737 org-agenda-category-filter)
7739 ">")
7740 'face 'org-agenda-filter-category
7741 'help-echo "Category used in filtering"))
7743 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7744 :preset-filter))
7745 '(:eval (org-propertize
7746 (concat " {"
7747 (mapconcat
7748 'identity
7749 (append
7750 (get 'org-agenda-tag-filter :preset-filter)
7751 org-agenda-tag-filter)
7753 "}")
7754 'face 'org-agenda-filter-tags
7755 'help-echo "Tags used in filtering"))
7757 (if org-agenda-archives-mode
7758 (if (eq org-agenda-archives-mode t)
7759 " Archives"
7760 (format " :%s:" org-archive-tag))
7762 (if org-agenda-clockreport-mode
7763 (if (eq org-agenda-clockreport-mode 'with-filter)
7764 " Clock{}" " Clock")
7765 "")))
7766 (force-mode-line-update))
7768 (define-obsolete-function-alias
7769 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7771 (defun org-agenda-update-agenda-type ()
7772 "Update the agenda type after each command."
7773 (setq org-agenda-type
7774 (or (get-text-property (point) 'org-agenda-type)
7775 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7777 (defun org-agenda-next-line ()
7778 "Move cursor to the next line, and show if follow mode is active."
7779 (interactive)
7780 (call-interactively 'next-line)
7781 (org-agenda-do-context-action))
7783 (defun org-agenda-previous-line ()
7784 "Move cursor to the previous line, and show if follow-mode is active."
7785 (interactive)
7786 (call-interactively 'previous-line)
7787 (org-agenda-do-context-action))
7789 (defun org-agenda-next-item (n)
7790 "Move cursor to next agenda item."
7791 (interactive "p")
7792 (let ((col (current-column)))
7793 (dotimes (c n)
7794 (when (next-single-property-change (point-at-eol) 'org-marker)
7795 (move-end-of-line 1)
7796 (goto-char (next-single-property-change (point) 'org-marker))))
7797 (org-move-to-column col))
7798 (org-agenda-do-context-action))
7800 (defun org-agenda-previous-item (n)
7801 "Move cursor to next agenda item."
7802 (interactive "p")
7803 (dotimes (c n)
7804 (let ((col (current-column))
7805 (goto (save-excursion
7806 (move-end-of-line 0)
7807 (previous-single-property-change (point) 'org-marker))))
7808 (if goto (goto-char goto))
7809 (org-move-to-column col)))
7810 (org-agenda-do-context-action))
7812 (defun org-agenda-do-context-action ()
7813 "Show outline path and, maybe, follow mode window."
7814 (let ((m (org-get-at-bol 'org-marker)))
7815 (when (and (markerp m) (marker-buffer m))
7816 (and org-agenda-follow-mode
7817 (if org-agenda-follow-indirect
7818 (org-agenda-tree-to-indirect-buffer nil)
7819 (org-agenda-show)))
7820 (and org-agenda-show-outline-path
7821 (org-with-point-at m (org-display-outline-path t))))))
7823 (defun org-agenda-show-tags ()
7824 "Show the tags applicable to the current item."
7825 (interactive)
7826 (let* ((tags (org-get-at-bol 'tags)))
7827 (if tags
7828 (message "Tags are :%s:"
7829 (org-no-properties (mapconcat 'identity tags ":")))
7830 (message "No tags associated with this line"))))
7832 (defun org-agenda-goto (&optional highlight)
7833 "Go to the Org-mode file which contains the item at point."
7834 (interactive)
7835 (let* ((marker (or (org-get-at-bol 'org-marker)
7836 (org-agenda-error)))
7837 (buffer (marker-buffer marker))
7838 (pos (marker-position marker)))
7839 (switch-to-buffer-other-window buffer)
7840 (widen)
7841 (push-mark)
7842 (goto-char pos)
7843 (when (derived-mode-p 'org-mode)
7844 (org-show-context 'agenda)
7845 (save-excursion
7846 (and (outline-next-heading)
7847 (org-flag-heading nil)))) ; show the next heading
7848 (when (outline-invisible-p)
7849 (show-entry)) ; display invisible text
7850 (recenter (/ (window-height) 2))
7851 (run-hooks 'org-agenda-after-show-hook)
7852 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7854 (defvar org-agenda-after-show-hook nil
7855 "Normal hook run after an item has been shown from the agenda.
7856 Point is in the buffer where the item originated.")
7858 (defun org-agenda-kill ()
7859 "Kill the entry or subtree belonging to the current agenda entry."
7860 (interactive)
7861 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7862 (let* ((bufname-orig (buffer-name))
7863 (marker (or (org-get-at-bol 'org-marker)
7864 (org-agenda-error)))
7865 (buffer (marker-buffer marker))
7866 (pos (marker-position marker))
7867 (type (org-get-at-bol 'type))
7868 dbeg dend (n 0) conf)
7869 (org-with-remote-undo buffer
7870 (with-current-buffer buffer
7871 (save-excursion
7872 (goto-char pos)
7873 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7874 (setq dbeg (progn (org-back-to-heading t) (point))
7875 dend (org-end-of-subtree t t))
7876 (setq dbeg (point-at-bol)
7877 dend (min (point-max) (1+ (point-at-eol)))))
7878 (goto-char dbeg)
7879 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7880 (setq conf (or (eq t org-agenda-confirm-kill)
7881 (and (numberp org-agenda-confirm-kill)
7882 (> n org-agenda-confirm-kill))))
7883 (and conf
7884 (not (y-or-n-p
7885 (format "Delete entry with %d lines in buffer \"%s\"? "
7886 n (buffer-name buffer))))
7887 (error "Abort"))
7888 (let ((org-agenda-buffer-name bufname-orig))
7889 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7890 (with-current-buffer buffer (delete-region dbeg dend))
7891 (message "Agenda item and source killed"))))
7893 (defvar org-archive-default-command) ; defined in org-archive.el
7894 (defun org-agenda-archive-default ()
7895 "Archive the entry or subtree belonging to the current agenda entry."
7896 (interactive)
7897 (require 'org-archive)
7898 (org-agenda-archive-with org-archive-default-command))
7900 (defun org-agenda-archive-default-with-confirmation ()
7901 "Archive the entry or subtree belonging to the current agenda entry."
7902 (interactive)
7903 (require 'org-archive)
7904 (org-agenda-archive-with org-archive-default-command 'confirm))
7906 (defun org-agenda-archive ()
7907 "Archive the entry or subtree belonging to the current agenda entry."
7908 (interactive)
7909 (org-agenda-archive-with 'org-archive-subtree))
7911 (defun org-agenda-archive-to-archive-sibling ()
7912 "Move the entry to the archive sibling."
7913 (interactive)
7914 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7916 (defun org-agenda-archive-with (cmd &optional confirm)
7917 "Move the entry to the archive sibling."
7918 (interactive)
7919 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7920 (let* ((bufname-orig (buffer-name))
7921 (marker (or (org-get-at-bol 'org-marker)
7922 (org-agenda-error)))
7923 (buffer (marker-buffer marker))
7924 (pos (marker-position marker)))
7925 (org-with-remote-undo buffer
7926 (with-current-buffer buffer
7927 (if (derived-mode-p 'org-mode)
7928 (if (and confirm
7929 (not (y-or-n-p "Archive this subtree or entry? ")))
7930 (error "Abort")
7931 (save-excursion
7932 (goto-char pos)
7933 (let ((org-agenda-buffer-name bufname-orig))
7934 (org-remove-subtree-entries-from-agenda))
7935 (org-back-to-heading t)
7936 (funcall cmd)))
7937 (error "Archiving works only in Org-mode files"))))))
7939 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7940 "Remove all lines in the agenda that correspond to a given subtree.
7941 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7942 If this information is not given, the function uses the tree at point."
7943 (let ((buf (or buf (current-buffer))) m p)
7944 (save-excursion
7945 (unless (and beg end)
7946 (org-back-to-heading t)
7947 (setq beg (point))
7948 (org-end-of-subtree t)
7949 (setq end (point)))
7950 (set-buffer (get-buffer org-agenda-buffer-name))
7951 (save-excursion
7952 (goto-char (point-max))
7953 (beginning-of-line 1)
7954 (while (not (bobp))
7955 (when (and (setq m (org-get-at-bol 'org-marker))
7956 (equal buf (marker-buffer m))
7957 (setq p (marker-position m))
7958 (>= p beg)
7959 (< p end))
7960 (let ((inhibit-read-only t))
7961 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7962 (beginning-of-line 0))))))
7964 (defun org-agenda-refile (&optional goto rfloc no-update)
7965 "Refile the item at point."
7966 (interactive "P")
7967 (if (equal goto '(16))
7968 (org-refile-goto-last-stored)
7969 (let* ((buffer-orig (buffer-name))
7970 (marker (or (org-get-at-bol 'org-hd-marker)
7971 (org-agenda-error)))
7972 (buffer (marker-buffer marker))
7973 (pos (marker-position marker))
7974 (rfloc (or rfloc
7975 (org-refile-get-location
7976 (if goto "Goto" "Refile to") buffer
7977 org-refile-allow-creating-parent-nodes))))
7978 (with-current-buffer buffer
7979 (save-excursion
7980 (save-restriction
7981 (widen)
7982 (goto-char marker)
7983 (let ((org-agenda-buffer-name buffer-orig))
7984 (org-remove-subtree-entries-from-agenda))
7985 (org-refile goto buffer rfloc)))))
7986 (unless no-update (org-agenda-redo))))
7988 (defun org-agenda-open-link (&optional arg)
7989 "Open the link(s) in the current entry, if any.
7990 This looks for a link in the displayed line in the agenda.
7991 It also looks at the text of the entry itself."
7992 (interactive "P")
7993 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7994 (org-get-at-bol 'org-marker)))
7995 (buffer (and marker (marker-buffer marker)))
7996 (prefix (buffer-substring
7997 (point-at-bol) (point-at-eol)))
7998 (lkall (org-offer-links-in-entry buffer marker arg prefix))
7999 (lk (car lkall))
8000 (lkend (cdr lkall))
8001 trg)
8002 (cond
8003 (buffer
8004 (with-current-buffer buffer
8005 (setq trg (and (string-match org-bracket-link-regexp lk)
8006 (match-string 1 lk)))
8007 (if (or (not trg) (string-match org-any-link-re trg))
8008 (save-excursion
8009 (save-restriction
8010 (widen)
8011 (goto-char marker)
8012 (when (search-forward lk nil lkend)
8013 (goto-char (match-beginning 0))
8014 (org-open-at-point))))
8015 ;; This is an internal link, widen the buffer
8016 (switch-to-buffer-other-window buffer)
8017 (widen)
8018 (goto-char marker)
8019 (when (search-forward lk nil lkend)
8020 (goto-char (match-beginning 0))
8021 (org-open-at-point)))))
8022 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8023 (save-excursion
8024 (beginning-of-line 1)
8025 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8026 (org-open-link-from-string (match-string 1)))
8027 (t (error "No link to open here")))))
8029 (defun org-agenda-copy-local-variable (var)
8030 "Get a variable from a referenced buffer and install it here."
8031 (let ((m (org-get-at-bol 'org-marker)))
8032 (when (and m (buffer-live-p (marker-buffer m)))
8033 (org-set-local var (with-current-buffer (marker-buffer m)
8034 (symbol-value var))))))
8036 (defun org-agenda-switch-to (&optional delete-other-windows)
8037 "Go to the Org-mode file which contains the item at point."
8038 (interactive)
8039 (if (and org-return-follows-link
8040 (not (org-get-at-bol 'org-marker))
8041 (org-in-regexp org-bracket-link-regexp))
8042 (org-open-link-from-string (match-string 0))
8043 (let* ((marker (or (org-get-at-bol 'org-marker)
8044 (org-agenda-error)))
8045 (buffer (marker-buffer marker))
8046 (pos (marker-position marker)))
8047 (org-pop-to-buffer-same-window buffer)
8048 (and delete-other-windows (delete-other-windows))
8049 (widen)
8050 (goto-char pos)
8051 (when (derived-mode-p 'org-mode)
8052 (org-show-context 'agenda)
8053 (save-excursion
8054 (and (outline-next-heading)
8055 (org-flag-heading nil))) ; show the next heading
8056 (when (outline-invisible-p)
8057 (show-entry)) ; display invisible text
8058 (run-hooks 'org-agenda-after-show-hook)))))
8060 (defun org-agenda-goto-mouse (ev)
8061 "Go to the Org-mode file which contains the item at the mouse click."
8062 (interactive "e")
8063 (mouse-set-point ev)
8064 (org-agenda-goto))
8066 (defun org-agenda-show (&optional full-entry)
8067 "Display the Org-mode file which contains the item at point.
8068 With prefix argument FULL-ENTRY, make the entire entry visible
8069 if it was hidden in the outline."
8070 (interactive "P")
8071 (let ((win (selected-window)))
8072 (if full-entry
8073 (let ((org-show-entry-below t))
8074 (org-agenda-goto t))
8075 (org-agenda-goto t))
8076 (select-window win)))
8078 (defvar org-agenda-show-window nil)
8079 (defun org-agenda-show-and-scroll-up (&optional arg)
8080 "Display the Org-mode file which contains the item at point.
8081 When called repeatedly, scroll the window that is displaying the buffer.
8082 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8083 `show-subtree' to display the item, so that drawers and logbooks stay
8084 folded."
8085 (interactive "P")
8086 (let ((win (selected-window)))
8087 (if (and (window-live-p org-agenda-show-window)
8088 (eq this-command last-command))
8089 (progn
8090 (select-window org-agenda-show-window)
8091 (ignore-errors (scroll-up)))
8092 (org-agenda-goto t)
8093 (if arg (org-show-entry) (show-subtree))
8094 (setq org-agenda-show-window (selected-window)))
8095 (select-window win)))
8097 (defun org-agenda-show-scroll-down ()
8098 "Scroll down the window showing the agenda."
8099 (interactive)
8100 (let ((win (selected-window)))
8101 (when (window-live-p org-agenda-show-window)
8102 (select-window org-agenda-show-window)
8103 (ignore-errors (scroll-down))
8104 (select-window win))))
8106 (defun org-agenda-show-1 (&optional more)
8107 "Display the Org-mode file which contains the item at point.
8108 The prefix arg selects the amount of information to display:
8110 0 hide the subtree
8111 1 just show the entry according to defaults.
8112 2 show the children view
8113 3 show the subtree view
8114 4 show the entire subtree and any LOGBOOK drawers
8115 5 show the entire subtree and any drawers
8116 With prefix argument FULL-ENTRY, make the entire entry visible
8117 if it was hidden in the outline."
8118 (interactive "p")
8119 (let ((win (selected-window)))
8120 (org-agenda-goto t)
8121 (org-recenter-heading 1)
8122 (cond
8123 ((= more 0)
8124 (hide-subtree)
8125 (save-excursion
8126 (org-back-to-heading)
8127 (run-hook-with-args 'org-cycle-hook 'folded))
8128 (message "Remote: FOLDED"))
8129 ((and (org-called-interactively-p 'any) (= more 1))
8130 (message "Remote: show with default settings"))
8131 ((= more 2)
8132 (show-entry)
8133 (show-children)
8134 (save-excursion
8135 (org-back-to-heading)
8136 (run-hook-with-args 'org-cycle-hook 'children))
8137 (message "Remote: CHILDREN"))
8138 ((= more 3)
8139 (show-subtree)
8140 (save-excursion
8141 (org-back-to-heading)
8142 (run-hook-with-args 'org-cycle-hook 'subtree))
8143 (message "Remote: SUBTREE"))
8144 ((= more 4)
8145 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8146 (org-drawer-regexp
8147 (concat "^[ \t]*:\\("
8148 (mapconcat 'regexp-quote org-drawers "\\|")
8149 "\\):[ \t]*$")))
8150 (show-subtree)
8151 (save-excursion
8152 (org-back-to-heading)
8153 (org-cycle-hide-drawers 'subtree)))
8154 (message "Remote: SUBTREE AND LOGBOOK"))
8155 ((> more 4)
8156 (show-subtree)
8157 (message "Remote: SUBTREE AND ALL DRAWERS")))
8158 (select-window win)))
8160 (defun org-recenter-heading (n)
8161 (save-excursion
8162 (org-back-to-heading)
8163 (recenter n)))
8165 (defvar org-agenda-cycle-counter nil)
8166 (defun org-agenda-cycle-show (&optional n)
8167 "Show the current entry in another window, with default settings.
8168 Default settings are taken from `org-show-hierarchy-above' and siblings.
8169 When use repeatedly in immediate succession, the remote entry will cycle
8170 through visibility
8172 children -> subtree -> folded
8174 When called with a numeric prefix arg, that arg will be passed through to
8175 `org-agenda-show-1'. For the interpretation of that argument, see the
8176 docstring of `org-agenda-show-1'."
8177 (interactive "P")
8178 (if (integerp n)
8179 (setq org-agenda-cycle-counter n)
8180 (if (not (eq last-command this-command))
8181 (setq org-agenda-cycle-counter 1)
8182 (if (equal org-agenda-cycle-counter 0)
8183 (setq org-agenda-cycle-counter 2)
8184 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8185 (if (> org-agenda-cycle-counter 3)
8186 (setq org-agenda-cycle-counter 0)))))
8187 (org-agenda-show-1 org-agenda-cycle-counter))
8189 (defun org-agenda-recenter (arg)
8190 "Display the Org-mode file which contains the item at point and recenter."
8191 (interactive "P")
8192 (let ((win (selected-window)))
8193 (org-agenda-goto t)
8194 (recenter arg)
8195 (select-window win)))
8197 (defun org-agenda-show-mouse (ev)
8198 "Display the Org-mode file which contains the item at the mouse click."
8199 (interactive "e")
8200 (mouse-set-point ev)
8201 (org-agenda-show))
8203 (defun org-agenda-check-no-diary ()
8204 "Check if the entry is a diary link and abort if yes."
8205 (if (org-get-at-bol 'org-agenda-diary-link)
8206 (org-agenda-error)))
8208 (defun org-agenda-error ()
8209 (error "Command not allowed in this line"))
8211 (defun org-agenda-tree-to-indirect-buffer (arg)
8212 "Show the subtree corresponding to the current entry in an indirect buffer.
8213 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8215 With a numerical prefix ARG, go up to this level and then take that tree.
8216 With a negative numeric ARG, go up by this number of levels.
8217 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8218 use the dedicated frame)."
8219 (interactive "P")
8220 (if current-prefix-arg
8221 (org-agenda-do-tree-to-indirect-buffer arg)
8222 (let ((agenda-buffer (buffer-name))
8223 (agenda-window (selected-window))
8224 (indirect-window
8225 (and org-last-indirect-buffer
8226 (get-buffer-window org-last-indirect-buffer))))
8227 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8228 (unless (or (eq org-indirect-buffer-display 'new-frame)
8229 (eq org-indirect-buffer-display 'dedicated-frame))
8230 (unwind-protect
8231 (unless (and indirect-window (window-live-p indirect-window))
8232 (setq indirect-window (split-window agenda-window)))
8233 (and indirect-window (select-window indirect-window))
8234 (switch-to-buffer org-last-indirect-buffer :norecord)
8235 (fit-window-to-buffer indirect-window)))
8236 (select-window (get-buffer-window agenda-buffer)))))
8238 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8239 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8240 (org-agenda-check-no-diary)
8241 (let* ((marker (or (org-get-at-bol 'org-marker)
8242 (org-agenda-error)))
8243 (buffer (marker-buffer marker))
8244 (pos (marker-position marker)))
8245 (with-current-buffer buffer
8246 (save-excursion
8247 (goto-char pos)
8248 (funcall 'org-tree-to-indirect-buffer arg)))))
8250 (defvar org-last-heading-marker (make-marker)
8251 "Marker pointing to the headline that last changed its TODO state
8252 by a remote command from the agenda.")
8254 (defun org-agenda-todo-nextset ()
8255 "Switch TODO entry to next sequence."
8256 (interactive)
8257 (org-agenda-todo 'nextset))
8259 (defun org-agenda-todo-previousset ()
8260 "Switch TODO entry to previous sequence."
8261 (interactive)
8262 (org-agenda-todo 'previousset))
8264 (defun org-agenda-todo (&optional arg)
8265 "Cycle TODO state of line at point, also in Org-mode file.
8266 This changes the line at point, all other lines in the agenda referring to
8267 the same tree node, and the headline of the tree node in the Org-mode file."
8268 (interactive "P")
8269 (org-agenda-check-no-diary)
8270 (let* ((col (current-column))
8271 (marker (or (org-get-at-bol 'org-marker)
8272 (org-agenda-error)))
8273 (buffer (marker-buffer marker))
8274 (pos (marker-position marker))
8275 (hdmarker (org-get-at-bol 'org-hd-marker))
8276 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8277 (inhibit-read-only t)
8278 org-agenda-headline-snapshot-before-repeat newhead just-one)
8279 (org-with-remote-undo buffer
8280 (with-current-buffer buffer
8281 (widen)
8282 (goto-char pos)
8283 (org-show-context 'agenda)
8284 (save-excursion
8285 (and (outline-next-heading)
8286 (org-flag-heading nil))) ; show the next heading
8287 (let ((current-prefix-arg arg))
8288 (call-interactively 'org-todo))
8289 (and (bolp) (forward-char 1))
8290 (setq newhead (org-get-heading))
8291 (when (and (org-bound-and-true-p
8292 org-agenda-headline-snapshot-before-repeat)
8293 (not (equal org-agenda-headline-snapshot-before-repeat
8294 newhead))
8295 todayp)
8296 (setq newhead org-agenda-headline-snapshot-before-repeat
8297 just-one t))
8298 (save-excursion
8299 (org-back-to-heading)
8300 (move-marker org-last-heading-marker (point))))
8301 (beginning-of-line 1)
8302 (save-excursion
8303 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8304 (org-move-to-column col))))
8306 (defun org-agenda-add-note (&optional arg)
8307 "Add a time-stamped note to the entry at point."
8308 (interactive "P")
8309 (org-agenda-check-no-diary)
8310 (let* ((marker (or (org-get-at-bol 'org-marker)
8311 (org-agenda-error)))
8312 (buffer (marker-buffer marker))
8313 (pos (marker-position marker))
8314 (hdmarker (org-get-at-bol 'org-hd-marker))
8315 (inhibit-read-only t))
8316 (with-current-buffer buffer
8317 (widen)
8318 (goto-char pos)
8319 (org-show-context 'agenda)
8320 (save-excursion
8321 (and (outline-next-heading)
8322 (org-flag-heading nil))) ; show the next heading
8323 (org-add-note))))
8325 (defun org-agenda-change-all-lines (newhead hdmarker
8326 &optional fixface just-this)
8327 "Change all lines in the agenda buffer which match HDMARKER.
8328 The new content of the line will be NEWHEAD (as modified by
8329 `org-agenda-format-item'). HDMARKER is checked with
8330 `equal' against all `org-hd-marker' text properties in the file.
8331 If FIXFACE is non-nil, the face of each item is modified according to
8332 the new TODO state.
8333 If JUST-THIS is non-nil, change just the current line, not all.
8334 If FORCE-TAGS is non nil, the car of it returns the new tags."
8335 (let* ((inhibit-read-only t)
8336 (line (org-current-line))
8337 (org-agenda-buffer (current-buffer))
8338 (thetags (with-current-buffer (marker-buffer hdmarker)
8339 (save-excursion (save-restriction (widen)
8340 (goto-char hdmarker)
8341 (org-get-tags-at)))))
8342 props m pl undone-face done-face finish new dotime level cat tags)
8343 (save-excursion
8344 (goto-char (point-max))
8345 (beginning-of-line 1)
8346 (while (not finish)
8347 (setq finish (bobp))
8348 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8349 (or (not just-this) (= (org-current-line) line))
8350 (equal m hdmarker))
8351 (setq props (text-properties-at (point))
8352 dotime (org-get-at-bol 'dotime)
8353 cat (org-get-at-bol 'org-category)
8354 level (org-get-at-bol 'level)
8355 tags thetags
8357 (let ((org-prefix-format-compiled
8358 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8359 org-prefix-format-compiled))
8360 (extra (org-get-at-bol 'extra)))
8361 (with-current-buffer (marker-buffer hdmarker)
8362 (save-excursion
8363 (save-restriction
8364 (widen)
8365 (org-agenda-format-item extra newhead level cat tags dotime)))))
8366 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8367 undone-face (org-get-at-bol 'undone-face)
8368 done-face (org-get-at-bol 'done-face))
8369 (beginning-of-line 1)
8370 (cond
8371 ((equal new "")
8372 (and (looking-at ".*\n?") (replace-match "")))
8373 ((looking-at ".*")
8374 (replace-match new t t)
8375 (beginning-of-line 1)
8376 (add-text-properties (point-at-bol) (point-at-eol) props)
8377 (when fixface
8378 (add-text-properties
8379 (point-at-bol) (point-at-eol)
8380 (list 'face
8381 (if org-last-todo-state-is-todo
8382 undone-face done-face))))
8383 (org-agenda-highlight-todo 'line)
8384 (beginning-of-line 1))
8385 (t (error "Line update did not work")))
8386 (save-restriction
8387 (narrow-to-region (point-at-bol) (point-at-eol))
8388 (org-agenda-finalize)))
8389 (beginning-of-line 0)))))
8391 (defun org-agenda-align-tags (&optional line)
8392 "Align all tags in agenda items to `org-agenda-tags-column'."
8393 (let ((inhibit-read-only t) l c)
8394 (save-excursion
8395 (goto-char (if line (point-at-bol) (point-min)))
8396 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8397 (if line (point-at-eol) nil) t)
8398 (add-text-properties
8399 (match-beginning 2) (match-end 2)
8400 (list 'face (delq nil (let ((prop (get-text-property
8401 (match-beginning 2) 'face)))
8402 (or (listp prop) (setq prop (list prop)))
8403 (if (memq 'org-tag prop)
8404 prop
8405 (cons 'org-tag prop))))))
8406 (setq l (- (match-end 2) (match-beginning 2))
8407 c (if (< org-agenda-tags-column 0)
8408 (- (abs org-agenda-tags-column) l)
8409 org-agenda-tags-column))
8410 (delete-region (match-beginning 1) (match-end 1))
8411 (goto-char (match-beginning 1))
8412 (insert (org-add-props
8413 (make-string (max 1 (- c (current-column))) ?\ )
8414 (plist-put (copy-sequence (text-properties-at (point)))
8415 'face nil))))
8416 (goto-char (point-min))
8417 (org-font-lock-add-tag-faces (point-max)))))
8419 (defun org-agenda-priority-up ()
8420 "Increase the priority of line at point, also in Org-mode file."
8421 (interactive)
8422 (org-agenda-priority 'up))
8424 (defun org-agenda-priority-down ()
8425 "Decrease the priority of line at point, also in Org-mode file."
8426 (interactive)
8427 (org-agenda-priority 'down))
8429 (defun org-agenda-priority (&optional force-direction show)
8430 "Set the priority of line at point, also in Org-mode file.
8431 This changes the line at point, all other lines in the agenda referring to
8432 the same tree node, and the headline of the tree node in the Org-mode file."
8433 (interactive "P")
8434 (if (equal force-direction '(4)) (setq show t))
8435 (unless org-enable-priority-commands
8436 (error "Priority commands are disabled"))
8437 (org-agenda-check-no-diary)
8438 (let* ((marker (or (org-get-at-bol 'org-marker)
8439 (org-agenda-error)))
8440 (hdmarker (org-get-at-bol 'org-hd-marker))
8441 (buffer (marker-buffer hdmarker))
8442 (pos (marker-position hdmarker))
8443 (inhibit-read-only t)
8444 newhead)
8445 (org-with-remote-undo buffer
8446 (with-current-buffer buffer
8447 (widen)
8448 (goto-char pos)
8449 (org-show-context 'agenda)
8450 (save-excursion
8451 (and (outline-next-heading)
8452 (org-flag-heading nil))) ; show the next heading
8453 (funcall 'org-priority force-direction show)
8454 (end-of-line 1)
8455 (setq newhead (org-get-heading)))
8456 (org-agenda-change-all-lines newhead hdmarker)
8457 (beginning-of-line 1))))
8459 ;; FIXME: should fix the tags property of the agenda line.
8460 (defun org-agenda-set-tags (&optional tag onoff)
8461 "Set tags for the current headline."
8462 (interactive)
8463 (org-agenda-check-no-diary)
8464 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8465 (call-interactively 'org-change-tag-in-region)
8466 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8467 (org-agenda-error)))
8468 (buffer (marker-buffer hdmarker))
8469 (pos (marker-position hdmarker))
8470 (inhibit-read-only t)
8471 newhead)
8472 (org-with-remote-undo buffer
8473 (with-current-buffer buffer
8474 (widen)
8475 (goto-char pos)
8476 (save-excursion
8477 (org-show-context 'agenda))
8478 (save-excursion
8479 (and (outline-next-heading)
8480 (org-flag-heading nil))) ; show the next heading
8481 (goto-char pos)
8482 (if tag
8483 (org-toggle-tag tag onoff)
8484 (call-interactively 'org-set-tags))
8485 (end-of-line 1)
8486 (setq newhead (org-get-heading)))
8487 (org-agenda-change-all-lines newhead hdmarker)
8488 (beginning-of-line 1)))))
8490 (defun org-agenda-set-property ()
8491 "Set a property for the current headline."
8492 (interactive)
8493 (org-agenda-check-no-diary)
8494 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8495 (org-agenda-error)))
8496 (buffer (marker-buffer hdmarker))
8497 (pos (marker-position hdmarker))
8498 (inhibit-read-only t)
8499 newhead)
8500 (org-with-remote-undo buffer
8501 (with-current-buffer buffer
8502 (widen)
8503 (goto-char pos)
8504 (save-excursion
8505 (org-show-context 'agenda))
8506 (save-excursion
8507 (and (outline-next-heading)
8508 (org-flag-heading nil))) ; show the next heading
8509 (goto-char pos)
8510 (call-interactively 'org-set-property)))))
8512 (defun org-agenda-set-effort ()
8513 "Set the effort property for the current headline."
8514 (interactive)
8515 (org-agenda-check-no-diary)
8516 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8517 (org-agenda-error)))
8518 (buffer (marker-buffer hdmarker))
8519 (pos (marker-position hdmarker))
8520 (inhibit-read-only t)
8521 newhead)
8522 (org-with-remote-undo buffer
8523 (with-current-buffer buffer
8524 (widen)
8525 (goto-char pos)
8526 (save-excursion
8527 (org-show-context 'agenda))
8528 (save-excursion
8529 (and (outline-next-heading)
8530 (org-flag-heading nil))) ; show the next heading
8531 (goto-char pos)
8532 (call-interactively 'org-set-effort)
8533 (end-of-line 1)
8534 (setq newhead (org-get-heading)))
8535 (org-agenda-change-all-lines newhead hdmarker))))
8537 (defun org-agenda-toggle-archive-tag ()
8538 "Toggle the archive tag for the current entry."
8539 (interactive)
8540 (org-agenda-check-no-diary)
8541 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8542 (org-agenda-error)))
8543 (buffer (marker-buffer hdmarker))
8544 (pos (marker-position hdmarker))
8545 (inhibit-read-only t)
8546 newhead)
8547 (org-with-remote-undo buffer
8548 (with-current-buffer buffer
8549 (widen)
8550 (goto-char pos)
8551 (org-show-context 'agenda)
8552 (save-excursion
8553 (and (outline-next-heading)
8554 (org-flag-heading nil))) ; show the next heading
8555 (call-interactively 'org-toggle-archive-tag)
8556 (end-of-line 1)
8557 (setq newhead (org-get-heading)))
8558 (org-agenda-change-all-lines newhead hdmarker)
8559 (beginning-of-line 1))))
8561 (defun org-agenda-do-date-later (arg)
8562 (interactive "P")
8563 (cond
8564 ((or (equal arg '(16))
8565 (memq last-command
8566 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8567 (setq this-command 'org-agenda-date-later-minutes)
8568 (org-agenda-date-later-minutes 1))
8569 ((or (equal arg '(4))
8570 (memq last-command
8571 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8572 (setq this-command 'org-agenda-date-later-hours)
8573 (org-agenda-date-later-hours 1))
8575 (org-agenda-date-later (prefix-numeric-value arg)))))
8577 (defun org-agenda-do-date-earlier (arg)
8578 (interactive "P")
8579 (cond
8580 ((or (equal arg '(16))
8581 (memq last-command
8582 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8583 (setq this-command 'org-agenda-date-earlier-minutes)
8584 (org-agenda-date-earlier-minutes 1))
8585 ((or (equal arg '(4))
8586 (memq last-command
8587 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8588 (setq this-command 'org-agenda-date-earlier-hours)
8589 (org-agenda-date-earlier-hours 1))
8591 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8593 (defun org-agenda-date-later (arg &optional what)
8594 "Change the date of this item to ARG day(s) later."
8595 (interactive "p")
8596 (org-agenda-check-type t 'agenda 'timeline)
8597 (org-agenda-check-no-diary)
8598 (let* ((marker (or (org-get-at-bol 'org-marker)
8599 (org-agenda-error)))
8600 (buffer (marker-buffer marker))
8601 (pos (marker-position marker))
8602 cdate today)
8603 (org-with-remote-undo buffer
8604 (with-current-buffer buffer
8605 (widen)
8606 (goto-char pos)
8607 (if (not (org-at-timestamp-p))
8608 (error "Cannot find time stamp"))
8609 (when (and org-agenda-move-date-from-past-immediately-to-today
8610 (equal arg 1)
8611 (or (not what) (eq what 'day))
8612 (not (save-match-data (org-at-date-range-p))))
8613 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8614 cdate (calendar-absolute-from-gregorian
8615 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8616 today (org-today))
8617 (if (> today cdate)
8618 ;; immediately shift to today
8619 (setq arg (- today cdate))))
8620 (org-timestamp-change arg (or what 'day))
8621 (when (and (org-at-date-range-p)
8622 (re-search-backward org-tr-regexp-both (point-at-bol)))
8623 (let ((end org-last-changed-timestamp))
8624 (org-timestamp-change arg (or what 'day))
8625 (setq org-last-changed-timestamp
8626 (concat org-last-changed-timestamp "--" end)))))
8627 (org-agenda-show-new-time marker org-last-changed-timestamp))
8628 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8630 (defun org-agenda-date-earlier (arg &optional what)
8631 "Change the date of this item to ARG day(s) earlier."
8632 (interactive "p")
8633 (org-agenda-date-later (- arg) what))
8635 (defun org-agenda-date-later-minutes (arg)
8636 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8637 (interactive "p")
8638 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8639 (org-agenda-date-later arg 'minute))
8641 (defun org-agenda-date-earlier-minutes (arg)
8642 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8643 (interactive "p")
8644 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8645 (org-agenda-date-earlier arg 'minute))
8647 (defun org-agenda-date-later-hours (arg)
8648 "Change the time of this item, in hour steps."
8649 (interactive "p")
8650 (org-agenda-date-later arg 'hour))
8652 (defun org-agenda-date-earlier-hours (arg)
8653 "Change the time of this item, in hour steps."
8654 (interactive "p")
8655 (org-agenda-date-earlier arg 'hour))
8657 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8658 "Show new date stamp via text properties."
8659 ;; We use text properties to make this undoable
8660 (let ((inhibit-read-only t)
8661 (buffer-invisibility-spec))
8662 (setq stamp (concat " " prefix " => " stamp))
8663 (save-excursion
8664 (goto-char (point-max))
8665 (while (not (bobp))
8666 (when (equal marker (org-get-at-bol 'org-marker))
8667 (org-move-to-column (- (window-width) (length stamp)) t)
8668 (org-agenda-fix-tags-filter-overlays-at (point))
8669 (if (featurep 'xemacs)
8670 ;; Use `duplicable' property to trigger undo recording
8671 (let ((ex (make-extent nil nil))
8672 (gl (make-glyph stamp)))
8673 (set-glyph-face gl 'secondary-selection)
8674 (set-extent-properties
8675 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8676 (insert-extent ex (1- (point)) (point-at-eol)))
8677 (add-text-properties
8678 (1- (point)) (point-at-eol)
8679 (list 'display (org-add-props stamp nil
8680 'face 'secondary-selection))))
8681 (beginning-of-line 1))
8682 (beginning-of-line 0)))))
8684 (defun org-agenda-date-prompt (arg)
8685 "Change the date of this item. Date is prompted for, with default today.
8686 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8687 be used to request time specification in the time stamp."
8688 (interactive "P")
8689 (org-agenda-check-type t 'agenda 'timeline)
8690 (org-agenda-check-no-diary)
8691 (let* ((marker (or (org-get-at-bol 'org-marker)
8692 (org-agenda-error)))
8693 (buffer (marker-buffer marker))
8694 (pos (marker-position marker)))
8695 (org-with-remote-undo buffer
8696 (with-current-buffer buffer
8697 (widen)
8698 (goto-char pos)
8699 (if (not (org-at-timestamp-p t))
8700 (error "Cannot find time stamp"))
8701 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8702 (org-agenda-show-new-time marker org-last-changed-timestamp))
8703 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8705 (defun org-agenda-schedule (arg &optional time)
8706 "Schedule the item at point.
8707 ARG is passed through to `org-schedule'."
8708 (interactive "P")
8709 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8710 (org-agenda-check-no-diary)
8711 (let* ((marker (or (org-get-at-bol 'org-marker)
8712 (org-agenda-error)))
8713 (type (marker-insertion-type marker))
8714 (buffer (marker-buffer marker))
8715 (pos (marker-position marker))
8716 (org-insert-labeled-timestamps-at-point nil)
8718 (set-marker-insertion-type marker t)
8719 (org-with-remote-undo buffer
8720 (with-current-buffer buffer
8721 (widen)
8722 (goto-char pos)
8723 (setq ts (org-schedule arg time)))
8724 (org-agenda-show-new-time marker ts "S"))
8725 (message "%s" ts)))
8727 (defun org-agenda-deadline (arg &optional time)
8728 "Schedule the item at point.
8729 ARG is passed through to `org-deadline'."
8730 (interactive "P")
8731 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8732 (org-agenda-check-no-diary)
8733 (let* ((marker (or (org-get-at-bol 'org-marker)
8734 (org-agenda-error)))
8735 (buffer (marker-buffer marker))
8736 (pos (marker-position marker))
8737 (org-insert-labeled-timestamps-at-point nil)
8739 (org-with-remote-undo buffer
8740 (with-current-buffer buffer
8741 (widen)
8742 (goto-char pos)
8743 (setq ts (org-deadline arg time)))
8744 (org-agenda-show-new-time marker ts "D"))
8745 (message "%s" ts)))
8747 (defun org-agenda-clock-in (&optional arg)
8748 "Start the clock on the currently selected item."
8749 (interactive "P")
8750 (org-agenda-check-no-diary)
8751 (if (equal arg '(4))
8752 (org-clock-in arg)
8753 (let* ((marker (or (org-get-at-bol 'org-marker)
8754 (org-agenda-error)))
8755 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8756 marker))
8757 (pos (marker-position marker))
8758 newhead)
8759 (org-with-remote-undo (marker-buffer marker)
8760 (with-current-buffer (marker-buffer marker)
8761 (widen)
8762 (goto-char pos)
8763 (org-show-context 'agenda)
8764 (org-show-entry)
8765 (org-cycle-hide-drawers 'children)
8766 (org-clock-in arg)
8767 (setq newhead (org-get-heading)))
8768 (org-agenda-change-all-lines newhead hdmarker)))))
8770 (defun org-agenda-clock-out ()
8771 "Stop the currently running clock."
8772 (interactive)
8773 (unless (marker-buffer org-clock-marker)
8774 (error "No running clock"))
8775 (let ((marker (make-marker)) newhead)
8776 (org-with-remote-undo (marker-buffer org-clock-marker)
8777 (with-current-buffer (marker-buffer org-clock-marker)
8778 (save-excursion
8779 (save-restriction
8780 (widen)
8781 (goto-char org-clock-marker)
8782 (org-back-to-heading t)
8783 (move-marker marker (point))
8784 (org-clock-out)
8785 (setq newhead (org-get-heading))))))
8786 (org-agenda-change-all-lines newhead marker)
8787 (move-marker marker nil)))
8789 (defun org-agenda-clock-cancel (&optional arg)
8790 "Cancel the currently running clock."
8791 (interactive "P")
8792 (unless (marker-buffer org-clock-marker)
8793 (error "No running clock"))
8794 (org-with-remote-undo (marker-buffer org-clock-marker)
8795 (org-clock-cancel)))
8797 (defun org-agenda-clock-goto ()
8798 "Jump to the currently clocked in task within the agenda.
8799 If the currently clocked in task is not listed in the agenda
8800 buffer, display it in another window."
8801 (interactive)
8802 (let (pos)
8803 (mapc (lambda (o)
8804 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8805 (setq pos (overlay-start o))))
8806 (overlays-in (point-min) (point-max)))
8807 (cond (pos (goto-char pos))
8808 ;; If the currently clocked entry is not in the agenda
8809 ;; buffer, we visit it in another window:
8810 (org-clock-current-task
8811 (org-switch-to-buffer-other-window (org-clock-goto)))
8812 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8814 (defun org-agenda-diary-entry-in-org-file ()
8815 "Make a diary entry in the file `org-agenda-diary-file'."
8816 (let (d1 d2 char (text "") dp1 dp2)
8817 (if (equal (buffer-name) "*Calendar*")
8818 (setq d1 (calendar-cursor-to-date t)
8819 d2 (car calendar-mark-ring))
8820 (setq dp1 (get-text-property (point-at-bol) 'day))
8821 (unless dp1 (error "No date defined in current line"))
8822 (setq d1 (calendar-gregorian-from-absolute dp1)
8823 d2 (and (ignore-errors (mark))
8824 (save-excursion
8825 (goto-char (mark))
8826 (setq dp2 (get-text-property (point-at-bol) 'day)))
8827 (calendar-gregorian-from-absolute dp2))))
8828 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8829 (setq char (read-char-exclusive))
8830 (cond
8831 ((equal char ?d)
8832 (setq text (read-string "Day entry: "))
8833 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8834 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8835 ((equal char ?a)
8836 (setq d1 (list (car d1) (nth 1 d1)
8837 (read-number (format "Reference year [%d]: " (nth 2 d1))
8838 (nth 2 d1))))
8839 (setq text (read-string "Anniversary (use %d to show years): "))
8840 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8841 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8842 ((equal char ?b)
8843 (setq text (read-string "Block entry: "))
8844 (unless (and d1 d2 (not (equal d1 d2)))
8845 (error "No block of days selected"))
8846 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8847 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8848 ((equal char ?j)
8849 (org-switch-to-buffer-other-window
8850 (find-file-noselect org-agenda-diary-file))
8851 (require 'org-datetree)
8852 (org-datetree-find-date-create d1)
8853 (org-reveal t))
8854 (t (error "Invalid selection character `%c'" char)))))
8856 (defcustom org-agenda-insert-diary-strategy 'date-tree
8857 "Where in `org-agenda-diary-file' should new entries be added?
8858 Valid values:
8860 date-tree in the date tree, as child of the date
8861 top-level as top-level entries at the end of the file."
8862 :group 'org-agenda
8863 :type '(choice
8864 (const :tag "in a date tree" date-tree)
8865 (const :tag "as top level at end of file" top-level)))
8867 (defcustom org-agenda-insert-diary-extract-time nil
8868 "Non-nil means extract any time specification from the diary entry."
8869 :group 'org-agenda
8870 :version "24.1"
8871 :type 'boolean)
8873 (defcustom org-agenda-bulk-mark-char ">"
8874 "A single-character string to be used as the bulk mark."
8875 :group 'org-agenda
8876 :version "24.1"
8877 :type 'string)
8879 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8880 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8881 If TEXT is not empty, it will become the headline of the new entry, and
8882 the resulting entry will not be shown. When TEXT is empty, switch to
8883 `org-agenda-diary-file' and let the user finish the entry there."
8884 (let ((cw (current-window-configuration)))
8885 (org-switch-to-buffer-other-window
8886 (find-file-noselect org-agenda-diary-file))
8887 (widen)
8888 (goto-char (point-min))
8889 (cond
8890 ((eq type 'anniversary)
8891 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8892 (progn
8893 (or (org-at-heading-p t)
8894 (progn
8895 (outline-next-heading)
8896 (insert "* Anniversaries\n\n")
8897 (beginning-of-line -1)))))
8898 (outline-next-heading)
8899 (org-back-over-empty-lines)
8900 (backward-char 1)
8901 (insert "\n")
8902 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8903 (nth 2 d1) (car d1) (nth 1 d1) text)))
8904 ((eq type 'day)
8905 (let ((org-prefix-has-time t)
8906 (org-agenda-time-leading-zero t)
8907 fmt time time2)
8908 (if org-agenda-insert-diary-extract-time
8909 ;; Use org-agenda-format-item to parse text for a time-range and
8910 ;; remove it. FIXME: This is a hack, we should refactor
8911 ;; that function to make time extraction available separately
8912 (setq fmt (org-agenda-format-item nil text nil nil nil t)
8913 time (get-text-property 0 'time fmt)
8914 time2 (if (> (length time) 0)
8915 ;; split-string removes trailing ...... if
8916 ;; no end time given. First space
8917 ;; separates time from date.
8918 (concat " " (car (split-string time "\\.")))
8919 nil)
8920 text (get-text-property 0 'txt fmt)))
8921 (if (eq org-agenda-insert-diary-strategy 'top-level)
8922 (org-agenda-insert-diary-as-top-level text)
8923 (require 'org-datetree)
8924 (org-datetree-find-date-create d1)
8925 (org-agenda-insert-diary-make-new-entry text))
8926 (org-insert-time-stamp (org-time-from-absolute
8927 (calendar-absolute-from-gregorian d1))
8928 nil nil nil nil time2))
8929 (end-of-line 0))
8930 ((eq type 'block)
8931 (if (> (calendar-absolute-from-gregorian d1)
8932 (calendar-absolute-from-gregorian d2))
8933 (setq d1 (prog1 d2 (setq d2 d1))))
8934 (if (eq org-agenda-insert-diary-strategy 'top-level)
8935 (org-agenda-insert-diary-as-top-level text)
8936 (require 'org-datetree)
8937 (org-datetree-find-date-create d1)
8938 (org-agenda-insert-diary-make-new-entry text))
8939 (org-insert-time-stamp (org-time-from-absolute
8940 (calendar-absolute-from-gregorian d1)))
8941 (insert "--")
8942 (org-insert-time-stamp (org-time-from-absolute
8943 (calendar-absolute-from-gregorian d2)))
8944 (end-of-line 0)))
8945 (if (string-match "\\S-" text)
8946 (progn
8947 (set-window-configuration cw)
8948 (message "%s entry added to %s"
8949 (capitalize (symbol-name type))
8950 (abbreviate-file-name org-agenda-diary-file)))
8951 (org-reveal t)
8952 (message "Please finish entry here"))))
8954 (defun org-agenda-insert-diary-as-top-level (text)
8955 "Make new entry as a top-level entry at the end of the file.
8956 Add TEXT as headline, and position the cursor in the second line so that
8957 a timestamp can be added there."
8958 (widen)
8959 (goto-char (point-max))
8960 (or (bolp) (insert "\n"))
8961 (insert "* " text "\n")
8962 (if org-adapt-indentation (org-indent-to-column 2)))
8964 (defun org-agenda-insert-diary-make-new-entry (text)
8965 "Make new entry as last child of current entry.
8966 Add TEXT as headline, and position the cursor in the second line so that
8967 a timestamp can be added there."
8968 (let ((org-show-following-heading t)
8969 (org-show-siblings t)
8970 (org-show-hierarchy-above t)
8971 (org-show-entry-below t)
8972 col)
8973 (outline-next-heading)
8974 (org-back-over-empty-lines)
8975 (or (looking-at "[ \t]*$")
8976 (progn (insert "\n") (backward-char 1)))
8977 (org-insert-heading nil t)
8978 (org-do-demote)
8979 (setq col (current-column))
8980 (insert text "\n")
8981 (if org-adapt-indentation (org-indent-to-column col))
8982 (let ((org-show-following-heading t)
8983 (org-show-siblings t)
8984 (org-show-hierarchy-above t)
8985 (org-show-entry-below t))
8986 (org-show-context))))
8988 (defun org-agenda-diary-entry ()
8989 "Make a diary entry, like the `i' command from the calendar.
8990 All the standard commands work: block, weekly etc.
8991 When `org-agenda-diary-file' points to a file,
8992 `org-agenda-diary-entry-in-org-file' is called instead to create
8993 entries in that Org-mode file."
8994 (interactive)
8995 (if (not (eq org-agenda-diary-file 'diary-file))
8996 (org-agenda-diary-entry-in-org-file)
8997 (require 'diary-lib)
8998 (let* ((char (progn
8999 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9000 (read-char-exclusive)))
9001 (cmd (cdr (assoc char
9002 '((?d . insert-diary-entry)
9003 (?w . insert-weekly-diary-entry)
9004 (?m . insert-monthly-diary-entry)
9005 (?y . insert-yearly-diary-entry)
9006 (?a . insert-anniversary-diary-entry)
9007 (?b . insert-block-diary-entry)
9008 (?c . insert-cyclic-diary-entry)))))
9009 (oldf (symbol-function 'calendar-cursor-to-date))
9010 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9011 (point (point))
9012 (mark (or (mark t) (point))))
9013 (unless cmd
9014 (error "No command associated with <%c>" char))
9015 (unless (and (get-text-property point 'day)
9016 (or (not (equal ?b char))
9017 (get-text-property mark 'day)))
9018 (error "Don't know which date to use for diary entry"))
9019 ;; We implement this by hacking the `calendar-cursor-to-date' function
9020 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9021 (let ((calendar-mark-ring
9022 (list (calendar-gregorian-from-absolute
9023 (or (get-text-property mark 'day)
9024 (get-text-property point 'day))))))
9025 (unwind-protect
9026 (progn
9027 (fset 'calendar-cursor-to-date
9028 (lambda (&optional error dummy)
9029 (calendar-gregorian-from-absolute
9030 (get-text-property point 'day))))
9031 (call-interactively cmd))
9032 (fset 'calendar-cursor-to-date oldf))))))
9034 (defun org-agenda-execute-calendar-command (cmd)
9035 "Execute a calendar command from the agenda with date from cursor."
9036 (org-agenda-check-type t 'agenda 'timeline)
9037 (require 'diary-lib)
9038 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9039 (error "Don't know which date to use for the calendar command"))
9040 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9041 (point (point))
9042 (date (calendar-gregorian-from-absolute
9043 (get-text-property point 'day)))
9044 ;; the following 2 vars are needed in the calendar
9045 (displayed-month (car date))
9046 (displayed-year (nth 2 date)))
9047 (unwind-protect
9048 (progn
9049 (fset 'calendar-cursor-to-date
9050 (lambda (&optional error dummy)
9051 (calendar-gregorian-from-absolute
9052 (get-text-property point 'day))))
9053 (call-interactively cmd))
9054 (fset 'calendar-cursor-to-date oldf))))
9056 (defun org-agenda-phases-of-moon ()
9057 "Display the phases of the moon for the 3 months around the cursor date."
9058 (interactive)
9059 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9061 (defun org-agenda-holidays ()
9062 "Display the holidays for the 3 months around the cursor date."
9063 (interactive)
9064 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9066 (defvar calendar-longitude) ; defined in calendar.el
9067 (defvar calendar-latitude) ; defined in calendar.el
9068 (defvar calendar-location-name) ; defined in calendar.el
9070 (defun org-agenda-sunrise-sunset (arg)
9071 "Display sunrise and sunset for the cursor date.
9072 Latitude and longitude can be specified with the variables
9073 `calendar-latitude' and `calendar-longitude'. When called with prefix
9074 argument, latitude and longitude will be prompted for."
9075 (interactive "P")
9076 (require 'solar)
9077 (let ((calendar-longitude (if arg nil calendar-longitude))
9078 (calendar-latitude (if arg nil calendar-latitude))
9079 (calendar-location-name
9080 (if arg "the given coordinates" calendar-location-name)))
9081 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9083 (defun org-agenda-goto-calendar ()
9084 "Open the Emacs calendar with the date at the cursor."
9085 (interactive)
9086 (org-agenda-check-type t 'agenda 'timeline)
9087 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9088 (error "Don't know which date to open in calendar")))
9089 (date (calendar-gregorian-from-absolute day))
9090 (calendar-move-hook nil)
9091 (calendar-view-holidays-initially-flag nil)
9092 (calendar-view-diary-initially-flag nil))
9093 (calendar)
9094 (calendar-goto-date date)))
9096 ;;;###autoload
9097 (defun org-calendar-goto-agenda ()
9098 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9099 This is a command that has to be installed in `calendar-mode-map'."
9100 (interactive)
9101 (org-agenda-list nil (calendar-absolute-from-gregorian
9102 (calendar-cursor-to-date))
9103 nil))
9105 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9106 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9107 This is a command that has to be installed in `calendar-mode-map'.
9109 \(fn)" t nil)
9111 (defun org-agenda-convert-date ()
9112 (interactive)
9113 (org-agenda-check-type t 'agenda 'timeline)
9114 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9115 date s)
9116 (unless day
9117 (error "Don't know which date to convert"))
9118 (setq date (calendar-gregorian-from-absolute day))
9119 (setq s (concat
9120 "Gregorian: " (calendar-date-string date) "\n"
9121 "ISO: " (calendar-iso-date-string date) "\n"
9122 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9123 "Julian: " (calendar-julian-date-string date) "\n"
9124 "Astron. JD: " (calendar-astro-date-string date)
9125 " (Julian date number at noon UTC)\n"
9126 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9127 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9128 "French: " (calendar-french-date-string date) "\n"
9129 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9130 "Mayan: " (calendar-mayan-date-string date) "\n"
9131 "Coptic: " (calendar-coptic-date-string date) "\n"
9132 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9133 "Persian: " (calendar-persian-date-string date) "\n"
9134 "Chinese: " (calendar-chinese-date-string date) "\n"))
9135 (with-output-to-temp-buffer "*Dates*"
9136 (princ s))
9137 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9139 ;;; Bulk commands
9141 (defun org-agenda-bulk-marked-p ()
9142 (eq (get-char-property (point-at-bol) 'type)
9143 'org-marked-entry-overlay))
9145 (defun org-agenda-bulk-mark (&optional arg)
9146 "Mark the entry at point for future bulk action."
9147 (interactive "p")
9148 (dotimes (i (or arg 1))
9149 (unless (org-get-at-bol 'org-agenda-diary-link)
9150 (let* ((m (org-get-at-bol 'org-hd-marker))
9152 (unless (org-agenda-bulk-marked-p)
9153 (unless m (error "Nothing to mark at point"))
9154 (push m org-agenda-bulk-marked-entries)
9155 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9156 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9157 (org-get-todo-face "TODO")
9158 'evaporate)
9159 (overlay-put ov 'type 'org-marked-entry-overlay))
9160 (beginning-of-line 2)
9161 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9162 (beginning-of-line 2))
9163 (message "%d entries marked for bulk action"
9164 (length org-agenda-bulk-marked-entries))))))
9166 (defun org-agenda-bulk-mark-all ()
9167 "Mark all entries for future agenda bulk action."
9168 (interactive)
9169 (org-agenda-bulk-mark-regexp "."))
9171 (defun org-agenda-bulk-mark-regexp (regexp)
9172 "Mark entries matching REGEXP for future agenda bulk action."
9173 (interactive "sMark entries matching regexp: ")
9174 (let ((entries-marked 0))
9175 (save-excursion
9176 (goto-char (point-min))
9177 (goto-char (next-single-property-change (point) 'txt))
9178 (while (re-search-forward regexp nil t)
9179 (when (string-match regexp (get-text-property (point) 'txt))
9180 (setq entries-marked (1+ entries-marked))
9181 (call-interactively 'org-agenda-bulk-mark))))
9182 (if (not entries-marked)
9183 (message "No entry matching this regexp."))))
9185 (defun org-agenda-bulk-unmark (&optional arg)
9186 "Unmark the entry at point for future bulk action."
9187 (interactive "P")
9188 (if arg
9189 (org-agenda-bulk-unmark-all)
9190 (cond ((org-agenda-bulk-marked-p)
9191 (org-agenda-bulk-remove-overlays
9192 (point-at-bol) (+ 2 (point-at-bol)))
9193 (setq org-agenda-bulk-marked-entries
9194 (delete (org-get-at-bol 'org-hd-marker)
9195 org-agenda-bulk-marked-entries))
9196 (beginning-of-line 2)
9197 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9198 (beginning-of-line 2))
9199 (message "%d entries left marked for bulk action"
9200 (length org-agenda-bulk-marked-entries)))
9201 (t (message "No entry to unmark here")))))
9203 (defun org-agenda-bulk-toggle ()
9204 "Toggle marking the entry at point for bulk action."
9205 (interactive)
9206 (if (org-agenda-bulk-marked-p)
9207 (org-agenda-bulk-unmark)
9208 (org-agenda-bulk-mark)))
9210 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9211 "Remove the mark overlays between BEG and END in the agenda buffer.
9212 BEG and END default to the buffer limits.
9214 This only removes the overlays, it does not remove the markers
9215 from the list in `org-agenda-bulk-marked-entries'."
9216 (interactive)
9217 (mapc (lambda (ov)
9218 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9219 (delete-overlay ov)))
9220 (overlays-in (or beg (point-min)) (or end (point-max)))))
9222 (defun org-agenda-bulk-unmark-all ()
9223 "Remove all marks in the agenda buffer.
9224 This will remove the markers and the overlays."
9225 (interactive)
9226 (if (null org-agenda-bulk-marked-entries)
9227 (message "No entry to unmark")
9228 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9229 (setq org-agenda-bulk-marked-entries nil)
9230 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9232 (defcustom org-agenda-persistent-marks nil
9233 "Non-nil means marked items will stay marked after a bulk action.
9234 You can toggle this interactively by typing `p' when prompted for a
9235 bulk action."
9236 :group 'org-agenda
9237 :version "24.1"
9238 :type 'boolean)
9240 (defun org-agenda-bulk-action (&optional arg)
9241 "Execute an remote-editing action on all marked entries.
9242 The prefix arg is passed through to the command if possible."
9243 (interactive "P")
9244 ;; Make sure we have markers, and only valid ones
9245 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9246 (mapc
9247 (lambda (m)
9248 (unless (and (markerp m)
9249 (marker-buffer m)
9250 (buffer-live-p (marker-buffer m))
9251 (marker-position m))
9252 (error "Marker %s for bulk command is invalid" m)))
9253 org-agenda-bulk-marked-entries)
9255 ;; Prompt for the bulk command
9256 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9257 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9258 "[S]catter [f]unction "
9259 (when org-agenda-bulk-custom-functions
9260 (concat " Custom: ["
9261 (mapconcat (lambda(f) (char-to-string (car f)))
9262 org-agenda-bulk-custom-functions "")
9263 "]"))))
9264 (catch 'exit
9265 (let* ((action (read-char-exclusive))
9266 (org-log-refile (if org-log-refile 'time nil))
9267 (entries (reverse org-agenda-bulk-marked-entries))
9268 (org-overriding-default-time
9269 (if (get-text-property (point) 'org-agenda-date-header)
9270 (org-get-cursor-date)))
9271 redo-at-end
9272 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9273 (cond
9274 ((equal action ?p)
9275 (let ((org-agenda-persistent-marks
9276 (not org-agenda-persistent-marks)))
9277 (org-agenda-bulk-action)
9278 (throw 'exit nil)))
9280 ((equal action ?$)
9281 (setq cmd '(org-agenda-archive)))
9283 ((equal action ?A)
9284 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9286 ((member action '(?r ?w))
9287 (setq rfloc (org-refile-get-location
9288 "Refile to"
9289 (marker-buffer (car entries))
9290 org-refile-allow-creating-parent-nodes))
9291 (if (nth 3 rfloc)
9292 (setcar (nthcdr 3 rfloc)
9293 (move-marker (make-marker) (nth 3 rfloc)
9294 (or (get-file-buffer (nth 1 rfloc))
9295 (find-buffer-visiting (nth 1 rfloc))
9296 (error "This should not happen")))))
9298 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9299 redo-at-end t))
9301 ((equal action ?t)
9302 (setq state (org-icompleting-read
9303 "Todo state: "
9304 (with-current-buffer (marker-buffer (car entries))
9305 (mapcar 'list org-todo-keywords-1))))
9306 (setq cmd `(let ((org-inhibit-blocking t)
9307 (org-inhibit-logging 'note))
9308 (org-agenda-todo ,state))))
9310 ((memq action '(?- ?+))
9311 (setq tag (org-icompleting-read
9312 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9313 (with-current-buffer (marker-buffer (car entries))
9314 (delq nil
9315 (mapcar (lambda (x)
9316 (if (stringp (car x)) x)) org-tag-alist)))))
9317 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9319 ((memq action '(?s ?d))
9320 (let* ((time
9321 (unless arg
9322 (org-read-date
9323 nil nil nil
9324 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9325 org-overriding-default-time)))
9326 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9327 (setq cmd `(eval '(,c1 arg ,time)))))
9329 ((equal action ?S)
9330 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9331 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9332 (let ((days (read-number
9333 (format "Scatter tasks across how many %sdays: "
9334 (if arg "week" "")) 7)))
9335 (setq cmd
9336 `(let ((distance (1+ (random ,days))))
9337 (if arg
9338 (let ((dist distance)
9339 (day-of-week
9340 (calendar-day-of-week
9341 (calendar-gregorian-from-absolute (org-today)))))
9342 (dotimes (i (1+ dist))
9343 (while (member day-of-week org-agenda-weekend-days)
9344 (incf distance)
9345 (incf day-of-week)
9346 (if (= day-of-week 7)
9347 (setq day-of-week 0)))
9348 (incf day-of-week)
9349 (if (= day-of-week 7)
9350 (setq day-of-week 0)))))
9351 ;; silently fail when try to replan a sexp entry
9352 (condition-case nil
9353 (let* ((date (calendar-gregorian-from-absolute
9354 (+ (org-today) distance)))
9355 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9356 (nth 2 date))))
9357 (org-agenda-schedule nil time))
9358 (error nil)))))))
9360 ((assoc action org-agenda-bulk-custom-functions)
9361 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9362 redo-at-end t))
9364 ((equal action ?f)
9365 (setq cmd (list (intern
9366 (org-icompleting-read "Function: "
9367 obarray 'fboundp t nil nil)))))
9369 (t (error "Invalid bulk action")))
9371 ;; Sort the markers, to make sure that parents are handled before children
9372 (setq entries (sort entries
9373 (lambda (a b)
9374 (cond
9375 ((equal (marker-buffer a) (marker-buffer b))
9376 (< (marker-position a) (marker-position b)))
9378 (string< (buffer-name (marker-buffer a))
9379 (buffer-name (marker-buffer b))))))))
9381 ;; Now loop over all markers and apply cmd
9382 (while (setq e (pop entries))
9383 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9384 (if (not pos)
9385 (progn (message "Skipping removed entry at %s" e)
9386 (setq cntskip (1+ cntskip)))
9387 (goto-char pos)
9388 (let (org-loop-over-headlines-in-active-region)
9389 (eval cmd))
9390 (setq cnt (1+ cnt))))
9391 (when redo-at-end (org-agenda-redo))
9392 (unless org-agenda-persistent-marks
9393 (org-agenda-bulk-unmark-all))
9394 (message "Acted on %d entries%s%s"
9396 (if (= cntskip 0)
9398 (format ", skipped %d (disappeared before their turn)"
9399 cntskip))
9400 (if (not org-agenda-persistent-marks)
9401 "" " (kept marked)"))))))
9403 (defun org-agenda-capture (&optional with-time)
9404 "Call `org-capture' with the date at point.
9405 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9406 current HH:MM time."
9407 (interactive "P")
9408 (if (not (eq major-mode 'org-agenda-mode))
9409 (user-error "You cannot do this outside of agenda buffers")
9410 (let ((org-overriding-default-time
9411 (org-get-cursor-date (equal with-time 1))))
9412 (call-interactively 'org-capture))))
9414 ;;; Flagging notes
9416 (defun org-agenda-show-the-flagging-note ()
9417 "Display the flagging note in the other window.
9418 When called a second time in direct sequence, offer to remove the FLAGGING
9419 tag and (if present) the flagging note."
9420 (interactive)
9421 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9422 (win (selected-window))
9423 note heading newhead)
9424 (unless hdmarker
9425 (error "No linked entry at point"))
9426 (if (and (eq this-command last-command)
9427 (y-or-n-p "Unflag and remove any flagging note? "))
9428 (progn
9429 (org-agenda-remove-flag hdmarker)
9430 (let ((win (get-buffer-window "*Flagging Note*")))
9431 (and win (delete-window win)))
9432 (message "Entry unflagged"))
9433 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9434 (unless note
9435 (error "No flagging note"))
9436 (org-kill-new note)
9437 (org-switch-to-buffer-other-window "*Flagging Note*")
9438 (erase-buffer)
9439 (insert note)
9440 (goto-char (point-min))
9441 (while (re-search-forward "\\\\n" nil t)
9442 (replace-match "\n" t t))
9443 (goto-char (point-min))
9444 (select-window win)
9445 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9447 (defun org-agenda-remove-flag (marker)
9448 "Remove the FLAGGED tag and any flagging note in the entry."
9449 (let (newhead)
9450 (org-with-point-at marker
9451 (org-toggle-tag "FLAGGED" 'off)
9452 (org-entry-delete nil "THEFLAGGINGNOTE")
9453 (setq newhead (org-get-heading)))
9454 (org-agenda-change-all-lines newhead marker)
9455 (message "Entry unflagged")))
9457 (defun org-agenda-get-any-marker (&optional pos)
9458 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9459 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9461 ;;; Appointment reminders
9463 (defvar appt-time-msg-list) ; defined in appt.el
9465 ;;;###autoload
9466 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9467 "Activate appointments found in `org-agenda-files'.
9468 With a \\[universal-argument] prefix, refresh the list of
9469 appointments.
9471 If FILTER is t, interactively prompt the user for a regular
9472 expression, and filter out entries that don't match it.
9474 If FILTER is a string, use this string as a regular expression
9475 for filtering entries out.
9477 If FILTER is a function, filter out entries against which
9478 calling the function returns nil. This function takes one
9479 argument: an entry from `org-agenda-get-day-entries'.
9481 FILTER can also be an alist with the car of each cell being
9482 either 'headline or 'category. For example:
9484 '((headline \"IMPORTANT\")
9485 (category \"Work\"))
9487 will only add headlines containing IMPORTANT or headlines
9488 belonging to the \"Work\" category.
9490 ARGS are symbols indicating what kind of entries to consider.
9491 By default `org-agenda-to-appt' will use :deadline, :scheduled
9492 and :timestamp entries. See the docstring of `org-diary' for
9493 details and examples.
9495 If an entry as a APPT_WARNTIME property, its value will be used
9496 to override `appt-message-warning-time'."
9497 (interactive "P")
9498 (if refresh (setq appt-time-msg-list nil))
9499 (if (eq filter t)
9500 (setq filter (read-from-minibuffer "Regexp filter: ")))
9501 (let* ((cnt 0) ; count added events
9502 (scope (or args '(:deadline :scheduled :timestamp)))
9503 (org-agenda-new-buffers nil)
9504 (org-deadline-warning-days 0)
9505 ;; Do not use `org-today' here because appt only takes
9506 ;; time and without date as argument, so it may pass wrong
9507 ;; information otherwise
9508 (today (org-date-to-gregorian
9509 (time-to-days (current-time))))
9510 (org-agenda-restrict nil)
9511 (files (org-agenda-files 'unrestricted)) entries file
9512 (org-agenda-buffer nil))
9513 ;; Get all entries which may contain an appt
9514 (org-agenda-prepare-buffers files)
9515 (while (setq file (pop files))
9516 (setq entries
9517 (delq nil
9518 (append entries
9519 (apply 'org-agenda-get-day-entries
9520 file today scope)))))
9521 ;; Map thru entries and find if we should filter them out
9522 (mapc
9523 (lambda(x)
9524 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9525 (cat (get-text-property 1 'org-category x))
9526 (tod (get-text-property 1 'time-of-day x))
9527 (ok (or (null filter)
9528 (and (stringp filter) (string-match filter evt))
9529 (and (functionp filter) (funcall filter x))
9530 (and (listp filter)
9531 (let ((cat-filter (cadr (assoc 'category filter)))
9532 (evt-filter (cadr (assoc 'headline filter))))
9533 (or (and (stringp cat-filter)
9534 (string-match cat-filter cat))
9535 (and (stringp evt-filter)
9536 (string-match evt-filter evt)))))))
9537 (wrn (get-text-property 1 'warntime x)))
9538 ;; FIXME: Shall we remove text-properties for the appt text?
9539 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9540 (when (and ok tod)
9541 (setq tod (concat "00" (number-to-string tod))
9542 tod (when (string-match
9543 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9544 (concat (match-string 1 tod) ":"
9545 (match-string 2 tod))))
9546 (if (version< emacs-version "23.3")
9547 (appt-add tod evt)
9548 (appt-add tod evt wrn))
9549 (setq cnt (1+ cnt))))) entries)
9550 (org-release-buffers org-agenda-new-buffers)
9551 (if (eq cnt 0)
9552 (message "No event to add")
9553 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9555 (autoload 'org-agenda-to-appt "org-agenda" "\
9556 Activate appointments found in `org-agenda-files'.
9557 With a \\[universal-argument] prefix, refresh the list of
9558 appointments.
9560 If FILTER is t, interactively prompt the user for a regular
9561 expression, and filter out entries that don't match it.
9563 If FILTER is a string, use this string as a regular expression
9564 for filtering entries out.
9566 If FILTER is a function, filter out entries against which
9567 calling the function returns nil. This function takes one
9568 argument: an entry from `org-agenda-get-day-entries'.
9570 FILTER can also be an alist with the car of each cell being
9571 either 'headline or 'category. For example:
9573 '((headline \"IMPORTANT\")
9574 (category \"Work\"))
9576 will only add headlines containing IMPORTANT or headlines
9577 belonging to the \"Work\" category.
9579 ARGS are symbols indicating what kind of entries to consider.
9580 By default `org-agenda-to-appt' will use :deadline, :scheduled
9581 and :timestamp entries. See the docstring of `org-diary' for
9582 details and examples.
9584 If an entry as a APPT_WARNTIME property, its value will be used
9585 to override `appt-message-warning-time'.
9587 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9589 (defun org-agenda-todayp (date)
9590 "Does DATE mean today, when considering `org-extend-today-until'?"
9591 (let ((today (org-today))
9592 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9593 date)))
9594 (eq date today)))
9596 (defun org-agenda-todo-yesterday (&optional arg)
9597 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9598 (interactive "P")
9599 (let* ((hour (third (decode-time
9600 (org-current-time))))
9601 (org-extend-today-until (1+ hour)))
9602 (org-agenda-todo arg)))
9604 (provide 'org-agenda)
9606 ;;; org-agenda.el ends here