Merge branch 'maint'
[org-mode.git] / lisp / org-agenda.el
blob2ce9f206e8f7a1ba76f77d3b33d69e07adc55367
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags do 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 nil
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 :version "24.3"
877 :type '(choice
878 (const :tag "Do not dim" nil)
879 (const :tag "Dim to a gray face" t)
880 (const :tag "Make invisible" invisible)))
882 (defcustom org-timeline-show-empty-dates 3
883 "Non-nil means `org-timeline' also shows dates without an entry.
884 When nil, only the days which actually have entries are shown.
885 When t, all days between the first and the last date are shown.
886 When an integer, show also empty dates, but if there is a gap of more than
887 N days, just insert a special line indicating the size of the gap."
888 :group 'org-agenda-skip
889 :type '(choice
890 (const :tag "None" nil)
891 (const :tag "All" t)
892 (integer :tag "at most")))
894 (defgroup org-agenda-startup nil
895 "Options concerning initial settings in the Agenda in Org Mode."
896 :tag "Org Agenda Startup"
897 :group 'org-agenda)
899 (defcustom org-agenda-menu-show-matcher t
900 "Non-nil means show the match string in the agenda dispatcher menu.
901 When nil, the matcher string is not shown, but is put into the help-echo
902 property so than moving the mouse over the command shows it.
903 Setting it to nil is good if matcher strings are very long and/or if
904 you want to use two-columns display (see `org-agenda-menu-two-columns')."
905 :group 'org-agenda
906 :version "24.1"
907 :type 'boolean)
909 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
911 (defcustom org-agenda-menu-two-columns nil
912 "Non-nil means, use two columns to show custom commands in the dispatcher.
913 If you use this, you probably want to set `org-agenda-menu-show-matcher'
914 to nil."
915 :group 'org-agenda
916 :version "24.1"
917 :type 'boolean)
919 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
920 (defcustom org-agenda-finalize-hook nil
921 "Hook run just before displaying an agenda buffer.
922 The buffer is still writable when the hook is called.
924 You can modify some of the buffer substrings but you should be
925 extra careful not to modify the text properties of the agenda
926 headlines as the agenda display heavily relies on them."
927 :group 'org-agenda-startup
928 :type 'hook)
930 (defcustom org-agenda-mouse-1-follows-link nil
931 "Non-nil means mouse-1 on a link will follow the link in the agenda.
932 A longer mouse click will still set point. Does not work on XEmacs.
933 Needs to be set before org.el is loaded."
934 :group 'org-agenda-startup
935 :type 'boolean)
937 (defcustom org-agenda-start-with-follow-mode nil
938 "The initial value of follow mode in a newly created agenda window."
939 :group 'org-agenda-startup
940 :type 'boolean)
942 (defcustom org-agenda-follow-indirect nil
943 "Non-nil means `org-agenda-follow-mode' displays only the
944 current item's tree, in an indirect buffer."
945 :group 'org-agenda
946 :version "24.1"
947 :type 'boolean)
949 (defcustom org-agenda-show-outline-path t
950 "Non-nil means show outline path in echo area after line motion."
951 :group 'org-agenda-startup
952 :type 'boolean)
954 (defcustom org-agenda-start-with-entry-text-mode nil
955 "The initial value of entry-text-mode in a newly created agenda window."
956 :group 'org-agenda-startup
957 :type 'boolean)
959 (defcustom org-agenda-entry-text-maxlines 5
960 "Number of text lines to be added when `E' is pressed in the agenda.
962 Note that this variable only used during agenda display. Add add entry text
963 when exporting the agenda, configure the variable
964 `org-agenda-add-entry-ext-maxlines'."
965 :group 'org-agenda
966 :type 'integer)
968 (defcustom org-agenda-entry-text-exclude-regexps nil
969 "List of regular expressions to clean up entry text.
970 The complete matches of all regular expressions in this list will be
971 removed from entry text before it is shown in the agenda."
972 :group 'org-agenda
973 :type '(repeat (regexp)))
975 (defvar org-agenda-entry-text-cleanup-hook nil
976 "Hook that is run after basic cleanup of entry text to be shown in agenda.
977 This cleanup is done in a temporary buffer, so the function may inspect and
978 change the entire buffer.
979 Some default stuff like drawers and scheduling/deadline dates will already
980 have been removed when this is called, as will any matches for regular
981 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
983 (defvar org-agenda-include-inactive-timestamps nil
984 "Non-nil means include inactive time stamps in agenda and timeline.
985 Dynamically scoped.")
987 (defgroup org-agenda-windows nil
988 "Options concerning the windows used by the Agenda in Org Mode."
989 :tag "Org Agenda Windows"
990 :group 'org-agenda)
992 (defcustom org-agenda-window-setup 'reorganize-frame
993 "How the agenda buffer should be displayed.
994 Possible values for this option are:
996 current-window Show agenda in the current window, keeping all other windows.
997 other-window Use `switch-to-buffer-other-window' to display agenda.
998 reorganize-frame Show only two windows on the current frame, the current
999 window and the agenda.
1000 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1001 Also, when exiting the agenda, kill that frame.
1002 See also the variable `org-agenda-restore-windows-after-quit'."
1003 :group 'org-agenda-windows
1004 :type '(choice
1005 (const current-window)
1006 (const other-frame)
1007 (const other-window)
1008 (const reorganize-frame)))
1010 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1011 "The min and max height of the agenda window as a fraction of frame height.
1012 The value of the variable is a cons cell with two numbers between 0 and 1.
1013 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1014 :group 'org-agenda-windows
1015 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1017 (defcustom org-agenda-restore-windows-after-quit nil
1018 "Non-nil means restore window configuration upon exiting agenda.
1019 Before the window configuration is changed for displaying the agenda,
1020 the current status is recorded. When the agenda is exited with
1021 `q' or `x' and this option is set, the old state is restored. If
1022 `org-agenda-window-setup' is `other-frame', the value of this
1023 option will be ignored."
1024 :group 'org-agenda-windows
1025 :type 'boolean)
1027 (defcustom org-agenda-ndays nil
1028 "Number of days to include in overview display.
1029 Should be 1 or 7.
1030 Obsolete, see `org-agenda-span'."
1031 :group 'org-agenda-daily/weekly
1032 :type 'integer)
1034 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1036 (defcustom org-agenda-span 'week
1037 "Number of days to include in overview display.
1038 Can be day, week, month, year, or any number of days.
1039 Custom commands can set this variable in the options section."
1040 :group 'org-agenda-daily/weekly
1041 :type '(choice (const :tag "Day" day)
1042 (const :tag "Week" week)
1043 (const :tag "Month" month)
1044 (const :tag "Year" year)
1045 (integer :tag "Custom")))
1047 (defcustom org-agenda-start-on-weekday 1
1048 "Non-nil means start the overview always on the specified weekday.
1049 0 denotes Sunday, 1 denotes Monday etc.
1050 When nil, always start on the current day.
1051 Custom commands can set this variable in the options section."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice (const :tag "Today" nil)
1054 (integer :tag "Weekday No.")))
1056 (defcustom org-agenda-show-all-dates t
1057 "Non-nil means `org-agenda' shows every day in the selected range.
1058 When nil, only the days which actually have entries are shown."
1059 :group 'org-agenda-daily/weekly
1060 :type 'boolean)
1062 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1063 "Format string for displaying dates in the agenda.
1064 Used by the daily/weekly agenda and by the timeline. This should be
1065 a format string understood by `format-time-string', or a function returning
1066 the formatted date as a string. The function must take a single argument,
1067 a calendar-style date list like (month day year)."
1068 :group 'org-agenda-daily/weekly
1069 :type '(choice
1070 (string :tag "Format string")
1071 (function :tag "Function")))
1073 (defun org-agenda-format-date-aligned (date)
1074 "Format a date string for display in the daily/weekly agenda, or timeline.
1075 This function makes sure that dates are aligned for easy reading."
1076 (require 'cal-iso)
1077 (let* ((dayname (calendar-day-name date))
1078 (day (cadr date))
1079 (day-of-week (calendar-day-of-week date))
1080 (month (car date))
1081 (monthname (calendar-month-name month))
1082 (year (nth 2 date))
1083 (iso-week (org-days-to-iso-week
1084 (calendar-absolute-from-gregorian date)))
1085 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1086 (1- year))
1087 ((and (= month 12) (<= iso-week 1))
1088 (1+ year))
1089 (t year)))
1090 (weekstring (if (= day-of-week 1)
1091 (format " W%02d" iso-week)
1092 "")))
1093 (format "%-10s %2d %s %4d%s"
1094 dayname day monthname year weekstring)))
1096 (defcustom org-agenda-time-leading-zero nil
1097 "Non-nil means use leading zero for military times in agenda.
1098 For example, 9:30am would become 09:30 rather than 9:30."
1099 :group 'org-agenda-daily/weekly
1100 :version "24.1"
1101 :type 'boolean)
1103 (defcustom org-agenda-timegrid-use-ampm nil
1104 "When set, show AM/PM style timestamps on the timegrid."
1105 :group 'org-agenda
1106 :version "24.1"
1107 :type 'boolean)
1109 (defun org-agenda-time-of-day-to-ampm (time)
1110 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1111 (let* ((hour-number (string-to-number (substring time 0 -3)))
1112 (minute (substring time -2))
1113 (ampm "am"))
1114 (cond
1115 ((equal hour-number 12)
1116 (setq ampm "pm"))
1117 ((> hour-number 12)
1118 (setq ampm "pm")
1119 (setq hour-number (- hour-number 12))))
1120 (concat
1121 (if org-agenda-time-leading-zero
1122 (format "%02d" hour-number)
1123 (format "%02s" (number-to-string hour-number)))
1124 ":" minute ampm)))
1126 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1127 "Conditionally convert TIME to AM/PM format
1128 based on `org-agenda-timegrid-use-ampm'"
1129 (if org-agenda-timegrid-use-ampm
1130 (org-agenda-time-of-day-to-ampm time)
1131 time))
1133 (defcustom org-agenda-weekend-days '(6 0)
1134 "Which days are weekend?
1135 These days get the special face `org-agenda-date-weekend' in the agenda
1136 and timeline buffers."
1137 :group 'org-agenda-daily/weekly
1138 :type '(set :greedy t
1139 (const :tag "Monday" 1)
1140 (const :tag "Tuesday" 2)
1141 (const :tag "Wednesday" 3)
1142 (const :tag "Thursday" 4)
1143 (const :tag "Friday" 5)
1144 (const :tag "Saturday" 6)
1145 (const :tag "Sunday" 0)))
1147 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1148 "Non-nil means jump to today when moving a past date forward in time.
1149 When using S-right in the agenda to move a a date forward, and the date
1150 stamp currently points to the past, the first key press will move it
1151 to today. WHen nil, just move one day forward even if the date stays
1152 in the past."
1153 :group 'org-agenda-daily/weekly
1154 :version "24.1"
1155 :type 'boolean)
1157 (defcustom org-agenda-include-diary nil
1158 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1159 Custom commands can set this variable in the options section."
1160 :group 'org-agenda-daily/weekly
1161 :type 'boolean)
1163 (defcustom org-agenda-include-deadlines t
1164 "If non-nil, include entries within their deadline warning period.
1165 Custom commands can set this variable in the options section."
1166 :group 'org-agenda-daily/weekly
1167 :version "24.1"
1168 :type 'boolean)
1170 (defcustom org-agenda-repeating-timestamp-show-all t
1171 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1172 When set to a list of strings, only show occurrences of repeating
1173 stamps for these TODO keywords. When nil, only one occurrence is
1174 shown, either today or the nearest into the future."
1175 :group 'org-agenda-daily/weekly
1176 :type '(choice
1177 (const :tag "Show repeating stamps" t)
1178 (repeat :tag "Show repeating stamps for these TODO keywords"
1179 (string :tag "TODO Keyword"))
1180 (const :tag "Don't show repeating stamps" nil)))
1182 (defcustom org-scheduled-past-days 10000
1183 "No. of days to continue listing scheduled items that are not marked DONE.
1184 When an item is scheduled on a date, it shows up in the agenda on this
1185 day and will be listed until it is marked done for the number of days
1186 given here."
1187 :group 'org-agenda-daily/weekly
1188 :type 'integer)
1190 (defcustom org-agenda-log-mode-items '(closed clock)
1191 "List of items that should be shown in agenda log mode.
1192 This list may contain the following symbols:
1194 closed Show entries that have been closed on that day.
1195 clock Show entries that have received clocked time on that day.
1196 state Show all logged state changes.
1197 Note that instead of changing this variable, you can also press `C-u l' in
1198 the agenda to display all available LOG items temporarily."
1199 :group 'org-agenda-daily/weekly
1200 :type '(set :greedy t (const closed) (const clock) (const state)))
1202 (defcustom org-agenda-clock-consistency-checks
1203 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1204 :gap-ok-around ("4:00")
1205 :default-face ((:background "DarkRed") (:foreground "white"))
1206 :overlap-face nil :gap-face nil :no-end-time-face nil
1207 :long-face nil :short-face nil)
1208 "This is a property list, with the following keys:
1210 :max-duration Mark clocking chunks that are longer than this time.
1211 This is a time string like \"HH:MM\", or the number
1212 of minutes as an integer.
1214 :min-duration Mark clocking chunks that are shorter that this.
1215 This is a time string like \"HH:MM\", or the number
1216 of minutes as an integer.
1218 :max-gap Mark gaps between clocking chunks that are longer than
1219 this duration. A number of minutes, or a string
1220 like \"HH:MM\".
1222 :gap-ok-around List of times during the day which are usually not working
1223 times. When a gap is detected, but the gap contains any
1224 of these times, the gap is *not* reported. For example,
1225 if this is (\"4:00\" \"13:00\") then gaps that contain
1226 4:00 in the morning (i.e. the night) and 13:00
1227 (i.e. a typical lunch time) do not cause a warning.
1228 You should have at least one time during the night in this
1229 list, or otherwise the first task each morning will trigger
1230 a warning because it follows a long gap.
1232 Furthermore, the following properties can be used to define faces for
1233 issue display.
1235 :default-face the default face, if the specific face is undefined
1236 :overlap-face face for overlapping clocks
1237 :gap-face face for gaps between clocks
1238 :no-end-time-face face for incomplete clocks
1239 :long-face face for clock intervals that are too long
1240 :short-face face for clock intervals that are too short"
1241 :group 'org-agenda-daily/weekly
1242 :group 'org-clock
1243 :version "24.1"
1244 :type 'plist)
1246 (defcustom org-agenda-log-mode-add-notes t
1247 "Non-nil means add first line of notes to log entries in agenda views.
1248 If a log item like a state change or a clock entry is associated with
1249 notes, the first line of these notes will be added to the entry in the
1250 agenda display."
1251 :group 'org-agenda-daily/weekly
1252 :type 'boolean)
1254 (defcustom org-agenda-start-with-log-mode nil
1255 "The initial value of log-mode in a newly created agenda window.
1256 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1257 explanations on the possible values."
1258 :group 'org-agenda-startup
1259 :group 'org-agenda-daily/weekly
1260 :type '(choice (const :tag "Don't show log items" nil)
1261 (const :tag "Show only log items" 'only)
1262 (const :tag "Show all possible log items" 'clockcheck)
1263 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1264 (choice (const :tag "Show closed log items" 'closed)
1265 (const :tag "Show clocked log items" 'clock)
1266 (const :tag "Show all logged state changes" 'state)))))
1268 (defcustom org-agenda-start-with-clockreport-mode nil
1269 "The initial value of clockreport-mode in a newly created agenda window."
1270 :group 'org-agenda-startup
1271 :group 'org-agenda-daily/weekly
1272 :type 'boolean)
1274 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1275 "Property list with parameters for the clocktable in clockreport mode.
1276 This is the display mode that shows a clock table in the daily/weekly
1277 agenda, the properties for this dynamic block can be set here.
1278 The usual clocktable parameters are allowed here, but you cannot set
1279 the properties :name, :tstart, :tend, :block, and :scope - these will
1280 be overwritten to make sure the content accurately reflects the
1281 current display in the agenda."
1282 :group 'org-agenda-daily/weekly
1283 :type 'plist)
1285 (defcustom org-agenda-search-view-always-boolean nil
1286 "Non-nil means the search string is interpreted as individual parts.
1288 The search string for search view can either be interpreted as a phrase,
1289 or as a list of snippets that define a boolean search for a number of
1290 strings.
1292 When this is non-nil, the string will be split on whitespace, and each
1293 snippet will be searched individually, and all must match in order to
1294 select an entry. A snippet is then a single string of non-white
1295 characters, or a string in double quotes, or a regexp in {} braces.
1296 If a snippet is preceded by \"-\", the snippet must *not* match.
1297 \"+\" is syntactic sugar for positive selection. Each snippet may
1298 be found as a full word or a partial word, but see the variable
1299 `org-agenda-search-view-force-full-words'.
1301 When this is nil, search will look for the entire search phrase as one,
1302 with each space character matching any amount of whitespace, including
1303 line breaks.
1305 Even when this is nil, you can still switch to Boolean search dynamically
1306 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1307 is a regexp marked with braces like \"{abc}\", this will also switch to
1308 boolean search."
1309 :group 'org-agenda-search-view
1310 :version "24.1"
1311 :type 'boolean)
1313 (if (fboundp 'defvaralias)
1314 (defvaralias 'org-agenda-search-view-search-words-only
1315 'org-agenda-search-view-always-boolean))
1317 (defcustom org-agenda-search-view-force-full-words nil
1318 "Non-nil means, search words must be matches as complete words.
1319 When nil, they may also match part of a word."
1320 :group 'org-agenda-search-view
1321 :version "24.1"
1322 :type 'boolean)
1324 (defcustom org-agenda-search-view-max-outline-level nil
1325 "Maximum outline level to display in search view.
1326 E.g. when this is set to 1, the search view will only
1327 show headlines of level 1."
1328 :group 'org-agenda-search-view
1329 :version "24.3"
1330 :type 'integer)
1332 (defgroup org-agenda-time-grid nil
1333 "Options concerning the time grid in the Org-mode Agenda."
1334 :tag "Org Agenda Time Grid"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-search-headline-for-time t
1338 "Non-nil means search headline for a time-of-day.
1339 If the headline contains a time-of-day in one format or another, it will
1340 be used to sort the entry into the time sequence of items for a day.
1341 Some people have time stamps in the headline that refer to the creation
1342 time or so, and then this produces an unwanted side effect. If this is
1343 the case for your, use this variable to turn off searching the headline
1344 for a time."
1345 :group 'org-agenda-time-grid
1346 :type 'boolean)
1348 (defcustom org-agenda-use-time-grid t
1349 "Non-nil means show a time grid in the agenda schedule.
1350 A time grid is a set of lines for specific times (like every two hours between
1351 8:00 and 20:00). The items scheduled for a day at specific times are
1352 sorted in between these lines.
1353 For details about when the grid will be shown, and what it will look like, see
1354 the variable `org-agenda-time-grid'."
1355 :group 'org-agenda-time-grid
1356 :type 'boolean)
1358 (defcustom org-agenda-time-grid
1359 '((daily today require-timed)
1360 "----------------"
1361 (800 1000 1200 1400 1600 1800 2000))
1363 "The settings for time grid for agenda display.
1364 This is a list of three items. The first item is again a list. It contains
1365 symbols specifying conditions when the grid should be displayed:
1367 daily if the agenda shows a single day
1368 weekly if the agenda shows an entire week
1369 today show grid on current date, independent of daily/weekly display
1370 require-timed show grid only if at least one item has a time specification
1372 The second item is a string which will be placed behind the grid time.
1374 The third item is a list of integers, indicating the times that should have
1375 a grid line."
1376 :group 'org-agenda-time-grid
1377 :type
1378 '(list
1379 (set :greedy t :tag "Grid Display Options"
1380 (const :tag "Show grid in single day agenda display" daily)
1381 (const :tag "Show grid in weekly agenda display" weekly)
1382 (const :tag "Always show grid for today" today)
1383 (const :tag "Show grid only if any timed entries are present"
1384 require-timed)
1385 (const :tag "Skip grid times already present in an entry"
1386 remove-match))
1387 (string :tag "Grid String")
1388 (repeat :tag "Grid Times" (integer :tag "Time"))))
1390 (defcustom org-agenda-show-current-time-in-grid t
1391 "Non-nil means show the current time in the time grid."
1392 :group 'org-agenda-time-grid
1393 :version "24.1"
1394 :type 'boolean)
1396 (defcustom org-agenda-current-time-string
1397 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1398 "The string for the current time marker in the agenda."
1399 :group 'org-agenda-time-grid
1400 :version "24.1"
1401 :type 'string)
1403 (defgroup org-agenda-sorting nil
1404 "Options concerning sorting in the Org-mode Agenda."
1405 :tag "Org Agenda Sorting"
1406 :group 'org-agenda)
1408 (defcustom org-agenda-sorting-strategy
1409 '((agenda habit-down time-up priority-down category-keep)
1410 (todo priority-down category-keep)
1411 (tags priority-down category-keep)
1412 (search category-keep))
1413 "Sorting structure for the agenda items of a single day.
1414 This is a list of symbols which will be used in sequence to determine
1415 if an entry should be listed before another entry. The following
1416 symbols are recognized:
1418 time-up Put entries with time-of-day indications first, early first
1419 time-down Put entries with time-of-day indications first, late first
1420 category-keep Keep the default order of categories, corresponding to the
1421 sequence in `org-agenda-files'.
1422 category-up Sort alphabetically by category, A-Z.
1423 category-down Sort alphabetically by category, Z-A.
1424 tag-up Sort alphabetically by last tag, A-Z.
1425 tag-down Sort alphabetically by last tag, Z-A.
1426 priority-up Sort numerically by priority, high priority last.
1427 priority-down Sort numerically by priority, high priority first.
1428 todo-state-up Sort by todo state, tasks that are done last.
1429 todo-state-down Sort by todo state, tasks that are done first.
1430 effort-up Sort numerically by estimated effort, high effort last.
1431 effort-down Sort numerically by estimated effort, high effort first.
1432 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1433 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1434 habit-up Put entries that are habits first
1435 habit-down Put entries that are habits last
1436 alpha-up Sort headlines alphabetically
1437 alpha-down Sort headlines alphabetically, reversed
1439 The different possibilities will be tried in sequence, and testing stops
1440 if one comparison returns a \"not-equal\". For example, the default
1441 '(time-up category-keep priority-down)
1442 means: Pull out all entries having a specified time of day and sort them,
1443 in order to make a time schedule for the current day the first thing in the
1444 agenda listing for the day. Of the entries without a time indication, keep
1445 the grouped in categories, don't sort the categories, but keep them in
1446 the sequence given in `org-agenda-files'. Within each category sort by
1447 priority.
1449 Leaving out `category-keep' would mean that items will be sorted across
1450 categories by priority.
1452 Instead of a single list, this can also be a set of list for specific
1453 contents, with a context symbol in the car of the list, any of
1454 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1456 Custom commands can bind this variable in the options section."
1457 :group 'org-agenda-sorting
1458 :type `(choice
1459 (repeat :tag "General" ,org-sorting-choice)
1460 (list :tag "Individually"
1461 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1462 (repeat ,org-sorting-choice))
1463 (cons (const :tag "Strategy for TODO lists" todo)
1464 (repeat ,org-sorting-choice))
1465 (cons (const :tag "Strategy for Tags matches" tags)
1466 (repeat ,org-sorting-choice))
1467 (cons (const :tag "Strategy for search matches" search)
1468 (repeat ,org-sorting-choice)))))
1470 (defcustom org-agenda-cmp-user-defined nil
1471 "A function to define the comparison `user-defined'.
1472 This function must receive two arguments, agenda entry a and b.
1473 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1474 the user comparison, return nil.
1475 When this is defined, you can make `user-defined-up' and `user-defined-down'
1476 part of an agenda sorting strategy."
1477 :group 'org-agenda-sorting
1478 :type 'symbol)
1480 (defcustom org-sort-agenda-notime-is-late t
1481 "Non-nil means items without time are considered late.
1482 This is only relevant for sorting. When t, items which have no explicit
1483 time like 15:30 will be considered as 99:01, i.e. later than any items which
1484 do have a time. When nil, the default time is before 0:00. You can use this
1485 option to decide if the schedule for today should come before or after timeless
1486 agenda entries."
1487 :group 'org-agenda-sorting
1488 :type 'boolean)
1490 (defcustom org-sort-agenda-noeffort-is-high t
1491 "Non-nil means items without effort estimate are sorted as high effort.
1492 This also applies when filtering an agenda view with respect to the
1493 < or > effort operator. Then, tasks with no effort defined will be treated
1494 as tasks with high effort.
1495 When nil, such items are sorted as 0 minutes effort."
1496 :group 'org-agenda-sorting
1497 :type 'boolean)
1499 (defgroup org-agenda-line-format nil
1500 "Options concerning the entry prefix in the Org-mode agenda display."
1501 :tag "Org Agenda Line Format"
1502 :group 'org-agenda)
1504 (defcustom org-agenda-prefix-format
1505 '((agenda . " %i %-12:c%?-12t% s")
1506 (timeline . " % s")
1507 (todo . " %i %-12:c")
1508 (tags . " %i %-12:c")
1509 (search . " %i %-12:c"))
1510 "Format specifications for the prefix of items in the agenda views.
1511 An alist with five entries, each for the different agenda types. The
1512 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1513 The values are format strings.
1515 This format works similar to a printf format, with the following meaning:
1517 %c the category of the item, \"Diary\" for entries from the diary,
1518 or as given by the CATEGORY keyword or derived from the file name
1519 %e the effort required by the item
1520 %l the level of the item (insert X space(s) if item is of level X)
1521 %i the icon category of the item, see `org-agenda-category-icon-alist'
1522 %T the last tag of the item (ignore inherited tags, which come first)
1523 %t the HH:MM time-of-day specification if one applies to the entry
1524 %s Scheduling/Deadline information, a short string
1525 %(expression) Eval EXPRESSION and replace the control string
1526 by the result
1528 All specifiers work basically like the standard `%s' of printf, but may
1529 contain two additional characters: a question mark just after the `%'
1530 and a whitespace/punctuation character just before the final letter.
1532 If the first character after `%' is a question mark, the entire field
1533 will only be included if the corresponding value applies to the current
1534 entry. This is useful for fields which should have fixed width when
1535 present, but zero width when absent. For example, \"%?-12t\" will
1536 result in a 12 character time field if a time of the day is specified,
1537 but will completely disappear in entries which do not contain a time.
1539 If there is punctuation or whitespace character just before the final
1540 format letter, this character will be appended to the field value if
1541 the value is not empty. For example, the format \"%-12:c\" leads to
1542 \"Diary: \" if the category is \"Diary\". If the category were be
1543 empty, no additional colon would be inserted.
1545 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1546 which means:
1548 - Indent the line with two space characters
1549 - Give the category a 12 chars wide field, padded with whitespace on
1550 the right (because of `-'). Append a colon if there is a category
1551 (because of `:').
1552 - If there is a time-of-day, put it into a 12 chars wide field. If no
1553 time, don't put in an empty field, just skip it (because of '?').
1554 - Finally, put the scheduling information.
1556 See also the variables `org-agenda-remove-times-when-in-prefix' and
1557 `org-agenda-remove-tags'.
1559 Custom commands can set this variable in the options section."
1560 :type '(choice
1561 (string :tag "General format")
1562 (list :greedy t :tag "View dependent"
1563 (cons (const agenda) (string :tag "Format"))
1564 (cons (const timeline) (string :tag "Format"))
1565 (cons (const todo) (string :tag "Format"))
1566 (cons (const tags) (string :tag "Format"))
1567 (cons (const search) (string :tag "Format"))))
1568 :group 'org-agenda-line-format)
1570 (defvar org-prefix-format-compiled nil
1571 "The compiled prefix format and associated variables.
1572 This is a list where first element is a list of variable bindings, and second
1573 element is the compiled format expression. See the variable
1574 `org-agenda-prefix-format'.")
1576 (defcustom org-agenda-todo-keyword-format "%-1s"
1577 "Format for the TODO keyword in agenda lines.
1578 Set this to something like \"%-12s\" if you want all TODO keywords
1579 to occupy a fixed space in the agenda display."
1580 :group 'org-agenda-line-format
1581 :type 'string)
1583 (defcustom org-agenda-diary-sexp-prefix nil
1584 "A regexp that matches part of a diary sexp entry
1585 which should be treated as scheduling/deadline information in
1586 `org-agenda'.
1588 For example, you can use this to extract the `diary-remind-message' from
1589 `diary-remind' entries."
1590 :group 'org-agenda-line-format
1591 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1593 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1594 "Text preceding timerange entries in the agenda view.
1595 This is a list with two strings. The first applies when the range
1596 is entirely on one day. The second applies if the range spans several days.
1597 The strings may have two \"%d\" format specifiers which will be filled
1598 with the sequence number of the days, and the total number of days in the
1599 range, respectively."
1600 :group 'org-agenda-line-format
1601 :type '(list
1602 (string :tag "Deadline today ")
1603 (choice :tag "Deadline relative"
1604 (string :tag "Format string")
1605 (function))))
1607 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1608 "Text preceding scheduled items in the agenda view.
1609 This is a list with two strings. The first applies when the item is
1610 scheduled on the current day. The second applies when it has been scheduled
1611 previously, it may contain a %d indicating that this is the nth time that
1612 this item is scheduled, due to automatic rescheduling of unfinished items
1613 for the following day. So this number is one larger than the number of days
1614 that passed since this item was scheduled first."
1615 :group 'org-agenda-line-format
1616 :type '(list
1617 (string :tag "Scheduled today ")
1618 (string :tag "Scheduled previously")))
1620 (defcustom org-agenda-inactive-leader "["
1621 "Text preceding item pulled into the agenda by inactive time stamps.
1622 These entries are added to the agenda when pressing \"[\"."
1623 :group 'org-agenda-line-format
1624 :version "24.1"
1625 :type '(list
1626 (string :tag "Scheduled today ")
1627 (string :tag "Scheduled previously")))
1629 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1630 "Text preceding deadline items in the agenda view.
1631 This is a list with two strings. The first applies when the item has its
1632 deadline on the current day. The second applies when it is in the past or
1633 in the future, it may contain %d to capture how many days away the deadline
1634 is (was)."
1635 :group 'org-agenda-line-format
1636 :type '(list
1637 (string :tag "Deadline today ")
1638 (choice :tag "Deadline relative"
1639 (string :tag "Format string")
1640 (function))))
1642 (defcustom org-agenda-remove-times-when-in-prefix t
1643 "Non-nil means remove duplicate time specifications in agenda items.
1644 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1645 time-of-day specification in a headline or diary entry is extracted and
1646 placed into the prefix. If this option is non-nil, the original specification
1647 \(a timestamp or -range, or just a plain time(range) specification like
1648 11:30-4pm) will be removed for agenda display. This makes the agenda less
1649 cluttered.
1650 The option can be t or nil. It may also be the symbol `beg', indicating
1651 that the time should only be removed when it is located at the beginning of
1652 the headline/diary entry."
1653 :group 'org-agenda-line-format
1654 :type '(choice
1655 (const :tag "Always" t)
1656 (const :tag "Never" nil)
1657 (const :tag "When at beginning of entry" beg)))
1659 (defcustom org-agenda-remove-timeranges-from-blocks nil
1660 "Non-nil means remove time ranges specifications in agenda
1661 items that span on several days."
1662 :group 'org-agenda-line-format
1663 :version "24.1"
1664 :type 'boolean)
1666 (defcustom org-agenda-default-appointment-duration nil
1667 "Default duration for appointments that only have a starting time.
1668 When nil, no duration is specified in such cases.
1669 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1670 :group 'org-agenda-line-format
1671 :type '(choice
1672 (integer :tag "Minutes")
1673 (const :tag "No default duration")))
1675 (defcustom org-agenda-show-inherited-tags t
1676 "Non-nil means show inherited tags in each agenda line.
1678 When this option is set to 'always, it take precedences over
1679 `org-agenda-use-tag-inheritance' and inherited tags are shown
1680 in every agenda.
1682 When this option is set to t (the default), inherited tags are
1683 shown when they are available, i.e. when the value of
1684 `org-agenda-use-tag-inheritance' has been taken into account.
1686 This can be set to a list of agenda types in which the agenda
1687 must display the inherited tags. Available types are 'todo,
1688 'agenda, 'search and 'timeline.
1690 When set to nil, never show inherited tags in agenda lines."
1691 :group 'org-agenda-line-format
1692 :group 'org-agenda
1693 :version "24.3"
1694 :type '(choice
1695 (const :tag "Show inherited tags when available" t)
1696 (const :tag "Always show inherited tags" 'always)
1697 (repeat :tag "Show inherited tags only in selected agenda types"
1698 (symbol :tag "Agenda type"))))
1700 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1701 "List of agenda view types where to use tag inheritance.
1703 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1704 controlled by `org-use-tag-inheritance'. In other agenda types,
1705 `org-use-tag-inheritance' is not used for the selection of the
1706 agenda entries. Still, you may want the agenda to be aware of
1707 the inherited tags anyway, e.g. for later tag filtering.
1709 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1711 This variable has no effect if `org-agenda-show-inherited-tags'
1712 is set to 'always. In that case, the agenda is aware of those
1713 tags.
1715 The default value sets tags in every agenda type. Setting this
1716 option to nil will speed up non-tags agenda view a lot."
1717 :group 'org-agenda
1718 :version "24.3"
1719 :type '(choice
1720 (const :tag "Use tag inheritance in all agenda types" t)
1721 (repeat :tag "Use tag inheritance in selected agenda types"
1722 (symbol :tag "Agenda type"))))
1724 (defcustom org-agenda-hide-tags-regexp nil
1725 "Regular expression used to filter away specific tags in agenda views.
1726 This means that these tags will be present, but not be shown in the agenda
1727 line. Secondary filtering will still work on the hidden tags.
1728 Nil means don't hide any tags."
1729 :group 'org-agenda-line-format
1730 :type '(choice
1731 (const :tag "Hide none" nil)
1732 (string :tag "Regexp ")))
1734 (defcustom org-agenda-remove-tags nil
1735 "Non-nil means remove the tags from the headline copy in the agenda.
1736 When this is the symbol `prefix', only remove tags when
1737 `org-agenda-prefix-format' contains a `%T' specifier."
1738 :group 'org-agenda-line-format
1739 :type '(choice
1740 (const :tag "Always" t)
1741 (const :tag "Never" nil)
1742 (const :tag "When prefix format contains %T" prefix)))
1744 (if (fboundp 'defvaralias)
1745 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1746 'org-agenda-remove-tags))
1748 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1749 "Shift tags in agenda items to this column.
1750 If this number is positive, it specifies the column. If it is negative,
1751 it means that the tags should be flushright to that column. For example,
1752 -80 works well for a normal 80 character screen."
1753 :group 'org-agenda-line-format
1754 :type 'integer)
1756 (if (fboundp 'defvaralias)
1757 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1759 (defcustom org-agenda-fontify-priorities 'cookies
1760 "Non-nil means highlight low and high priorities in agenda.
1761 When t, the highest priority entries are bold, lowest priority italic.
1762 However, settings in `org-priority-faces' will overrule these faces.
1763 When this variable is the symbol `cookies', only fontify the
1764 cookies, not the entire task.
1765 This may also be an association list of priority faces, whose
1766 keys are the character values of `org-highest-priority',
1767 `org-default-priority', and `org-lowest-priority' (the default values
1768 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1769 color as a string, or a list like `(:background \"Red\")'.
1770 If it is a color, the variable `org-faces-easy-properties'
1771 determines if it is a foreground or a background color."
1772 :group 'org-agenda-line-format
1773 :type '(choice
1774 (const :tag "Never" nil)
1775 (const :tag "Defaults" t)
1776 (const :tag "Cookies only" cookies)
1777 (repeat :tag "Specify"
1778 (list (character :tag "Priority" :value ?A)
1779 (choice :tag "Face "
1780 (string :tag "Color")
1781 (sexp :tag "Face"))))))
1783 (defcustom org-agenda-day-face-function nil
1784 "Function called to determine what face should be used to display a day.
1785 The only argument passed to that function is the day. It should
1786 returns a face, or nil if does not want to specify a face and let
1787 the normal rules apply."
1788 :group 'org-agenda-line-format
1789 :version "24.1"
1790 :type 'function)
1792 (defcustom org-agenda-category-icon-alist nil
1793 "Alist of category icon to be displayed in agenda views.
1795 Each entry should have the following format:
1797 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1799 Where CATEGORY-REGEXP is a regexp matching the categories where
1800 the icon should be displayed.
1801 FILE-OR-DATA either a file path or a string containing image data.
1803 The other fields can be omitted safely if not needed:
1804 TYPE indicates the image type.
1805 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1806 image data.
1807 PROPS are additional image attributes to assign to the image,
1808 like, e.g. `:ascent center'.
1810 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1812 If you want to set the display properties yourself, just put a
1813 list as second element:
1815 (CATEGORY-REGEXP (MY PROPERTY LIST))
1817 For example, to display a 16px horizontal space for Emacs
1818 category, you can use:
1820 (\"Emacs\" '(space . (:width (16))))"
1821 :group 'org-agenda-line-format
1822 :version "24.1"
1823 :type '(alist :key-type (string :tag "Regexp matching category")
1824 :value-type (choice (list :tag "Icon"
1825 (string :tag "File or data")
1826 (symbol :tag "Type")
1827 (boolean :tag "Data?")
1828 (repeat :tag "Extra image properties" :inline t symbol))
1829 (list :tag "Display properties" sexp))))
1831 (defgroup org-agenda-column-view nil
1832 "Options concerning column view in the agenda."
1833 :tag "Org Agenda Column View"
1834 :group 'org-agenda)
1836 (defcustom org-agenda-columns-show-summaries t
1837 "Non-nil means show summaries for columns displayed in the agenda view."
1838 :group 'org-agenda-column-view
1839 :type 'boolean)
1841 (defcustom org-agenda-columns-compute-summary-properties t
1842 "Non-nil means recompute all summary properties before column view.
1843 When column view in the agenda is listing properties that have a summary
1844 operator, it can go to all relevant buffers and recompute the summaries
1845 there. This can mean overhead for the agenda column view, but is necessary
1846 to have thing up to date.
1847 As a special case, a CLOCKSUM property also makes sure that the clock
1848 computations are current."
1849 :group 'org-agenda-column-view
1850 :type 'boolean)
1852 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1853 "Non-nil means the duration of an appointment will add to day effort.
1854 The property to which appointment durations will be added is the one given
1855 in the option `org-effort-property'. If an appointment does not have
1856 an end time, `org-agenda-default-appointment-duration' will be used. If that
1857 is not set, an appointment without end time will not contribute to the time
1858 estimate."
1859 :group 'org-agenda-column-view
1860 :type 'boolean)
1862 (defcustom org-agenda-auto-exclude-function nil
1863 "A function called with a tag to decide if it is filtered on '/ RET'.
1864 The sole argument to the function, which is called once for each
1865 possible tag, is a string giving the name of the tag. The
1866 function should return either nil if the tag should be included
1867 as normal, or \"-<TAG>\" to exclude the tag.
1868 Note that for the purpose of tag filtering, only the lower-case version of
1869 all tags will be considered, so that this function will only ever see
1870 the lower-case version of all tags."
1871 :group 'org-agenda
1872 :type 'function)
1874 (defcustom org-agenda-bulk-custom-functions nil
1875 "Alist of characters and custom functions for bulk actions.
1876 For example, this value makes those two functions available:
1878 '((?R set-category)
1879 (?C bulk-cut))
1881 With selected entries in an agenda buffer, `B R' will call
1882 the custom function `set-category' on the selected entries.
1883 Note that functions in this alist don't need to be quoted."
1884 :type 'alist
1885 :version "24.1"
1886 :group 'org-agenda)
1888 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1889 "Execute BODY with point at location given by `org-hd-marker' property.
1890 If STRING is non-nil, the text property will be fetched from position 0
1891 in that string. If STRING is nil, it will be fetched from the beginning
1892 of the current line."
1893 (org-with-gensyms (marker)
1894 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1895 'org-hd-marker ,string)))
1896 (with-current-buffer (marker-buffer ,marker)
1897 (save-excursion
1898 (goto-char ,marker)
1899 ,@body)))))
1900 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1902 (defun org-add-agenda-custom-command (entry)
1903 "Replace or add a command in `org-agenda-custom-commands'.
1904 This is mostly for hacking and trying a new command - once the command
1905 works you probably want to add it to `org-agenda-custom-commands' for good."
1906 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1907 (if ass
1908 (setcdr ass (cdr entry))
1909 (push entry org-agenda-custom-commands))))
1911 ;;; Define the org-agenda-mode
1913 (defvar org-agenda-mode-map (make-sparse-keymap)
1914 "Keymap for `org-agenda-mode'.")
1915 (if (fboundp 'defvaralias)
1916 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1918 (defvar org-agenda-menu) ; defined later in this file.
1919 (defvar org-agenda-restrict nil) ; defined later in this file.
1920 (defvar org-agenda-follow-mode nil)
1921 (defvar org-agenda-entry-text-mode nil)
1922 (defvar org-agenda-clockreport-mode nil)
1923 (defvar org-agenda-show-log nil)
1924 (defvar org-agenda-redo-command nil)
1925 (defvar org-agenda-query-string nil)
1926 (defvar org-agenda-mode-hook nil
1927 "Hook run after `org-agenda-mode' is turned on.
1928 The buffer is still writable when this hook is called.")
1929 (defvar org-agenda-type nil)
1930 (defvar org-agenda-force-single-file nil)
1931 (defvar org-agenda-bulk-marked-entries nil
1932 "List of markers that refer to marked entries in the agenda.")
1934 ;;; Multiple agenda buffers support
1936 (defcustom org-agenda-sticky nil
1937 "Non-nil means agenda q key will bury agenda buffers.
1938 Agenda commands will then show existing buffer instead of generating new ones.
1939 When nil, `q' will kill the single agenda buffer."
1940 :group 'org-agenda
1941 :version "24.3"
1942 :type 'boolean)
1945 ;;;###autoload
1946 (defun org-toggle-sticky-agenda (&optional arg)
1947 "Toggle `org-agenda-sticky'."
1948 (interactive "P")
1949 (let ((new-value (if arg
1950 (> (prefix-numeric-value arg) 0)
1951 (not org-agenda-sticky))))
1952 (if (equal new-value org-agenda-sticky)
1953 (and (org-called-interactively-p 'interactive)
1954 (message "Sticky agenda was already %s"
1955 (if org-agenda-sticky "enabled" "disabled")))
1956 (setq org-agenda-sticky new-value)
1957 (org-agenda-kill-all-agenda-buffers)
1958 (and (org-called-interactively-p 'interactive)
1959 (message "Sticky agenda was %s"
1960 (if org-agenda-sticky "enabled" "disabled"))))))
1962 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1963 Toggle `org-agenda-sticky'.
1965 \(fn &optional ARG)" t nil)
1967 (defvar org-agenda-buffer nil
1968 "Agenda buffer currently being generated.")
1970 (defvar org-agenda-last-prefix-arg nil)
1971 (defvar org-agenda-this-buffer-name nil)
1972 (defvar org-agenda-doing-sticky-redo nil)
1973 (defvar org-agenda-this-buffer-is-sticky nil)
1975 (defconst org-agenda-local-vars
1976 '(org-agenda-this-buffer-name
1977 org-agenda-undo-list
1978 org-agenda-pending-undo-list
1979 org-agenda-follow-mode
1980 org-agenda-entry-text-mode
1981 org-agenda-clockreport-mode
1982 org-agenda-show-log
1983 org-agenda-redo-command
1984 org-agenda-query-string
1985 org-agenda-type
1986 org-agenda-bulk-marked-entries
1987 org-agenda-undo-has-started-in
1988 org-agenda-info
1989 org-agenda-tag-filter-overlays
1990 org-agenda-cat-filter-overlays
1991 org-agenda-pre-window-conf
1992 org-agenda-columns-active
1993 org-agenda-tag-filter
1994 org-agenda-category-filter
1995 org-agenda-markers
1996 org-agenda-last-search-view-search-was-boolean
1997 org-agenda-filtered-by-category
1998 org-agenda-filter-form
1999 org-agenda-show-window
2000 org-agenda-cycle-counter
2001 org-agenda-last-prefix-arg)
2002 "Variables that must be local in agenda buffers to allow multiple buffers.")
2004 (defun org-agenda-mode ()
2005 "Mode for time-sorted view on action items in Org-mode files.
2007 The following commands are available:
2009 \\{org-agenda-mode-map}"
2010 (interactive)
2011 (cond (org-agenda-doing-sticky-redo
2012 ;; Refreshing sticky agenda-buffer
2014 ;; Preserve the value of `org-agenda-local-vars' variables,
2015 ;; while letting `kill-all-local-variables' kill the rest
2016 (let ((save (buffer-local-variables)))
2017 (kill-all-local-variables)
2018 (mapc 'make-local-variable org-agenda-local-vars)
2019 (dolist (elem save)
2020 (let ((var (car elem))
2021 (val (cdr elem)))
2022 (when (and val
2023 (member var org-agenda-local-vars))
2024 (set var val)))))
2025 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2026 (org-agenda-sticky
2027 ;; Creating a sticky Agenda buffer for the first time
2028 (kill-all-local-variables)
2029 (mapc 'make-local-variable org-agenda-local-vars)
2030 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2032 ;; Creating a non-sticky agenda buffer
2033 (kill-all-local-variables)
2034 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2035 (setq org-agenda-undo-list nil
2036 org-agenda-pending-undo-list nil
2037 org-agenda-bulk-marked-entries nil)
2038 (setq major-mode 'org-agenda-mode)
2039 ;; Keep global-font-lock-mode from turning on font-lock-mode
2040 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2041 (setq mode-name "Org-Agenda")
2042 (use-local-map org-agenda-mode-map)
2043 (easy-menu-add org-agenda-menu)
2044 (if org-startup-truncated (setq truncate-lines t))
2045 (org-set-local 'line-move-visual nil)
2046 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2047 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2048 ;; Make sure properties are removed when copying text
2049 (make-local-variable 'filter-buffer-substring-functions)
2050 (add-hook 'filter-buffer-substring-functions
2051 (lambda (fun start end delete)
2052 (substring-no-properties (funcall fun start end delete))))
2053 (unless org-agenda-keep-modes
2054 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2055 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2056 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2057 org-agenda-show-log org-agenda-start-with-log-mode))
2059 (easy-menu-change
2060 '("Agenda") "Agenda Files"
2061 (append
2062 (list
2063 (vector
2064 (if (get 'org-agenda-files 'org-restrict)
2065 "Restricted to single file"
2066 "Edit File List")
2067 '(org-edit-agenda-file-list)
2068 (not (get 'org-agenda-files 'org-restrict)))
2069 "--")
2070 (mapcar 'org-file-menu-entry (org-agenda-files))))
2071 (org-agenda-set-mode-name)
2072 (apply
2073 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2074 (list 'org-agenda-mode-hook)))
2076 (substitute-key-definition 'undo 'org-agenda-undo
2077 org-agenda-mode-map global-map)
2078 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2079 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2080 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2081 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2082 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2083 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2084 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2085 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2086 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2087 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2088 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2089 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2090 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2091 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2092 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2093 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2094 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2095 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2096 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2097 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2098 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2099 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2100 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2101 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2102 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2103 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2104 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2105 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2106 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2107 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2108 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2109 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2110 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2111 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2112 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2113 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2114 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2115 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2116 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2117 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2118 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2119 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2120 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2121 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2122 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2123 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2125 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2126 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2127 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2128 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2129 (while l (org-defkey org-agenda-mode-map
2130 (int-to-string (pop l)) 'digit-argument)))
2132 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2133 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2134 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2135 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2136 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2137 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2138 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2139 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2140 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2141 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2142 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2143 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2144 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2145 'org-clock-modify-effort-estimate)
2146 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2147 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2148 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2149 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2150 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2151 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2152 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2153 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2154 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2155 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2156 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2157 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2158 (substitute-key-definition 'next-line 'org-agenda-next-line
2159 org-agenda-mode-map global-map)
2160 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2161 org-agenda-mode-map global-map)
2162 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2163 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2164 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2165 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2166 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2167 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2168 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2169 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2170 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2171 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2172 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2173 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2174 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2175 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2176 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2177 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2178 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2179 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2180 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2181 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2182 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2183 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2184 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2185 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2186 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2187 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2188 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2189 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2190 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2191 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2193 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2194 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2195 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2196 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2197 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2198 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2199 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2200 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2201 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2202 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2203 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2204 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2206 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2207 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2208 (when org-agenda-mouse-1-follows-link
2209 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2210 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2211 '("Agenda"
2212 ("Agenda Files")
2213 "--"
2214 ("Agenda Dates"
2215 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2216 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2217 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2218 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2219 "--"
2220 ("View"
2221 ["Day View" org-agenda-day-view
2222 :active (org-agenda-check-type nil 'agenda)
2223 :style radio :selected (eq org-agenda-current-span 'day)
2224 :keys "v d (or just d)"]
2225 ["Week View" org-agenda-week-view
2226 :active (org-agenda-check-type nil 'agenda)
2227 :style radio :selected (eq org-agenda-current-span 'week)
2228 :keys "v w (or just w)"]
2229 ["Month View" org-agenda-month-view
2230 :active (org-agenda-check-type nil 'agenda)
2231 :style radio :selected (eq org-agenda-current-span 'month)
2232 :keys "v m"]
2233 ["Year View" org-agenda-year-view
2234 :active (org-agenda-check-type nil 'agenda)
2235 :style radio :selected (eq org-agenda-current-span 'year)
2236 :keys "v y"]
2237 "--"
2238 ["Include Diary" org-agenda-toggle-diary
2239 :style toggle :selected org-agenda-include-diary
2240 :active (org-agenda-check-type nil 'agenda)]
2241 ["Include Deadlines" org-agenda-toggle-deadlines
2242 :style toggle :selected org-agenda-include-deadlines
2243 :active (org-agenda-check-type nil 'agenda)]
2244 ["Use Time Grid" org-agenda-toggle-time-grid
2245 :style toggle :selected org-agenda-use-time-grid
2246 :active (org-agenda-check-type nil 'agenda)]
2247 "--"
2248 ["Show clock report" org-agenda-clockreport-mode
2249 :style toggle :selected org-agenda-clockreport-mode
2250 :active (org-agenda-check-type nil 'agenda)]
2251 ["Show some entry text" org-agenda-entry-text-mode
2252 :style toggle :selected org-agenda-entry-text-mode
2253 :active t]
2254 "--"
2255 ["Show Logbook entries" org-agenda-log-mode
2256 :style toggle :selected org-agenda-show-log
2257 :active (org-agenda-check-type nil 'agenda 'timeline)
2258 :keys "v l (or just l)"]
2259 ["Include archived trees" org-agenda-archives-mode
2260 :style toggle :selected org-agenda-archives-mode :active t
2261 :keys "v a"]
2262 ["Include archive files" (org-agenda-archives-mode t)
2263 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2264 :keys "v A"]
2265 "--"
2266 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2267 ["Write view to file" org-agenda-write t]
2268 ["Rebuild buffer" org-agenda-redo t]
2269 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2270 "--"
2271 ["Show original entry" org-agenda-show t]
2272 ["Go To (other window)" org-agenda-goto t]
2273 ["Go To (this window)" org-agenda-switch-to t]
2274 ["Capture with cursor date" org-agenda-capture t]
2275 ["Follow Mode" org-agenda-follow-mode
2276 :style toggle :selected org-agenda-follow-mode :active t]
2277 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2278 "--"
2279 ("TODO"
2280 ["Cycle TODO" org-agenda-todo t]
2281 ["Next TODO set" org-agenda-todo-nextset t]
2282 ["Previous TODO set" org-agenda-todo-previousset t]
2283 ["Add note" org-agenda-add-note t])
2284 ("Archive/Refile/Delete"
2285 ["Archive default" org-agenda-archive-default t]
2286 ["Archive default" org-agenda-archive-default-with-confirmation t]
2287 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2288 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2289 ["Archive subtree" org-agenda-archive t]
2290 "--"
2291 ["Refile" org-agenda-refile t]
2292 "--"
2293 ["Delete subtree" org-agenda-kill t])
2294 ("Bulk action"
2295 ["Mark entry" org-agenda-bulk-mark t]
2296 ["Mark all" org-agenda-bulk-mark-all t]
2297 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2298 ["Unmark entry" org-agenda-bulk-unmark t]
2299 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2300 ["Act on all marked" org-agenda-bulk-action t]
2301 "--"
2302 ("Tags and Properties"
2303 ["Show all Tags" org-agenda-show-tags t]
2304 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2305 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2306 "--"
2307 ["Column View" org-columns t])
2308 ("Deadline/Schedule"
2309 ["Schedule" org-agenda-schedule t]
2310 ["Set Deadline" org-agenda-deadline t]
2311 "--"
2312 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2313 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2314 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2315 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2316 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2317 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2318 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2319 ("Clock and Effort"
2320 ["Clock in" org-agenda-clock-in t]
2321 ["Clock out" org-agenda-clock-out t]
2322 ["Clock cancel" org-agenda-clock-cancel t]
2323 ["Goto running clock" org-clock-goto t]
2324 "--"
2325 ["Set Effort" org-agenda-set-effort t]
2326 ["Change clocked effort" org-clock-modify-effort-estimate
2327 (org-clock-is-active)])
2328 ("Priority"
2329 ["Set Priority" org-agenda-priority t]
2330 ["Increase Priority" org-agenda-priority-up t]
2331 ["Decrease Priority" org-agenda-priority-down t]
2332 ["Show Priority" org-show-priority t])
2333 ("Calendar/Diary"
2334 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2335 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2336 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2337 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2338 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2339 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2340 "--"
2341 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2342 "--"
2343 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2344 "--"
2345 ("MobileOrg"
2346 ["Push Files and Views" org-mobile-push t]
2347 ["Get Captured and Flagged" org-mobile-pull t]
2348 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2349 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2350 "--"
2351 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2352 "--"
2353 ["Quit" org-agenda-quit t]
2354 ["Exit and Release Buffers" org-agenda-exit t]
2357 ;;; Agenda undo
2359 (defvar org-agenda-allow-remote-undo t
2360 "Non-nil means allow remote undo from the agenda buffer.")
2361 (defvar org-agenda-undo-has-started-in nil
2362 "Buffers that have already seen `undo-start' in the current undo sequence.")
2364 (defun org-agenda-undo ()
2365 "Undo a remote editing step in the agenda.
2366 This undoes changes both in the agenda buffer and in the remote buffer
2367 that have been changed along."
2368 (interactive)
2369 (or org-agenda-allow-remote-undo
2370 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2371 (if (not (eq this-command last-command))
2372 (setq org-agenda-undo-has-started-in nil
2373 org-agenda-pending-undo-list org-agenda-undo-list))
2374 (if (not org-agenda-pending-undo-list)
2375 (error "No further undo information"))
2376 (let* ((entry (pop org-agenda-pending-undo-list))
2377 buf line cmd rembuf)
2378 (setq cmd (pop entry) line (pop entry))
2379 (setq rembuf (nth 2 entry))
2380 (org-with-remote-undo rembuf
2381 (while (bufferp (setq buf (pop entry)))
2382 (if (pop entry)
2383 (with-current-buffer buf
2384 (let ((last-undo-buffer buf)
2385 (inhibit-read-only t))
2386 (unless (memq buf org-agenda-undo-has-started-in)
2387 (push buf org-agenda-undo-has-started-in)
2388 (make-local-variable 'pending-undo-list)
2389 (undo-start))
2390 (while (and pending-undo-list
2391 (listp pending-undo-list)
2392 (not (car pending-undo-list)))
2393 (pop pending-undo-list))
2394 (undo-more 1))))))
2395 (org-goto-line line)
2396 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2398 (defun org-verify-change-for-undo (l1 l2)
2399 "Verify that a real change occurred between the undo lists L1 and L2."
2400 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2401 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2402 (not (eq l1 l2)))
2404 ;;; Agenda dispatch
2406 (defvar org-agenda-restrict-begin (make-marker))
2407 (defvar org-agenda-restrict-end (make-marker))
2408 (defvar org-agenda-last-dispatch-buffer nil)
2409 (defvar org-agenda-overriding-restriction nil)
2411 (defcustom org-agenda-custom-commands-contexts nil
2412 "Alist of custom agenda keys and contextual rules.
2414 For example, if you have a custom agenda command \"p\" and you
2415 want this command to be accessible only from plain text files,
2416 use this:
2418 '((\"p\" ((in-file . \"\\.txt\"))))
2420 Here are the available contexts definitions:
2422 in-file: command displayed only in matching files
2423 in-mode: command displayed only in matching modes
2424 not-in-file: command not displayed in matching files
2425 not-in-mode: command not displayed in matching modes
2426 in-buffer: command displayed only in matching buffers
2427 not-in-buffer: command not displayed in matching buffers
2428 [function]: a custom function taking no argument
2430 If you define several checks, the agenda command will be
2431 accessible if there is at least one valid check.
2433 You can also bind a key to another agenda custom command
2434 depending on contextual rules.
2436 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2438 Here it means: in .txt files, use \"p\" as the key for the
2439 agenda command otherwise associated with \"q\". (The command
2440 originally associated with \"q\" is not displayed to avoid
2441 duplicates.)"
2442 :version "24.3"
2443 :group 'org-agenda-custom-commands
2444 :type '(repeat (list :tag "Rule"
2445 (string :tag " Agenda key")
2446 (string :tag "Replace by command")
2447 (repeat :tag "Available when"
2448 (choice
2449 (cons :tag "Condition"
2450 (choice
2451 (const :tag "In file" in-file)
2452 (const :tag "Not in file" not-in-file)
2453 (const :tag "In buffer" in-buffer)
2454 (const :tag "Not in buffer" not-in-buffer)
2455 (const :tag "In mode" in-mode)
2456 (const :tag "Not in mode" not-in-mode))
2457 (regexp))
2458 (function :tag "Custom function"))))))
2460 (defvar org-keys nil)
2461 (defvar org-match nil)
2462 ;;;###autoload
2463 (defun org-agenda (&optional arg org-keys restriction)
2464 "Dispatch agenda commands to collect entries to the agenda buffer.
2465 Prompts for a command to execute. Any prefix arg will be passed
2466 on to the selected command. The default selections are:
2468 a Call `org-agenda-list' to display the agenda for current day or week.
2469 t Call `org-todo-list' to display the global todo list.
2470 T Call `org-todo-list' to display the global todo list, select only
2471 entries with a specific TODO keyword (the user gets a prompt).
2472 m Call `org-tags-view' to display headlines with tags matching
2473 a condition (the user is prompted for the condition).
2474 M Like `m', but select only TODO entries, no ordinary headlines.
2475 L Create a timeline for the current buffer.
2476 e Export views to associated files.
2477 s Search entries for keywords.
2478 S Search entries for keywords, only with TODO keywords.
2479 / Multi occur across all agenda files and also files listed
2480 in `org-agenda-text-search-extra-files'.
2481 < Restrict agenda commands to buffer, subtree, or region.
2482 Press several times to get the desired effect.
2483 > Remove a previous restriction.
2484 # List \"stuck\" projects.
2485 ! Configure what \"stuck\" means.
2486 C Configure custom agenda commands.
2488 More commands can be added by configuring the variable
2489 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2490 searches can be pre-defined in this way.
2492 If the current buffer is in Org-mode and visiting a file, you can also
2493 first press `<' once to indicate that the agenda should be temporarily
2494 \(until the next use of \\[org-agenda]) restricted to the current file.
2495 Pressing `<' twice means to restrict to the current subtree or region
2496 \(if active)."
2497 (interactive "P")
2498 (catch 'exit
2499 (let* ((prefix-descriptions nil)
2500 (org-agenda-buffer-name org-agenda-buffer-name)
2501 (org-agenda-window-setup (if (equal (buffer-name)
2502 org-agenda-buffer-name)
2503 'current-window
2504 org-agenda-window-setup))
2505 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2506 (org-agenda-custom-commands
2507 ;; normalize different versions
2508 (delq nil
2509 (mapcar
2510 (lambda (x)
2511 (cond ((stringp (cdr x))
2512 (push x prefix-descriptions)
2513 nil)
2514 ((stringp (nth 1 x)) x)
2515 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2516 (t (cons (car x) (cons "" (cdr x))))))
2517 org-agenda-custom-commands)))
2518 (org-agenda-custom-commands
2519 (org-contextualize-keys
2520 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2521 (buf (current-buffer))
2522 (bfn (buffer-file-name (buffer-base-buffer)))
2523 entry key type org-match lprops ans)
2524 ;; Turn off restriction unless there is an overriding one,
2525 (unless org-agenda-overriding-restriction
2526 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2527 ;; There is a request to keep the file list in place
2528 (put 'org-agenda-files 'org-restrict nil))
2529 (setq org-agenda-restrict nil)
2530 (move-marker org-agenda-restrict-begin nil)
2531 (move-marker org-agenda-restrict-end nil))
2532 ;; Delete old local properties
2533 (put 'org-agenda-redo-command 'org-lprops nil)
2534 ;; Delete previously set last-arguments
2535 (put 'org-agenda-redo-command 'last-args nil)
2536 ;; Remember where this call originated
2537 (setq org-agenda-last-dispatch-buffer (current-buffer))
2538 (unless org-keys
2539 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2540 org-keys (car ans)
2541 restriction (cdr ans)))
2542 ;; If we have sticky agenda buffers, set a name for the buffer,
2543 ;; depending on the invoking keys. The user may still set this
2544 ;; as a command option, which will overwrite what we do here.
2545 (if org-agenda-sticky
2546 (setq org-agenda-buffer-name
2547 (format "*Org Agenda(%s)*" org-keys)))
2548 ;; Establish the restriction, if any
2549 (when (and (not org-agenda-overriding-restriction) restriction)
2550 (put 'org-agenda-files 'org-restrict (list bfn))
2551 (cond
2552 ((eq restriction 'region)
2553 (setq org-agenda-restrict t)
2554 (move-marker org-agenda-restrict-begin (region-beginning))
2555 (move-marker org-agenda-restrict-end (region-end)))
2556 ((eq restriction 'subtree)
2557 (save-excursion
2558 (setq org-agenda-restrict t)
2559 (org-back-to-heading t)
2560 (move-marker org-agenda-restrict-begin (point))
2561 (move-marker org-agenda-restrict-end
2562 (progn (org-end-of-subtree t)))))))
2564 ;; For example the todo list should not need it (but does...)
2565 (cond
2566 ((setq entry (assoc org-keys org-agenda-custom-commands))
2567 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2568 (progn
2569 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2570 lprops (nth 4 entry))
2571 (if org-agenda-sticky
2572 (setq org-agenda-buffer-name
2573 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2574 (format "*Org Agenda(%s)*" org-keys))))
2575 (put 'org-agenda-redo-command 'org-lprops lprops)
2576 (cond
2577 ((eq type 'agenda)
2578 (org-let lprops '(org-agenda-list current-prefix-arg)))
2579 ((eq type 'alltodo)
2580 (org-let lprops '(org-todo-list current-prefix-arg)))
2581 ((eq type 'search)
2582 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2583 ((eq type 'stuck)
2584 (org-let lprops '(org-agenda-list-stuck-projects
2585 current-prefix-arg)))
2586 ((eq type 'tags)
2587 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2588 ((eq type 'tags-todo)
2589 (org-let lprops '(org-tags-view '(4) org-match)))
2590 ((eq type 'todo)
2591 (org-let lprops '(org-todo-list org-match)))
2592 ((eq type 'tags-tree)
2593 (org-check-for-org-mode)
2594 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2595 ((eq type 'todo-tree)
2596 (org-check-for-org-mode)
2597 (org-let lprops
2598 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2599 (regexp-quote org-match) "\\>"))))
2600 ((eq type 'occur-tree)
2601 (org-check-for-org-mode)
2602 (org-let lprops '(org-occur org-match)))
2603 ((functionp type)
2604 (org-let lprops '(funcall type org-match)))
2605 ((fboundp type)
2606 (org-let lprops '(funcall type org-match)))
2607 (t (error "Invalid custom agenda command type %s" type))))
2608 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2609 ((equal org-keys "C")
2610 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2611 (customize-variable 'org-agenda-custom-commands))
2612 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2613 ((equal org-keys "s") (call-interactively 'org-search-view))
2614 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2615 ((equal org-keys "t") (call-interactively 'org-todo-list))
2616 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2617 ((equal org-keys "m") (call-interactively 'org-tags-view))
2618 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2619 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2620 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2621 (org-add-hook
2622 'post-command-hook
2623 (lambda ()
2624 (unless (current-message)
2625 (let* ((m (org-agenda-get-any-marker))
2626 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2627 (when note
2628 (message (concat
2629 "FLAGGING-NOTE ([?] for more info): "
2630 (org-add-props
2631 (replace-regexp-in-string
2632 "\\\\n" "//"
2633 (copy-sequence note))
2634 nil 'face 'org-warning)))))))
2635 t t))
2636 ((equal org-keys "L")
2637 (unless (derived-mode-p 'org-mode)
2638 (error "This is not an Org-mode file"))
2639 (unless restriction
2640 (put 'org-agenda-files 'org-restrict (list bfn))
2641 (org-call-with-arg 'org-timeline arg)))
2642 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2643 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2644 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2645 (t (error "Invalid agenda key"))))))
2647 (autoload 'org-agenda "org-agenda" "\
2648 Dispatch agenda commands to collect entries to the agenda buffer.
2649 Prompts for a command to execute. Any prefix arg will be passed
2650 on to the selected command. The default selections are:
2652 a Call `org-agenda-list' to display the agenda for current day or week.
2653 t Call `org-todo-list' to display the global todo list.
2654 T Call `org-todo-list' to display the global todo list, select only
2655 entries with a specific TODO keyword (the user gets a prompt).
2656 m Call `org-tags-view' to display headlines with tags matching
2657 a condition (the user is prompted for the condition).
2658 M Like `m', but select only TODO entries, no ordinary headlines.
2659 L Create a timeline for the current buffer.
2660 e Export views to associated files.
2661 s Search entries for keywords.
2662 S Search entries for keywords, only with TODO keywords.
2663 / Multi occur across all agenda files and also files listed
2664 in `org-agenda-text-search-extra-files'.
2665 < Restrict agenda commands to buffer, subtree, or region.
2666 Press several times to get the desired effect.
2667 > Remove a previous restriction.
2668 # List \"stuck\" projects.
2669 ! Configure what \"stuck\" means.
2670 C Configure custom agenda commands.
2672 More commands can be added by configuring the variable
2673 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2674 searches can be pre-defined in this way.
2676 If the current buffer is in Org-mode and visiting a file, you can also
2677 first press `<' once to indicate that the agenda should be temporarily
2678 \(until the next use of \\[org-agenda]) restricted to the current file.
2679 Pressing `<' twice means to restrict to the current subtree or region
2680 \(if active).
2682 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2684 (defun org-agenda-append-agenda ()
2685 "Append another agenda view to the current one.
2686 This function allows interactive building of block agendas.
2687 Agenda views are separated by `org-agenda-block-separator'."
2688 (interactive)
2689 (unless (derived-mode-p 'org-agenda-mode)
2690 (error "Can only append from within agenda buffer"))
2691 (let ((org-agenda-multi t))
2692 (org-agenda)
2693 (widen)
2694 (org-agenda-finalize)
2695 (org-agenda-fit-window-to-buffer)))
2697 (defun org-agenda-normalize-custom-commands (cmds)
2698 (delq nil
2699 (mapcar
2700 (lambda (x)
2701 (cond ((stringp (cdr x)) nil)
2702 ((stringp (nth 1 x)) x)
2703 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2704 (t (cons (car x) (cons "" (cdr x))))))
2705 cmds)))
2707 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2708 "The user interface for selecting an agenda command."
2709 (catch 'exit
2710 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2711 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2712 (region-p (org-region-active-p))
2713 (custom org-agenda-custom-commands)
2714 (selstring "")
2715 restriction second-time
2716 c entry key type match prefixes rmheader header-end custom1 desc
2717 line lines left right n n1)
2718 (save-window-excursion
2719 (delete-other-windows)
2720 (org-switch-to-buffer-other-window " *Agenda Commands*")
2721 (erase-buffer)
2722 (insert (eval-when-compile
2723 (let ((header
2724 "Press key for an agenda command: < Buffer, subtree/region restriction
2725 -------------------------------- > Remove restriction
2726 a Agenda for current week or day e Export agenda views
2727 t List of all TODO entries T Entries with special TODO kwd
2728 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2729 s Search for keywords S Like s, but only TODO entries
2730 L Timeline for current buffer # List stuck projects (!=configure)
2731 / Multi-occur C Configure custom agenda commands
2732 ? Find :FLAGGED: entries * Toggle sticky agenda views
2734 (start 0))
2735 (while (string-match
2736 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2737 header start)
2738 (setq start (match-end 0))
2739 (add-text-properties (match-beginning 2) (match-end 2)
2740 '(face bold) header))
2741 header)))
2742 (setq header-end (point-marker))
2743 (while t
2744 (setq custom1 custom)
2745 (when (eq rmheader t)
2746 (org-goto-line 1)
2747 (re-search-forward ":" nil t)
2748 (delete-region (match-end 0) (point-at-eol))
2749 (forward-char 1)
2750 (looking-at "-+")
2751 (delete-region (match-end 0) (point-at-eol))
2752 (move-marker header-end (match-end 0)))
2753 (goto-char header-end)
2754 (delete-region (point) (point-max))
2756 ;; Produce all the lines that describe custom commands and prefixes
2757 (setq lines nil)
2758 (while (setq entry (pop custom1))
2759 (setq key (car entry) desc (nth 1 entry)
2760 type (nth 2 entry)
2761 match (nth 3 entry))
2762 (if (> (length key) 1)
2763 (add-to-list 'prefixes (string-to-char key))
2764 (setq line
2765 (format
2766 "%-4s%-14s"
2767 (org-add-props (copy-sequence key)
2768 '(face bold))
2769 (cond
2770 ((string-match "\\S-" desc) desc)
2771 ((eq type 'agenda) "Agenda for current week or day")
2772 ((eq type 'alltodo) "List of all TODO entries")
2773 ((eq type 'search) "Word search")
2774 ((eq type 'stuck) "List of stuck projects")
2775 ((eq type 'todo) "TODO keyword")
2776 ((eq type 'tags) "Tags query")
2777 ((eq type 'tags-todo) "Tags (TODO)")
2778 ((eq type 'tags-tree) "Tags tree")
2779 ((eq type 'todo-tree) "TODO kwd tree")
2780 ((eq type 'occur-tree) "Occur tree")
2781 ((functionp type) (if (symbolp type)
2782 (symbol-name type)
2783 "Lambda expression"))
2784 (t "???"))))
2785 (if org-agenda-menu-show-matcher
2786 (setq line
2787 (concat line ": "
2788 (cond
2789 ((stringp match)
2790 (setq match (copy-sequence match))
2791 (org-add-props match nil 'face 'org-warning))
2792 ((listp type)
2793 (format "set of %d commands" (length type))))))
2794 (if (org-string-nw-p match)
2795 (add-text-properties
2796 0 (length line) (list 'help-echo
2797 (concat "Matcher: " match)) line)))
2798 (push line lines)))
2799 (setq lines (nreverse lines))
2800 (when prefixes
2801 (mapc (lambda (x)
2802 (push
2803 (format "%s %s"
2804 (org-add-props (char-to-string x)
2805 nil 'face 'bold)
2806 (or (cdr (assoc (concat selstring
2807 (char-to-string x))
2808 prefix-descriptions))
2809 "Prefix key"))
2810 lines))
2811 prefixes))
2813 ;; Check if we should display in two columns
2814 (if org-agenda-menu-two-columns
2815 (progn
2816 (setq n (length lines)
2817 n1 (+ (/ n 2) (mod n 2))
2818 right (nthcdr n1 lines)
2819 left (copy-sequence lines))
2820 (setcdr (nthcdr (1- n1) left) nil))
2821 (setq left lines right nil))
2822 (while left
2823 (insert "\n" (pop left))
2824 (when right
2825 (if (< (current-column) 40)
2826 (move-to-column 40 t)
2827 (insert " "))
2828 (insert (pop right))))
2830 ;; Make the window the right size
2831 (goto-char (point-min))
2832 (if second-time
2833 (if (not (pos-visible-in-window-p (point-max)))
2834 (org-fit-window-to-buffer))
2835 (setq second-time t)
2836 (org-fit-window-to-buffer))
2838 ;; Ask for selection
2839 (message "Press key for agenda command%s:"
2840 (if (or restrict-ok org-agenda-overriding-restriction)
2841 (if org-agenda-overriding-restriction
2842 " (restriction lock active)"
2843 (if restriction
2844 (format " (restricted to %s)" restriction)
2845 " (unrestricted)"))
2846 ""))
2847 (setq c (read-char-exclusive))
2848 (message "")
2849 (cond
2850 ((assoc (char-to-string c) custom)
2851 (setq selstring (concat selstring (char-to-string c)))
2852 (throw 'exit (cons selstring restriction)))
2853 ((memq c prefixes)
2854 (setq selstring (concat selstring (char-to-string c))
2855 prefixes nil
2856 rmheader (or rmheader t)
2857 custom (delq nil (mapcar
2858 (lambda (x)
2859 (if (or (= (length (car x)) 1)
2860 (/= (string-to-char (car x)) c))
2862 (cons (substring (car x) 1) (cdr x))))
2863 custom))))
2864 ((eq c ?*)
2865 (call-interactively 'org-toggle-sticky-agenda)
2866 (sit-for 2))
2867 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2868 (message "Restriction is only possible in Org-mode buffers")
2869 (ding) (sit-for 1))
2870 ((eq c ?1)
2871 (org-agenda-remove-restriction-lock 'noupdate)
2872 (setq restriction 'buffer))
2873 ((eq c ?0)
2874 (org-agenda-remove-restriction-lock 'noupdate)
2875 (setq restriction (if region-p 'region 'subtree)))
2876 ((eq c ?<)
2877 (org-agenda-remove-restriction-lock 'noupdate)
2878 (setq restriction
2879 (cond
2880 ((eq restriction 'buffer)
2881 (if region-p 'region 'subtree))
2882 ((memq restriction '(subtree region))
2883 nil)
2884 (t 'buffer))))
2885 ((eq c ?>)
2886 (org-agenda-remove-restriction-lock 'noupdate)
2887 (setq restriction nil))
2888 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2889 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2890 ((and (> (length selstring) 0) (eq c ?\d))
2891 (delete-window)
2892 (org-agenda-get-restriction-and-command prefix-descriptions))
2894 ((equal c ?q) (error "Abort"))
2895 (t (error "Invalid key %c" c))))))))
2897 (defun org-agenda-fit-window-to-buffer ()
2898 "Fit the window to the buffer size."
2899 (and (memq org-agenda-window-setup '(reorganize-frame))
2900 (fboundp 'fit-window-to-buffer)
2901 (org-fit-window-to-buffer
2903 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2904 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2906 (defvar org-cmd nil)
2907 (defvar org-agenda-overriding-cmd nil)
2908 (defvar org-agenda-overriding-arguments nil)
2909 (defvar org-agenda-overriding-cmd-arguments nil)
2910 (defun org-agenda-run-series (name series)
2911 (org-let (nth 1 series) '(org-agenda-prepare name))
2912 ;; We need to reset agenda markers here, because when constructing a
2913 ;; block agenda, the individual blocks do not do that.
2914 (org-agenda-reset-markers)
2915 (let* ((org-agenda-multi t)
2916 (redo (list 'org-agenda-run-series name (list 'quote series)))
2917 (cmds (car series))
2918 (gprops (nth 1 series))
2919 match ;; The byte compiler incorrectly complains about this. Keep it!
2920 org-cmd type lprops)
2921 (while (setq org-cmd (pop cmds))
2922 (setq type (car org-cmd)
2923 match (eval (nth 1 org-cmd))
2924 lprops (nth 2 org-cmd))
2925 (let ((org-agenda-overriding-arguments
2926 (if (eq org-agenda-overriding-cmd org-cmd)
2927 (or org-agenda-overriding-arguments
2928 org-agenda-overriding-cmd-arguments))))
2929 (cond
2930 ((eq type 'agenda)
2931 (org-let2 gprops lprops
2932 '(call-interactively 'org-agenda-list)))
2933 ((eq type 'alltodo)
2934 (org-let2 gprops lprops
2935 '(call-interactively 'org-todo-list)))
2936 ((eq type 'search)
2937 (org-let2 gprops lprops
2938 '(org-search-view current-prefix-arg match nil)))
2939 ((eq type 'stuck)
2940 (org-let2 gprops lprops
2941 '(call-interactively 'org-agenda-list-stuck-projects)))
2942 ((eq type 'tags)
2943 (org-let2 gprops lprops
2944 '(org-tags-view current-prefix-arg match)))
2945 ((eq type 'tags-todo)
2946 (org-let2 gprops lprops
2947 '(org-tags-view '(4) match)))
2948 ((eq type 'todo)
2949 (org-let2 gprops lprops
2950 '(org-todo-list match)))
2951 ((fboundp type)
2952 (org-let2 gprops lprops
2953 '(funcall type match)))
2954 (t (error "Invalid type in command series")))))
2955 (widen)
2956 (let ((inhibit-read-only t))
2957 (add-text-properties (point-min) (point-max)
2958 `(org-series t org-series-redo-cmd ,redo)))
2959 (setq org-agenda-redo-command redo)
2960 (goto-char (point-min)))
2961 (org-agenda-fit-window-to-buffer)
2962 (org-let (nth 1 series) '(org-agenda-finalize)))
2964 ;;;###autoload
2965 (defmacro org-batch-agenda (cmd-key &rest parameters)
2966 "Run an agenda command in batch mode and send the result to STDOUT.
2967 If CMD-KEY is a string of length 1, it is used as a key in
2968 `org-agenda-custom-commands' and triggers this command. If it is a
2969 longer string it is used as a tags/todo match string.
2970 Parameters are alternating variable names and values that will be bound
2971 before running the agenda command."
2972 (org-eval-in-environment (org-make-parameter-alist parameters)
2973 (if (> (length cmd-key) 2)
2974 (org-tags-view nil cmd-key)
2975 (org-agenda nil cmd-key)))
2976 (set-buffer org-agenda-buffer-name)
2977 (princ (buffer-string)))
2979 (autoload 'org-batch-agenda "org-agenda" "\
2980 Run an agenda command in batch mode and send the result to STDOUT.
2981 If CMD-KEY is a string of length 1, it is used as a key in
2982 `org-agenda-custom-commands' and triggers this command. If it is a
2983 longer string it is used as a tags/todo match string.
2984 Parameters are alternating variable names and values that will be bound
2985 before running the agenda command.
2987 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2988 (def-edebug-spec org-batch-agenda (form &rest sexp))
2990 (defvar org-agenda-info nil)
2992 ;;;###autoload
2993 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2994 "Run an agenda command in batch mode and send the result to STDOUT.
2995 If CMD-KEY is a string of length 1, it is used as a key in
2996 `org-agenda-custom-commands' and triggers this command. If it is a
2997 longer string it is used as a tags/todo match string.
2998 Parameters are alternating variable names and values that will be bound
2999 before running the agenda command.
3001 The output gives a line for each selected agenda item. Each
3002 item is a list of comma-separated values, like this:
3004 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3006 category The category of the item
3007 head The headline, without TODO kwd, TAGS and PRIORITY
3008 type The type of the agenda entry, can be
3009 todo selected in TODO match
3010 tagsmatch selected in tags match
3011 diary imported from diary
3012 deadline a deadline on given date
3013 scheduled scheduled on given date
3014 timestamp entry has timestamp on given date
3015 closed entry was closed on given date
3016 upcoming-deadline warning about deadline
3017 past-scheduled forwarded scheduled item
3018 block entry has date block including g. date
3019 todo The todo keyword, if any
3020 tags All tags including inherited ones, separated by colons
3021 date The relevant date, like 2007-2-14
3022 time The time, like 15:00-16:50
3023 extra Sting with extra planning info
3024 priority-l The priority letter if any was given
3025 priority-n The computed numerical priority
3026 agenda-day The day in the agenda where this is listed"
3027 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3028 (org-make-parameter-alist parameters))
3029 (if (> (length cmd-key) 2)
3030 (org-tags-view nil cmd-key)
3031 (org-agenda nil cmd-key)))
3032 (set-buffer org-agenda-buffer-name)
3033 (let* ((lines (org-split-string (buffer-string) "\n"))
3034 line)
3035 (while (setq line (pop lines))
3036 (catch 'next
3037 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3038 (setq org-agenda-info
3039 (org-fix-agenda-info (text-properties-at 0 line)))
3040 (princ
3041 (mapconcat 'org-agenda-export-csv-mapper
3042 '(org-category txt type todo tags date time extra
3043 priority-letter priority agenda-day)
3044 ","))
3045 (princ "\n")))))
3047 (autoload 'org-batch-agenda-csv "org-agenda" "\
3048 Run an agenda command in batch mode and send the result to STDOUT.
3049 If CMD-KEY is a string of length 1, it is used as a key in
3050 `org-agenda-custom-commands' and triggers this command. If it is a
3051 longer string it is used as a tags/todo match string.
3052 Parameters are alternating variable names and values that will be bound
3053 before running the agenda command.
3055 The output gives a line for each selected agenda item. Each
3056 item is a list of comma-separated values, like this:
3058 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3060 category The category of the item
3061 head The headline, without TODO kwd, TAGS and PRIORITY
3062 type The type of the agenda entry, can be
3063 todo selected in TODO match
3064 tagsmatch selected in tags match
3065 diary imported from diary
3066 deadline a deadline on given date
3067 scheduled scheduled on given date
3068 timestamp entry has timestamp on given date
3069 closed entry was closed on given date
3070 upcoming-deadline warning about deadline
3071 past-scheduled forwarded scheduled item
3072 block entry has date block including g. date
3073 todo The todo keyword, if any
3074 tags All tags including inherited ones, separated by colons
3075 date The relevant date, like 2007-2-14
3076 time The time, like 15:00-16:50
3077 extra Sting with extra planning info
3078 priority-l The priority letter if any was given
3079 priority-n The computed numerical priority
3080 agenda-day The day in the agenda where this is listed
3082 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3083 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3085 (defun org-fix-agenda-info (props)
3086 "Make sure all properties on an agenda item have a canonical form.
3087 This ensures the export commands can easily use it."
3088 (let (tmp re)
3089 (when (setq tmp (plist-get props 'tags))
3090 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3091 (when (setq tmp (plist-get props 'date))
3092 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3093 (let ((calendar-date-display-form '(year "-" month "-" day)))
3094 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3096 (setq tmp (calendar-date-string tmp)))
3097 (setq props (plist-put props 'date tmp)))
3098 (when (setq tmp (plist-get props 'day))
3099 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3100 (let ((calendar-date-display-form '(year "-" month "-" day)))
3101 (setq tmp (calendar-date-string tmp)))
3102 (setq props (plist-put props 'day tmp))
3103 (setq props (plist-put props 'agenda-day tmp)))
3104 (when (setq tmp (plist-get props 'txt))
3105 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3106 (plist-put props 'priority-letter (match-string 1 tmp))
3107 (setq tmp (replace-match "" t t tmp)))
3108 (when (and (setq re (plist-get props 'org-todo-regexp))
3109 (setq re (concat "\\`\\.*" re " ?"))
3110 (string-match re tmp))
3111 (plist-put props 'todo (match-string 1 tmp))
3112 (setq tmp (replace-match "" t t tmp)))
3113 (plist-put props 'txt tmp)))
3114 props)
3116 (defun org-agenda-export-csv-mapper (prop)
3117 (let ((res (plist-get org-agenda-info prop)))
3118 (setq res
3119 (cond
3120 ((not res) "")
3121 ((stringp res) res)
3122 (t (prin1-to-string res))))
3123 (while (string-match "," res)
3124 (setq res (replace-match ";" t t res)))
3125 (org-trim res)))
3127 ;;;###autoload
3128 (defun org-store-agenda-views (&rest parameters)
3129 (interactive)
3130 (eval (list 'org-batch-store-agenda-views)))
3132 (autoload 'org-store-agenda-views "org-agenda" "\
3135 \(fn &rest PARAMETERS)" t nil)
3137 ;;;###autoload
3138 (defmacro org-batch-store-agenda-views (&rest parameters)
3139 "Run all custom agenda commands that have a file argument."
3140 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3141 (pop-up-frames nil)
3142 (dir default-directory)
3143 (pars (org-make-parameter-alist parameters))
3144 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3145 (save-window-excursion
3146 (while cmds
3147 (setq cmd (pop cmds)
3148 thiscmdkey (car cmd)
3149 thiscmdcmd (cdr cmd)
3150 match (nth 2 thiscmdcmd)
3151 bufname (if org-agenda-sticky
3152 (or (and (stringp match)
3153 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3154 (format "*Org Agenda(%s)*" thiscmdkey))
3155 org-agenda-buffer-name)
3156 cmd-or-set (nth 2 cmd)
3157 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3158 files (nth (if (listp cmd-or-set) 4 5) cmd))
3159 (if (stringp files) (setq files (list files)))
3160 (when files
3161 (org-eval-in-environment (append org-agenda-exporter-settings
3162 opts pars)
3163 (org-agenda nil thiscmdkey))
3164 (set-buffer bufname)
3165 (while files
3166 (org-eval-in-environment (append org-agenda-exporter-settings
3167 opts pars)
3168 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3169 (and (get-buffer bufname)
3170 (kill-buffer bufname)))))))
3172 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3173 Run all custom agenda commands that have a file argument.
3175 \(fn &rest PARAMETERS)" nil t)
3176 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3178 (defvar org-agenda-current-span nil
3179 "The current span used in the agenda view.") ; local variable in the agenda buffer
3180 (defun org-agenda-mark-header-line (pos)
3181 "Mark the line at POS as an agenda structure header."
3182 (save-excursion
3183 (goto-char pos)
3184 (put-text-property (point-at-bol) (point-at-eol)
3185 'org-agenda-structural-header t)
3186 (when org-agenda-title-append
3187 (put-text-property (point-at-bol) (point-at-eol)
3188 'org-agenda-title-append org-agenda-title-append))))
3190 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3191 (defvar org-agenda-write-buffer-name "Agenda View")
3192 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3193 "Write the current buffer (an agenda view) as a file.
3194 Depending on the extension of the file name, plain text (.txt),
3195 HTML (.html or .htm) or Postscript (.ps) is produced.
3196 If the extension is .ics, run icalendar export over all files used
3197 to construct the agenda and limit the export to entries listed in the
3198 agenda now.
3199 With prefix argument OPEN, open the new file immediately.
3200 If NOSETTINGS is given, do not scope the settings of
3201 `org-agenda-exporter-settings' into the export commands. This is used when
3202 the settings have already been scoped and we do not wish to overrule other,
3203 higher priority settings.
3204 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3205 (interactive "FWrite agenda to file: \nP")
3206 (if (not (file-writable-p file))
3207 (error "Cannot write agenda to file %s" file))
3208 (org-let (if nosettings nil org-agenda-exporter-settings)
3209 '(save-excursion
3210 (save-window-excursion
3211 (org-agenda-mark-filtered-text)
3212 (let ((bs (copy-sequence (buffer-string))) beg)
3213 (org-agenda-unmark-filtered-text)
3214 (with-temp-buffer
3215 (rename-buffer org-agenda-write-buffer-name t)
3216 (set-buffer-modified-p nil)
3217 (insert bs)
3218 (org-agenda-remove-marked-text 'org-filtered)
3219 (while (setq beg (text-property-any (point-min) (point-max)
3220 'org-filtered t))
3221 (delete-region
3222 beg (or (next-single-property-change beg 'org-filtered)
3223 (point-max))))
3224 (run-hooks 'org-agenda-before-write-hook)
3225 (cond
3226 ((org-bound-and-true-p org-mobile-creating-agendas)
3227 (org-mobile-write-agenda-for-mobile file))
3228 ((string-match "\\.html?\\'" file)
3229 (require 'htmlize)
3230 (set-buffer (htmlize-buffer (current-buffer)))
3231 (when org-agenda-export-html-style
3232 ;; replace <style> section with org-agenda-export-html-style
3233 (goto-char (point-min))
3234 (kill-region (- (search-forward "<style") 6)
3235 (search-forward "</style>"))
3236 (insert org-agenda-export-html-style))
3237 (write-file file)
3238 (kill-buffer (current-buffer))
3239 (message "HTML written to %s" file))
3240 ((string-match "\\.ps\\'" file)
3241 (require 'ps-print)
3242 (ps-print-buffer-with-faces file)
3243 (message "Postscript written to %s" file))
3244 ((string-match "\\.pdf\\'" file)
3245 (require 'ps-print)
3246 (ps-print-buffer-with-faces
3247 (concat (file-name-sans-extension file) ".ps"))
3248 (call-process "ps2pdf" nil nil nil
3249 (expand-file-name
3250 (concat (file-name-sans-extension file) ".ps"))
3251 (expand-file-name file))
3252 (delete-file (concat (file-name-sans-extension file) ".ps"))
3253 (message "PDF written to %s" file))
3254 ((string-match "\\.ics\\'" file)
3255 (require 'org-icalendar)
3256 (let ((org-agenda-marker-table
3257 (org-create-marker-find-array
3258 (org-agenda-collect-markers)))
3259 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3260 (org-combined-agenda-icalendar-file file))
3261 (apply 'org-export-icalendar 'combine
3262 (org-agenda-files nil 'ifmode))))
3264 (let ((bs (buffer-string)))
3265 (find-file file)
3266 (erase-buffer)
3267 (insert bs)
3268 (save-buffer 0)
3269 (kill-buffer (current-buffer))
3270 (message "Plain text written to %s" file))))))))
3271 (set-buffer (or agenda-bufname
3272 (and (org-called-interactively-p 'any) (buffer-name))
3273 org-agenda-buffer-name)))
3274 (when open (org-open-file file)))
3276 (defvar org-agenda-tag-filter-overlays nil)
3277 (defvar org-agenda-cat-filter-overlays nil)
3279 (defun org-agenda-mark-filtered-text ()
3280 "Mark all text hidden by filtering with a text property."
3281 (let ((inhibit-read-only t))
3282 (mapc
3283 (lambda (o)
3284 (when (equal (overlay-buffer o) (current-buffer))
3285 (put-text-property
3286 (overlay-start o) (overlay-end o)
3287 'org-filtered t)))
3288 (append org-agenda-tag-filter-overlays
3289 org-agenda-cat-filter-overlays))))
3291 (defun org-agenda-unmark-filtered-text ()
3292 "Remove the filtering text property."
3293 (let ((inhibit-read-only t))
3294 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3296 (defun org-agenda-remove-marked-text (property &optional value)
3297 "Delete all text marked with VALUE of PROPERTY.
3298 VALUE defaults to t."
3299 (let (beg)
3300 (setq value (or value t))
3301 (while (setq beg (text-property-any (point-min) (point-max)
3302 property value))
3303 (delete-region
3304 beg (or (next-single-property-change beg 'org-filtered)
3305 (point-max))))))
3307 (defun org-agenda-add-entry-text ()
3308 "Add entry text to agenda lines.
3309 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3310 entry text following headings shown in the agenda.
3311 Drawers will be excluded, also the line with scheduling/deadline info."
3312 (when (and (> org-agenda-add-entry-text-maxlines 0)
3313 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3314 (let (m txt)
3315 (goto-char (point-min))
3316 (while (not (eobp))
3317 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3318 (beginning-of-line 2)
3319 (setq txt (org-agenda-get-some-entry-text
3320 m org-agenda-add-entry-text-maxlines " > "))
3321 (end-of-line 1)
3322 (if (string-match "\\S-" txt)
3323 (insert "\n" txt)
3324 (or (eobp) (forward-char 1))))))))
3326 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3327 &rest keep)
3328 "Extract entry text from MARKER, at most N-LINES lines.
3329 This will ignore drawers etc, just get the text.
3330 If INDENT is given, prefix every line with this string. If KEEP is
3331 given, it is a list of symbols, defining stuff that should not be
3332 removed from the entry content. Currently only `planning' is allowed here."
3333 (let (txt drawer-re kwd-time-re ind)
3334 (save-excursion
3335 (with-current-buffer (marker-buffer marker)
3336 (if (not (derived-mode-p 'org-mode))
3337 (setq txt "")
3338 (save-excursion
3339 (save-restriction
3340 (widen)
3341 (goto-char marker)
3342 (end-of-line 1)
3343 (setq txt (buffer-substring
3344 (min (1+ (point)) (point-max))
3345 (progn (outline-next-heading) (point)))
3346 drawer-re org-drawer-regexp
3347 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3348 ".*\n?"))
3349 (with-temp-buffer
3350 (insert txt)
3351 (when org-agenda-add-entry-text-descriptive-links
3352 (goto-char (point-min))
3353 (while (org-activate-bracket-links (point-max))
3354 (add-text-properties (match-beginning 0) (match-end 0)
3355 '(face org-link))))
3356 (goto-char (point-min))
3357 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3358 (set-text-properties (match-beginning 0) (match-end 0)
3359 nil))
3360 (goto-char (point-min))
3361 (while (re-search-forward drawer-re nil t)
3362 (delete-region
3363 (match-beginning 0)
3364 (progn (re-search-forward
3365 "^[ \t]*:END:.*\n?" nil 'move)
3366 (point))))
3367 (unless (member 'planning keep)
3368 (goto-char (point-min))
3369 (while (re-search-forward kwd-time-re nil t)
3370 (replace-match "")))
3371 (goto-char (point-min))
3372 (when org-agenda-entry-text-exclude-regexps
3373 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3374 (while (setq re (pop re-list))
3375 (goto-char (point-min))
3376 (while (re-search-forward re nil t)
3377 (replace-match "")))))
3378 (goto-char (point-max))
3379 (skip-chars-backward " \t\n")
3380 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3382 ;; find and remove min common indentation
3383 (goto-char (point-min))
3384 (untabify (point-min) (point-max))
3385 (setq ind (org-get-indentation))
3386 (while (not (eobp))
3387 (unless (looking-at "[ \t]*$")
3388 (setq ind (min ind (org-get-indentation))))
3389 (beginning-of-line 2))
3390 (goto-char (point-min))
3391 (while (not (eobp))
3392 (unless (looking-at "[ \t]*$")
3393 (move-to-column ind)
3394 (delete-region (point-at-bol) (point)))
3395 (beginning-of-line 2))
3397 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3399 (goto-char (point-min))
3400 (when indent
3401 (while (and (not (eobp)) (re-search-forward "^" nil t))
3402 (replace-match indent t t)))
3403 (goto-char (point-min))
3404 (while (looking-at "[ \t]*\n") (replace-match ""))
3405 (goto-char (point-max))
3406 (when (> (org-current-line)
3407 n-lines)
3408 (org-goto-line (1+ n-lines))
3409 (backward-char 1))
3410 (setq txt (buffer-substring (point-min) (point)))))))))
3411 txt))
3413 (defun org-agenda-collect-markers ()
3414 "Collect the markers pointing to entries in the agenda buffer."
3415 (let (m markers)
3416 (save-excursion
3417 (goto-char (point-min))
3418 (while (not (eobp))
3419 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3420 (org-get-at-bol 'org-marker)))
3421 (push m markers))
3422 (beginning-of-line 2)))
3423 (nreverse markers)))
3425 (defun org-create-marker-find-array (marker-list)
3426 "Create a alist of files names with all marker positions in that file."
3427 (let (f tbl m a p)
3428 (while (setq m (pop marker-list))
3429 (setq p (marker-position m)
3430 f (buffer-file-name (or (buffer-base-buffer
3431 (marker-buffer m))
3432 (marker-buffer m))))
3433 (if (setq a (assoc f tbl))
3434 (push (marker-position m) (cdr a))
3435 (push (list f p) tbl)))
3436 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3437 tbl)))
3439 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3440 (defun org-check-agenda-marker-table ()
3441 "Check of the current entry is on the marker list."
3442 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3444 (and (setq a (assoc file org-agenda-marker-table))
3445 (save-match-data
3446 (save-excursion
3447 (org-back-to-heading t)
3448 (member (point) (cdr a)))))))
3450 (defun org-check-for-org-mode ()
3451 "Make sure current buffer is in org-mode. Error if not."
3452 (or (derived-mode-p 'org-mode)
3453 (error "Cannot execute org-mode agenda command on buffer in %s"
3454 major-mode)))
3456 ;;; Agenda prepare and finalize
3458 (defvar org-agenda-multi nil) ; dynamically scoped
3459 (defvar org-agenda-pre-window-conf nil)
3460 (defvar org-agenda-columns-active nil)
3461 (defvar org-agenda-name nil)
3462 (defvar org-agenda-tag-filter nil)
3463 (defvar org-agenda-category-filter nil)
3464 (defvar org-agenda-top-category-filter nil)
3465 (defvar org-agenda-tag-filter-while-redo nil)
3466 (defvar org-agenda-tag-filter-preset nil
3467 "A preset of the tags filter used for secondary agenda filtering.
3468 This must be a list of strings, each string must be a single tag preceded
3469 by \"+\" or \"-\".
3470 This variable should not be set directly, but agenda custom commands can
3471 bind it in the options section. The preset filter is a global property of
3472 the entire agenda view. In a block agenda, it will not work reliably to
3473 define a filter for one of the individual blocks. You need to set it in
3474 the global options and expect it to be applied to the entire view.")
3476 (defvar org-agenda-category-filter-preset nil
3477 "A preset of the category filter used for secondary agenda filtering.
3478 This must be a list of strings, each string must be a single category
3479 preceded by \"+\" or \"-\".
3480 This variable should not be set directly, but agenda custom commands can
3481 bind it in the options section. The preset filter is a global property of
3482 the entire agenda view. In a block agenda, it will not work reliably to
3483 define a filter for one of the individual blocks. You need to set it in
3484 the global options and expect it to be applied to the entire view.")
3487 (defun org-agenda-use-sticky-p ()
3488 "Return non-nil if an agenda buffer named
3489 `org-agenda-buffer-name' exists and should be shown instead of
3490 generating a new one."
3491 (and
3492 ;; turned off by user
3493 org-agenda-sticky
3494 ;; For multi-agenda buffer already exists
3495 (not org-agenda-multi)
3496 ;; buffer found
3497 (get-buffer org-agenda-buffer-name)
3498 ;; C-u parameter is same as last call
3499 (with-current-buffer (get-buffer org-agenda-buffer-name)
3500 (and
3501 (equal current-prefix-arg
3502 org-agenda-last-prefix-arg)
3503 ;; In case user turned stickiness on, while having existing
3504 ;; Agenda buffer active, don't reuse that buffer, because it
3505 ;; does not have org variables local
3506 org-agenda-this-buffer-is-sticky))))
3508 (defun org-agenda-prepare-window (abuf)
3509 "Setup agenda buffer in the window."
3510 (let* ((awin (get-buffer-window abuf))
3511 wconf)
3512 (cond
3513 ((equal (current-buffer) abuf) nil)
3514 (awin (select-window awin))
3515 ((not (setq wconf (current-window-configuration))))
3516 ((equal org-agenda-window-setup 'current-window)
3517 (org-pop-to-buffer-same-window abuf))
3518 ((equal org-agenda-window-setup 'other-window)
3519 (org-switch-to-buffer-other-window abuf))
3520 ((equal org-agenda-window-setup 'other-frame)
3521 (switch-to-buffer-other-frame abuf))
3522 ((equal org-agenda-window-setup 'reorganize-frame)
3523 (delete-other-windows)
3524 (org-switch-to-buffer-other-window abuf)))
3525 ;; additional test in case agenda is invoked from within agenda
3526 ;; buffer via elisp link
3527 (unless (equal (current-buffer) abuf)
3528 (org-pop-to-buffer-same-window abuf))
3529 (setq org-agenda-pre-window-conf
3530 (or org-agenda-pre-window-conf wconf))))
3532 (defun org-agenda-prepare (&optional name)
3533 (if (org-agenda-use-sticky-p)
3534 (progn
3535 ;; Popup existing buffer
3536 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3537 (message "Sticky Agenda buffer, use `r' to refresh")
3538 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3539 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3540 (setq org-todo-keywords-for-agenda nil)
3541 (setq org-drawers-for-agenda nil)
3542 (unless org-agenda-persistent-filter
3543 (setq org-agenda-tag-filter nil
3544 org-agenda-category-filter nil))
3545 (put 'org-agenda-tag-filter :preset-filter
3546 org-agenda-tag-filter-preset)
3547 (put 'org-agenda-category-filter :preset-filter
3548 org-agenda-category-filter-preset)
3549 (if org-agenda-multi
3550 (progn
3551 (setq buffer-read-only nil)
3552 (goto-char (point-max))
3553 (unless (or (bobp) org-agenda-compact-blocks
3554 (not org-agenda-block-separator))
3555 (insert "\n"
3556 (if (stringp org-agenda-block-separator)
3557 org-agenda-block-separator
3558 (make-string (window-width) org-agenda-block-separator))
3559 "\n"))
3560 (narrow-to-region (point) (point-max)))
3561 (setq org-done-keywords-for-agenda nil)
3563 ;; Setting any org variables that are in org-agenda-local-vars
3564 ;; list need to be done after the prepare call
3565 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3566 (setq buffer-read-only nil)
3567 (org-agenda-reset-markers)
3568 (let ((inhibit-read-only t)) (erase-buffer))
3569 (org-agenda-mode)
3570 (setq org-agenda-buffer (current-buffer))
3571 (setq org-agenda-contributing-files nil)
3572 (setq org-agenda-columns-active nil)
3573 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3574 (setq org-todo-keywords-for-agenda
3575 (org-uniquify org-todo-keywords-for-agenda))
3576 (setq org-done-keywords-for-agenda
3577 (org-uniquify org-done-keywords-for-agenda))
3578 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3579 (setq org-agenda-last-prefix-arg current-prefix-arg)
3580 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3581 (and name (not org-agenda-name)
3582 (org-set-local 'org-agenda-name name)))
3583 (setq buffer-read-only nil)))
3585 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3586 (defun org-agenda-finalize ()
3587 "Finishing touch for the agenda buffer, called just before displaying it."
3588 (unless org-agenda-multi
3589 (save-excursion
3590 (let ((inhibit-read-only t))
3591 (goto-char (point-min))
3592 (save-excursion
3593 (while (org-activate-bracket-links (point-max))
3594 (add-text-properties (match-beginning 0) (match-end 0)
3595 '(face org-link))))
3596 (save-excursion
3597 (while (org-activate-plain-links (point-max))
3598 (add-text-properties (match-beginning 0) (match-end 0)
3599 '(face org-link))))
3600 (unless (eq org-agenda-remove-tags t)
3601 (org-agenda-align-tags))
3602 (unless org-agenda-with-colors
3603 (remove-text-properties (point-min) (point-max) '(face nil)))
3604 (if (and (boundp 'org-agenda-overriding-columns-format)
3605 org-agenda-overriding-columns-format)
3606 (org-set-local 'org-agenda-overriding-columns-format
3607 org-agenda-overriding-columns-format))
3608 (if (and (boundp 'org-agenda-view-columns-initially)
3609 org-agenda-view-columns-initially)
3610 (org-agenda-columns))
3611 (when org-agenda-fontify-priorities
3612 (org-agenda-fontify-priorities))
3613 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3614 (org-agenda-dim-blocked-tasks))
3615 ;; We need to widen when `org-agenda-finalize' is called from
3616 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3617 (when org-clock-current-task
3618 (save-restriction
3619 (widen)
3620 (org-agenda-mark-clocking-task)))
3621 (when org-agenda-entry-text-mode
3622 (org-agenda-entry-text-hide)
3623 (org-agenda-entry-text-show))
3624 (if (and (functionp 'org-habit-insert-consistency-graphs)
3625 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3626 (org-habit-insert-consistency-graphs))
3627 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3628 (unless (or (eq org-agenda-show-inherited-tags 'always)
3629 (and (listp org-agenda-show-inherited-tags)
3630 (memq org-agenda-type org-agenda-show-inherited-tags))
3631 (and (eq org-agenda-show-inherited-tags t)
3632 (or (eq org-agenda-use-tag-inheritance t)
3633 (and (listp org-agenda-use-tag-inheritance)
3634 (not (memq org-agenda-type
3635 org-agenda-use-tag-inheritance))))))
3636 (let (mrk)
3637 (save-excursion
3638 (goto-char (point-min))
3639 (while (equal (forward-line) 0)
3640 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3641 (get-text-property (point) 'org-hd-marker)))
3642 (put-text-property (point-at-bol) (point-at-eol)
3643 'tags (org-with-point-at mrk
3644 (delete-dups
3645 (mapcar 'downcase (org-get-tags-at))))))))))
3646 (run-hooks 'org-agenda-finalize-hook)
3647 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3648 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3649 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3650 (org-agenda-filter-apply org-agenda-category-filter 'category))
3651 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3653 (defun org-agenda-mark-clocking-task ()
3654 "Mark the current clock entry in the agenda if it is present."
3655 (mapc (lambda (o)
3656 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3657 (delete-overlay o)))
3658 (overlays-in (point-min) (point-max)))
3659 (when (marker-buffer org-clock-hd-marker)
3660 (save-excursion
3661 (goto-char (point-min))
3662 (let (s ov)
3663 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3664 (goto-char s)
3665 (when (equal (org-get-at-bol 'org-hd-marker)
3666 org-clock-hd-marker)
3667 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3668 (overlay-put ov 'type 'org-agenda-clocking)
3669 (overlay-put ov 'face 'org-agenda-clocking)
3670 (overlay-put ov 'help-echo
3671 "The clock is running in this item")))))))
3673 (defun org-agenda-fontify-priorities ()
3674 "Make highest priority lines bold, and lowest italic."
3675 (interactive)
3676 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3677 (delete-overlay o)))
3678 (overlays-in (point-min) (point-max)))
3679 (save-excursion
3680 (let (b e p ov h l)
3681 (goto-char (point-min))
3682 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3683 (setq h (or (get-char-property (point) 'org-highest-priority)
3684 org-highest-priority)
3685 l (or (get-char-property (point) 'org-lowest-priority)
3686 org-lowest-priority)
3687 p (string-to-char (match-string 1))
3688 b (match-beginning 0)
3689 e (if (eq org-agenda-fontify-priorities 'cookies)
3690 (match-end 0)
3691 (point-at-eol))
3692 ov (make-overlay b e))
3693 (overlay-put
3694 ov 'face
3695 (cons (cond ((org-face-from-face-or-color
3696 'priority nil
3697 (cdr (assoc p org-priority-faces))))
3698 ((and (listp org-agenda-fontify-priorities)
3699 (org-face-from-face-or-color
3700 'priority nil
3701 (cdr (assoc p org-agenda-fontify-priorities)))))
3702 ((equal p l) 'italic)
3703 ((equal p h) 'bold))
3704 'org-priority))
3705 (overlay-put ov 'org-type 'org-priority)))))
3707 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3708 (interactive "P")
3709 "Dim currently blocked TODO's in the agenda display."
3710 (message "Dim or hide blocked tasks...")
3711 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3712 (delete-overlay o)))
3713 (overlays-in (point-min) (point-max)))
3714 (save-excursion
3715 (let ((inhibit-read-only t)
3716 (org-depend-tag-blocked nil)
3717 (invis (or (not (null invisible))
3718 (eq org-agenda-dim-blocked-tasks 'invisible)))
3719 org-blocked-by-checkboxes
3720 invis1 b e p ov h l)
3721 (goto-char (point-min))
3722 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3723 (and pos (goto-char (1+ pos))))
3724 (setq org-blocked-by-checkboxes nil invis1 invis)
3725 (let ((marker (org-get-at-bol 'org-hd-marker)))
3726 (when (and marker
3727 (with-current-buffer (marker-buffer marker)
3728 (save-excursion (goto-char marker)
3729 (org-entry-blocked-p))))
3730 (if org-blocked-by-checkboxes (setq invis1 nil))
3731 (setq b (if invis1
3732 (max (point-min) (1- (point-at-bol)))
3733 (point-at-bol))
3734 e (point-at-eol)
3735 ov (make-overlay b e))
3736 (if invis1
3737 (overlay-put ov 'invisible t)
3738 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3739 (overlay-put ov 'org-type 'org-blocked-todo))))))
3740 (message "Dim or hide blocked tasks...done"))
3742 (defvar org-agenda-skip-function nil
3743 "Function to be called at each match during agenda construction.
3744 If this function returns nil, the current match should not be skipped.
3745 Otherwise, the function must return a position from where the search
3746 should be continued.
3747 This may also be a Lisp form, it will be evaluated.
3748 Never set this variable using `setq' or so, because then it will apply
3749 to all future agenda commands. If you do want a global skipping condition,
3750 use the option `org-agenda-skip-function-global' instead.
3751 The correct usage for `org-agenda-skip-function' is to bind it with
3752 `let' to scope it dynamically into the agenda-constructing command.
3753 A good way to set it is through options in `org-agenda-custom-commands'.")
3755 (defun org-agenda-skip ()
3756 "Throw to `:skip' in places that should be skipped.
3757 Also moves point to the end of the skipped region, so that search can
3758 continue from there."
3759 (let ((p (point-at-bol)) to)
3760 (when (or
3761 (save-excursion (goto-char p) (looking-at comment-start-skip))
3762 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3763 (get-text-property p :org-archived)
3764 (org-end-of-subtree t))
3765 (and org-agenda-skip-comment-trees
3766 (get-text-property p :org-comment)
3767 (org-end-of-subtree t))
3768 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3769 (org-agenda-skip-eval org-agenda-skip-function)))
3770 (goto-char to))
3771 (org-in-src-block-p t))
3772 (throw :skip t))))
3774 (defun org-agenda-skip-eval (form)
3775 "If FORM is a function or a list, call (or eval) is and return result.
3776 `save-excursion' and `save-match-data' are wrapped around the call, so point
3777 and match data are returned to the previous state no matter what these
3778 functions do."
3779 (let (fp)
3780 (and form
3781 (or (setq fp (functionp form))
3782 (consp form))
3783 (save-excursion
3784 (save-match-data
3785 (if fp
3786 (funcall form)
3787 (eval form)))))))
3789 (defvar org-agenda-markers nil
3790 "List of all currently active markers created by `org-agenda'.")
3791 (defvar org-agenda-last-marker-time (org-float-time)
3792 "Creation time of the last agenda marker.")
3794 (defun org-agenda-new-marker (&optional pos)
3795 "Return a new agenda marker.
3796 Org-mode keeps a list of these markers and resets them when they are
3797 no longer in use."
3798 (let ((m (copy-marker (or pos (point)))))
3799 (setq org-agenda-last-marker-time (org-float-time))
3800 (if org-agenda-buffer
3801 (with-current-buffer org-agenda-buffer
3802 (push m org-agenda-markers))
3803 (push m org-agenda-markers))
3806 (defun org-agenda-reset-markers ()
3807 "Reset markers created by `org-agenda'."
3808 (while org-agenda-markers
3809 (move-marker (pop org-agenda-markers) nil)))
3811 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3812 "Save relative positions of markers in region.
3813 This check for agenda markers in all agenda buffers currently active."
3814 (dolist (buf (buffer-list))
3815 (with-current-buffer buf
3816 (when (eq major-mode 'org-agenda-mode)
3817 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3818 org-agenda-markers)))))
3820 ;;; Entry text mode
3822 (defun org-agenda-entry-text-show-here ()
3823 "Add some text from the entry as context to the current line."
3824 (let (m txt o)
3825 (setq m (org-get-at-bol 'org-hd-marker))
3826 (unless (marker-buffer m)
3827 (error "No marker points to an entry here"))
3828 (setq txt (concat "\n" (org-no-properties
3829 (org-agenda-get-some-entry-text
3830 m org-agenda-entry-text-maxlines " > "))))
3831 (when (string-match "\\S-" txt)
3832 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3833 (overlay-put o 'evaporate t)
3834 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3835 (overlay-put o 'after-string txt))))
3837 (defun org-agenda-entry-text-show ()
3838 "Add entry context for all agenda lines."
3839 (interactive)
3840 (save-excursion
3841 (goto-char (point-max))
3842 (beginning-of-line 1)
3843 (while (not (bobp))
3844 (when (org-get-at-bol 'org-hd-marker)
3845 (org-agenda-entry-text-show-here))
3846 (beginning-of-line 0))))
3848 (defun org-agenda-entry-text-hide ()
3849 "Remove any shown entry context."
3850 (delq nil
3851 (mapcar (lambda (o)
3852 (if (eq (overlay-get o 'org-overlay-type)
3853 'agenda-entry-content)
3854 (progn (delete-overlay o) t)))
3855 (overlays-in (point-min) (point-max)))))
3857 (defun org-agenda-get-day-face (date)
3858 "Return the face DATE should be displayed with."
3859 (or (and (functionp org-agenda-day-face-function)
3860 (funcall org-agenda-day-face-function date))
3861 (cond ((org-agenda-todayp date)
3862 'org-agenda-date-today)
3863 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3864 'org-agenda-date-weekend)
3865 (t 'org-agenda-date))))
3867 ;;; Agenda timeline
3869 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3871 (defun org-timeline (&optional dotodo)
3872 "Show a time-sorted view of the entries in the current org file.
3873 Only entries with a time stamp of today or later will be listed. With
3874 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3875 under the current date.
3876 If the buffer contains an active region, only check the region for
3877 dates."
3878 (interactive "P")
3879 (let* ((dopast t)
3880 (org-agenda-show-log-scoped org-agenda-show-log)
3881 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3882 (current-buffer))))
3883 (date (calendar-current-date))
3884 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3885 (end (if (org-region-active-p) (region-end) (point-max)))
3886 (day-numbers (org-get-all-dates
3887 beg end 'no-ranges
3888 t org-agenda-show-log-scoped ; always include today
3889 org-timeline-show-empty-dates))
3890 (org-deadline-warning-days 0)
3891 (org-agenda-only-exact-dates t)
3892 (today (org-today))
3893 (past t)
3894 args
3895 s e rtn d emptyp)
3896 (setq org-agenda-redo-command
3897 (list 'progn
3898 (list 'org-switch-to-buffer-other-window (current-buffer))
3899 (list 'org-timeline (list 'quote dotodo))))
3900 (if (not dopast)
3901 ;; Remove past dates from the list of dates.
3902 (setq day-numbers (delq nil (mapcar (lambda(x)
3903 (if (>= x today) x nil))
3904 day-numbers))))
3905 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3906 (org-compile-prefix-format 'timeline)
3907 (org-set-sorting-strategy 'timeline)
3908 (if org-agenda-show-log-scoped (push :closed args))
3909 (push :timestamp args)
3910 (push :deadline args)
3911 (push :scheduled args)
3912 (push :sexp args)
3913 (if dotodo (push :todo args))
3914 (insert "Timeline of file " entry "\n")
3915 (add-text-properties (point-min) (point)
3916 (list 'face 'org-agenda-structure))
3917 (org-agenda-mark-header-line (point-min))
3918 (while (setq d (pop day-numbers))
3919 (if (and (listp d) (eq (car d) :omitted))
3920 (progn
3921 (setq s (point))
3922 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3923 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3924 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3925 (if (and (>= d today)
3926 dopast
3927 past)
3928 (progn
3929 (setq past nil)
3930 (insert (make-string 79 ?-) "\n")))
3931 (setq date (calendar-gregorian-from-absolute d))
3932 (setq s (point))
3933 (setq rtn (and (not emptyp)
3934 (apply 'org-agenda-get-day-entries entry
3935 date args)))
3936 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3937 (progn
3938 (insert
3939 (if (stringp org-agenda-format-date)
3940 (format-time-string org-agenda-format-date
3941 (org-time-from-absolute date))
3942 (funcall org-agenda-format-date date))
3943 "\n")
3944 (put-text-property s (1- (point)) 'face
3945 (org-agenda-get-day-face date))
3946 (put-text-property s (1- (point)) 'org-date-line t)
3947 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3948 (if (equal d today)
3949 (put-text-property s (1- (point)) 'org-today t))
3950 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3951 (put-text-property s (1- (point)) 'day d)))))
3952 (goto-char (point-min))
3953 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3954 (point-min)))
3955 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3956 (org-agenda-finalize)
3957 (setq buffer-read-only t)))
3959 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3960 "Return a list of all relevant day numbers from BEG to END buffer positions.
3961 If NO-RANGES is non-nil, include only the start and end dates of a range,
3962 not every single day in the range. If FORCE-TODAY is non-nil, make
3963 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3964 inactive time stamps (those in square brackets) are included.
3965 When EMPTY is non-nil, also include days without any entries."
3966 (let ((re (concat
3967 (if pre-re pre-re "")
3968 (if inactive org-ts-regexp-both org-ts-regexp)))
3969 dates dates1 date day day1 day2 ts1 ts2 pos)
3970 (if force-today
3971 (setq dates (list (org-today))))
3972 (save-excursion
3973 (goto-char beg)
3974 (while (re-search-forward re end t)
3975 (setq day (time-to-days (org-time-string-to-time
3976 (substring (match-string 1) 0 10)
3977 (current-buffer) (match-beginning 0))))
3978 (or (memq day dates) (push day dates)))
3979 (unless no-ranges
3980 (goto-char beg)
3981 (while (re-search-forward org-tr-regexp end t)
3982 (setq pos (match-beginning 0))
3983 (setq ts1 (substring (match-string 1) 0 10)
3984 ts2 (substring (match-string 2) 0 10)
3985 day1 (time-to-days (org-time-string-to-time
3986 ts1 (current-buffer) pos))
3987 day2 (time-to-days (org-time-string-to-time
3988 ts2 (current-buffer) pos)))
3989 (while (< (setq day1 (1+ day1)) day2)
3990 (or (memq day1 dates) (push day1 dates)))))
3991 (setq dates (sort dates '<))
3992 (when empty
3993 (while (setq day (pop dates))
3994 (setq day2 (car dates))
3995 (push day dates1)
3996 (when (and day2 empty)
3997 (if (or (eq empty t)
3998 (and (numberp empty) (<= (- day2 day) empty)))
3999 (while (< (setq day (1+ day)) day2)
4000 (push (list day) dates1))
4001 (push (cons :omitted (- day2 day)) dates1))))
4002 (setq dates (nreverse dates1)))
4003 dates)))
4005 ;;; Agenda Daily/Weekly
4007 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4008 "Start day for the agenda view.
4009 Custom commands can set this variable in the options section.")
4010 (defvar org-starting-day nil) ; local variable in the agenda buffer
4011 (defvar org-arg-loc nil) ; local variable
4013 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
4014 "List of types searched for when creating the daily/weekly agenda.
4015 This variable is a list of symbols that controls the types of
4016 items that appear in the daily/weekly agenda. Allowed symbols in this
4017 list are are
4019 :timestamp List items containing a date stamp or date range matching
4020 the selected date. This includes sexp entries in
4021 angular brackets.
4023 :sexp List entries resulting from plain diary-like sexps.
4025 :deadline List deadline due on that date. When the date is today,
4026 also list any deadlines past due, or due within
4027 `org-deadline-warning-days'. `:deadline' must appear before
4028 `:scheduled' if the setting of
4029 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4030 any effect.
4032 :scheduled List all items which are scheduled for the given date.
4033 The diary for *today* also contains items which were
4034 scheduled earlier and are not yet marked DONE.
4036 By default, all four types are turned on.
4038 Never set this variable globally using `setq', because then it
4039 will apply to all future agenda commands. Instead, bind it with
4040 `let' to scope it dynamically into the agenda-constructing
4041 command. A good way to set it is through options in
4042 `org-agenda-custom-commands'. For a more flexible (though
4043 somewhat less efficient) way of determining what is included in
4044 the daily/weekly agenda, see `org-agenda-skip-function'.")
4046 (defvar org-agenda-buffer-tmp-name nil)
4047 ;;;###autoload
4048 (defun org-agenda-list (&optional arg start-day span)
4049 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4050 The view will be for the current day or week, but from the overview buffer
4051 you will be able to go to other days/weeks.
4053 With a numeric prefix argument in an interactive call, the agenda will
4054 span ARG days. Lisp programs should instead specify SPAN to change
4055 the number of days. SPAN defaults to `org-agenda-span'.
4057 START-DAY defaults to TODAY, or to the most recent match for the weekday
4058 given in `org-agenda-start-on-weekday'."
4059 (interactive "P")
4060 (if org-agenda-overriding-arguments
4061 (setq arg (car org-agenda-overriding-arguments)
4062 start-day (nth 1 org-agenda-overriding-arguments)
4063 span (nth 2 org-agenda-overriding-arguments)))
4064 (if (and (integerp arg) (> arg 0))
4065 (setq span arg arg nil))
4066 (catch 'exit
4067 (setq org-agenda-buffer-name
4068 (or org-agenda-buffer-tmp-name
4069 (if org-agenda-sticky
4070 (cond ((and org-keys (stringp org-match))
4071 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4072 (org-keys
4073 (format "*Org Agenda(%s)*" org-keys))
4074 (t "*Org Agenda(a)*")))
4075 org-agenda-buffer-name))
4076 (org-agenda-prepare "Day/Week")
4077 (setq start-day (or start-day org-agenda-start-day))
4078 (if (stringp start-day)
4079 ;; Convert to an absolute day number
4080 (setq start-day (time-to-days (org-read-date nil t start-day))))
4081 (org-compile-prefix-format 'agenda)
4082 (org-set-sorting-strategy 'agenda)
4083 (let* ((span (org-agenda-ndays-to-span
4084 (or span org-agenda-ndays org-agenda-span)))
4085 (today (org-today))
4086 (sd (or start-day today))
4087 (ndays (org-agenda-span-to-ndays span sd))
4088 (org-agenda-start-on-weekday
4089 (if (eq ndays 7)
4090 org-agenda-start-on-weekday))
4091 (thefiles (org-agenda-files nil 'ifmode))
4092 (files thefiles)
4093 (start (if (or (null org-agenda-start-on-weekday)
4094 (< ndays 7))
4096 (let* ((nt (calendar-day-of-week
4097 (calendar-gregorian-from-absolute sd)))
4098 (n1 org-agenda-start-on-weekday)
4099 (d (- nt n1)))
4100 (- sd (+ (if (< d 0) 7 0) d)))))
4101 (day-numbers (list start))
4102 (day-cnt 0)
4103 (inhibit-redisplay (not debug-on-error))
4104 (org-agenda-show-log-scoped org-agenda-show-log)
4105 s e rtn rtnall file date d start-pos end-pos todayp
4106 clocktable-start clocktable-end filter)
4107 (setq org-agenda-redo-command
4108 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4109 (dotimes (n (1- ndays))
4110 (push (1+ (car day-numbers)) day-numbers))
4111 (setq day-numbers (nreverse day-numbers))
4112 (setq clocktable-start (car day-numbers)
4113 clocktable-end (1+ (or (org-last day-numbers) 0)))
4114 (org-set-local 'org-starting-day (car day-numbers))
4115 (org-set-local 'org-arg-loc arg)
4116 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4117 (unless org-agenda-compact-blocks
4118 (let* ((d1 (car day-numbers))
4119 (d2 (org-last day-numbers))
4120 (w1 (org-days-to-iso-week d1))
4121 (w2 (org-days-to-iso-week d2)))
4122 (setq s (point))
4123 (if org-agenda-overriding-header
4124 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4125 nil 'face 'org-agenda-structure) "\n")
4126 (insert (org-agenda-span-name span)
4127 "-agenda"
4128 (if (< (- d2 d1) 350)
4129 (if (= w1 w2)
4130 (format " (W%02d)" w1)
4131 (format " (W%02d-W%02d)" w1 w2))
4133 ":\n")))
4134 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4135 'org-date-line t))
4136 (org-agenda-mark-header-line s))
4137 (while (setq d (pop day-numbers))
4138 (setq date (calendar-gregorian-from-absolute d)
4139 s (point))
4140 (if (or (setq todayp (= d today))
4141 (and (not start-pos) (= d sd)))
4142 (setq start-pos (point))
4143 (if (and start-pos (not end-pos))
4144 (setq end-pos (point))))
4145 (setq files thefiles
4146 rtnall nil)
4147 (while (setq file (pop files))
4148 (catch 'nextfile
4149 (org-check-agenda-file file)
4150 (let ((org-agenda-entry-types org-agenda-entry-types))
4151 (unless org-agenda-include-deadlines
4152 (setq org-agenda-entry-types
4153 (delq :deadline org-agenda-entry-types)))
4154 (cond
4155 ((memq org-agenda-show-log-scoped '(only clockcheck))
4156 (setq rtn (org-agenda-get-day-entries
4157 file date :closed)))
4158 (org-agenda-show-log-scoped
4159 (setq rtn (apply 'org-agenda-get-day-entries
4160 file date
4161 (append '(:closed) org-agenda-entry-types))))
4163 (setq rtn (apply 'org-agenda-get-day-entries
4164 file date
4165 org-agenda-entry-types)))))
4166 (setq rtnall (append rtnall rtn)))) ;; all entries
4167 (if org-agenda-include-diary
4168 (let ((org-agenda-search-headline-for-time t))
4169 (require 'diary-lib)
4170 (setq rtn (org-get-entries-from-diary date))
4171 (setq rtnall (append rtnall rtn))))
4172 (if (or rtnall org-agenda-show-all-dates)
4173 (progn
4174 (setq day-cnt (1+ day-cnt))
4175 (insert
4176 (if (stringp org-agenda-format-date)
4177 (format-time-string org-agenda-format-date
4178 (org-time-from-absolute date))
4179 (funcall org-agenda-format-date date))
4180 "\n")
4181 (put-text-property s (1- (point)) 'face
4182 (org-agenda-get-day-face date))
4183 (put-text-property s (1- (point)) 'org-date-line t)
4184 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4185 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4186 (when todayp
4187 (put-text-property s (1- (point)) 'org-today t))
4188 (setq rtnall
4189 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4190 (if rtnall (insert ;; all entries
4191 (org-agenda-finalize-entries rtnall)
4192 "\n"))
4193 (put-text-property s (1- (point)) 'day d)
4194 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4195 (when (and org-agenda-clockreport-mode clocktable-start)
4196 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4197 ;; the above line is to ensure the restricted range!
4198 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4199 tbl)
4200 (setq p (org-plist-delete p :block))
4201 (setq p (plist-put p :tstart clocktable-start))
4202 (setq p (plist-put p :tend clocktable-end))
4203 (setq p (plist-put p :scope 'agenda))
4204 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4205 (setq filter (or org-agenda-tag-filter-while-redo
4206 (get 'org-agenda-tag-filter :preset-filter))))
4207 (setq p (plist-put p :tags (mapconcat (lambda (x)
4208 (if (string-match "[<>=]" x)
4211 filter ""))))
4212 (setq tbl (apply 'org-clock-get-clocktable p))
4213 (insert tbl)))
4214 (goto-char (point-min))
4215 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4216 (unless (and (pos-visible-in-window-p (point-min))
4217 (pos-visible-in-window-p (point-max)))
4218 (goto-char (1- (point-max)))
4219 (recenter -1)
4220 (if (not (pos-visible-in-window-p (or start-pos 1)))
4221 (progn
4222 (goto-char (or start-pos 1))
4223 (recenter 1))))
4224 (goto-char (or start-pos 1))
4225 (add-text-properties (point-min) (point-max)
4226 `(org-agenda-type agenda
4227 org-last-args (,arg ,start-day ,span)
4228 org-redo-cmd ,org-agenda-redo-command
4229 org-series-cmd ,org-cmd))
4230 (if (eq org-agenda-show-log-scoped 'clockcheck)
4231 (org-agenda-show-clocking-issues))
4232 (org-agenda-finalize)
4233 (setq buffer-read-only t)
4234 (message ""))))
4236 (autoload 'org-agenda-list "org-agenda" "\
4237 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4238 The view will be for the current day or week, but from the overview buffer
4239 you will be able to go to other days/weeks.
4241 With a numeric prefix argument in an interactive call, the agenda will
4242 span ARG days. Lisp programs should instead specify SPAN to change
4243 the number of days. SPAN defaults to `org-agenda-span'.
4245 START-DAY defaults to TODAY, or to the most recent match for the weekday
4246 given in `org-agenda-start-on-weekday'.
4248 \(fn &optional ARG START-DAY SPAN)" t nil)
4250 (defun org-agenda-ndays-to-span (n)
4251 "Return a span symbol for a span of N days, or N if none matches."
4252 (cond ((symbolp n) n)
4253 ((= n 1) 'day)
4254 ((= n 7) 'week)
4255 (t n)))
4257 (defun org-agenda-span-to-ndays (span &optional start-day)
4258 "Return ndays from SPAN, possibly starting at START-DAY."
4259 (cond ((numberp span) span)
4260 ((eq span 'day) 1)
4261 ((eq span 'week) 7)
4262 ((eq span 'month)
4263 (let ((date (calendar-gregorian-from-absolute start-day)))
4264 (calendar-last-day-of-month (car date) (caddr date))))
4265 ((eq span 'year)
4266 (let ((date (calendar-gregorian-from-absolute start-day)))
4267 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4269 (defun org-agenda-span-name (span)
4270 "Return a SPAN name."
4271 (if (null span)
4273 (if (symbolp span)
4274 (capitalize (symbol-name span))
4275 (format "%d days" span))))
4277 ;;; Agenda word search
4279 (defvar org-agenda-search-history nil)
4281 (defvar org-search-syntax-table nil
4282 "Special syntax table for org-mode search.
4283 In this table, we have single quotes not as word constituents, to
4284 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4286 (defvar org-mode-syntax-table) ; From org.el
4287 (defun org-search-syntax-table ()
4288 (unless org-search-syntax-table
4289 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4290 (modify-syntax-entry ?' "." org-search-syntax-table)
4291 (modify-syntax-entry ?` "." org-search-syntax-table))
4292 org-search-syntax-table)
4294 (defvar org-agenda-last-search-view-search-was-boolean nil)
4296 ;;;###autoload
4297 (defun org-search-view (&optional todo-only string edit-at)
4298 "Show all entries that contain a phrase or words or regular expressions.
4300 With optional prefix argument TODO-ONLY, only consider entries that are
4301 TODO entries. The argument STRING can be used to pass a default search
4302 string into this function. If EDIT-AT is non-nil, it means that the
4303 user should get a chance to edit this string, with cursor at position
4304 EDIT-AT.
4306 The search string can be viewed either as a phrase that should be found as
4307 is, or it can be broken into a number of snippets, each of which must match
4308 in a Boolean way to select an entry. The default depends on the variable
4309 `org-agenda-search-view-always-boolean'.
4310 Even if this is turned off (the default) you can always switch to
4311 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4313 The default is a direct search of the whole phrase, where each space in
4314 the search string can expand to an arbitrary amount of whitespace,
4315 including newlines.
4317 If using a Boolean search, the search string is split on whitespace and
4318 each snippet is searched separately, with logical AND to select an entry.
4319 Words prefixed with a minus must *not* occur in the entry. Words without
4320 a prefix or prefixed with a plus must occur in the entry. Matching is
4321 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4322 match whole words, not parts of a word) if
4323 `org-agenda-search-view-force-full-words' is set (default is nil).
4325 Boolean search snippets enclosed by curly braces are interpreted as
4326 regular expressions that must or (when preceded with \"-\") must not
4327 match in the entry. Snippets enclosed into double quotes will be taken
4328 as a whole, to include whitespace.
4330 - If the search string starts with an asterisk, search only in headlines.
4331 - If (possibly after the leading star) the search string starts with an
4332 exclamation mark, this also means to look at TODO entries only, an effect
4333 that can also be achieved with a prefix argument.
4334 - If (possibly after star and exclamation mark) the search string starts
4335 with a colon, this will mean that the (non-regexp) snippets of the
4336 Boolean search must match as full words.
4338 This command searches the agenda files, and in addition the files listed
4339 in `org-agenda-text-search-extra-files'."
4340 (interactive "P")
4341 (if org-agenda-overriding-arguments
4342 (setq todo-only (car org-agenda-overriding-arguments)
4343 string (nth 1 org-agenda-overriding-arguments)
4344 edit-at (nth 2 org-agenda-overriding-arguments)))
4345 (let* ((props (list 'face nil
4346 'done-face 'org-agenda-done
4347 'org-not-done-regexp org-not-done-regexp
4348 'org-todo-regexp org-todo-regexp
4349 'org-complex-heading-regexp org-complex-heading-regexp
4350 'mouse-face 'highlight
4351 'help-echo (format "mouse-2 or RET jump to location")))
4352 (full-words org-agenda-search-view-force-full-words)
4353 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4354 regexp rtn rtnall files file pos inherited-tags
4355 marker category category-pos level tags c neg re boolean
4356 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4357 (unless (and (not edit-at)
4358 (stringp string)
4359 (string-match "\\S-" string))
4360 (setq string (read-string
4361 (if org-agenda-search-view-always-boolean
4362 "[+-]Word/{Regexp} ...: "
4363 "Phrase or [+-]Word/{Regexp} ...: ")
4364 (cond
4365 ((integerp edit-at) (cons string edit-at))
4366 (edit-at string))
4367 'org-agenda-search-history)))
4368 (catch 'exit
4369 (if org-agenda-sticky
4370 (setq org-agenda-buffer-name
4371 (if (stringp string)
4372 (format "*Org Agenda(%s:%s)*"
4373 (or org-keys (or (and todo-only "S") "s")) string)
4374 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4375 (org-agenda-prepare "SEARCH")
4376 (org-compile-prefix-format 'search)
4377 (org-set-sorting-strategy 'search)
4378 (setq org-agenda-redo-command
4379 (list 'org-search-view (if todo-only t nil)
4380 (list 'if 'current-prefix-arg nil string)))
4381 (setq org-agenda-query-string string)
4382 (if (equal (string-to-char string) ?*)
4383 (setq hdl-only t
4384 words (substring string 1))
4385 (setq words string))
4386 (when (equal (string-to-char words) ?!)
4387 (setq todo-only t
4388 words (substring words 1)))
4389 (when (equal (string-to-char words) ?:)
4390 (setq full-words t
4391 words (substring words 1)))
4392 (if (or org-agenda-search-view-always-boolean
4393 (member (string-to-char words) '(?- ?+ ?\{)))
4394 (setq boolean t))
4395 (setq words (org-split-string words))
4396 (let (www w)
4397 (while (setq w (pop words))
4398 (while (and (string-match "\\\\\\'" w) words)
4399 (setq w (concat (substring w 0 -1) " " (pop words))))
4400 (push w www))
4401 (setq words (nreverse www) www nil)
4402 (while (setq w (pop words))
4403 (when (and (string-match "\\`[-+]?{" w)
4404 (not (string-match "}\\'" w)))
4405 (while (and words (not (string-match "}\\'" (car words))))
4406 (setq w (concat w " " (pop words))))
4407 (setq w (concat w " " (pop words))))
4408 (push w www))
4409 (setq words (nreverse www)))
4410 (setq org-agenda-last-search-view-search-was-boolean boolean)
4411 (when boolean
4412 (let (wds w)
4413 (while (setq w (pop words))
4414 (if (or (equal (substring w 0 1) "\"")
4415 (and (> (length w) 1)
4416 (member (substring w 0 1) '("+" "-"))
4417 (equal (substring w 1 2) "\"")))
4418 (while (and words (not (equal (substring w -1) "\"")))
4419 (setq w (concat w " " (pop words)))))
4420 (and (string-match "\\`\\([-+]?\\)\"" w)
4421 (setq w (replace-match "\\1" nil nil w)))
4422 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4423 (push w wds))
4424 (setq words (nreverse wds))))
4425 (if boolean
4426 (mapc (lambda (w)
4427 (setq c (string-to-char w))
4428 (if (equal c ?-)
4429 (setq neg t w (substring w 1))
4430 (if (equal c ?+)
4431 (setq neg nil w (substring w 1))
4432 (setq neg nil)))
4433 (if (string-match "\\`{.*}\\'" w)
4434 (setq re (substring w 1 -1))
4435 (if full-words
4436 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4437 (setq re (regexp-quote (downcase w)))))
4438 (if neg (push re regexps-) (push re regexps+)))
4439 words)
4440 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4441 regexps+))
4442 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4443 (if (not regexps+)
4444 (setq regexp org-outline-regexp-bol)
4445 (setq regexp (pop regexps+))
4446 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4447 regexp))))
4448 (setq files (org-agenda-files nil 'ifmode))
4449 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4450 (pop org-agenda-text-search-extra-files)
4451 (setq files (org-add-archive-files files)))
4452 (setq files (append files org-agenda-text-search-extra-files)
4453 rtnall nil)
4454 (while (setq file (pop files))
4455 (setq ee nil)
4456 (catch 'nextfile
4457 (org-check-agenda-file file)
4458 (setq buffer (if (file-exists-p file)
4459 (org-get-agenda-file-buffer file)
4460 (error "No such file %s" file)))
4461 (if (not buffer)
4462 ;; If file does not exist, make sure an error message is sent
4463 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4464 file))))
4465 (with-current-buffer buffer
4466 (with-syntax-table (org-search-syntax-table)
4467 (unless (derived-mode-p 'org-mode)
4468 (error "Agenda file %s is not in `org-mode'" file))
4469 (let ((case-fold-search t))
4470 (save-excursion
4471 (save-restriction
4472 (if org-agenda-restrict
4473 (narrow-to-region org-agenda-restrict-begin
4474 org-agenda-restrict-end)
4475 (widen))
4476 (goto-char (point-min))
4477 (unless (or (org-at-heading-p)
4478 (outline-next-heading))
4479 (throw 'nextfile t))
4480 (goto-char (max (point-min) (1- (point))))
4481 (while (re-search-forward regexp nil t)
4482 (org-back-to-heading t)
4483 (while (and org-agenda-search-view-max-outline-level
4484 (> (org-reduced-level (org-outline-level))
4485 org-agenda-search-view-max-outline-level)
4486 (forward-line -1)
4487 (outline-back-to-heading t)))
4488 (skip-chars-forward "* ")
4489 (setq beg (point-at-bol)
4490 beg1 (point)
4491 end (progn
4492 (outline-next-heading)
4493 (while (and org-agenda-search-view-max-outline-level
4494 (> (org-reduced-level (org-outline-level))
4495 org-agenda-search-view-max-outline-level)
4496 (forward-line 1)
4497 (outline-next-heading)))
4498 (point)))
4500 (catch :skip
4501 (goto-char beg)
4502 (org-agenda-skip)
4503 (setq str (buffer-substring-no-properties
4504 (point-at-bol)
4505 (if hdl-only (point-at-eol) end)))
4506 (mapc (lambda (wr) (when (string-match wr str)
4507 (goto-char (1- end))
4508 (throw :skip t)))
4509 regexps-)
4510 (mapc (lambda (wr) (unless (string-match wr str)
4511 (goto-char (1- end))
4512 (throw :skip t)))
4513 (if todo-only
4514 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4515 regexps+)
4516 regexps+))
4517 (goto-char beg)
4518 (setq marker (org-agenda-new-marker (point))
4519 category (org-get-category)
4520 level (make-string (org-reduced-level (org-outline-level)) ? )
4521 category-pos (get-text-property (point) 'org-category-position)
4522 inherited-tags
4523 (or (eq org-agenda-show-inherited-tags 'always)
4524 (and (listp org-agenda-show-inherited-tags)
4525 (memq 'todo org-agenda-show-inherited-tags))
4526 (and (eq org-agenda-show-inherited-tags t)
4527 (or (eq org-agenda-use-tag-inheritance t)
4528 (memq 'todo org-agenda-use-tag-inheritance))))
4529 tags (org-get-tags-at nil (not inherited-tags))
4530 txt (org-agenda-format-item
4532 (buffer-substring-no-properties
4533 beg1 (point-at-eol))
4534 level category tags t))
4535 (org-add-props txt props
4536 'org-marker marker 'org-hd-marker marker
4537 'org-todo-regexp org-todo-regexp
4538 'level level
4539 'org-complex-heading-regexp org-complex-heading-regexp
4540 'priority 1000 'org-category category
4541 'org-category-position category-pos
4542 'type "search")
4543 (push txt ee)
4544 (goto-char (1- end))))))))))
4545 (setq rtn (nreverse ee))
4546 (setq rtnall (append rtnall rtn)))
4547 (if org-agenda-overriding-header
4548 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4549 nil 'face 'org-agenda-structure) "\n")
4550 (insert "Search words: ")
4551 (add-text-properties (point-min) (1- (point))
4552 (list 'face 'org-agenda-structure))
4553 (setq pos (point))
4554 (insert string "\n")
4555 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4556 (setq pos (point))
4557 (unless org-agenda-multi
4558 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4559 (add-text-properties pos (1- (point))
4560 (list 'face 'org-agenda-structure))))
4561 (org-agenda-mark-header-line (point-min))
4562 (when rtnall
4563 (insert (org-agenda-finalize-entries rtnall) "\n"))
4564 (goto-char (point-min))
4565 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4566 (add-text-properties (point-min) (point-max)
4567 `(org-agenda-type search
4568 org-last-args (,todo-only ,string ,edit-at)
4569 org-redo-cmd ,org-agenda-redo-command
4570 org-series-cmd ,org-cmd))
4571 (org-agenda-finalize)
4572 (setq buffer-read-only t))))
4574 (autoload 'org-search-view "org-agenda" "\
4575 Show all entries that contain a phrase or words or regular expressions.
4577 With optional prefix argument TODO-ONLY, only consider entries that are
4578 TODO entries. The argument STRING can be used to pass a default search
4579 string into this function. If EDIT-AT is non-nil, it means that the
4580 user should get a chance to edit this string, with cursor at position
4581 EDIT-AT.
4583 The search string can be viewed either as a phrase that should be found as
4584 is, or it can be broken into a number of snippets, each of which must match
4585 in a Boolean way to select an entry. The default depends on the variable
4586 `org-agenda-search-view-always-boolean'.
4587 Even if this is turned off (the default) you can always switch to
4588 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4590 The default is a direct search of the whole phrase, where each space in
4591 the search string can expand to an arbitrary amount of whitespace,
4592 including newlines.
4594 If using a Boolean search, the search string is split on whitespace and
4595 each snippet is searched separately, with logical AND to select an entry.
4596 Words prefixed with a minus must *not* occur in the entry. Words without
4597 a prefix or prefixed with a plus must occur in the entry. Matching is
4598 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4599 match whole words, not parts of a word) if
4600 `org-agenda-search-view-force-full-words' is set (default is nil).
4602 Boolean search snippets enclosed by curly braces are interpreted as
4603 regular expressions that must or (when preceded with \"-\") must not
4604 match in the entry. Snippets enclosed into double quotes will be taken
4605 as a whole, to include whitespace.
4607 - If the search string starts with an asterisk, search only in headlines.
4608 - If (possibly after the leading star) the search string starts with an
4609 exclamation mark, this also means to look at TODO entries only, an effect
4610 that can also be achieved with a prefix argument.
4611 - If (possibly after star and exclamation mark) the search string starts
4612 with a colon, this will mean that the (non-regexp) snippets of the
4613 Boolean search must match as full words.
4615 This command searches the agenda files, and in addition the files listed
4616 in `org-agenda-text-search-extra-files'.
4618 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4620 ;;; Agenda TODO list
4622 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4623 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4624 (concat
4625 (if (or (equal keywords "ALL") (not keywords))
4626 (propertize "ALL" 'face 'warning)
4627 (mapconcat
4628 (lambda (kw)
4629 (propertize kw 'face (org-get-todo-face kw)))
4630 (org-split-string keywords "|")
4631 "|"))
4632 "\n"))
4634 (defvar org-select-this-todo-keyword nil)
4635 (defvar org-last-arg nil)
4637 ;;;###autoload
4638 (defun org-todo-list (&optional arg)
4639 "Show all (not done) TODO entries from all agenda file in a single list.
4640 The prefix arg can be used to select a specific TODO keyword and limit
4641 the list to these. When using \\[universal-argument], you will be prompted
4642 for a keyword. A numeric prefix directly selects the Nth keyword in
4643 `org-todo-keywords-1'."
4644 (interactive "P")
4645 (if org-agenda-overriding-arguments
4646 (setq arg org-agenda-overriding-arguments))
4647 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4648 (let* ((today (org-today))
4649 (date (calendar-gregorian-from-absolute today))
4650 (kwds org-todo-keywords-for-agenda)
4651 (completion-ignore-case t)
4652 (org-select-this-todo-keyword
4653 (if (stringp arg) arg
4654 (and arg (integerp arg) (> arg 0)
4655 (nth (1- arg) kwds))))
4656 rtn rtnall files file pos)
4657 (when (equal arg '(4))
4658 (setq org-select-this-todo-keyword
4659 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4660 (mapcar 'list kwds) nil nil)))
4661 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4662 (catch 'exit
4663 (if org-agenda-sticky
4664 (setq org-agenda-buffer-name
4665 (if (stringp org-select-this-todo-keyword)
4666 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4667 org-select-this-todo-keyword)
4668 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4669 (org-agenda-prepare "TODO")
4670 (org-compile-prefix-format 'todo)
4671 (org-set-sorting-strategy 'todo)
4672 (setq org-agenda-redo-command
4673 `(org-todo-list (or (and (numberp current-prefix-arg)
4674 current-prefix-arg)
4675 ,org-select-this-todo-keyword
4676 current-prefix-arg ,arg)))
4677 (setq files (org-agenda-files nil 'ifmode)
4678 rtnall nil)
4679 (while (setq file (pop files))
4680 (catch 'nextfile
4681 (org-check-agenda-file file)
4682 (setq rtn (org-agenda-get-day-entries file date :todo))
4683 (setq rtnall (append rtnall rtn))))
4684 (if org-agenda-overriding-header
4685 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4686 nil 'face 'org-agenda-structure) "\n")
4687 (insert "Global list of TODO items of type: ")
4688 (add-text-properties (point-min) (1- (point))
4689 (list 'face 'org-agenda-structure
4690 'short-heading
4691 (concat "ToDo: "
4692 (or org-select-this-todo-keyword "ALL"))))
4693 (org-agenda-mark-header-line (point-min))
4694 (insert (org-agenda-propertize-selected-todo-keywords
4695 org-select-this-todo-keyword))
4696 (setq pos (point))
4697 (unless org-agenda-multi
4698 (insert "Available with `N r': (0)[ALL]")
4699 (let ((n 0) s)
4700 (mapc (lambda (x)
4701 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4702 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4703 (insert "\n "))
4704 (insert " " s))
4705 kwds))
4706 (insert "\n"))
4707 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4708 (org-agenda-mark-header-line (point-min))
4709 (when rtnall
4710 (insert (org-agenda-finalize-entries rtnall) "\n"))
4711 (goto-char (point-min))
4712 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4713 (add-text-properties (point-min) (point-max)
4714 `(org-agenda-type todo
4715 org-last-args ,arg
4716 org-redo-cmd ,org-agenda-redo-command
4717 org-series-cmd ,org-cmd))
4718 (org-agenda-finalize)
4719 (setq buffer-read-only t))))
4721 (autoload 'org-todo-list "org-agenda" "\
4722 Show all (not done) TODO entries from all agenda file in a single list.
4723 The prefix arg can be used to select a specific TODO keyword and limit
4724 the list to these. When using \\[universal-argument], you will be prompted
4725 for a keyword. A numeric prefix directly selects the Nth keyword in
4726 `org-todo-keywords-1'.
4728 \(fn &optional ARG)" t nil)
4730 ;;; Agenda tags match
4732 ;;;###autoload
4733 (defun org-tags-view (&optional todo-only match)
4734 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4735 The prefix arg TODO-ONLY limits the search to TODO entries."
4736 (interactive "P")
4737 (if org-agenda-overriding-arguments
4738 (setq todo-only (car org-agenda-overriding-arguments)
4739 match (nth 1 org-agenda-overriding-arguments)))
4740 (let* ((org-tags-match-list-sublevels
4741 org-tags-match-list-sublevels)
4742 (completion-ignore-case t)
4743 rtn rtnall files file pos matcher
4744 buffer)
4745 (when (and (stringp match) (not (string-match "\\S-" match)))
4746 (setq match nil))
4747 (setq matcher (org-make-tags-matcher match)
4748 match (car matcher) matcher (cdr matcher))
4749 (catch 'exit
4750 (if org-agenda-sticky
4751 (setq org-agenda-buffer-name
4752 (if (stringp match)
4753 (format "*Org Agenda(%s:%s)*"
4754 (or org-keys (or (and todo-only "M") "m")) match)
4755 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4756 (org-agenda-prepare (concat "TAGS " match))
4757 (org-compile-prefix-format 'tags)
4758 (org-set-sorting-strategy 'tags)
4759 (setq org-agenda-query-string match)
4760 (setq org-agenda-redo-command
4761 (list 'org-tags-view `(quote ,todo-only)
4762 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4763 (setq files (org-agenda-files nil 'ifmode)
4764 rtnall nil)
4765 (while (setq file (pop files))
4766 (catch 'nextfile
4767 (org-check-agenda-file file)
4768 (setq buffer (if (file-exists-p file)
4769 (org-get-agenda-file-buffer file)
4770 (error "No such file %s" file)))
4771 (if (not buffer)
4772 ;; If file does not exist, error message to agenda
4773 (setq rtn (list
4774 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4775 rtnall (append rtnall rtn))
4776 (with-current-buffer buffer
4777 (unless (derived-mode-p 'org-mode)
4778 (error "Agenda file %s is not in `org-mode'" file))
4779 (save-excursion
4780 (save-restriction
4781 (if org-agenda-restrict
4782 (narrow-to-region org-agenda-restrict-begin
4783 org-agenda-restrict-end)
4784 (widen))
4785 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4786 (setq rtnall (append rtnall rtn))))))))
4787 (if org-agenda-overriding-header
4788 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4789 nil 'face 'org-agenda-structure) "\n")
4790 (insert "Headlines with TAGS match: ")
4791 (add-text-properties (point-min) (1- (point))
4792 (list 'face 'org-agenda-structure
4793 'short-heading
4794 (concat "Match: " match)))
4795 (setq pos (point))
4796 (insert match "\n")
4797 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4798 (setq pos (point))
4799 (unless org-agenda-multi
4800 (insert "Press `C-u r' to search again with new search string\n"))
4801 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4802 (org-agenda-mark-header-line (point-min))
4803 (when rtnall
4804 (insert (org-agenda-finalize-entries rtnall) "\n"))
4805 (goto-char (point-min))
4806 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4807 (add-text-properties (point-min) (point-max)
4808 `(org-agenda-type tags
4809 org-last-args (,todo-only ,match)
4810 org-redo-cmd ,org-agenda-redo-command
4811 org-series-cmd ,org-cmd))
4812 (org-agenda-finalize)
4813 (setq buffer-read-only t))))
4815 (autoload 'org-tags-view "org-agenda" "\
4816 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4817 The prefix arg TODO-ONLY limits the search to TODO entries.
4819 \(fn &optional TODO-ONLY MATCH)" t nil)
4821 ;;; Agenda Finding stuck projects
4823 (defvar org-agenda-skip-regexp nil
4824 "Regular expression used in skipping subtrees for the agenda.
4825 This is basically a temporary global variable that can be set and then
4826 used by user-defined selections using `org-agenda-skip-function'.")
4828 (defvar org-agenda-overriding-header nil
4829 "When set during agenda, todo and tags searches it replaces the header.
4830 This variable should not be set directly, but custom commands can bind it
4831 in the options section.")
4833 (defun org-agenda-skip-entry-when-regexp-matches ()
4834 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4835 If yes, it returns the end position of this entry, causing agenda commands
4836 to skip the entry but continuing the search in the subtree. This is a
4837 function that can be put into `org-agenda-skip-function' for the duration
4838 of a command."
4839 (let ((end (save-excursion (org-end-of-subtree t)))
4840 skip)
4841 (save-excursion
4842 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4843 (and skip end)))
4845 (defun org-agenda-skip-subtree-when-regexp-matches ()
4846 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4847 If yes, it returns the end position of this tree, causing agenda commands
4848 to skip this subtree. This is a function that can be put into
4849 `org-agenda-skip-function' for the duration of a command."
4850 (let ((end (save-excursion (org-end-of-subtree t)))
4851 skip)
4852 (save-excursion
4853 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4854 (and skip end)))
4856 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4857 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4858 If yes, it returns the end position of the current entry (NOT the tree),
4859 causing agenda commands to skip the entry but continuing the search in
4860 the subtree. This is a function that can be put into
4861 `org-agenda-skip-function' for the duration of a command. An important
4862 use of this function is for the stuck project list."
4863 (let ((end (save-excursion (org-end-of-subtree t)))
4864 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4865 skip)
4866 (save-excursion
4867 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4868 (and skip entry-end)))
4870 (defun org-agenda-skip-entry-if (&rest conditions)
4871 "Skip entry if any of CONDITIONS is true.
4872 See `org-agenda-skip-if' for details."
4873 (org-agenda-skip-if nil conditions))
4875 (defun org-agenda-skip-subtree-if (&rest conditions)
4876 "Skip entry if any of CONDITIONS is true.
4877 See `org-agenda-skip-if' for details."
4878 (org-agenda-skip-if t conditions))
4880 (defun org-agenda-skip-if (subtree conditions)
4881 "Checks current entity for CONDITIONS.
4882 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4883 the entry (i.e. the text before the next heading) is checked.
4885 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4886 from different tests. Valid conditions are:
4888 scheduled Check if there is a scheduled cookie
4889 notscheduled Check if there is no scheduled cookie
4890 deadline Check if there is a deadline
4891 notdeadline Check if there is no deadline
4892 timestamp Check if there is a timestamp (also deadline or scheduled)
4893 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4894 regexp Check if regexp matches
4895 notregexp Check if regexp does not match.
4896 todo Check if TODO keyword matches
4897 nottodo Check if TODO keyword does not match
4899 The regexp is taken from the conditions list, it must come right after
4900 the `regexp' or `notregexp' element.
4902 `todo' and `nottodo' accept as an argument a list of todo
4903 keywords, which may include \"*\" to match any todo keyword.
4905 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4907 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4909 Instead of a list, a keyword class may be given. For example:
4911 (org-agenda-skip-entry-if 'nottodo 'done)
4913 would skip entries that haven't been marked with any of \"DONE\"
4914 keywords. Possible classes are: `todo', `done', `any'.
4916 If any of these conditions is met, this function returns the end point of
4917 the entity, causing the search to continue from there. This is a function
4918 that can be put into `org-agenda-skip-function' for the duration of a command."
4919 (let (beg end m)
4920 (org-back-to-heading t)
4921 (setq beg (point)
4922 end (if subtree
4923 (progn (org-end-of-subtree t) (point))
4924 (progn (outline-next-heading) (1- (point)))))
4925 (goto-char beg)
4926 (and
4928 (and (memq 'scheduled conditions)
4929 (re-search-forward org-scheduled-time-regexp end t))
4930 (and (memq 'notscheduled conditions)
4931 (not (re-search-forward org-scheduled-time-regexp end t)))
4932 (and (memq 'deadline conditions)
4933 (re-search-forward org-deadline-time-regexp end t))
4934 (and (memq 'notdeadline conditions)
4935 (not (re-search-forward org-deadline-time-regexp end t)))
4936 (and (memq 'timestamp conditions)
4937 (re-search-forward org-ts-regexp end t))
4938 (and (memq 'nottimestamp conditions)
4939 (not (re-search-forward org-ts-regexp end t)))
4940 (and (setq m (memq 'regexp conditions))
4941 (stringp (nth 1 m))
4942 (re-search-forward (nth 1 m) end t))
4943 (and (setq m (memq 'notregexp conditions))
4944 (stringp (nth 1 m))
4945 (not (re-search-forward (nth 1 m) end t)))
4946 (and (or
4947 (setq m (memq 'nottodo conditions))
4948 (setq m (memq 'todo-unblocked conditions))
4949 (setq m (memq 'nottodo-unblocked conditions))
4950 (setq m (memq 'todo conditions)))
4951 (org-agenda-skip-if-todo m end)))
4952 end)))
4954 (defun org-agenda-skip-if-todo (args end)
4955 "Helper function for `org-agenda-skip-if', do not use it directly.
4956 ARGS is a list with first element either `todo', `nottodo',
4957 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4958 a list of TODO keywords, or a state symbol `todo' or `done' or
4959 `any'."
4960 (let ((kw (car args))
4961 (arg (cadr args))
4962 todo-wds todo-re)
4963 (setq todo-wds
4964 (org-uniquify
4965 (cond
4966 ((listp arg) ;; list of keywords
4967 (if (member "*" arg)
4968 (mapcar 'substring-no-properties org-todo-keywords-1)
4969 arg))
4970 ((symbolp arg) ;; keyword class name
4971 (cond
4972 ((eq arg 'todo)
4973 (org-delete-all org-done-keywords
4974 (mapcar 'substring-no-properties
4975 org-todo-keywords-1)))
4976 ((eq arg 'done) org-done-keywords)
4977 ((eq arg 'any)
4978 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4979 (setq todo-re
4980 (concat "^\\*+[ \t]+\\<\\("
4981 (mapconcat 'identity todo-wds "\\|")
4982 "\\)\\>"))
4983 (cond
4984 ((eq kw 'todo) (re-search-forward todo-re end t))
4985 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4986 ((eq kw 'todo-unblocked)
4987 (catch 'unblocked
4988 (while (re-search-forward todo-re end t)
4989 (or (org-entry-blocked-p) (throw 'unblocked t)))
4990 nil))
4991 ((eq kw 'nottodo-unblocked)
4992 (catch 'unblocked
4993 (while (re-search-forward todo-re end t)
4994 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4998 ;;;###autoload
4999 (defun org-agenda-list-stuck-projects (&rest ignore)
5000 "Create agenda view for projects that are stuck.
5001 Stuck projects are project that have no next actions. For the definitions
5002 of what a project is and how to check if it stuck, customize the variable
5003 `org-stuck-projects'."
5004 (interactive)
5005 (let* ((org-agenda-skip-function
5006 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5007 ;; We could have used org-agenda-skip-if here.
5008 (org-agenda-overriding-header
5009 (or org-agenda-overriding-header "List of stuck projects: "))
5010 (matcher (nth 0 org-stuck-projects))
5011 (todo (nth 1 org-stuck-projects))
5012 (todo-wds (if (member "*" todo)
5013 (progn
5014 (org-agenda-prepare-buffers (org-agenda-files
5015 nil 'ifmode))
5016 (org-delete-all
5017 org-done-keywords-for-agenda
5018 (copy-sequence org-todo-keywords-for-agenda)))
5019 todo))
5020 (todo-re (concat "^\\*+[ \t]+\\("
5021 (mapconcat 'identity todo-wds "\\|")
5022 "\\)\\>"))
5023 (tags (nth 2 org-stuck-projects))
5024 (tags-re (if (member "*" tags)
5025 (concat org-outline-regexp-bol
5026 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5027 (if tags
5028 (concat org-outline-regexp-bol
5029 ".*:\\("
5030 (mapconcat 'identity tags "\\|")
5031 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5032 (gen-re (nth 3 org-stuck-projects))
5033 (re-list
5034 (delq nil
5035 (list
5036 (if todo todo-re)
5037 (if tags tags-re)
5038 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5039 gen-re)))))
5040 (setq org-agenda-skip-regexp
5041 (if re-list
5042 (mapconcat 'identity re-list "\\|")
5043 (error "No information how to identify unstuck projects")))
5044 (org-tags-view nil matcher)
5045 (with-current-buffer org-agenda-buffer-name
5046 (setq org-agenda-redo-command
5047 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5049 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
5050 Create agenda view for projects that are stuck.
5051 Stuck projects are project that have no next actions. For the definitions
5052 of what a project is and how to check if it stuck, customize the variable
5053 `org-stuck-projects'.
5055 \(fn &rest IGNORE)" t nil)
5057 ;;; Diary integration
5059 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5060 (defvar diary-list-entries-hook)
5061 (defvar diary-time-regexp)
5062 (defun org-get-entries-from-diary (date)
5063 "Get the (Emacs Calendar) diary entries for DATE."
5064 (require 'diary-lib)
5065 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5066 (diary-display-hook '(fancy-diary-display))
5067 (diary-display-function 'fancy-diary-display)
5068 (pop-up-frames nil)
5069 (diary-list-entries-hook
5070 (cons 'org-diary-default-entry diary-list-entries-hook))
5071 (diary-file-name-prefix nil) ; turn this feature off
5072 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5073 entries
5074 (org-disable-agenda-to-diary t))
5075 (save-excursion
5076 (save-window-excursion
5077 (funcall (if (fboundp 'diary-list-entries)
5078 'diary-list-entries 'list-diary-entries)
5079 date 1)))
5080 (if (not (get-buffer diary-fancy-buffer))
5081 (setq entries nil)
5082 (with-current-buffer diary-fancy-buffer
5083 (setq buffer-read-only nil)
5084 (if (zerop (buffer-size))
5085 ;; No entries
5086 (setq entries nil)
5087 ;; Omit the date and other unnecessary stuff
5088 (org-agenda-cleanup-fancy-diary)
5089 ;; Add prefix to each line and extend the text properties
5090 (if (zerop (buffer-size))
5091 (setq entries nil)
5092 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5093 (setq entries
5094 (with-temp-buffer
5095 (insert entries) (goto-char (point-min))
5096 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5097 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5098 (replace-match (concat "; " (match-string 1)))))
5099 (buffer-string)))))
5100 (set-buffer-modified-p nil)
5101 (kill-buffer diary-fancy-buffer)))
5102 (when entries
5103 (setq entries (org-split-string entries "\n"))
5104 (setq entries
5105 (mapcar
5106 (lambda (x)
5107 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5108 ;; Extend the text properties to the beginning of the line
5109 (org-add-props x (text-properties-at (1- (length x)) x)
5110 'type "diary" 'date date 'face 'org-agenda-diary))
5111 entries)))))
5113 (defvar org-agenda-cleanup-fancy-diary-hook nil
5114 "Hook run when the fancy diary buffer is cleaned up.")
5116 (defun org-agenda-cleanup-fancy-diary ()
5117 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5118 This gets rid of the date, the underline under the date, and
5119 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5120 date. It also removes lines that contain only whitespace."
5121 (goto-char (point-min))
5122 (if (looking-at ".*?:[ \t]*")
5123 (progn
5124 (replace-match "")
5125 (re-search-forward "\n=+$" nil t)
5126 (replace-match "")
5127 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5128 (re-search-forward "\n=+$" nil t)
5129 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5130 (goto-char (point-min))
5131 (while (re-search-forward "^ +\n" nil t)
5132 (replace-match ""))
5133 (goto-char (point-min))
5134 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5135 (replace-match ""))
5136 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5138 ;; Make sure entries from the diary have the right text properties.
5139 (eval-after-load "diary-lib"
5140 '(if (boundp 'diary-modify-entry-list-string-function)
5141 ;; We can rely on the hook, nothing to do
5143 ;; Hook not available, must use advice to make this work
5144 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5145 "Make the position visible."
5146 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5147 (stringp string)
5148 buffer-file-name)
5149 (setq string (org-modify-diary-entry-string string))))))
5151 (defun org-modify-diary-entry-string (string)
5152 "Add text properties to string, allowing org-mode to act on it."
5153 (org-add-props string nil
5154 'mouse-face 'highlight
5155 'help-echo (if buffer-file-name
5156 (format "mouse-2 or RET jump to diary file %s"
5157 (abbreviate-file-name buffer-file-name))
5159 'org-agenda-diary-link t
5160 'org-marker (org-agenda-new-marker (point-at-bol))))
5162 (defun org-diary-default-entry ()
5163 "Add a dummy entry to the diary.
5164 Needed to avoid empty dates which mess up holiday display."
5165 ;; Catch the error if dealing with the new add-to-diary-alist
5166 (when org-disable-agenda-to-diary
5167 (condition-case nil
5168 (org-add-to-diary-list original-date "Org-mode dummy" "")
5169 (error
5170 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5172 (defun org-add-to-diary-list (&rest args)
5173 (if (fboundp 'diary-add-to-list)
5174 (apply 'diary-add-to-list args)
5175 (apply 'add-to-diary-list args)))
5177 (defvar org-diary-last-run-time nil)
5179 ;;;###autoload
5180 (defun org-diary (&rest args)
5181 "Return diary information from org files.
5182 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5183 It accesses org files and extracts information from those files to be
5184 listed in the diary. The function accepts arguments specifying what
5185 items should be listed. For a list of arguments allowed here, see the
5186 variable `org-agenda-entry-types'.
5188 The call in the diary file should look like this:
5190 &%%(org-diary) ~/path/to/some/orgfile.org
5192 Use a separate line for each org file to check. Or, if you omit the file name,
5193 all files listed in `org-agenda-files' will be checked automatically:
5195 &%%(org-diary)
5197 If you don't give any arguments (as in the example above), the default
5198 arguments (:deadline :scheduled :timestamp :sexp) are used.
5199 So the example above may also be written as
5201 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5203 The function expects the lisp variables `entry' and `date' to be provided
5204 by the caller, because this is how the calendar works. Don't use this
5205 function from a program - use `org-agenda-get-day-entries' instead."
5206 (when (> (- (org-float-time)
5207 org-agenda-last-marker-time)
5209 ;; I am not sure if this works with sticky agendas, because the marker
5210 ;; list is then no longer a global variable.
5211 (org-agenda-reset-markers))
5212 (org-compile-prefix-format 'agenda)
5213 (org-set-sorting-strategy 'agenda)
5214 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5215 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5216 (list entry)
5217 (org-agenda-files t)))
5218 (time (org-float-time))
5219 file rtn results)
5220 (when (or (not org-diary-last-run-time)
5221 (> (- time
5222 org-diary-last-run-time)
5224 (org-agenda-prepare-buffers files))
5225 (setq org-diary-last-run-time time)
5226 ;; If this is called during org-agenda, don't return any entries to
5227 ;; the calendar. Org Agenda will list these entries itself.
5228 (if org-disable-agenda-to-diary (setq files nil))
5229 (while (setq file (pop files))
5230 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5231 (setq results (append results rtn)))
5232 (when results
5233 (setq results
5234 (mapcar (lambda (i) (replace-regexp-in-string
5235 org-bracket-link-regexp "\\3" i)) results))
5236 (concat (org-agenda-finalize-entries results) "\n"))))
5238 (autoload 'org-diary "org-agenda" "\
5239 Return diary information from org files.
5240 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5241 It accesses org files and extracts information from those files to be
5242 listed in the diary. The function accepts arguments specifying what
5243 items should be listed. For a list of arguments allowed here, see the
5244 variable `org-agenda-entry-types'.
5246 The call in the diary file should look like this:
5248 &%%(org-diary) ~/path/to/some/orgfile.org
5250 Use a separate line for each org file to check. Or, if you omit the file name,
5251 all files listed in `org-agenda-files' will be checked automatically:
5253 &%%(org-diary)
5255 If you don't give any arguments (as in the example above), the default
5256 arguments (:deadline :scheduled :timestamp :sexp) are used.
5257 So the example above may also be written as
5259 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5261 The function expects the lisp variables `entry' and `date' to be provided
5262 by the caller, because this is how the calendar works. Don't use this
5263 function from a program - use `org-agenda-get-day-entries' instead.
5265 \(fn &rest ARGS)" nil nil)
5267 ;;; Agenda entry finders
5269 (defun org-agenda-get-day-entries (file date &rest args)
5270 "Does the work for `org-diary' and `org-agenda'.
5271 FILE is the path to a file to be checked for entries. DATE is date like
5272 the one returned by `calendar-current-date'. ARGS are symbols indicating
5273 which kind of entries should be extracted. For details about these, see
5274 the documentation of `org-diary'."
5275 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5276 (let* ((org-startup-folded nil)
5277 (org-startup-align-all-tables nil)
5278 (buffer (if (file-exists-p file)
5279 (org-get-agenda-file-buffer file)
5280 (error "No such file %s" file)))
5281 arg results rtn deadline-results)
5282 (if (not buffer)
5283 ;; If file does not exist, make sure an error message ends up in diary
5284 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5285 (with-current-buffer buffer
5286 (unless (derived-mode-p 'org-mode)
5287 (error "Agenda file %s is not in `org-mode'" file))
5288 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5289 (let ((case-fold-search nil))
5290 (save-excursion
5291 (save-restriction
5292 (if org-agenda-restrict
5293 (narrow-to-region org-agenda-restrict-begin
5294 org-agenda-restrict-end)
5295 (widen))
5296 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5297 (while (setq arg (pop args))
5298 (cond
5299 ((and (eq arg :todo)
5300 (equal date (calendar-gregorian-from-absolute
5301 (org-today))))
5302 (setq rtn (org-agenda-get-todos))
5303 (setq results (append results rtn)))
5304 ((eq arg :timestamp)
5305 (setq rtn (org-agenda-get-blocks))
5306 (setq results (append results rtn))
5307 (setq rtn (org-agenda-get-timestamps deadline-results))
5308 (setq results (append results rtn)))
5309 ((eq arg :sexp)
5310 (setq rtn (org-agenda-get-sexps))
5311 (setq results (append results rtn)))
5312 ((eq arg :scheduled)
5313 (setq rtn (org-agenda-get-scheduled deadline-results))
5314 (setq results (append results rtn)))
5315 ((eq arg :closed)
5316 (setq rtn (org-agenda-get-progress))
5317 (setq results (append results rtn)))
5318 ((eq arg :deadline)
5319 (setq rtn (org-agenda-get-deadlines))
5320 (setq deadline-results (copy-sequence rtn))
5321 (setq results (append results rtn))))))))
5322 results))))
5324 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5325 (defun org-agenda-get-todos ()
5326 "Return the TODO information for agenda display."
5327 (let* ((props (list 'face nil
5328 'done-face 'org-agenda-done
5329 'org-not-done-regexp org-not-done-regexp
5330 'org-todo-regexp org-todo-regexp
5331 'org-complex-heading-regexp org-complex-heading-regexp
5332 'mouse-face 'highlight
5333 'help-echo
5334 (format "mouse-2 or RET jump to org file %s"
5335 (abbreviate-file-name buffer-file-name))))
5336 (regexp (format org-heading-keyword-regexp-format
5337 (cond
5338 ((and org-select-this-todo-keyword
5339 (equal org-select-this-todo-keyword "*"))
5340 org-todo-regexp)
5341 (org-select-this-todo-keyword
5342 (concat "\\("
5343 (mapconcat 'identity
5344 (org-split-string
5345 org-select-this-todo-keyword
5346 "|")
5347 "\\|") "\\)"))
5348 (t org-not-done-regexp))))
5349 marker priority category category-pos level tags todo-state
5350 ee txt beg end inherited-tags)
5351 (goto-char (point-min))
5352 (while (re-search-forward regexp nil t)
5353 (catch :skip
5354 (save-match-data
5355 (beginning-of-line)
5356 (org-agenda-skip)
5357 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5358 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5359 (goto-char (1+ beg))
5360 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5361 (throw :skip nil)))
5362 (goto-char (match-beginning 2))
5363 (setq marker (org-agenda-new-marker (match-beginning 0))
5364 category (org-get-category)
5365 category-pos (get-text-property (point) 'org-category-position)
5366 txt (org-trim
5367 (buffer-substring (match-beginning 2) (match-end 0)))
5368 inherited-tags
5369 (or (eq org-agenda-show-inherited-tags 'always)
5370 (and (listp org-agenda-show-inherited-tags)
5371 (memq 'todo org-agenda-show-inherited-tags))
5372 (and (eq org-agenda-show-inherited-tags t)
5373 (or (eq org-agenda-use-tag-inheritance t)
5374 (memq 'todo org-agenda-use-tag-inheritance))))
5375 tags (org-get-tags-at nil (not inherited-tags))
5376 level (make-string (org-reduced-level (org-outline-level)) ? )
5377 txt (org-agenda-format-item "" txt level category tags t)
5378 priority (1+ (org-get-priority txt))
5379 todo-state (org-get-todo-state))
5380 (org-add-props txt props
5381 'org-marker marker 'org-hd-marker marker
5382 'priority priority 'org-category category
5383 'level level
5384 'org-category-position category-pos
5385 'type "todo" 'todo-state todo-state)
5386 (push txt ee)
5387 (if org-agenda-todo-list-sublevels
5388 (goto-char (match-end 2))
5389 (org-end-of-subtree 'invisible))))
5390 (nreverse ee)))
5392 (defun org-agenda-todo-custom-ignore-p (time n)
5393 "Check whether timestamp is farther away than n number of days.
5394 This function is invoked if `org-agenda-todo-ignore-deadlines',
5395 `org-agenda-todo-ignore-scheduled' or
5396 `org-agenda-todo-ignore-timestamp' is set to an integer."
5397 (let ((days (org-time-stamp-to-now
5398 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5399 (if (>= n 0)
5400 (>= days n)
5401 (<= days n))))
5403 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5404 (&optional end)
5405 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5406 (when (or org-agenda-todo-ignore-with-date
5407 org-agenda-todo-ignore-scheduled
5408 org-agenda-todo-ignore-deadlines
5409 org-agenda-todo-ignore-timestamp)
5410 (setq end (or end (save-excursion (outline-next-heading) (point))))
5411 (save-excursion
5412 (or (and org-agenda-todo-ignore-with-date
5413 (re-search-forward org-ts-regexp end t))
5414 (and org-agenda-todo-ignore-scheduled
5415 (re-search-forward org-scheduled-time-regexp end t)
5416 (cond
5417 ((eq org-agenda-todo-ignore-scheduled 'future)
5418 (> (org-time-stamp-to-now
5419 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5420 ((eq org-agenda-todo-ignore-scheduled 'past)
5421 (<= (org-time-stamp-to-now
5422 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5423 ((numberp org-agenda-todo-ignore-scheduled)
5424 (org-agenda-todo-custom-ignore-p
5425 (match-string 1) org-agenda-todo-ignore-scheduled))
5426 (t)))
5427 (and org-agenda-todo-ignore-deadlines
5428 (re-search-forward org-deadline-time-regexp end t)
5429 (cond
5430 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5431 ((eq org-agenda-todo-ignore-deadlines 'far)
5432 (not (org-deadline-close (match-string 1))))
5433 ((eq org-agenda-todo-ignore-deadlines 'future)
5434 (> (org-time-stamp-to-now
5435 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5436 ((eq org-agenda-todo-ignore-deadlines 'past)
5437 (<= (org-time-stamp-to-now
5438 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5439 ((numberp org-agenda-todo-ignore-deadlines)
5440 (org-agenda-todo-custom-ignore-p
5441 (match-string 1) org-agenda-todo-ignore-deadlines))
5442 (t (org-deadline-close (match-string 1)))))
5443 (and org-agenda-todo-ignore-timestamp
5444 (let ((buffer (current-buffer))
5445 (regexp
5446 (concat
5447 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5448 (start (point)))
5449 ;; Copy current buffer into a temporary one
5450 (with-temp-buffer
5451 (insert-buffer-substring buffer start end)
5452 (goto-char (point-min))
5453 ;; Delete SCHEDULED and DEADLINE items
5454 (while (re-search-forward regexp end t)
5455 (delete-region (match-beginning 0) (match-end 0)))
5456 (goto-char (point-min))
5457 ;; No search for timestamp left
5458 (when (re-search-forward org-ts-regexp nil t)
5459 (cond
5460 ((eq org-agenda-todo-ignore-timestamp 'future)
5461 (> (org-time-stamp-to-now
5462 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5463 ((eq org-agenda-todo-ignore-timestamp 'past)
5464 (<= (org-time-stamp-to-now
5465 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5466 ((numberp org-agenda-todo-ignore-timestamp)
5467 (org-agenda-todo-custom-ignore-p
5468 (match-string 1) org-agenda-todo-ignore-timestamp))
5469 (t))))))))))
5471 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5472 Do we have a reason to ignore this TODO entry because it has a time stamp?
5474 \(fn &optional END)" nil nil)
5476 (defun org-agenda-get-timestamps (&optional deadline-results)
5477 "Return the date stamp information for agenda display."
5478 (let* ((props (list 'face 'org-agenda-calendar-event
5479 'org-not-done-regexp org-not-done-regexp
5480 'org-todo-regexp org-todo-regexp
5481 'org-complex-heading-regexp org-complex-heading-regexp
5482 'mouse-face 'highlight
5483 'help-echo
5484 (format "mouse-2 or RET jump to org file %s"
5485 (abbreviate-file-name buffer-file-name))))
5486 (d1 (calendar-absolute-from-gregorian date))
5488 (deadline-position-alist
5489 (mapcar (lambda (a) (and (setq mm (get-text-property
5490 0 'org-hd-marker a))
5491 (cons (marker-position mm) a)))
5492 deadline-results))
5493 (remove-re org-ts-regexp)
5494 (regexp
5495 (concat
5496 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5497 (regexp-quote
5498 (substring
5499 (format-time-string
5500 (car org-time-stamp-formats)
5501 (apply 'encode-time ; DATE bound by calendar
5502 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5503 1 11))
5504 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5505 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5506 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5507 donep tmp priority category category-pos level ee txt timestr tags
5508 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5509 inherited-tags)
5510 (goto-char (point-min))
5511 (while (setq end-of-match (re-search-forward regexp nil t))
5512 (setq b0 (match-beginning 0)
5513 b3 (match-beginning 3) e3 (match-end 3)
5514 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5515 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5516 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5517 (member todo-state
5518 org-agenda-repeating-timestamp-show-all)))
5519 (catch :skip
5520 (and (org-at-date-range-p) (throw :skip nil))
5521 (org-agenda-skip)
5522 (if (and (match-end 1)
5523 (not (= d1 (org-time-string-to-absolute
5524 (match-string 1) d1 nil show-all
5525 (current-buffer) b0))))
5526 (throw :skip nil))
5527 (if (and e3
5528 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5529 (throw :skip nil))
5530 (setq tmp (buffer-substring (max (point-min)
5531 (- b0 org-ds-keyword-length))
5533 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5534 inactivep (= (char-after b0) ?\[)
5535 deadlinep (string-match org-deadline-regexp tmp)
5536 scheduledp (string-match org-scheduled-regexp tmp)
5537 closedp (and org-agenda-include-inactive-timestamps
5538 (string-match org-closed-string tmp))
5539 clockp (and org-agenda-include-inactive-timestamps
5540 (or (string-match org-clock-string tmp)
5541 (string-match "]-+\\'" tmp)))
5542 warntime (get-text-property (point) 'org-appt-warntime)
5543 donep (member todo-state org-done-keywords))
5544 (if (or scheduledp deadlinep closedp clockp
5545 (and donep org-agenda-skip-timestamp-if-done))
5546 (throw :skip t))
5547 (if (string-match ">" timestr)
5548 ;; substring should only run to end of time stamp
5549 (setq timestr (substring timestr 0 (match-end 0))))
5550 (setq marker (org-agenda-new-marker b0)
5551 category (org-get-category b0)
5552 category-pos (get-text-property b0 'org-category-position))
5553 (save-excursion
5554 (if (not (re-search-backward org-outline-regexp-bol nil t))
5555 (throw :skip nil)
5556 (goto-char (match-beginning 0))
5557 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5558 (assoc (point) deadline-position-alist))
5559 (throw :skip nil))
5560 (setq hdmarker (org-agenda-new-marker)
5561 inherited-tags
5562 (or (eq org-agenda-show-inherited-tags 'always)
5563 (and (listp org-agenda-show-inherited-tags)
5564 (memq 'agenda org-agenda-show-inherited-tags))
5565 (and (eq org-agenda-show-inherited-tags t)
5566 (or (eq org-agenda-use-tag-inheritance t)
5567 (memq 'agenda org-agenda-use-tag-inheritance))))
5568 tags (org-get-tags-at nil (not inherited-tags))
5569 level (make-string (org-reduced-level (org-outline-level)) ? ))
5570 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5571 (setq head (or (match-string 1) ""))
5572 (setq txt (org-agenda-format-item
5573 (if inactivep org-agenda-inactive-leader nil)
5574 head level category tags timestr
5575 remove-re habitp)))
5576 (setq priority (org-get-priority txt))
5577 (org-add-props txt props 'priority priority
5578 'org-marker marker 'org-hd-marker hdmarker
5579 'org-category category 'date date
5580 'level level
5581 'org-category-position category-pos
5582 'todo-state todo-state
5583 'warntime warntime
5584 'type "timestamp")
5585 (push txt ee))
5586 (if org-agenda-skip-additional-timestamps-same-entry
5587 (outline-next-heading)
5588 (goto-char end-of-match))))
5589 (nreverse ee)))
5591 (defun org-agenda-get-sexps ()
5592 "Return the sexp information for agenda display."
5593 (require 'diary-lib)
5594 (let* ((props (list 'face 'org-agenda-calendar-sexp
5595 'mouse-face 'highlight
5596 'help-echo
5597 (format "mouse-2 or RET jump to org file %s"
5598 (abbreviate-file-name buffer-file-name))))
5599 (regexp "^&?%%(")
5600 marker category extra category-pos level ee txt tags entry
5601 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5602 (goto-char (point-min))
5603 (while (re-search-forward regexp nil t)
5604 (catch :skip
5605 (org-agenda-skip)
5606 (setq beg (match-beginning 0))
5607 (goto-char (1- (match-end 0)))
5608 (setq b (point))
5609 (forward-sexp 1)
5610 (setq sexp (buffer-substring b (point)))
5611 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5612 (org-trim (match-string 1))
5613 ""))
5614 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5615 (when result
5616 (setq marker (org-agenda-new-marker beg)
5617 level (make-string (org-reduced-level (org-outline-level)) ? )
5618 category (org-get-category beg)
5619 category-pos (get-text-property beg 'org-category-position)
5620 inherited-tags
5621 (or (eq org-agenda-show-inherited-tags 'always)
5622 (and (listp org-agenda-show-inherited-tags)
5623 (memq 'agenda org-agenda-show-inherited-tags))
5624 (and (eq org-agenda-show-inherited-tags t)
5625 (or (eq org-agenda-use-tag-inheritance t)
5626 (memq 'agenda org-agenda-use-tag-inheritance))))
5627 tags (org-get-tags-at nil (not inherited-tags))
5628 todo-state (org-get-todo-state)
5629 warntime (get-text-property (point) 'org-appt-warntime)
5630 extra nil)
5632 (dolist (r (if (stringp result)
5633 (list result)
5634 result)) ;; we expect a list here
5635 (when (and org-agenda-diary-sexp-prefix
5636 (string-match org-agenda-diary-sexp-prefix r))
5637 (setq extra (match-string 0 r)
5638 r (replace-match "" nil nil r)))
5639 (if (string-match "\\S-" r)
5640 (setq txt r)
5641 (setq txt "SEXP entry returned empty string"))
5642 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5643 (org-add-props txt props 'org-marker marker
5644 'org-category category 'date date 'todo-state todo-state
5645 'org-category-position category-pos 'tags tags
5646 'level level
5647 'type "sexp" 'warntime warntime)
5648 (push txt ee)))))
5649 (nreverse ee)))
5651 ;; Calendar sanity: define some functions that are independent of
5652 ;; `calendar-date-style'.
5653 ;; Normally I would like to use ISO format when calling the diary functions,
5654 ;; but to make sure we still have Emacs 22 compatibility we bind
5655 ;; also `european-calendar-style' and use european format
5656 (defun org-anniversary (year month day &optional mark)
5657 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5658 (org-no-warnings
5659 (let ((calendar-date-style 'european) (european-calendar-style t))
5660 (diary-anniversary day month year mark))))
5661 (defun org-cyclic (N year month day &optional mark)
5662 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5663 (org-no-warnings
5664 (let ((calendar-date-style 'european) (european-calendar-style t))
5665 (diary-cyclic N day month year mark))))
5666 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5667 "Like `diary-block', but with fixed (ISO) order of arguments."
5668 (org-no-warnings
5669 (let ((calendar-date-style 'european) (european-calendar-style t))
5670 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5671 (defun org-date (year month day &optional mark)
5672 "Like `diary-date', but with fixed (ISO) order of arguments."
5673 (org-no-warnings
5674 (let ((calendar-date-style 'european) (european-calendar-style t))
5675 (diary-date day month year mark))))
5677 ;; Define the` org-class' function
5678 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5679 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5680 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5681 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5682 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5683 `holidays', then any date that is known by the Emacs calendar to be a
5684 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5685 then those holidays will be skipped."
5686 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5687 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5688 (d (calendar-absolute-from-gregorian date))
5689 (h (when skip-weeks (calendar-check-holidays date))))
5690 (and
5691 (<= date1 d)
5692 (<= d date2)
5693 (= (calendar-day-of-week date) dayname)
5694 (or (not skip-weeks)
5695 (progn
5696 (require 'cal-iso)
5697 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5698 (not (or (and h (memq 'holidays skip-weeks))
5699 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5700 entry)))
5702 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5703 "Like `org-class', but honor `calendar-date-style'.
5704 The order of the first 2 times 3 arguments depends on the variable
5705 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5706 So for American calendars, give this as MONTH DAY YEAR, for European as
5707 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5708 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5709 is any number of ISO weeks in the block period for which the item should
5710 be skipped.
5712 This function is here only for backward compatibility and it is deprecated,
5713 please use `org-class' instead."
5714 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5715 (date2 (org-order-calendar-date-args m2 d2 y2)))
5716 (org-class
5717 (nth 2 date1) (car date1) (nth 1 date1)
5718 (nth 2 date2) (car date2) (nth 1 date2)
5719 dayname skip-weeks)))
5720 (make-obsolete 'org-diary-class 'org-class "")
5722 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5723 (defalias 'org-get-closed 'org-agenda-get-progress)
5724 (defun org-agenda-get-progress ()
5725 "Return the logged TODO entries for agenda display."
5726 (let* ((props (list 'mouse-face 'highlight
5727 'org-not-done-regexp org-not-done-regexp
5728 'org-todo-regexp org-todo-regexp
5729 'org-complex-heading-regexp org-complex-heading-regexp
5730 'help-echo
5731 (format "mouse-2 or RET jump to org file %s"
5732 (abbreviate-file-name buffer-file-name))))
5733 (items (if (consp org-agenda-show-log-scoped)
5734 org-agenda-show-log-scoped
5735 (if (eq org-agenda-show-log-scoped 'clockcheck)
5736 '(clock)
5737 org-agenda-log-mode-items)))
5738 (parts
5739 (delq nil
5740 (list
5741 (if (memq 'closed items) (concat "\\<" org-closed-string))
5742 (if (memq 'clock items) (concat "\\<" org-clock-string))
5743 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5744 (parts-re (if parts (mapconcat 'identity parts "\\|")
5745 (error "`org-agenda-log-mode-items' is empty")))
5746 (regexp (concat
5747 "\\(" parts-re "\\)"
5748 " *\\["
5749 (regexp-quote
5750 (substring
5751 (format-time-string
5752 (car org-time-stamp-formats)
5753 (apply 'encode-time ; DATE bound by calendar
5754 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5755 1 11))))
5756 (org-agenda-search-headline-for-time nil)
5757 marker hdmarker priority category category-pos level tags closedp
5758 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5759 (goto-char (point-min))
5760 (while (re-search-forward regexp nil t)
5761 (catch :skip
5762 (org-agenda-skip)
5763 (setq marker (org-agenda-new-marker (match-beginning 0))
5764 closedp (equal (match-string 1) org-closed-string)
5765 statep (equal (string-to-char (match-string 1)) ?-)
5766 clockp (not (or closedp statep))
5767 state (and statep (match-string 2))
5768 category (org-get-category (match-beginning 0))
5769 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5770 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5771 (when (string-match "\\]" timestr)
5772 ;; substring should only run to end of time stamp
5773 (setq rest (substring timestr (match-end 0))
5774 timestr (substring timestr 0 (match-end 0)))
5775 (if (and (not closedp) (not statep)
5776 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5777 rest))
5778 (progn (setq timestr (concat (substring timestr 0 -1)
5779 "-" (match-string 1 rest) "]"))
5780 (setq clocked (match-string 2 rest)))
5781 (setq clocked "-")))
5782 (save-excursion
5783 (setq extra
5784 (cond
5785 ((not org-agenda-log-mode-add-notes) nil)
5786 (statep
5787 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5788 (match-string 1)))
5789 (clockp
5790 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5791 (match-string 1)))))
5792 (if (not (re-search-backward org-outline-regexp-bol nil t))
5793 (throw :skip nil)
5794 (goto-char (match-beginning 0))
5795 (setq hdmarker (org-agenda-new-marker)
5796 inherited-tags
5797 (or (eq org-agenda-show-inherited-tags 'always)
5798 (and (listp org-agenda-show-inherited-tags)
5799 (memq 'todo org-agenda-show-inherited-tags))
5800 (and (eq org-agenda-show-inherited-tags t)
5801 (or (eq org-agenda-use-tag-inheritance t)
5802 (memq 'todo org-agenda-use-tag-inheritance))))
5803 tags (org-get-tags-at nil (not inherited-tags))
5804 level (make-string (org-reduced-level (org-outline-level)) ? ))
5805 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5806 (setq txt (match-string 1))
5807 (when extra
5808 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5809 (setq txt (concat (substring txt 0 (match-beginning 1))
5810 " - " extra " " (match-string 2 txt)))
5811 (setq txt (concat txt " - " extra))))
5812 (setq txt (org-agenda-format-item
5813 (cond
5814 (closedp "Closed: ")
5815 (statep (concat "State: (" state ")"))
5816 (t (concat "Clocked: (" clocked ")")))
5817 txt level category tags timestr)))
5818 (setq priority 100000)
5819 (org-add-props txt props
5820 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5821 'priority priority 'org-category category
5822 'org-category-position category-pos
5823 'level level
5824 'type "closed" 'date date
5825 'undone-face 'org-warning 'done-face 'org-agenda-done)
5826 (push txt ee))
5827 (goto-char (point-at-eol))))
5828 (nreverse ee)))
5830 (defun org-agenda-show-clocking-issues ()
5831 "Add overlays, showing issues with clocking.
5832 See also the user option `org-agenda-clock-consistency-checks'."
5833 (interactive)
5834 (let* ((org-time-clocksum-use-effort-durations nil)
5835 (pl org-agenda-clock-consistency-checks)
5836 (re (concat "^[ \t]*"
5837 org-clock-string
5838 "[ \t]+"
5839 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5840 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5841 (tlstart 0.)
5842 (tlend 0.)
5843 (maxtime (org-hh:mm-string-to-minutes
5844 (or (plist-get pl :max-duration) "24:00")))
5845 (mintime (org-hh:mm-string-to-minutes
5846 (or (plist-get pl :min-duration) 0)))
5847 (maxgap (org-hh:mm-string-to-minutes
5848 ;; default 30:00 means never complain
5849 (or (plist-get pl :max-gap) "30:00")))
5850 (gapok (mapcar 'org-hh:mm-string-to-minutes
5851 (plist-get pl :gap-ok-around)))
5852 (def-face (or (plist-get pl :default-face)
5853 '((:background "DarkRed") (:foreground "white"))))
5854 issue face m te ts dt ov)
5855 (goto-char (point-min))
5856 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5857 (setq issue nil face def-face)
5858 (catch 'next
5859 (setq m (org-get-at-bol 'org-marker)
5860 te nil ts nil)
5861 (unless (and m (markerp m))
5862 (setq issue "No valid clock line") (throw 'next t))
5863 (org-with-point-at m
5864 (save-excursion
5865 (goto-char (point-at-bol))
5866 (unless (looking-at re)
5867 (error "No valid Clock line")
5868 (throw 'next t))
5869 (unless (match-end 3)
5870 (setq issue "No end time"
5871 face (or (plist-get pl :no-end-time-face) face))
5872 (throw 'next t))
5873 (setq ts (match-string 1)
5874 te (match-string 3)
5875 ts (org-float-time
5876 (apply 'encode-time (org-parse-time-string ts)))
5877 te (org-float-time
5878 (apply 'encode-time (org-parse-time-string te)))
5879 dt (- te ts))))
5880 (cond
5881 ((> dt (* 60 maxtime))
5882 ;; a very long clocking chunk
5883 (setq issue (format "Clocking interval is very long: %s"
5884 (org-minutes-to-clocksum-string
5885 (floor (/ (float dt) 60.))))
5886 face (or (plist-get pl :long-face) face)))
5887 ((< dt (* 60 mintime))
5888 ;; a very short clocking chunk
5889 (setq issue (format "Clocking interval is very short: %s"
5890 (org-minutes-to-clocksum-string
5891 (floor (/ (float dt) 60.))))
5892 face (or (plist-get pl :short-face) face)))
5893 ((and (> tlend 0) (< ts tlend))
5894 ;; Two clock entries are overlapping
5895 (setq issue (format "Clocking overlap: %d minutes"
5896 (/ (- tlend ts) 60))
5897 face (or (plist-get pl :overlap-face) face)))
5898 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5899 ;; There is a gap, lets see if we need to report it
5900 (unless (org-agenda-check-clock-gap tlend ts gapok)
5901 (setq issue (format "Clocking gap: %d minutes"
5902 (/ (- ts tlend) 60))
5903 face (or (plist-get pl :gap-face) face))))
5904 (t nil)))
5905 (setq tlend (or te tlend) tlstart (or ts tlstart))
5906 (when issue
5907 ;; OK, there was some issue, add an overlay to show the issue
5908 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5909 (overlay-put ov 'before-string
5910 (concat
5911 (org-add-props
5912 (format "%-43s" (concat " " issue))
5914 'face face)
5915 "\n"))
5916 (overlay-put ov 'evaporate t)))))
5918 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5919 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5920 (catch 'exit
5921 (unless ok-list
5922 ;; there are no OK times for gaps...
5923 (throw 'exit nil))
5924 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5925 ;; This is more than 24 hours, so it is OK.
5926 ;; because we have at least one OK time, that must be in the
5927 ;; 24 hour interval.
5928 (throw 'exit t))
5929 ;; We have a shorter gap.
5930 ;; Now we have to get the minute of the day when these times are
5931 (let* ((t1dec (decode-time (seconds-to-time t1)))
5932 (t2dec (decode-time (seconds-to-time t2)))
5933 ;; compute the minute on the day
5934 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5935 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5936 (when (< min2 min1)
5937 ;; if min2 is smaller than min1, this means it is on the next day.
5938 ;; Wrap it to after midnight.
5939 (setq min2 (+ min2 1440)))
5940 ;; Now check if any of the OK times is in the gap
5941 (mapc (lambda (x)
5942 ;; Wrap the time to after midnight if necessary
5943 (if (< x min1) (setq x (+ x 1440)))
5944 ;; Check if in interval
5945 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5946 ok-list)
5947 ;; Nope, this gap is not OK
5948 nil)))
5950 (defun org-agenda-get-deadlines ()
5951 "Return the deadline information for agenda display."
5952 (let* ((props (list 'mouse-face 'highlight
5953 'org-not-done-regexp org-not-done-regexp
5954 'org-todo-regexp org-todo-regexp
5955 'org-complex-heading-regexp org-complex-heading-regexp
5956 'help-echo
5957 (format "mouse-2 or RET jump to org file %s"
5958 (abbreviate-file-name buffer-file-name))))
5959 (regexp org-deadline-time-regexp)
5960 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5961 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5962 d2 diff dfrac wdays pos pos1 category category-pos level
5963 tags suppress-prewarning ee txt head face s todo-state
5964 show-all upcomingp donep timestr warntime inherited-tags)
5965 (goto-char (point-min))
5966 (while (re-search-forward regexp nil t)
5967 (catch :skip
5968 (org-agenda-skip)
5969 (setq s (match-string 1)
5970 txt nil
5971 pos (1- (match-beginning 1))
5972 todo-state (save-match-data (org-get-todo-state))
5973 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5974 (member todo-state
5975 org-agenda-repeating-timestamp-show-all))
5976 d2 (org-time-string-to-absolute
5977 (match-string 1) d1 'past show-all
5978 (current-buffer) pos)
5979 diff (- d2 d1))
5980 (setq suppress-prewarning
5981 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5982 (let ((item (buffer-substring (point-at-bol)
5983 (point-at-eol))))
5984 (save-match-data
5985 (and (string-match
5986 org-scheduled-time-regexp item)
5987 (match-string 1 item)))))))
5988 (cond
5989 ((not ds) nil)
5990 ;; The current item has a scheduled date (in ds), so
5991 ;; evaluate its prewarning lead time.
5992 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5993 ;; Use global prewarning-restart lead time.
5994 org-agenda-skip-deadline-prewarning-if-scheduled)
5995 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5996 'pre-scheduled)
5997 ;; Set prewarning to no earlier than scheduled.
5998 (min (- d2 (org-time-string-to-absolute
5999 ds d1 'past show-all (current-buffer) pos))
6000 org-deadline-warning-days))
6001 ;; Set prewarning to deadline.
6002 (t 0))))
6003 (setq wdays (if suppress-prewarning
6004 (let ((org-deadline-warning-days suppress-prewarning))
6005 (org-get-wdays s))
6006 (org-get-wdays s))
6007 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
6008 upcomingp (and todayp (> diff 0)))
6009 ;; When to show a deadline in the calendar:
6010 ;; If the expiration is within wdays warning time.
6011 ;; Past-due deadlines are only shown on the current date
6012 (if (and (or (and (<= diff wdays)
6013 (and todayp (not org-agenda-only-exact-dates)))
6014 (= diff 0)))
6015 (save-excursion
6016 ;; (setq todo-state (org-get-todo-state))
6017 (setq donep (member todo-state org-done-keywords))
6018 (if (and donep
6019 (or org-agenda-skip-deadline-if-done
6020 (not (= diff 0))))
6021 (setq txt nil)
6022 (setq category (org-get-category)
6023 warntime (get-text-property (point) 'org-appt-warntime)
6024 category-pos (get-text-property (point) 'org-category-position))
6025 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6026 (throw :skip nil)
6027 (goto-char (match-end 0))
6028 (setq pos1 (match-beginning 0))
6029 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6030 (setq inherited-tags
6031 (or (eq org-agenda-show-inherited-tags 'always)
6032 (and (listp org-agenda-show-inherited-tags)
6033 (memq 'agenda org-agenda-show-inherited-tags))
6034 (and (eq org-agenda-show-inherited-tags t)
6035 (or (eq org-agenda-use-tag-inheritance t)
6036 (memq 'agenda org-agenda-use-tag-inheritance))))
6037 tags (org-get-tags-at pos1 (not inherited-tags)))
6038 (setq head (buffer-substring-no-properties
6039 (point)
6040 (progn (skip-chars-forward "^\r\n")
6041 (point))))
6042 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6043 (setq timestr
6044 (concat (substring s (match-beginning 1)) " "))
6045 (setq timestr 'time))
6046 (setq txt (org-agenda-format-item
6047 (if (= diff 0)
6048 (car org-agenda-deadline-leaders)
6049 (if (functionp
6050 (nth 1 org-agenda-deadline-leaders))
6051 (funcall
6052 (nth 1 org-agenda-deadline-leaders)
6053 diff date)
6054 (format (nth 1 org-agenda-deadline-leaders)
6055 diff)))
6056 head level category tags
6057 (if (not (= diff 0)) nil timestr)))))
6058 (when txt
6059 (setq face (org-agenda-deadline-face dfrac))
6060 (org-add-props txt props
6061 'org-marker (org-agenda-new-marker pos)
6062 'warntime warntime
6063 'level level
6064 'org-hd-marker (org-agenda-new-marker pos1)
6065 'priority (+ (- diff)
6066 (org-get-priority txt))
6067 'org-category category
6068 'org-category-position category-pos
6069 'todo-state todo-state
6070 'type (if upcomingp "upcoming-deadline" "deadline")
6071 'date (if upcomingp date d2)
6072 'face (if donep 'org-agenda-done face)
6073 'undone-face face 'done-face 'org-agenda-done)
6074 (push txt ee))))))
6075 (nreverse ee)))
6077 (defun org-agenda-deadline-face (fraction)
6078 "Return the face to displaying a deadline item.
6079 FRACTION is what fraction of the head-warning time has passed."
6080 (let ((faces org-agenda-deadline-faces) f)
6081 (catch 'exit
6082 (while (setq f (pop faces))
6083 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6085 (defun org-agenda-get-scheduled (&optional deadline-results)
6086 "Return the scheduled information for agenda display."
6087 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6088 'org-todo-regexp org-todo-regexp
6089 'org-complex-heading-regexp org-complex-heading-regexp
6090 'done-face 'org-agenda-done
6091 'mouse-face 'highlight
6092 'help-echo
6093 (format "mouse-2 or RET jump to org file %s"
6094 (abbreviate-file-name buffer-file-name))))
6095 (regexp org-scheduled-time-regexp)
6096 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6097 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6099 (deadline-position-alist
6100 (mapcar (lambda (a) (and (setq mm (get-text-property
6101 0 'org-hd-marker a))
6102 (cons (marker-position mm) a)))
6103 deadline-results))
6104 d2 diff pos pos1 category category-pos level tags donep
6105 ee txt head pastschedp todo-state face timestr s habitp show-all
6106 did-habit-check-p warntime inherited-tags)
6107 (goto-char (point-min))
6108 (while (re-search-forward regexp nil t)
6109 (catch :skip
6110 (org-agenda-skip)
6111 (setq s (match-string 1)
6112 txt nil
6113 pos (1- (match-beginning 1))
6114 todo-state (save-match-data (org-get-todo-state))
6115 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6116 (member todo-state
6117 org-agenda-repeating-timestamp-show-all))
6118 d2 (org-time-string-to-absolute
6119 (match-string 1) d1 'past show-all
6120 (current-buffer) pos)
6121 diff (- d2 d1)
6122 warntime (get-text-property (point) 'org-appt-warntime))
6123 (setq pastschedp (and todayp (< diff 0)))
6124 (setq did-habit-check-p nil)
6125 ;; When to show a scheduled item in the calendar:
6126 ;; If it is on or past the date.
6127 (when (or (and (< diff 0)
6128 (< (abs diff) org-scheduled-past-days)
6129 (and todayp (not org-agenda-only-exact-dates)))
6130 (= diff 0)
6131 ;; org-is-habit-p uses org-entry-get, which is expansive
6132 ;; so we go extra mile to only call it once
6133 (and todayp
6134 (boundp 'org-habit-show-all-today)
6135 org-habit-show-all-today
6136 (setq did-habit-check-p t)
6137 (setq habitp (and (functionp 'org-is-habit-p)
6138 (org-is-habit-p)))))
6139 (save-excursion
6140 (setq donep (member todo-state org-done-keywords))
6141 (if (and donep
6142 (or org-agenda-skip-scheduled-if-done
6143 (not (= diff 0))
6144 (and (functionp 'org-is-habit-p)
6145 (org-is-habit-p))))
6146 (setq txt nil)
6147 (setq habitp (if did-habit-check-p habitp
6148 (and (functionp 'org-is-habit-p)
6149 (org-is-habit-p))))
6150 (setq category (org-get-category)
6151 category-pos (get-text-property (point) 'org-category-position))
6152 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6153 (throw :skip nil)
6154 (goto-char (match-end 0))
6155 (setq pos1 (match-beginning 0))
6156 (if habitp
6157 (if (or (not org-habit-show-habits)
6158 (and (not todayp)
6159 (boundp 'org-habit-show-habits-only-for-today)
6160 org-habit-show-habits-only-for-today))
6161 (throw :skip nil))
6162 (if (and
6163 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6164 (and org-agenda-skip-scheduled-if-deadline-is-shown
6165 pastschedp))
6166 (setq mm (assoc pos1 deadline-position-alist)))
6167 (throw :skip nil)))
6168 (setq inherited-tags
6169 (or (eq org-agenda-show-inherited-tags 'always)
6170 (and (listp org-agenda-show-inherited-tags)
6171 (memq 'agenda org-agenda-show-inherited-tags))
6172 (and (eq org-agenda-show-inherited-tags t)
6173 (or (eq org-agenda-use-tag-inheritance t)
6174 (memq 'agenda org-agenda-use-tag-inheritance))))
6176 tags (org-get-tags-at nil (not inherited-tags)))
6177 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6178 (setq head (buffer-substring-no-properties
6179 (point)
6180 (progn (skip-chars-forward "^\r\n") (point))))
6181 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6182 (setq timestr
6183 (concat (substring s (match-beginning 1)) " "))
6184 (setq timestr 'time))
6185 (setq txt (org-agenda-format-item
6186 (if (= diff 0)
6187 (car org-agenda-scheduled-leaders)
6188 (format (nth 1 org-agenda-scheduled-leaders)
6189 (- 1 diff)))
6190 head level category tags
6191 (if (not (= diff 0)) nil timestr)
6192 nil habitp))))
6193 (when txt
6194 (setq face
6195 (cond
6196 ((and (not habitp) pastschedp)
6197 'org-scheduled-previously)
6198 (todayp 'org-scheduled-today)
6199 (t 'org-scheduled))
6200 habitp (and habitp (org-habit-parse-todo)))
6201 (org-add-props txt props
6202 'undone-face face
6203 'face (if donep 'org-agenda-done face)
6204 'org-marker (org-agenda-new-marker pos)
6205 'org-hd-marker (org-agenda-new-marker pos1)
6206 'type (if pastschedp "past-scheduled" "scheduled")
6207 'date (if pastschedp d2 date)
6208 'warntime warntime
6209 'level level
6210 'priority (if habitp
6211 (org-habit-get-priority habitp)
6212 (+ 94 (- 5 diff) (org-get-priority txt)))
6213 'org-category category
6214 'category-position category-pos
6215 'org-habit-p habitp
6216 'todo-state todo-state)
6217 (push txt ee))))))
6218 (nreverse ee)))
6220 (defun org-agenda-get-blocks ()
6221 "Return the date-range information for agenda display."
6222 (let* ((props (list 'face nil
6223 'org-not-done-regexp org-not-done-regexp
6224 'org-todo-regexp org-todo-regexp
6225 'org-complex-heading-regexp org-complex-heading-regexp
6226 'mouse-face 'highlight
6227 'help-echo
6228 (format "mouse-2 or RET jump to org file %s"
6229 (abbreviate-file-name buffer-file-name))))
6230 (regexp org-tr-regexp)
6231 (d0 (calendar-absolute-from-gregorian date))
6232 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6233 level todo-state tags pos head donep inherited-tags)
6234 (goto-char (point-min))
6235 (while (re-search-forward regexp nil t)
6236 (catch :skip
6237 (org-agenda-skip)
6238 (setq pos (point))
6239 (let ((start-time (match-string 1))
6240 (end-time (match-string 2)))
6241 (setq s1 (match-string 1)
6242 s2 (match-string 2)
6243 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6244 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6245 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6246 ;; Only allow days between the limits, because the normal
6247 ;; date stamps will catch the limits.
6248 (save-excursion
6249 (setq todo-state (org-get-todo-state))
6250 (setq donep (member todo-state org-done-keywords))
6251 (if (and donep org-agenda-skip-timestamp-if-done)
6252 (throw :skip t))
6253 (setq marker (org-agenda-new-marker (point)))
6254 (setq category (org-get-category)
6255 category-pos (get-text-property (point) 'org-category-position))
6256 (if (not (re-search-backward org-outline-regexp-bol nil t))
6257 (throw :skip nil)
6258 (goto-char (match-beginning 0))
6259 (setq hdmarker (org-agenda-new-marker (point))
6260 inherited-tags
6261 (or (eq org-agenda-show-inherited-tags 'always)
6262 (and (listp org-agenda-show-inherited-tags)
6263 (memq 'agenda org-agenda-show-inherited-tags))
6264 (and (eq org-agenda-show-inherited-tags t)
6265 (or (eq org-agenda-use-tag-inheritance t)
6266 (memq 'agenda org-agenda-use-tag-inheritance))))
6268 tags (org-get-tags-at nil (not inherited-tags)))
6269 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6270 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6271 (setq head (match-string 1))
6272 (let ((remove-re
6273 (if org-agenda-remove-timeranges-from-blocks
6274 (concat
6275 "<" (regexp-quote s1) ".*?>"
6276 "--"
6277 "<" (regexp-quote s2) ".*?>")
6278 nil)))
6279 (setq txt (org-agenda-format-item
6280 (format
6281 (nth (if (= d1 d2) 0 1)
6282 org-agenda-timerange-leaders)
6283 (1+ (- d0 d1)) (1+ (- d2 d1)))
6284 head level category tags
6285 (cond ((and (= d1 d0) (= d2 d0))
6286 (concat "<" start-time ">--<" end-time ">"))
6287 ((= d1 d0)
6288 (concat "<" start-time ">"))
6289 ((= d2 d0)
6290 (concat "<" end-time ">")))
6291 remove-re))))
6292 (org-add-props txt props
6293 'org-marker marker 'org-hd-marker hdmarker
6294 'type "block" 'date date
6295 'level level
6296 'todo-state todo-state
6297 'priority (org-get-priority txt) 'org-category category
6298 'org-category-position category-pos)
6299 (push txt ee))))
6300 (goto-char pos)))
6301 ;; Sort the entries by expiration date.
6302 (nreverse ee)))
6304 ;;; Agenda presentation and sorting
6306 (defvar org-prefix-has-time nil
6307 "A flag, set by `org-compile-prefix-format'.
6308 The flag is set if the currently compiled format contains a `%t'.")
6309 (defvar org-prefix-has-tag nil
6310 "A flag, set by `org-compile-prefix-format'.
6311 The flag is set if the currently compiled format contains a `%T'.")
6312 (defvar org-prefix-has-effort nil
6313 "A flag, set by `org-compile-prefix-format'.
6314 The flag is set if the currently compiled format contains a `%e'.")
6315 (defvar org-prefix-category-length nil
6316 "Used by `org-compile-prefix-format' to remember the category field width.")
6317 (defvar org-prefix-category-max-length nil
6318 "Used by `org-compile-prefix-format' to remember the category field width.")
6320 (defun org-agenda-get-category-icon (category)
6321 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6322 (dolist (entry org-agenda-category-icon-alist)
6323 (when (org-string-match-p (car entry) category)
6324 (if (listp (cadr entry))
6325 (return (cadr entry))
6326 (return (apply 'create-image (cdr entry)))))))
6328 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6329 remove-re habitp)
6330 "Format TXT to be inserted into the agenda buffer.
6331 In particular, add the prefix and corresponding text properties.
6333 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6334 LEVEL may be a string to replace the `%l' specifier.
6335 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6336 category taken from local variable or file name. It will replace the `%c'
6337 specifier in the format.
6338 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6339 TXT for sorting of this entry, and for the `%t' specifier in the format.
6340 When DOTIME is a string, this string is searched for a time before TXT is.
6341 TAGS can be the tags of the headline.
6342 Any match of REMOVE-RE will be removed from TXT."
6343 ;; We keep the org-prefix-* variable values along with a compiled
6344 ;; formatter, so that multiple agendas existing at the same time do
6345 ;; not step on each other toes.
6347 ;; It was inconvenient to make these variables buffer local in
6348 ;; Agenda buffers, because this function expects to be called with
6349 ;; the buffer where item comes from being current, and not agenda
6350 ;; buffer
6351 (let* ((bindings (car org-prefix-format-compiled))
6352 (formatter (cadr org-prefix-format-compiled)))
6353 (loop for (var value) in bindings
6354 do (set var value))
6355 (save-match-data
6356 ;; Diary entries sometimes have extra whitespace at the beginning
6357 (setq txt (org-trim txt))
6359 ;; Fix the tags part in txt
6360 (setq txt (org-agenda-fix-displayed-tags
6361 txt tags
6362 org-agenda-show-inherited-tags
6363 org-agenda-hide-tags-regexp))
6365 (let* ((category (or category
6366 (if (stringp org-category)
6367 org-category
6368 (and org-category (symbol-name org-category)))
6369 (if buffer-file-name
6370 (file-name-sans-extension
6371 (file-name-nondirectory buffer-file-name))
6372 "")))
6373 (category-icon (org-agenda-get-category-icon category))
6374 (category-icon (if category-icon
6375 (propertize " " 'display category-icon)
6376 ""))
6377 ;; time, tag, effort are needed for the eval of the prefix format
6378 (tag (if tags (nth (1- (length tags)) tags) ""))
6379 time effort neffort
6380 (ts (if dotime (concat
6381 (if (stringp dotime) dotime "")
6382 (and org-agenda-search-headline-for-time txt))))
6383 (time-of-day (and dotime (org-get-time-of-day ts)))
6384 stamp plain s0 s1 s2 rtn srp l
6385 duration thecategory)
6386 (and (derived-mode-p 'org-mode) buffer-file-name
6387 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6388 (when (and dotime time-of-day)
6389 ;; Extract starting and ending time and move them to prefix
6390 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6391 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6392 (setq s0 (match-string 0 ts)
6393 srp (and stamp (match-end 3))
6394 s1 (match-string (if plain 1 2) ts)
6395 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6397 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6398 ;; them, we might want to remove them there to avoid duplication.
6399 ;; The user can turn this off with a variable.
6400 (if (and org-prefix-has-time
6401 org-agenda-remove-times-when-in-prefix (or stamp plain)
6402 (string-match (concat (regexp-quote s0) " *") txt)
6403 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6404 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6405 (= (match-beginning 0) 0)
6407 (setq txt (replace-match "" nil nil txt))))
6408 ;; Normalize the time(s) to 24 hour
6409 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6410 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6412 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6413 (let (org-time-clocksum-use-effort-durations)
6414 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6415 (setq s2
6416 (org-minutes-to-clocksum-string
6417 (+ (org-hh:mm-string-to-minutes s1)
6418 org-agenda-default-appointment-duration)))))
6420 ;; Compute the duration
6421 (when s2
6422 (setq duration (- (org-hh:mm-string-to-minutes s2)
6423 (org-hh:mm-string-to-minutes s1)))))
6425 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6426 txt)
6427 ;; Tags are in the string
6428 (if (or (eq org-agenda-remove-tags t)
6429 (and org-agenda-remove-tags
6430 org-prefix-has-tag))
6431 (setq txt (replace-match "" t t txt))
6432 (setq txt (replace-match
6433 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6434 (match-string 2 txt))
6435 t t txt))))
6436 (when (derived-mode-p 'org-mode)
6437 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6438 (when effort
6439 (setq neffort (org-duration-string-to-minutes effort)
6440 effort (setq effort (concat "[" effort "]")))))
6441 ;; prevent erroring out with %e format when there is no effort
6442 (or effort (setq effort ""))
6444 (when remove-re
6445 (while (string-match remove-re txt)
6446 (setq txt (replace-match "" t t txt))))
6448 ;; Set org-heading property on `txt' to mark the start of the
6449 ;; heading.
6450 (add-text-properties 0 (length txt) '(org-heading t) txt)
6452 ;; Prepare the variables needed in the eval of the compiled format
6453 (setq time (cond (s2 (concat
6454 (org-agenda-time-of-day-to-ampm-maybe s1)
6455 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6456 (if org-agenda-timegrid-use-ampm " ")))
6457 (s1 (concat
6458 (org-agenda-time-of-day-to-ampm-maybe s1)
6459 (if org-agenda-timegrid-use-ampm
6460 "........ "
6461 "......")))
6462 (t ""))
6463 extra (or (and (not habitp) extra) "")
6464 category (if (symbolp category) (symbol-name category) category)
6465 thecategory (copy-sequence category)
6466 level (or level ""))
6467 (if (string-match org-bracket-link-regexp category)
6468 (progn
6469 (setq l (if (match-end 3)
6470 (- (match-end 3) (match-beginning 3))
6471 (- (match-end 1) (match-beginning 1))))
6472 (when (< l (or org-prefix-category-length 0))
6473 (setq category (copy-sequence category))
6474 (org-add-props category nil
6475 'extra-space (make-string
6476 (- org-prefix-category-length l 1) ?\ ))))
6477 (if (and org-prefix-category-max-length
6478 (>= (length category) org-prefix-category-max-length))
6479 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6480 ;; Evaluate the compiled format
6481 (setq rtn (concat (eval formatter) txt))
6483 ;; And finally add the text properties
6484 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6485 (org-add-props rtn nil
6486 'org-category (if thecategory (downcase thecategory) category)
6487 'tags (mapcar 'org-downcase-keep-props tags)
6488 'org-highest-priority org-highest-priority
6489 'org-lowest-priority org-lowest-priority
6490 'time-of-day time-of-day
6491 'duration duration
6492 'effort effort
6493 'effort-minutes neffort
6494 'txt txt
6495 'level level
6496 'time time
6497 'extra extra
6498 'format org-prefix-format-compiled
6499 'dotime dotime)))))
6501 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6502 "Remove tags string from TXT, and add a modified list of tags.
6503 The modified list may contain inherited tags, and tags matched by
6504 `org-agenda-hide-tags-regexp' will be removed."
6505 (when (or add-inherited hide-re)
6506 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6507 (setq txt (substring txt 0 (match-beginning 0))))
6508 (setq tags
6509 (delq nil
6510 (mapcar (lambda (tg)
6511 (if (or (and hide-re (string-match hide-re tg))
6512 (and (not add-inherited)
6513 (get-text-property 0 'inherited tg)))
6515 tg))
6516 tags)))
6517 (when tags
6518 (let ((have-i (get-text-property 0 'inherited (car tags)))
6520 (setq txt (concat txt " :"
6521 (mapconcat
6522 (lambda (x)
6523 (setq i (get-text-property 0 'inherited x))
6524 (if (and have-i (not i))
6525 (progn
6526 (setq have-i nil)
6527 (concat ":" x))
6529 tags ":")
6530 (if have-i "::" ":"))))))
6531 txt)
6533 (defun org-downcase-keep-props (s)
6534 (let ((props (text-properties-at 0 s)))
6535 (setq s (downcase s))
6536 (add-text-properties 0 (length s) props s)
6539 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6540 (defvar org-agenda-sorting-strategy-selected nil)
6542 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6543 "Add a time-grid for agenda items which need it.
6545 LIST is the list of agenda items formatted by `org-agenda-list'.
6546 NDAYS is the span of the current agenda view.
6547 TODAYP is `t' when the current agenda view is on today."
6548 (catch 'exit
6549 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6550 ((and todayp (member 'today (car org-agenda-time-grid))))
6551 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6552 ((member 'weekly (car org-agenda-time-grid)))
6553 (t (throw 'exit list)))
6554 (let* ((have (delq nil (mapcar
6555 (lambda (x) (get-text-property 1 'time-of-day x))
6556 list)))
6557 (string (nth 1 org-agenda-time-grid))
6558 (gridtimes (nth 2 org-agenda-time-grid))
6559 (req (car org-agenda-time-grid))
6560 (remove (member 'remove-match req))
6561 new time)
6562 (if (and (member 'require-timed req) (not have))
6563 ;; don't show empty grid
6564 (throw 'exit list))
6565 (while (setq time (pop gridtimes))
6566 (unless (and remove (member time have))
6567 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6568 (push (org-agenda-format-item
6569 nil string nil "" nil
6570 (concat (substring time 0 -2) ":" (substring time -2)))
6571 new)
6572 (put-text-property
6573 2 (length (car new)) 'face 'org-time-grid (car new))))
6574 (when (and todayp org-agenda-show-current-time-in-grid)
6575 (push (org-agenda-format-item
6576 nil org-agenda-current-time-string nil "" nil
6577 (format-time-string "%H:%M "))
6578 new)
6579 (put-text-property
6580 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6582 (if (member 'time-up org-agenda-sorting-strategy-selected)
6583 (append new list)
6584 (append list new)))))
6586 (defun org-compile-prefix-format (key)
6587 "Compile the prefix format into a Lisp form that can be evaluated.
6588 The resulting form and associated variable bindings is returned
6589 and stored in the variable `org-prefix-format-compiled'."
6590 (setq org-prefix-has-time nil
6591 org-prefix-has-tag nil
6592 org-prefix-category-length nil
6593 org-prefix-has-effort nil)
6594 (let ((s (cond
6595 ((stringp org-agenda-prefix-format)
6596 org-agenda-prefix-format)
6597 ((assq key org-agenda-prefix-format)
6598 (cdr (assq key org-agenda-prefix-format)))
6599 (t " %-12:c%?-12t% s")))
6600 (start 0)
6601 varform vars var e c f opt)
6602 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6603 s start)
6604 (setq var (or (cdr (assoc (match-string 4 s)
6605 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6606 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6607 'eval)
6608 c (or (match-string 3 s) "")
6609 opt (match-beginning 1)
6610 start (1+ (match-beginning 0)))
6611 (if (equal var 'time) (setq org-prefix-has-time t))
6612 (if (equal var 'tag) (setq org-prefix-has-tag t))
6613 (if (equal var 'effort) (setq org-prefix-has-effort t))
6614 (setq f (concat "%" (match-string 2 s) "s"))
6615 (when (equal var 'category)
6616 (setq org-prefix-category-length
6617 (floor (abs (string-to-number (match-string 2 s)))))
6618 (setq org-prefix-category-max-length
6619 (let ((x (match-string 2 s)))
6620 (save-match-data
6621 (if (string-match "\\.[0-9]+" x)
6622 (string-to-number (substring (match-string 0 x) 1)))))))
6623 (if (eq var 'eval)
6624 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6625 (if opt
6626 (setq varform
6627 `(if (equal "" ,var)
6629 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6630 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6631 (setq s (replace-match "%s" t nil s))
6632 (push varform vars))
6633 (setq vars (nreverse vars))
6634 (with-current-buffer (or org-agenda-buffer (current-buffer))
6635 (setq org-prefix-format-compiled
6636 (list
6637 `((org-prefix-has-time ,org-prefix-has-time)
6638 (org-prefix-has-tag ,org-prefix-has-tag)
6639 (org-prefix-category-length ,org-prefix-category-length)
6640 (org-prefix-has-effort ,org-prefix-has-effort))
6641 `(format ,s ,@vars))))))
6643 (defun org-set-sorting-strategy (key)
6644 (if (symbolp (car org-agenda-sorting-strategy))
6645 ;; the old format
6646 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6647 (setq org-agenda-sorting-strategy-selected
6648 (or (cdr (assq key org-agenda-sorting-strategy))
6649 (cdr (assq 'agenda org-agenda-sorting-strategy))
6650 '(time-up category-keep priority-down)))))
6652 (defun org-get-time-of-day (s &optional string mod24)
6653 "Check string S for a time of day.
6654 If found, return it as a military time number between 0 and 2400.
6655 If not found, return nil.
6656 The optional STRING argument forces conversion into a 5 character wide string
6657 HH:MM."
6658 (save-match-data
6659 (when
6660 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6661 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6662 (let* ((h (string-to-number (match-string 1 s)))
6663 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6664 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6665 (am-p (equal ampm "am"))
6666 (h1 (cond ((not ampm) h)
6667 ((= h 12) (if am-p 0 12))
6668 (t (+ h (if am-p 0 12)))))
6669 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6670 (mod h1 24) h1))
6671 (t0 (+ (* 100 h2) m))
6672 (t1 (concat (if (>= h1 24) "+" " ")
6673 (if (and org-agenda-time-leading-zero
6674 (< t0 1000)) "0" "")
6675 (if (< t0 100) "0" "")
6676 (if (< t0 10) "0" "")
6677 (int-to-string t0))))
6678 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6680 (defvar org-agenda-before-sorting-filter-function nil
6681 "Function to be applied to agenda items prior to sorting.
6682 Prior to sorting also means just before they are inserted into the agenda.
6684 To aid sorting, you may revisit the original entries and add more text
6685 properties which will later be used by the sorting functions.
6687 The function should take a string argument, an agenda line.
6688 It has access to the text properties in that line, which contain among
6689 other things, the property `org-hd-marker' that points to the entry
6690 where the line comes from. Note that not all lines going into the agenda
6691 have this property, only most.
6693 The function should return the modified string. It is probably best
6694 to ONLY change text properties.
6696 You can also use this function as a filter, by returning nil for lines
6697 you don't want to have in the agenda at all. For this application, you
6698 could bind the variable in the options section of a custom command.")
6700 (defun org-agenda-finalize-entries (list &optional nosort)
6701 "Sort and concatenate the agenda items."
6702 (setq list (mapcar 'org-agenda-highlight-todo list))
6703 (if nosort
6704 list
6705 (when org-agenda-before-sorting-filter-function
6706 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6707 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6709 (defun org-agenda-highlight-todo (x)
6710 (let ((org-done-keywords org-done-keywords-for-agenda)
6711 (case-fold-search nil)
6713 (if (eq x 'line)
6714 (save-excursion
6715 (beginning-of-line 1)
6716 (setq re (org-get-at-bol 'org-todo-regexp))
6717 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6718 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6719 (add-text-properties (match-beginning 0) (match-end 1)
6720 (list 'face (org-get-todo-face 1)))
6721 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6722 (delete-region (match-beginning 1) (1- (match-end 0)))
6723 (goto-char (match-beginning 1))
6724 (insert (format org-agenda-todo-keyword-format s)))))
6725 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6726 (setq re (get-text-property 0 'org-todo-regexp x))
6727 (when (and re
6728 ;; Test `pl' because if there's no heading content,
6729 ;; there's no point matching to highlight. Note
6730 ;; that if we didn't test `pl' first, and there
6731 ;; happened to be no keyword from `org-todo-regexp'
6732 ;; on this heading line, then the `equal' comparison
6733 ;; afterwards would spuriously succeed in the case
6734 ;; where `pl' is nil -- causing an args-out-of-range
6735 ;; error when we try to add text properties to text
6736 ;; that isn't there.
6738 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6739 x pl) pl))
6740 (add-text-properties
6741 (or (match-end 1) (match-end 0)) (match-end 0)
6742 (list 'face (org-get-todo-face (match-string 2 x)))
6744 (when (match-end 1)
6745 (setq x (concat (substring x 0 (match-end 1))
6746 (format org-agenda-todo-keyword-format
6747 (match-string 2 x))
6748 (org-add-props " " (text-properties-at 0 x))
6749 (substring x (match-end 3)))))))
6750 x)))
6752 (defsubst org-cmp-priority (a b)
6753 "Compare the priorities of string A and B."
6754 (let ((pa (or (get-text-property 1 'priority a) 0))
6755 (pb (or (get-text-property 1 'priority b) 0)))
6756 (cond ((> pa pb) +1)
6757 ((< pa pb) -1))))
6759 (defsubst org-cmp-effort (a b)
6760 "Compare the effort values of string A and B."
6761 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6762 (ea (or (get-text-property 1 'effort-minutes a) def))
6763 (eb (or (get-text-property 1 'effort-minutes b) def)))
6764 (cond ((> ea eb) +1)
6765 ((< ea eb) -1))))
6767 (defsubst org-cmp-category (a b)
6768 "Compare the string values of categories of strings A and B."
6769 (let ((ca (or (get-text-property 1 'org-category a) ""))
6770 (cb (or (get-text-property 1 'org-category b) "")))
6771 (cond ((string-lessp ca cb) -1)
6772 ((string-lessp cb ca) +1))))
6774 (defsubst org-cmp-todo-state (a b)
6775 "Compare the todo states of strings A and B."
6776 (let* ((ma (or (get-text-property 1 'org-marker a)
6777 (get-text-property 1 'org-hd-marker a)))
6778 (mb (or (get-text-property 1 'org-marker b)
6779 (get-text-property 1 'org-hd-marker b)))
6780 (fa (and ma (marker-buffer ma)))
6781 (fb (and mb (marker-buffer mb)))
6782 (todo-kwds
6783 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6784 (and fb (with-current-buffer fb org-todo-keywords-1))))
6785 (ta (or (get-text-property 1 'todo-state a) ""))
6786 (tb (or (get-text-property 1 'todo-state b) ""))
6787 (la (- (length (member ta todo-kwds))))
6788 (lb (- (length (member tb todo-kwds))))
6789 (donepa (member ta org-done-keywords-for-agenda))
6790 (donepb (member tb org-done-keywords-for-agenda)))
6791 (cond ((and donepa (not donepb)) -1)
6792 ((and (not donepa) donepb) +1)
6793 ((< la lb) -1)
6794 ((< lb la) +1))))
6796 (defsubst org-cmp-alpha (a b)
6797 "Compare the headlines, alphabetically."
6798 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6799 (plb (text-property-any 0 (length b) 'org-heading t b))
6800 (ta (and pla (substring a pla)))
6801 (tb (and plb (substring b plb))))
6802 (when pla
6803 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6804 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6805 (setq ta (substring ta (match-end 0))))
6806 (setq ta (downcase ta)))
6807 (when plb
6808 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6809 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6810 (setq tb (substring tb (match-end 0))))
6811 (setq tb (downcase tb)))
6812 (cond ((not ta) +1)
6813 ((not tb) -1)
6814 ((string-lessp ta tb) -1)
6815 ((string-lessp tb ta) +1))))
6817 (defsubst org-cmp-tag (a b)
6818 "Compare the string values of the first tags of A and B."
6819 (let ((ta (car (last (get-text-property 1 'tags a))))
6820 (tb (car (last (get-text-property 1 'tags b)))))
6821 (cond ((not ta) +1)
6822 ((not tb) -1)
6823 ((string-lessp ta tb) -1)
6824 ((string-lessp tb ta) +1))))
6826 (defsubst org-cmp-time (a b)
6827 "Compare the time-of-day values of strings A and B."
6828 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6829 (ta (or (get-text-property 1 'time-of-day a) def))
6830 (tb (or (get-text-property 1 'time-of-day b) def)))
6831 (cond ((< ta tb) -1)
6832 ((< tb ta) +1))))
6834 (defsubst org-cmp-habit-p (a b)
6835 "Compare the todo states of strings A and B."
6836 (let ((ha (get-text-property 1 'org-habit-p a))
6837 (hb (get-text-property 1 'org-habit-p b)))
6838 (cond ((and ha (not hb)) -1)
6839 ((and (not ha) hb) +1))))
6841 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6843 (defun org-entries-lessp (a b)
6844 "Predicate for sorting agenda entries."
6845 ;; The following variables will be used when the form is evaluated.
6846 ;; So even though the compiler complains, keep them.
6847 (let* ((ss org-agenda-sorting-strategy-selected)
6848 (time-up (and (org-em 'time-up 'time-down ss)
6849 (org-cmp-time a b)))
6850 (time-down (if time-up (- time-up) nil))
6851 (priority-up (and (org-em 'priority-up 'priority-down ss)
6852 (org-cmp-priority a b)))
6853 (priority-down (if priority-up (- priority-up) nil))
6854 (effort-up (and (org-em 'effort-up 'effort-down ss)
6855 (org-cmp-effort a b)))
6856 (effort-down (if effort-up (- effort-up) nil))
6857 (category-up (and (or (org-em 'category-up 'category-down ss)
6858 (memq 'category-keep ss))
6859 (org-cmp-category a b)))
6860 (category-down (if category-up (- category-up) nil))
6861 (category-keep (if category-up +1 nil))
6862 (tag-up (and (org-em 'tag-up 'tag-down ss)
6863 (org-cmp-tag a b)))
6864 (tag-down (if tag-up (- tag-up) nil))
6865 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6866 (org-cmp-todo-state a b)))
6867 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6868 (habit-up (and (org-em 'habit-up 'habit-down ss)
6869 (org-cmp-habit-p a b)))
6870 (habit-down (if habit-up (- habit-up) nil))
6871 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6872 (org-cmp-alpha a b)))
6873 (alpha-down (if alpha-up (- alpha-up) nil))
6874 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6875 user-defined-up user-defined-down)
6876 (if (and need-user-cmp org-agenda-cmp-user-defined
6877 (functionp org-agenda-cmp-user-defined))
6878 (setq user-defined-up
6879 (funcall org-agenda-cmp-user-defined a b)
6880 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6881 (cdr (assoc
6882 (eval (cons 'or org-agenda-sorting-strategy-selected))
6883 '((-1 . t) (1 . nil) (nil . nil))))))
6885 ;;; Agenda restriction lock
6887 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6888 "Overlay to mark the headline to which agenda commands are restricted.")
6889 (overlay-put org-agenda-restriction-lock-overlay
6890 'face 'org-agenda-restriction-lock)
6891 (overlay-put org-agenda-restriction-lock-overlay
6892 'help-echo "Agendas are currently limited to this subtree.")
6893 (org-detach-overlay org-agenda-restriction-lock-overlay)
6895 (defun org-agenda-set-restriction-lock (&optional type)
6896 "Set restriction lock for agenda, to current subtree or file.
6897 Restriction will be the file if TYPE is `file', or if type is the
6898 universal prefix '(4), or if the cursor is before the first headline
6899 in the file. Otherwise, restriction will be to the current subtree."
6900 (interactive "P")
6901 (and (equal type '(4)) (setq type 'file))
6902 (setq type (cond
6903 (type type)
6904 ((org-at-heading-p) 'subtree)
6905 ((condition-case nil (org-back-to-heading t) (error nil))
6906 'subtree)
6907 (t 'file)))
6908 (if (eq type 'subtree)
6909 (progn
6910 (setq org-agenda-restrict t)
6911 (setq org-agenda-overriding-restriction 'subtree)
6912 (put 'org-agenda-files 'org-restrict
6913 (list (buffer-file-name (buffer-base-buffer))))
6914 (org-back-to-heading t)
6915 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6916 (move-marker org-agenda-restrict-begin (point))
6917 (move-marker org-agenda-restrict-end
6918 (save-excursion (org-end-of-subtree t)))
6919 (message "Locking agenda restriction to subtree"))
6920 (put 'org-agenda-files 'org-restrict
6921 (list (buffer-file-name (buffer-base-buffer))))
6922 (setq org-agenda-restrict nil)
6923 (setq org-agenda-overriding-restriction 'file)
6924 (move-marker org-agenda-restrict-begin nil)
6925 (move-marker org-agenda-restrict-end nil)
6926 (message "Locking agenda restriction to file"))
6927 (setq current-prefix-arg nil)
6928 (org-agenda-maybe-redo))
6930 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6931 "Remove the agenda restriction lock."
6932 (interactive "P")
6933 (org-detach-overlay org-agenda-restriction-lock-overlay)
6934 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6935 (setq org-agenda-overriding-restriction nil)
6936 (setq org-agenda-restrict nil)
6937 (put 'org-agenda-files 'org-restrict nil)
6938 (move-marker org-agenda-restrict-begin nil)
6939 (move-marker org-agenda-restrict-end nil)
6940 (setq current-prefix-arg nil)
6941 (message "Agenda restriction lock removed")
6942 (or noupdate (org-agenda-maybe-redo)))
6944 (defun org-agenda-maybe-redo ()
6945 "If there is any window showing the agenda view, update it."
6946 (let ((w (get-buffer-window org-agenda-buffer-name t))
6947 (w0 (selected-window)))
6948 (when w
6949 (select-window w)
6950 (org-agenda-redo)
6951 (select-window w0)
6952 (if org-agenda-overriding-restriction
6953 (message "Agenda view shifted to new %s restriction"
6954 org-agenda-overriding-restriction)
6955 (message "Agenda restriction lock removed")))))
6957 ;;; Agenda commands
6959 (defun org-agenda-check-type (error &rest types)
6960 "Check if agenda buffer is of allowed type.
6961 If ERROR is non-nil, throw an error, otherwise just return nil.
6962 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6963 (if (not org-agenda-type)
6964 (error "No Org agenda currently displayed")
6965 (if (memq org-agenda-type types)
6967 (if error
6968 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6969 nil))))
6971 (defun org-agenda-Quit ()
6972 "Exit the agenda and kill buffers loaded by `org-agenda'.
6973 Also restore the window configuration."
6974 (interactive)
6975 (if org-agenda-columns-active
6976 (org-columns-quit)
6977 (let ((buf (current-buffer)))
6978 (if (eq org-agenda-window-setup 'other-frame)
6979 (progn
6980 (org-agenda-reset-markers)
6981 (kill-buffer buf)
6982 (org-columns-remove-overlays)
6983 (setq org-agenda-archives-mode nil)
6984 (delete-frame))
6985 (and (not (eq org-agenda-window-setup 'current-window))
6986 (not (one-window-p))
6987 (delete-window))
6988 (org-agenda-reset-markers)
6989 (kill-buffer buf)
6990 (org-columns-remove-overlays)
6991 (setq org-agenda-archives-mode nil)))
6992 ;; Maybe restore the pre-agenda window configuration.
6993 (and org-agenda-restore-windows-after-quit
6994 (not (eq org-agenda-window-setup 'other-frame))
6995 org-agenda-pre-window-conf
6996 (set-window-configuration org-agenda-pre-window-conf)
6997 (setq org-agenda-pre-window-conf nil))))
6999 (defun org-agenda-quit ()
7000 "Exit the agenda and restore the window configuration.
7001 When `org-agenda-sticky' is non-nil, only bury the agenda."
7002 (interactive)
7003 (if (and (eq org-indirect-buffer-display 'other-window)
7004 org-last-indirect-buffer)
7005 (let ((org-last-indirect-window
7006 (get-buffer-window org-last-indirect-buffer)))
7007 (if org-last-indirect-window
7008 (delete-window org-last-indirect-window))))
7009 (if org-agenda-columns-active
7010 (org-columns-quit)
7011 (if org-agenda-sticky
7012 (let ((buf (current-buffer)))
7013 (if (eq org-agenda-window-setup 'other-frame)
7014 (progn
7015 (delete-frame))
7016 (and (not (eq org-agenda-window-setup 'current-window))
7017 (not (one-window-p))
7018 (delete-window)))
7019 (with-current-buffer buf
7020 (bury-buffer)
7021 ;; Maybe restore the pre-agenda window configuration.
7022 (and org-agenda-restore-windows-after-quit
7023 (not (eq org-agenda-window-setup 'other-frame))
7024 org-agenda-pre-window-conf
7025 (set-window-configuration org-agenda-pre-window-conf)
7026 (setq org-agenda-pre-window-conf nil))))
7027 (org-agenda-Quit))))
7029 (defun org-agenda-exit ()
7030 "Exit the agenda and restore the window configuration.
7031 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7032 buffers visited directly by the user will not be touched."
7033 (interactive)
7034 (org-release-buffers org-agenda-new-buffers)
7035 (setq org-agenda-new-buffers nil)
7036 (org-agenda-Quit))
7038 (defun org-agenda-kill-all-agenda-buffers ()
7039 "Kill all buffers in `org-agenda-mode'.
7040 This is used when toggling sticky agendas.
7041 You can also explicitly invoke it with `C-c a C-k'."
7042 (interactive)
7043 (let (blist)
7044 (dolist (buf (buffer-list))
7045 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7046 (push buf blist)))
7047 (mapc 'kill-buffer blist)))
7049 (defun org-agenda-execute (arg)
7050 "Execute another agenda command, keeping same window.
7051 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7052 in the agenda."
7053 (interactive "P")
7054 (let ((org-agenda-window-setup 'current-window))
7055 (org-agenda arg)))
7057 (defun org-agenda-redo (&optional all)
7058 "Rebuild possibly ALL agenda view(s) in the current buffer."
7059 (interactive "P")
7060 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7061 (cpa (unless (eq all t) current-prefix-arg))
7062 (org-agenda-doing-sticky-redo org-agenda-sticky)
7063 (org-agenda-sticky nil)
7064 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7065 org-agenda-buffer-name))
7066 (org-agenda-keep-modes t)
7067 (tag-filter org-agenda-tag-filter)
7068 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7069 (top-cat-filter org-agenda-top-category-filter)
7070 (cat-filter org-agenda-category-filter)
7071 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7072 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7073 (cols org-agenda-columns-active)
7074 (line (org-current-line))
7075 (window-line (- line (org-current-line (window-start))))
7076 (lprops (get 'org-agenda-redo-command 'org-lprops))
7077 (redo-cmd (get-text-property p 'org-redo-cmd))
7078 (last-args (get-text-property p 'org-last-args))
7079 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7080 (org-agenda-overriding-cmd-arguments
7081 (unless (eq all t)
7082 (cond ((listp last-args)
7083 (cons (or cpa (car last-args)) (cdr last-args)))
7084 ((stringp last-args)
7085 last-args))))
7086 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7087 (put 'org-agenda-tag-filter :preset-filter nil)
7088 (put 'org-agenda-category-filter :preset-filter nil)
7089 (and cols (org-columns-quit))
7090 (message "Rebuilding agenda buffer...")
7091 (if series-redo-cmd
7092 (eval series-redo-cmd)
7093 (org-let lprops '(eval redo-cmd)))
7094 (setq org-agenda-undo-list nil
7095 org-agenda-pending-undo-list nil)
7096 (message "Rebuilding agenda buffer...done")
7097 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7098 (put 'org-agenda-category-filter :preset-filter cat-preset)
7099 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7100 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7101 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
7102 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7103 (org-goto-line line)
7104 (recenter window-line)))
7106 (defvar org-global-tags-completion-table nil)
7107 (defvar org-agenda-filter-form nil)
7108 (defvar org-agenda-filtered-by-category nil)
7110 (defun org-agenda-filter-by-category (strip)
7111 "Keep only those lines in the agenda buffer that have a specific category.
7112 The category is that of the current line."
7113 (interactive "P")
7114 (if (and org-agenda-filtered-by-category
7115 org-agenda-category-filter)
7116 (org-agenda-filter-show-all-cat)
7117 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7118 (if cat (org-agenda-filter-apply
7119 (list (concat (if strip "-" "+") cat)) 'category)
7120 (error "No category at point")))))
7122 (defun org-find-top-category (&optional pos)
7123 (save-excursion
7124 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7125 (if pos (goto-char pos))
7126 ;; Skip up to the topmost parent
7127 (while (ignore-errors (outline-up-heading 1) t))
7128 (ignore-errors
7129 (nth 4 (org-heading-components))))))
7131 (defvar org-agenda-filtered-by-top-category nil)
7133 (defun org-agenda-filter-by-top-category (strip)
7134 "Keep only those lines in the agenda buffer that have a specific category.
7135 The category is that of the current line."
7136 (interactive "P")
7137 (if org-agenda-filtered-by-top-category
7138 (progn
7139 (setq org-agenda-filtered-by-top-category nil
7140 org-agenda-top-category-filter nil)
7141 (org-agenda-filter-show-all-cat))
7142 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7143 (if cat (org-agenda-filter-top-category-apply cat strip)
7144 (error "No top-level category at point")))))
7146 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7147 "Keep only those lines in the agenda buffer that have a specific tag.
7148 The tag is selected with its fast selection letter, as configured.
7149 With prefix argument STRIP, remove all lines that do have the tag.
7150 A lisp caller can specify CHAR. NARROW means that the new tag should be
7151 used to narrow the search - the interactive user can also press `-' or `+'
7152 to switch to narrowing."
7153 (interactive "P")
7154 (let* ((alist org-tag-alist-for-agenda)
7155 (tag-chars (mapconcat
7156 (lambda (x) (if (and (not (symbolp (car x)))
7157 (cdr x))
7158 (char-to-string (cdr x))
7159 ""))
7160 alist ""))
7161 (efforts (org-split-string
7162 (or (cdr (assoc (concat org-effort-property "_ALL")
7163 org-global-properties))
7164 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7165 "")))
7166 (effort-op org-agenda-filter-effort-default-operator)
7167 (effort-prompt "")
7168 (inhibit-read-only t)
7169 (current org-agenda-tag-filter)
7170 maybe-refresh a n tag)
7171 (unless char
7172 (message
7173 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7174 (if narrow "Narrow" "Filter") tag-chars
7175 (if org-agenda-auto-exclude-function "[RET], " ""))
7176 (setq char (read-char-exclusive)))
7177 (when (member char '(?+ ?-))
7178 ;; Narrowing down
7179 (cond ((equal char ?-) (setq strip t narrow t))
7180 ((equal char ?+) (setq strip nil narrow t)))
7181 (message
7182 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7183 (setq char (read-char-exclusive)))
7184 (when (member char '(?< ?> ?= ??))
7185 ;; An effort operator
7186 (setq effort-op (char-to-string char))
7187 (setq alist nil) ; to make sure it will be interpreted as effort.
7188 (unless (equal char ??)
7189 (loop for i from 0 to 9 do
7190 (setq effort-prompt
7191 (concat
7192 effort-prompt " ["
7193 (if (= i 9) "0" (int-to-string (1+ i)))
7194 "]" (nth i efforts))))
7195 (message "Effort%s: %s " effort-op effort-prompt)
7196 (setq char (read-char-exclusive))
7197 (when (or (< char ?0) (> char ?9))
7198 (error "Need 1-9,0 to select effort"))))
7199 (when (equal char ?\t)
7200 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7201 (org-set-local 'org-global-tags-completion-table
7202 (org-global-tags-completion-table)))
7203 (let ((completion-ignore-case t))
7204 (setq tag (org-icompleting-read
7205 "Tag: " org-global-tags-completion-table))))
7206 (cond
7207 ((equal char ?\r)
7208 (org-agenda-filter-show-all-tag)
7209 (when org-agenda-auto-exclude-function
7210 (setq org-agenda-tag-filter '())
7211 (dolist (tag (org-agenda-get-represented-tags))
7212 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7213 (if modifier
7214 (push modifier org-agenda-tag-filter))))
7215 (if (not (null org-agenda-tag-filter))
7216 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7217 (setq maybe-refresh t))
7218 ((equal char ?/)
7219 (org-agenda-filter-show-all-tag)
7220 (when (get 'org-agenda-tag-filter :preset-filter)
7221 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7222 (setq maybe-refresh t))
7223 ((equal char ?. )
7224 (setq org-agenda-tag-filter
7225 (mapcar (lambda(tag) (concat "+" tag))
7226 (org-get-at-bol 'tags)))
7227 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7228 (setq maybe-refresh t))
7229 ((or (equal char ?\ )
7230 (setq a (rassoc char alist))
7231 (and (>= char ?0) (<= char ?9)
7232 (setq n (if (= char ?0) 9 (- char ?0 1))
7233 tag (concat effort-op (nth n efforts))
7234 a (cons tag nil)))
7235 (and (= char ??)
7236 (setq tag "?eff")
7237 a (cons tag nil))
7238 (and tag (setq a (cons tag nil))))
7239 (org-agenda-filter-show-all-tag)
7240 (setq tag (car a))
7241 (setq org-agenda-tag-filter
7242 (cons (concat (if strip "-" "+") tag)
7243 (if narrow current nil)))
7244 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7245 (setq maybe-refresh t))
7246 (t (error "Invalid tag selection character %c" char)))
7247 (when (and maybe-refresh
7248 (eq org-agenda-clockreport-mode 'with-filter))
7249 (org-agenda-redo))))
7251 (defun org-agenda-get-represented-tags ()
7252 "Get a list of all tags currently represented in the agenda."
7253 (let (p tags)
7254 (save-excursion
7255 (goto-char (point-min))
7256 (while (setq p (next-single-property-change (point) 'tags))
7257 (goto-char p)
7258 (mapc (lambda (x) (add-to-list 'tags x))
7259 (get-text-property (point) 'tags))))
7260 tags))
7262 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7263 "Refine the current filter. See `org-agenda-filter-by-tag'."
7264 (interactive "P")
7265 (org-agenda-filter-by-tag strip char 'refine))
7267 (defun org-agenda-filter-make-matcher ()
7268 "Create the form that tests a line for agenda filter."
7269 (let (f f1)
7270 ;; first compute the tag-filter matcher
7271 (dolist (x (delete-dups
7272 (append (get 'org-agenda-tag-filter
7273 :preset-filter) org-agenda-tag-filter)))
7274 (if (member x '("-" "+"))
7275 (setq f1 (if (equal x "-") 'tags '(not tags)))
7276 (if (string-match "[<=>?]" x)
7277 (setq f1 (org-agenda-filter-effort-form x))
7278 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7279 (if (equal (string-to-char x) ?-)
7280 (setq f1 (list 'not f1))))
7281 (push f1 f))
7282 ;; then compute the category-filter matcher
7283 (dolist (x (delete-dups
7284 (append (get 'org-agenda-category-filter
7285 :preset-filter) org-agenda-category-filter)))
7286 (if (equal "-" (substring x 0 1))
7287 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7288 (setq f1 (list 'equal (substring x 1) 'cat)))
7289 (push f1 f))
7290 (cons 'and (nreverse f))))
7292 (defun org-agenda-filter-effort-form (e)
7293 "Return the form to compare the effort of the current line with what E says.
7294 E looks like \"+<2:25\"."
7295 (let (op)
7296 (setq e (substring e 1))
7297 (setq op (string-to-char e) e (substring e 1))
7298 (setq op (cond ((equal op ?<) '<=)
7299 ((equal op ?>) '>=)
7300 ((equal op ??) op)
7301 (t '=)))
7302 (list 'org-agenda-compare-effort (list 'quote op)
7303 (org-duration-string-to-minutes e))))
7305 (defun org-agenda-compare-effort (op value)
7306 "Compare the effort of the current line with VALUE, using OP.
7307 If the line does not have an effort defined, return nil."
7308 (let ((eff (org-get-at-bol 'effort-minutes)))
7309 (if (equal op ??)
7310 (not eff)
7311 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7312 value))))
7314 (defun org-agenda-filter-apply (filter type)
7315 "Set FILTER as the new agenda filter and apply it."
7316 (let (tags cat)
7317 (if (eq type 'tag)
7318 (setq org-agenda-tag-filter filter)
7319 (setq org-agenda-category-filter filter))
7320 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7321 (if (and (eq type 'category)
7322 (not (equal (substring (car filter) 0 1) "-")))
7323 ;; Only set `org-agenda-filtered-by-category' to t
7324 ;; when a unique category is used as the filter
7325 (setq org-agenda-filtered-by-category t))
7326 (org-agenda-set-mode-name)
7327 (save-excursion
7328 (goto-char (point-min))
7329 (while (not (eobp))
7330 (if (org-get-at-bol 'org-marker)
7331 (progn
7332 (setq tags (org-get-at-bol 'tags) ; used in eval
7333 cat (get-text-property (point) 'org-category))
7334 (if (not (eval org-agenda-filter-form))
7335 (org-agenda-filter-hide-line type))
7336 (beginning-of-line 2))
7337 (beginning-of-line 2))))
7338 (if (get-char-property (point) 'invisible)
7339 (ignore-errors (org-agenda-previous-line)))))
7341 (defun org-agenda-filter-top-category-apply (category &optional negative)
7342 "Set FILTER as the new agenda filter and apply it."
7343 (org-agenda-set-mode-name)
7344 (save-excursion
7345 (goto-char (point-min))
7346 (while (not (eobp))
7347 (let* ((pos (org-get-at-bol 'org-hd-marker))
7348 (topcat (and pos (org-find-top-category pos))))
7349 (if (and topcat (funcall (if negative 'identity 'not)
7350 (string= category topcat)))
7351 (org-agenda-filter-hide-line 'category)))
7352 (beginning-of-line 2)))
7353 (if (get-char-property (point) 'invisible)
7354 (org-agenda-previous-line))
7355 (setq org-agenda-top-category-filter category
7356 org-agenda-filtered-by-top-category t))
7358 (defun org-agenda-filter-hide-line (type)
7359 (let (ov)
7360 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7361 (point-at-eol)))
7362 (overlay-put ov 'invisible t)
7363 (overlay-put ov 'type type)
7364 (if (eq type 'tag)
7365 (push ov org-agenda-tag-filter-overlays)
7366 (push ov org-agenda-cat-filter-overlays))))
7368 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7369 (setq pos (or pos (point)))
7370 (save-excursion
7371 (dolist (ov (overlays-at pos))
7372 (when (and (overlay-get ov 'invisible)
7373 (eq (overlay-get ov 'type) 'tag))
7374 (goto-char pos)
7375 (if (< (overlay-start ov) (point-at-eol))
7376 (move-overlay ov (point-at-eol)
7377 (overlay-end ov)))))))
7379 (defun org-agenda-filter-show-all-tag nil
7380 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7381 (setq org-agenda-tag-filter-overlays nil
7382 org-agenda-tag-filter nil
7383 org-agenda-filter-form nil)
7384 (org-agenda-set-mode-name))
7386 (defun org-agenda-filter-show-all-cat nil
7387 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7388 (setq org-agenda-cat-filter-overlays nil
7389 org-agenda-filtered-by-category nil
7390 org-agenda-category-filter nil
7391 org-agenda-filter-form nil)
7392 (org-agenda-set-mode-name))
7394 (defun org-agenda-manipulate-query-add ()
7395 "Manipulate the query by adding a search term with positive selection.
7396 Positive selection means the term must be matched for selection of an entry."
7397 (interactive)
7398 (org-agenda-manipulate-query ?\[))
7399 (defun org-agenda-manipulate-query-subtract ()
7400 "Manipulate the query by adding a search term with negative selection.
7401 Negative selection means term must not be matched for selection of an entry."
7402 (interactive)
7403 (org-agenda-manipulate-query ?\]))
7404 (defun org-agenda-manipulate-query-add-re ()
7405 "Manipulate the query by adding a search regexp with positive selection.
7406 Positive selection means the regexp must match for selection of an entry."
7407 (interactive)
7408 (org-agenda-manipulate-query ?\{))
7409 (defun org-agenda-manipulate-query-subtract-re ()
7410 "Manipulate the query by adding a search regexp with negative selection.
7411 Negative selection means regexp must not match for selection of an entry."
7412 (interactive)
7413 (org-agenda-manipulate-query ?\}))
7414 (defun org-agenda-manipulate-query (char)
7415 (cond
7416 ((memq org-agenda-type '(timeline agenda))
7417 (let ((org-agenda-include-inactive-timestamps t))
7418 (org-agenda-redo))
7419 (message "Display now includes inactive timestamps as well"))
7420 ((eq org-agenda-type 'search)
7421 (org-add-to-string
7422 'org-agenda-query-string
7423 (if org-agenda-last-search-view-search-was-boolean
7424 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7425 (?\{ . " +{}") (?\} . " -{}"))))
7426 " "))
7427 (setq org-agenda-redo-command
7428 (list 'org-search-view
7429 (car (get-text-property (min (1- (point-max)) (point))
7430 'org-last-args))
7431 org-agenda-query-string
7432 (+ (length org-agenda-query-string)
7433 (if (member char '(?\{ ?\})) 0 1))))
7434 (set-register org-agenda-query-register org-agenda-query-string)
7435 (let ((org-agenda-overriding-arguments
7436 (cdr org-agenda-redo-command)))
7437 (org-agenda-redo)))
7438 (t (error "Cannot manipulate query for %s-type agenda buffers"
7439 org-agenda-type))))
7441 (defun org-add-to-string (var string)
7442 (set var (concat (symbol-value var) string)))
7444 (defun org-agenda-goto-date (span)
7445 "Jump to DATE in agenda."
7446 (interactive "P")
7447 (let* ((org-read-date-prefer-future
7448 (eval org-agenda-jump-prefer-future))
7449 (date (org-read-date))
7450 (org-agenda-sticky-orig org-agenda-sticky)
7451 (org-agenda-buffer-tmp-name (buffer-name))
7452 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7453 (0-arg (or current-prefix-arg (car args)))
7454 (2-arg (nth 2 args))
7455 (newcmd (list 'org-agenda-list 0-arg date
7456 (org-agenda-span-to-ndays 2-arg)))
7457 (newargs (cdr newcmd))
7458 (inhibit-read-only t)
7459 org-agenda-sticky)
7460 (if (not (org-agenda-check-type t 'agenda))
7461 (error "Not available in non-agenda blocks")
7462 (add-text-properties (point-min) (point-max)
7463 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7464 (org-agenda-redo)
7465 (setq org-agenda-sticky org-agenda-sticky-orig
7466 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7468 (defun org-agenda-goto-today ()
7469 "Go to today."
7470 (interactive)
7471 (org-agenda-check-type t 'timeline 'agenda)
7472 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7473 (curspan (nth 2 args))
7474 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7475 (cond
7476 (tdpos (goto-char tdpos))
7477 ((eq org-agenda-type 'agenda)
7478 (let* ((sd (org-agenda-compute-starting-span
7479 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7480 (org-agenda-overriding-arguments args))
7481 (setf (nth 1 org-agenda-overriding-arguments) sd)
7482 (org-agenda-redo)
7483 (org-agenda-find-same-or-today-or-agenda)))
7484 (t (error "Cannot find today")))))
7486 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7487 (goto-char
7488 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7489 (text-property-any (point-min) (point-max) 'org-today t)
7490 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7491 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7492 (org-agenda-goto-block-beginning))
7493 (point-min))))
7495 (defun org-agenda-goto-block-beginning ()
7496 "Go the agenda block beginning."
7497 (interactive)
7498 (if (not (derived-mode-p 'org-agenda-mode))
7499 (error "Cannot execute this command outside of org-agenda-mode buffers")
7500 (let (dest)
7501 (save-excursion
7502 (unless (looking-at "\\'")
7503 (forward-char))
7504 (let* ((prop 'org-agenda-structural-header)
7505 (p (previous-single-property-change (point) prop))
7506 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7507 (1- (point))) prop)))
7508 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7509 (if (not dest)
7510 (error "Cannot find the beginning of the blog")
7511 (goto-char dest)
7512 (move-beginning-of-line 1)))))
7514 (defun org-agenda-later (arg)
7515 "Go forward in time by the current span.
7516 With prefix ARG, go forward that many times the current span."
7517 (interactive "p")
7518 (org-agenda-check-type t 'agenda)
7519 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7520 (span (or (nth 2 args) org-agenda-current-span))
7521 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7522 (greg (calendar-gregorian-from-absolute sd))
7523 (cnt (org-get-at-bol 'org-day-cnt))
7524 greg2)
7525 (cond
7526 ((numberp span)
7527 (setq sd (+ (* span arg) sd)))
7528 ((eq span 'day)
7529 (setq sd (+ arg sd)))
7530 ((eq span 'week)
7531 (setq sd (+ (* 7 arg) sd)))
7532 ((eq span 'month)
7533 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7534 sd (calendar-absolute-from-gregorian greg2))
7535 (setcar greg2 (1+ (car greg2))))
7536 ((eq span 'year)
7537 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7538 sd (calendar-absolute-from-gregorian greg2))
7539 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7541 (setq sd (+ (* span arg) sd))))
7542 (let ((org-agenda-overriding-cmd
7543 ;; `cmd' may have been set by `org-agenda-run-series' which
7544 ;; uses `org-agenda-overriding-cmd' to decide whether
7545 ;; overriding is allowed for `cmd'
7546 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7547 (org-agenda-overriding-arguments
7548 (list (car args) sd span)))
7549 (org-agenda-redo)
7550 (org-agenda-find-same-or-today-or-agenda cnt))))
7552 (defun org-agenda-earlier (arg)
7553 "Go backward in time by the current span.
7554 With prefix ARG, go backward that many times the current span."
7555 (interactive "p")
7556 (org-agenda-later (- arg)))
7558 (defun org-agenda-view-mode-dispatch ()
7559 "Call one of the view mode commands."
7560 (interactive)
7561 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7562 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7563 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7564 (let ((a (read-char-exclusive)))
7565 (case a
7566 (?\ (call-interactively 'org-agenda-reset-view))
7567 (?d (call-interactively 'org-agenda-day-view))
7568 (?w (call-interactively 'org-agenda-week-view))
7569 (?m (call-interactively 'org-agenda-month-view))
7570 (?y (call-interactively 'org-agenda-year-view))
7571 (?l (call-interactively 'org-agenda-log-mode))
7572 (?L (org-agenda-log-mode '(4)))
7573 (?c (org-agenda-log-mode 'clockcheck))
7574 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7575 (?a (call-interactively 'org-agenda-archives-mode))
7576 (?A (org-agenda-archives-mode 'files))
7577 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7578 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7579 (?G (call-interactively 'org-agenda-toggle-time-grid))
7580 (?D (call-interactively 'org-agenda-toggle-diary))
7581 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7582 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7583 (org-agenda-check-type t 'timeline 'agenda)
7584 (org-agenda-redo))
7585 (message "Display now includes inactive timestamps as well"))
7586 (?q (message "Abort"))
7587 (otherwise (error "Invalid key" )))))
7589 (defun org-agenda-reset-view ()
7590 "Switch to default view for agenda."
7591 (interactive)
7592 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7593 (defun org-agenda-day-view (&optional day-of-year)
7594 "Switch to daily view for agenda.
7595 With argument DAY-OF-YEAR, switch to that day of the year."
7596 (interactive "P")
7597 (org-agenda-change-time-span 'day day-of-year))
7598 (defun org-agenda-week-view (&optional iso-week)
7599 "Switch to daily view for agenda.
7600 With argument ISO-WEEK, switch to the corresponding ISO week.
7601 If ISO-WEEK has more then 2 digits, only the last two encode the
7602 week. Any digits before this encode a year. So 200712 means
7603 week 12 of year 2007. Years in the range 1938-2037 can also be
7604 written as 2-digit years."
7605 (interactive "P")
7606 (org-agenda-change-time-span 'week iso-week))
7607 (defun org-agenda-month-view (&optional month)
7608 "Switch to monthly view for agenda.
7609 With argument MONTH, switch to that month."
7610 (interactive "P")
7611 (org-agenda-change-time-span 'month month))
7612 (defun org-agenda-year-view (&optional year)
7613 "Switch to yearly view for agenda.
7614 With argument YEAR, switch to that year.
7615 If MONTH has more then 2 digits, only the last two encode the
7616 month. Any digits before this encode a year. So 200712 means
7617 December year 2007. Years in the range 1938-2037 can also be
7618 written as 2-digit years."
7619 (interactive "P")
7620 (when year
7621 (setq year (org-small-year-to-year year)))
7622 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7623 (org-agenda-change-time-span 'year year)
7624 (error "Abort")))
7626 (defun org-agenda-change-time-span (span &optional n)
7627 "Change the agenda view to SPAN.
7628 SPAN may be `day', `week', `month', `year'."
7629 (org-agenda-check-type t 'agenda)
7630 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7631 (curspan (nth 2 args)))
7632 (if (and (not n) (equal curspan span))
7633 (error "Viewing span is already \"%s\"" span))
7634 (let* ((sd (or (org-get-at-bol 'day)
7635 (nth 1 args)
7636 org-starting-day))
7637 (sd (org-agenda-compute-starting-span sd span n))
7638 (org-agenda-overriding-cmd
7639 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7640 (org-agenda-overriding-arguments
7641 (list (car args) sd span)))
7642 (org-agenda-redo)
7643 (org-agenda-find-same-or-today-or-agenda))
7644 (org-agenda-set-mode-name)
7645 (message "Switched to %s view" span)))
7647 (defun org-agenda-compute-starting-span (sd span &optional n)
7648 "Compute starting date for agenda.
7649 SPAN may be `day', `week', `month', `year'. The return value
7650 is a cons cell with the starting date and the number of days,
7651 so that the date SD will be in that range."
7652 (let* ((greg (calendar-gregorian-from-absolute sd))
7653 (dg (nth 1 greg))
7654 (mg (car greg))
7655 (yg (nth 2 greg)))
7656 (cond
7657 ((eq span 'day)
7658 (when n
7659 (setq sd (+ (calendar-absolute-from-gregorian
7660 (list mg 1 yg))
7661 n -1))))
7662 ((eq span 'week)
7663 (let* ((nt (calendar-day-of-week
7664 (calendar-gregorian-from-absolute sd)))
7665 (d (if org-agenda-start-on-weekday
7666 (- nt org-agenda-start-on-weekday)
7669 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7670 (when n
7671 (require 'cal-iso)
7672 (when (> n 99)
7673 (setq y1 (org-small-year-to-year (/ n 100))
7674 n (mod n 100)))
7675 (setq sd
7676 (calendar-absolute-from-iso
7677 (list n 1
7678 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7679 ((eq span 'month)
7680 (let (y1)
7681 (when (and n (> n 99))
7682 (setq y1 (org-small-year-to-year (/ n 100))
7683 n (mod n 100)))
7684 (setq sd (calendar-absolute-from-gregorian
7685 (list (or n mg) 1 (or y1 yg))))))
7686 ((eq span 'year)
7687 (setq sd (calendar-absolute-from-gregorian
7688 (list 1 1 (or n yg))))))
7689 sd))
7691 (defun org-agenda-next-date-line (&optional arg)
7692 "Jump to the next line indicating a date in agenda buffer."
7693 (interactive "p")
7694 (org-agenda-check-type t 'agenda 'timeline)
7695 (beginning-of-line 1)
7696 ;; This does not work if user makes date format that starts with a blank
7697 (if (looking-at "^\\S-") (forward-char 1))
7698 (if (not (re-search-forward "^\\S-" nil t arg))
7699 (progn
7700 (backward-char 1)
7701 (error "No next date after this line in this buffer")))
7702 (goto-char (match-beginning 0)))
7704 (defun org-agenda-previous-date-line (&optional arg)
7705 "Jump to the previous line indicating a date in agenda buffer."
7706 (interactive "p")
7707 (org-agenda-check-type t 'agenda 'timeline)
7708 (beginning-of-line 1)
7709 (if (not (re-search-backward "^\\S-" nil t arg))
7710 (error "No previous date before this line in this buffer")))
7712 ;; Initialize the highlight
7713 (defvar org-hl (make-overlay 1 1))
7714 (overlay-put org-hl 'face 'highlight)
7716 (defun org-highlight (begin end &optional buffer)
7717 "Highlight a region with overlay."
7718 (move-overlay org-hl begin end (or buffer (current-buffer))))
7720 (defun org-unhighlight ()
7721 "Detach overlay INDEX."
7722 (org-detach-overlay org-hl))
7724 (defun org-unhighlight-once ()
7725 "Remove the highlight from its position, and this function from the hook."
7726 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7727 (org-unhighlight))
7729 (defvar org-agenda-pre-follow-window-conf nil)
7730 (defun org-agenda-follow-mode ()
7731 "Toggle follow mode in an agenda buffer."
7732 (interactive)
7733 (unless org-agenda-follow-mode
7734 (setq org-agenda-pre-follow-window-conf
7735 (current-window-configuration)))
7736 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7737 (unless org-agenda-follow-mode
7738 (set-window-configuration org-agenda-pre-follow-window-conf))
7739 (org-agenda-set-mode-name)
7740 (org-agenda-do-context-action)
7741 (message "Follow mode is %s"
7742 (if org-agenda-follow-mode "on" "off")))
7744 (defun org-agenda-entry-text-mode (&optional arg)
7745 "Toggle entry text mode in an agenda buffer."
7746 (interactive "P")
7747 (setq org-agenda-entry-text-mode (or (integerp arg)
7748 (not org-agenda-entry-text-mode)))
7749 (org-agenda-entry-text-hide)
7750 (and org-agenda-entry-text-mode
7751 (let ((org-agenda-entry-text-maxlines
7752 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7753 (org-agenda-entry-text-show)))
7754 (org-agenda-set-mode-name)
7755 (message "Entry text mode is %s. Maximum number of lines is %d"
7756 (if org-agenda-entry-text-mode "on" "off")
7757 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7759 (defun org-agenda-clockreport-mode (&optional with-filter)
7760 "Toggle clocktable mode in an agenda buffer.
7761 With prefix arg WITH-FILTER, make the clocktable respect the current
7762 agenda filter."
7763 (interactive "P")
7764 (org-agenda-check-type t 'agenda)
7765 (if with-filter
7766 (setq org-agenda-clockreport-mode 'with-filter)
7767 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7768 (org-agenda-set-mode-name)
7769 (org-agenda-redo)
7770 (message "Clocktable mode is %s"
7771 (if org-agenda-clockreport-mode "on" "off")))
7773 (defun org-agenda-log-mode (&optional special)
7774 "Toggle log mode in an agenda buffer.
7775 With argument SPECIAL, show all possible log items, not only the ones
7776 configured in `org-agenda-log-mode-items'.
7777 With a double `C-u' prefix arg, show *only* log items, nothing else."
7778 (interactive "P")
7779 (org-agenda-check-type t 'agenda 'timeline)
7780 (setq org-agenda-show-log
7781 (cond
7782 ((equal special '(16)) 'only)
7783 ((eq special 'clockcheck)
7784 (if (eq org-agenda-show-log 'clockcheck)
7785 nil 'clockcheck))
7786 (special '(closed clock state))
7787 (t (not org-agenda-show-log))))
7788 (org-agenda-set-mode-name)
7789 (org-agenda-redo)
7790 (message "Log mode is %s"
7791 (if org-agenda-show-log "on" "off")))
7793 (defun org-agenda-archives-mode (&optional with-files)
7794 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7795 When called with a prefix argument, include all archive files as well."
7796 (interactive "P")
7797 (setq org-agenda-archives-mode
7798 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7799 (org-agenda-set-mode-name)
7800 (org-agenda-redo)
7801 (message
7802 "%s"
7803 (cond
7804 ((eq org-agenda-archives-mode nil)
7805 "No archives are included")
7806 ((eq org-agenda-archives-mode 'trees)
7807 (format "Trees with :%s: tag are included" org-archive-tag))
7808 ((eq org-agenda-archives-mode t)
7809 (format "Trees with :%s: tag and all active archive files are included"
7810 org-archive-tag)))))
7812 (defun org-agenda-toggle-diary ()
7813 "Toggle diary inclusion in an agenda buffer."
7814 (interactive)
7815 (org-agenda-check-type t 'agenda)
7816 (setq org-agenda-include-diary (not org-agenda-include-diary))
7817 (org-agenda-redo)
7818 (org-agenda-set-mode-name)
7819 (message "Diary inclusion turned %s"
7820 (if org-agenda-include-diary "on" "off")))
7822 (defun org-agenda-toggle-deadlines ()
7823 "Toggle inclusion of entries with a deadline in an agenda buffer."
7824 (interactive)
7825 (org-agenda-check-type t 'agenda)
7826 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7827 (org-agenda-redo)
7828 (org-agenda-set-mode-name)
7829 (message "Deadlines inclusion turned %s"
7830 (if org-agenda-include-deadlines "on" "off")))
7832 (defun org-agenda-toggle-time-grid ()
7833 "Toggle time grid in an agenda buffer."
7834 (interactive)
7835 (org-agenda-check-type t 'agenda)
7836 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7837 (org-agenda-redo)
7838 (org-agenda-set-mode-name)
7839 (message "Time-grid turned %s"
7840 (if org-agenda-use-time-grid "on" "off")))
7842 (defun org-agenda-set-mode-name ()
7843 "Set the mode name to indicate all the small mode settings."
7844 (setq mode-name
7845 (list "Org-Agenda"
7846 (if (get 'org-agenda-files 'org-restrict) " []" "")
7848 '(:eval (org-agenda-span-name org-agenda-current-span))
7849 (if org-agenda-follow-mode " Follow" "")
7850 (if org-agenda-entry-text-mode " ETxt" "")
7851 (if org-agenda-include-diary " Diary" "")
7852 (if org-agenda-include-deadlines " Ddl" "")
7853 (if org-agenda-use-time-grid " Grid" "")
7854 (if (and (boundp 'org-habit-show-habits)
7855 org-habit-show-habits) " Habit" "")
7856 (cond
7857 ((consp org-agenda-show-log) " LogAll")
7858 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7859 (org-agenda-show-log " Log")
7860 (t ""))
7861 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7862 :preset-filter))
7863 '(:eval (org-propertize
7864 (concat " <"
7865 (mapconcat
7866 'identity
7867 (append
7868 (get 'org-agenda-category-filter :preset-filter)
7869 org-agenda-category-filter)
7871 ">")
7872 'face 'org-agenda-filter-category
7873 'help-echo "Category used in filtering"))
7875 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7876 :preset-filter))
7877 '(:eval (org-propertize
7878 (concat " {"
7879 (mapconcat
7880 'identity
7881 (append
7882 (get 'org-agenda-tag-filter :preset-filter)
7883 org-agenda-tag-filter)
7885 "}")
7886 'face 'org-agenda-filter-tags
7887 'help-echo "Tags used in filtering"))
7889 (if org-agenda-archives-mode
7890 (if (eq org-agenda-archives-mode t)
7891 " Archives"
7892 (format " :%s:" org-archive-tag))
7894 (if org-agenda-clockreport-mode
7895 (if (eq org-agenda-clockreport-mode 'with-filter)
7896 " Clock{}" " Clock")
7897 "")))
7898 (force-mode-line-update))
7900 (define-obsolete-function-alias
7901 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7903 (defun org-agenda-update-agenda-type ()
7904 "Update the agenda type after each command."
7905 (setq org-agenda-type
7906 (or (get-text-property (point) 'org-agenda-type)
7907 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7909 (defun org-agenda-next-line ()
7910 "Move cursor to the next line, and show if follow mode is active."
7911 (interactive)
7912 (call-interactively 'next-line)
7913 (org-agenda-do-context-action))
7915 (defun org-agenda-previous-line ()
7916 "Move cursor to the previous line, and show if follow-mode is active."
7917 (interactive)
7918 (call-interactively 'previous-line)
7919 (org-agenda-do-context-action))
7921 (defun org-agenda-next-item (n)
7922 "Move cursor to next agenda item."
7923 (interactive "p")
7924 (let ((col (current-column)))
7925 (dotimes (c n)
7926 (when (next-single-property-change (point-at-eol) 'org-marker)
7927 (move-end-of-line 1)
7928 (goto-char (next-single-property-change (point) 'org-marker))))
7929 (org-move-to-column col))
7930 (org-agenda-do-context-action))
7932 (defun org-agenda-previous-item (n)
7933 "Move cursor to next agenda item."
7934 (interactive "p")
7935 (dotimes (c n)
7936 (let ((col (current-column))
7937 (goto (save-excursion
7938 (move-end-of-line 0)
7939 (previous-single-property-change (point) 'org-marker))))
7940 (if goto (goto-char goto))
7941 (org-move-to-column col)))
7942 (org-agenda-do-context-action))
7944 (defun org-agenda-do-context-action ()
7945 "Show outline path and, maybe, follow mode window."
7946 (let ((m (org-get-at-bol 'org-marker)))
7947 (when (and (markerp m) (marker-buffer m))
7948 (and org-agenda-follow-mode
7949 (if org-agenda-follow-indirect
7950 (org-agenda-tree-to-indirect-buffer nil)
7951 (org-agenda-show)))
7952 (and org-agenda-show-outline-path
7953 (org-with-point-at m (org-display-outline-path t))))))
7955 (defun org-agenda-show-tags ()
7956 "Show the tags applicable to the current item."
7957 (interactive)
7958 (let* ((tags (org-get-at-bol 'tags)))
7959 (if tags
7960 (message "Tags are :%s:"
7961 (org-no-properties (mapconcat 'identity tags ":")))
7962 (message "No tags associated with this line"))))
7964 (defun org-agenda-goto (&optional highlight)
7965 "Go to the Org-mode file which contains the item at point."
7966 (interactive)
7967 (let* ((marker (or (org-get-at-bol 'org-marker)
7968 (org-agenda-error)))
7969 (buffer (marker-buffer marker))
7970 (pos (marker-position marker)))
7971 (switch-to-buffer-other-window buffer)
7972 (widen)
7973 (push-mark)
7974 (goto-char pos)
7975 (when (derived-mode-p 'org-mode)
7976 (org-show-context 'agenda)
7977 (save-excursion
7978 (and (outline-next-heading)
7979 (org-flag-heading nil)))) ; show the next heading
7980 (when (outline-invisible-p)
7981 (show-entry)) ; display invisible text
7982 (recenter (/ (window-height) 2))
7983 (run-hooks 'org-agenda-after-show-hook)
7984 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7986 (defvar org-agenda-after-show-hook nil
7987 "Normal hook run after an item has been shown from the agenda.
7988 Point is in the buffer where the item originated.")
7990 (defun org-agenda-kill ()
7991 "Kill the entry or subtree belonging to the current agenda entry."
7992 (interactive)
7993 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7994 (let* ((bufname-orig (buffer-name))
7995 (marker (or (org-get-at-bol 'org-marker)
7996 (org-agenda-error)))
7997 (buffer (marker-buffer marker))
7998 (pos (marker-position marker))
7999 (type (org-get-at-bol 'type))
8000 dbeg dend (n 0) conf)
8001 (org-with-remote-undo buffer
8002 (with-current-buffer buffer
8003 (save-excursion
8004 (goto-char pos)
8005 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8006 (setq dbeg (progn (org-back-to-heading t) (point))
8007 dend (org-end-of-subtree t t))
8008 (setq dbeg (point-at-bol)
8009 dend (min (point-max) (1+ (point-at-eol)))))
8010 (goto-char dbeg)
8011 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8012 (setq conf (or (eq t org-agenda-confirm-kill)
8013 (and (numberp org-agenda-confirm-kill)
8014 (> n org-agenda-confirm-kill))))
8015 (and conf
8016 (not (y-or-n-p
8017 (format "Delete entry with %d lines in buffer \"%s\"? "
8018 n (buffer-name buffer))))
8019 (error "Abort"))
8020 (let ((org-agenda-buffer-name bufname-orig))
8021 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8022 (with-current-buffer buffer (delete-region dbeg dend))
8023 (message "Agenda item and source killed"))))
8025 (defvar org-archive-default-command) ; defined in org-archive.el
8026 (defun org-agenda-archive-default ()
8027 "Archive the entry or subtree belonging to the current agenda entry."
8028 (interactive)
8029 (require 'org-archive)
8030 (org-agenda-archive-with org-archive-default-command))
8032 (defun org-agenda-archive-default-with-confirmation ()
8033 "Archive the entry or subtree belonging to the current agenda entry."
8034 (interactive)
8035 (require 'org-archive)
8036 (org-agenda-archive-with org-archive-default-command 'confirm))
8038 (defun org-agenda-archive ()
8039 "Archive the entry or subtree belonging to the current agenda entry."
8040 (interactive)
8041 (org-agenda-archive-with 'org-archive-subtree))
8043 (defun org-agenda-archive-to-archive-sibling ()
8044 "Move the entry to the archive sibling."
8045 (interactive)
8046 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8048 (defun org-agenda-archive-with (cmd &optional confirm)
8049 "Move the entry to the archive sibling."
8050 (interactive)
8051 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8052 (let* ((bufname-orig (buffer-name))
8053 (marker (or (org-get-at-bol 'org-marker)
8054 (org-agenda-error)))
8055 (buffer (marker-buffer marker))
8056 (pos (marker-position marker)))
8057 (org-with-remote-undo buffer
8058 (with-current-buffer buffer
8059 (if (derived-mode-p 'org-mode)
8060 (if (and confirm
8061 (not (y-or-n-p "Archive this subtree or entry? ")))
8062 (error "Abort")
8063 (save-excursion
8064 (goto-char pos)
8065 (let ((org-agenda-buffer-name bufname-orig))
8066 (org-remove-subtree-entries-from-agenda))
8067 (org-back-to-heading t)
8068 (funcall cmd)))
8069 (error "Archiving works only in Org-mode files"))))))
8071 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8072 "Remove all lines in the agenda that correspond to a given subtree.
8073 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8074 If this information is not given, the function uses the tree at point."
8075 (let ((buf (or buf (current-buffer))) m p)
8076 (save-excursion
8077 (unless (and beg end)
8078 (org-back-to-heading t)
8079 (setq beg (point))
8080 (org-end-of-subtree t)
8081 (setq end (point)))
8082 (set-buffer (get-buffer org-agenda-buffer-name))
8083 (save-excursion
8084 (goto-char (point-max))
8085 (beginning-of-line 1)
8086 (while (not (bobp))
8087 (when (and (setq m (org-get-at-bol 'org-marker))
8088 (equal buf (marker-buffer m))
8089 (setq p (marker-position m))
8090 (>= p beg)
8091 (< p end))
8092 (let ((inhibit-read-only t))
8093 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8094 (beginning-of-line 0))))))
8096 (defun org-agenda-refile (&optional goto rfloc no-update)
8097 "Refile the item at point."
8098 (interactive "P")
8099 (if (equal goto '(16))
8100 (org-refile-goto-last-stored)
8101 (let* ((buffer-orig (buffer-name))
8102 (marker (or (org-get-at-bol 'org-hd-marker)
8103 (org-agenda-error)))
8104 (buffer (marker-buffer marker))
8105 (pos (marker-position marker))
8106 (rfloc (or rfloc
8107 (org-refile-get-location
8108 (if goto "Goto" "Refile to") buffer
8109 org-refile-allow-creating-parent-nodes))))
8110 (with-current-buffer buffer
8111 (save-excursion
8112 (save-restriction
8113 (widen)
8114 (goto-char marker)
8115 (let ((org-agenda-buffer-name buffer-orig))
8116 (org-remove-subtree-entries-from-agenda))
8117 (org-refile goto buffer rfloc)))))
8118 (unless no-update (org-agenda-redo))))
8120 (defun org-agenda-open-link (&optional arg)
8121 "Open the link(s) in the current entry, if any.
8122 This looks for a link in the displayed line in the agenda.
8123 It also looks at the text of the entry itself."
8124 (interactive "P")
8125 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8126 (org-get-at-bol 'org-marker)))
8127 (buffer (and marker (marker-buffer marker)))
8128 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8129 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8130 (lk0 (car lkall))
8131 (lk (if (stringp lk0) (list lk0) lk0))
8132 (lkend (cdr lkall))
8133 trg)
8134 (cond
8135 ((and buffer lk)
8136 (mapcar (lambda(l)
8137 (with-current-buffer buffer
8138 (setq trg (and (string-match org-bracket-link-regexp l)
8139 (match-string 1 l)))
8140 (if (or (not trg) (string-match org-any-link-re trg))
8141 (save-excursion
8142 (save-restriction
8143 (widen)
8144 (goto-char marker)
8145 (when (search-forward l nil lkend)
8146 (goto-char (match-beginning 0))
8147 (org-open-at-point))))
8148 ;; This is an internal link, widen the buffer
8149 (switch-to-buffer-other-window buffer)
8150 (widen)
8151 (goto-char marker)
8152 (when (search-forward l nil lkend)
8153 (goto-char (match-beginning 0))
8154 (org-open-at-point)))))
8155 lk))
8156 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8157 (save-excursion
8158 (beginning-of-line 1)
8159 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8160 (org-open-link-from-string (match-string 1)))
8161 (t (message "No link to open here")))))
8163 (defun org-agenda-copy-local-variable (var)
8164 "Get a variable from a referenced buffer and install it here."
8165 (let ((m (org-get-at-bol 'org-marker)))
8166 (when (and m (buffer-live-p (marker-buffer m)))
8167 (org-set-local var (with-current-buffer (marker-buffer m)
8168 (symbol-value var))))))
8170 (defun org-agenda-switch-to (&optional delete-other-windows)
8171 "Go to the Org-mode file which contains the item at point."
8172 (interactive)
8173 (if (and org-return-follows-link
8174 (not (org-get-at-bol 'org-marker))
8175 (org-in-regexp org-bracket-link-regexp))
8176 (org-open-link-from-string (match-string 0))
8177 (let* ((marker (or (org-get-at-bol 'org-marker)
8178 (org-agenda-error)))
8179 (buffer (marker-buffer marker))
8180 (pos (marker-position marker)))
8181 (org-pop-to-buffer-same-window buffer)
8182 (and delete-other-windows (delete-other-windows))
8183 (widen)
8184 (goto-char pos)
8185 (when (derived-mode-p 'org-mode)
8186 (org-show-context 'agenda)
8187 (save-excursion
8188 (and (outline-next-heading)
8189 (org-flag-heading nil))) ; show the next heading
8190 (when (outline-invisible-p)
8191 (show-entry)) ; display invisible text
8192 (run-hooks 'org-agenda-after-show-hook)))))
8194 (defun org-agenda-goto-mouse (ev)
8195 "Go to the Org-mode file which contains the item at the mouse click."
8196 (interactive "e")
8197 (mouse-set-point ev)
8198 (org-agenda-goto))
8200 (defun org-agenda-show (&optional full-entry)
8201 "Display the Org-mode file which contains the item at point.
8202 With prefix argument FULL-ENTRY, make the entire entry visible
8203 if it was hidden in the outline."
8204 (interactive "P")
8205 (let ((win (selected-window)))
8206 (if full-entry
8207 (let ((org-show-entry-below t))
8208 (org-agenda-goto t))
8209 (org-agenda-goto t))
8210 (select-window win)))
8212 (defvar org-agenda-show-window nil)
8213 (defun org-agenda-show-and-scroll-up (&optional arg)
8214 "Display the Org-mode file which contains the item at point.
8215 When called repeatedly, scroll the window that is displaying the buffer.
8216 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8217 `show-subtree' to display the item, so that drawers and logbooks stay
8218 folded."
8219 (interactive "P")
8220 (let ((win (selected-window)))
8221 (if (and (window-live-p org-agenda-show-window)
8222 (eq this-command last-command))
8223 (progn
8224 (select-window org-agenda-show-window)
8225 (ignore-errors (scroll-up)))
8226 (org-agenda-goto t)
8227 (if arg (org-show-entry) (show-subtree))
8228 (setq org-agenda-show-window (selected-window)))
8229 (select-window win)))
8231 (defun org-agenda-show-scroll-down ()
8232 "Scroll down the window showing the agenda."
8233 (interactive)
8234 (let ((win (selected-window)))
8235 (when (window-live-p org-agenda-show-window)
8236 (select-window org-agenda-show-window)
8237 (ignore-errors (scroll-down))
8238 (select-window win))))
8240 (defun org-agenda-show-1 (&optional more)
8241 "Display the Org-mode file which contains the item at point.
8242 The prefix arg selects the amount of information to display:
8244 0 hide the subtree
8245 1 just show the entry according to defaults.
8246 2 show the children view
8247 3 show the subtree view
8248 4 show the entire subtree and any LOGBOOK drawers
8249 5 show the entire subtree and any drawers
8250 With prefix argument FULL-ENTRY, make the entire entry visible
8251 if it was hidden in the outline."
8252 (interactive "p")
8253 (let ((win (selected-window)))
8254 (org-agenda-goto t)
8255 (org-recenter-heading 1)
8256 (cond
8257 ((= more 0)
8258 (hide-subtree)
8259 (save-excursion
8260 (org-back-to-heading)
8261 (run-hook-with-args 'org-cycle-hook 'folded))
8262 (message "Remote: FOLDED"))
8263 ((and (org-called-interactively-p 'any) (= more 1))
8264 (message "Remote: show with default settings"))
8265 ((= more 2)
8266 (show-entry)
8267 (show-children)
8268 (save-excursion
8269 (org-back-to-heading)
8270 (run-hook-with-args 'org-cycle-hook 'children))
8271 (message "Remote: CHILDREN"))
8272 ((= more 3)
8273 (show-subtree)
8274 (save-excursion
8275 (org-back-to-heading)
8276 (run-hook-with-args 'org-cycle-hook 'subtree))
8277 (message "Remote: SUBTREE"))
8278 ((= more 4)
8279 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8280 (org-drawer-regexp
8281 (concat "^[ \t]*:\\("
8282 (mapconcat 'regexp-quote org-drawers "\\|")
8283 "\\):[ \t]*$")))
8284 (show-subtree)
8285 (save-excursion
8286 (org-back-to-heading)
8287 (org-cycle-hide-drawers 'subtree)))
8288 (message "Remote: SUBTREE AND LOGBOOK"))
8289 ((> more 4)
8290 (show-subtree)
8291 (message "Remote: SUBTREE AND ALL DRAWERS")))
8292 (select-window win)))
8294 (defun org-recenter-heading (n)
8295 (save-excursion
8296 (org-back-to-heading)
8297 (recenter n)))
8299 (defvar org-agenda-cycle-counter nil)
8300 (defun org-agenda-cycle-show (&optional n)
8301 "Show the current entry in another window, with default settings.
8302 Default settings are taken from `org-show-hierarchy-above' and siblings.
8303 When use repeatedly in immediate succession, the remote entry will cycle
8304 through visibility
8306 children -> subtree -> folded
8308 When called with a numeric prefix arg, that arg will be passed through to
8309 `org-agenda-show-1'. For the interpretation of that argument, see the
8310 docstring of `org-agenda-show-1'."
8311 (interactive "P")
8312 (if (integerp n)
8313 (setq org-agenda-cycle-counter n)
8314 (if (not (eq last-command this-command))
8315 (setq org-agenda-cycle-counter 1)
8316 (if (equal org-agenda-cycle-counter 0)
8317 (setq org-agenda-cycle-counter 2)
8318 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8319 (if (> org-agenda-cycle-counter 3)
8320 (setq org-agenda-cycle-counter 0)))))
8321 (org-agenda-show-1 org-agenda-cycle-counter))
8323 (defun org-agenda-recenter (arg)
8324 "Display the Org-mode file which contains the item at point and recenter."
8325 (interactive "P")
8326 (let ((win (selected-window)))
8327 (org-agenda-goto t)
8328 (recenter arg)
8329 (select-window win)))
8331 (defun org-agenda-show-mouse (ev)
8332 "Display the Org-mode file which contains the item at the mouse click."
8333 (interactive "e")
8334 (mouse-set-point ev)
8335 (org-agenda-show))
8337 (defun org-agenda-check-no-diary ()
8338 "Check if the entry is a diary link and abort if yes."
8339 (if (org-get-at-bol 'org-agenda-diary-link)
8340 (org-agenda-error)))
8342 (defun org-agenda-error ()
8343 (error "Command not allowed in this line"))
8345 (defun org-agenda-tree-to-indirect-buffer (arg)
8346 "Show the subtree corresponding to the current entry in an indirect buffer.
8347 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8349 With a numerical prefix ARG, go up to this level and then take that tree.
8350 With a negative numeric ARG, go up by this number of levels.
8351 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8352 use the dedicated frame)."
8353 (interactive "P")
8354 (if current-prefix-arg
8355 (org-agenda-do-tree-to-indirect-buffer arg)
8356 (let ((agenda-buffer (buffer-name))
8357 (agenda-window (selected-window))
8358 (indirect-window
8359 (and org-last-indirect-buffer
8360 (get-buffer-window org-last-indirect-buffer))))
8361 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8362 (unless (or (eq org-indirect-buffer-display 'new-frame)
8363 (eq org-indirect-buffer-display 'dedicated-frame))
8364 (unwind-protect
8365 (unless (and indirect-window (window-live-p indirect-window))
8366 (setq indirect-window (split-window agenda-window)))
8367 (and indirect-window (select-window indirect-window))
8368 (switch-to-buffer org-last-indirect-buffer :norecord)
8369 (fit-window-to-buffer indirect-window)))
8370 (select-window (get-buffer-window agenda-buffer)))))
8372 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8373 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8374 (org-agenda-check-no-diary)
8375 (let* ((marker (or (org-get-at-bol 'org-marker)
8376 (org-agenda-error)))
8377 (buffer (marker-buffer marker))
8378 (pos (marker-position marker)))
8379 (with-current-buffer buffer
8380 (save-excursion
8381 (goto-char pos)
8382 (funcall 'org-tree-to-indirect-buffer arg)))))
8384 (defvar org-last-heading-marker (make-marker)
8385 "Marker pointing to the headline that last changed its TODO state
8386 by a remote command from the agenda.")
8388 (defun org-agenda-todo-nextset ()
8389 "Switch TODO entry to next sequence."
8390 (interactive)
8391 (org-agenda-todo 'nextset))
8393 (defun org-agenda-todo-previousset ()
8394 "Switch TODO entry to previous sequence."
8395 (interactive)
8396 (org-agenda-todo 'previousset))
8398 (defun org-agenda-todo (&optional arg)
8399 "Cycle TODO state of line at point, also in Org-mode file.
8400 This changes the line at point, all other lines in the agenda referring to
8401 the same tree node, and the headline of the tree node in the Org-mode file."
8402 (interactive "P")
8403 (org-agenda-check-no-diary)
8404 (let* ((col (current-column))
8405 (marker (or (org-get-at-bol 'org-marker)
8406 (org-agenda-error)))
8407 (buffer (marker-buffer marker))
8408 (pos (marker-position marker))
8409 (hdmarker (org-get-at-bol 'org-hd-marker))
8410 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8411 (inhibit-read-only t)
8412 org-agenda-headline-snapshot-before-repeat newhead just-one)
8413 (org-with-remote-undo buffer
8414 (with-current-buffer buffer
8415 (widen)
8416 (goto-char pos)
8417 (org-show-context 'agenda)
8418 (save-excursion
8419 (and (outline-next-heading)
8420 (org-flag-heading nil))) ; show the next heading
8421 (let ((current-prefix-arg arg))
8422 (call-interactively 'org-todo))
8423 (and (bolp) (forward-char 1))
8424 (setq newhead (org-get-heading))
8425 (when (and (org-bound-and-true-p
8426 org-agenda-headline-snapshot-before-repeat)
8427 (not (equal org-agenda-headline-snapshot-before-repeat
8428 newhead))
8429 todayp)
8430 (setq newhead org-agenda-headline-snapshot-before-repeat
8431 just-one t))
8432 (save-excursion
8433 (org-back-to-heading)
8434 (move-marker org-last-heading-marker (point))))
8435 (beginning-of-line 1)
8436 (save-excursion
8437 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8438 (org-move-to-column col))))
8440 (defun org-agenda-add-note (&optional arg)
8441 "Add a time-stamped note to the entry at point."
8442 (interactive "P")
8443 (org-agenda-check-no-diary)
8444 (let* ((marker (or (org-get-at-bol 'org-marker)
8445 (org-agenda-error)))
8446 (buffer (marker-buffer marker))
8447 (pos (marker-position marker))
8448 (hdmarker (org-get-at-bol 'org-hd-marker))
8449 (inhibit-read-only t))
8450 (with-current-buffer buffer
8451 (widen)
8452 (goto-char pos)
8453 (org-show-context 'agenda)
8454 (save-excursion
8455 (and (outline-next-heading)
8456 (org-flag-heading nil))) ; show the next heading
8457 (org-add-note))))
8459 (defun org-agenda-change-all-lines (newhead hdmarker
8460 &optional fixface just-this)
8461 "Change all lines in the agenda buffer which match HDMARKER.
8462 The new content of the line will be NEWHEAD (as modified by
8463 `org-agenda-format-item'). HDMARKER is checked with
8464 `equal' against all `org-hd-marker' text properties in the file.
8465 If FIXFACE is non-nil, the face of each item is modified according to
8466 the new TODO state.
8467 If JUST-THIS is non-nil, change just the current line, not all.
8468 If FORCE-TAGS is non nil, the car of it returns the new tags."
8469 (let* ((inhibit-read-only t)
8470 (line (org-current-line))
8471 (org-agenda-buffer (current-buffer))
8472 (thetags (with-current-buffer (marker-buffer hdmarker)
8473 (save-excursion (save-restriction (widen)
8474 (goto-char hdmarker)
8475 (org-get-tags-at)))))
8476 props m pl undone-face done-face finish new dotime level cat tags)
8477 (save-excursion
8478 (goto-char (point-max))
8479 (beginning-of-line 1)
8480 (while (not finish)
8481 (setq finish (bobp))
8482 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8483 (or (not just-this) (= (org-current-line) line))
8484 (equal m hdmarker))
8485 (setq props (text-properties-at (point))
8486 dotime (org-get-at-bol 'dotime)
8487 cat (org-get-at-bol 'org-category)
8488 level (org-get-at-bol 'level)
8489 tags thetags
8491 (let ((org-prefix-format-compiled
8492 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8493 org-prefix-format-compiled))
8494 (extra (org-get-at-bol 'extra)))
8495 (with-current-buffer (marker-buffer hdmarker)
8496 (save-excursion
8497 (save-restriction
8498 (widen)
8499 (org-agenda-format-item extra newhead level cat tags dotime)))))
8500 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8501 undone-face (org-get-at-bol 'undone-face)
8502 done-face (org-get-at-bol 'done-face))
8503 (beginning-of-line 1)
8504 (cond
8505 ((equal new "")
8506 (and (looking-at ".*\n?") (replace-match "")))
8507 ((looking-at ".*")
8508 (replace-match new t t)
8509 (beginning-of-line 1)
8510 (add-text-properties (point-at-bol) (point-at-eol) props)
8511 (when fixface
8512 (add-text-properties
8513 (point-at-bol) (point-at-eol)
8514 (list 'face
8515 (if org-last-todo-state-is-todo
8516 undone-face done-face))))
8517 (org-agenda-highlight-todo 'line)
8518 (beginning-of-line 1))
8519 (t (error "Line update did not work")))
8520 (save-restriction
8521 (narrow-to-region (point-at-bol) (point-at-eol))
8522 (org-agenda-finalize)))
8523 (beginning-of-line 0)))))
8525 (defun org-agenda-align-tags (&optional line)
8526 "Align all tags in agenda items to `org-agenda-tags-column'."
8527 (let ((inhibit-read-only t) l c)
8528 (save-excursion
8529 (goto-char (if line (point-at-bol) (point-min)))
8530 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8531 (if line (point-at-eol) nil) t)
8532 (add-text-properties
8533 (match-beginning 2) (match-end 2)
8534 (list 'face (delq nil (let ((prop (get-text-property
8535 (match-beginning 2) 'face)))
8536 (or (listp prop) (setq prop (list prop)))
8537 (if (memq 'org-tag prop)
8538 prop
8539 (cons 'org-tag prop))))))
8540 (setq l (- (match-end 2) (match-beginning 2))
8541 c (if (< org-agenda-tags-column 0)
8542 (- (abs org-agenda-tags-column) l)
8543 org-agenda-tags-column))
8544 (delete-region (match-beginning 1) (match-end 1))
8545 (goto-char (match-beginning 1))
8546 (insert (org-add-props
8547 (make-string (max 1 (- c (current-column))) ?\ )
8548 (plist-put (copy-sequence (text-properties-at (point)))
8549 'face nil))))
8550 (goto-char (point-min))
8551 (org-font-lock-add-tag-faces (point-max)))))
8553 (defun org-agenda-priority-up ()
8554 "Increase the priority of line at point, also in Org-mode file."
8555 (interactive)
8556 (org-agenda-priority 'up))
8558 (defun org-agenda-priority-down ()
8559 "Decrease the priority of line at point, also in Org-mode file."
8560 (interactive)
8561 (org-agenda-priority 'down))
8563 (defun org-agenda-priority (&optional force-direction)
8564 "Set the priority of line at point, also in Org-mode file.
8565 This changes the line at point, all other lines in the agenda referring to
8566 the same tree node, and the headline of the tree node in the Org-mode file.
8567 Called with a universal prefix arg, show the priority instead of setting it."
8568 (interactive "P")
8569 (if (equal force-direction '(4))
8570 (org-show-priority)
8571 (unless org-enable-priority-commands
8572 (error "Priority commands are disabled"))
8573 (org-agenda-check-no-diary)
8574 (let* ((marker (or (org-get-at-bol 'org-marker)
8575 (org-agenda-error)))
8576 (hdmarker (org-get-at-bol 'org-hd-marker))
8577 (buffer (marker-buffer hdmarker))
8578 (pos (marker-position hdmarker))
8579 (inhibit-read-only t)
8580 newhead)
8581 (org-with-remote-undo buffer
8582 (with-current-buffer buffer
8583 (widen)
8584 (goto-char pos)
8585 (org-show-context 'agenda)
8586 (save-excursion
8587 (and (outline-next-heading)
8588 (org-flag-heading nil))) ; show the next heading
8589 (funcall 'org-priority force-direction)
8590 (end-of-line 1)
8591 (setq newhead (org-get-heading)))
8592 (org-agenda-change-all-lines newhead hdmarker)
8593 (beginning-of-line 1)))))
8595 ;; FIXME: should fix the tags property of the agenda line.
8596 (defun org-agenda-set-tags (&optional tag onoff)
8597 "Set tags for the current headline."
8598 (interactive)
8599 (org-agenda-check-no-diary)
8600 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8601 (call-interactively 'org-change-tag-in-region)
8602 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8603 (org-agenda-error)))
8604 (buffer (marker-buffer hdmarker))
8605 (pos (marker-position hdmarker))
8606 (inhibit-read-only t)
8607 newhead)
8608 (org-with-remote-undo buffer
8609 (with-current-buffer buffer
8610 (widen)
8611 (goto-char pos)
8612 (save-excursion
8613 (org-show-context 'agenda))
8614 (save-excursion
8615 (and (outline-next-heading)
8616 (org-flag-heading nil))) ; show the next heading
8617 (goto-char pos)
8618 (if tag
8619 (org-toggle-tag tag onoff)
8620 (call-interactively 'org-set-tags))
8621 (end-of-line 1)
8622 (setq newhead (org-get-heading)))
8623 (org-agenda-change-all-lines newhead hdmarker)
8624 (beginning-of-line 1)))))
8626 (defun org-agenda-set-property ()
8627 "Set a property for the current headline."
8628 (interactive)
8629 (org-agenda-check-no-diary)
8630 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8631 (org-agenda-error)))
8632 (buffer (marker-buffer hdmarker))
8633 (pos (marker-position hdmarker))
8634 (inhibit-read-only t)
8635 newhead)
8636 (org-with-remote-undo buffer
8637 (with-current-buffer buffer
8638 (widen)
8639 (goto-char pos)
8640 (save-excursion
8641 (org-show-context 'agenda))
8642 (save-excursion
8643 (and (outline-next-heading)
8644 (org-flag-heading nil))) ; show the next heading
8645 (goto-char pos)
8646 (call-interactively 'org-set-property)))))
8648 (defun org-agenda-set-effort ()
8649 "Set the effort property for the current headline."
8650 (interactive)
8651 (org-agenda-check-no-diary)
8652 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8653 (org-agenda-error)))
8654 (buffer (marker-buffer hdmarker))
8655 (pos (marker-position hdmarker))
8656 (inhibit-read-only t)
8657 newhead)
8658 (org-with-remote-undo buffer
8659 (with-current-buffer buffer
8660 (widen)
8661 (goto-char pos)
8662 (save-excursion
8663 (org-show-context 'agenda))
8664 (save-excursion
8665 (and (outline-next-heading)
8666 (org-flag-heading nil))) ; show the next heading
8667 (goto-char pos)
8668 (call-interactively 'org-set-effort)
8669 (end-of-line 1)
8670 (setq newhead (org-get-heading)))
8671 (org-agenda-change-all-lines newhead hdmarker))))
8673 (defun org-agenda-toggle-archive-tag ()
8674 "Toggle the archive tag for the current entry."
8675 (interactive)
8676 (org-agenda-check-no-diary)
8677 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8678 (org-agenda-error)))
8679 (buffer (marker-buffer hdmarker))
8680 (pos (marker-position hdmarker))
8681 (inhibit-read-only t)
8682 newhead)
8683 (org-with-remote-undo buffer
8684 (with-current-buffer buffer
8685 (widen)
8686 (goto-char pos)
8687 (org-show-context 'agenda)
8688 (save-excursion
8689 (and (outline-next-heading)
8690 (org-flag-heading nil))) ; show the next heading
8691 (call-interactively 'org-toggle-archive-tag)
8692 (end-of-line 1)
8693 (setq newhead (org-get-heading)))
8694 (org-agenda-change-all-lines newhead hdmarker)
8695 (beginning-of-line 1))))
8697 (defun org-agenda-do-date-later (arg)
8698 (interactive "P")
8699 (cond
8700 ((or (equal arg '(16))
8701 (memq last-command
8702 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8703 (setq this-command 'org-agenda-date-later-minutes)
8704 (org-agenda-date-later-minutes 1))
8705 ((or (equal arg '(4))
8706 (memq last-command
8707 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8708 (setq this-command 'org-agenda-date-later-hours)
8709 (org-agenda-date-later-hours 1))
8711 (org-agenda-date-later (prefix-numeric-value arg)))))
8713 (defun org-agenda-do-date-earlier (arg)
8714 (interactive "P")
8715 (cond
8716 ((or (equal arg '(16))
8717 (memq last-command
8718 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8719 (setq this-command 'org-agenda-date-earlier-minutes)
8720 (org-agenda-date-earlier-minutes 1))
8721 ((or (equal arg '(4))
8722 (memq last-command
8723 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8724 (setq this-command 'org-agenda-date-earlier-hours)
8725 (org-agenda-date-earlier-hours 1))
8727 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8729 (defun org-agenda-date-later (arg &optional what)
8730 "Change the date of this item to ARG day(s) later."
8731 (interactive "p")
8732 (org-agenda-check-type t 'agenda 'timeline)
8733 (org-agenda-check-no-diary)
8734 (let* ((marker (or (org-get-at-bol 'org-marker)
8735 (org-agenda-error)))
8736 (buffer (marker-buffer marker))
8737 (pos (marker-position marker))
8738 cdate today)
8739 (org-with-remote-undo buffer
8740 (with-current-buffer buffer
8741 (widen)
8742 (goto-char pos)
8743 (if (not (org-at-timestamp-p))
8744 (error "Cannot find time stamp"))
8745 (when (and org-agenda-move-date-from-past-immediately-to-today
8746 (equal arg 1)
8747 (or (not what) (eq what 'day))
8748 (not (save-match-data (org-at-date-range-p))))
8749 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8750 cdate (calendar-absolute-from-gregorian
8751 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8752 today (org-today))
8753 (if (> today cdate)
8754 ;; immediately shift to today
8755 (setq arg (- today cdate))))
8756 (org-timestamp-change arg (or what 'day))
8757 (when (and (org-at-date-range-p)
8758 (re-search-backward org-tr-regexp-both (point-at-bol)))
8759 (let ((end org-last-changed-timestamp))
8760 (org-timestamp-change arg (or what 'day))
8761 (setq org-last-changed-timestamp
8762 (concat org-last-changed-timestamp "--" end)))))
8763 (org-agenda-show-new-time marker org-last-changed-timestamp))
8764 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8766 (defun org-agenda-date-earlier (arg &optional what)
8767 "Change the date of this item to ARG day(s) earlier."
8768 (interactive "p")
8769 (org-agenda-date-later (- arg) what))
8771 (defun org-agenda-date-later-minutes (arg)
8772 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8773 (interactive "p")
8774 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8775 (org-agenda-date-later arg 'minute))
8777 (defun org-agenda-date-earlier-minutes (arg)
8778 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8779 (interactive "p")
8780 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8781 (org-agenda-date-earlier arg 'minute))
8783 (defun org-agenda-date-later-hours (arg)
8784 "Change the time of this item, in hour steps."
8785 (interactive "p")
8786 (org-agenda-date-later arg 'hour))
8788 (defun org-agenda-date-earlier-hours (arg)
8789 "Change the time of this item, in hour steps."
8790 (interactive "p")
8791 (org-agenda-date-earlier arg 'hour))
8793 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8794 "Show new date stamp via text properties."
8795 ;; We use text properties to make this undoable
8796 (let ((inhibit-read-only t)
8797 (buffer-invisibility-spec))
8798 (setq stamp (concat " " prefix " => " stamp))
8799 (save-excursion
8800 (goto-char (point-max))
8801 (while (not (bobp))
8802 (when (equal marker (org-get-at-bol 'org-marker))
8803 (org-move-to-column (- (window-width) (length stamp)) t)
8804 (org-agenda-fix-tags-filter-overlays-at (point))
8805 (if (featurep 'xemacs)
8806 ;; Use `duplicable' property to trigger undo recording
8807 (let ((ex (make-extent nil nil))
8808 (gl (make-glyph stamp)))
8809 (set-glyph-face gl 'secondary-selection)
8810 (set-extent-properties
8811 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8812 (insert-extent ex (1- (point)) (point-at-eol)))
8813 (add-text-properties
8814 (1- (point)) (point-at-eol)
8815 (list 'display (org-add-props stamp nil
8816 'face 'secondary-selection))))
8817 (beginning-of-line 1))
8818 (beginning-of-line 0)))))
8820 (defun org-agenda-date-prompt (arg)
8821 "Change the date of this item. Date is prompted for, with default today.
8822 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8823 be used to request time specification in the time stamp."
8824 (interactive "P")
8825 (org-agenda-check-type t 'agenda 'timeline)
8826 (org-agenda-check-no-diary)
8827 (let* ((marker (or (org-get-at-bol 'org-marker)
8828 (org-agenda-error)))
8829 (buffer (marker-buffer marker))
8830 (pos (marker-position marker)))
8831 (org-with-remote-undo buffer
8832 (with-current-buffer buffer
8833 (widen)
8834 (goto-char pos)
8835 (if (not (org-at-timestamp-p t))
8836 (error "Cannot find time stamp"))
8837 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8838 (org-agenda-show-new-time marker org-last-changed-timestamp))
8839 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8841 (defun org-agenda-schedule (arg &optional time)
8842 "Schedule the item at point.
8843 ARG is passed through to `org-schedule'."
8844 (interactive "P")
8845 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8846 (org-agenda-check-no-diary)
8847 (let* ((marker (or (org-get-at-bol 'org-marker)
8848 (org-agenda-error)))
8849 (type (marker-insertion-type marker))
8850 (buffer (marker-buffer marker))
8851 (pos (marker-position marker))
8852 (org-insert-labeled-timestamps-at-point nil)
8854 (set-marker-insertion-type marker t)
8855 (org-with-remote-undo buffer
8856 (with-current-buffer buffer
8857 (widen)
8858 (goto-char pos)
8859 (setq ts (org-schedule arg time)))
8860 (org-agenda-show-new-time marker ts "S"))
8861 (message "%s" ts)))
8863 (defun org-agenda-deadline (arg &optional time)
8864 "Schedule the item at point.
8865 ARG is passed through to `org-deadline'."
8866 (interactive "P")
8867 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8868 (org-agenda-check-no-diary)
8869 (let* ((marker (or (org-get-at-bol 'org-marker)
8870 (org-agenda-error)))
8871 (buffer (marker-buffer marker))
8872 (pos (marker-position marker))
8873 (org-insert-labeled-timestamps-at-point nil)
8875 (org-with-remote-undo buffer
8876 (with-current-buffer buffer
8877 (widen)
8878 (goto-char pos)
8879 (setq ts (org-deadline arg time)))
8880 (org-agenda-show-new-time marker ts "D"))
8881 (message "%s" ts)))
8883 (defun org-agenda-clock-in (&optional arg)
8884 "Start the clock on the currently selected item."
8885 (interactive "P")
8886 (org-agenda-check-no-diary)
8887 (if (equal arg '(4))
8888 (org-clock-in arg)
8889 (let* ((marker (or (org-get-at-bol 'org-marker)
8890 (org-agenda-error)))
8891 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8892 marker))
8893 (pos (marker-position marker))
8894 newhead)
8895 (org-with-remote-undo (marker-buffer marker)
8896 (with-current-buffer (marker-buffer marker)
8897 (widen)
8898 (goto-char pos)
8899 (org-show-context 'agenda)
8900 (org-show-entry)
8901 (org-cycle-hide-drawers 'children)
8902 (org-clock-in arg)
8903 (setq newhead (org-get-heading)))
8904 (org-agenda-change-all-lines newhead hdmarker)))))
8906 (defun org-agenda-clock-out ()
8907 "Stop the currently running clock."
8908 (interactive)
8909 (unless (marker-buffer org-clock-marker)
8910 (error "No running clock"))
8911 (let ((marker (make-marker)) newhead)
8912 (org-with-remote-undo (marker-buffer org-clock-marker)
8913 (with-current-buffer (marker-buffer org-clock-marker)
8914 (save-excursion
8915 (save-restriction
8916 (widen)
8917 (goto-char org-clock-marker)
8918 (org-back-to-heading t)
8919 (move-marker marker (point))
8920 (org-clock-out)
8921 (setq newhead (org-get-heading))))))
8922 (org-agenda-change-all-lines newhead marker)
8923 (move-marker marker nil)))
8925 (defun org-agenda-clock-cancel (&optional arg)
8926 "Cancel the currently running clock."
8927 (interactive "P")
8928 (unless (marker-buffer org-clock-marker)
8929 (error "No running clock"))
8930 (org-with-remote-undo (marker-buffer org-clock-marker)
8931 (org-clock-cancel)))
8933 (defun org-agenda-clock-goto ()
8934 "Jump to the currently clocked in task within the agenda.
8935 If the currently clocked in task is not listed in the agenda
8936 buffer, display it in another window."
8937 (interactive)
8938 (let (pos)
8939 (mapc (lambda (o)
8940 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8941 (setq pos (overlay-start o))))
8942 (overlays-in (point-min) (point-max)))
8943 (cond (pos (goto-char pos))
8944 ;; If the currently clocked entry is not in the agenda
8945 ;; buffer, we visit it in another window:
8946 (org-clock-current-task
8947 (org-switch-to-buffer-other-window (org-clock-goto)))
8948 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8950 (defun org-agenda-diary-entry-in-org-file ()
8951 "Make a diary entry in the file `org-agenda-diary-file'."
8952 (let (d1 d2 char (text "") dp1 dp2)
8953 (if (equal (buffer-name) "*Calendar*")
8954 (setq d1 (calendar-cursor-to-date t)
8955 d2 (car calendar-mark-ring))
8956 (setq dp1 (get-text-property (point-at-bol) 'day))
8957 (unless dp1 (error "No date defined in current line"))
8958 (setq d1 (calendar-gregorian-from-absolute dp1)
8959 d2 (and (ignore-errors (mark))
8960 (save-excursion
8961 (goto-char (mark))
8962 (setq dp2 (get-text-property (point-at-bol) 'day)))
8963 (calendar-gregorian-from-absolute dp2))))
8964 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8965 (setq char (read-char-exclusive))
8966 (cond
8967 ((equal char ?d)
8968 (setq text (read-string "Day entry: "))
8969 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8970 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8971 ((equal char ?a)
8972 (setq d1 (list (car d1) (nth 1 d1)
8973 (read-number (format "Reference year [%d]: " (nth 2 d1))
8974 (nth 2 d1))))
8975 (setq text (read-string "Anniversary (use %d to show years): "))
8976 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8977 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8978 ((equal char ?b)
8979 (setq text (read-string "Block entry: "))
8980 (unless (and d1 d2 (not (equal d1 d2)))
8981 (error "No block of days selected"))
8982 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8983 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8984 ((equal char ?j)
8985 (org-switch-to-buffer-other-window
8986 (find-file-noselect org-agenda-diary-file))
8987 (require 'org-datetree)
8988 (org-datetree-find-date-create d1)
8989 (org-reveal t))
8990 (t (error "Invalid selection character `%c'" char)))))
8992 (defcustom org-agenda-insert-diary-strategy 'date-tree
8993 "Where in `org-agenda-diary-file' should new entries be added?
8994 Valid values:
8996 date-tree in the date tree, as child of the date
8997 top-level as top-level entries at the end of the file."
8998 :group 'org-agenda
8999 :type '(choice
9000 (const :tag "in a date tree" date-tree)
9001 (const :tag "as top level at end of file" top-level)))
9003 (defcustom org-agenda-insert-diary-extract-time nil
9004 "Non-nil means extract any time specification from the diary entry."
9005 :group 'org-agenda
9006 :version "24.1"
9007 :type 'boolean)
9009 (defcustom org-agenda-bulk-mark-char ">"
9010 "A single-character string to be used as the bulk mark."
9011 :group 'org-agenda
9012 :version "24.1"
9013 :type 'string)
9015 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9016 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9017 If TEXT is not empty, it will become the headline of the new entry, and
9018 the resulting entry will not be shown. When TEXT is empty, switch to
9019 `org-agenda-diary-file' and let the user finish the entry there."
9020 (let ((cw (current-window-configuration)))
9021 (org-switch-to-buffer-other-window
9022 (find-file-noselect org-agenda-diary-file))
9023 (widen)
9024 (goto-char (point-min))
9025 (cond
9026 ((eq type 'anniversary)
9027 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9028 (progn
9029 (or (org-at-heading-p t)
9030 (progn
9031 (outline-next-heading)
9032 (insert "* Anniversaries\n\n")
9033 (beginning-of-line -1)))))
9034 (outline-next-heading)
9035 (org-back-over-empty-lines)
9036 (backward-char 1)
9037 (insert "\n")
9038 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9039 (nth 2 d1) (car d1) (nth 1 d1) text)))
9040 ((eq type 'day)
9041 (let ((org-prefix-has-time t)
9042 (org-agenda-time-leading-zero t)
9043 fmt time time2)
9044 (if org-agenda-insert-diary-extract-time
9045 ;; Use org-agenda-format-item to parse text for a time-range and
9046 ;; remove it. FIXME: This is a hack, we should refactor
9047 ;; that function to make time extraction available separately
9048 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9049 time (get-text-property 0 'time fmt)
9050 time2 (if (> (length time) 0)
9051 ;; split-string removes trailing ...... if
9052 ;; no end time given. First space
9053 ;; separates time from date.
9054 (concat " " (car (split-string time "\\.")))
9055 nil)
9056 text (get-text-property 0 'txt fmt)))
9057 (if (eq org-agenda-insert-diary-strategy 'top-level)
9058 (org-agenda-insert-diary-as-top-level text)
9059 (require 'org-datetree)
9060 (org-datetree-find-date-create d1)
9061 (org-agenda-insert-diary-make-new-entry text))
9062 (org-insert-time-stamp (org-time-from-absolute
9063 (calendar-absolute-from-gregorian d1))
9064 nil nil nil nil time2))
9065 (end-of-line 0))
9066 ((eq type 'block)
9067 (if (> (calendar-absolute-from-gregorian d1)
9068 (calendar-absolute-from-gregorian d2))
9069 (setq d1 (prog1 d2 (setq d2 d1))))
9070 (if (eq org-agenda-insert-diary-strategy 'top-level)
9071 (org-agenda-insert-diary-as-top-level text)
9072 (require 'org-datetree)
9073 (org-datetree-find-date-create d1)
9074 (org-agenda-insert-diary-make-new-entry text))
9075 (org-insert-time-stamp (org-time-from-absolute
9076 (calendar-absolute-from-gregorian d1)))
9077 (insert "--")
9078 (org-insert-time-stamp (org-time-from-absolute
9079 (calendar-absolute-from-gregorian d2)))
9080 (end-of-line 0)))
9081 (if (string-match "\\S-" text)
9082 (progn
9083 (set-window-configuration cw)
9084 (message "%s entry added to %s"
9085 (capitalize (symbol-name type))
9086 (abbreviate-file-name org-agenda-diary-file)))
9087 (org-reveal t)
9088 (message "Please finish entry here"))))
9090 (defun org-agenda-insert-diary-as-top-level (text)
9091 "Make new entry as a top-level entry at the end of the file.
9092 Add TEXT as headline, and position the cursor in the second line so that
9093 a timestamp can be added there."
9094 (widen)
9095 (goto-char (point-max))
9096 (or (bolp) (insert "\n"))
9097 (insert "* " text "\n")
9098 (if org-adapt-indentation (org-indent-to-column 2)))
9100 (defun org-agenda-insert-diary-make-new-entry (text)
9101 "Make new entry as last child of current entry.
9102 Add TEXT as headline, and position the cursor in the second line so that
9103 a timestamp can be added there."
9104 (let ((org-show-following-heading t)
9105 (org-show-siblings t)
9106 (org-show-hierarchy-above t)
9107 (org-show-entry-below t)
9108 col)
9109 (outline-next-heading)
9110 (org-back-over-empty-lines)
9111 (or (looking-at "[ \t]*$")
9112 (progn (insert "\n") (backward-char 1)))
9113 (org-insert-heading nil t)
9114 (org-do-demote)
9115 (setq col (current-column))
9116 (insert text "\n")
9117 (if org-adapt-indentation (org-indent-to-column col))
9118 (let ((org-show-following-heading t)
9119 (org-show-siblings t)
9120 (org-show-hierarchy-above t)
9121 (org-show-entry-below t))
9122 (org-show-context))))
9124 (defun org-agenda-diary-entry ()
9125 "Make a diary entry, like the `i' command from the calendar.
9126 All the standard commands work: block, weekly etc.
9127 When `org-agenda-diary-file' points to a file,
9128 `org-agenda-diary-entry-in-org-file' is called instead to create
9129 entries in that Org-mode file."
9130 (interactive)
9131 (if (not (eq org-agenda-diary-file 'diary-file))
9132 (org-agenda-diary-entry-in-org-file)
9133 (require 'diary-lib)
9134 (let* ((char (progn
9135 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9136 (read-char-exclusive)))
9137 (cmd (cdr (assoc char
9138 '((?d . insert-diary-entry)
9139 (?w . insert-weekly-diary-entry)
9140 (?m . insert-monthly-diary-entry)
9141 (?y . insert-yearly-diary-entry)
9142 (?a . insert-anniversary-diary-entry)
9143 (?b . insert-block-diary-entry)
9144 (?c . insert-cyclic-diary-entry)))))
9145 (oldf (symbol-function 'calendar-cursor-to-date))
9146 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9147 (point (point))
9148 (mark (or (mark t) (point))))
9149 (unless cmd
9150 (error "No command associated with <%c>" char))
9151 (unless (and (get-text-property point 'day)
9152 (or (not (equal ?b char))
9153 (get-text-property mark 'day)))
9154 (error "Don't know which date to use for diary entry"))
9155 ;; We implement this by hacking the `calendar-cursor-to-date' function
9156 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9157 (let ((calendar-mark-ring
9158 (list (calendar-gregorian-from-absolute
9159 (or (get-text-property mark 'day)
9160 (get-text-property point 'day))))))
9161 (unwind-protect
9162 (progn
9163 (fset 'calendar-cursor-to-date
9164 (lambda (&optional error dummy)
9165 (calendar-gregorian-from-absolute
9166 (get-text-property point 'day))))
9167 (call-interactively cmd))
9168 (fset 'calendar-cursor-to-date oldf))))))
9170 (defun org-agenda-execute-calendar-command (cmd)
9171 "Execute a calendar command from the agenda with date from cursor."
9172 (org-agenda-check-type t 'agenda 'timeline)
9173 (require 'diary-lib)
9174 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9175 (error "Don't know which date to use for the calendar command"))
9176 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9177 (point (point))
9178 (date (calendar-gregorian-from-absolute
9179 (get-text-property point 'day)))
9180 ;; the following 2 vars are needed in the calendar
9181 (displayed-month (car date))
9182 (displayed-year (nth 2 date)))
9183 (unwind-protect
9184 (progn
9185 (fset 'calendar-cursor-to-date
9186 (lambda (&optional error dummy)
9187 (calendar-gregorian-from-absolute
9188 (get-text-property point 'day))))
9189 (call-interactively cmd))
9190 (fset 'calendar-cursor-to-date oldf))))
9192 (defun org-agenda-phases-of-moon ()
9193 "Display the phases of the moon for the 3 months around the cursor date."
9194 (interactive)
9195 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9197 (defun org-agenda-holidays ()
9198 "Display the holidays for the 3 months around the cursor date."
9199 (interactive)
9200 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9202 (defvar calendar-longitude) ; defined in calendar.el
9203 (defvar calendar-latitude) ; defined in calendar.el
9204 (defvar calendar-location-name) ; defined in calendar.el
9206 (defun org-agenda-sunrise-sunset (arg)
9207 "Display sunrise and sunset for the cursor date.
9208 Latitude and longitude can be specified with the variables
9209 `calendar-latitude' and `calendar-longitude'. When called with prefix
9210 argument, latitude and longitude will be prompted for."
9211 (interactive "P")
9212 (require 'solar)
9213 (let ((calendar-longitude (if arg nil calendar-longitude))
9214 (calendar-latitude (if arg nil calendar-latitude))
9215 (calendar-location-name
9216 (if arg "the given coordinates" calendar-location-name)))
9217 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9219 (defun org-agenda-goto-calendar ()
9220 "Open the Emacs calendar with the date at the cursor."
9221 (interactive)
9222 (org-agenda-check-type t 'agenda 'timeline)
9223 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9224 (error "Don't know which date to open in calendar")))
9225 (date (calendar-gregorian-from-absolute day))
9226 (calendar-move-hook nil)
9227 (calendar-view-holidays-initially-flag nil)
9228 (calendar-view-diary-initially-flag nil))
9229 (calendar)
9230 (calendar-goto-date date)))
9232 ;;;###autoload
9233 (defun org-calendar-goto-agenda ()
9234 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9235 This is a command that has to be installed in `calendar-mode-map'."
9236 (interactive)
9237 (org-agenda-list nil (calendar-absolute-from-gregorian
9238 (calendar-cursor-to-date))
9239 nil))
9241 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9242 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9243 This is a command that has to be installed in `calendar-mode-map'.
9245 \(fn)" t nil)
9247 (defun org-agenda-convert-date ()
9248 (interactive)
9249 (org-agenda-check-type t 'agenda 'timeline)
9250 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9251 date s)
9252 (unless day
9253 (error "Don't know which date to convert"))
9254 (setq date (calendar-gregorian-from-absolute day))
9255 (setq s (concat
9256 "Gregorian: " (calendar-date-string date) "\n"
9257 "ISO: " (calendar-iso-date-string date) "\n"
9258 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9259 "Julian: " (calendar-julian-date-string date) "\n"
9260 "Astron. JD: " (calendar-astro-date-string date)
9261 " (Julian date number at noon UTC)\n"
9262 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9263 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9264 "French: " (calendar-french-date-string date) "\n"
9265 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9266 "Mayan: " (calendar-mayan-date-string date) "\n"
9267 "Coptic: " (calendar-coptic-date-string date) "\n"
9268 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9269 "Persian: " (calendar-persian-date-string date) "\n"
9270 "Chinese: " (calendar-chinese-date-string date) "\n"))
9271 (with-output-to-temp-buffer "*Dates*"
9272 (princ s))
9273 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9275 ;;; Bulk commands
9277 (defun org-agenda-bulk-marked-p ()
9278 (eq (get-char-property (point-at-bol) 'type)
9279 'org-marked-entry-overlay))
9281 (defun org-agenda-bulk-mark (&optional arg)
9282 "Mark the entry at point for future bulk action."
9283 (interactive "p")
9284 (dotimes (i (or arg 1))
9285 (unless (org-get-at-bol 'org-agenda-diary-link)
9286 (let* ((m (org-get-at-bol 'org-hd-marker))
9288 (unless (org-agenda-bulk-marked-p)
9289 (unless m (error "Nothing to mark at point"))
9290 (push m org-agenda-bulk-marked-entries)
9291 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9292 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9293 (org-get-todo-face "TODO")
9294 'evaporate)
9295 (overlay-put ov 'type 'org-marked-entry-overlay))
9296 (beginning-of-line 2)
9297 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9298 (beginning-of-line 2))
9299 (message "%d entries marked for bulk action"
9300 (length org-agenda-bulk-marked-entries))))))
9302 (defun org-agenda-bulk-mark-all ()
9303 "Mark all entries for future agenda bulk action."
9304 (interactive)
9305 (org-agenda-bulk-mark-regexp "."))
9307 (defun org-agenda-bulk-mark-regexp (regexp)
9308 "Mark entries matching REGEXP for future agenda bulk action."
9309 (interactive "sMark entries matching regexp: ")
9310 (let ((entries-marked 0))
9311 (save-excursion
9312 (goto-char (point-min))
9313 (goto-char (next-single-property-change (point) 'txt))
9314 (while (re-search-forward regexp nil t)
9315 (when (string-match regexp (get-text-property (point) 'txt))
9316 (setq entries-marked (1+ entries-marked))
9317 (call-interactively 'org-agenda-bulk-mark))))
9318 (if (not entries-marked)
9319 (message "No entry matching this regexp."))))
9321 (defun org-agenda-bulk-unmark (&optional arg)
9322 "Unmark the entry at point for future bulk action."
9323 (interactive "P")
9324 (if arg
9325 (org-agenda-bulk-unmark-all)
9326 (cond ((org-agenda-bulk-marked-p)
9327 (org-agenda-bulk-remove-overlays
9328 (point-at-bol) (+ 2 (point-at-bol)))
9329 (setq org-agenda-bulk-marked-entries
9330 (delete (org-get-at-bol 'org-hd-marker)
9331 org-agenda-bulk-marked-entries))
9332 (beginning-of-line 2)
9333 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9334 (beginning-of-line 2))
9335 (message "%d entries left marked for bulk action"
9336 (length org-agenda-bulk-marked-entries)))
9337 (t (message "No entry to unmark here")))))
9339 (defun org-agenda-bulk-toggle ()
9340 "Toggle marking the entry at point for bulk action."
9341 (interactive)
9342 (if (org-agenda-bulk-marked-p)
9343 (org-agenda-bulk-unmark)
9344 (org-agenda-bulk-mark)))
9346 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9347 "Remove the mark overlays between BEG and END in the agenda buffer.
9348 BEG and END default to the buffer limits.
9350 This only removes the overlays, it does not remove the markers
9351 from the list in `org-agenda-bulk-marked-entries'."
9352 (interactive)
9353 (mapc (lambda (ov)
9354 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9355 (delete-overlay ov)))
9356 (overlays-in (or beg (point-min)) (or end (point-max)))))
9358 (defun org-agenda-bulk-unmark-all ()
9359 "Remove all marks in the agenda buffer.
9360 This will remove the markers and the overlays."
9361 (interactive)
9362 (if (null org-agenda-bulk-marked-entries)
9363 (message "No entry to unmark")
9364 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9365 (setq org-agenda-bulk-marked-entries nil)
9366 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9368 (defcustom org-agenda-persistent-marks nil
9369 "Non-nil means marked items will stay marked after a bulk action.
9370 You can toggle this interactively by typing `p' when prompted for a
9371 bulk action."
9372 :group 'org-agenda
9373 :version "24.1"
9374 :type 'boolean)
9376 (defun org-agenda-bulk-action (&optional arg)
9377 "Execute an remote-editing action on all marked entries.
9378 The prefix arg is passed through to the command if possible."
9379 (interactive "P")
9380 ;; Make sure we have markers, and only valid ones
9381 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9382 (mapc
9383 (lambda (m)
9384 (unless (and (markerp m)
9385 (marker-buffer m)
9386 (buffer-live-p (marker-buffer m))
9387 (marker-position m))
9388 (error "Marker %s for bulk command is invalid" m)))
9389 org-agenda-bulk-marked-entries)
9391 ;; Prompt for the bulk command
9392 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9393 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9394 "[S]catter [f]unction "
9395 (when org-agenda-bulk-custom-functions
9396 (concat " Custom: ["
9397 (mapconcat (lambda(f) (char-to-string (car f)))
9398 org-agenda-bulk-custom-functions "")
9399 "]"))))
9400 (catch 'exit
9401 (let* ((action (read-char-exclusive))
9402 (org-log-refile (if org-log-refile 'time nil))
9403 (entries (reverse org-agenda-bulk-marked-entries))
9404 (org-overriding-default-time
9405 (if (get-text-property (point) 'org-agenda-date-header)
9406 (org-get-cursor-date)))
9407 redo-at-end
9408 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9409 (cond
9410 ((equal action ?p)
9411 (let ((org-agenda-persistent-marks
9412 (not org-agenda-persistent-marks)))
9413 (org-agenda-bulk-action)
9414 (throw 'exit nil)))
9416 ((equal action ?$)
9417 (setq cmd '(org-agenda-archive)))
9419 ((equal action ?A)
9420 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9422 ((member action '(?r ?w))
9423 (setq rfloc (org-refile-get-location
9424 "Refile to"
9425 (marker-buffer (car entries))
9426 org-refile-allow-creating-parent-nodes))
9427 (if (nth 3 rfloc)
9428 (setcar (nthcdr 3 rfloc)
9429 (move-marker (make-marker) (nth 3 rfloc)
9430 (or (get-file-buffer (nth 1 rfloc))
9431 (find-buffer-visiting (nth 1 rfloc))
9432 (error "This should not happen")))))
9434 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9435 redo-at-end t))
9437 ((equal action ?t)
9438 (setq state (org-icompleting-read
9439 "Todo state: "
9440 (with-current-buffer (marker-buffer (car entries))
9441 (mapcar 'list org-todo-keywords-1))))
9442 (setq cmd `(let ((org-inhibit-blocking t)
9443 (org-inhibit-logging 'note))
9444 (org-agenda-todo ,state))))
9446 ((memq action '(?- ?+))
9447 (setq tag (org-icompleting-read
9448 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9449 (with-current-buffer (marker-buffer (car entries))
9450 (delq nil
9451 (mapcar (lambda (x)
9452 (if (stringp (car x)) x)) org-tag-alist)))))
9453 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9455 ((memq action '(?s ?d))
9456 (let* ((time
9457 (unless arg
9458 (org-read-date
9459 nil nil nil
9460 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9461 org-overriding-default-time)))
9462 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9463 (setq cmd `(eval '(,c1 arg ,time)))))
9465 ((equal action ?S)
9466 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9467 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9468 (let ((days (read-number
9469 (format "Scatter tasks across how many %sdays: "
9470 (if arg "week" "")) 7)))
9471 (setq cmd
9472 `(let ((distance (1+ (random ,days))))
9473 (if arg
9474 (let ((dist distance)
9475 (day-of-week
9476 (calendar-day-of-week
9477 (calendar-gregorian-from-absolute (org-today)))))
9478 (dotimes (i (1+ dist))
9479 (while (member day-of-week org-agenda-weekend-days)
9480 (incf distance)
9481 (incf day-of-week)
9482 (if (= day-of-week 7)
9483 (setq day-of-week 0)))
9484 (incf day-of-week)
9485 (if (= day-of-week 7)
9486 (setq day-of-week 0)))))
9487 ;; silently fail when try to replan a sexp entry
9488 (condition-case nil
9489 (let* ((date (calendar-gregorian-from-absolute
9490 (+ (org-today) distance)))
9491 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9492 (nth 2 date))))
9493 (org-agenda-schedule nil time))
9494 (error nil)))))))
9496 ((assoc action org-agenda-bulk-custom-functions)
9497 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9498 redo-at-end t))
9500 ((equal action ?f)
9501 (setq cmd (list (intern
9502 (org-icompleting-read "Function: "
9503 obarray 'fboundp t nil nil)))))
9505 (t (error "Invalid bulk action")))
9507 ;; Sort the markers, to make sure that parents are handled before children
9508 (setq entries (sort entries
9509 (lambda (a b)
9510 (cond
9511 ((equal (marker-buffer a) (marker-buffer b))
9512 (< (marker-position a) (marker-position b)))
9514 (string< (buffer-name (marker-buffer a))
9515 (buffer-name (marker-buffer b))))))))
9517 ;; Now loop over all markers and apply cmd
9518 (while (setq e (pop entries))
9519 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9520 (if (not pos)
9521 (progn (message "Skipping removed entry at %s" e)
9522 (setq cntskip (1+ cntskip)))
9523 (goto-char pos)
9524 (let (org-loop-over-headlines-in-active-region)
9525 (eval cmd))
9526 (setq cnt (1+ cnt))))
9527 (when redo-at-end (org-agenda-redo))
9528 (unless org-agenda-persistent-marks
9529 (org-agenda-bulk-unmark-all))
9530 (message "Acted on %d entries%s%s"
9532 (if (= cntskip 0)
9534 (format ", skipped %d (disappeared before their turn)"
9535 cntskip))
9536 (if (not org-agenda-persistent-marks)
9537 "" " (kept marked)"))))))
9539 (defun org-agenda-capture (&optional with-time)
9540 "Call `org-capture' with the date at point.
9541 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9542 current HH:MM time."
9543 (interactive "P")
9544 (if (not (eq major-mode 'org-agenda-mode))
9545 (user-error "You cannot do this outside of agenda buffers")
9546 (let ((org-overriding-default-time
9547 (org-get-cursor-date (equal with-time 1))))
9548 (call-interactively 'org-capture))))
9550 ;;; Flagging notes
9552 (defun org-agenda-show-the-flagging-note ()
9553 "Display the flagging note in the other window.
9554 When called a second time in direct sequence, offer to remove the FLAGGING
9555 tag and (if present) the flagging note."
9556 (interactive)
9557 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9558 (win (selected-window))
9559 note heading newhead)
9560 (unless hdmarker
9561 (error "No linked entry at point"))
9562 (if (and (eq this-command last-command)
9563 (y-or-n-p "Unflag and remove any flagging note? "))
9564 (progn
9565 (org-agenda-remove-flag hdmarker)
9566 (let ((win (get-buffer-window "*Flagging Note*")))
9567 (and win (delete-window win)))
9568 (message "Entry unflagged"))
9569 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9570 (unless note
9571 (error "No flagging note"))
9572 (org-kill-new note)
9573 (org-switch-to-buffer-other-window "*Flagging Note*")
9574 (erase-buffer)
9575 (insert note)
9576 (goto-char (point-min))
9577 (while (re-search-forward "\\\\n" nil t)
9578 (replace-match "\n" t t))
9579 (goto-char (point-min))
9580 (select-window win)
9581 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9583 (defun org-agenda-remove-flag (marker)
9584 "Remove the FLAGGED tag and any flagging note in the entry."
9585 (let (newhead)
9586 (org-with-point-at marker
9587 (org-toggle-tag "FLAGGED" 'off)
9588 (org-entry-delete nil "THEFLAGGINGNOTE")
9589 (setq newhead (org-get-heading)))
9590 (org-agenda-change-all-lines newhead marker)
9591 (message "Entry unflagged")))
9593 (defun org-agenda-get-any-marker (&optional pos)
9594 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9595 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9597 ;;; Appointment reminders
9599 (defvar appt-time-msg-list) ; defined in appt.el
9601 ;;;###autoload
9602 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9603 "Activate appointments found in `org-agenda-files'.
9604 With a \\[universal-argument] prefix, refresh the list of
9605 appointments.
9607 If FILTER is t, interactively prompt the user for a regular
9608 expression, and filter out entries that don't match it.
9610 If FILTER is a string, use this string as a regular expression
9611 for filtering entries out.
9613 If FILTER is a function, filter out entries against which
9614 calling the function returns nil. This function takes one
9615 argument: an entry from `org-agenda-get-day-entries'.
9617 FILTER can also be an alist with the car of each cell being
9618 either 'headline or 'category. For example:
9620 '((headline \"IMPORTANT\")
9621 (category \"Work\"))
9623 will only add headlines containing IMPORTANT or headlines
9624 belonging to the \"Work\" category.
9626 ARGS are symbols indicating what kind of entries to consider.
9627 By default `org-agenda-to-appt' will use :deadline, :scheduled
9628 and :timestamp entries. See the docstring of `org-diary' for
9629 details and examples.
9631 If an entry as a APPT_WARNTIME property, its value will be used
9632 to override `appt-message-warning-time'."
9633 (interactive "P")
9634 (if refresh (setq appt-time-msg-list nil))
9635 (if (eq filter t)
9636 (setq filter (read-from-minibuffer "Regexp filter: ")))
9637 (let* ((cnt 0) ; count added events
9638 (scope (or args '(:deadline :scheduled :timestamp)))
9639 (org-agenda-new-buffers nil)
9640 (org-deadline-warning-days 0)
9641 ;; Do not use `org-today' here because appt only takes
9642 ;; time and without date as argument, so it may pass wrong
9643 ;; information otherwise
9644 (today (org-date-to-gregorian
9645 (time-to-days (current-time))))
9646 (org-agenda-restrict nil)
9647 (files (org-agenda-files 'unrestricted)) entries file
9648 (org-agenda-buffer nil))
9649 ;; Get all entries which may contain an appt
9650 (org-agenda-prepare-buffers files)
9651 (while (setq file (pop files))
9652 (setq entries
9653 (delq nil
9654 (append entries
9655 (apply 'org-agenda-get-day-entries
9656 file today scope)))))
9657 ;; Map thru entries and find if we should filter them out
9658 (mapc
9659 (lambda(x)
9660 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9661 (cat (get-text-property 1 'org-category x))
9662 (tod (get-text-property 1 'time-of-day x))
9663 (ok (or (null filter)
9664 (and (stringp filter) (string-match filter evt))
9665 (and (functionp filter) (funcall filter x))
9666 (and (listp filter)
9667 (let ((cat-filter (cadr (assoc 'category filter)))
9668 (evt-filter (cadr (assoc 'headline filter))))
9669 (or (and (stringp cat-filter)
9670 (string-match cat-filter cat))
9671 (and (stringp evt-filter)
9672 (string-match evt-filter evt)))))))
9673 (wrn (get-text-property 1 'warntime x)))
9674 ;; FIXME: Shall we remove text-properties for the appt text?
9675 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9676 (when (and ok tod)
9677 (setq tod (concat "00" (number-to-string tod))
9678 tod (when (string-match
9679 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9680 (concat (match-string 1 tod) ":"
9681 (match-string 2 tod))))
9682 (if (version< emacs-version "23.3")
9683 (appt-add tod evt)
9684 (appt-add tod evt wrn))
9685 (setq cnt (1+ cnt))))) entries)
9686 (org-release-buffers org-agenda-new-buffers)
9687 (if (eq cnt 0)
9688 (message "No event to add")
9689 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9691 (autoload 'org-agenda-to-appt "org-agenda" "\
9692 Activate appointments found in `org-agenda-files'.
9693 With a \\[universal-argument] prefix, refresh the list of
9694 appointments.
9696 If FILTER is t, interactively prompt the user for a regular
9697 expression, and filter out entries that don't match it.
9699 If FILTER is a string, use this string as a regular expression
9700 for filtering entries out.
9702 If FILTER is a function, filter out entries against which
9703 calling the function returns nil. This function takes one
9704 argument: an entry from `org-agenda-get-day-entries'.
9706 FILTER can also be an alist with the car of each cell being
9707 either 'headline or 'category. For example:
9709 '((headline \"IMPORTANT\")
9710 (category \"Work\"))
9712 will only add headlines containing IMPORTANT or headlines
9713 belonging to the \"Work\" category.
9715 ARGS are symbols indicating what kind of entries to consider.
9716 By default `org-agenda-to-appt' will use :deadline, :scheduled
9717 and :timestamp entries. See the docstring of `org-diary' for
9718 details and examples.
9720 If an entry as a APPT_WARNTIME property, its value will be used
9721 to override `appt-message-warning-time'.
9723 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9725 (defun org-agenda-todayp (date)
9726 "Does DATE mean today, when considering `org-extend-today-until'?"
9727 (let ((today (org-today))
9728 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9729 date)))
9730 (eq date today)))
9732 (defun org-agenda-todo-yesterday (&optional arg)
9733 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9734 (interactive "P")
9735 (let* ((hour (third (decode-time
9736 (org-current-time))))
9737 (org-extend-today-until (1+ hour)))
9738 (org-agenda-todo arg)))
9740 (provide 'org-agenda)
9742 ;;; org-agenda.el ends here