org-agenda.el: Allow `org-agenda-finalize-hook' to modify the buffer
[org-mode.git] / lisp / org-agenda.el
blob708831599e68a8d726bc2baa52b2bc66b140951d
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style ""
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. However,
228 <style>...</style> is required, if not present the variable will be ignored."
229 :group 'org-agenda-export
230 :group 'org-export-html
231 :type 'string)
233 (defcustom org-agenda-persistent-filter nil
234 "When set, keep filters from one agenda view to the next."
235 :group 'org-agenda
236 :type 'boolean)
238 (defgroup org-agenda-custom-commands nil
239 "Options concerning agenda views in Org-mode."
240 :tag "Org Agenda Custom Commands"
241 :group 'org-agenda)
243 (defconst org-sorting-choice
244 '(choice
245 (const time-up) (const time-down)
246 (const category-keep) (const category-up) (const category-down)
247 (const tag-down) (const tag-up)
248 (const priority-up) (const priority-down)
249 (const todo-state-up) (const todo-state-down)
250 (const effort-up) (const effort-down)
251 (const habit-up) (const habit-down)
252 (const alpha-up) (const alpha-down)
253 (const user-defined-up) (const user-defined-down))
254 "Sorting choices.")
256 ;; Keep custom values for `org-agenda-filter-preset' compatible with
257 ;; the new variable `org-agenda-tag-filter-preset'.
258 (if (fboundp 'defvaralias)
259 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
260 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
262 (defconst org-agenda-custom-commands-local-options
263 `(repeat :tag "Local settings for this command. Remember to quote values"
264 (choice :tag "Setting"
265 (list :tag "Heading for this block"
266 (const org-agenda-overriding-header)
267 (string :tag "Headline"))
268 (list :tag "Files to be searched"
269 (const org-agenda-files)
270 (list
271 (const :format "" quote)
272 (repeat (file))))
273 (list :tag "Sorting strategy"
274 (const org-agenda-sorting-strategy)
275 (list
276 (const :format "" quote)
277 (repeat
278 ,org-sorting-choice)))
279 (list :tag "Prefix format"
280 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
281 (string))
282 (list :tag "Number of days in agenda"
283 (const org-agenda-span)
284 (choice (const :tag "Day" 'day)
285 (const :tag "Week" 'week)
286 (const :tag "Month" 'month)
287 (const :tag "Year" 'year)
288 (integer :tag "Custom")))
289 (list :tag "Fixed starting date"
290 (const org-agenda-start-day)
291 (string :value "2007-11-01"))
292 (list :tag "Start on day of week"
293 (const org-agenda-start-on-weekday)
294 (choice :value 1
295 (const :tag "Today" nil)
296 (integer :tag "Weekday No.")))
297 (list :tag "Include data from diary"
298 (const org-agenda-include-diary)
299 (boolean))
300 (list :tag "Deadline Warning days"
301 (const org-deadline-warning-days)
302 (integer :value 1))
303 (list :tag "Category filter preset"
304 (const org-agenda-category-filter-preset)
305 (list
306 (const :format "" quote)
307 (repeat
308 (string :tag "+category or -category"))))
309 (list :tag "Tags filter preset"
310 (const org-agenda-tag-filter-preset)
311 (list
312 (const :format "" quote)
313 (repeat
314 (string :tag "+tag or -tag"))))
315 (list :tag "Set daily/weekly entry types"
316 (const org-agenda-entry-types)
317 (list
318 (const :format "" quote)
319 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
320 (const :deadline)
321 (const :scheduled)
322 (const :timestamp)
323 (const :sexp))))
324 (list :tag "Standard skipping condition"
325 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
326 (const org-agenda-skip-function)
327 (list
328 (const :format "" quote)
329 (list
330 (choice
331 :tag "Skipping range"
332 (const :tag "Skip entry" org-agenda-skip-entry-if)
333 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
334 (repeat :inline t :tag "Conditions for skipping"
335 (choice
336 :tag "Condition type"
337 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
338 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
339 (list :tag "TODO state is" :inline t
340 (const 'todo)
341 (choice
342 (const :tag "any not-done state" 'todo)
343 (const :tag "any done state" 'done)
344 (const :tag "any state" 'any)
345 (list :tag "Keyword list"
346 (const :format "" quote)
347 (repeat (string :tag "Keyword")))))
348 (list :tag "TODO state is not" :inline t
349 (const 'nottodo)
350 (choice
351 (const :tag "any not-done state" 'todo)
352 (const :tag "any done state" 'done)
353 (const :tag "any state" 'any)
354 (list :tag "Keyword list"
355 (const :format "" quote)
356 (repeat (string :tag "Keyword")))))
357 (const :tag "scheduled" 'scheduled)
358 (const :tag "not scheduled" 'notscheduled)
359 (const :tag "deadline" 'deadline)
360 (const :tag "no deadline" 'notdeadline)
361 (const :tag "timestamp" 'timestamp)
362 (const :tag "no timestamp" 'nottimestamp))))))
363 (list :tag "Non-standard skipping condition"
364 :value (org-agenda-skip-function)
365 (const org-agenda-skip-function)
366 (sexp :tag "Function or form (quoted!)"))
367 (list :tag "Any variable"
368 (variable :tag "Variable")
369 (sexp :tag "Value (sexp)"))))
370 "Selection of examples for agenda command settings.
371 This will be spliced into the custom type of
372 `org-agenda-custom-commands'.")
375 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
376 ((agenda "") (alltodo))))
377 "Custom commands for the agenda.
378 These commands will be offered on the splash screen displayed by the
379 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
381 (key desc type match settings files)
383 key The key (one or more characters as a string) to be associated
384 with the command.
385 desc A description of the command, when omitted or nil, a default
386 description is built using MATCH.
387 type The command type, any of the following symbols:
388 agenda The daily/weekly agenda.
389 todo Entries with a specific TODO keyword, in all agenda files.
390 search Entries containing search words entry or headline.
391 tags Tags/Property/TODO match in all agenda files.
392 tags-todo Tags/P/T match in all agenda files, TODO entries only.
393 todo-tree Sparse tree of specific TODO keyword in *current* file.
394 tags-tree Sparse tree with all tags matches in *current* file.
395 occur-tree Occur sparse tree for *current* file.
396 ... A user-defined function.
397 match What to search for:
398 - a single keyword for TODO keyword searches
399 - a tags match expression for tags searches
400 - a word search expression for text searches.
401 - a regular expression for occur searches
402 For all other commands, this should be the empty string.
403 settings A list of option settings, similar to that in a let form, so like
404 this: ((opt1 val1) (opt2 val2) ...). The values will be
405 evaluated at the moment of execution, so quote them when needed.
406 files A list of files file to write the produced agenda buffer to
407 with the command `org-store-agenda-views'.
408 If a file name ends in \".html\", an HTML version of the buffer
409 is written out. If it ends in \".ps\", a postscript version is
410 produced. Otherwise, only the plain text is written to the file.
412 You can also define a set of commands, to create a composite agenda buffer.
413 In this case, an entry looks like this:
415 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
417 where
419 desc A description string to be displayed in the dispatcher menu.
420 cmd An agenda command, similar to the above. However, tree commands
421 are not allowed, but instead you can get agenda and global todo list.
422 So valid commands for a set are:
423 (agenda \"\" settings)
424 (alltodo \"\" settings)
425 (stuck \"\" settings)
426 (todo \"match\" settings files)
427 (search \"match\" settings files)
428 (tags \"match\" settings files)
429 (tags-todo \"match\" settings files)
431 Each command can carry a list of options, and another set of options can be
432 given for the whole set of commands. Individual command options take
433 precedence over the general options.
435 When using several characters as key to a command, the first characters
436 are prefix commands. For the dispatcher to display useful information, you
437 should provide a description for the prefix, like
439 (setq org-agenda-custom-commands
440 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
441 (\"hl\" tags \"+HOME+Lisa\")
442 (\"hp\" tags \"+HOME+Peter\")
443 (\"hk\" tags \"+HOME+Kim\")))"
444 :group 'org-agenda-custom-commands
445 :type `(repeat
446 (choice :value ("x" "Describe command here" tags "" nil)
447 (list :tag "Single command"
448 (string :tag "Access Key(s) ")
449 (option (string :tag "Description"))
450 (choice
451 (const :tag "Agenda" agenda)
452 (const :tag "TODO list" alltodo)
453 (const :tag "Search words" search)
454 (const :tag "Stuck projects" stuck)
455 (const :tag "Tags/Property match (all agenda files)" tags)
456 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
457 (const :tag "TODO keyword search (all agenda files)" todo)
458 (const :tag "Tags sparse tree (current buffer)" tags-tree)
459 (const :tag "TODO keyword tree (current buffer)" todo-tree)
460 (const :tag "Occur tree (current buffer)" occur-tree)
461 (sexp :tag "Other, user-defined function"))
462 (string :tag "Match (only for some commands)")
463 ,org-agenda-custom-commands-local-options
464 (option (repeat :tag "Export" (file :tag "Export to"))))
465 (list :tag "Command series, all agenda files"
466 (string :tag "Access Key(s)")
467 (string :tag "Description ")
468 (repeat :tag "Component"
469 (choice
470 (list :tag "Agenda"
471 (const :format "" agenda)
472 (const :tag "" :format "" "")
473 ,org-agenda-custom-commands-local-options)
474 (list :tag "TODO list (all keywords)"
475 (const :format "" alltodo)
476 (const :tag "" :format "" "")
477 ,org-agenda-custom-commands-local-options)
478 (list :tag "Search words"
479 (const :format "" search)
480 (string :tag "Match")
481 ,org-agenda-custom-commands-local-options)
482 (list :tag "Stuck projects"
483 (const :format "" stuck)
484 (const :tag "" :format "" "")
485 ,org-agenda-custom-commands-local-options)
486 (list :tag "Tags search"
487 (const :format "" tags)
488 (string :tag "Match")
489 ,org-agenda-custom-commands-local-options)
490 (list :tag "Tags search, TODO entries only"
491 (const :format "" tags-todo)
492 (string :tag "Match")
493 ,org-agenda-custom-commands-local-options)
494 (list :tag "TODO keyword search"
495 (const :format "" todo)
496 (string :tag "Match")
497 ,org-agenda-custom-commands-local-options)
498 (list :tag "Other, user-defined function"
499 (symbol :tag "function")
500 (string :tag "Match")
501 ,org-agenda-custom-commands-local-options)))
503 (repeat :tag "Settings for entire command set"
504 (list (variable :tag "Any variable")
505 (sexp :tag "Value")))
506 (option (repeat :tag "Export" (file :tag "Export to"))))
507 (cons :tag "Prefix key documentation"
508 (string :tag "Access Key(s)")
509 (string :tag "Description ")))))
511 (defcustom org-agenda-query-register ?o
512 "The register holding the current query string.
513 The purpose of this is that if you construct a query string interactively,
514 you can then use it to define a custom command."
515 :group 'org-agenda-custom-commands
516 :type 'character)
518 (defcustom org-stuck-projects
519 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
520 "How to identify stuck projects.
521 This is a list of four items:
522 1. A tags/todo/property matcher string that is used to identify a project.
523 See the manual for a description of tag and property searches.
524 The entire tree below a headline matched by this is considered one project.
525 2. A list of TODO keywords identifying non-stuck projects.
526 If the project subtree contains any headline with one of these todo
527 keywords, the project is considered to be not stuck. If you specify
528 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
529 3. A list of tags identifying non-stuck projects.
530 If the project subtree contains any headline with one of these tags,
531 the project is considered to be not stuck. If you specify \"*\" as
532 a tag, any tag will mark the project unstuck. Note that this is about
533 the explicit presence of a tag somewhere in the subtree, inherited
534 tags to not count here. If inherited tags make a project not stuck,
535 use \"-TAG\" in the tags part of the matcher under (1.) above.
536 4. An arbitrary regular expression matching non-stuck projects.
538 If the project turns out to be not stuck, search continues also in the
539 subtree to see if any of the subtasks have project status.
541 See also the variable `org-tags-match-list-sublevels' which applies
542 to projects matched by this search as well.
544 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
545 or `C-c a #' to produce the list."
546 :group 'org-agenda-custom-commands
547 :type '(list
548 (string :tag "Tags/TODO match to identify a project")
549 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
550 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
551 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
553 (defcustom org-agenda-filter-effort-default-operator "<"
554 "The default operator for effort estimate filtering.
555 If you select an effort estimate limit without first pressing an operator,
556 this one will be used."
557 :group 'org-agenda-custom-commands
558 :type '(choice (const :tag "less or equal" "<")
559 (const :tag "greater or equal"">")
560 (const :tag "equal" "=")))
562 (defgroup org-agenda-skip nil
563 "Options concerning skipping parts of agenda files."
564 :tag "Org Agenda Skip"
565 :group 'org-agenda)
567 (defcustom org-agenda-skip-function-global nil
568 "Function to be called at each match during agenda construction.
569 If this function returns nil, the current match should not be skipped.
570 If the function decided to skip an agenda match, is must return the
571 buffer position from which the search should be continued.
572 This may also be a Lisp form, which will be evaluated.
574 This variable will be applied to every agenda match, including
575 tags/property searches and TODO lists. So try to make the test function
576 do its checking as efficiently as possible. To implement a skipping
577 condition just for specific agenda commands, use the variable
578 `org-agenda-skip-function' which can be set in the options section
579 of custom agenda commands."
580 :group 'org-agenda-skip
581 :type 'sexp)
583 (defgroup org-agenda-daily/weekly nil
584 "Options concerning the daily/weekly agenda."
585 :tag "Org Agenda Daily/Weekly"
586 :group 'org-agenda)
587 (defgroup org-agenda-todo-list nil
588 "Options concerning the global todo list agenda view."
589 :tag "Org Agenda Todo List"
590 :group 'org-agenda)
591 (defgroup org-agenda-match-view nil
592 "Options concerning the general tags/property/todo match agenda view."
593 :tag "Org Agenda Match View"
594 :group 'org-agenda)
595 (defgroup org-agenda-search-view nil
596 "Options concerning the general tags/property/todo match agenda view."
597 :tag "Org Agenda Match View"
598 :group 'org-agenda)
600 (defvar org-agenda-archives-mode nil
601 "Non-nil means the agenda will include archived items.
602 If this is the symbol `trees', trees in the selected agenda scope
603 that are marked with the ARCHIVE tag will be included anyway. When this is
604 t, also all archive files associated with the current selection of agenda
605 files will be included.")
607 (defcustom org-agenda-skip-comment-trees t
608 "Non-nil means skip trees that start with the COMMENT keyword.
609 When nil, these trees are also scanned by agenda commands."
610 :group 'org-agenda-skip
611 :type 'boolean)
613 (defcustom org-agenda-todo-list-sublevels t
614 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
615 When nil, the sublevels of a TODO entry are not checked, resulting in
616 potentially much shorter TODO lists."
617 :group 'org-agenda-skip
618 :group 'org-agenda-todo-list
619 :type 'boolean)
621 (defcustom org-agenda-todo-ignore-with-date nil
622 "Non-nil means don't show entries with a date in the global todo list.
623 You can use this if you prefer to mark mere appointments with a TODO keyword,
624 but don't want them to show up in the TODO list.
625 When this is set, it also covers deadlines and scheduled items, the settings
626 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
627 will be ignored.
628 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
629 :group 'org-agenda-skip
630 :group 'org-agenda-todo-list
631 :type 'boolean)
633 (defcustom org-agenda-todo-ignore-timestamp nil
634 "Non-nil means don't show entries with a timestamp.
635 This applies when creating the global todo list.
636 Valid values are:
638 past Don't show entries for today or in the past.
640 future Don't show entries with a timestamp in the future.
641 The idea behind this is that if it has a future
642 timestamp, you don't want to think about it until the
643 date.
645 all Don't show any entries with a timestamp in the global todo list.
646 The idea behind this is that by setting a timestamp, you
647 have already \"taken care\" of this item.
649 This variable can also have an integer as a value. If positive (N),
650 todos with a timestamp N or more days in the future will be ignored. If
651 negative (-N), todos with a timestamp N or more days in the past will be
652 ignored. If 0, todos with a timestamp either today or in the future will
653 be ignored. For example, a value of -1 will exclude todos with a
654 timestamp in the past (yesterday or earlier), while a value of 7 will
655 exclude todos with a timestamp a week or more in the future.
657 See also `org-agenda-todo-ignore-with-date'.
658 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
659 to make his option also apply to the tags-todo list."
660 :group 'org-agenda-skip
661 :group 'org-agenda-todo-list
662 :version "24.1"
663 :type '(choice
664 (const :tag "Ignore future timestamp todos" future)
665 (const :tag "Ignore past or present timestamp todos" past)
666 (const :tag "Ignore all timestamp todos" all)
667 (const :tag "Show timestamp todos" nil)
668 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
670 (defcustom org-agenda-todo-ignore-scheduled nil
671 "Non-nil means, ignore some scheduled TODO items when making TODO list.
672 This applies when creating the global todo list.
673 Valid values are:
675 past Don't show entries scheduled today or in the past.
677 future Don't show entries scheduled in the future.
678 The idea behind this is that by scheduling it, you don't want to
679 think about it until the scheduled date.
681 all Don't show any scheduled entries in the global todo list.
682 The idea behind this is that by scheduling it, you have already
683 \"taken care\" of this item.
685 t Same as `all', for backward compatibility.
687 This variable can also have an integer as a value. See
688 `org-agenda-todo-ignore-timestamp' for more details.
690 See also `org-agenda-todo-ignore-with-date'.
691 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
692 to make his option also apply to the tags-todo list."
693 :group 'org-agenda-skip
694 :group 'org-agenda-todo-list
695 :type '(choice
696 (const :tag "Ignore future-scheduled todos" future)
697 (const :tag "Ignore past- or present-scheduled todos" past)
698 (const :tag "Ignore all scheduled todos" all)
699 (const :tag "Ignore all scheduled todos (compatibility)" t)
700 (const :tag "Show scheduled todos" nil)
701 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
703 (defcustom org-agenda-todo-ignore-deadlines nil
704 "Non-nil means ignore some deadlined TODO items when making TODO list.
705 There are different motivations for using different values, please think
706 carefully when configuring this variable.
708 This applies when creating the global todo list.
709 Valid values are:
711 near Don't show near deadline entries. A deadline is near when it is
712 closer than `org-deadline-warning-days' days. The idea behind this
713 is that such items will appear in the agenda anyway.
715 far Don't show TODO entries where a deadline has been defined, but
716 the deadline is not near. This is useful if you don't want to
717 use the todo list to figure out what to do now.
719 past Don't show entries with a deadline timestamp for today or in the past.
721 future Don't show entries with a deadline timestamp in the future, not even
722 when they become `near' ones. Use it with caution.
724 all Ignore all TODO entries that do have a deadline.
726 t Same as `near', for backward compatibility.
728 This variable can also have an integer as a value. See
729 `org-agenda-todo-ignore-timestamp' for more details.
731 See also `org-agenda-todo-ignore-with-date'.
732 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
733 to make his option also apply to the tags-todo list."
734 :group 'org-agenda-skip
735 :group 'org-agenda-todo-list
736 :type '(choice
737 (const :tag "Ignore near deadlines" near)
738 (const :tag "Ignore near deadlines (compatibility)" t)
739 (const :tag "Ignore far deadlines" far)
740 (const :tag "Ignore all TODOs with a deadlines" all)
741 (const :tag "Show all TODOs, even if they have a deadline" nil)
742 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
744 (defcustom org-agenda-tags-todo-honor-ignore-options nil
745 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
746 The variables
747 `org-agenda-todo-ignore-with-date',
748 `org-agenda-todo-ignore-timestamp',
749 `org-agenda-todo-ignore-scheduled',
750 `org-agenda-todo-ignore-deadlines'
751 make the global TODO list skip entries that have time stamps of certain
752 kinds. If this option is set, the same options will also apply for the
753 tags-todo search, which is the general tags/property matcher
754 restricted to unfinished TODO entries only."
755 :group 'org-agenda-skip
756 :group 'org-agenda-todo-list
757 :group 'org-agenda-match-view
758 :type 'boolean)
760 (defcustom org-agenda-skip-scheduled-if-done nil
761 "Non-nil means don't show scheduled items in agenda when they are done.
762 This is relevant for the daily/weekly agenda, not for the TODO list. And
763 it applies only to the actual date of the scheduling. Warnings about
764 an item with a past scheduling dates are always turned off when the item
765 is DONE."
766 :group 'org-agenda-skip
767 :group 'org-agenda-daily/weekly
768 :type 'boolean)
770 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
771 "Non-nil means skip scheduling line if same entry shows because of deadline.
772 In the agenda of today, an entry can show up multiple times because
773 it is both scheduled and has a nearby deadline, and maybe a plain time
774 stamp as well.
775 When this variable is t, then only the deadline is shown and the fact that
776 the entry is scheduled today or was scheduled previously is not shown.
777 When this variable is nil, the entry will be shown several times. When
778 the variable is the symbol `not-today', then skip scheduled previously,
779 but not scheduled today."
780 :group 'org-agenda-skip
781 :group 'org-agenda-daily/weekly
782 :type '(choice
783 (const :tag "Never" nil)
784 (const :tag "Always" t)
785 (const :tag "Not when scheduled today" not-today)))
787 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
788 "Non-nil means skip timestamp line if same entry shows because of deadline.
789 In the agenda of today, an entry can show up multiple times
790 because it has both a plain timestamp and has a nearby deadline.
791 When this variable is t, then only the deadline is shown and the
792 fact that the entry has a timestamp for or including today is not
793 shown. When this variable is nil, the entry will be shown
794 several times."
795 :group 'org-agenda-skip
796 :group 'org-agenda-daily/weekly
797 :version "24.1"
798 :type '(choice
799 (const :tag "Never" nil)
800 (const :tag "Always" t)))
802 (defcustom org-agenda-skip-deadline-if-done nil
803 "Non-nil means don't show deadlines when the corresponding item is done.
804 When nil, the deadline is still shown and should give you a happy feeling.
805 This is relevant for the daily/weekly agenda. And it applied only to the
806 actually date of the deadline. Warnings about approaching and past-due
807 deadlines are always turned off when the item is DONE."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :type 'boolean)
812 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
813 "Non-nil means skip deadline prewarning when entry is also scheduled.
814 This will apply on all days where a prewarning for the deadline would
815 be shown, but not at the day when the entry is actually due. On that day,
816 the deadline will be shown anyway.
817 This variable may be set to nil, t, or a number which will then give
818 the number of days before the actual deadline when the prewarnings
819 should resume.
820 This can be used in a workflow where the first showing of the deadline will
821 trigger you to schedule it, and then you don't want to be reminded of it
822 because you will take care of it on the day when scheduled."
823 :group 'org-agenda-skip
824 :group 'org-agenda-daily/weekly
825 :version "24.1"
826 :type '(choice
827 (const :tag "Alwas show prewarning" nil)
828 (const :tag "Remove prewarning if entry is scheduled" t)
829 (integer :tag "Restart prewarning N days before deadline")))
831 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
832 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
833 When non-nil, after the search for timestamps has matched once in an
834 entry, the rest of the entry will not be searched."
835 :group 'org-agenda-skip
836 :type 'boolean)
838 (defcustom org-agenda-skip-timestamp-if-done nil
839 "Non-nil means don't select item by timestamp or -range if it is DONE."
840 :group 'org-agenda-skip
841 :group 'org-agenda-daily/weekly
842 :type 'boolean)
844 (defcustom org-agenda-dim-blocked-tasks t
845 "Non-nil means dim blocked tasks in the agenda display.
846 This causes some overhead during agenda construction, but if you
847 have turned on `org-enforce-todo-dependencies',
848 `org-enforce-todo-checkbox-dependencies', or any other blocking
849 mechanism, this will create useful feedback in the agenda.
851 Instead of t, this variable can also have the value `invisible'.
852 Then blocked tasks will be invisible and only become visible when
853 they become unblocked. An exemption to this behavior is when a task is
854 blocked because of unchecked checkboxes below it. Since checkboxes do
855 not show up in the agenda views, making this task invisible you remove any
856 trace from agenda views that there is something to do. Therefore, a task
857 that is blocked because of checkboxes will never be made invisible, it
858 will only be dimmed."
859 :group 'org-agenda-daily/weekly
860 :group 'org-agenda-todo-list
861 :type '(choice
862 (const :tag "Do not dim" nil)
863 (const :tag "Dim to a gray face" t)
864 (const :tag "Make invisible" invisible)))
866 (defcustom org-timeline-show-empty-dates 3
867 "Non-nil means `org-timeline' also shows dates without an entry.
868 When nil, only the days which actually have entries are shown.
869 When t, all days between the first and the last date are shown.
870 When an integer, show also empty dates, but if there is a gap of more than
871 N days, just insert a special line indicating the size of the gap."
872 :group 'org-agenda-skip
873 :type '(choice
874 (const :tag "None" nil)
875 (const :tag "All" t)
876 (integer :tag "at most")))
878 (defgroup org-agenda-startup nil
879 "Options concerning initial settings in the Agenda in Org Mode."
880 :tag "Org Agenda Startup"
881 :group 'org-agenda)
883 (defcustom org-agenda-menu-show-matcher t
884 "Non-nil means show the match string in the agenda dispatcher menu.
885 When nil, the matcher string is not shown, but is put into the help-echo
886 property so than moving the mouse over the command shows it.
887 Setting it to nil is good if matcher strings are very long and/or if
888 you want to use two-columns display (see `org-agenda-menu-two-columns')."
889 :group 'org-agenda
890 :version "24.1"
891 :type 'boolean)
893 (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
895 (defcustom org-agenda-menu-two-columns nil
896 "Non-nil means, use two columns to show custom commands in the dispatcher.
897 If you use this, you probably want to set `org-agenda-menu-show-matcher'
898 to nil."
899 :group 'org-agenda
900 :version "24.1"
901 :type 'boolean)
903 (make-obsolete-variable 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
904 (defcustom org-agenda-finalize-hook nil
905 "Hook run just before displaying an agenda buffer.
906 The buffer is still writable when the hook is called.
908 You can modify some of the buffer substrings but you should be
909 extra careful not to modify the text properties of the agenda
910 headlines as the agenda display heavily relies on them."
911 :group 'org-agenda-startup
912 :type 'hook)
914 (defcustom org-agenda-mouse-1-follows-link nil
915 "Non-nil means mouse-1 on a link will follow the link in the agenda.
916 A longer mouse click will still set point. Does not work on XEmacs.
917 Needs to be set before org.el is loaded."
918 :group 'org-agenda-startup
919 :type 'boolean)
921 (defcustom org-agenda-start-with-follow-mode nil
922 "The initial value of follow mode in a newly created agenda window."
923 :group 'org-agenda-startup
924 :type 'boolean)
926 (defcustom org-agenda-follow-indirect nil
927 "Non-nil means `org-agenda-follow-mode' displays only the
928 current item's tree, in an indirect buffer."
929 :group 'org-agenda
930 :version "24.1"
931 :type 'boolean)
933 (defcustom org-agenda-show-outline-path t
934 "Non-nil means show outline path in echo area after line motion."
935 :group 'org-agenda-startup
936 :type 'boolean)
938 (defcustom org-agenda-start-with-entry-text-mode nil
939 "The initial value of entry-text-mode in a newly created agenda window."
940 :group 'org-agenda-startup
941 :type 'boolean)
943 (defcustom org-agenda-entry-text-maxlines 5
944 "Number of text lines to be added when `E' is pressed in the agenda.
946 Note that this variable only used during agenda display. Add add entry text
947 when exporting the agenda, configure the variable
948 `org-agenda-add-entry-ext-maxlines'."
949 :group 'org-agenda
950 :type 'integer)
952 (defcustom org-agenda-entry-text-exclude-regexps nil
953 "List of regular expressions to clean up entry text.
954 The complete matches of all regular expressions in this list will be
955 removed from entry text before it is shown in the agenda."
956 :group 'org-agenda
957 :type '(repeat (regexp)))
959 (defvar org-agenda-entry-text-cleanup-hook nil
960 "Hook that is run after basic cleanup of entry text to be shown in agenda.
961 This cleanup is done in a temporary buffer, so the function may inspect and
962 change the entire buffer.
963 Some default stuff like drawers and scheduling/deadline dates will already
964 have been removed when this is called, as will any matches for regular
965 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
967 (defvar org-agenda-include-inactive-timestamps nil
968 "Non-nil means include inactive time stamps in agenda and timeline.
969 Dynamically scoped.")
971 (defgroup org-agenda-windows nil
972 "Options concerning the windows used by the Agenda in Org Mode."
973 :tag "Org Agenda Windows"
974 :group 'org-agenda)
976 (defcustom org-agenda-window-setup 'reorganize-frame
977 "How the agenda buffer should be displayed.
978 Possible values for this option are:
980 current-window Show agenda in the current window, keeping all other windows.
981 other-window Use `switch-to-buffer-other-window' to display agenda.
982 reorganize-frame Show only two windows on the current frame, the current
983 window and the agenda.
984 other-frame Use `switch-to-buffer-other-frame' to display agenda.
985 Also, when exiting the agenda, kill that frame.
986 See also the variable `org-agenda-restore-windows-after-quit'."
987 :group 'org-agenda-windows
988 :type '(choice
989 (const current-window)
990 (const other-frame)
991 (const other-window)
992 (const reorganize-frame)))
994 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
995 "The min and max height of the agenda window as a fraction of frame height.
996 The value of the variable is a cons cell with two numbers between 0 and 1.
997 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
998 :group 'org-agenda-windows
999 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1001 (defcustom org-agenda-restore-windows-after-quit nil
1002 "Non-nil means restore window configuration upon exiting agenda.
1003 Before the window configuration is changed for displaying the agenda,
1004 the current status is recorded. When the agenda is exited with
1005 `q' or `x' and this option is set, the old state is restored. If
1006 `org-agenda-window-setup' is `other-frame', the value of this
1007 option will be ignored."
1008 :group 'org-agenda-windows
1009 :type 'boolean)
1011 (defcustom org-agenda-ndays nil
1012 "Number of days to include in overview display.
1013 Should be 1 or 7.
1014 Obsolete, see `org-agenda-span'."
1015 :group 'org-agenda-daily/weekly
1016 :type 'integer)
1018 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1020 (defcustom org-agenda-span 'week
1021 "Number of days to include in overview display.
1022 Can be day, week, month, year, or any number of days.
1023 Custom commands can set this variable in the options section."
1024 :group 'org-agenda-daily/weekly
1025 :type '(choice (const :tag "Day" day)
1026 (const :tag "Week" week)
1027 (const :tag "Month" month)
1028 (const :tag "Year" year)
1029 (integer :tag "Custom")))
1031 (defcustom org-agenda-start-on-weekday 1
1032 "Non-nil means start the overview always on the specified weekday.
1033 0 denotes Sunday, 1 denotes Monday etc.
1034 When nil, always start on the current day.
1035 Custom commands can set this variable in the options section."
1036 :group 'org-agenda-daily/weekly
1037 :type '(choice (const :tag "Today" nil)
1038 (integer :tag "Weekday No.")))
1040 (defcustom org-agenda-show-all-dates t
1041 "Non-nil means `org-agenda' shows every day in the selected range.
1042 When nil, only the days which actually have entries are shown."
1043 :group 'org-agenda-daily/weekly
1044 :type 'boolean)
1046 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1047 "Format string for displaying dates in the agenda.
1048 Used by the daily/weekly agenda and by the timeline. This should be
1049 a format string understood by `format-time-string', or a function returning
1050 the formatted date as a string. The function must take a single argument,
1051 a calendar-style date list like (month day year)."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice
1054 (string :tag "Format string")
1055 (function :tag "Function")))
1057 (defun org-agenda-format-date-aligned (date)
1058 "Format a date string for display in the daily/weekly agenda, or timeline.
1059 This function makes sure that dates are aligned for easy reading."
1060 (require 'cal-iso)
1061 (let* ((dayname (calendar-day-name date))
1062 (day (cadr date))
1063 (day-of-week (calendar-day-of-week date))
1064 (month (car date))
1065 (monthname (calendar-month-name month))
1066 (year (nth 2 date))
1067 (iso-week (org-days-to-iso-week
1068 (calendar-absolute-from-gregorian date)))
1069 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1070 (1- year))
1071 ((and (= month 12) (<= iso-week 1))
1072 (1+ year))
1073 (t year)))
1074 (weekstring (if (= day-of-week 1)
1075 (format " W%02d" iso-week)
1076 "")))
1077 (format "%-10s %2d %s %4d%s"
1078 dayname day monthname year weekstring)))
1080 (defcustom org-agenda-time-leading-zero nil
1081 "Non-nil means use leading zero for military times in agenda.
1082 For example, 9:30am would become 09:30 rather than 9:30."
1083 :group 'org-agenda-daily/weekly
1084 :version "24.1"
1085 :type 'boolean)
1087 (defcustom org-agenda-timegrid-use-ampm nil
1088 "When set, show AM/PM style timestamps on the timegrid."
1089 :group 'org-agenda
1090 :version "24.1"
1091 :type 'boolean)
1093 (defun org-agenda-time-of-day-to-ampm (time)
1094 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1095 (let* ((hour-number (string-to-number (substring time 0 -3)))
1096 (minute (substring time -2))
1097 (ampm "am"))
1098 (cond
1099 ((equal hour-number 12)
1100 (setq ampm "pm"))
1101 ((> hour-number 12)
1102 (setq ampm "pm")
1103 (setq hour-number (- hour-number 12))))
1104 (concat
1105 (if org-agenda-time-leading-zero
1106 (format "%02d" hour-number)
1107 (format "%02s" (number-to-string hour-number)))
1108 ":" minute ampm)))
1110 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1111 "Conditionally convert TIME to AM/PM format
1112 based on `org-agenda-timegrid-use-ampm'"
1113 (if org-agenda-timegrid-use-ampm
1114 (org-agenda-time-of-day-to-ampm time)
1115 time))
1117 (defcustom org-agenda-weekend-days '(6 0)
1118 "Which days are weekend?
1119 These days get the special face `org-agenda-date-weekend' in the agenda
1120 and timeline buffers."
1121 :group 'org-agenda-daily/weekly
1122 :type '(set :greedy t
1123 (const :tag "Monday" 1)
1124 (const :tag "Tuesday" 2)
1125 (const :tag "Wednesday" 3)
1126 (const :tag "Thursday" 4)
1127 (const :tag "Friday" 5)
1128 (const :tag "Saturday" 6)
1129 (const :tag "Sunday" 0)))
1131 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1132 "Non-nil means jump to today when moving a past date forward in time.
1133 When using S-right in the agenda to move a a date forward, and the date
1134 stamp currently points to the past, the first key press will move it
1135 to today. WHen nil, just move one day forward even if the date stays
1136 in the past."
1137 :group 'org-agenda-daily/weekly
1138 :version "24.1"
1139 :type 'boolean)
1141 (defcustom org-agenda-include-diary nil
1142 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1143 Custom commands can set this variable in the options section."
1144 :group 'org-agenda-daily/weekly
1145 :type 'boolean)
1147 (defcustom org-agenda-include-deadlines t
1148 "If non-nil, include entries within their deadline warning period.
1149 Custom commands can set this variable in the options section."
1150 :group 'org-agenda-daily/weekly
1151 :version "24.1"
1152 :type 'boolean)
1154 (defcustom org-agenda-repeating-timestamp-show-all t
1155 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1156 When set to a list of strings, only show occurrences of repeating
1157 stamps for these TODO keywords. When nil, only one occurrence is
1158 shown, either today or the nearest into the future."
1159 :group 'org-agenda-daily/weekly
1160 :type '(choice
1161 (const :tag "Show repeating stamps" t)
1162 (repeat :tag "Show repeating stamps for these TODO keywords"
1163 (string :tag "TODO Keyword"))
1164 (const :tag "Don't show repeating stamps" nil)))
1166 (defcustom org-scheduled-past-days 10000
1167 "No. of days to continue listing scheduled items that are not marked DONE.
1168 When an item is scheduled on a date, it shows up in the agenda on this
1169 day and will be listed until it is marked done for the number of days
1170 given here."
1171 :group 'org-agenda-daily/weekly
1172 :type 'integer)
1174 (defcustom org-agenda-log-mode-items '(closed clock)
1175 "List of items that should be shown in agenda log mode.
1176 This list may contain the following symbols:
1178 closed Show entries that have been closed on that day.
1179 clock Show entries that have received clocked time on that day.
1180 state Show all logged state changes.
1181 Note that instead of changing this variable, you can also press `C-u l' in
1182 the agenda to display all available LOG items temporarily."
1183 :group 'org-agenda-daily/weekly
1184 :type '(set :greedy t (const closed) (const clock) (const state)))
1186 (defcustom org-agenda-clock-consistency-checks
1187 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1188 :gap-ok-around ("4:00")
1189 :default-face ((:background "DarkRed") (:foreground "white"))
1190 :overlap-face nil :gap-face nil :no-end-time-face nil
1191 :long-face nil :short-face nil)
1192 "This is a property list, with the following keys:
1194 :max-duration Mark clocking chunks that are longer than this time.
1195 This is a time string like \"HH:MM\", or the number
1196 of minutes as an integer.
1198 :min-duration Mark clocking chunks that are shorter that this.
1199 This is a time string like \"HH:MM\", or the number
1200 of minutes as an integer.
1202 :max-gap Mark gaps between clocking chunks that are longer than
1203 this duration. A number of minutes, or a string
1204 like \"HH:MM\".
1206 :gap-ok-around List of times during the day which are usually not working
1207 times. When a gap is detected, but the gap contains any
1208 of these times, the gap is *not* reported. For example,
1209 if this is (\"4:00\" \"13:00\") then gaps that contain
1210 4:00 in the morning (i.e. the night) and 13:00
1211 (i.e. a typical lunch time) do not cause a warning.
1212 You should have at least one time during the night in this
1213 list, or otherwise the first task each morning will trigger
1214 a warning because it follows a long gap.
1216 Furthermore, the following properties can be used to define faces for
1217 issue display.
1219 :default-face the default face, if the specific face is undefined
1220 :overlap-face face for overlapping clocks
1221 :gap-face face for gaps between clocks
1222 :no-end-time-face face for incomplete clocks
1223 :long-face face for clock intervals that are too long
1224 :short-face face for clock intervals that are too short"
1225 :group 'org-agenda-daily/weekly
1226 :group 'org-clock
1227 :version "24.1"
1228 :type 'plist)
1230 (defcustom org-agenda-log-mode-add-notes t
1231 "Non-nil means add first line of notes to log entries in agenda views.
1232 If a log item like a state change or a clock entry is associated with
1233 notes, the first line of these notes will be added to the entry in the
1234 agenda display."
1235 :group 'org-agenda-daily/weekly
1236 :type 'boolean)
1238 (defcustom org-agenda-start-with-log-mode nil
1239 "The initial value of log-mode in a newly created agenda window.
1240 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1241 explanations on the possible values."
1242 :group 'org-agenda-startup
1243 :group 'org-agenda-daily/weekly
1244 :type '(choice (const :tag "Don't show log items" nil)
1245 (const :tag "Show only log items" 'only)
1246 (const :tag "Show all possible log items" 'clockcheck)
1247 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1248 (choice (const :tag "Show closed log items" 'closed)
1249 (const :tag "Show clocked log items" 'clock)
1250 (const :tag "Show all logged state changes" 'state)))))
1252 (defcustom org-agenda-start-with-clockreport-mode nil
1253 "The initial value of clockreport-mode in a newly created agenda window."
1254 :group 'org-agenda-startup
1255 :group 'org-agenda-daily/weekly
1256 :type 'boolean)
1258 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1259 "Property list with parameters for the clocktable in clockreport mode.
1260 This is the display mode that shows a clock table in the daily/weekly
1261 agenda, the properties for this dynamic block can be set here.
1262 The usual clocktable parameters are allowed here, but you cannot set
1263 the properties :name, :tstart, :tend, :block, and :scope - these will
1264 be overwritten to make sure the content accurately reflects the
1265 current display in the agenda."
1266 :group 'org-agenda-daily/weekly
1267 :type 'plist)
1269 (defcustom org-agenda-search-view-always-boolean nil
1270 "Non-nil means the search string is interpreted as individual parts.
1272 The search string for search view can either be interpreted as a phrase,
1273 or as a list of snippets that define a boolean search for a number of
1274 strings.
1276 When this is non-nil, the string will be split on whitespace, and each
1277 snippet will be searched individually, and all must match in order to
1278 select an entry. A snippet is then a single string of non-white
1279 characters, or a string in double quotes, or a regexp in {} braces.
1280 If a snippet is preceded by \"-\", the snippet must *not* match.
1281 \"+\" is syntactic sugar for positive selection. Each snippet may
1282 be found as a full word or a partial word, but see the variable
1283 `org-agenda-search-view-force-full-words'.
1285 When this is nil, search will look for the entire search phrase as one,
1286 with each space character matching any amount of whitespace, including
1287 line breaks.
1289 Even when this is nil, you can still switch to Boolean search dynamically
1290 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1291 is a regexp marked with braces like \"{abc}\", this will also switch to
1292 boolean search."
1293 :group 'org-agenda-search-view
1294 :version "24.1"
1295 :type 'boolean)
1297 (if (fboundp 'defvaralias)
1298 (defvaralias 'org-agenda-search-view-search-words-only
1299 'org-agenda-search-view-always-boolean))
1301 (defcustom org-agenda-search-view-force-full-words nil
1302 "Non-nil means, search words must be matches as complete words.
1303 When nil, they may also match part of a word."
1304 :group 'org-agenda-search-view
1305 :version "24.1"
1306 :type 'boolean)
1308 (defgroup org-agenda-time-grid nil
1309 "Options concerning the time grid in the Org-mode Agenda."
1310 :tag "Org Agenda Time Grid"
1311 :group 'org-agenda)
1313 (defcustom org-agenda-search-headline-for-time t
1314 "Non-nil means search headline for a time-of-day.
1315 If the headline contains a time-of-day in one format or another, it will
1316 be used to sort the entry into the time sequence of items for a day.
1317 Some people have time stamps in the headline that refer to the creation
1318 time or so, and then this produces an unwanted side effect. If this is
1319 the case for your, use this variable to turn off searching the headline
1320 for a time."
1321 :group 'org-agenda-time-grid
1322 :type 'boolean)
1324 (defcustom org-agenda-use-time-grid t
1325 "Non-nil means show a time grid in the agenda schedule.
1326 A time grid is a set of lines for specific times (like every two hours between
1327 8:00 and 20:00). The items scheduled for a day at specific times are
1328 sorted in between these lines.
1329 For details about when the grid will be shown, and what it will look like, see
1330 the variable `org-agenda-time-grid'."
1331 :group 'org-agenda-time-grid
1332 :type 'boolean)
1334 (defcustom org-agenda-time-grid
1335 '((daily today require-timed)
1336 "----------------"
1337 (800 1000 1200 1400 1600 1800 2000))
1339 "The settings for time grid for agenda display.
1340 This is a list of three items. The first item is again a list. It contains
1341 symbols specifying conditions when the grid should be displayed:
1343 daily if the agenda shows a single day
1344 weekly if the agenda shows an entire week
1345 today show grid on current date, independent of daily/weekly display
1346 require-timed show grid only if at least one item has a time specification
1348 The second item is a string which will be placed behind the grid time.
1350 The third item is a list of integers, indicating the times that should have
1351 a grid line."
1352 :group 'org-agenda-time-grid
1353 :type
1354 '(list
1355 (set :greedy t :tag "Grid Display Options"
1356 (const :tag "Show grid in single day agenda display" daily)
1357 (const :tag "Show grid in weekly agenda display" weekly)
1358 (const :tag "Always show grid for today" today)
1359 (const :tag "Show grid only if any timed entries are present"
1360 require-timed)
1361 (const :tag "Skip grid times already present in an entry"
1362 remove-match))
1363 (string :tag "Grid String")
1364 (repeat :tag "Grid Times" (integer :tag "Time"))))
1366 (defcustom org-agenda-show-current-time-in-grid t
1367 "Non-nil means show the current time in the time grid."
1368 :group 'org-agenda-time-grid
1369 :version "24.1"
1370 :type 'boolean)
1372 (defcustom org-agenda-current-time-string
1373 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1374 "The string for the current time marker in the agenda."
1375 :group 'org-agenda-time-grid
1376 :version "24.1"
1377 :type 'string)
1379 (defgroup org-agenda-sorting nil
1380 "Options concerning sorting in the Org-mode Agenda."
1381 :tag "Org Agenda Sorting"
1382 :group 'org-agenda)
1384 (defcustom org-agenda-sorting-strategy
1385 '((agenda habit-down time-up priority-down category-keep)
1386 (todo priority-down category-keep)
1387 (tags priority-down category-keep)
1388 (search category-keep))
1389 "Sorting structure for the agenda items of a single day.
1390 This is a list of symbols which will be used in sequence to determine
1391 if an entry should be listed before another entry. The following
1392 symbols are recognized:
1394 time-up Put entries with time-of-day indications first, early first
1395 time-down Put entries with time-of-day indications first, late first
1396 category-keep Keep the default order of categories, corresponding to the
1397 sequence in `org-agenda-files'.
1398 category-up Sort alphabetically by category, A-Z.
1399 category-down Sort alphabetically by category, Z-A.
1400 tag-up Sort alphabetically by last tag, A-Z.
1401 tag-down Sort alphabetically by last tag, Z-A.
1402 priority-up Sort numerically by priority, high priority last.
1403 priority-down Sort numerically by priority, high priority first.
1404 todo-state-up Sort by todo state, tasks that are done last.
1405 todo-state-down Sort by todo state, tasks that are done first.
1406 effort-up Sort numerically by estimated effort, high effort last.
1407 effort-down Sort numerically by estimated effort, high effort first.
1408 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1409 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1410 habit-up Put entries that are habits first
1411 habit-down Put entries that are habits last
1412 alpha-up Sort headlines alphabetically
1413 alpha-down Sort headlines alphabetically, reversed
1415 The different possibilities will be tried in sequence, and testing stops
1416 if one comparison returns a \"not-equal\". For example, the default
1417 '(time-up category-keep priority-down)
1418 means: Pull out all entries having a specified time of day and sort them,
1419 in order to make a time schedule for the current day the first thing in the
1420 agenda listing for the day. Of the entries without a time indication, keep
1421 the grouped in categories, don't sort the categories, but keep them in
1422 the sequence given in `org-agenda-files'. Within each category sort by
1423 priority.
1425 Leaving out `category-keep' would mean that items will be sorted across
1426 categories by priority.
1428 Instead of a single list, this can also be a set of list for specific
1429 contents, with a context symbol in the car of the list, any of
1430 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1432 Custom commands can bind this variable in the options section."
1433 :group 'org-agenda-sorting
1434 :type `(choice
1435 (repeat :tag "General" ,org-sorting-choice)
1436 (list :tag "Individually"
1437 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1438 (repeat ,org-sorting-choice))
1439 (cons (const :tag "Strategy for TODO lists" todo)
1440 (repeat ,org-sorting-choice))
1441 (cons (const :tag "Strategy for Tags matches" tags)
1442 (repeat ,org-sorting-choice))
1443 (cons (const :tag "Strategy for search matches" search)
1444 (repeat ,org-sorting-choice)))))
1446 (defcustom org-agenda-cmp-user-defined nil
1447 "A function to define the comparison `user-defined'.
1448 This function must receive two arguments, agenda entry a and b.
1449 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1450 the user comparison, return nil.
1451 When this is defined, you can make `user-defined-up' and `user-defined-down'
1452 part of an agenda sorting strategy."
1453 :group 'org-agenda-sorting
1454 :type 'symbol)
1456 (defcustom org-sort-agenda-notime-is-late t
1457 "Non-nil means items without time are considered late.
1458 This is only relevant for sorting. When t, items which have no explicit
1459 time like 15:30 will be considered as 99:01, i.e. later than any items which
1460 do have a time. When nil, the default time is before 0:00. You can use this
1461 option to decide if the schedule for today should come before or after timeless
1462 agenda entries."
1463 :group 'org-agenda-sorting
1464 :type 'boolean)
1466 (defcustom org-sort-agenda-noeffort-is-high t
1467 "Non-nil means items without effort estimate are sorted as high effort.
1468 This also applies when filtering an agenda view with respect to the
1469 < or > effort operator. Then, tasks with no effort defined will be treated
1470 as tasks with high effort.
1471 When nil, such items are sorted as 0 minutes effort."
1472 :group 'org-agenda-sorting
1473 :type 'boolean)
1475 (defgroup org-agenda-line-format nil
1476 "Options concerning the entry prefix in the Org-mode agenda display."
1477 :tag "Org Agenda Line Format"
1478 :group 'org-agenda)
1480 (defcustom org-agenda-prefix-format
1481 '((agenda . " %i %-12:c%?-12t% s")
1482 (timeline . " % s")
1483 (todo . " %i %-12:c")
1484 (tags . " %i %-12:c")
1485 (search . " %i %-12:c"))
1486 "Format specifications for the prefix of items in the agenda views.
1487 An alist with five entries, each for the different agenda types. The
1488 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1489 The values are format strings.
1491 This format works similar to a printf format, with the following meaning:
1493 %c the category of the item, \"Diary\" for entries from the diary,
1494 or as given by the CATEGORY keyword or derived from the file name
1495 %e the effort required by the item
1496 %i the icon category of the item, see `org-agenda-category-icon-alist'
1497 %T the last tag of the item (ignore inherited tags, which come first)
1498 %t the HH:MM time-of-day specification if one applies to the entry
1499 %s Scheduling/Deadline information, a short string
1500 %(expression) Eval EXPRESSION and replace the control string
1501 by the result
1503 All specifiers work basically like the standard `%s' of printf, but may
1504 contain two additional characters: a question mark just after the `%'
1505 and a whitespace/punctuation character just before the final letter.
1507 If the first character after `%' is a question mark, the entire field
1508 will only be included if the corresponding value applies to the current
1509 entry. This is useful for fields which should have fixed width when
1510 present, but zero width when absent. For example, \"%?-12t\" will
1511 result in a 12 character time field if a time of the day is specified,
1512 but will completely disappear in entries which do not contain a time.
1514 If there is punctuation or whitespace character just before the final
1515 format letter, this character will be appended to the field value if
1516 the value is not empty. For example, the format \"%-12:c\" leads to
1517 \"Diary: \" if the category is \"Diary\". If the category were be
1518 empty, no additional colon would be inserted.
1520 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1521 which means:
1523 - Indent the line with two space characters
1524 - Give the category a 12 chars wide field, padded with whitespace on
1525 the right (because of `-'). Append a colon if there is a category
1526 (because of `:').
1527 - If there is a time-of-day, put it into a 12 chars wide field. If no
1528 time, don't put in an empty field, just skip it (because of '?').
1529 - Finally, put the scheduling information.
1531 See also the variables `org-agenda-remove-times-when-in-prefix' and
1532 `org-agenda-remove-tags'.
1534 Custom commands can set this variable in the options section."
1535 :type '(choice
1536 (string :tag "General format")
1537 (list :greedy t :tag "View dependent"
1538 (cons (const agenda) (string :tag "Format"))
1539 (cons (const timeline) (string :tag "Format"))
1540 (cons (const todo) (string :tag "Format"))
1541 (cons (const tags) (string :tag "Format"))
1542 (cons (const search) (string :tag "Format"))))
1543 :group 'org-agenda-line-format)
1545 (defvar org-prefix-format-compiled nil
1546 "The compiled prefix format and associated variables.
1547 This is a list where first element is a list of variable bindings, and second
1548 element is the compiled format expression. See the variable
1549 `org-agenda-prefix-format'.")
1551 (defcustom org-agenda-todo-keyword-format "%-1s"
1552 "Format for the TODO keyword in agenda lines.
1553 Set this to something like \"%-12s\" if you want all TODO keywords
1554 to occupy a fixed space in the agenda display."
1555 :group 'org-agenda-line-format
1556 :type 'string)
1558 (defcustom org-agenda-diary-sexp-prefix nil
1559 "A regexp that matches part of a diary sexp entry
1560 which should be treated as scheduling/deadline information in
1561 `org-agenda'.
1563 For example, you can use this to extract the `diary-remind-message' from
1564 `diary-remind' entries."
1565 :group 'org-agenda-line-format
1566 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1568 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1569 "Text preceding timerange entries in the agenda view.
1570 This is a list with two strings. The first applies when the range
1571 is entirely on one day. The second applies if the range spans several days.
1572 The strings may have two \"%d\" format specifiers which will be filled
1573 with the sequence number of the days, and the total number of days in the
1574 range, respectively."
1575 :group 'org-agenda-line-format
1576 :type '(list
1577 (string :tag "Deadline today ")
1578 (choice :tag "Deadline relative"
1579 (string :tag "Format string")
1580 (function))))
1582 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1583 "Text preceding scheduled items in the agenda view.
1584 This is a list with two strings. The first applies when the item is
1585 scheduled on the current day. The second applies when it has been scheduled
1586 previously, it may contain a %d indicating that this is the nth time that
1587 this item is scheduled, due to automatic rescheduling of unfinished items
1588 for the following day. So this number is one larger than the number of days
1589 that passed since this item was scheduled first."
1590 :group 'org-agenda-line-format
1591 :type '(list
1592 (string :tag "Scheduled today ")
1593 (string :tag "Scheduled previously")))
1595 (defcustom org-agenda-inactive-leader "["
1596 "Text preceding item pulled into the agenda by inactive time stamps.
1597 These entries are added to the agenda when pressing \"[\"."
1598 :group 'org-agenda-line-format
1599 :version "24.1"
1600 :type '(list
1601 (string :tag "Scheduled today ")
1602 (string :tag "Scheduled previously")))
1604 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1605 "Text preceding deadline items in the agenda view.
1606 This is a list with two strings. The first applies when the item has its
1607 deadline on the current day. The second applies when it is in the past or
1608 in the future, it may contain %d to capture how many days away the deadline
1609 is (was)."
1610 :group 'org-agenda-line-format
1611 :type '(list
1612 (string :tag "Deadline today ")
1613 (choice :tag "Deadline relative"
1614 (string :tag "Format string")
1615 (function))))
1617 (defcustom org-agenda-remove-times-when-in-prefix t
1618 "Non-nil means remove duplicate time specifications in agenda items.
1619 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1620 time-of-day specification in a headline or diary entry is extracted and
1621 placed into the prefix. If this option is non-nil, the original specification
1622 \(a timestamp or -range, or just a plain time(range) specification like
1623 11:30-4pm) will be removed for agenda display. This makes the agenda less
1624 cluttered.
1625 The option can be t or nil. It may also be the symbol `beg', indicating
1626 that the time should only be removed when it is located at the beginning of
1627 the headline/diary entry."
1628 :group 'org-agenda-line-format
1629 :type '(choice
1630 (const :tag "Always" t)
1631 (const :tag "Never" nil)
1632 (const :tag "When at beginning of entry" beg)))
1634 (defcustom org-agenda-remove-timeranges-from-blocks nil
1635 "Non-nil means remove time ranges specifications in agenda
1636 items that span on several days."
1637 :group 'org-agenda-line-format
1638 :version "24.1"
1639 :type 'boolean)
1641 (defcustom org-agenda-default-appointment-duration nil
1642 "Default duration for appointments that only have a starting time.
1643 When nil, no duration is specified in such cases.
1644 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1645 :group 'org-agenda-line-format
1646 :type '(choice
1647 (integer :tag "Minutes")
1648 (const :tag "No default duration")))
1650 (defcustom org-agenda-show-inherited-tags t
1651 "Non-nil means show inherited tags in each agenda line."
1652 :group 'org-agenda-line-format
1653 :type 'boolean)
1655 (defcustom org-agenda-hide-tags-regexp nil
1656 "Regular expression used to filter away specific tags in agenda views.
1657 This means that these tags will be present, but not be shown in the agenda
1658 line. Secondary filtering will still work on the hidden tags.
1659 Nil means don't hide any tags."
1660 :group 'org-agenda-line-format
1661 :type '(choice
1662 (const :tag "Hide none" nil)
1663 (string :tag "Regexp ")))
1665 (defcustom org-agenda-remove-tags nil
1666 "Non-nil means remove the tags from the headline copy in the agenda.
1667 When this is the symbol `prefix', only remove tags when
1668 `org-agenda-prefix-format' contains a `%T' specifier."
1669 :group 'org-agenda-line-format
1670 :type '(choice
1671 (const :tag "Always" t)
1672 (const :tag "Never" nil)
1673 (const :tag "When prefix format contains %T" prefix)))
1675 (if (fboundp 'defvaralias)
1676 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1677 'org-agenda-remove-tags))
1679 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1680 "Shift tags in agenda items to this column.
1681 If this number is positive, it specifies the column. If it is negative,
1682 it means that the tags should be flushright to that column. For example,
1683 -80 works well for a normal 80 character screen."
1684 :group 'org-agenda-line-format
1685 :type 'integer)
1687 (if (fboundp 'defvaralias)
1688 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1690 (defcustom org-agenda-fontify-priorities 'cookies
1691 "Non-nil means highlight low and high priorities in agenda.
1692 When t, the highest priority entries are bold, lowest priority italic.
1693 However, settings in `org-priority-faces' will overrule these faces.
1694 When this variable is the symbol `cookies', only fontify the
1695 cookies, not the entire task.
1696 This may also be an association list of priority faces, whose
1697 keys are the character values of `org-highest-priority',
1698 `org-default-priority', and `org-lowest-priority' (the default values
1699 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1700 color as a string, or a list like `(:background \"Red\")'.
1701 If it is a color, the variable `org-faces-easy-properties'
1702 determines if it is a foreground or a background color."
1703 :group 'org-agenda-line-format
1704 :type '(choice
1705 (const :tag "Never" nil)
1706 (const :tag "Defaults" t)
1707 (const :tag "Cookies only" cookies)
1708 (repeat :tag "Specify"
1709 (list (character :tag "Priority" :value ?A)
1710 (choice :tag "Face "
1711 (string :tag "Color")
1712 (sexp :tag "Face"))))))
1714 (defcustom org-agenda-day-face-function nil
1715 "Function called to determine what face should be used to display a day.
1716 The only argument passed to that function is the day. It should
1717 returns a face, or nil if does not want to specify a face and let
1718 the normal rules apply."
1719 :group 'org-agenda-line-format
1720 :version "24.1"
1721 :type 'function)
1723 (defcustom org-agenda-category-icon-alist nil
1724 "Alist of category icon to be displayed in agenda views.
1726 Each entry should have the following format:
1728 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1730 Where CATEGORY-REGEXP is a regexp matching the categories where
1731 the icon should be displayed.
1732 FILE-OR-DATA either a file path or a string containing image data.
1734 The other fields can be omitted safely if not needed:
1735 TYPE indicates the image type.
1736 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1737 image data.
1738 PROPS are additional image attributes to assign to the image,
1739 like, e.g. `:ascent center'.
1741 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1743 If you want to set the display properties yourself, just put a
1744 list as second element:
1746 (CATEGORY-REGEXP (MY PROPERTY LIST))
1748 For example, to display a 16px horizontal space for Emacs
1749 category, you can use:
1751 (\"Emacs\" '(space . (:width (16))))"
1752 :group 'org-agenda-line-format
1753 :version "24.1"
1754 :type '(alist :key-type (string :tag "Regexp matching category")
1755 :value-type (choice (list :tag "Icon"
1756 (string :tag "File or data")
1757 (symbol :tag "Type")
1758 (boolean :tag "Data?")
1759 (repeat :tag "Extra image properties" :inline t symbol))
1760 (list :tag "Display properties" sexp))))
1762 (defgroup org-agenda-column-view nil
1763 "Options concerning column view in the agenda."
1764 :tag "Org Agenda Column View"
1765 :group 'org-agenda)
1767 (defcustom org-agenda-columns-show-summaries t
1768 "Non-nil means show summaries for columns displayed in the agenda view."
1769 :group 'org-agenda-column-view
1770 :type 'boolean)
1772 (defcustom org-agenda-columns-compute-summary-properties t
1773 "Non-nil means recompute all summary properties before column view.
1774 When column view in the agenda is listing properties that have a summary
1775 operator, it can go to all relevant buffers and recompute the summaries
1776 there. This can mean overhead for the agenda column view, but is necessary
1777 to have thing up to date.
1778 As a special case, a CLOCKSUM property also makes sure that the clock
1779 computations are current."
1780 :group 'org-agenda-column-view
1781 :type 'boolean)
1783 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1784 "Non-nil means the duration of an appointment will add to day effort.
1785 The property to which appointment durations will be added is the one given
1786 in the option `org-effort-property'. If an appointment does not have
1787 an end time, `org-agenda-default-appointment-duration' will be used. If that
1788 is not set, an appointment without end time will not contribute to the time
1789 estimate."
1790 :group 'org-agenda-column-view
1791 :type 'boolean)
1793 (defcustom org-agenda-auto-exclude-function nil
1794 "A function called with a tag to decide if it is filtered on '/ RET'.
1795 The sole argument to the function, which is called once for each
1796 possible tag, is a string giving the name of the tag. The
1797 function should return either nil if the tag should be included
1798 as normal, or \"-<TAG>\" to exclude the tag.
1799 Note that for the purpose of tag filtering, only the lower-case version of
1800 all tags will be considered, so that this function will only ever see
1801 the lower-case version of all tags."
1802 :group 'org-agenda
1803 :type 'function)
1805 (defcustom org-agenda-bulk-custom-functions nil
1806 "Alist of characters and custom functions for bulk actions.
1807 For example, this value makes those two functions available:
1809 '((?R set-category)
1810 (?C bulk-cut))
1812 With selected entries in an agenda buffer, `B R' will call
1813 the custom function `set-category' on the selected entries.
1814 Note that functions in this alist don't need to be quoted."
1815 :type 'alist
1816 :version "24.1"
1817 :group 'org-agenda)
1819 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1820 "Execute BODY with point at location given by `org-hd-marker' property.
1821 If STRING is non-nil, the text property will be fetched from position 0
1822 in that string. If STRING is nil, it will be fetched from the beginning
1823 of the current line."
1824 (org-with-gensyms (marker)
1825 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1826 'org-hd-marker ,string)))
1827 (with-current-buffer (marker-buffer ,marker)
1828 (save-excursion
1829 (goto-char ,marker)
1830 ,@body)))))
1831 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1833 (defun org-add-agenda-custom-command (entry)
1834 "Replace or add a command in `org-agenda-custom-commands'.
1835 This is mostly for hacking and trying a new command - once the command
1836 works you probably want to add it to `org-agenda-custom-commands' for good."
1837 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1838 (if ass
1839 (setcdr ass (cdr entry))
1840 (push entry org-agenda-custom-commands))))
1842 ;;; Define the org-agenda-mode
1844 (defvar org-agenda-mode-map (make-sparse-keymap)
1845 "Keymap for `org-agenda-mode'.")
1846 (if (fboundp 'defvaralias)
1847 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1849 (defvar org-agenda-menu) ; defined later in this file.
1850 (defvar org-agenda-restrict nil) ; defined later in this file.
1851 (defvar org-agenda-follow-mode nil)
1852 (defvar org-agenda-entry-text-mode nil)
1853 (defvar org-agenda-clockreport-mode nil)
1854 (defvar org-agenda-show-log nil)
1855 (defvar org-agenda-redo-command nil)
1856 (defvar org-agenda-query-string nil)
1857 (defvar org-agenda-mode-hook nil
1858 "Hook run after `org-agenda-mode' is turned on.
1859 The buffer is still writable when this hook is called.")
1860 (defvar org-agenda-type nil)
1861 (defvar org-agenda-force-single-file nil)
1862 (defvar org-agenda-bulk-marked-entries nil
1863 "List of markers that refer to marked entries in the agenda.")
1865 ;;; Multiple agenda buffers support
1867 (defcustom org-agenda-sticky nil
1868 "Non-nil means agenda q key will bury agenda buffers.
1869 Agenda commands will then show existing buffer instead of generating new ones.
1870 When nil, `q' will kill the single agenda buffer."
1871 :group 'org-agenda
1872 :type 'boolean
1873 :set (lambda (var val)
1874 (if (boundp var)
1875 (org-toggle-sticky-agenda (if val 1 0))
1876 (set var val))))
1878 ;;;###autoload
1879 (defun org-toggle-sticky-agenda (&optional arg)
1880 "Toggle `org-agenda-sticky'."
1881 (interactive "P")
1882 (let ((new-value (if arg
1883 (> (prefix-numeric-value arg) 0)
1884 (not org-agenda-sticky))))
1885 (if (equal new-value org-agenda-sticky)
1886 (and (org-called-interactively-p 'interactive)
1887 (message "Sticky agenda was already %s"
1888 (if org-agenda-sticky "enabled" "disabled")))
1889 (setq org-agenda-sticky new-value)
1890 (org-agenda-kill-all-agenda-buffers)
1891 (and (org-called-interactively-p 'interactive)
1892 (message "Sticky agenda was %s"
1893 (if org-agenda-sticky "enabled" "disabled"))))))
1895 (defvar org-agenda-buffer nil
1896 "Agenda buffer currently being generated.")
1898 (defvar org-agenda-last-prefix-arg nil)
1899 (defvar org-agenda-this-buffer-name nil)
1900 (defvar org-agenda-doing-sticky-redo nil)
1901 (defvar org-agenda-this-buffer-is-sticky nil)
1903 (defconst org-agenda-local-vars
1904 '(org-agenda-this-buffer-name
1905 org-agenda-undo-list
1906 org-agenda-pending-undo-list
1907 org-agenda-follow-mode
1908 org-agenda-entry-text-mode
1909 org-agenda-clockreport-mode
1910 org-agenda-show-log
1911 org-agenda-redo-command
1912 org-agenda-query-string
1913 org-agenda-type
1914 org-agenda-bulk-marked-entries
1915 org-agenda-undo-has-started-in
1916 org-agenda-info
1917 org-agenda-tag-filter-overlays
1918 org-agenda-cat-filter-overlays
1919 org-agenda-pre-window-conf
1920 org-agenda-columns-active
1921 org-agenda-tag-filter
1922 org-agenda-category-filter
1923 org-agenda-markers
1924 org-agenda-last-search-view-search-was-boolean
1925 org-agenda-filtered-by-category
1926 org-agenda-filter-form
1927 org-agenda-show-window
1928 org-agenda-cycle-counter
1929 org-agenda-last-prefix-arg)
1930 "Variables that must be local in agenda buffers to allow multiple buffers.")
1932 (defun org-agenda-mode ()
1933 "Mode for time-sorted view on action items in Org-mode files.
1935 The following commands are available:
1937 \\{org-agenda-mode-map}"
1938 (interactive)
1939 (cond (org-agenda-doing-sticky-redo
1940 ;; Refreshing sticky agenda-buffer
1942 ;; Preserve the value of `org-agenda-local-vars' variables,
1943 ;; while letting `kill-all-local-variables' kill the rest
1944 (let ((save (buffer-local-variables)))
1945 (kill-all-local-variables)
1946 (mapc 'make-local-variable org-agenda-local-vars)
1947 (dolist (elem save)
1948 (let ((var (car elem))
1949 (val (cdr elem)))
1950 (when (and val
1951 (member var org-agenda-local-vars))
1952 (set var val)))))
1953 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1954 (org-agenda-sticky
1955 ;; Creating a sticky Agenda buffer for the first time
1956 (kill-all-local-variables)
1957 (mapc 'make-local-variable org-agenda-local-vars)
1958 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1960 ;; Creating a non-sticky agenda buffer
1961 (kill-all-local-variables)
1962 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1963 (setq org-agenda-undo-list nil
1964 org-agenda-pending-undo-list nil
1965 org-agenda-bulk-marked-entries nil)
1966 (setq major-mode 'org-agenda-mode)
1967 ;; Keep global-font-lock-mode from turning on font-lock-mode
1968 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1969 (setq mode-name "Org-Agenda")
1970 (use-local-map org-agenda-mode-map)
1971 (easy-menu-add org-agenda-menu)
1972 (if org-startup-truncated (setq truncate-lines t))
1973 (org-set-local 'line-move-visual nil)
1974 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1975 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1976 ;; Make sure properties are removed when copying text
1977 (make-local-variable 'filter-buffer-substring-functions)
1978 (add-hook 'filter-buffer-substring-functions
1979 (lambda (fun start end delete)
1980 (substring-no-properties (funcall fun start end delete))))
1981 (unless org-agenda-keep-modes
1982 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1983 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1984 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1985 org-agenda-show-log org-agenda-start-with-log-mode))
1987 (easy-menu-change
1988 '("Agenda") "Agenda Files"
1989 (append
1990 (list
1991 (vector
1992 (if (get 'org-agenda-files 'org-restrict)
1993 "Restricted to single file"
1994 "Edit File List")
1995 '(org-edit-agenda-file-list)
1996 (not (get 'org-agenda-files 'org-restrict)))
1997 "--")
1998 (mapcar 'org-file-menu-entry (org-agenda-files))))
1999 (org-agenda-set-mode-name)
2000 (apply
2001 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2002 (list 'org-agenda-mode-hook)))
2004 (substitute-key-definition 'undo 'org-agenda-undo
2005 org-agenda-mode-map global-map)
2006 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2007 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2008 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2009 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2010 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2011 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2012 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2013 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2014 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2015 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2016 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2017 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2018 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2019 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2020 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2021 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2022 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2023 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2024 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2025 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2026 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2027 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2028 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2029 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2030 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2031 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2032 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2033 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2034 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2035 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2036 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2037 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2038 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2039 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2040 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2041 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2042 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2043 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2044 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2045 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2046 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2047 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2048 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2049 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2050 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2052 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2053 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2054 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2055 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2056 (while l (org-defkey org-agenda-mode-map
2057 (int-to-string (pop l)) 'digit-argument)))
2059 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2060 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2061 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2062 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2063 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2064 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2065 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2066 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2067 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2068 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2069 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2070 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2071 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2072 'org-clock-modify-effort-estimate)
2073 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2074 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2075 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2076 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2077 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2078 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2079 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2080 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2081 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2082 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2083 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2084 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2085 (substitute-key-definition 'next-line 'org-agenda-next-line
2086 org-agenda-mode-map global-map)
2087 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2088 org-agenda-mode-map global-map)
2089 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2090 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2091 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2092 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2093 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2094 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2095 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2096 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2097 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2098 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2099 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2100 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2101 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2102 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2103 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2104 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2105 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2106 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2107 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2108 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2109 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2110 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2111 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2112 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2113 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2114 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2115 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2116 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2117 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2120 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2121 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2122 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2123 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2124 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2125 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2126 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2127 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2128 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2129 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2130 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2131 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2133 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2134 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2135 (when org-agenda-mouse-1-follows-link
2136 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2137 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2138 '("Agenda"
2139 ("Agenda Files")
2140 "--"
2141 ("Agenda Dates"
2142 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2143 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2144 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2145 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2146 "--"
2147 ("View"
2148 ["Day View" org-agenda-day-view
2149 :active (org-agenda-check-type nil 'agenda)
2150 :style radio :selected (eq org-agenda-current-span 'day)
2151 :keys "v d (or just d)"]
2152 ["Week View" org-agenda-week-view
2153 :active (org-agenda-check-type nil 'agenda)
2154 :style radio :selected (eq org-agenda-current-span 'week)
2155 :keys "v w (or just w)"]
2156 ["Month View" org-agenda-month-view
2157 :active (org-agenda-check-type nil 'agenda)
2158 :style radio :selected (eq org-agenda-current-span 'month)
2159 :keys "v m"]
2160 ["Year View" org-agenda-year-view
2161 :active (org-agenda-check-type nil 'agenda)
2162 :style radio :selected (eq org-agenda-current-span 'year)
2163 :keys "v y"]
2164 "--"
2165 ["Include Diary" org-agenda-toggle-diary
2166 :style toggle :selected org-agenda-include-diary
2167 :active (org-agenda-check-type nil 'agenda)]
2168 ["Include Deadlines" org-agenda-toggle-deadlines
2169 :style toggle :selected org-agenda-include-deadlines
2170 :active (org-agenda-check-type nil 'agenda)]
2171 ["Use Time Grid" org-agenda-toggle-time-grid
2172 :style toggle :selected org-agenda-use-time-grid
2173 :active (org-agenda-check-type nil 'agenda)]
2174 "--"
2175 ["Show clock report" org-agenda-clockreport-mode
2176 :style toggle :selected org-agenda-clockreport-mode
2177 :active (org-agenda-check-type nil 'agenda)]
2178 ["Show some entry text" org-agenda-entry-text-mode
2179 :style toggle :selected org-agenda-entry-text-mode
2180 :active t]
2181 "--"
2182 ["Show Logbook entries" org-agenda-log-mode
2183 :style toggle :selected org-agenda-show-log
2184 :active (org-agenda-check-type nil 'agenda 'timeline)
2185 :keys "v l (or just l)"]
2186 ["Include archived trees" org-agenda-archives-mode
2187 :style toggle :selected org-agenda-archives-mode :active t
2188 :keys "v a"]
2189 ["Include archive files" (org-agenda-archives-mode t)
2190 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2191 :keys "v A"]
2192 "--"
2193 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2194 ["Write view to file" org-agenda-write t]
2195 ["Rebuild buffer" org-agenda-redo t]
2196 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2197 "--"
2198 ["Show original entry" org-agenda-show t]
2199 ["Go To (other window)" org-agenda-goto t]
2200 ["Go To (this window)" org-agenda-switch-to t]
2201 ["Capture with cursor date" org-agenda-capture t]
2202 ["Follow Mode" org-agenda-follow-mode
2203 :style toggle :selected org-agenda-follow-mode :active t]
2204 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2205 "--"
2206 ("TODO"
2207 ["Cycle TODO" org-agenda-todo t]
2208 ["Next TODO set" org-agenda-todo-nextset t]
2209 ["Previous TODO set" org-agenda-todo-previousset t]
2210 ["Add note" org-agenda-add-note t])
2211 ("Archive/Refile/Delete"
2212 ["Archive default" org-agenda-archive-default t]
2213 ["Archive default" org-agenda-archive-default-with-confirmation t]
2214 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2215 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2216 ["Archive subtree" org-agenda-archive t]
2217 "--"
2218 ["Refile" org-agenda-refile t]
2219 "--"
2220 ["Delete subtree" org-agenda-kill t])
2221 ("Bulk action"
2222 ["Mark entry" org-agenda-bulk-mark t]
2223 ["Mark all" org-agenda-bulk-mark-all t]
2224 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2225 ["Unmark entry" org-agenda-bulk-unmark t]
2226 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2227 ["Act on all marked" org-agenda-bulk-action t]
2228 "--"
2229 ("Tags and Properties"
2230 ["Show all Tags" org-agenda-show-tags t]
2231 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2232 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2233 "--"
2234 ["Column View" org-columns t])
2235 ("Deadline/Schedule"
2236 ["Schedule" org-agenda-schedule t]
2237 ["Set Deadline" org-agenda-deadline t]
2238 "--"
2239 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2240 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2241 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2242 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2243 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2244 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2245 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2246 ("Clock and Effort"
2247 ["Clock in" org-agenda-clock-in t]
2248 ["Clock out" org-agenda-clock-out t]
2249 ["Clock cancel" org-agenda-clock-cancel t]
2250 ["Goto running clock" org-clock-goto t]
2251 "--"
2252 ["Set Effort" org-agenda-set-effort t]
2253 ["Change clocked effort" org-clock-modify-effort-estimate
2254 (org-clock-is-active)])
2255 ("Priority"
2256 ["Set Priority" org-agenda-priority t]
2257 ["Increase Priority" org-agenda-priority-up t]
2258 ["Decrease Priority" org-agenda-priority-down t]
2259 ["Show Priority" org-agenda-show-priority t])
2260 ("Calendar/Diary"
2261 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2262 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2263 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2264 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2265 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2266 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2267 "--"
2268 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2269 "--"
2270 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2271 "--"
2272 ("MobileOrg"
2273 ["Push Files and Views" org-mobile-push t]
2274 ["Get Captured and Flagged" org-mobile-pull t]
2275 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2276 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2277 "--"
2278 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2279 "--"
2280 ["Quit" org-agenda-quit t]
2281 ["Exit and Release Buffers" org-agenda-exit t]
2284 ;;; Agenda undo
2286 (defvar org-agenda-allow-remote-undo t
2287 "Non-nil means allow remote undo from the agenda buffer.")
2288 (defvar org-agenda-undo-has-started-in nil
2289 "Buffers that have already seen `undo-start' in the current undo sequence.")
2291 (defun org-agenda-undo ()
2292 "Undo a remote editing step in the agenda.
2293 This undoes changes both in the agenda buffer and in the remote buffer
2294 that have been changed along."
2295 (interactive)
2296 (or org-agenda-allow-remote-undo
2297 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2298 (if (not (eq this-command last-command))
2299 (setq org-agenda-undo-has-started-in nil
2300 org-agenda-pending-undo-list org-agenda-undo-list))
2301 (if (not org-agenda-pending-undo-list)
2302 (error "No further undo information"))
2303 (let* ((entry (pop org-agenda-pending-undo-list))
2304 buf line cmd rembuf)
2305 (setq cmd (pop entry) line (pop entry))
2306 (setq rembuf (nth 2 entry))
2307 (org-with-remote-undo rembuf
2308 (while (bufferp (setq buf (pop entry)))
2309 (if (pop entry)
2310 (with-current-buffer buf
2311 (let ((last-undo-buffer buf)
2312 (inhibit-read-only t))
2313 (unless (memq buf org-agenda-undo-has-started-in)
2314 (push buf org-agenda-undo-has-started-in)
2315 (make-local-variable 'pending-undo-list)
2316 (undo-start))
2317 (while (and pending-undo-list
2318 (listp pending-undo-list)
2319 (not (car pending-undo-list)))
2320 (pop pending-undo-list))
2321 (undo-more 1))))))
2322 (org-goto-line line)
2323 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2325 (defun org-verify-change-for-undo (l1 l2)
2326 "Verify that a real change occurred between the undo lists L1 and L2."
2327 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2328 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2329 (not (eq l1 l2)))
2331 ;;; Agenda dispatch
2333 (defvar org-agenda-restrict-begin (make-marker))
2334 (defvar org-agenda-restrict-end (make-marker))
2335 (defvar org-agenda-last-dispatch-buffer nil)
2336 (defvar org-agenda-overriding-restriction nil)
2338 (defcustom org-agenda-custom-commands-contexts nil
2339 "Alist of custom agenda keys and contextual rules.
2341 For example, if you have a custom agenda command \"p\" and you
2342 want this command to be accessible only from plain text files,
2343 use this:
2345 '((\"p\" (in-file . \"\\.txt\")))
2347 Here are the available contexts definitions:
2349 in-file: command displayed only in matching files
2350 in-mode: command displayed only in matching modes
2351 not-in-file: command not displayed in matching files
2352 not-in-mode: command not displayed in matching modes
2353 [function]: a custom function taking no argument
2355 If you define several checks, the agenda command will be
2356 accessible if there is at least one valid check.
2358 You can also bind a key to another agenda custom command
2359 depending on contextual rules.
2361 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2363 Here it means: in .txt files, use \"p\" as the key for the
2364 agenda command otherwise associated with \"q\". (The command
2365 originally associated with \"q\" is not displayed to avoid
2366 duplicates.)"
2367 ;; :version "24.3"
2368 :group 'org-agenda-custom-commands
2369 :type '(repeat (list :tag "Rule"
2370 (string :tag " Agenda key")
2371 (string :tag "Replace by command")
2372 (repeat :tag "Available when"
2373 (choice
2374 (cons :tag "Condition"
2375 (choice
2376 (const :tag "In file" in-file)
2377 (const :tag "Not in file" not-in-file)
2378 (const :tag "In mode" in-mode)
2379 (const :tag "Not in mode" not-in-mode))
2380 (regexp))
2381 (function :tag "Custom function"))))))
2383 (defvar org-keys nil)
2384 (defvar org-match nil)
2385 ;;;###autoload
2386 (defun org-agenda (&optional arg org-keys restriction)
2387 "Dispatch agenda commands to collect entries to the agenda buffer.
2388 Prompts for a command to execute. Any prefix arg will be passed
2389 on to the selected command. The default selections are:
2391 a Call `org-agenda-list' to display the agenda for current day or week.
2392 t Call `org-todo-list' to display the global todo list.
2393 T Call `org-todo-list' to display the global todo list, select only
2394 entries with a specific TODO keyword (the user gets a prompt).
2395 m Call `org-tags-view' to display headlines with tags matching
2396 a condition (the user is prompted for the condition).
2397 M Like `m', but select only TODO entries, no ordinary headlines.
2398 L Create a timeline for the current buffer.
2399 e Export views to associated files.
2400 s Search entries for keywords.
2401 S Search entries for keywords, only with TODO keywords.
2402 / Multi occur across all agenda files and also files listed
2403 in `org-agenda-text-search-extra-files'.
2404 < Restrict agenda commands to buffer, subtree, or region.
2405 Press several times to get the desired effect.
2406 > Remove a previous restriction.
2407 # List \"stuck\" projects.
2408 ! Configure what \"stuck\" means.
2409 C Configure custom agenda commands.
2411 More commands can be added by configuring the variable
2412 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2413 searches can be pre-defined in this way.
2415 If the current buffer is in Org-mode and visiting a file, you can also
2416 first press `<' once to indicate that the agenda should be temporarily
2417 \(until the next use of \\[org-agenda]) restricted to the current file.
2418 Pressing `<' twice means to restrict to the current subtree or region
2419 \(if active)."
2420 (interactive "P")
2421 (catch 'exit
2422 (let* ((prefix-descriptions nil)
2423 (org-agenda-buffer-name org-agenda-buffer-name)
2424 (org-agenda-window-setup (if (equal (buffer-name)
2425 org-agenda-buffer-name)
2426 'current-window
2427 org-agenda-window-setup))
2428 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2429 (org-agenda-custom-commands
2430 ;; normalize different versions
2431 (delq nil
2432 (mapcar
2433 (lambda (x)
2434 (cond ((stringp (cdr x))
2435 (push x prefix-descriptions)
2436 nil)
2437 ((stringp (nth 1 x)) x)
2438 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2439 (t (cons (car x) (cons "" (cdr x))))))
2440 org-agenda-custom-commands)))
2441 (org-agenda-custom-commands
2442 (org-contextualize-keys
2443 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2444 (buf (current-buffer))
2445 (bfn (buffer-file-name (buffer-base-buffer)))
2446 entry key type org-match lprops ans)
2447 ;; Turn off restriction unless there is an overriding one,
2448 (unless org-agenda-overriding-restriction
2449 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2450 ;; There is a request to keep the file list in place
2451 (put 'org-agenda-files 'org-restrict nil))
2452 (setq org-agenda-restrict nil)
2453 (move-marker org-agenda-restrict-begin nil)
2454 (move-marker org-agenda-restrict-end nil))
2455 ;; Delete old local properties
2456 (put 'org-agenda-redo-command 'org-lprops nil)
2457 ;; Delete previously set last-arguments
2458 (put 'org-agenda-redo-command 'last-args nil)
2459 ;; Remember where this call originated
2460 (setq org-agenda-last-dispatch-buffer (current-buffer))
2461 (unless org-keys
2462 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2463 org-keys (car ans)
2464 restriction (cdr ans)))
2465 ;; If we have sticky agenda buffers, set a name for the buffer,
2466 ;; depending on the invoking keys. The user may still set this
2467 ;; as a command option, which will overwrite what we do here.
2468 (if org-agenda-sticky
2469 (setq org-agenda-buffer-name
2470 (format "*Org Agenda(%s)*" org-keys)))
2471 ;; Establish the restriction, if any
2472 (when (and (not org-agenda-overriding-restriction) restriction)
2473 (put 'org-agenda-files 'org-restrict (list bfn))
2474 (cond
2475 ((eq restriction 'region)
2476 (setq org-agenda-restrict t)
2477 (move-marker org-agenda-restrict-begin (region-beginning))
2478 (move-marker org-agenda-restrict-end (region-end)))
2479 ((eq restriction 'subtree)
2480 (save-excursion
2481 (setq org-agenda-restrict t)
2482 (org-back-to-heading t)
2483 (move-marker org-agenda-restrict-begin (point))
2484 (move-marker org-agenda-restrict-end
2485 (progn (org-end-of-subtree t)))))))
2487 ;; For example the todo list should not need it (but does...)
2488 (cond
2489 ((setq entry (assoc org-keys org-agenda-custom-commands))
2490 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2491 (progn
2492 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2493 lprops (nth 4 entry))
2494 (if org-agenda-sticky
2495 (setq org-agenda-buffer-name
2496 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2497 (format "*Org Agenda(%s)*" org-keys))))
2498 (put 'org-agenda-redo-command 'org-lprops lprops)
2499 (cond
2500 ((eq type 'agenda)
2501 (org-let lprops '(org-agenda-list current-prefix-arg)))
2502 ((eq type 'alltodo)
2503 (org-let lprops '(org-todo-list current-prefix-arg)))
2504 ((eq type 'search)
2505 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2506 ((eq type 'stuck)
2507 (org-let lprops '(org-agenda-list-stuck-projects
2508 current-prefix-arg)))
2509 ((eq type 'tags)
2510 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2511 ((eq type 'tags-todo)
2512 (org-let lprops '(org-tags-view '(4) org-match)))
2513 ((eq type 'todo)
2514 (org-let lprops '(org-todo-list org-match)))
2515 ((eq type 'tags-tree)
2516 (org-check-for-org-mode)
2517 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2518 ((eq type 'todo-tree)
2519 (org-check-for-org-mode)
2520 (org-let lprops
2521 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2522 (regexp-quote org-match) "\\>"))))
2523 ((eq type 'occur-tree)
2524 (org-check-for-org-mode)
2525 (org-let lprops '(org-occur org-match)))
2526 ((functionp type)
2527 (org-let lprops '(funcall type org-match)))
2528 ((fboundp type)
2529 (org-let lprops '(funcall type org-match)))
2530 (t (error "Invalid custom agenda command type %s" type))))
2531 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2532 ((equal org-keys "C")
2533 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2534 (customize-variable 'org-agenda-custom-commands))
2535 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2536 ((equal org-keys "s") (call-interactively 'org-search-view))
2537 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2538 ((equal org-keys "t") (call-interactively 'org-todo-list))
2539 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2540 ((equal org-keys "m") (call-interactively 'org-tags-view))
2541 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2542 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2543 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2544 (org-add-hook
2545 'post-command-hook
2546 (lambda ()
2547 (unless (current-message)
2548 (let* ((m (org-agenda-get-any-marker))
2549 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2550 (when note
2551 (message (concat
2552 "FLAGGING-NOTE ([?] for more info): "
2553 (org-add-props
2554 (replace-regexp-in-string
2555 "\\\\n" "//"
2556 (copy-sequence note))
2557 nil 'face 'org-warning)))))))
2558 t t))
2559 ((equal org-keys "L")
2560 (unless (derived-mode-p 'org-mode)
2561 (error "This is not an Org-mode file"))
2562 (unless restriction
2563 (put 'org-agenda-files 'org-restrict (list bfn))
2564 (org-call-with-arg 'org-timeline arg)))
2565 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2566 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2567 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2568 (t (error "Invalid agenda key"))))))
2570 (defun org-agenda-append-agenda ()
2571 "Append another agenda view to the current one.
2572 This function allows interactive building of block agendas.
2573 Agenda views are separated by `org-agenda-block-separator'."
2574 (interactive)
2575 (unless (derived-mode-p 'org-agenda-mode)
2576 (error "Can only append from within agenda buffer"))
2577 (let ((org-agenda-multi t))
2578 (org-agenda)
2579 (widen)
2580 (org-agenda-finalize)
2581 (org-agenda-fit-window-to-buffer)))
2583 (defun org-agenda-normalize-custom-commands (cmds)
2584 (delq nil
2585 (mapcar
2586 (lambda (x)
2587 (cond ((stringp (cdr x)) nil)
2588 ((stringp (nth 1 x)) x)
2589 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2590 (t (cons (car x) (cons "" (cdr x))))))
2591 cmds)))
2593 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2594 "The user interface for selecting an agenda command."
2595 (catch 'exit
2596 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2597 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2598 (region-p (org-region-active-p))
2599 (custom org-agenda-custom-commands)
2600 (selstring "")
2601 restriction second-time
2602 c entry key type match prefixes rmheader header-end custom1 desc
2603 line lines left right n n1)
2604 (save-window-excursion
2605 (delete-other-windows)
2606 (org-switch-to-buffer-other-window " *Agenda Commands*")
2607 (erase-buffer)
2608 (insert (eval-when-compile
2609 (let ((header
2610 "Press key for an agenda command: < Buffer, subtree/region restriction
2611 -------------------------------- > Remove restriction
2612 a Agenda for current week or day e Export agenda views
2613 t List of all TODO entries T Entries with special TODO kwd
2614 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2615 s Search for keywords S Like s, but only TODO entries
2616 L Timeline for current buffer # List stuck projects (!=configure)
2617 / Multi-occur C Configure custom agenda commands
2618 ? Find :FLAGGED: entries * Toggle sticky agenda views
2620 (start 0))
2621 (while (string-match
2622 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2623 header start)
2624 (setq start (match-end 0))
2625 (add-text-properties (match-beginning 2) (match-end 2)
2626 '(face bold) header))
2627 header)))
2628 (setq header-end (move-marker (make-marker) (point)))
2629 (while t
2630 (setq custom1 custom)
2631 (when (eq rmheader t)
2632 (org-goto-line 1)
2633 (re-search-forward ":" nil t)
2634 (delete-region (match-end 0) (point-at-eol))
2635 (forward-char 1)
2636 (looking-at "-+")
2637 (delete-region (match-end 0) (point-at-eol))
2638 (move-marker header-end (match-end 0)))
2639 (goto-char header-end)
2640 (delete-region (point) (point-max))
2642 ;; Produce all the lines that describe custom commands and prefixes
2643 (setq lines nil)
2644 (while (setq entry (pop custom1))
2645 (setq key (car entry) desc (nth 1 entry)
2646 type (nth 2 entry)
2647 match (nth 3 entry))
2648 (if (> (length key) 1)
2649 (add-to-list 'prefixes (string-to-char key))
2650 (setq line
2651 (format
2652 "%-4s%-14s"
2653 (org-add-props (copy-sequence key)
2654 '(face bold))
2655 (cond
2656 ((string-match "\\S-" desc) desc)
2657 ((eq type 'agenda) "Agenda for current week or day")
2658 ((eq type 'alltodo) "List of all TODO entries")
2659 ((eq type 'search) "Word search")
2660 ((eq type 'stuck) "List of stuck projects")
2661 ((eq type 'todo) "TODO keyword")
2662 ((eq type 'tags) "Tags query")
2663 ((eq type 'tags-todo) "Tags (TODO)")
2664 ((eq type 'tags-tree) "Tags tree")
2665 ((eq type 'todo-tree) "TODO kwd tree")
2666 ((eq type 'occur-tree) "Occur tree")
2667 ((functionp type) (if (symbolp type)
2668 (symbol-name type)
2669 "Lambda expression"))
2670 (t "???"))))
2671 (if org-agenda-menu-show-matcher
2672 (setq line
2673 (concat line ": "
2674 (cond
2675 ((stringp match)
2676 (setq match (copy-sequence match))
2677 (org-add-props match nil 'face 'org-warning))
2678 (match
2679 (format "set of %d commands" (length match)))
2680 (t ""))))
2681 (if (org-string-nw-p match)
2682 (add-text-properties
2683 0 (length line) (list 'help-echo
2684 (concat "Matcher: "match)) line)))
2685 (push line lines)))
2686 (setq lines (nreverse lines))
2687 (when prefixes
2688 (mapc (lambda (x)
2689 (push
2690 (format "%s %s"
2691 (org-add-props (char-to-string x)
2692 nil 'face 'bold)
2693 (or (cdr (assoc (concat selstring
2694 (char-to-string x))
2695 prefix-descriptions))
2696 "Prefix key"))
2697 lines))
2698 prefixes))
2700 ;; Check if we should display in two columns
2701 (if org-agenda-menu-two-columns
2702 (progn
2703 (setq n (length lines)
2704 n1 (+ (/ n 2) (mod n 2))
2705 right (nthcdr n1 lines)
2706 left (copy-sequence lines))
2707 (setcdr (nthcdr (1- n1) left) nil))
2708 (setq left lines right nil))
2709 (while left
2710 (insert "\n" (pop left))
2711 (when right
2712 (if (< (current-column) 40)
2713 (move-to-column 40 t)
2714 (insert " "))
2715 (insert (pop right))))
2717 ;; Make the window the right size
2718 (goto-char (point-min))
2719 (if second-time
2720 (if (not (pos-visible-in-window-p (point-max)))
2721 (org-fit-window-to-buffer))
2722 (setq second-time t)
2723 (org-fit-window-to-buffer))
2725 ;; Ask for selection
2726 (message "Press key for agenda command%s:"
2727 (if (or restrict-ok org-agenda-overriding-restriction)
2728 (if org-agenda-overriding-restriction
2729 " (restriction lock active)"
2730 (if restriction
2731 (format " (restricted to %s)" restriction)
2732 " (unrestricted)"))
2733 ""))
2734 (setq c (read-char-exclusive))
2735 (message "")
2736 (cond
2737 ((assoc (char-to-string c) custom)
2738 (setq selstring (concat selstring (char-to-string c)))
2739 (throw 'exit (cons selstring restriction)))
2740 ((memq c prefixes)
2741 (setq selstring (concat selstring (char-to-string c))
2742 prefixes nil
2743 rmheader (or rmheader t)
2744 custom (delq nil (mapcar
2745 (lambda (x)
2746 (if (or (= (length (car x)) 1)
2747 (/= (string-to-char (car x)) c))
2749 (cons (substring (car x) 1) (cdr x))))
2750 custom))))
2751 ((eq c ?*)
2752 (call-interactively 'org-toggle-sticky-agenda)
2753 (sit-for 2))
2754 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2755 (message "Restriction is only possible in Org-mode buffers")
2756 (ding) (sit-for 1))
2757 ((eq c ?1)
2758 (org-agenda-remove-restriction-lock 'noupdate)
2759 (setq restriction 'buffer))
2760 ((eq c ?0)
2761 (org-agenda-remove-restriction-lock 'noupdate)
2762 (setq restriction (if region-p 'region 'subtree)))
2763 ((eq c ?<)
2764 (org-agenda-remove-restriction-lock 'noupdate)
2765 (setq restriction
2766 (cond
2767 ((eq restriction 'buffer)
2768 (if region-p 'region 'subtree))
2769 ((memq restriction '(subtree region))
2770 nil)
2771 (t 'buffer))))
2772 ((eq c ?>)
2773 (org-agenda-remove-restriction-lock 'noupdate)
2774 (setq restriction nil))
2775 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2776 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2777 ((and (> (length selstring) 0) (eq c ?\d))
2778 (delete-window)
2779 (org-agenda-get-restriction-and-command prefix-descriptions))
2781 ((equal c ?q) (error "Abort"))
2782 (t (error "Invalid key %c" c))))))))
2784 (defun org-agenda-fit-window-to-buffer ()
2785 "Fit the window to the buffer size."
2786 (and (memq org-agenda-window-setup '(reorganize-frame))
2787 (fboundp 'fit-window-to-buffer)
2788 (org-fit-window-to-buffer
2790 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2791 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2793 (defvar org-cmd nil)
2794 (defvar org-agenda-overriding-cmd nil)
2795 (defvar org-agenda-overriding-arguments nil)
2796 (defvar org-agenda-overriding-cmd-arguments nil)
2797 (defun org-agenda-run-series (name series)
2798 (org-let (nth 1 series) '(org-agenda-prepare name))
2799 ;; We need to reset agenda markers here, because when constructing a
2800 ;; block agenda, the individual blocks do not do that.
2801 (org-agenda-reset-markers)
2802 (let* ((org-agenda-multi t)
2803 (redo (list 'org-agenda-run-series name (list 'quote series)))
2804 (cmds (car series))
2805 (gprops (nth 1 series))
2806 match ;; The byte compiler incorrectly complains about this. Keep it!
2807 org-cmd type lprops)
2808 (while (setq org-cmd (pop cmds))
2809 (setq type (car org-cmd)
2810 match (eval (nth 1 org-cmd))
2811 lprops (nth 2 org-cmd))
2812 (let ((org-agenda-overriding-arguments
2813 (if (eq org-agenda-overriding-cmd org-cmd)
2814 (or org-agenda-overriding-arguments
2815 org-agenda-overriding-cmd-arguments))))
2816 (cond
2817 ((eq type 'agenda)
2818 (org-let2 gprops lprops
2819 '(call-interactively 'org-agenda-list)))
2820 ((eq type 'alltodo)
2821 (org-let2 gprops lprops
2822 '(call-interactively 'org-todo-list)))
2823 ((eq type 'search)
2824 (org-let2 gprops lprops
2825 '(org-search-view current-prefix-arg match nil)))
2826 ((eq type 'stuck)
2827 (org-let2 gprops lprops
2828 '(call-interactively 'org-agenda-list-stuck-projects)))
2829 ((eq type 'tags)
2830 (org-let2 gprops lprops
2831 '(org-tags-view current-prefix-arg match)))
2832 ((eq type 'tags-todo)
2833 (org-let2 gprops lprops
2834 '(org-tags-view '(4) match)))
2835 ((eq type 'todo)
2836 (org-let2 gprops lprops
2837 '(org-todo-list match)))
2838 ((fboundp type)
2839 (org-let2 gprops lprops
2840 '(funcall type match)))
2841 (t (error "Invalid type in command series")))))
2842 (widen)
2843 (let ((inhibit-read-only t))
2844 (add-text-properties (point-min) (point-max)
2845 `(org-serie t org-serie-redo-cmd ,redo)))
2846 (setq org-agenda-redo-command redo)
2847 (goto-char (point-min)))
2848 (org-agenda-fit-window-to-buffer)
2849 (org-let (nth 1 series) '(org-agenda-finalize)))
2851 ;;;###autoload
2852 (defmacro org-batch-agenda (cmd-key &rest parameters)
2853 "Run an agenda command in batch mode and send the result to STDOUT.
2854 If CMD-KEY is a string of length 1, it is used as a key in
2855 `org-agenda-custom-commands' and triggers this command. If it is a
2856 longer string it is used as a tags/todo match string.
2857 Parameters are alternating variable names and values that will be bound
2858 before running the agenda command."
2859 (org-eval-in-environment (org-make-parameter-alist parameters)
2860 (if (> (length cmd-key) 2)
2861 (org-tags-view nil cmd-key)
2862 (org-agenda nil cmd-key)))
2863 (set-buffer org-agenda-buffer-name)
2864 (princ (buffer-string)))
2865 (def-edebug-spec org-batch-agenda (form &rest sexp))
2867 (defvar org-agenda-info nil)
2869 ;;;###autoload
2870 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2871 "Run an agenda command in batch mode and send the result to STDOUT.
2872 If CMD-KEY is a string of length 1, it is used as a key in
2873 `org-agenda-custom-commands' and triggers this command. If it is a
2874 longer string it is used as a tags/todo match string.
2875 Parameters are alternating variable names and values that will be bound
2876 before running the agenda command.
2878 The output gives a line for each selected agenda item. Each
2879 item is a list of comma-separated values, like this:
2881 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2883 category The category of the item
2884 head The headline, without TODO kwd, TAGS and PRIORITY
2885 type The type of the agenda entry, can be
2886 todo selected in TODO match
2887 tagsmatch selected in tags match
2888 diary imported from diary
2889 deadline a deadline on given date
2890 scheduled scheduled on given date
2891 timestamp entry has timestamp on given date
2892 closed entry was closed on given date
2893 upcoming-deadline warning about deadline
2894 past-scheduled forwarded scheduled item
2895 block entry has date block including g. date
2896 todo The todo keyword, if any
2897 tags All tags including inherited ones, separated by colons
2898 date The relevant date, like 2007-2-14
2899 time The time, like 15:00-16:50
2900 extra Sting with extra planning info
2901 priority-l The priority letter if any was given
2902 priority-n The computed numerical priority
2903 agenda-day The day in the agenda where this is listed"
2904 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2905 (org-make-parameter-alist parameters))
2906 (if (> (length cmd-key) 2)
2907 (org-tags-view nil cmd-key)
2908 (org-agenda nil cmd-key)))
2909 (set-buffer org-agenda-buffer-name)
2910 (let* ((lines (org-split-string (buffer-string) "\n"))
2911 line)
2912 (while (setq line (pop lines))
2913 (catch 'next
2914 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2915 (setq org-agenda-info
2916 (org-fix-agenda-info (text-properties-at 0 line)))
2917 (princ
2918 (mapconcat 'org-agenda-export-csv-mapper
2919 '(org-category txt type todo tags date time extra
2920 priority-letter priority agenda-day)
2921 ","))
2922 (princ "\n")))))
2923 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2925 (defun org-fix-agenda-info (props)
2926 "Make sure all properties on an agenda item have a canonical form.
2927 This ensures the export commands can easily use it."
2928 (let (tmp re)
2929 (when (setq tmp (plist-get props 'tags))
2930 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2931 (when (setq tmp (plist-get props 'date))
2932 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2933 (let ((calendar-date-display-form '(year "-" month "-" day)))
2934 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2936 (setq tmp (calendar-date-string tmp)))
2937 (setq props (plist-put props 'date tmp)))
2938 (when (setq tmp (plist-get props 'day))
2939 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2940 (let ((calendar-date-display-form '(year "-" month "-" day)))
2941 (setq tmp (calendar-date-string tmp)))
2942 (setq props (plist-put props 'day tmp))
2943 (setq props (plist-put props 'agenda-day tmp)))
2944 (when (setq tmp (plist-get props 'txt))
2945 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2946 (plist-put props 'priority-letter (match-string 1 tmp))
2947 (setq tmp (replace-match "" t t tmp)))
2948 (when (and (setq re (plist-get props 'org-todo-regexp))
2949 (setq re (concat "\\`\\.*" re " ?"))
2950 (string-match re tmp))
2951 (plist-put props 'todo (match-string 1 tmp))
2952 (setq tmp (replace-match "" t t tmp)))
2953 (plist-put props 'txt tmp)))
2954 props)
2956 (defun org-agenda-export-csv-mapper (prop)
2957 (let ((res (plist-get org-agenda-info prop)))
2958 (setq res
2959 (cond
2960 ((not res) "")
2961 ((stringp res) res)
2962 (t (prin1-to-string res))))
2963 (while (string-match "," res)
2964 (setq res (replace-match ";" t t res)))
2965 (org-trim res)))
2967 ;;;###autoload
2968 (defun org-store-agenda-views (&rest parameters)
2969 (interactive)
2970 (eval (list 'org-batch-store-agenda-views)))
2972 ;;;###autoload
2973 (defmacro org-batch-store-agenda-views (&rest parameters)
2974 "Run all custom agenda commands that have a file argument."
2975 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2976 (pop-up-frames nil)
2977 (dir default-directory)
2978 (pars (org-make-parameter-alist parameters))
2979 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
2980 (save-window-excursion
2981 (while cmds
2982 (setq cmd (pop cmds)
2983 thiscmdkey (car cmd)
2984 thiscmdcmd (cdr cmd)
2985 match (nth 2 thiscmdcmd)
2986 bufname (if org-agenda-sticky
2987 (or (and (stringp match)
2988 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
2989 (format "*Org Agenda(%s)*" thiscmdkey))
2990 org-agenda-buffer-name)
2991 cmd-or-set (nth 2 cmd)
2992 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2993 files (nth (if (listp cmd-or-set) 4 5) cmd))
2994 (if (stringp files) (setq files (list files)))
2995 (when files
2996 (org-eval-in-environment (append org-agenda-exporter-settings
2997 opts pars)
2998 (org-agenda nil thiscmdkey))
2999 (set-buffer bufname)
3000 (while files
3001 (org-eval-in-environment (append org-agenda-exporter-settings
3002 opts pars)
3003 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3004 (and (get-buffer bufname)
3005 (kill-buffer bufname)))))))
3006 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3008 (defvar org-agenda-current-span nil
3009 "The current span used in the agenda view.") ; local variable in the agenda buffer
3010 (defun org-agenda-mark-header-line (pos)
3011 "Mark the line at POS as an agenda structure header."
3012 (save-excursion
3013 (goto-char pos)
3014 (put-text-property (point-at-bol) (point-at-eol)
3015 'org-agenda-structural-header t)
3016 (when org-agenda-title-append
3017 (put-text-property (point-at-bol) (point-at-eol)
3018 'org-agenda-title-append org-agenda-title-append))))
3020 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3021 (defvar org-agenda-write-buffer-name "Agenda View")
3022 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3023 "Write the current buffer (an agenda view) as a file.
3024 Depending on the extension of the file name, plain text (.txt),
3025 HTML (.html or .htm) or Postscript (.ps) is produced.
3026 If the extension is .ics, run icalendar export over all files used
3027 to construct the agenda and limit the export to entries listed in the
3028 agenda now.
3029 With prefix argument OPEN, open the new file immediately.
3030 If NOSETTINGS is given, do not scope the settings of
3031 `org-agenda-exporter-settings' into the export commands. This is used when
3032 the settings have already been scoped and we do not wish to overrule other,
3033 higher priority settings.
3034 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3035 (interactive "FWrite agenda to file: \nP")
3036 (if (not (file-writable-p file))
3037 (error "Cannot write agenda to file %s" file))
3038 (org-let (if nosettings nil org-agenda-exporter-settings)
3039 '(save-excursion
3040 (save-window-excursion
3041 (org-agenda-mark-filtered-text)
3042 (let ((bs (copy-sequence (buffer-string))) beg)
3043 (org-agenda-unmark-filtered-text)
3044 (with-temp-buffer
3045 (rename-buffer org-agenda-write-buffer-name t)
3046 (set-buffer-modified-p nil)
3047 (insert bs)
3048 (org-agenda-remove-marked-text 'org-filtered)
3049 (while (setq beg (text-property-any (point-min) (point-max)
3050 'org-filtered t))
3051 (delete-region
3052 beg (or (next-single-property-change beg 'org-filtered)
3053 (point-max))))
3054 (run-hooks 'org-agenda-before-write-hook)
3055 (cond
3056 ((org-bound-and-true-p org-mobile-creating-agendas)
3057 (org-mobile-write-agenda-for-mobile file))
3058 ((string-match "\\.html?\\'" file)
3059 (require 'htmlize)
3060 (set-buffer (htmlize-buffer (current-buffer)))
3061 (when (and org-agenda-export-html-style
3062 (string-match "<style>" org-agenda-export-html-style))
3063 ;; replace <style> section with org-agenda-export-html-style
3064 (goto-char (point-min))
3065 (kill-region (- (search-forward "<style") 6)
3066 (search-forward "</style>"))
3067 (insert org-agenda-export-html-style))
3068 (write-file file)
3069 (kill-buffer (current-buffer))
3070 (message "HTML written to %s" file))
3071 ((string-match "\\.ps\\'" file)
3072 (require 'ps-print)
3073 (ps-print-buffer-with-faces file)
3074 (message "Postscript written to %s" file))
3075 ((string-match "\\.pdf\\'" file)
3076 (require 'ps-print)
3077 (ps-print-buffer-with-faces
3078 (concat (file-name-sans-extension file) ".ps"))
3079 (call-process "ps2pdf" nil nil nil
3080 (expand-file-name
3081 (concat (file-name-sans-extension file) ".ps"))
3082 (expand-file-name file))
3083 (delete-file (concat (file-name-sans-extension file) ".ps"))
3084 (message "PDF written to %s" file))
3085 ((string-match "\\.ics\\'" file)
3086 (require 'org-icalendar)
3087 (let ((org-agenda-marker-table
3088 (org-create-marker-find-array
3089 (org-agenda-collect-markers)))
3090 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3091 (org-combined-agenda-icalendar-file file))
3092 (apply 'org-export-icalendar 'combine
3093 (org-agenda-files nil 'ifmode))))
3095 (let ((bs (buffer-string)))
3096 (find-file file)
3097 (erase-buffer)
3098 (insert bs)
3099 (save-buffer 0)
3100 (kill-buffer (current-buffer))
3101 (message "Plain text written to %s" file))))))))
3102 (set-buffer (or agenda-bufname
3103 (and (called-interactively-p 'any) (buffer-name))
3104 org-agenda-buffer-name)))
3105 (when open (org-open-file file)))
3107 (defvar org-agenda-tag-filter-overlays nil)
3108 (defvar org-agenda-cat-filter-overlays nil)
3110 (defun org-agenda-mark-filtered-text ()
3111 "Mark all text hidden by filtering with a text property."
3112 (let ((inhibit-read-only t))
3113 (mapc
3114 (lambda (o)
3115 (when (equal (overlay-buffer o) (current-buffer))
3116 (put-text-property
3117 (overlay-start o) (overlay-end o)
3118 'org-filtered t)))
3119 (append org-agenda-tag-filter-overlays
3120 org-agenda-cat-filter-overlays))))
3122 (defun org-agenda-unmark-filtered-text ()
3123 "Remove the filtering text property."
3124 (let ((inhibit-read-only t))
3125 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3127 (defun org-agenda-remove-marked-text (property &optional value)
3128 "Delete all text marked with VALUE of PROPERTY.
3129 VALUE defaults to t."
3130 (let (beg)
3131 (setq value (or value t))
3132 (while (setq beg (text-property-any (point-min) (point-max)
3133 property value))
3134 (delete-region
3135 beg (or (next-single-property-change beg 'org-filtered)
3136 (point-max))))))
3138 (defun org-agenda-add-entry-text ()
3139 "Add entry text to agenda lines.
3140 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3141 entry text following headings shown in the agenda.
3142 Drawers will be excluded, also the line with scheduling/deadline info."
3143 (when (and (> org-agenda-add-entry-text-maxlines 0)
3144 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3145 (let (m txt)
3146 (goto-char (point-min))
3147 (while (not (eobp))
3148 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3149 (beginning-of-line 2)
3150 (setq txt (org-agenda-get-some-entry-text
3151 m org-agenda-add-entry-text-maxlines " > "))
3152 (end-of-line 1)
3153 (if (string-match "\\S-" txt)
3154 (insert "\n" txt)
3155 (or (eobp) (forward-char 1))))))))
3157 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3158 &rest keep)
3159 "Extract entry text from MARKER, at most N-LINES lines.
3160 This will ignore drawers etc, just get the text.
3161 If INDENT is given, prefix every line with this string. If KEEP is
3162 given, it is a list of symbols, defining stuff that should not be
3163 removed from the entry content. Currently only `planning' is allowed here."
3164 (let (txt drawer-re kwd-time-re ind)
3165 (save-excursion
3166 (with-current-buffer (marker-buffer marker)
3167 (if (not (derived-mode-p 'org-mode))
3168 (setq txt "")
3169 (save-excursion
3170 (save-restriction
3171 (widen)
3172 (goto-char marker)
3173 (end-of-line 1)
3174 (setq txt (buffer-substring
3175 (min (1+ (point)) (point-max))
3176 (progn (outline-next-heading) (point)))
3177 drawer-re org-drawer-regexp
3178 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3179 ".*\n?"))
3180 (with-temp-buffer
3181 (insert txt)
3182 (when org-agenda-add-entry-text-descriptive-links
3183 (goto-char (point-min))
3184 (while (org-activate-bracket-links (point-max))
3185 (add-text-properties (match-beginning 0) (match-end 0)
3186 '(face org-link))))
3187 (goto-char (point-min))
3188 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3189 (set-text-properties (match-beginning 0) (match-end 0)
3190 nil))
3191 (goto-char (point-min))
3192 (while (re-search-forward drawer-re nil t)
3193 (delete-region
3194 (match-beginning 0)
3195 (progn (re-search-forward
3196 "^[ \t]*:END:.*\n?" nil 'move)
3197 (point))))
3198 (unless (member 'planning keep)
3199 (goto-char (point-min))
3200 (while (re-search-forward kwd-time-re nil t)
3201 (replace-match "")))
3202 (goto-char (point-min))
3203 (when org-agenda-entry-text-exclude-regexps
3204 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3205 (while (setq re (pop re-list))
3206 (goto-char (point-min))
3207 (while (re-search-forward re nil t)
3208 (replace-match "")))))
3209 (goto-char (point-max))
3210 (skip-chars-backward " \t\n")
3211 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3213 ;; find and remove min common indentation
3214 (goto-char (point-min))
3215 (untabify (point-min) (point-max))
3216 (setq ind (org-get-indentation))
3217 (while (not (eobp))
3218 (unless (looking-at "[ \t]*$")
3219 (setq ind (min ind (org-get-indentation))))
3220 (beginning-of-line 2))
3221 (goto-char (point-min))
3222 (while (not (eobp))
3223 (unless (looking-at "[ \t]*$")
3224 (move-to-column ind)
3225 (delete-region (point-at-bol) (point)))
3226 (beginning-of-line 2))
3228 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3230 (goto-char (point-min))
3231 (when indent
3232 (while (and (not (eobp)) (re-search-forward "^" nil t))
3233 (replace-match indent t t)))
3234 (goto-char (point-min))
3235 (while (looking-at "[ \t]*\n") (replace-match ""))
3236 (goto-char (point-max))
3237 (when (> (org-current-line)
3238 n-lines)
3239 (org-goto-line (1+ n-lines))
3240 (backward-char 1))
3241 (setq txt (buffer-substring (point-min) (point)))))))))
3242 txt))
3244 (defun org-agenda-collect-markers ()
3245 "Collect the markers pointing to entries in the agenda buffer."
3246 (let (m markers)
3247 (save-excursion
3248 (goto-char (point-min))
3249 (while (not (eobp))
3250 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3251 (org-get-at-bol 'org-marker)))
3252 (push m markers))
3253 (beginning-of-line 2)))
3254 (nreverse markers)))
3256 (defun org-create-marker-find-array (marker-list)
3257 "Create a alist of files names with all marker positions in that file."
3258 (let (f tbl m a p)
3259 (while (setq m (pop marker-list))
3260 (setq p (marker-position m)
3261 f (buffer-file-name (or (buffer-base-buffer
3262 (marker-buffer m))
3263 (marker-buffer m))))
3264 (if (setq a (assoc f tbl))
3265 (push (marker-position m) (cdr a))
3266 (push (list f p) tbl)))
3267 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3268 tbl)))
3270 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3271 (defun org-check-agenda-marker-table ()
3272 "Check of the current entry is on the marker list."
3273 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3275 (and (setq a (assoc file org-agenda-marker-table))
3276 (save-match-data
3277 (save-excursion
3278 (org-back-to-heading t)
3279 (member (point) (cdr a)))))))
3281 (defun org-check-for-org-mode ()
3282 "Make sure current buffer is in org-mode. Error if not."
3283 (or (derived-mode-p 'org-mode)
3284 (error "Cannot execute org-mode agenda command on buffer in %s"
3285 major-mode)))
3287 ;;; Agenda prepare and finalize
3289 (defvar org-agenda-multi nil) ; dynamically scoped
3290 (defvar org-agenda-pre-window-conf nil)
3291 (defvar org-agenda-columns-active nil)
3292 (defvar org-agenda-name nil)
3293 (defvar org-agenda-tag-filter nil)
3294 (defvar org-agenda-category-filter nil)
3295 (defvar org-agenda-top-category-filter nil)
3296 (defvar org-agenda-tag-filter-while-redo nil)
3297 (defvar org-agenda-tag-filter-preset nil
3298 "A preset of the tags filter used for secondary agenda filtering.
3299 This must be a list of strings, each string must be a single tag preceded
3300 by \"+\" or \"-\".
3301 This variable should not be set directly, but agenda custom commands can
3302 bind it in the options section. The preset filter is a global property of
3303 the entire agenda view. In a block agenda, it will not work reliably to
3304 define a filter for one of the individual blocks. You need to set it in
3305 the global options and expect it to be applied to the entire view.")
3307 (defvar org-agenda-category-filter-preset nil
3308 "A preset of the category filter used for secondary agenda filtering.
3309 This must be a list of strings, each string must be a single category
3310 preceded by \"+\" or \"-\".
3311 This variable should not be set directly, but agenda custom commands can
3312 bind it in the options section. The preset filter is a global property of
3313 the entire agenda view. In a block agenda, it will not work reliably to
3314 define a filter for one of the individual blocks. You need to set it in
3315 the global options and expect it to be applied to the entire view.")
3318 (defun org-agenda-use-sticky-p ()
3319 "Return non-nil if an agenda buffer named
3320 `org-agenda-buffer-name' exists and should be shown instead of
3321 generating a new one."
3322 (and
3323 ;; turned off by user
3324 org-agenda-sticky
3325 ;; For multi-agenda buffer already exists
3326 (not org-agenda-multi)
3327 ;; buffer found
3328 (get-buffer org-agenda-buffer-name)
3329 ;; C-u parameter is same as last call
3330 (with-current-buffer (get-buffer org-agenda-buffer-name)
3331 (and
3332 (equal current-prefix-arg
3333 org-agenda-last-prefix-arg)
3334 ;; In case user turned stickiness on, while having existing
3335 ;; Agenda buffer active, don't reuse that buffer, because it
3336 ;; does not have org variables local
3337 org-agenda-this-buffer-is-sticky))))
3339 (defun org-agenda-prepare-window (abuf)
3340 "Setup agenda buffer in the window."
3341 (let* ((awin (get-buffer-window abuf))
3342 wconf)
3343 (cond
3344 ((equal (current-buffer) abuf) nil)
3345 (awin (select-window awin))
3346 ((not (setq wconf (current-window-configuration))))
3347 ((equal org-agenda-window-setup 'current-window)
3348 (org-pop-to-buffer-same-window abuf))
3349 ((equal org-agenda-window-setup 'other-window)
3350 (org-switch-to-buffer-other-window abuf))
3351 ((equal org-agenda-window-setup 'other-frame)
3352 (switch-to-buffer-other-frame abuf))
3353 ((equal org-agenda-window-setup 'reorganize-frame)
3354 (delete-other-windows)
3355 (org-switch-to-buffer-other-window abuf)))
3356 ;; additional test in case agenda is invoked from within agenda
3357 ;; buffer via elisp link
3358 (unless (equal (current-buffer) abuf)
3359 (org-pop-to-buffer-same-window abuf))
3360 (setq org-agenda-pre-window-conf
3361 (or org-agenda-pre-window-conf wconf))))
3363 (defun org-agenda-prepare (&optional name)
3364 (if (org-agenda-use-sticky-p)
3365 (progn
3366 ;; Popup existing buffer
3367 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3368 (message "Sticky Agenda buffer, use `r' to refresh")
3369 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3370 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3371 (setq org-todo-keywords-for-agenda nil)
3372 (setq org-drawers-for-agenda nil)
3373 (unless org-agenda-persistent-filter
3374 (setq org-agenda-tag-filter nil
3375 org-agenda-category-filter nil))
3376 (put 'org-agenda-tag-filter :preset-filter
3377 org-agenda-tag-filter-preset)
3378 (put 'org-agenda-category-filter :preset-filter
3379 org-agenda-category-filter-preset)
3380 (if org-agenda-multi
3381 (progn
3382 (setq buffer-read-only nil)
3383 (goto-char (point-max))
3384 (unless (or (bobp) org-agenda-compact-blocks
3385 (not org-agenda-block-separator))
3386 (insert "\n"
3387 (if (stringp org-agenda-block-separator)
3388 org-agenda-block-separator
3389 (make-string (window-width) org-agenda-block-separator))
3390 "\n"))
3391 (narrow-to-region (point) (point-max)))
3392 (setq org-done-keywords-for-agenda nil)
3394 ;; Setting any org variables that are in org-agenda-local-vars
3395 ;; list need to be done after the prepare call
3396 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3397 (setq buffer-read-only nil)
3398 (org-agenda-reset-markers)
3399 (let ((inhibit-read-only t)) (erase-buffer))
3400 (org-agenda-mode)
3401 (setq org-agenda-buffer (current-buffer))
3402 (setq org-agenda-contributing-files nil)
3403 (setq org-agenda-columns-active nil)
3404 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3405 (setq org-todo-keywords-for-agenda
3406 (org-uniquify org-todo-keywords-for-agenda))
3407 (setq org-done-keywords-for-agenda
3408 (org-uniquify org-done-keywords-for-agenda))
3409 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3410 (setq org-agenda-last-prefix-arg current-prefix-arg)
3411 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3412 (and name (not org-agenda-name)
3413 (org-set-local 'org-agenda-name name)))
3414 (setq buffer-read-only nil)))
3416 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3417 (defun org-agenda-finalize ()
3418 "Finishing touch for the agenda buffer, called just before displaying it."
3419 (unless org-agenda-multi
3420 (save-excursion
3421 (let ((inhibit-read-only t))
3422 (goto-char (point-min))
3423 (while (org-activate-bracket-links (point-max))
3424 (add-text-properties (match-beginning 0) (match-end 0)
3425 '(face org-link)))
3426 (org-agenda-align-tags)
3427 (unless org-agenda-with-colors
3428 (remove-text-properties (point-min) (point-max) '(face nil))))
3429 (if (and (boundp 'org-agenda-overriding-columns-format)
3430 org-agenda-overriding-columns-format)
3431 (org-set-local 'org-agenda-overriding-columns-format
3432 org-agenda-overriding-columns-format))
3433 (if (and (boundp 'org-agenda-view-columns-initially)
3434 org-agenda-view-columns-initially)
3435 (org-agenda-columns))
3436 (when org-agenda-fontify-priorities
3437 (org-agenda-fontify-priorities))
3438 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3439 (org-agenda-dim-blocked-tasks))
3440 (org-agenda-mark-clocking-task)
3441 (when org-agenda-entry-text-mode
3442 (org-agenda-entry-text-hide)
3443 (org-agenda-entry-text-show))
3444 (if (functionp 'org-habit-insert-consistency-graphs)
3445 (org-habit-insert-consistency-graphs))
3446 (let ((inhibit-read-only t))
3447 (run-hooks 'org-agenda-finalize-hook))
3448 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3449 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3450 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3451 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3452 (org-agenda-filter-apply org-agenda-category-filter 'category))
3453 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3455 (defun org-agenda-mark-clocking-task ()
3456 "Mark the current clock entry in the agenda if it is present."
3457 (mapc (lambda (o)
3458 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3459 (delete-overlay o)))
3460 (overlays-in (point-min) (point-max)))
3461 (when (marker-buffer org-clock-hd-marker)
3462 (save-excursion
3463 (goto-char (point-min))
3464 (let (s ov)
3465 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3466 (goto-char s)
3467 (when (equal (org-get-at-bol 'org-hd-marker)
3468 org-clock-hd-marker)
3469 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3470 (overlay-put ov 'type 'org-agenda-clocking)
3471 (overlay-put ov 'face 'org-agenda-clocking)
3472 (overlay-put ov 'help-echo
3473 "The clock is running in this item")))))))
3475 (defun org-agenda-fontify-priorities ()
3476 "Make highest priority lines bold, and lowest italic."
3477 (interactive)
3478 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3479 (delete-overlay o)))
3480 (overlays-in (point-min) (point-max)))
3481 (save-excursion
3482 (let ((inhibit-read-only t)
3483 b e p ov h l)
3484 (goto-char (point-min))
3485 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3486 (setq h (or (get-char-property (point) 'org-highest-priority)
3487 org-highest-priority)
3488 l (or (get-char-property (point) 'org-lowest-priority)
3489 org-lowest-priority)
3490 p (string-to-char (match-string 1))
3491 b (match-beginning 0)
3492 e (if (eq org-agenda-fontify-priorities 'cookies)
3493 (match-end 0)
3494 (point-at-eol))
3495 ov (make-overlay b e))
3496 (overlay-put
3497 ov 'face
3498 (cond ((org-face-from-face-or-color
3499 'priority nil
3500 (cdr (assoc p org-priority-faces))))
3501 ((and (listp org-agenda-fontify-priorities)
3502 (org-face-from-face-or-color
3503 'priority nil
3504 (cdr (assoc p org-agenda-fontify-priorities)))))
3505 ((equal p l) 'italic)
3506 ((equal p h) 'bold)))
3507 (overlay-put ov 'org-type 'org-priority)))))
3509 (defun org-agenda-dim-blocked-tasks ()
3510 "Dim currently blocked TODO's in the agenda display."
3511 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3512 (delete-overlay o)))
3513 (overlays-in (point-min) (point-max)))
3514 (save-excursion
3515 (let ((inhibit-read-only t)
3516 (org-depend-tag-blocked nil)
3517 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3518 org-blocked-by-checkboxes
3519 invis1 b e p ov h l)
3520 (goto-char (point-min))
3521 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3522 (and pos (goto-char (1+ pos))))
3523 (setq org-blocked-by-checkboxes nil invis1 invis)
3524 (let ((marker (org-get-at-bol 'org-hd-marker)))
3525 (when (and marker
3526 (with-current-buffer (marker-buffer marker)
3527 (save-excursion (goto-char marker)
3528 (org-entry-blocked-p))))
3529 (if org-blocked-by-checkboxes (setq invis1 nil))
3530 (setq b (if invis1
3531 (max (point-min) (1- (point-at-bol)))
3532 (point-at-bol))
3533 e (point-at-eol)
3534 ov (make-overlay b e))
3535 (if invis1
3536 (overlay-put ov 'invisible t)
3537 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3538 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3540 (defvar org-agenda-skip-function nil
3541 "Function to be called at each match during agenda construction.
3542 If this function returns nil, the current match should not be skipped.
3543 Otherwise, the function must return a position from where the search
3544 should be continued.
3545 This may also be a Lisp form, it will be evaluated.
3546 Never set this variable using `setq' or so, because then it will apply
3547 to all future agenda commands. If you do want a global skipping condition,
3548 use the option `org-agenda-skip-function-global' instead.
3549 The correct usage for `org-agenda-skip-function' is to bind it with
3550 `let' to scope it dynamically into the agenda-constructing command.
3551 A good way to set it is through options in `org-agenda-custom-commands'.")
3553 (defun org-agenda-skip ()
3554 "Throw to `:skip' in places that should be skipped.
3555 Also moves point to the end of the skipped region, so that search can
3556 continue from there."
3557 (let ((p (point-at-bol)) to)
3558 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3559 (get-text-property p :org-archived)
3560 (org-end-of-subtree t)
3561 (throw :skip t))
3562 (and org-agenda-skip-comment-trees
3563 (get-text-property p :org-comment)
3564 (org-end-of-subtree t)
3565 (throw :skip t))
3566 (if (equal (char-after p) ?#) (throw :skip t))
3567 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3568 (org-agenda-skip-eval org-agenda-skip-function)))
3569 (goto-char to)
3570 (throw :skip t))))
3572 (defun org-agenda-skip-eval (form)
3573 "If FORM is a function or a list, call (or eval) is and return result.
3574 `save-excursion' and `save-match-data' are wrapped around the call, so point
3575 and match data are returned to the previous state no matter what these
3576 functions do."
3577 (let (fp)
3578 (and form
3579 (or (setq fp (functionp form))
3580 (consp form))
3581 (save-excursion
3582 (save-match-data
3583 (if fp
3584 (funcall form)
3585 (eval form)))))))
3587 (defvar org-agenda-markers nil
3588 "List of all currently active markers created by `org-agenda'.")
3589 (defvar org-agenda-last-marker-time (org-float-time)
3590 "Creation time of the last agenda marker.")
3592 (defun org-agenda-new-marker (&optional pos)
3593 "Return a new agenda marker.
3594 Org-mode keeps a list of these markers and resets them when they are
3595 no longer in use."
3596 (let ((m (copy-marker (or pos (point)))))
3597 (setq org-agenda-last-marker-time (org-float-time))
3598 (if org-agenda-buffer
3599 (with-current-buffer org-agenda-buffer
3600 (push m org-agenda-markers))
3601 (push m org-agenda-markers))
3604 (defun org-agenda-reset-markers ()
3605 "Reset markers created by `org-agenda'."
3606 (while org-agenda-markers
3607 (move-marker (pop org-agenda-markers) nil)))
3609 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3610 "Save relative positions of markers in region.
3611 This check for agenda markers in all agenda buffers currently active."
3612 (dolist (buf (buffer-list))
3613 (with-current-buffer buf
3614 (when (eq major-mode 'org-agenda-mode)
3615 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3616 org-agenda-markers)))))
3618 ;;; Entry text mode
3620 (defun org-agenda-entry-text-show-here ()
3621 "Add some text from the entry as context to the current line."
3622 (let (m txt o)
3623 (setq m (org-get-at-bol 'org-hd-marker))
3624 (unless (marker-buffer m)
3625 (error "No marker points to an entry here"))
3626 (setq txt (concat "\n" (org-no-properties
3627 (org-agenda-get-some-entry-text
3628 m org-agenda-entry-text-maxlines " > "))))
3629 (when (string-match "\\S-" txt)
3630 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3631 (overlay-put o 'evaporate t)
3632 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3633 (overlay-put o 'after-string txt))))
3635 (defun org-agenda-entry-text-show ()
3636 "Add entry context for all agenda lines."
3637 (interactive)
3638 (save-excursion
3639 (goto-char (point-max))
3640 (beginning-of-line 1)
3641 (while (not (bobp))
3642 (when (org-get-at-bol 'org-hd-marker)
3643 (org-agenda-entry-text-show-here))
3644 (beginning-of-line 0))))
3646 (defun org-agenda-entry-text-hide ()
3647 "Remove any shown entry context."
3648 (delq nil
3649 (mapcar (lambda (o)
3650 (if (eq (overlay-get o 'org-overlay-type)
3651 'agenda-entry-content)
3652 (progn (delete-overlay o) t)))
3653 (overlays-in (point-min) (point-max)))))
3655 (defun org-agenda-get-day-face (date)
3656 "Return the face DATE should be displayed with."
3657 (or (and (functionp org-agenda-day-face-function)
3658 (funcall org-agenda-day-face-function date))
3659 (cond ((org-agenda-todayp date)
3660 'org-agenda-date-today)
3661 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3662 'org-agenda-date-weekend)
3663 (t 'org-agenda-date))))
3665 ;;; Agenda timeline
3667 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3669 (defun org-timeline (&optional dotodo)
3670 "Show a time-sorted view of the entries in the current org file.
3671 Only entries with a time stamp of today or later will be listed. With
3672 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3673 under the current date.
3674 If the buffer contains an active region, only check the region for
3675 dates."
3676 (interactive "P")
3677 (let* ((dopast t)
3678 (org-agenda-show-log-scoped org-agenda-show-log)
3679 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3680 (current-buffer))))
3681 (date (calendar-current-date))
3682 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3683 (end (if (org-region-active-p) (region-end) (point-max)))
3684 (day-numbers (org-get-all-dates
3685 beg end 'no-ranges
3686 t org-agenda-show-log-scoped ; always include today
3687 org-timeline-show-empty-dates))
3688 (org-deadline-warning-days 0)
3689 (org-agenda-only-exact-dates t)
3690 (today (org-today))
3691 (past t)
3692 args
3693 s e rtn d emptyp)
3694 (setq org-agenda-redo-command
3695 (list 'progn
3696 (list 'org-switch-to-buffer-other-window (current-buffer))
3697 (list 'org-timeline (list 'quote dotodo))))
3698 (if (not dopast)
3699 ;; Remove past dates from the list of dates.
3700 (setq day-numbers (delq nil (mapcar (lambda(x)
3701 (if (>= x today) x nil))
3702 day-numbers))))
3703 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3704 (org-compile-prefix-format 'timeline)
3705 (org-set-sorting-strategy 'timeline)
3706 (if org-agenda-show-log-scoped (push :closed args))
3707 (push :timestamp args)
3708 (push :deadline args)
3709 (push :scheduled args)
3710 (push :sexp args)
3711 (if dotodo (push :todo args))
3712 (insert "Timeline of file " entry "\n")
3713 (add-text-properties (point-min) (point)
3714 (list 'face 'org-agenda-structure))
3715 (org-agenda-mark-header-line (point-min))
3716 (while (setq d (pop day-numbers))
3717 (if (and (listp d) (eq (car d) :omitted))
3718 (progn
3719 (setq s (point))
3720 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3721 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3722 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3723 (if (and (>= d today)
3724 dopast
3725 past)
3726 (progn
3727 (setq past nil)
3728 (insert (make-string 79 ?-) "\n")))
3729 (setq date (calendar-gregorian-from-absolute d))
3730 (setq s (point))
3731 (setq rtn (and (not emptyp)
3732 (apply 'org-agenda-get-day-entries entry
3733 date args)))
3734 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3735 (progn
3736 (insert
3737 (if (stringp org-agenda-format-date)
3738 (format-time-string org-agenda-format-date
3739 (org-time-from-absolute date))
3740 (funcall org-agenda-format-date date))
3741 "\n")
3742 (put-text-property s (1- (point)) 'face
3743 (org-agenda-get-day-face date))
3744 (put-text-property s (1- (point)) 'org-date-line t)
3745 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3746 (if (equal d today)
3747 (put-text-property s (1- (point)) 'org-today t))
3748 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3749 (put-text-property s (1- (point)) 'day d)))))
3750 (goto-char (point-min))
3751 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3752 (point-min)))
3753 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3754 (org-agenda-finalize)
3755 (setq buffer-read-only t)))
3757 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3758 "Return a list of all relevant day numbers from BEG to END buffer positions.
3759 If NO-RANGES is non-nil, include only the start and end dates of a range,
3760 not every single day in the range. If FORCE-TODAY is non-nil, make
3761 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3762 inactive time stamps (those in square brackets) are included.
3763 When EMPTY is non-nil, also include days without any entries."
3764 (let ((re (concat
3765 (if pre-re pre-re "")
3766 (if inactive org-ts-regexp-both org-ts-regexp)))
3767 dates dates1 date day day1 day2 ts1 ts2 pos)
3768 (if force-today
3769 (setq dates (list (org-today))))
3770 (save-excursion
3771 (goto-char beg)
3772 (while (re-search-forward re end t)
3773 (setq day (time-to-days (org-time-string-to-time
3774 (substring (match-string 1) 0 10)
3775 (current-buffer) (match-beginning 0))))
3776 (or (memq day dates) (push day dates)))
3777 (unless no-ranges
3778 (goto-char beg)
3779 (while (re-search-forward org-tr-regexp end t)
3780 (setq pos (match-beginning 0))
3781 (setq ts1 (substring (match-string 1) 0 10)
3782 ts2 (substring (match-string 2) 0 10)
3783 day1 (time-to-days (org-time-string-to-time
3784 ts1 (current-buffer) pos))
3785 day2 (time-to-days (org-time-string-to-time
3786 ts2 (current-buffer) pos)))
3787 (while (< (setq day1 (1+ day1)) day2)
3788 (or (memq day1 dates) (push day1 dates)))))
3789 (setq dates (sort dates '<))
3790 (when empty
3791 (while (setq day (pop dates))
3792 (setq day2 (car dates))
3793 (push day dates1)
3794 (when (and day2 empty)
3795 (if (or (eq empty t)
3796 (and (numberp empty) (<= (- day2 day) empty)))
3797 (while (< (setq day (1+ day)) day2)
3798 (push (list day) dates1))
3799 (push (cons :omitted (- day2 day)) dates1))))
3800 (setq dates (nreverse dates1)))
3801 dates)))
3803 ;;; Agenda Daily/Weekly
3805 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3806 "Start day for the agenda view.
3807 Custom commands can set this variable in the options section.")
3808 (defvar org-starting-day nil) ; local variable in the agenda buffer
3809 (defvar org-arg-loc nil) ; local variable
3811 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3812 "List of types searched for when creating the daily/weekly agenda.
3813 This variable is a list of symbols that controls the types of
3814 items that appear in the daily/weekly agenda. Allowed symbols in this
3815 list are are
3817 :timestamp List items containing a date stamp or date range matching
3818 the selected date. This includes sexp entries in
3819 angular brackets.
3821 :sexp List entries resulting from plain diary-like sexps.
3823 :deadline List deadline due on that date. When the date is today,
3824 also list any deadlines past due, or due within
3825 `org-deadline-warning-days'. `:deadline' must appear before
3826 `:scheduled' if the setting of
3827 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3828 any effect.
3830 :scheduled List all items which are scheduled for the given date.
3831 The diary for *today* also contains items which were
3832 scheduled earlier and are not yet marked DONE.
3834 By default, all four types are turned on.
3836 Never set this variable globally using `setq', because then it
3837 will apply to all future agenda commands. Instead, bind it with
3838 `let' to scope it dynamically into the agenda-constructing
3839 command. A good way to set it is through options in
3840 `org-agenda-custom-commands'. For a more flexible (though
3841 somewhat less efficient) way of determining what is included in
3842 the daily/weekly agenda, see `org-agenda-skip-function'.")
3844 (defvar org-agenda-buffer-tmp-name nil)
3845 ;;;###autoload
3846 (defun org-agenda-list (&optional arg start-day span)
3847 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3848 The view will be for the current day or week, but from the overview buffer
3849 you will be able to go to other days/weeks.
3851 With a numeric prefix argument in an interactive call, the agenda will
3852 span ARG days. Lisp programs should instead specify SPAN to change
3853 the number of days. SPAN defaults to `org-agenda-span'.
3855 START-DAY defaults to TODAY, or to the most recent match for the weekday
3856 given in `org-agenda-start-on-weekday'."
3857 (interactive "P")
3858 (if org-agenda-overriding-arguments
3859 (setq arg (car org-agenda-overriding-arguments)
3860 start-day (nth 1 org-agenda-overriding-arguments)
3861 span (nth 2 org-agenda-overriding-arguments)))
3862 (if (and (integerp arg) (> arg 0))
3863 (setq span arg arg nil))
3864 (catch 'exit
3865 (setq org-agenda-buffer-name
3866 (or org-agenda-buffer-tmp-name
3867 (if org-agenda-sticky
3868 (cond ((and org-keys (stringp org-match))
3869 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3870 (org-keys
3871 (format "*Org Agenda(%s)*" org-keys))
3872 (t "*Org Agenda(a)*")))
3873 org-agenda-buffer-name))
3874 (org-agenda-prepare "Day/Week")
3875 (setq start-day (or start-day org-agenda-start-day))
3876 (if (stringp start-day)
3877 ;; Convert to an absolute day number
3878 (setq start-day (time-to-days (org-read-date nil t start-day))))
3879 (org-compile-prefix-format 'agenda)
3880 (org-set-sorting-strategy 'agenda)
3881 (let* ((span (org-agenda-ndays-to-span
3882 (or span org-agenda-ndays org-agenda-span)))
3883 (today (org-today))
3884 (sd (or start-day today))
3885 (ndays (org-agenda-span-to-ndays span sd))
3886 (org-agenda-start-on-weekday
3887 (if (eq ndays 7)
3888 org-agenda-start-on-weekday))
3889 (thefiles (org-agenda-files nil 'ifmode))
3890 (files thefiles)
3891 (start (if (or (null org-agenda-start-on-weekday)
3892 (< ndays 7))
3894 (let* ((nt (calendar-day-of-week
3895 (calendar-gregorian-from-absolute sd)))
3896 (n1 org-agenda-start-on-weekday)
3897 (d (- nt n1)))
3898 (- sd (+ (if (< d 0) 7 0) d)))))
3899 (day-numbers (list start))
3900 (day-cnt 0)
3901 (inhibit-redisplay (not debug-on-error))
3902 (org-agenda-show-log-scoped org-agenda-show-log)
3903 s e rtn rtnall file date d start-pos end-pos todayp
3904 clocktable-start clocktable-end filter)
3905 (setq org-agenda-redo-command
3906 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3907 (dotimes (n (1- ndays))
3908 (push (1+ (car day-numbers)) day-numbers))
3909 (setq day-numbers (nreverse day-numbers))
3910 (setq clocktable-start (car day-numbers)
3911 clocktable-end (1+ (or (org-last day-numbers) 0)))
3912 (org-set-local 'org-starting-day (car day-numbers))
3913 (org-set-local 'org-arg-loc arg)
3914 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3915 (unless org-agenda-compact-blocks
3916 (let* ((d1 (car day-numbers))
3917 (d2 (org-last day-numbers))
3918 (w1 (org-days-to-iso-week d1))
3919 (w2 (org-days-to-iso-week d2)))
3920 (setq s (point))
3921 (if org-agenda-overriding-header
3922 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3923 nil 'face 'org-agenda-structure) "\n")
3924 (insert (org-agenda-span-name span)
3925 "-agenda"
3926 (if (< (- d2 d1) 350)
3927 (if (= w1 w2)
3928 (format " (W%02d)" w1)
3929 (format " (W%02d-W%02d)" w1 w2))
3931 ":\n")))
3932 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3933 'org-date-line t))
3934 (org-agenda-mark-header-line s))
3935 (while (setq d (pop day-numbers))
3936 (setq date (calendar-gregorian-from-absolute d)
3937 s (point))
3938 (if (or (setq todayp (= d today))
3939 (and (not start-pos) (= d sd)))
3940 (setq start-pos (point))
3941 (if (and start-pos (not end-pos))
3942 (setq end-pos (point))))
3943 (setq files thefiles
3944 rtnall nil)
3945 (while (setq file (pop files))
3946 (catch 'nextfile
3947 (org-check-agenda-file file)
3948 (let ((org-agenda-entry-types org-agenda-entry-types))
3949 (unless org-agenda-include-deadlines
3950 (setq org-agenda-entry-types
3951 (delq :deadline org-agenda-entry-types)))
3952 (cond
3953 ((memq org-agenda-show-log-scoped '(only clockcheck))
3954 (setq rtn (org-agenda-get-day-entries
3955 file date :closed)))
3956 (org-agenda-show-log-scoped
3957 (setq rtn (apply 'org-agenda-get-day-entries
3958 file date
3959 (append '(:closed) org-agenda-entry-types))))
3961 (setq rtn (apply 'org-agenda-get-day-entries
3962 file date
3963 org-agenda-entry-types)))))
3964 (setq rtnall (append rtnall rtn)))) ;; all entries
3965 (if org-agenda-include-diary
3966 (let ((org-agenda-search-headline-for-time t))
3967 (require 'diary-lib)
3968 (setq rtn (org-get-entries-from-diary date))
3969 (setq rtnall (append rtnall rtn))))
3970 (if (or rtnall org-agenda-show-all-dates)
3971 (progn
3972 (setq day-cnt (1+ day-cnt))
3973 (insert
3974 (if (stringp org-agenda-format-date)
3975 (format-time-string org-agenda-format-date
3976 (org-time-from-absolute date))
3977 (funcall org-agenda-format-date date))
3978 "\n")
3979 (put-text-property s (1- (point)) 'face
3980 (org-agenda-get-day-face date))
3981 (put-text-property s (1- (point)) 'org-date-line t)
3982 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3983 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3984 (when todayp
3985 (put-text-property s (1- (point)) 'org-today t))
3986 (setq rtnall
3987 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3988 (if rtnall (insert ;; all entries
3989 (org-agenda-finalize-entries rtnall)
3990 "\n"))
3991 (put-text-property s (1- (point)) 'day d)
3992 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3993 (when (and org-agenda-clockreport-mode clocktable-start)
3994 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3995 ;; the above line is to ensure the restricted range!
3996 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3997 tbl)
3998 (setq p (org-plist-delete p :block))
3999 (setq p (plist-put p :tstart clocktable-start))
4000 (setq p (plist-put p :tend clocktable-end))
4001 (setq p (plist-put p :scope 'agenda))
4002 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4003 (setq filter (or org-agenda-tag-filter-while-redo
4004 (get 'org-agenda-tag-filter :preset-filter))))
4005 (setq p (plist-put p :tags (mapconcat (lambda (x)
4006 (if (string-match "[<>=]" x)
4009 filter ""))))
4010 (setq tbl (apply 'org-get-clocktable p))
4011 (insert tbl)))
4012 (goto-char (point-min))
4013 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4014 (unless (and (pos-visible-in-window-p (point-min))
4015 (pos-visible-in-window-p (point-max)))
4016 (goto-char (1- (point-max)))
4017 (recenter -1)
4018 (if (not (pos-visible-in-window-p (or start-pos 1)))
4019 (progn
4020 (goto-char (or start-pos 1))
4021 (recenter 1))))
4022 (goto-char (or start-pos 1))
4023 (add-text-properties (point-min) (point-max)
4024 `(org-agenda-type agenda
4025 org-last-args (,arg ,start-day ,span)
4026 org-redo-cmd ,org-agenda-redo-command
4027 org-serie-cmd ,org-cmd))
4028 (if (eq org-agenda-show-log-scoped 'clockcheck)
4029 (org-agenda-show-clocking-issues))
4030 (org-agenda-finalize)
4031 (setq buffer-read-only t)
4032 (message ""))))
4034 (defun org-agenda-ndays-to-span (n)
4035 "Return a span symbol for a span of N days, or N if none matches."
4036 (cond ((symbolp n) n)
4037 ((= n 1) 'day)
4038 ((= n 7) 'week)
4039 (t n)))
4041 (defun org-agenda-span-to-ndays (span &optional start-day)
4042 "Return ndays from SPAN, possibly starting at START-DAY."
4043 (cond ((numberp span) span)
4044 ((eq span 'day) 1)
4045 ((eq span 'week) 7)
4046 ((eq span 'month)
4047 (let ((date (calendar-gregorian-from-absolute start-day)))
4048 (calendar-last-day-of-month (car date) (caddr date))))
4049 ((eq span 'year)
4050 (let ((date (calendar-gregorian-from-absolute start-day)))
4051 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4053 (defun org-agenda-span-name (span)
4054 "Return a SPAN name."
4055 (if (null span)
4057 (if (symbolp span)
4058 (capitalize (symbol-name span))
4059 (format "%d days" span))))
4061 ;;; Agenda word search
4063 (defvar org-agenda-search-history nil)
4065 (defvar org-search-syntax-table nil
4066 "Special syntax table for org-mode search.
4067 In this table, we have single quotes not as word constituents, to
4068 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4070 (defvar org-mode-syntax-table) ; From org.el
4071 (defun org-search-syntax-table ()
4072 (unless org-search-syntax-table
4073 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4074 (modify-syntax-entry ?' "." org-search-syntax-table)
4075 (modify-syntax-entry ?` "." org-search-syntax-table))
4076 org-search-syntax-table)
4078 (defvar org-agenda-last-search-view-search-was-boolean nil)
4080 ;;;###autoload
4081 (defun org-search-view (&optional todo-only string edit-at)
4082 "Show all entries that contain a phrase or words or regular expressions.
4084 With optional prefix argument TODO-ONLY, only consider entries that are
4085 TODO entries. The argument STRING can be used to pass a default search
4086 string into this function. If EDIT-AT is non-nil, it means that the
4087 user should get a chance to edit this string, with cursor at position
4088 EDIT-AT.
4090 The search string can be viewed either as a phrase that should be found as
4091 is, or it can be broken into a number of snippets, each of which must match
4092 in a Boolean way to select an entry. The default depends on the variable
4093 `org-agenda-search-view-always-boolean'.
4094 Even if this is turned off (the default) you can always switch to
4095 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4097 The default is a direct search of the whole phrase, where each space in
4098 the search string can expand to an arbitrary amount of whitespace,
4099 including newlines.
4101 If using a Boolean search, the search string is split on whitespace and
4102 each snippet is searched separately, with logical AND to select an entry.
4103 Words prefixed with a minus must *not* occur in the entry. Words without
4104 a prefix or prefixed with a plus must occur in the entry. Matching is
4105 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4106 match whole words, not parts of a word) if
4107 `org-agenda-search-view-force-full-words' is set (default is nil).
4109 Boolean search snippets enclosed by curly braces are interpreted as
4110 regular expressions that must or (when preceded with \"-\") must not
4111 match in the entry. Snippets enclosed into double quotes will be taken
4112 as a whole, to include whitespace.
4114 - If the search string starts with an asterisk, search only in headlines.
4115 - If (possibly after the leading star) the search string starts with an
4116 exclamation mark, this also means to look at TODO entries only, an effect
4117 that can also be achieved with a prefix argument.
4118 - If (possibly after star and exclamation mark) the search string starts
4119 with a colon, this will mean that the (non-regexp) snippets of the
4120 Boolean search must match as full words.
4122 This command searches the agenda files, and in addition the files listed
4123 in `org-agenda-text-search-extra-files'."
4124 (interactive "P")
4125 (if org-agenda-overriding-arguments
4126 (setq todo-only (car org-agenda-overriding-arguments)
4127 string (nth 1 org-agenda-overriding-arguments)
4128 edit-at (nth 2 org-agenda-overriding-arguments)))
4129 (let* ((props (list 'face nil
4130 'done-face 'org-agenda-done
4131 'org-not-done-regexp org-not-done-regexp
4132 'org-todo-regexp org-todo-regexp
4133 'org-complex-heading-regexp org-complex-heading-regexp
4134 'mouse-face 'highlight
4135 'help-echo (format "mouse-2 or RET jump to location")))
4136 (full-words org-agenda-search-view-force-full-words)
4137 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4138 regexp rtn rtnall files file pos
4139 marker category category-pos tags c neg re boolean
4140 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4141 (unless (and (not edit-at)
4142 (stringp string)
4143 (string-match "\\S-" string))
4144 (setq string (read-string
4145 (if org-agenda-search-view-always-boolean
4146 "[+-]Word/{Regexp} ...: "
4147 "Phrase or [+-]Word/{Regexp} ...: ")
4148 (cond
4149 ((integerp edit-at) (cons string edit-at))
4150 (edit-at string))
4151 'org-agenda-search-history)))
4152 (catch 'exit
4153 (if org-agenda-sticky
4154 (setq org-agenda-buffer-name
4155 (if (stringp string)
4156 (format "*Org Agenda(%s:%s)*"
4157 (or org-keys (or (and todo-only "S") "s")) string)
4158 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4159 (org-agenda-prepare "SEARCH")
4160 (org-compile-prefix-format 'search)
4161 (org-set-sorting-strategy 'search)
4162 (setq org-agenda-redo-command
4163 (list 'org-search-view (if todo-only t nil)
4164 (list 'if 'current-prefix-arg nil string)))
4165 (setq org-agenda-query-string string)
4166 (if (equal (string-to-char string) ?*)
4167 (setq hdl-only t
4168 words (substring string 1))
4169 (setq words string))
4170 (when (equal (string-to-char words) ?!)
4171 (setq todo-only t
4172 words (substring words 1)))
4173 (when (equal (string-to-char words) ?:)
4174 (setq full-words t
4175 words (substring words 1)))
4176 (if (or org-agenda-search-view-always-boolean
4177 (member (string-to-char words) '(?- ?+ ?\{)))
4178 (setq boolean t))
4179 (setq words (org-split-string words))
4180 (let (www w)
4181 (while (setq w (pop words))
4182 (while (and (string-match "\\\\\\'" w) words)
4183 (setq w (concat (substring w 0 -1) " " (pop words))))
4184 (push w www))
4185 (setq words (nreverse www) www nil)
4186 (while (setq w (pop words))
4187 (when (and (string-match "\\`[-+]?{" w)
4188 (not (string-match "}\\'" w)))
4189 (while (and words (not (string-match "}\\'" (car words))))
4190 (setq w (concat w " " (pop words))))
4191 (setq w (concat w " " (pop words))))
4192 (push w www))
4193 (setq words (nreverse www)))
4194 (setq org-agenda-last-search-view-search-was-boolean boolean)
4195 (when boolean
4196 (let (wds w)
4197 (while (setq w (pop words))
4198 (if (or (equal (substring w 0 1) "\"")
4199 (and (> (length w) 1)
4200 (member (substring w 0 1) '("+" "-"))
4201 (equal (substring w 1 2) "\"")))
4202 (while (and words (not (equal (substring w -1) "\"")))
4203 (setq w (concat w " " (pop words)))))
4204 (and (string-match "\\`\\([-+]?\\)\"" w)
4205 (setq w (replace-match "\\1" nil nil w)))
4206 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4207 (push w wds))
4208 (setq words (nreverse wds))))
4209 (if boolean
4210 (mapc (lambda (w)
4211 (setq c (string-to-char w))
4212 (if (equal c ?-)
4213 (setq neg t w (substring w 1))
4214 (if (equal c ?+)
4215 (setq neg nil w (substring w 1))
4216 (setq neg nil)))
4217 (if (string-match "\\`{.*}\\'" w)
4218 (setq re (substring w 1 -1))
4219 (if full-words
4220 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4221 (setq re (regexp-quote (downcase w)))))
4222 (if neg (push re regexps-) (push re regexps+)))
4223 words)
4224 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4225 regexps+))
4226 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4227 (if (not regexps+)
4228 (setq regexp org-outline-regexp-bol)
4229 (setq regexp (pop regexps+))
4230 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4231 regexp))))
4232 (setq files (org-agenda-files nil 'ifmode))
4233 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4234 (pop org-agenda-text-search-extra-files)
4235 (setq files (org-add-archive-files files)))
4236 (setq files (append files org-agenda-text-search-extra-files)
4237 rtnall nil)
4238 (while (setq file (pop files))
4239 (setq ee nil)
4240 (catch 'nextfile
4241 (org-check-agenda-file file)
4242 (setq buffer (if (file-exists-p file)
4243 (org-get-agenda-file-buffer file)
4244 (error "No such file %s" file)))
4245 (if (not buffer)
4246 ;; If file does not exist, make sure an error message is sent
4247 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4248 file))))
4249 (with-current-buffer buffer
4250 (with-syntax-table (org-search-syntax-table)
4251 (unless (derived-mode-p 'org-mode)
4252 (error "Agenda file %s is not in `org-mode'" file))
4253 (let ((case-fold-search t))
4254 (save-excursion
4255 (save-restriction
4256 (if org-agenda-restrict
4257 (narrow-to-region org-agenda-restrict-begin
4258 org-agenda-restrict-end)
4259 (widen))
4260 (goto-char (point-min))
4261 (unless (or (org-at-heading-p)
4262 (outline-next-heading))
4263 (throw 'nextfile t))
4264 (goto-char (max (point-min) (1- (point))))
4265 (while (re-search-forward regexp nil t)
4266 (org-back-to-heading t)
4267 (skip-chars-forward "* ")
4268 (setq beg (point-at-bol)
4269 beg1 (point)
4270 end (progn (outline-next-heading) (point)))
4271 (catch :skip
4272 (goto-char beg)
4273 (org-agenda-skip)
4274 (setq str (buffer-substring-no-properties
4275 (point-at-bol)
4276 (if hdl-only (point-at-eol) end)))
4277 (mapc (lambda (wr) (when (string-match wr str)
4278 (goto-char (1- end))
4279 (throw :skip t)))
4280 regexps-)
4281 (mapc (lambda (wr) (unless (string-match wr str)
4282 (goto-char (1- end))
4283 (throw :skip t)))
4284 (if todo-only
4285 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4286 regexps+)
4287 regexps+))
4288 (goto-char beg)
4289 (setq marker (org-agenda-new-marker (point))
4290 category (org-get-category)
4291 category-pos (get-text-property (point) 'org-category-position)
4292 tags (org-get-tags-at (point))
4293 txt (org-agenda-format-item
4295 (buffer-substring-no-properties
4296 beg1 (point-at-eol))
4297 category tags))
4298 (org-add-props txt props
4299 'org-marker marker 'org-hd-marker marker
4300 'org-todo-regexp org-todo-regexp
4301 'org-complex-heading-regexp org-complex-heading-regexp
4302 'priority 1000 'org-category category
4303 'org-category-position category-pos
4304 'type "search")
4305 (push txt ee)
4306 (goto-char (1- end))))))))))
4307 (setq rtn (nreverse ee))
4308 (setq rtnall (append rtnall rtn)))
4309 (if org-agenda-overriding-header
4310 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4311 nil 'face 'org-agenda-structure) "\n")
4312 (insert "Search words: ")
4313 (add-text-properties (point-min) (1- (point))
4314 (list 'face 'org-agenda-structure))
4315 (setq pos (point))
4316 (insert string "\n")
4317 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4318 (setq pos (point))
4319 (unless org-agenda-multi
4320 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4321 (add-text-properties pos (1- (point))
4322 (list 'face 'org-agenda-structure))))
4323 (org-agenda-mark-header-line (point-min))
4324 (when rtnall
4325 (insert (org-agenda-finalize-entries rtnall) "\n"))
4326 (goto-char (point-min))
4327 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4328 (add-text-properties (point-min) (point-max)
4329 `(org-agenda-type search
4330 org-last-args (,todo-only ,string ,edit-at)
4331 org-redo-cmd ,org-agenda-redo-command
4332 org-serie-cmd ,org-cmd))
4333 (org-agenda-finalize)
4334 (setq buffer-read-only t))))
4336 ;;; Agenda TODO list
4338 (defvar org-select-this-todo-keyword nil)
4339 (defvar org-last-arg nil)
4341 ;;;###autoload
4342 (defun org-todo-list (&optional arg)
4343 "Show all (not done) TODO entries from all agenda file in a single list.
4344 The prefix arg can be used to select a specific TODO keyword and limit
4345 the list to these. When using \\[universal-argument], you will be prompted
4346 for a keyword. A numeric prefix directly selects the Nth keyword in
4347 `org-todo-keywords-1'."
4348 (interactive "P")
4349 (if org-agenda-overriding-arguments
4350 (setq arg org-agenda-overriding-arguments))
4351 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4352 (let* ((today (org-today))
4353 (date (calendar-gregorian-from-absolute today))
4354 (kwds org-todo-keywords-for-agenda)
4355 (completion-ignore-case t)
4356 (org-select-this-todo-keyword
4357 (if (stringp arg) arg
4358 (and arg (integerp arg) (> arg 0)
4359 (nth (1- arg) kwds))))
4360 rtn rtnall files file pos)
4361 (when (equal arg '(4))
4362 (setq org-select-this-todo-keyword
4363 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4364 (mapcar 'list kwds) nil nil)))
4365 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4366 (catch 'exit
4367 (if org-agenda-sticky
4368 (setq org-agenda-buffer-name
4369 (if (stringp org-select-this-todo-keyword)
4370 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4371 org-select-this-todo-keyword)
4372 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4373 (org-agenda-prepare "TODO")
4374 (org-compile-prefix-format 'todo)
4375 (org-set-sorting-strategy 'todo)
4376 (setq org-agenda-redo-command
4377 `(org-todo-list (or current-prefix-arg (quote ,arg))))
4378 (setq files (org-agenda-files nil 'ifmode)
4379 rtnall nil)
4380 (while (setq file (pop files))
4381 (catch 'nextfile
4382 (org-check-agenda-file file)
4383 (setq rtn (org-agenda-get-day-entries file date :todo))
4384 (setq rtnall (append rtnall rtn))))
4385 (if org-agenda-overriding-header
4386 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4387 nil 'face 'org-agenda-structure) "\n")
4388 (insert "Global list of TODO items of type: ")
4389 (add-text-properties (point-min) (1- (point))
4390 (list 'face 'org-agenda-structure
4391 'short-heading
4392 (concat "ToDo: "
4393 (or org-select-this-todo-keyword "ALL"))))
4394 (org-agenda-mark-header-line (point-min))
4395 (setq pos (point))
4396 (insert (or org-select-this-todo-keyword "ALL") "\n")
4397 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4398 (setq pos (point))
4399 (unless org-agenda-multi
4400 (insert "Available with `N r': (0)[ALL]")
4401 (let ((n 0) s)
4402 (mapc (lambda (x)
4403 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4404 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4405 (insert "\n "))
4406 (insert " " s))
4407 kwds))
4408 (insert "\n"))
4409 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4410 (org-agenda-mark-header-line (point-min))
4411 (when rtnall
4412 (insert (org-agenda-finalize-entries rtnall) "\n"))
4413 (goto-char (point-min))
4414 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4415 (add-text-properties (point-min) (point-max)
4416 `(org-agenda-type todo
4417 org-last-args ,arg
4418 org-redo-cmd ,org-agenda-redo-command
4419 org-serie-cmd ,org-cmd))
4420 (org-agenda-finalize)
4421 (setq buffer-read-only t))))
4423 ;;; Agenda tags match
4425 ;;;###autoload
4426 (defun org-tags-view (&optional todo-only match)
4427 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4428 The prefix arg TODO-ONLY limits the search to TODO entries."
4429 (interactive "P")
4430 (if org-agenda-overriding-arguments
4431 (setq todo-only (car org-agenda-overriding-arguments)
4432 match (nth 1 org-agenda-overriding-arguments)))
4433 (let* ((org-tags-match-list-sublevels
4434 org-tags-match-list-sublevels)
4435 (completion-ignore-case t)
4436 rtn rtnall files file pos matcher
4437 buffer)
4438 (when (and (stringp match) (not (string-match "\\S-" match)))
4439 (setq match nil))
4440 (setq matcher (org-make-tags-matcher match)
4441 match (car matcher) matcher (cdr matcher))
4442 (catch 'exit
4443 (if org-agenda-sticky
4444 (setq org-agenda-buffer-name
4445 (if (stringp match)
4446 (format "*Org Agenda(%s:%s)*"
4447 (or org-keys (or (and todo-only "M") "m")) match)
4448 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4449 (org-agenda-prepare (concat "TAGS " match))
4450 (org-compile-prefix-format 'tags)
4451 (org-set-sorting-strategy 'tags)
4452 (setq org-agenda-query-string match)
4453 (setq org-agenda-redo-command
4454 (list 'org-tags-view `(quote ,todo-only)
4455 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4456 (setq files (org-agenda-files nil 'ifmode)
4457 rtnall nil)
4458 (while (setq file (pop files))
4459 (catch 'nextfile
4460 (org-check-agenda-file file)
4461 (setq buffer (if (file-exists-p file)
4462 (org-get-agenda-file-buffer file)
4463 (error "No such file %s" file)))
4464 (if (not buffer)
4465 ;; If file does not exist, error message to agenda
4466 (setq rtn (list
4467 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4468 rtnall (append rtnall rtn))
4469 (with-current-buffer buffer
4470 (unless (derived-mode-p 'org-mode)
4471 (error "Agenda file %s is not in `org-mode'" file))
4472 (save-excursion
4473 (save-restriction
4474 (if org-agenda-restrict
4475 (narrow-to-region org-agenda-restrict-begin
4476 org-agenda-restrict-end)
4477 (widen))
4478 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4479 (setq rtnall (append rtnall rtn))))))))
4480 (if org-agenda-overriding-header
4481 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4482 nil 'face 'org-agenda-structure) "\n")
4483 (insert "Headlines with TAGS match: ")
4484 (add-text-properties (point-min) (1- (point))
4485 (list 'face 'org-agenda-structure
4486 'short-heading
4487 (concat "Match: " match)))
4488 (setq pos (point))
4489 (insert match "\n")
4490 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4491 (setq pos (point))
4492 (unless org-agenda-multi
4493 (insert "Press `C-u r' to search again with new search string\n"))
4494 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4495 (org-agenda-mark-header-line (point-min))
4496 (when rtnall
4497 (insert (org-agenda-finalize-entries rtnall) "\n"))
4498 (goto-char (point-min))
4499 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4500 (add-text-properties (point-min) (point-max)
4501 `(org-agenda-type tags
4502 org-last-args (,todo-only ,match)
4503 org-redo-cmd ,org-agenda-redo-command
4504 org-serie-cmd ,org-cmd))
4505 (org-agenda-finalize)
4506 (setq buffer-read-only t))))
4508 ;;; Agenda Finding stuck projects
4510 (defvar org-agenda-skip-regexp nil
4511 "Regular expression used in skipping subtrees for the agenda.
4512 This is basically a temporary global variable that can be set and then
4513 used by user-defined selections using `org-agenda-skip-function'.")
4515 (defvar org-agenda-overriding-header nil
4516 "When set during agenda, todo and tags searches it replaces the header.
4517 This variable should not be set directly, but custom commands can bind it
4518 in the options section.")
4520 (defun org-agenda-skip-entry-when-regexp-matches ()
4521 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4522 If yes, it returns the end position of this entry, causing agenda commands
4523 to skip the entry but continuing the search in the subtree. This is a
4524 function that can be put into `org-agenda-skip-function' for the duration
4525 of a command."
4526 (let ((end (save-excursion (org-end-of-subtree t)))
4527 skip)
4528 (save-excursion
4529 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4530 (and skip end)))
4532 (defun org-agenda-skip-subtree-when-regexp-matches ()
4533 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4534 If yes, it returns the end position of this tree, causing agenda commands
4535 to skip this subtree. This is a function that can be put into
4536 `org-agenda-skip-function' for the duration of a command."
4537 (let ((end (save-excursion (org-end-of-subtree t)))
4538 skip)
4539 (save-excursion
4540 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4541 (and skip end)))
4543 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4544 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4545 If yes, it returns the end position of the current entry (NOT the tree),
4546 causing agenda commands to skip the entry but continuing the search in
4547 the subtree. This is a function that can be put into
4548 `org-agenda-skip-function' for the duration of a command. An important
4549 use of this function is for the stuck project list."
4550 (let ((end (save-excursion (org-end-of-subtree t)))
4551 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4552 skip)
4553 (save-excursion
4554 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4555 (and skip entry-end)))
4557 (defun org-agenda-skip-entry-if (&rest conditions)
4558 "Skip entry if any of CONDITIONS is true.
4559 See `org-agenda-skip-if' for details."
4560 (org-agenda-skip-if nil conditions))
4562 (defun org-agenda-skip-subtree-if (&rest conditions)
4563 "Skip entry if any of CONDITIONS is true.
4564 See `org-agenda-skip-if' for details."
4565 (org-agenda-skip-if t conditions))
4567 (defun org-agenda-skip-if (subtree conditions)
4568 "Checks current entity for CONDITIONS.
4569 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4570 the entry (i.e. the text before the next heading) is checked.
4572 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4573 from different tests. Valid conditions are:
4575 scheduled Check if there is a scheduled cookie
4576 notscheduled Check if there is no scheduled cookie
4577 deadline Check if there is a deadline
4578 notdeadline Check if there is no deadline
4579 timestamp Check if there is a timestamp (also deadline or scheduled)
4580 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4581 regexp Check if regexp matches
4582 notregexp Check if regexp does not match.
4583 todo Check if TODO keyword matches
4584 nottodo Check if TODO keyword does not match
4586 The regexp is taken from the conditions list, it must come right after
4587 the `regexp' or `notregexp' element.
4589 `todo' and `nottodo' accept as an argument a list of todo
4590 keywords, which may include \"*\" to match any todo keyword.
4592 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4594 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4596 Instead of a list, a keyword class may be given. For example:
4598 (org-agenda-skip-entry-if 'nottodo 'done)
4600 would skip entries that haven't been marked with any of \"DONE\"
4601 keywords. Possible classes are: `todo', `done', `any'.
4603 If any of these conditions is met, this function returns the end point of
4604 the entity, causing the search to continue from there. This is a function
4605 that can be put into `org-agenda-skip-function' for the duration of a command."
4606 (let (beg end m)
4607 (org-back-to-heading t)
4608 (setq beg (point)
4609 end (if subtree
4610 (progn (org-end-of-subtree t) (point))
4611 (progn (outline-next-heading) (1- (point)))))
4612 (goto-char beg)
4613 (and
4615 (and (memq 'scheduled conditions)
4616 (re-search-forward org-scheduled-time-regexp end t))
4617 (and (memq 'notscheduled conditions)
4618 (not (re-search-forward org-scheduled-time-regexp end t)))
4619 (and (memq 'deadline conditions)
4620 (re-search-forward org-deadline-time-regexp end t))
4621 (and (memq 'notdeadline conditions)
4622 (not (re-search-forward org-deadline-time-regexp end t)))
4623 (and (memq 'timestamp conditions)
4624 (re-search-forward org-ts-regexp end t))
4625 (and (memq 'nottimestamp conditions)
4626 (not (re-search-forward org-ts-regexp end t)))
4627 (and (setq m (memq 'regexp conditions))
4628 (stringp (nth 1 m))
4629 (re-search-forward (nth 1 m) end t))
4630 (and (setq m (memq 'notregexp conditions))
4631 (stringp (nth 1 m))
4632 (not (re-search-forward (nth 1 m) end t)))
4633 (and (or
4634 (setq m (memq 'nottodo conditions))
4635 (setq m (memq 'todo-unblocked conditions))
4636 (setq m (memq 'nottodo-unblocked conditions))
4637 (setq m (memq 'todo conditions)))
4638 (org-agenda-skip-if-todo m end)))
4639 end)))
4641 (defun org-agenda-skip-if-todo (args end)
4642 "Helper function for `org-agenda-skip-if', do not use it directly.
4643 ARGS is a list with first element either `todo', `nottodo',
4644 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4645 a list of TODO keywords, or a state symbol `todo' or `done' or
4646 `any'."
4647 (let ((kw (car args))
4648 (arg (cadr args))
4649 todo-wds todo-re)
4650 (setq todo-wds
4651 (org-uniquify
4652 (cond
4653 ((listp arg) ;; list of keywords
4654 (if (member "*" arg)
4655 (mapcar 'substring-no-properties org-todo-keywords-1)
4656 arg))
4657 ((symbolp arg) ;; keyword class name
4658 (cond
4659 ((eq arg 'todo)
4660 (org-delete-all org-done-keywords
4661 (mapcar 'substring-no-properties
4662 org-todo-keywords-1)))
4663 ((eq arg 'done) org-done-keywords)
4664 ((eq arg 'any)
4665 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4666 (setq todo-re
4667 (concat "^\\*+[ \t]+\\<\\("
4668 (mapconcat 'identity todo-wds "\\|")
4669 "\\)\\>"))
4670 (cond
4671 ((eq kw 'todo) (re-search-forward todo-re end t))
4672 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4673 ((eq kw 'todo-unblocked)
4674 (catch 'unblocked
4675 (while (re-search-forward todo-re end t)
4676 (or (org-entry-blocked-p) (throw 'unblocked t)))
4677 nil))
4678 ((eq kw 'nottodo-unblocked)
4679 (catch 'unblocked
4680 (while (re-search-forward todo-re end t)
4681 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4685 ;;;###autoload
4686 (defun org-agenda-list-stuck-projects (&rest ignore)
4687 "Create agenda view for projects that are stuck.
4688 Stuck projects are project that have no next actions. For the definitions
4689 of what a project is and how to check if it stuck, customize the variable
4690 `org-stuck-projects'."
4691 (interactive)
4692 (let* ((org-agenda-skip-function
4693 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4694 ;; We could have used org-agenda-skip-if here.
4695 (org-agenda-overriding-header
4696 (or org-agenda-overriding-header "List of stuck projects: "))
4697 (matcher (nth 0 org-stuck-projects))
4698 (todo (nth 1 org-stuck-projects))
4699 (todo-wds (if (member "*" todo)
4700 (progn
4701 (org-agenda-prepare-buffers (org-agenda-files
4702 nil 'ifmode))
4703 (org-delete-all
4704 org-done-keywords-for-agenda
4705 (copy-sequence org-todo-keywords-for-agenda)))
4706 todo))
4707 (todo-re (concat "^\\*+[ \t]+\\("
4708 (mapconcat 'identity todo-wds "\\|")
4709 "\\)\\>"))
4710 (tags (nth 2 org-stuck-projects))
4711 (tags-re (if (member "*" tags)
4712 (concat org-outline-regexp-bol
4713 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4714 (if tags
4715 (concat org-outline-regexp-bol
4716 ".*:\\("
4717 (mapconcat 'identity tags "\\|")
4718 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4719 (gen-re (nth 3 org-stuck-projects))
4720 (re-list
4721 (delq nil
4722 (list
4723 (if todo todo-re)
4724 (if tags tags-re)
4725 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4726 gen-re)))))
4727 (setq org-agenda-skip-regexp
4728 (if re-list
4729 (mapconcat 'identity re-list "\\|")
4730 (error "No information how to identify unstuck projects")))
4731 (org-tags-view nil matcher)
4732 (with-current-buffer org-agenda-buffer-name
4733 (setq org-agenda-redo-command
4734 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4736 ;;; Diary integration
4738 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4739 (defvar diary-list-entries-hook)
4740 (defvar diary-time-regexp)
4741 (defun org-get-entries-from-diary (date)
4742 "Get the (Emacs Calendar) diary entries for DATE."
4743 (require 'diary-lib)
4744 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4745 (diary-display-hook '(fancy-diary-display))
4746 (diary-display-function 'fancy-diary-display)
4747 (pop-up-frames nil)
4748 (diary-list-entries-hook
4749 (cons 'org-diary-default-entry diary-list-entries-hook))
4750 (diary-file-name-prefix-function nil) ; turn this feature off
4751 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4752 entries
4753 (org-disable-agenda-to-diary t))
4754 (save-excursion
4755 (save-window-excursion
4756 (funcall (if (fboundp 'diary-list-entries)
4757 'diary-list-entries 'list-diary-entries)
4758 date 1)))
4759 (if (not (get-buffer diary-fancy-buffer))
4760 (setq entries nil)
4761 (with-current-buffer diary-fancy-buffer
4762 (setq buffer-read-only nil)
4763 (if (zerop (buffer-size))
4764 ;; No entries
4765 (setq entries nil)
4766 ;; Omit the date and other unnecessary stuff
4767 (org-agenda-cleanup-fancy-diary)
4768 ;; Add prefix to each line and extend the text properties
4769 (if (zerop (buffer-size))
4770 (setq entries nil)
4771 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4772 (setq entries
4773 (with-temp-buffer
4774 (insert entries) (goto-char (point-min))
4775 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4776 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4777 (replace-match (concat "; " (match-string 1)))))
4778 (buffer-string)))))
4779 (set-buffer-modified-p nil)
4780 (kill-buffer diary-fancy-buffer)))
4781 (when entries
4782 (setq entries (org-split-string entries "\n"))
4783 (setq entries
4784 (mapcar
4785 (lambda (x)
4786 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4787 ;; Extend the text properties to the beginning of the line
4788 (org-add-props x (text-properties-at (1- (length x)) x)
4789 'type "diary" 'date date 'face 'org-agenda-diary))
4790 entries)))))
4792 (defvar org-agenda-cleanup-fancy-diary-hook nil
4793 "Hook run when the fancy diary buffer is cleaned up.")
4795 (defun org-agenda-cleanup-fancy-diary ()
4796 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4797 This gets rid of the date, the underline under the date, and
4798 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4799 date. It also removes lines that contain only whitespace."
4800 (goto-char (point-min))
4801 (if (looking-at ".*?:[ \t]*")
4802 (progn
4803 (replace-match "")
4804 (re-search-forward "\n=+$" nil t)
4805 (replace-match "")
4806 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4807 (re-search-forward "\n=+$" nil t)
4808 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4809 (goto-char (point-min))
4810 (while (re-search-forward "^ +\n" nil t)
4811 (replace-match ""))
4812 (goto-char (point-min))
4813 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4814 (replace-match ""))
4815 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4817 ;; Make sure entries from the diary have the right text properties.
4818 (eval-after-load "diary-lib"
4819 '(if (boundp 'diary-modify-entry-list-string-function)
4820 ;; We can rely on the hook, nothing to do
4822 ;; Hook not available, must use advice to make this work
4823 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4824 "Make the position visible."
4825 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4826 (stringp string)
4827 buffer-file-name)
4828 (setq string (org-modify-diary-entry-string string))))))
4830 (defun org-modify-diary-entry-string (string)
4831 "Add text properties to string, allowing org-mode to act on it."
4832 (org-add-props string nil
4833 'mouse-face 'highlight
4834 'help-echo (if buffer-file-name
4835 (format "mouse-2 or RET jump to diary file %s"
4836 (abbreviate-file-name buffer-file-name))
4838 'org-agenda-diary-link t
4839 'org-marker (org-agenda-new-marker (point-at-bol))))
4841 (defun org-diary-default-entry ()
4842 "Add a dummy entry to the diary.
4843 Needed to avoid empty dates which mess up holiday display."
4844 ;; Catch the error if dealing with the new add-to-diary-alist
4845 (when org-disable-agenda-to-diary
4846 (condition-case nil
4847 (org-add-to-diary-list original-date "Org-mode dummy" "")
4848 (error
4849 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4851 (defun org-add-to-diary-list (&rest args)
4852 (if (fboundp 'diary-add-to-list)
4853 (apply 'diary-add-to-list args)
4854 (apply 'add-to-diary-list args)))
4856 (defvar org-diary-last-run-time nil)
4858 ;;;###autoload
4859 (defun org-diary (&rest args)
4860 "Return diary information from org files.
4861 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4862 It accesses org files and extracts information from those files to be
4863 listed in the diary. The function accepts arguments specifying what
4864 items should be listed. For a list of arguments allowed here, see the
4865 variable `org-agenda-entry-types'.
4867 The call in the diary file should look like this:
4869 &%%(org-diary) ~/path/to/some/orgfile.org
4871 Use a separate line for each org file to check. Or, if you omit the file name,
4872 all files listed in `org-agenda-files' will be checked automatically:
4874 &%%(org-diary)
4876 If you don't give any arguments (as in the example above), the default
4877 arguments (:deadline :scheduled :timestamp :sexp) are used.
4878 So the example above may also be written as
4880 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4882 The function expects the lisp variables `entry' and `date' to be provided
4883 by the caller, because this is how the calendar works. Don't use this
4884 function from a program - use `org-agenda-get-day-entries' instead."
4885 (when (> (- (org-float-time)
4886 org-agenda-last-marker-time)
4888 ;; I am not sure if this works with sticky agendas, because the marker
4889 ;; list is then no longer a global variable.
4890 (org-agenda-reset-markers))
4891 (org-compile-prefix-format 'agenda)
4892 (org-set-sorting-strategy 'agenda)
4893 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4894 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4895 (list entry)
4896 (org-agenda-files t)))
4897 (time (org-float-time))
4898 file rtn results)
4899 (when (or (not org-diary-last-run-time)
4900 (> (- time
4901 org-diary-last-run-time)
4903 (org-agenda-prepare-buffers files))
4904 (setq org-diary-last-run-time time)
4905 ;; If this is called during org-agenda, don't return any entries to
4906 ;; the calendar. Org Agenda will list these entries itself.
4907 (if org-disable-agenda-to-diary (setq files nil))
4908 (while (setq file (pop files))
4909 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4910 (setq results (append results rtn)))
4911 (if results
4912 (concat (org-agenda-finalize-entries results) "\n"))))
4914 ;;; Agenda entry finders
4916 (defun org-agenda-get-day-entries (file date &rest args)
4917 "Does the work for `org-diary' and `org-agenda'.
4918 FILE is the path to a file to be checked for entries. DATE is date like
4919 the one returned by `calendar-current-date'. ARGS are symbols indicating
4920 which kind of entries should be extracted. For details about these, see
4921 the documentation of `org-diary'."
4922 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4923 (let* ((org-startup-folded nil)
4924 (org-startup-align-all-tables nil)
4925 (buffer (if (file-exists-p file)
4926 (org-get-agenda-file-buffer file)
4927 (error "No such file %s" file)))
4928 arg results rtn deadline-results)
4929 (if (not buffer)
4930 ;; If file does not exist, make sure an error message ends up in diary
4931 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4932 (with-current-buffer buffer
4933 (unless (derived-mode-p 'org-mode)
4934 (error "Agenda file %s is not in `org-mode'" file))
4935 (setq org-agenda-buffer (or org-agenda-buffer buffer))
4936 (let ((case-fold-search nil))
4937 (save-excursion
4938 (save-restriction
4939 (if org-agenda-restrict
4940 (narrow-to-region org-agenda-restrict-begin
4941 org-agenda-restrict-end)
4942 (widen))
4943 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4944 (while (setq arg (pop args))
4945 (cond
4946 ((and (eq arg :todo)
4947 (equal date (calendar-gregorian-from-absolute
4948 (org-today))))
4949 (setq rtn (org-agenda-get-todos))
4950 (setq results (append results rtn)))
4951 ((eq arg :timestamp)
4952 (setq rtn (org-agenda-get-blocks))
4953 (setq results (append results rtn))
4954 (setq rtn (org-agenda-get-timestamps deadline-results))
4955 (setq results (append results rtn)))
4956 ((eq arg :sexp)
4957 (setq rtn (org-agenda-get-sexps))
4958 (setq results (append results rtn)))
4959 ((eq arg :scheduled)
4960 (setq rtn (org-agenda-get-scheduled deadline-results))
4961 (setq results (append results rtn)))
4962 ((eq arg :closed)
4963 (setq rtn (org-agenda-get-progress))
4964 (setq results (append results rtn)))
4965 ((eq arg :deadline)
4966 (setq rtn (org-agenda-get-deadlines))
4967 (setq deadline-results (copy-sequence rtn))
4968 (setq results (append results rtn))))))))
4969 results))))
4971 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4972 (defun org-agenda-get-todos ()
4973 "Return the TODO information for agenda display."
4974 (let* ((props (list 'face nil
4975 'done-face 'org-agenda-done
4976 'org-not-done-regexp org-not-done-regexp
4977 'org-todo-regexp org-todo-regexp
4978 'org-complex-heading-regexp org-complex-heading-regexp
4979 'mouse-face 'highlight
4980 'help-echo
4981 (format "mouse-2 or RET jump to org file %s"
4982 (abbreviate-file-name buffer-file-name))))
4983 (regexp (format org-heading-keyword-regexp-format
4984 (cond
4985 ((and org-select-this-todo-keyword
4986 (equal org-select-this-todo-keyword "*"))
4987 org-todo-regexp)
4988 (org-select-this-todo-keyword
4989 (concat "\\("
4990 (mapconcat 'identity
4991 (org-split-string
4992 org-select-this-todo-keyword
4993 "|")
4994 "\\|") "\\)"))
4995 (t org-not-done-regexp))))
4996 marker priority category category-pos tags todo-state
4997 ee txt beg end)
4998 (goto-char (point-min))
4999 (while (re-search-forward regexp nil t)
5000 (catch :skip
5001 (save-match-data
5002 (beginning-of-line)
5003 (org-agenda-skip)
5004 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5005 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5006 (goto-char (1+ beg))
5007 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5008 (throw :skip nil)))
5009 (goto-char (match-beginning 2))
5010 (setq marker (org-agenda-new-marker (match-beginning 0))
5011 category (org-get-category)
5012 category-pos (get-text-property (point) 'org-category-position)
5013 txt (org-trim
5014 (buffer-substring (match-beginning 2) (match-end 0)))
5015 tags (org-get-tags-at (point))
5016 txt (org-agenda-format-item "" txt category tags)
5017 priority (1+ (org-get-priority txt))
5018 todo-state (org-get-todo-state))
5019 (org-add-props txt props
5020 'org-marker marker 'org-hd-marker marker
5021 'priority priority 'org-category category
5022 'org-category-position category-pos
5023 'type "todo" 'todo-state todo-state)
5024 (push txt ee)
5025 (if org-agenda-todo-list-sublevels
5026 (goto-char (match-end 2))
5027 (org-end-of-subtree 'invisible))))
5028 (nreverse ee)))
5030 (defun org-agenda-todo-custom-ignore-p (time n)
5031 "Check whether timestamp is farther away then n number of days.
5032 This function is invoked if `org-agenda-todo-ignore-deadlines',
5033 `org-agenda-todo-ignore-scheduled' or
5034 `org-agenda-todo-ignore-timestamp' is set to an integer."
5035 (let ((days (org-days-to-time time)))
5036 (if (>= n 0)
5037 (>= days n)
5038 (<= days n))))
5040 ;;;###autoload
5041 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5042 (&optional end)
5043 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5044 (when (or org-agenda-todo-ignore-with-date
5045 org-agenda-todo-ignore-scheduled
5046 org-agenda-todo-ignore-deadlines
5047 org-agenda-todo-ignore-timestamp)
5048 (setq end (or end (save-excursion (outline-next-heading) (point))))
5049 (save-excursion
5050 (or (and org-agenda-todo-ignore-with-date
5051 (re-search-forward org-ts-regexp end t))
5052 (and org-agenda-todo-ignore-scheduled
5053 (re-search-forward org-scheduled-time-regexp end t)
5054 (cond
5055 ((eq org-agenda-todo-ignore-scheduled 'future)
5056 (> (org-days-to-time (match-string 1)) 0))
5057 ((eq org-agenda-todo-ignore-scheduled 'past)
5058 (<= (org-days-to-time (match-string 1)) 0))
5059 ((numberp org-agenda-todo-ignore-scheduled)
5060 (org-agenda-todo-custom-ignore-p
5061 (match-string 1) org-agenda-todo-ignore-scheduled))
5062 (t)))
5063 (and org-agenda-todo-ignore-deadlines
5064 (re-search-forward org-deadline-time-regexp end t)
5065 (cond
5066 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5067 ((eq org-agenda-todo-ignore-deadlines 'far)
5068 (not (org-deadline-close (match-string 1))))
5069 ((eq org-agenda-todo-ignore-deadlines 'future)
5070 (> (org-days-to-time (match-string 1)) 0))
5071 ((eq org-agenda-todo-ignore-deadlines 'past)
5072 (<= (org-days-to-time (match-string 1)) 0))
5073 ((numberp org-agenda-todo-ignore-deadlines)
5074 (org-agenda-todo-custom-ignore-p
5075 (match-string 1) org-agenda-todo-ignore-deadlines))
5076 (t (org-deadline-close (match-string 1)))))
5077 (and org-agenda-todo-ignore-timestamp
5078 (let ((buffer (current-buffer))
5079 (regexp
5080 (concat
5081 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5082 (start (point)))
5083 ;; Copy current buffer into a temporary one
5084 (with-temp-buffer
5085 (insert-buffer-substring buffer start end)
5086 (goto-char (point-min))
5087 ;; Delete SCHEDULED and DEADLINE items
5088 (while (re-search-forward regexp end t)
5089 (delete-region (match-beginning 0) (match-end 0)))
5090 (goto-char (point-min))
5091 ;; No search for timestamp left
5092 (when (re-search-forward org-ts-regexp nil t)
5093 (cond
5094 ((eq org-agenda-todo-ignore-timestamp 'future)
5095 (> (org-days-to-time (match-string 1)) 0))
5096 ((eq org-agenda-todo-ignore-timestamp 'past)
5097 (<= (org-days-to-time (match-string 1)) 0))
5098 ((numberp org-agenda-todo-ignore-timestamp)
5099 (org-agenda-todo-custom-ignore-p
5100 (match-string 1) org-agenda-todo-ignore-timestamp))
5101 (t))))))))))
5103 (defconst org-agenda-no-heading-message
5104 "No heading for this item in buffer or region.")
5106 (defun org-agenda-get-timestamps (&optional deadline-results)
5107 "Return the date stamp information for agenda display."
5108 (let* ((props (list 'face 'org-agenda-calendar-event
5109 'org-not-done-regexp org-not-done-regexp
5110 'org-todo-regexp org-todo-regexp
5111 'org-complex-heading-regexp org-complex-heading-regexp
5112 'mouse-face 'highlight
5113 'help-echo
5114 (format "mouse-2 or RET jump to org file %s"
5115 (abbreviate-file-name buffer-file-name))))
5116 (d1 (calendar-absolute-from-gregorian date))
5118 (deadline-position-alist
5119 (mapcar (lambda (a) (and (setq mm (get-text-property
5120 0 'org-hd-marker a))
5121 (cons (marker-position mm) a)))
5122 deadline-results))
5123 (remove-re org-ts-regexp)
5124 (regexp
5125 (concat
5126 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5127 (regexp-quote
5128 (substring
5129 (format-time-string
5130 (car org-time-stamp-formats)
5131 (apply 'encode-time ; DATE bound by calendar
5132 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5133 1 11))
5134 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5135 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5136 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5137 donep tmp priority category category-pos ee txt timestr tags
5138 b0 b3 e3 head todo-state end-of-match show-all warntime)
5139 (goto-char (point-min))
5140 (while (setq end-of-match (re-search-forward regexp nil t))
5141 (setq b0 (match-beginning 0)
5142 b3 (match-beginning 3) e3 (match-end 3)
5143 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5144 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5145 (member todo-state
5146 org-agenda-repeating-timestamp-show-all)))
5147 (catch :skip
5148 (and (org-at-date-range-p) (throw :skip nil))
5149 (org-agenda-skip)
5150 (if (and (match-end 1)
5151 (not (= d1 (org-time-string-to-absolute
5152 (match-string 1) d1 nil show-all
5153 (current-buffer) b0))))
5154 (throw :skip nil))
5155 (if (and e3
5156 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5157 (throw :skip nil))
5158 (setq tmp (buffer-substring (max (point-min)
5159 (- b0 org-ds-keyword-length))
5161 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5162 inactivep (= (char-after b0) ?\[)
5163 deadlinep (string-match org-deadline-regexp tmp)
5164 scheduledp (string-match org-scheduled-regexp tmp)
5165 closedp (and org-agenda-include-inactive-timestamps
5166 (string-match org-closed-string tmp))
5167 clockp (and org-agenda-include-inactive-timestamps
5168 (or (string-match org-clock-string tmp)
5169 (string-match "]-+\\'" tmp)))
5170 warntime (org-entry-get (point) "APPT_WARNTIME")
5171 donep (member todo-state org-done-keywords))
5172 (if (or scheduledp deadlinep closedp clockp
5173 (and donep org-agenda-skip-timestamp-if-done))
5174 (throw :skip t))
5175 (if (string-match ">" timestr)
5176 ;; substring should only run to end of time stamp
5177 (setq timestr (substring timestr 0 (match-end 0))))
5178 (setq marker (org-agenda-new-marker b0)
5179 category (org-get-category b0)
5180 category-pos (get-text-property b0 'org-category-position))
5181 (save-excursion
5182 (if (not (re-search-backward org-outline-regexp-bol nil t))
5183 (setq txt org-agenda-no-heading-message)
5184 (goto-char (match-beginning 0))
5185 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5186 (assoc (point) deadline-position-alist))
5187 (throw :skip nil))
5188 (setq hdmarker (org-agenda-new-marker)
5189 tags (org-get-tags-at))
5190 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5191 (setq head (or (match-string 1) ""))
5192 (setq txt (org-agenda-format-item
5193 (if inactivep org-agenda-inactive-leader nil)
5194 head category tags timestr
5195 remove-re)))
5196 (setq priority (org-get-priority txt))
5197 (org-add-props txt props
5198 'org-marker marker 'org-hd-marker hdmarker)
5199 (org-add-props txt nil 'priority priority
5200 'org-category category 'date date
5201 'org-category-position category-pos
5202 'todo-state todo-state
5203 'warntime warntime
5204 'type "timestamp")
5205 (push txt ee))
5206 (if org-agenda-skip-additional-timestamps-same-entry
5207 (outline-next-heading)
5208 (goto-char end-of-match))))
5209 (nreverse ee)))
5211 (defun org-agenda-get-sexps ()
5212 "Return the sexp information for agenda display."
5213 (require 'diary-lib)
5214 (let* ((props (list 'face 'org-agenda-calendar-sexp
5215 'mouse-face 'highlight
5216 'help-echo
5217 (format "mouse-2 or RET jump to org file %s"
5218 (abbreviate-file-name buffer-file-name))))
5219 (regexp "^&?%%(")
5220 marker category extra category-pos ee txt tags entry
5221 result beg b sexp sexp-entry todo-state warntime)
5222 (goto-char (point-min))
5223 (while (re-search-forward regexp nil t)
5224 (catch :skip
5225 (org-agenda-skip)
5226 (setq beg (match-beginning 0))
5227 (goto-char (1- (match-end 0)))
5228 (setq b (point))
5229 (forward-sexp 1)
5230 (setq sexp (buffer-substring b (point)))
5231 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5232 (org-trim (match-string 1))
5233 ""))
5234 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5235 (when result
5236 (setq marker (org-agenda-new-marker beg)
5237 category (org-get-category beg)
5238 category-pos (get-text-property beg 'org-category-position)
5239 tags (save-excursion (org-backward-heading-same-level 0)
5240 (org-get-tags-at))
5241 todo-state (org-get-todo-state)
5242 warntime (org-entry-get (point) "APPT_WARNTIME"))
5244 (dolist (r (if (stringp result)
5245 (list result)
5246 result)) ;; we expect a list here
5247 (when (and org-agenda-diary-sexp-prefix
5248 (string-match org-agenda-diary-sexp-prefix r))
5249 (setq extra (match-string 0 r)
5250 r (replace-match "" nil nil r)))
5251 (if (string-match "\\S-" r)
5252 (setq txt r)
5253 (setq txt "SEXP entry returned empty string"))
5255 (setq txt (org-agenda-format-item
5256 extra txt category tags 'time))
5257 (org-add-props txt props 'org-marker marker)
5258 (org-add-props txt nil
5259 'org-category category 'date date 'todo-state todo-state
5260 'org-category-position category-pos 'tags tags
5261 'type "sexp" 'warntime warntime)
5262 (push txt ee)))))
5263 (nreverse ee)))
5265 ;; Calendar sanity: define some functions that are independent of
5266 ;; `calendar-date-style'.
5267 ;; Normally I would like to use ISO format when calling the diary functions,
5268 ;; but to make sure we still have Emacs 22 compatibility we bind
5269 ;; also `european-calendar-style' and use european format
5270 (defun org-anniversary (year month day &optional mark)
5271 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5272 (org-no-warnings
5273 (let ((calendar-date-style 'european) (european-calendar-style t))
5274 (diary-anniversary day month year mark))))
5275 (defun org-cyclic (N year month day &optional mark)
5276 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5277 (org-no-warnings
5278 (let ((calendar-date-style 'european) (european-calendar-style t))
5279 (diary-cyclic N day month year mark))))
5280 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5281 "Like `diary-block', but with fixed (ISO) order of arguments."
5282 (org-no-warnings
5283 (let ((calendar-date-style 'european) (european-calendar-style t))
5284 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5285 (defun org-date (year month day &optional mark)
5286 "Like `diary-date', but with fixed (ISO) order of arguments."
5287 (org-no-warnings
5288 (let ((calendar-date-style 'european) (european-calendar-style t))
5289 (diary-date day month year mark))))
5290 (defalias 'org-float 'diary-float)
5292 ;; Define the` org-class' function
5293 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5294 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5295 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5296 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5297 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5298 `holidays', then any date that is known by the Emacs calendar to be a
5299 holiday will also be skipped."
5300 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5301 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5302 (d (calendar-absolute-from-gregorian date)))
5303 (and
5304 (<= date1 d)
5305 (<= d date2)
5306 (= (calendar-day-of-week date) dayname)
5307 (or (not skip-weeks)
5308 (progn
5309 (require 'cal-iso)
5310 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5311 (not (and (memq 'holidays skip-weeks)
5312 (calendar-check-holidays date)))
5313 entry)))
5315 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5316 "Like `org-class', but honor `calendar-date-style'.
5317 The order of the first 2 times 3 arguments depends on the variable
5318 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5319 So for American calendars, give this as MONTH DAY YEAR, for European as
5320 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5321 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5322 is any number of ISO weeks in the block period for which the item should
5323 be skipped.
5325 This function is here only for backward compatibility and it is deprecated,
5326 please use `org-class' instead."
5327 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5328 (date2 (org-order-calendar-date-args m2 d2 y2)))
5329 (org-class
5330 (nth 2 date1) (car date1) (nth 1 date1)
5331 (nth 2 date2) (car date2) (nth 1 date2)
5332 dayname skip-weeks)))
5333 (make-obsolete 'org-diary-class 'org-class "")
5335 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5336 (defalias 'org-get-closed 'org-agenda-get-progress)
5337 (defun org-agenda-get-progress ()
5338 "Return the logged TODO entries for agenda display."
5339 (let* ((props (list 'mouse-face 'highlight
5340 'org-not-done-regexp org-not-done-regexp
5341 'org-todo-regexp org-todo-regexp
5342 'org-complex-heading-regexp org-complex-heading-regexp
5343 'help-echo
5344 (format "mouse-2 or RET jump to org file %s"
5345 (abbreviate-file-name buffer-file-name))))
5346 (items (if (consp org-agenda-show-log-scoped)
5347 org-agenda-show-log-scoped
5348 (if (eq org-agenda-show-log-scoped 'clockcheck)
5349 '(clock)
5350 org-agenda-log-mode-items)))
5351 (parts
5352 (delq nil
5353 (list
5354 (if (memq 'closed items) (concat "\\<" org-closed-string))
5355 (if (memq 'clock items) (concat "\\<" org-clock-string))
5356 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5357 (parts-re (if parts (mapconcat 'identity parts "\\|")
5358 (error "`org-agenda-log-mode-items' is empty")))
5359 (regexp (concat
5360 "\\(" parts-re "\\)"
5361 " *\\["
5362 (regexp-quote
5363 (substring
5364 (format-time-string
5365 (car org-time-stamp-formats)
5366 (apply 'encode-time ; DATE bound by calendar
5367 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5368 1 11))))
5369 (org-agenda-search-headline-for-time nil)
5370 marker hdmarker priority category category-pos tags closedp
5371 statep clockp state ee txt extra timestr rest clocked)
5372 (goto-char (point-min))
5373 (while (re-search-forward regexp nil t)
5374 (catch :skip
5375 (org-agenda-skip)
5376 (setq marker (org-agenda-new-marker (match-beginning 0))
5377 closedp (equal (match-string 1) org-closed-string)
5378 statep (equal (string-to-char (match-string 1)) ?-)
5379 clockp (not (or closedp statep))
5380 state (and statep (match-string 2))
5381 category (org-get-category (match-beginning 0))
5382 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5383 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5384 (when (string-match "\\]" timestr)
5385 ;; substring should only run to end of time stamp
5386 (setq rest (substring timestr (match-end 0))
5387 timestr (substring timestr 0 (match-end 0)))
5388 (if (and (not closedp) (not statep)
5389 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5390 rest))
5391 (progn (setq timestr (concat (substring timestr 0 -1)
5392 "-" (match-string 1 rest) "]"))
5393 (setq clocked (match-string 2 rest)))
5394 (setq clocked "-")))
5395 (save-excursion
5396 (setq extra
5397 (cond
5398 ((not org-agenda-log-mode-add-notes) nil)
5399 (statep
5400 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5401 (match-string 1)))
5402 (clockp
5403 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5404 (match-string 1)))))
5405 (if (not (re-search-backward org-outline-regexp-bol nil t))
5406 (setq txt org-agenda-no-heading-message)
5407 (goto-char (match-beginning 0))
5408 (setq hdmarker (org-agenda-new-marker)
5409 tags (org-get-tags-at))
5410 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5411 (setq txt (match-string 1))
5412 (when extra
5413 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5414 (setq txt (concat (substring txt 0 (match-beginning 1))
5415 " - " extra " " (match-string 2 txt)))
5416 (setq txt (concat txt " - " extra))))
5417 (setq txt (org-agenda-format-item
5418 (cond
5419 (closedp "Closed: ")
5420 (statep (concat "State: (" state ")"))
5421 (t (concat "Clocked: (" clocked ")")))
5422 txt category tags timestr)))
5423 (setq priority 100000)
5424 (org-add-props txt props
5425 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5426 'priority priority 'org-category category
5427 'org-category-position category-pos
5428 'type "closed" 'date date
5429 'undone-face 'org-warning 'done-face 'org-agenda-done)
5430 (push txt ee))
5431 (goto-char (point-at-eol))))
5432 (nreverse ee)))
5434 (defun org-agenda-show-clocking-issues ()
5435 "Add overlays, showing issues with clocking.
5436 See also the user option `org-agenda-clock-consistency-checks'."
5437 (interactive)
5438 (let* ((pl org-agenda-clock-consistency-checks)
5439 (re (concat "^[ \t]*"
5440 org-clock-string
5441 "[ \t]+"
5442 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5443 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5444 (tlstart 0.)
5445 (tlend 0.)
5446 (maxtime (org-hh:mm-string-to-minutes
5447 (or (plist-get pl :max-duration) "24:00")))
5448 (mintime (org-hh:mm-string-to-minutes
5449 (or (plist-get pl :min-duration) 0)))
5450 (maxgap (org-hh:mm-string-to-minutes
5451 ;; default 30:00 means never complain
5452 (or (plist-get pl :max-gap) "30:00")))
5453 (gapok (mapcar 'org-hh:mm-string-to-minutes
5454 (plist-get pl :gap-ok-around)))
5455 (def-face (or (plist-get pl :default-face)
5456 '((:background "DarkRed") (:foreground "white"))))
5457 issue face m te ts dt ov)
5458 (goto-char (point-min))
5459 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5460 (setq issue nil face def-face)
5461 (catch 'next
5462 (setq m (org-get-at-bol 'org-marker)
5463 te nil ts nil)
5464 (unless (and m (markerp m))
5465 (setq issue "No valid clock line") (throw 'next t))
5466 (org-with-point-at m
5467 (save-excursion
5468 (goto-char (point-at-bol))
5469 (unless (looking-at re)
5470 (error "No valid Clock line")
5471 (throw 'next t))
5472 (unless (match-end 3)
5473 (setq issue "No end time"
5474 face (or (plist-get pl :no-end-time-face) face))
5475 (throw 'next t))
5476 (setq ts (match-string 1)
5477 te (match-string 3)
5478 ts (org-float-time
5479 (apply 'encode-time (org-parse-time-string ts)))
5480 te (org-float-time
5481 (apply 'encode-time (org-parse-time-string te)))
5482 dt (- te ts))))
5483 (cond
5484 ((> dt (* 60 maxtime))
5485 ;; a very long clocking chunk
5486 (setq issue (format "Clocking interval is very long: %s"
5487 (org-minutes-to-hh:mm-string
5488 (floor (/ (float dt) 60.))))
5489 face (or (plist-get pl :long-face) face)))
5490 ((< dt (* 60 mintime))
5491 ;; a very short clocking chunk
5492 (setq issue (format "Clocking interval is very short: %s"
5493 (org-minutes-to-hh:mm-string
5494 (floor (/ (float dt) 60.))))
5495 face (or (plist-get pl :short-face) face)))
5496 ((and (> tlend 0) (< ts tlend))
5497 ;; Two clock entries are overlapping
5498 (setq issue (format "Clocking overlap: %d minutes"
5499 (/ (- tlend ts) 60))
5500 face (or (plist-get pl :overlap-face) face)))
5501 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5502 ;; There is a gap, lets see if we need to report it
5503 (unless (org-agenda-check-clock-gap tlend ts gapok)
5504 (setq issue (format "Clocking gap: %d minutes"
5505 (/ (- ts tlend) 60))
5506 face (or (plist-get pl :gap-face) face))))
5507 (t nil)))
5508 (setq tlend (or te tlend) tlstart (or ts tlstart))
5509 (when issue
5510 ;; OK, there was some issue, add an overlay to show the issue
5511 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5512 (overlay-put ov 'before-string
5513 (concat
5514 (org-add-props
5515 (format "%-43s" (concat " " issue))
5517 'face face)
5518 "\n"))
5519 (overlay-put ov 'evaporate t)))))
5521 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5522 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5523 (catch 'exit
5524 (unless ok-list
5525 ;; there are no OK times for gaps...
5526 (throw 'exit nil))
5527 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5528 ;; This is more than 24 hours, so it is OK.
5529 ;; because we have at least one OK time, that must be in the
5530 ;; 24 hour interval.
5531 (throw 'exit t))
5532 ;; We have a shorter gap.
5533 ;; Now we have to get the minute of the day when these times are
5534 (let* ((t1dec (decode-time (seconds-to-time t1)))
5535 (t2dec (decode-time (seconds-to-time t2)))
5536 ;; compute the minute on the day
5537 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5538 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5539 (when (< min2 min1)
5540 ;; if min2 is smaller than min1, this means it is on the next day.
5541 ;; Wrap it to after midnight.
5542 (setq min2 (+ min2 1440)))
5543 ;; Now check if any of the OK times is in the gap
5544 (mapc (lambda (x)
5545 ;; Wrap the time to after midnight if necessary
5546 (if (< x min1) (setq x (+ x 1440)))
5547 ;; Check if in interval
5548 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5549 ok-list)
5550 ;; Nope, this gap is not OK
5551 nil)))
5553 (defun org-agenda-get-deadlines ()
5554 "Return the deadline information for agenda display."
5555 (let* ((props (list 'mouse-face 'highlight
5556 'org-not-done-regexp org-not-done-regexp
5557 'org-todo-regexp org-todo-regexp
5558 'org-complex-heading-regexp org-complex-heading-regexp
5559 'help-echo
5560 (format "mouse-2 or RET jump to org file %s"
5561 (abbreviate-file-name buffer-file-name))))
5562 (regexp org-deadline-time-regexp)
5563 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5564 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5565 d2 diff dfrac wdays pos pos1 category category-pos
5566 tags suppress-prewarning ee txt head face s todo-state
5567 show-all upcomingp donep timestr warntime)
5568 (goto-char (point-min))
5569 (while (re-search-forward regexp nil t)
5570 (setq suppress-prewarning nil)
5571 (catch :skip
5572 (org-agenda-skip)
5573 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5574 (save-match-data
5575 (string-match org-scheduled-time-regexp
5576 (buffer-substring (point-at-bol)
5577 (point-at-eol)))))
5578 (setq suppress-prewarning
5579 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5580 org-agenda-skip-deadline-prewarning-if-scheduled
5581 0)))
5582 (setq s (match-string 1)
5583 txt nil
5584 pos (1- (match-beginning 1))
5585 todo-state (save-match-data (org-get-todo-state))
5586 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5587 (member todo-state
5588 org-agenda-repeating-timestamp-show-all))
5589 d2 (org-time-string-to-absolute
5590 (match-string 1) d1 'past show-all
5591 (current-buffer) pos)
5592 diff (- d2 d1)
5593 wdays (if suppress-prewarning
5594 (let ((org-deadline-warning-days suppress-prewarning))
5595 (org-get-wdays s))
5596 (org-get-wdays s))
5597 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5598 upcomingp (and todayp (> diff 0)))
5599 ;; When to show a deadline in the calendar:
5600 ;; If the expiration is within wdays warning time.
5601 ;; Past-due deadlines are only shown on the current date
5602 (if (and (or (and (<= diff wdays)
5603 (and todayp (not org-agenda-only-exact-dates)))
5604 (= diff 0)))
5605 (save-excursion
5606 ;; (setq todo-state (org-get-todo-state))
5607 (setq donep (member todo-state org-done-keywords))
5608 (if (and donep
5609 (or org-agenda-skip-deadline-if-done
5610 (not (= diff 0))))
5611 (setq txt nil)
5612 (setq category (org-get-category)
5613 warntime (org-entry-get (point) "APPT_WARNTIME")
5614 category-pos (get-text-property (point) 'org-category-position))
5615 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5616 (setq txt org-agenda-no-heading-message)
5617 (goto-char (match-end 0))
5618 (setq pos1 (match-beginning 0))
5619 (setq tags (org-get-tags-at pos1))
5620 (setq head (buffer-substring-no-properties
5621 (point)
5622 (progn (skip-chars-forward "^\r\n")
5623 (point))))
5624 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5625 (setq timestr
5626 (concat (substring s (match-beginning 1)) " "))
5627 (setq timestr 'time))
5628 (setq txt (org-agenda-format-item
5629 (if (= diff 0)
5630 (car org-agenda-deadline-leaders)
5631 (if (functionp
5632 (nth 1 org-agenda-deadline-leaders))
5633 (funcall
5634 (nth 1 org-agenda-deadline-leaders)
5635 diff date)
5636 (format (nth 1 org-agenda-deadline-leaders)
5637 diff)))
5638 head category tags
5639 (if (not (= diff 0)) nil timestr)))))
5640 (when txt
5641 (setq face (org-agenda-deadline-face dfrac))
5642 (org-add-props txt props
5643 'org-marker (org-agenda-new-marker pos)
5644 'warntime warntime
5645 'org-hd-marker (org-agenda-new-marker pos1)
5646 'priority (+ (- diff)
5647 (org-get-priority txt))
5648 'org-category category
5649 'org-category-position category-pos
5650 'todo-state todo-state
5651 'type (if upcomingp "upcoming-deadline" "deadline")
5652 'date (if upcomingp date d2)
5653 'face (if donep 'org-agenda-done face)
5654 'undone-face face 'done-face 'org-agenda-done)
5655 (push txt ee))))))
5656 (nreverse ee)))
5658 (defun org-agenda-deadline-face (fraction)
5659 "Return the face to displaying a deadline item.
5660 FRACTION is what fraction of the head-warning time has passed."
5661 (let ((faces org-agenda-deadline-faces) f)
5662 (catch 'exit
5663 (while (setq f (pop faces))
5664 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5666 (defun org-agenda-get-scheduled (&optional deadline-results)
5667 "Return the scheduled information for agenda display."
5668 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5669 'org-todo-regexp org-todo-regexp
5670 'org-complex-heading-regexp org-complex-heading-regexp
5671 'done-face 'org-agenda-done
5672 'mouse-face 'highlight
5673 'help-echo
5674 (format "mouse-2 or RET jump to org file %s"
5675 (abbreviate-file-name buffer-file-name))))
5676 (regexp org-scheduled-time-regexp)
5677 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5678 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5680 (deadline-position-alist
5681 (mapcar (lambda (a) (and (setq mm (get-text-property
5682 0 'org-hd-marker a))
5683 (cons (marker-position mm) a)))
5684 deadline-results))
5685 d2 diff pos pos1 category category-pos tags donep
5686 ee txt head pastschedp todo-state face timestr s habitp show-all
5687 did-habit-check-p warntime)
5688 (goto-char (point-min))
5689 (while (re-search-forward regexp nil t)
5690 (catch :skip
5691 (org-agenda-skip)
5692 (setq s (match-string 1)
5693 txt nil
5694 pos (1- (match-beginning 1))
5695 todo-state (save-match-data (org-get-todo-state))
5696 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5697 (member todo-state
5698 org-agenda-repeating-timestamp-show-all))
5699 d2 (org-time-string-to-absolute
5700 (match-string 1) d1 'past show-all
5701 (current-buffer) pos)
5702 diff (- d2 d1)
5703 warntime (org-entry-get (point) "APPT_WARNTIME"))
5704 (setq pastschedp (and todayp (< diff 0)))
5705 (setq did-habit-check-p nil)
5706 ;; When to show a scheduled item in the calendar:
5707 ;; If it is on or past the date.
5708 (when (or (and (< diff 0)
5709 (< (abs diff) org-scheduled-past-days)
5710 (and todayp (not org-agenda-only-exact-dates)))
5711 (= diff 0)
5712 ;; org-is-habit-p uses org-entry-get, which is expansive
5713 ;; so we go extra mile to only call it once
5714 (and todayp
5715 (boundp 'org-habit-show-all-today)
5716 org-habit-show-all-today
5717 (setq did-habit-check-p t)
5718 (setq habitp (and (functionp 'org-is-habit-p)
5719 (org-is-habit-p)))))
5720 (save-excursion
5721 (setq donep (member todo-state org-done-keywords))
5722 (if (and donep
5723 (or org-agenda-skip-scheduled-if-done
5724 (not (= diff 0))
5725 (and (functionp 'org-is-habit-p)
5726 (org-is-habit-p))))
5727 (setq txt nil)
5728 (setq habitp (if did-habit-check-p habitp
5729 (and (functionp 'org-is-habit-p)
5730 (org-is-habit-p))))
5731 (setq category (org-get-category)
5732 category-pos (get-text-property (point) 'org-category-position))
5733 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5734 (setq txt org-agenda-no-heading-message)
5735 (goto-char (match-end 0))
5736 (setq pos1 (match-beginning 0))
5737 (if habitp
5738 (if (or (not org-habit-show-habits)
5739 (and (not todayp)
5740 (boundp 'org-habit-show-habits-only-for-today)
5741 org-habit-show-habits-only-for-today))
5742 (throw :skip nil))
5743 (if (and
5744 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5745 (and org-agenda-skip-scheduled-if-deadline-is-shown
5746 pastschedp))
5747 (setq mm (assoc pos1 deadline-position-alist)))
5748 (throw :skip nil)))
5749 (setq tags (org-get-tags-at))
5750 (setq head (buffer-substring-no-properties
5751 (point)
5752 (progn (skip-chars-forward "^\r\n") (point))))
5753 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5754 (setq timestr
5755 (concat (substring s (match-beginning 1)) " "))
5756 (setq timestr 'time))
5757 (setq txt (org-agenda-format-item
5758 (if (= diff 0)
5759 (car org-agenda-scheduled-leaders)
5760 (format (nth 1 org-agenda-scheduled-leaders)
5761 (- 1 diff)))
5762 head category tags
5763 (if (not (= diff 0)) nil timestr)
5764 nil habitp))))
5765 (when txt
5766 (setq face
5767 (cond
5768 ((and (not habitp) pastschedp)
5769 'org-scheduled-previously)
5770 (todayp 'org-scheduled-today)
5771 (t 'org-scheduled))
5772 habitp (and habitp (org-habit-parse-todo)))
5773 (org-add-props txt props
5774 'undone-face face
5775 'face (if donep 'org-agenda-done face)
5776 'org-marker (org-agenda-new-marker pos)
5777 'org-hd-marker (org-agenda-new-marker pos1)
5778 'type (if pastschedp "past-scheduled" "scheduled")
5779 'date (if pastschedp d2 date)
5780 'warntime warntime
5781 'priority (if habitp
5782 (org-habit-get-priority habitp)
5783 (+ 94 (- 5 diff) (org-get-priority txt)))
5784 'org-category category
5785 'category-position category-pos
5786 'org-habit-p habitp
5787 'todo-state todo-state)
5788 (push txt ee))))))
5789 (nreverse ee)))
5791 (defun org-agenda-get-blocks ()
5792 "Return the date-range information for agenda display."
5793 (let* ((props (list 'face nil
5794 'org-not-done-regexp org-not-done-regexp
5795 'org-todo-regexp org-todo-regexp
5796 'org-complex-heading-regexp org-complex-heading-regexp
5797 'mouse-face 'highlight
5798 'help-echo
5799 (format "mouse-2 or RET jump to org file %s"
5800 (abbreviate-file-name buffer-file-name))))
5801 (regexp org-tr-regexp)
5802 (d0 (calendar-absolute-from-gregorian date))
5803 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
5804 todo-state tags pos head donep)
5805 (goto-char (point-min))
5806 (while (re-search-forward regexp nil t)
5807 (catch :skip
5808 (org-agenda-skip)
5809 (setq pos (point))
5810 (let ((start-time (match-string 1))
5811 (end-time (match-string 2)))
5812 (setq s1 (match-string 1)
5813 s2 (match-string 2)
5814 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5815 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5816 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5817 ;; Only allow days between the limits, because the normal
5818 ;; date stamps will catch the limits.
5819 (save-excursion
5820 (setq todo-state (org-get-todo-state))
5821 (setq donep (member todo-state org-done-keywords))
5822 (if (and donep org-agenda-skip-timestamp-if-done)
5823 (throw :skip t))
5824 (setq marker (org-agenda-new-marker (point)))
5825 (setq category (org-get-category)
5826 category-pos (get-text-property (point) 'org-category-position))
5827 (if (not (re-search-backward org-outline-regexp-bol nil t))
5828 (setq txt org-agenda-no-heading-message)
5829 (goto-char (match-beginning 0))
5830 (setq hdmarker (org-agenda-new-marker (point)))
5831 (setq tags (org-get-tags-at))
5832 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5833 (setq head (match-string 1))
5834 (let ((remove-re
5835 (if org-agenda-remove-timeranges-from-blocks
5836 (concat
5837 "<" (regexp-quote s1) ".*?>"
5838 "--"
5839 "<" (regexp-quote s2) ".*?>")
5840 nil)))
5841 (setq txt (org-agenda-format-item
5842 (format
5843 (nth (if (= d1 d2) 0 1)
5844 org-agenda-timerange-leaders)
5845 (1+ (- d0 d1)) (1+ (- d2 d1)))
5846 head category tags
5847 (cond ((and (= d1 d0) (= d2 d0))
5848 (concat "<" start-time ">--<" end-time ">"))
5849 ((= d1 d0)
5850 (concat "<" start-time ">"))
5851 ((= d2 d0)
5852 (concat "<" end-time ">")))
5853 remove-re))))
5854 (org-add-props txt props
5855 'org-marker marker 'org-hd-marker hdmarker
5856 'type "block" 'date date
5857 'todo-state todo-state
5858 'priority (org-get-priority txt) 'org-category category
5859 'org-category-position category-pos)
5860 (push txt ee))))
5861 (goto-char pos)))
5862 ;; Sort the entries by expiration date.
5863 (nreverse ee)))
5865 ;;; Agenda presentation and sorting
5867 (defvar org-prefix-has-time nil
5868 "A flag, set by `org-compile-prefix-format'.
5869 The flag is set if the currently compiled format contains a `%t'.")
5870 (defvar org-prefix-has-tag nil
5871 "A flag, set by `org-compile-prefix-format'.
5872 The flag is set if the currently compiled format contains a `%T'.")
5873 (defvar org-prefix-has-effort nil
5874 "A flag, set by `org-compile-prefix-format'.
5875 The flag is set if the currently compiled format contains a `%e'.")
5876 (defvar org-prefix-category-length nil
5877 "Used by `org-compile-prefix-format' to remember the category field width.")
5878 (defvar org-prefix-category-max-length nil
5879 "Used by `org-compile-prefix-format' to remember the category field width.")
5881 (defun org-agenda-get-category-icon (category)
5882 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5883 (dolist (entry org-agenda-category-icon-alist)
5884 (when (org-string-match-p (car entry) category)
5885 (if (listp (cadr entry))
5886 (return (cadr entry))
5887 (return (apply 'create-image (cdr entry)))))))
5889 (defun org-agenda-format-item (extra txt &optional category tags dotime
5890 remove-re habitp)
5891 "Format TXT to be inserted into the agenda buffer.
5892 In particular, it adds the prefix and corresponding text properties. EXTRA
5893 must be a string and replaces the `%s' specifier in the prefix format.
5894 CATEGORY (string, symbol or nil) may be used to overrule the default
5895 category taken from local variable or file name. It will replace the `%c'
5896 specifier in the format. DOTIME, when non-nil, indicates that a
5897 time-of-day should be extracted from TXT for sorting of this entry, and for
5898 the `%t' specifier in the format. When DOTIME is a string, this string is
5899 searched for a time before TXT is. TAGS can be the tags of the headline.
5900 Any match of REMOVE-RE will be removed from TXT."
5901 ;; We keep the org-prefix-* variable values along with a compiled
5902 ;; formatter, so that multiple agendas existing at the same time, do
5903 ;; not step on each other toes.
5905 ;; It was inconvenient to make these variables buffer local in
5906 ;; Agenda buffers, because this function expects to be called with
5907 ;; the buffer where item comes from being current, and not agenda
5908 ;; buffer
5909 (let* ((bindings (car org-prefix-format-compiled))
5910 (formatter (cadr org-prefix-format-compiled)))
5911 (loop for (var value) in bindings
5912 do (set var value))
5913 (save-match-data
5914 ;; Diary entries sometimes have extra whitespace at the beginning
5915 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5917 ;; Fix the tags part in txt
5918 (setq txt (org-agenda-fix-displayed-tags
5919 txt tags
5920 org-agenda-show-inherited-tags
5921 org-agenda-hide-tags-regexp))
5922 (let* ((category (or category
5923 (if (stringp org-category)
5924 org-category
5925 (and org-category (symbol-name org-category)))
5926 (if buffer-file-name
5927 (file-name-sans-extension
5928 (file-name-nondirectory buffer-file-name))
5929 "")))
5930 (category-icon (org-agenda-get-category-icon category))
5931 (category-icon (if category-icon
5932 (propertize " " 'display category-icon)
5933 ""))
5934 ;; time, tag, effort are needed for the eval of the prefix format
5935 (tag (if tags (nth (1- (length tags)) tags) ""))
5936 time effort neffort
5937 (ts (if dotime (concat
5938 (if (stringp dotime) dotime "")
5939 (and org-agenda-search-headline-for-time txt))))
5940 (time-of-day (and dotime (org-get-time-of-day ts)))
5941 stamp plain s0 s1 s2 rtn srp l
5942 duration thecategory)
5943 (and (derived-mode-p 'org-mode) buffer-file-name
5944 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5945 (when (and dotime time-of-day)
5946 ;; Extract starting and ending time and move them to prefix
5947 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5948 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5949 (setq s0 (match-string 0 ts)
5950 srp (and stamp (match-end 3))
5951 s1 (match-string (if plain 1 2) ts)
5952 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5954 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5955 ;; them, we might want to remove them there to avoid duplication.
5956 ;; The user can turn this off with a variable.
5957 (if (and org-prefix-has-time
5958 org-agenda-remove-times-when-in-prefix (or stamp plain)
5959 (string-match (concat (regexp-quote s0) " *") txt)
5960 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5961 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5962 (= (match-beginning 0) 0)
5964 (setq txt (replace-match "" nil nil txt))))
5965 ;; Normalize the time(s) to 24 hour
5966 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5967 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5969 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5970 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5971 (setq s2
5972 (org-minutes-to-hh:mm-string
5973 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5975 ;; Compute the duration
5976 (when s2
5977 (setq duration (- (org-hh:mm-string-to-minutes s2)
5978 (org-hh:mm-string-to-minutes s1)))))
5980 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5981 txt)
5982 ;; Tags are in the string
5983 (if (or (eq org-agenda-remove-tags t)
5984 (and org-agenda-remove-tags
5985 org-prefix-has-tag))
5986 (setq txt (replace-match "" t t txt))
5987 (setq txt (replace-match
5988 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5989 (match-string 2 txt))
5990 t t txt))))
5991 (when (derived-mode-p 'org-mode)
5992 (setq effort
5993 (condition-case nil
5994 (org-get-effort
5995 (or (get-text-property 0 'org-hd-marker txt)
5996 (get-text-property 0 'org-marker txt)))
5997 (error nil)))
5998 (when effort
5999 (setq neffort (org-duration-string-to-minutes effort)
6000 effort (setq effort (concat "[" effort "]")))))
6001 ;; prevent erroring out with %e format when there is no effort
6002 (or effort (setq effort ""))
6004 (when remove-re
6005 (while (string-match remove-re txt)
6006 (setq txt (replace-match "" t t txt))))
6008 ;; Set org-heading property on `txt' to mark the start of the
6009 ;; heading.
6010 (add-text-properties 0 (length txt) '(org-heading t) txt)
6012 ;; Prepare the variables needed in the eval of the compiled format
6013 (setq time (cond (s2 (concat
6014 (org-agenda-time-of-day-to-ampm-maybe s1)
6015 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6016 (if org-agenda-timegrid-use-ampm " ")))
6017 (s1 (concat
6018 (org-agenda-time-of-day-to-ampm-maybe s1)
6019 (if org-agenda-timegrid-use-ampm
6020 "........ "
6021 "......")))
6022 (t ""))
6023 extra (or (and (not habitp) extra) "")
6024 category (if (symbolp category) (symbol-name category) category)
6025 thecategory (copy-sequence category))
6026 (if (string-match org-bracket-link-regexp category)
6027 (progn
6028 (setq l (if (match-end 3)
6029 (- (match-end 3) (match-beginning 3))
6030 (- (match-end 1) (match-beginning 1))))
6031 (when (< l (or org-prefix-category-length 0))
6032 (setq category (copy-sequence category))
6033 (org-add-props category nil
6034 'extra-space (make-string
6035 (- org-prefix-category-length l 1) ?\ ))))
6036 (if (and org-prefix-category-max-length
6037 (>= (length category) org-prefix-category-max-length))
6038 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6039 ;; Evaluate the compiled format
6040 (setq rtn (concat (eval formatter) txt))
6042 ;; And finally add the text properties
6043 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6044 (org-add-props rtn nil
6045 'org-category (if thecategory (downcase thecategory) category)
6046 'tags (mapcar 'org-downcase-keep-props tags)
6047 'org-highest-priority org-highest-priority
6048 'org-lowest-priority org-lowest-priority
6049 'time-of-day time-of-day
6050 'duration duration
6051 'effort effort
6052 'effort-minutes neffort
6053 'txt txt
6054 'time time
6055 'extra extra
6056 'format org-prefix-format-compiled
6057 'dotime dotime)))))
6059 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6060 "Remove tags string from TXT, and add a modified list of tags.
6061 The modified list may contain inherited tags, and tags matched by
6062 `org-agenda-hide-tags-regexp' will be removed."
6063 (when (or add-inherited hide-re)
6064 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6065 (setq txt (substring txt 0 (match-beginning 0))))
6066 (setq tags
6067 (delq nil
6068 (mapcar (lambda (tg)
6069 (if (or (and hide-re (string-match hide-re tg))
6070 (and (not add-inherited)
6071 (get-text-property 0 'inherited tg)))
6073 tg))
6074 tags)))
6075 (when tags
6076 (let ((have-i (get-text-property 0 'inherited (car tags)))
6078 (setq txt (concat txt " :"
6079 (mapconcat
6080 (lambda (x)
6081 (setq i (get-text-property 0 'inherited x))
6082 (if (and have-i (not i))
6083 (progn
6084 (setq have-i nil)
6085 (concat ":" x))
6087 tags ":")
6088 (if have-i "::" ":"))))))
6089 txt)
6091 (defun org-downcase-keep-props (s)
6092 (let ((props (text-properties-at 0 s)))
6093 (setq s (downcase s))
6094 (add-text-properties 0 (length s) props s)
6097 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6098 (defvar org-agenda-sorting-strategy-selected nil)
6100 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6101 (catch 'exit
6102 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6103 ((and todayp (member 'today (car org-agenda-time-grid))))
6104 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6105 ((member 'weekly (car org-agenda-time-grid)))
6106 (t (throw 'exit list)))
6107 (let* ((have (delq nil (mapcar
6108 (lambda (x) (get-text-property 1 'time-of-day x))
6109 list)))
6110 (string (nth 1 org-agenda-time-grid))
6111 (gridtimes (nth 2 org-agenda-time-grid))
6112 (req (car org-agenda-time-grid))
6113 (remove (member 'remove-match req))
6114 new time)
6115 (if (and (member 'require-timed req) (not have))
6116 ;; don't show empty grid
6117 (throw 'exit list))
6118 (while (setq time (pop gridtimes))
6119 (unless (and remove (member time have))
6120 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6121 (push (org-agenda-format-item
6122 nil string "" nil
6123 (concat (substring time 0 -2) ":" (substring time -2)))
6124 new)
6125 (put-text-property
6126 2 (length (car new)) 'face 'org-time-grid (car new))))
6127 (when (and todayp org-agenda-show-current-time-in-grid)
6128 (push (org-agenda-format-item
6130 org-agenda-current-time-string
6131 "" nil
6132 (format-time-string "%H:%M "))
6133 new)
6134 (put-text-property
6135 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6137 (if (member 'time-up org-agenda-sorting-strategy-selected)
6138 (append new list)
6139 (append list new)))))
6141 (defun org-compile-prefix-format (key)
6142 "Compile the prefix format into a Lisp form that can be evaluated.
6143 The resulting form and associated variable bindings is returned
6144 and stored in the variable `org-prefix-format-compiled'."
6145 (setq org-prefix-has-time nil org-prefix-has-tag nil
6146 org-prefix-category-length nil
6147 org-prefix-has-effort nil)
6148 (let ((s (cond
6149 ((stringp org-agenda-prefix-format)
6150 org-agenda-prefix-format)
6151 ((assq key org-agenda-prefix-format)
6152 (cdr (assq key org-agenda-prefix-format)))
6153 (t " %-12:c%?-12t% s")))
6154 (start 0)
6155 varform vars var e c f opt)
6156 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6157 s start)
6158 (setq var (or (cdr (assoc (match-string 4 s)
6159 '(("c" . category) ("t" . time) ("s" . extra)
6160 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6161 'eval)
6162 c (or (match-string 3 s) "")
6163 opt (match-beginning 1)
6164 start (1+ (match-beginning 0)))
6165 (if (equal var 'time) (setq org-prefix-has-time t))
6166 (if (equal var 'tag) (setq org-prefix-has-tag t))
6167 (if (equal var 'effort) (setq org-prefix-has-effort t))
6168 (setq f (concat "%" (match-string 2 s) "s"))
6169 (when (equal var 'category)
6170 (setq org-prefix-category-length
6171 (floor (abs (string-to-number (match-string 2 s)))))
6172 (setq org-prefix-category-max-length
6173 (let ((x (match-string 2 s)))
6174 (save-match-data
6175 (if (string-match "\\.[0-9]+" x)
6176 (string-to-number (substring (match-string 0 x) 1)))))))
6177 (if (eq var 'eval)
6178 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6179 (if opt
6180 (setq varform
6181 `(if (equal "" ,var)
6183 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6184 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6185 (setq s (replace-match "%s" t nil s))
6186 (push varform vars))
6187 (setq vars (nreverse vars))
6188 (with-current-buffer (or org-agenda-buffer (current-buffer))
6189 (setq org-prefix-format-compiled
6190 (list
6191 `((org-prefix-has-time ,org-prefix-has-time)
6192 (org-prefix-has-tag ,org-prefix-has-tag)
6193 (org-prefix-category-length ,org-prefix-category-length)
6194 (org-prefix-has-effort ,org-prefix-has-effort))
6195 `(format ,s ,@vars))))))
6197 (defun org-set-sorting-strategy (key)
6198 (if (symbolp (car org-agenda-sorting-strategy))
6199 ;; the old format
6200 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6201 (setq org-agenda-sorting-strategy-selected
6202 (or (cdr (assq key org-agenda-sorting-strategy))
6203 (cdr (assq 'agenda org-agenda-sorting-strategy))
6204 '(time-up category-keep priority-down)))))
6206 (defun org-get-time-of-day (s &optional string mod24)
6207 "Check string S for a time of day.
6208 If found, return it as a military time number between 0 and 2400.
6209 If not found, return nil.
6210 The optional STRING argument forces conversion into a 5 character wide string
6211 HH:MM."
6212 (save-match-data
6213 (when
6214 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6215 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6216 (let* ((h (string-to-number (match-string 1 s)))
6217 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6218 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6219 (am-p (equal ampm "am"))
6220 (h1 (cond ((not ampm) h)
6221 ((= h 12) (if am-p 0 12))
6222 (t (+ h (if am-p 0 12)))))
6223 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6224 (mod h1 24) h1))
6225 (t0 (+ (* 100 h2) m))
6226 (t1 (concat (if (>= h1 24) "+" " ")
6227 (if (and org-agenda-time-leading-zero
6228 (< t0 1000)) "0" "")
6229 (if (< t0 100) "0" "")
6230 (if (< t0 10) "0" "")
6231 (int-to-string t0))))
6232 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6234 (defvar org-agenda-before-sorting-filter-function nil
6235 "Function to be applied to agenda items prior to sorting.
6236 Prior to sorting also means just before they are inserted into the agenda.
6238 To aid sorting, you may revisit the original entries and add more text
6239 properties which will later be used by the sorting functions.
6241 The function should take a string argument, an agenda line.
6242 It has access to the text properties in that line, which contain among
6243 other things, the property `org-hd-marker' that points to the entry
6244 where the line comes from. Note that not all lines going into the agenda
6245 have this property, only most.
6247 The function should return the modified string. It is probably best
6248 to ONLY change text properties.
6250 You can also use this function as a filter, by returning nil for lines
6251 you don't want to have in the agenda at all. For this application, you
6252 could bind the variable in the options section of a custom command.")
6254 (defun org-agenda-finalize-entries (list &optional nosort)
6255 "Sort and concatenate the agenda items."
6256 (setq list (mapcar 'org-agenda-highlight-todo list))
6257 (if nosort
6258 list
6259 (when org-agenda-before-sorting-filter-function
6260 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6261 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6263 (defun org-agenda-highlight-todo (x)
6264 (let ((org-done-keywords org-done-keywords-for-agenda)
6265 (case-fold-search nil)
6267 (if (eq x 'line)
6268 (save-excursion
6269 (beginning-of-line 1)
6270 (setq re (org-get-at-bol 'org-todo-regexp))
6271 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6272 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6273 (add-text-properties (match-beginning 0) (match-end 1)
6274 (list 'face (org-get-todo-face 1)))
6275 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6276 (delete-region (match-beginning 1) (1- (match-end 0)))
6277 (goto-char (match-beginning 1))
6278 (insert (format org-agenda-todo-keyword-format s)))))
6279 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6280 (setq re (get-text-property 0 'org-todo-regexp x))
6281 (when (and re
6282 ;; Test `pl' because if there's no heading content,
6283 ;; there's no point matching to highlight. Note
6284 ;; that if we didn't test `pl' first, and there
6285 ;; happened to be no keyword from `org-todo-regexp'
6286 ;; on this heading line, then the `equal' comparison
6287 ;; afterwards would spuriously succeed in the case
6288 ;; where `pl' is nil -- causing an args-out-of-range
6289 ;; error when we try to add text properties to text
6290 ;; that isn't there.
6292 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6293 x pl) pl))
6294 (add-text-properties
6295 (or (match-end 1) (match-end 0)) (match-end 0)
6296 (list 'face (org-get-todo-face (match-string 2 x)))
6298 (when (match-end 1)
6299 (setq x (concat (substring x 0 (match-end 1))
6300 (format org-agenda-todo-keyword-format
6301 (match-string 2 x))
6302 (org-add-props " " (text-properties-at 0 x))
6303 (substring x (match-end 3)))))))
6304 x)))
6306 (defsubst org-cmp-priority (a b)
6307 "Compare the priorities of string A and B."
6308 (let ((pa (or (get-text-property 1 'priority a) 0))
6309 (pb (or (get-text-property 1 'priority b) 0)))
6310 (cond ((> pa pb) +1)
6311 ((< pa pb) -1))))
6313 (defsubst org-cmp-effort (a b)
6314 "Compare the effort values of string A and B."
6315 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6316 (ea (or (get-text-property 1 'effort-minutes a) def))
6317 (eb (or (get-text-property 1 'effort-minutes b) def)))
6318 (cond ((> ea eb) +1)
6319 ((< ea eb) -1))))
6321 (defsubst org-cmp-category (a b)
6322 "Compare the string values of categories of strings A and B."
6323 (let ((ca (or (get-text-property 1 'org-category a) ""))
6324 (cb (or (get-text-property 1 'org-category b) "")))
6325 (cond ((string-lessp ca cb) -1)
6326 ((string-lessp cb ca) +1))))
6328 (defsubst org-cmp-todo-state (a b)
6329 "Compare the todo states of strings A and B."
6330 (let* ((ma (or (get-text-property 1 'org-marker a)
6331 (get-text-property 1 'org-hd-marker a)))
6332 (mb (or (get-text-property 1 'org-marker b)
6333 (get-text-property 1 'org-hd-marker b)))
6334 (fa (and ma (marker-buffer ma)))
6335 (fb (and mb (marker-buffer mb)))
6336 (todo-kwds
6337 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6338 (and fb (with-current-buffer fb org-todo-keywords-1))))
6339 (ta (or (get-text-property 1 'todo-state a) ""))
6340 (tb (or (get-text-property 1 'todo-state b) ""))
6341 (la (- (length (member ta todo-kwds))))
6342 (lb (- (length (member tb todo-kwds))))
6343 (donepa (member ta org-done-keywords-for-agenda))
6344 (donepb (member tb org-done-keywords-for-agenda)))
6345 (cond ((and donepa (not donepb)) -1)
6346 ((and (not donepa) donepb) +1)
6347 ((< la lb) -1)
6348 ((< lb la) +1))))
6350 (defsubst org-cmp-alpha (a b)
6351 "Compare the headlines, alphabetically."
6352 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6353 (plb (text-property-any 0 (length b) 'org-heading t b))
6354 (ta (and pla (substring a pla)))
6355 (tb (and plb (substring b plb))))
6356 (when pla
6357 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6358 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6359 (setq ta (substring ta (match-end 0))))
6360 (setq ta (downcase ta)))
6361 (when plb
6362 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6363 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6364 (setq tb (substring tb (match-end 0))))
6365 (setq tb (downcase tb)))
6366 (cond ((not ta) +1)
6367 ((not tb) -1)
6368 ((string-lessp ta tb) -1)
6369 ((string-lessp tb ta) +1))))
6371 (defsubst org-cmp-tag (a b)
6372 "Compare the string values of the first tags of A and B."
6373 (let ((ta (car (last (get-text-property 1 'tags a))))
6374 (tb (car (last (get-text-property 1 'tags b)))))
6375 (cond ((not ta) +1)
6376 ((not tb) -1)
6377 ((string-lessp ta tb) -1)
6378 ((string-lessp tb ta) +1))))
6380 (defsubst org-cmp-time (a b)
6381 "Compare the time-of-day values of strings A and B."
6382 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6383 (ta (or (get-text-property 1 'time-of-day a) def))
6384 (tb (or (get-text-property 1 'time-of-day b) def)))
6385 (cond ((< ta tb) -1)
6386 ((< tb ta) +1))))
6388 (defsubst org-cmp-habit-p (a b)
6389 "Compare the todo states of strings A and B."
6390 (let ((ha (get-text-property 1 'org-habit-p a))
6391 (hb (get-text-property 1 'org-habit-p b)))
6392 (cond ((and ha (not hb)) -1)
6393 ((and (not ha) hb) +1))))
6395 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6397 (defun org-entries-lessp (a b)
6398 "Predicate for sorting agenda entries."
6399 ;; The following variables will be used when the form is evaluated.
6400 ;; So even though the compiler complains, keep them.
6401 (let* ((ss org-agenda-sorting-strategy-selected)
6402 (time-up (and (org-em 'time-up 'time-down ss)
6403 (org-cmp-time a b)))
6404 (time-down (if time-up (- time-up) nil))
6405 (priority-up (and (org-em 'priority-up 'priority-down ss)
6406 (org-cmp-priority a b)))
6407 (priority-down (if priority-up (- priority-up) nil))
6408 (effort-up (and (org-em 'effort-up 'effort-down ss)
6409 (org-cmp-effort a b)))
6410 (effort-down (if effort-up (- effort-up) nil))
6411 (category-up (and (or (org-em 'category-up 'category-down ss)
6412 (memq 'category-keep ss))
6413 (org-cmp-category a b)))
6414 (category-down (if category-up (- category-up) nil))
6415 (category-keep (if category-up +1 nil))
6416 (tag-up (and (org-em 'tag-up 'tag-down ss)
6417 (org-cmp-tag a b)))
6418 (tag-down (if tag-up (- tag-up) nil))
6419 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6420 (org-cmp-todo-state a b)))
6421 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6422 (habit-up (and (org-em 'habit-up 'habit-down ss)
6423 (org-cmp-habit-p a b)))
6424 (habit-down (if habit-up (- habit-up) nil))
6425 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6426 (org-cmp-alpha a b)))
6427 (alpha-down (if alpha-up (- alpha-up) nil))
6428 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6429 user-defined-up user-defined-down)
6430 (if (and need-user-cmp org-agenda-cmp-user-defined
6431 (functionp org-agenda-cmp-user-defined))
6432 (setq user-defined-up
6433 (funcall org-agenda-cmp-user-defined a b)
6434 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6435 (cdr (assoc
6436 (eval (cons 'or org-agenda-sorting-strategy-selected))
6437 '((-1 . t) (1 . nil) (nil . nil))))))
6439 ;;; Agenda restriction lock
6441 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6442 "Overlay to mark the headline to which agenda commands are restricted.")
6443 (overlay-put org-agenda-restriction-lock-overlay
6444 'face 'org-agenda-restriction-lock)
6445 (overlay-put org-agenda-restriction-lock-overlay
6446 'help-echo "Agendas are currently limited to this subtree.")
6447 (org-detach-overlay org-agenda-restriction-lock-overlay)
6449 (defun org-agenda-set-restriction-lock (&optional type)
6450 "Set restriction lock for agenda, to current subtree or file.
6451 Restriction will be the file if TYPE is `file', or if type is the
6452 universal prefix '(4), or if the cursor is before the first headline
6453 in the file. Otherwise, restriction will be to the current subtree."
6454 (interactive "P")
6455 (and (equal type '(4)) (setq type 'file))
6456 (setq type (cond
6457 (type type)
6458 ((org-at-heading-p) 'subtree)
6459 ((condition-case nil (org-back-to-heading t) (error nil))
6460 'subtree)
6461 (t 'file)))
6462 (if (eq type 'subtree)
6463 (progn
6464 (setq org-agenda-restrict t)
6465 (setq org-agenda-overriding-restriction 'subtree)
6466 (put 'org-agenda-files 'org-restrict
6467 (list (buffer-file-name (buffer-base-buffer))))
6468 (org-back-to-heading t)
6469 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6470 (move-marker org-agenda-restrict-begin (point))
6471 (move-marker org-agenda-restrict-end
6472 (save-excursion (org-end-of-subtree t)))
6473 (message "Locking agenda restriction to subtree"))
6474 (put 'org-agenda-files 'org-restrict
6475 (list (buffer-file-name (buffer-base-buffer))))
6476 (setq org-agenda-restrict nil)
6477 (setq org-agenda-overriding-restriction 'file)
6478 (move-marker org-agenda-restrict-begin nil)
6479 (move-marker org-agenda-restrict-end nil)
6480 (message "Locking agenda restriction to file"))
6481 (setq current-prefix-arg nil)
6482 (org-agenda-maybe-redo))
6484 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6485 "Remove the agenda restriction lock."
6486 (interactive "P")
6487 (org-detach-overlay org-agenda-restriction-lock-overlay)
6488 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6489 (setq org-agenda-overriding-restriction nil)
6490 (setq org-agenda-restrict nil)
6491 (put 'org-agenda-files 'org-restrict nil)
6492 (move-marker org-agenda-restrict-begin nil)
6493 (move-marker org-agenda-restrict-end nil)
6494 (setq current-prefix-arg nil)
6495 (message "Agenda restriction lock removed")
6496 (or noupdate (org-agenda-maybe-redo)))
6498 (defun org-agenda-maybe-redo ()
6499 "If there is any window showing the agenda view, update it."
6500 (let ((w (get-buffer-window org-agenda-buffer-name t))
6501 (w0 (selected-window)))
6502 (when w
6503 (select-window w)
6504 (org-agenda-redo)
6505 (select-window w0)
6506 (if org-agenda-overriding-restriction
6507 (message "Agenda view shifted to new %s restriction"
6508 org-agenda-overriding-restriction)
6509 (message "Agenda restriction lock removed")))))
6511 ;;; Agenda commands
6513 (defun org-agenda-check-type (error &rest types)
6514 "Check if agenda buffer is of allowed type.
6515 If ERROR is non-nil, throw an error, otherwise just return nil."
6516 (if (not org-agenda-type)
6517 (error "No Org agenda currently displayed")
6518 (if (memq org-agenda-type types)
6520 (if error
6521 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6522 nil))))
6524 (defun org-agenda-Quit (&optional arg)
6525 "Exit agenda by removing the window or the buffer."
6526 (interactive)
6527 (if org-agenda-columns-active
6528 (org-columns-quit)
6529 (let ((buf (current-buffer)))
6530 (if (eq org-agenda-window-setup 'other-frame)
6531 (progn
6532 (org-agenda-reset-markers)
6533 (kill-buffer buf)
6534 (org-columns-remove-overlays)
6535 (setq org-agenda-archives-mode nil)
6536 (delete-frame))
6537 (and (not (eq org-agenda-window-setup 'current-window))
6538 (not (one-window-p))
6539 (delete-window))
6540 (org-agenda-reset-markers)
6541 (kill-buffer buf)
6542 (org-columns-remove-overlays)
6543 (setq org-agenda-archives-mode nil)))
6544 ;; Maybe restore the pre-agenda window configuration.
6545 (and org-agenda-restore-windows-after-quit
6546 (not (eq org-agenda-window-setup 'other-frame))
6547 org-agenda-pre-window-conf
6548 (set-window-configuration org-agenda-pre-window-conf)
6549 (setq org-agenda-pre-window-conf nil))))
6551 (defun org-agenda-quit ()
6552 "Exit agenda by killing agenda buffer or burying it when
6553 `org-agenda-sticky' is non-NIL"
6554 (interactive)
6555 (if org-agenda-columns-active
6556 (org-columns-quit)
6557 (if org-agenda-sticky
6558 (let ((buf (current-buffer)))
6559 (if (eq org-agenda-window-setup 'other-frame)
6560 (progn
6561 (delete-frame))
6562 (and (not (eq org-agenda-window-setup 'current-window))
6563 (not (one-window-p))
6564 (delete-window)))
6565 (with-current-buffer buf
6566 (bury-buffer)
6567 ;; Maybe restore the pre-agenda window configuration.
6568 (and org-agenda-restore-windows-after-quit
6569 (not (eq org-agenda-window-setup 'other-frame))
6570 org-agenda-pre-window-conf
6571 (set-window-configuration org-agenda-pre-window-conf)
6572 (setq org-agenda-pre-window-conf nil))))
6573 (org-agenda-Quit))))
6575 (defun org-agenda-exit ()
6576 "Exit agenda by removing the window or the buffer.
6577 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6578 Org-mode buffers visited directly by the user will not be touched."
6579 (interactive)
6580 (org-release-buffers org-agenda-new-buffers)
6581 (setq org-agenda-new-buffers nil)
6582 (org-agenda-Quit))
6584 (defun org-agenda-kill-all-agenda-buffers ()
6585 "Kill all buffers in `org-agena-mode'.
6586 This is used when toggling sticky agendas. You can also explicitly invoke it
6587 with `C-c a C-k'."
6588 (interactive)
6589 (let (blist)
6590 (dolist (buf (buffer-list))
6591 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6592 (push buf blist)))
6593 (mapc 'kill-buffer blist)))
6595 (defun org-agenda-execute (arg)
6596 "Execute another agenda command, keeping same window.
6597 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6598 in the agenda."
6599 (interactive "P")
6600 (let ((org-agenda-window-setup 'current-window))
6601 (org-agenda arg)))
6603 (defun org-agenda-redo (&optional all)
6604 "Rebuild possibly ALL agenda view(s) in the current buffer."
6605 (interactive "P")
6606 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6607 (cpa (unless (eq all t) current-prefix-arg))
6608 (org-agenda-doing-sticky-redo org-agenda-sticky)
6609 (org-agenda-sticky nil)
6610 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6611 org-agenda-buffer-name))
6612 (org-agenda-keep-modes t)
6613 (tag-filter org-agenda-tag-filter)
6614 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6615 (top-cat-filter org-agenda-top-category-filter)
6616 (cat-filter org-agenda-category-filter)
6617 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6618 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6619 (cols org-agenda-columns-active)
6620 (line (org-current-line))
6621 (window-line (- line (org-current-line (window-start))))
6622 (lprops (get 'org-agenda-redo-command 'org-lprops))
6623 (redo-cmd (get-text-property p 'org-redo-cmd))
6624 (last-args (get-text-property p 'org-last-args))
6625 (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
6626 (org-agenda-overriding-cmd-arguments
6627 (unless (eq all t)
6628 (cond ((listp last-args)
6629 (cons (or cpa (car last-args)) (cdr last-args)))
6630 ((stringp last-args)
6631 last-args))))
6632 (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
6633 (put 'org-agenda-tag-filter :preset-filter nil)
6634 (put 'org-agenda-category-filter :preset-filter nil)
6635 (and cols (org-columns-quit))
6636 (message "Rebuilding agenda buffer...")
6637 (if serie-redo-cmd
6638 (eval serie-redo-cmd)
6639 (org-let lprops '(eval redo-cmd)))
6640 (setq org-agenda-undo-list nil
6641 org-agenda-pending-undo-list nil)
6642 (message "Rebuilding agenda buffer...done")
6643 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6644 (put 'org-agenda-category-filter :preset-filter cat-preset)
6645 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6646 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6647 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6648 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6649 (org-goto-line line)
6650 (recenter window-line)))
6652 (defvar org-global-tags-completion-table nil)
6653 (defvar org-agenda-filter-form nil)
6654 (defvar org-agenda-filtered-by-category nil)
6656 (defun org-agenda-filter-by-category (strip)
6657 "Keep only those lines in the agenda buffer that have a specific category.
6658 The category is that of the current line."
6659 (interactive "P")
6660 (if (and org-agenda-filtered-by-category
6661 org-agenda-category-filter)
6662 (org-agenda-filter-show-all-cat)
6663 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6664 (if cat (org-agenda-filter-apply
6665 (list (concat (if strip "-" "+") cat)) 'category)
6666 (error "No category at point")))))
6668 (defun org-find-top-category (&optional pos)
6669 (save-excursion
6670 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6671 (if pos (goto-char pos))
6672 ;; Skip up to the topmost parent
6673 (while (ignore-errors (outline-up-heading 1) t))
6674 (ignore-errors
6675 (nth 4 (org-heading-components))))))
6677 (defvar org-agenda-filtered-by-top-category nil)
6679 (defun org-agenda-filter-by-top-category (strip)
6680 "Keep only those lines in the agenda buffer that have a specific category.
6681 The category is that of the current line."
6682 (interactive "P")
6683 (if org-agenda-filtered-by-top-category
6684 (progn
6685 (setq org-agenda-filtered-by-top-category nil
6686 org-agenda-top-category-filter nil)
6687 (org-agenda-filter-show-all-cat))
6688 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6689 (if cat (org-agenda-filter-top-category-apply cat strip)
6690 (error "No top-level category at point")))))
6692 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6693 "Keep only those lines in the agenda buffer that have a specific tag.
6694 The tag is selected with its fast selection letter, as configured.
6695 With prefix argument STRIP, remove all lines that do have the tag.
6696 A lisp caller can specify CHAR. NARROW means that the new tag should be
6697 used to narrow the search - the interactive user can also press `-' or `+'
6698 to switch to narrowing."
6699 (interactive "P")
6700 (let* ((alist org-tag-alist-for-agenda)
6701 (tag-chars (mapconcat
6702 (lambda (x) (if (and (not (symbolp (car x)))
6703 (cdr x))
6704 (char-to-string (cdr x))
6705 ""))
6706 alist ""))
6707 (efforts (org-split-string
6708 (or (cdr (assoc (concat org-effort-property "_ALL")
6709 org-global-properties))
6710 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6711 "")))
6712 (effort-op org-agenda-filter-effort-default-operator)
6713 (effort-prompt "")
6714 (inhibit-read-only t)
6715 (current org-agenda-tag-filter)
6716 maybe-refresh a n tag)
6717 (unless char
6718 (message
6719 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6720 (if narrow "Narrow" "Filter") tag-chars
6721 (if org-agenda-auto-exclude-function "[RET], " ""))
6722 (setq char (read-char-exclusive)))
6723 (when (member char '(?+ ?-))
6724 ;; Narrowing down
6725 (cond ((equal char ?-) (setq strip t narrow t))
6726 ((equal char ?+) (setq strip nil narrow t)))
6727 (message
6728 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6729 (setq char (read-char-exclusive)))
6730 (when (member char '(?< ?> ?= ??))
6731 ;; An effort operator
6732 (setq effort-op (char-to-string char))
6733 (setq alist nil) ; to make sure it will be interpreted as effort.
6734 (unless (equal char ??)
6735 (loop for i from 0 to 9 do
6736 (setq effort-prompt
6737 (concat
6738 effort-prompt " ["
6739 (if (= i 9) "0" (int-to-string (1+ i)))
6740 "]" (nth i efforts))))
6741 (message "Effort%s: %s " effort-op effort-prompt)
6742 (setq char (read-char-exclusive))
6743 (when (or (< char ?0) (> char ?9))
6744 (error "Need 1-9,0 to select effort"))))
6745 (when (equal char ?\t)
6746 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6747 (org-set-local 'org-global-tags-completion-table
6748 (org-global-tags-completion-table)))
6749 (let ((completion-ignore-case t))
6750 (setq tag (org-icompleting-read
6751 "Tag: " org-global-tags-completion-table))))
6752 (cond
6753 ((equal char ?\r)
6754 (org-agenda-filter-show-all-tag)
6755 (when org-agenda-auto-exclude-function
6756 (setq org-agenda-tag-filter '())
6757 (dolist (tag (org-agenda-get-represented-tags))
6758 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6759 (if modifier
6760 (push modifier org-agenda-tag-filter))))
6761 (if (not (null org-agenda-tag-filter))
6762 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6763 (setq maybe-refresh t))
6764 ((equal char ?/)
6765 (org-agenda-filter-show-all-tag)
6766 (when (get 'org-agenda-tag-filter :preset-filter)
6767 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6768 (setq maybe-refresh t))
6769 ((equal char ?. )
6770 (setq org-agenda-tag-filter
6771 (mapcar (lambda(tag) (concat "+" tag))
6772 (org-get-at-bol 'tags)))
6773 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6774 (setq maybe-refresh t))
6775 ((or (equal char ?\ )
6776 (setq a (rassoc char alist))
6777 (and (>= char ?0) (<= char ?9)
6778 (setq n (if (= char ?0) 9 (- char ?0 1))
6779 tag (concat effort-op (nth n efforts))
6780 a (cons tag nil)))
6781 (and (= char ??)
6782 (setq tag "?eff")
6783 a (cons tag nil))
6784 (and tag (setq a (cons tag nil))))
6785 (org-agenda-filter-show-all-tag)
6786 (setq tag (car a))
6787 (setq org-agenda-tag-filter
6788 (cons (concat (if strip "-" "+") tag)
6789 (if narrow current nil)))
6790 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6791 (setq maybe-refresh t))
6792 (t (error "Invalid tag selection character %c" char)))
6793 (when (and maybe-refresh
6794 (eq org-agenda-clockreport-mode 'with-filter))
6795 (org-agenda-redo))))
6797 (defun org-agenda-get-represented-tags ()
6798 "Get a list of all tags currently represented in the agenda."
6799 (let (p tags)
6800 (save-excursion
6801 (goto-char (point-min))
6802 (while (setq p (next-single-property-change (point) 'tags))
6803 (goto-char p)
6804 (mapc (lambda (x) (add-to-list 'tags x))
6805 (get-text-property (point) 'tags))))
6806 tags))
6808 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6809 "Refine the current filter. See `org-agenda-filter-by-tag'."
6810 (interactive "P")
6811 (org-agenda-filter-by-tag strip char 'refine))
6813 (defun org-agenda-filter-make-matcher ()
6814 "Create the form that tests a line for agenda filter."
6815 (let (f f1)
6816 ;; first compute the tag-filter matcher
6817 (dolist (x (delete-dups
6818 (append (get 'org-agenda-tag-filter
6819 :preset-filter) org-agenda-tag-filter)))
6820 (if (member x '("-" "+"))
6821 (setq f1 (if (equal x "-") 'tags '(not tags)))
6822 (if (string-match "[<=>?]" x)
6823 (setq f1 (org-agenda-filter-effort-form x))
6824 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6825 (if (equal (string-to-char x) ?-)
6826 (setq f1 (list 'not f1))))
6827 (push f1 f))
6828 ;; then compute the category-filter matcher
6829 (dolist (x (delete-dups
6830 (append (get 'org-agenda-category-filter
6831 :preset-filter) org-agenda-category-filter)))
6832 (if (equal "-" (substring x 0 1))
6833 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6834 (setq f1 (list 'equal (substring x 1) 'cat)))
6835 (push f1 f))
6836 (cons 'and (nreverse f))))
6838 (defun org-agenda-filter-effort-form (e)
6839 "Return the form to compare the effort of the current line with what E says.
6840 E looks like \"+<2:25\"."
6841 (let (op)
6842 (setq e (substring e 1))
6843 (setq op (string-to-char e) e (substring e 1))
6844 (setq op (cond ((equal op ?<) '<=)
6845 ((equal op ?>) '>=)
6846 ((equal op ??) op)
6847 (t '=)))
6848 (list 'org-agenda-compare-effort (list 'quote op)
6849 (org-duration-string-to-minutes e))))
6851 (defun org-agenda-compare-effort (op value)
6852 "Compare the effort of the current line with VALUE, using OP.
6853 If the line does not have an effort defined, return nil."
6854 (let ((eff (org-get-at-bol 'effort-minutes)))
6855 (if (equal op ??)
6856 (not eff)
6857 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6858 value))))
6860 (defun org-agenda-filter-apply (filter type)
6861 "Set FILTER as the new agenda filter and apply it."
6862 (let (tags cat)
6863 (if (eq type 'tag)
6864 (setq org-agenda-tag-filter filter)
6865 (setq org-agenda-category-filter filter))
6866 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6867 (if (and (eq type 'category)
6868 (not (equal (substring (car filter) 0 1) "-")))
6869 ;; Only set `org-agenda-filtered-by-category' to t
6870 ;; when a unique category is used as the filter
6871 (setq org-agenda-filtered-by-category t))
6872 (org-agenda-set-mode-name)
6873 (save-excursion
6874 (goto-char (point-min))
6875 (while (not (eobp))
6876 (if (org-get-at-bol 'org-marker)
6877 (progn
6878 (setq tags (org-get-at-bol 'tags) ; used in eval
6879 cat (get-text-property (point) 'org-category))
6880 (if (not (eval org-agenda-filter-form))
6881 (org-agenda-filter-hide-line type))
6882 (beginning-of-line 2))
6883 (beginning-of-line 2))))
6884 (if (get-char-property (point) 'invisible)
6885 (ignore-errors (org-agenda-previous-line)))))
6887 (defun org-agenda-filter-top-category-apply (category &optional negative)
6888 "Set FILTER as the new agenda filter and apply it."
6889 (org-agenda-set-mode-name)
6890 (save-excursion
6891 (goto-char (point-min))
6892 (while (not (eobp))
6893 (let* ((pos (org-get-at-bol 'org-hd-marker))
6894 (topcat (and pos (org-find-top-category pos))))
6895 (if (and topcat (funcall (if negative 'identity 'not)
6896 (string= category topcat)))
6897 (org-agenda-filter-hide-line 'category)))
6898 (beginning-of-line 2)))
6899 (if (get-char-property (point) 'invisible)
6900 (org-agenda-previous-line))
6901 (setq org-agenda-top-category-filter category
6902 org-agenda-filtered-by-top-category t))
6904 (defun org-agenda-filter-hide-line (type)
6905 (let (ov)
6906 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6907 (point-at-eol)))
6908 (overlay-put ov 'invisible t)
6909 (overlay-put ov 'type type)
6910 (if (eq type 'tag)
6911 (push ov org-agenda-tag-filter-overlays)
6912 (push ov org-agenda-cat-filter-overlays))))
6914 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6915 (setq pos (or pos (point)))
6916 (save-excursion
6917 (dolist (ov (overlays-at pos))
6918 (when (and (overlay-get ov 'invisible)
6919 (eq (overlay-get ov 'type) 'tag))
6920 (goto-char pos)
6921 (if (< (overlay-start ov) (point-at-eol))
6922 (move-overlay ov (point-at-eol)
6923 (overlay-end ov)))))))
6925 (defun org-agenda-filter-show-all-tag nil
6926 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6927 (setq org-agenda-tag-filter-overlays nil
6928 org-agenda-tag-filter nil
6929 org-agenda-filter-form nil)
6930 (org-agenda-set-mode-name))
6932 (defun org-agenda-filter-show-all-cat nil
6933 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6934 (setq org-agenda-cat-filter-overlays nil
6935 org-agenda-filtered-by-category nil
6936 org-agenda-category-filter nil
6937 org-agenda-filter-form nil)
6938 (org-agenda-set-mode-name))
6940 (defun org-agenda-manipulate-query-add ()
6941 "Manipulate the query by adding a search term with positive selection.
6942 Positive selection means the term must be matched for selection of an entry."
6943 (interactive)
6944 (org-agenda-manipulate-query ?\[))
6945 (defun org-agenda-manipulate-query-subtract ()
6946 "Manipulate the query by adding a search term with negative selection.
6947 Negative selection means term must not be matched for selection of an entry."
6948 (interactive)
6949 (org-agenda-manipulate-query ?\]))
6950 (defun org-agenda-manipulate-query-add-re ()
6951 "Manipulate the query by adding a search regexp with positive selection.
6952 Positive selection means the regexp must match for selection of an entry."
6953 (interactive)
6954 (org-agenda-manipulate-query ?\{))
6955 (defun org-agenda-manipulate-query-subtract-re ()
6956 "Manipulate the query by adding a search regexp with negative selection.
6957 Negative selection means regexp must not match for selection of an entry."
6958 (interactive)
6959 (org-agenda-manipulate-query ?\}))
6960 (defun org-agenda-manipulate-query (char)
6961 (cond
6962 ((memq org-agenda-type '(timeline agenda))
6963 (let ((org-agenda-include-inactive-timestamps t))
6964 (org-agenda-redo))
6965 (message "Display now includes inactive timestamps as well"))
6966 ((eq org-agenda-type 'search)
6967 (org-add-to-string
6968 'org-agenda-query-string
6969 (if org-agenda-last-search-view-search-was-boolean
6970 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6971 (?\{ . " +{}") (?\} . " -{}"))))
6972 " "))
6973 (setq org-agenda-redo-command
6974 (list 'org-search-view
6975 (car (get-text-property (point) 'org-last-args))
6976 org-agenda-query-string
6977 (+ (length org-agenda-query-string)
6978 (if (member char '(?\{ ?\})) 0 1))))
6979 (set-register org-agenda-query-register org-agenda-query-string)
6980 (let ((org-agenda-overriding-arguments
6981 (cdr org-agenda-redo-command)))
6982 (org-agenda-redo)))
6983 (t (error "Cannot manipulate query for %s-type agenda buffers"
6984 org-agenda-type))))
6986 (defun org-add-to-string (var string)
6987 (set var (concat (symbol-value var) string)))
6989 (defun org-agenda-goto-date (span)
6990 "Jump to DATE in agenda."
6991 (interactive "P")
6992 (let* ((org-read-date-prefer-future
6993 (eval org-agenda-jump-prefer-future))
6994 (date (org-read-date))
6995 (org-agenda-sticky-orig org-agenda-sticky)
6996 (org-agenda-buffer-tmp-name (buffer-name))
6997 (args (get-text-property (point) 'org-last-args))
6998 (0-arg (or current-prefix-arg (car args)))
6999 (2-arg (nth 2 args))
7000 (newcmd (list 'org-agenda-list 0-arg date
7001 (org-agenda-span-to-ndays 2-arg)))
7002 (newargs (cdr newcmd))
7003 (inhibit-read-only t)
7004 org-agenda-sticky)
7005 (if (not (org-agenda-check-type t 'agenda))
7006 (error "Not available in non-agenda blocks")
7007 (add-text-properties (point-min) (point-max)
7008 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7009 (org-agenda-redo)
7010 (setq org-agenda-sticky org-agenda-sticky-orig
7011 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7013 (defun org-agenda-goto-today ()
7014 "Go to today."
7015 (interactive)
7016 (org-agenda-check-type t 'timeline 'agenda)
7017 (let* ((args (get-text-property (point) 'org-last-args))
7018 (curspan (nth 2 args))
7019 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7020 (cond
7021 (tdpos (goto-char tdpos))
7022 ((eq org-agenda-type 'agenda)
7023 (let* ((sd (org-agenda-compute-starting-span
7024 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7025 (org-agenda-overriding-arguments args))
7026 (setf (nth 1 org-agenda-overriding-arguments) sd)
7027 (org-agenda-redo)
7028 (org-agenda-find-same-or-today-or-agenda)))
7029 (t (error "Cannot find today")))))
7031 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7032 (goto-char
7033 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7034 (text-property-any (point-min) (point-max) 'org-today t)
7035 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7036 (and (get-text-property (point) 'org-serie)
7037 (org-agenda-goto-block-beginning))
7038 (point-min))))
7040 (defun org-agenda-goto-block-beginning ()
7041 "Go the agenda block beginning."
7042 (interactive)
7043 (if (not (derived-mode-p 'org-agenda-mode))
7044 (error "Cannot execute this command outside of org-agenda-mode buffers")
7045 (let (dest)
7046 (save-excursion
7047 (unless (looking-at "\\'")
7048 (forward-char))
7049 (let* ((prop 'org-agenda-structural-header)
7050 (p (previous-single-property-change (point) prop))
7051 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7052 (1- (point))) prop)))
7053 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7054 (if (not dest)
7055 (error "Cannot find the beginning of the blog")
7056 (goto-char dest)
7057 (move-beginning-of-line 1)))))
7059 (defun org-agenda-later (arg)
7060 "Go forward in time by thee current span.
7061 With prefix ARG, go forward that many times the current span."
7062 (interactive "p")
7063 (org-agenda-check-type t 'agenda)
7064 (let* ((args (get-text-property (point) 'org-last-args))
7065 (span (or (nth 2 args) org-agenda-current-span))
7066 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7067 (greg (calendar-gregorian-from-absolute sd))
7068 (cnt (org-get-at-bol 'org-day-cnt))
7069 greg2)
7070 (cond
7071 ((numberp span)
7072 (setq sd (+ span sd)))
7073 ((eq span 'day)
7074 (setq sd (+ arg sd)))
7075 ((eq span 'week)
7076 (setq sd (+ (* 7 arg) sd)))
7077 ((eq span 'month)
7078 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7079 sd (calendar-absolute-from-gregorian greg2))
7080 (setcar greg2 (1+ (car greg2))))
7081 ((eq span 'year)
7082 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7083 sd (calendar-absolute-from-gregorian greg2))
7084 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7086 (setq sd (+ (* span arg) sd))))
7087 (let ((org-agenda-overriding-cmd
7088 ;; `cmd' may have been set by `org-agenda-run-series' which
7089 ;; uses `org-agenda-overriding-cmd' to decide whether
7090 ;; overriding is allowed for `cmd'
7091 (get-text-property (point) 'org-serie-cmd))
7092 (org-agenda-overriding-arguments
7093 (list (car args) sd span)))
7094 (org-agenda-redo)
7095 (org-agenda-find-same-or-today-or-agenda cnt))))
7097 (defun org-agenda-earlier (arg)
7098 "Go backward in time by the current span.
7099 With prefix ARG, go backward that many times the current span."
7100 (interactive "p")
7101 (org-agenda-later (- arg)))
7103 (defun org-agenda-view-mode-dispatch ()
7104 "Call one of the view mode commands."
7105 (interactive)
7106 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7107 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7108 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7109 (let ((a (read-char-exclusive)))
7110 (case a
7111 (?\ (call-interactively 'org-agenda-reset-view))
7112 (?d (call-interactively 'org-agenda-day-view))
7113 (?w (call-interactively 'org-agenda-week-view))
7114 (?m (call-interactively 'org-agenda-month-view))
7115 (?y (call-interactively 'org-agenda-year-view))
7116 (?l (call-interactively 'org-agenda-log-mode))
7117 (?L (org-agenda-log-mode '(4)))
7118 (?c (org-agenda-log-mode 'clockcheck))
7119 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7120 (?a (call-interactively 'org-agenda-archives-mode))
7121 (?A (org-agenda-archives-mode 'files))
7122 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7123 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7124 (?G (call-interactively 'org-agenda-toggle-time-grid))
7125 (?D (call-interactively 'org-agenda-toggle-diary))
7126 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7127 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7128 (org-agenda-check-type t 'timeline 'agenda)
7129 (org-agenda-redo))
7130 (message "Display now includes inactive timestamps as well"))
7131 (?q (message "Abort"))
7132 (otherwise (error "Invalid key" )))))
7134 (defun org-agenda-reset-view ()
7135 "Switch to default view for agenda."
7136 (interactive)
7137 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7138 (defun org-agenda-day-view (&optional day-of-year)
7139 "Switch to daily view for agenda.
7140 With argument DAY-OF-YEAR, switch to that day of the year."
7141 (interactive "P")
7142 (org-agenda-change-time-span 'day day-of-year))
7143 (defun org-agenda-week-view (&optional iso-week)
7144 "Switch to daily view for agenda.
7145 With argument ISO-WEEK, switch to the corresponding ISO week.
7146 If ISO-WEEK has more then 2 digits, only the last two encode the
7147 week. Any digits before this encode a year. So 200712 means
7148 week 12 of year 2007. Years in the range 1938-2037 can also be
7149 written as 2-digit years."
7150 (interactive "P")
7151 (org-agenda-change-time-span 'week iso-week))
7152 (defun org-agenda-month-view (&optional month)
7153 "Switch to monthly view for agenda.
7154 With argument MONTH, switch to that month."
7155 (interactive "P")
7156 (org-agenda-change-time-span 'month month))
7157 (defun org-agenda-year-view (&optional year)
7158 "Switch to yearly view for agenda.
7159 With argument YEAR, switch to that year.
7160 If MONTH has more then 2 digits, only the last two encode the
7161 month. Any digits before this encode a year. So 200712 means
7162 December year 2007. Years in the range 1938-2037 can also be
7163 written as 2-digit years."
7164 (interactive "P")
7165 (when year
7166 (setq year (org-small-year-to-year year)))
7167 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7168 (org-agenda-change-time-span 'year year)
7169 (error "Abort")))
7171 (defun org-agenda-change-time-span (span &optional n)
7172 "Change the agenda view to SPAN.
7173 SPAN may be `day', `week', `month', `year'."
7174 (org-agenda-check-type t 'agenda)
7175 (let* ((args (get-text-property (point) 'org-last-args))
7176 (curspan (nth 2 args)))
7177 (if (and (not n) (equal curspan span))
7178 (error "Viewing span is already \"%s\"" span))
7179 (let* ((sd (or (org-get-at-bol 'day)
7180 (nth 1 args)
7181 org-starting-day))
7182 (sd (org-agenda-compute-starting-span sd span n))
7183 (org-agenda-overriding-cmd
7184 (get-text-property (point) 'org-serie-cmd))
7185 (org-agenda-overriding-arguments
7186 (list (car args) sd span)))
7187 (org-agenda-redo)
7188 (org-agenda-find-same-or-today-or-agenda))
7189 (org-agenda-set-mode-name)
7190 (message "Switched to %s view" span)))
7192 (defun org-agenda-compute-starting-span (sd span &optional n)
7193 "Compute starting date for agenda.
7194 SPAN may be `day', `week', `month', `year'. The return value
7195 is a cons cell with the starting date and the number of days,
7196 so that the date SD will be in that range."
7197 (let* ((greg (calendar-gregorian-from-absolute sd))
7198 (dg (nth 1 greg))
7199 (mg (car greg))
7200 (yg (nth 2 greg)))
7201 (cond
7202 ((eq span 'day)
7203 (when n
7204 (setq sd (+ (calendar-absolute-from-gregorian
7205 (list mg 1 yg))
7206 n -1))))
7207 ((eq span 'week)
7208 (let* ((nt (calendar-day-of-week
7209 (calendar-gregorian-from-absolute sd)))
7210 (d (if org-agenda-start-on-weekday
7211 (- nt org-agenda-start-on-weekday)
7214 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7215 (when n
7216 (require 'cal-iso)
7217 (when (> n 99)
7218 (setq y1 (org-small-year-to-year (/ n 100))
7219 n (mod n 100)))
7220 (setq sd
7221 (calendar-absolute-from-iso
7222 (list n 1
7223 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7224 ((eq span 'month)
7225 (let (y1)
7226 (when (and n (> n 99))
7227 (setq y1 (org-small-year-to-year (/ n 100))
7228 n (mod n 100)))
7229 (setq sd (calendar-absolute-from-gregorian
7230 (list (or n mg) 1 (or y1 yg))))))
7231 ((eq span 'year)
7232 (setq sd (calendar-absolute-from-gregorian
7233 (list 1 1 (or n yg))))))
7234 sd))
7236 (defun org-agenda-next-date-line (&optional arg)
7237 "Jump to the next line indicating a date in agenda buffer."
7238 (interactive "p")
7239 (org-agenda-check-type t 'agenda 'timeline)
7240 (beginning-of-line 1)
7241 ;; This does not work if user makes date format that starts with a blank
7242 (if (looking-at "^\\S-") (forward-char 1))
7243 (if (not (re-search-forward "^\\S-" nil t arg))
7244 (progn
7245 (backward-char 1)
7246 (error "No next date after this line in this buffer")))
7247 (goto-char (match-beginning 0)))
7249 (defun org-agenda-previous-date-line (&optional arg)
7250 "Jump to the previous line indicating a date in agenda buffer."
7251 (interactive "p")
7252 (org-agenda-check-type t 'agenda 'timeline)
7253 (beginning-of-line 1)
7254 (if (not (re-search-backward "^\\S-" nil t arg))
7255 (error "No previous date before this line in this buffer")))
7257 ;; Initialize the highlight
7258 (defvar org-hl (make-overlay 1 1))
7259 (overlay-put org-hl 'face 'highlight)
7261 (defun org-highlight (begin end &optional buffer)
7262 "Highlight a region with overlay."
7263 (move-overlay org-hl begin end (or buffer (current-buffer))))
7265 (defun org-unhighlight ()
7266 "Detach overlay INDEX."
7267 (org-detach-overlay org-hl))
7269 (defun org-unhighlight-once ()
7270 "Remove the highlight from its position, and this function from the hook."
7271 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7272 (org-unhighlight))
7274 (defun org-agenda-follow-mode ()
7275 "Toggle follow mode in an agenda buffer."
7276 (interactive)
7277 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7278 (org-agenda-set-mode-name)
7279 (org-agenda-do-context-action)
7280 (message "Follow mode is %s"
7281 (if org-agenda-follow-mode "on" "off")))
7283 (defun org-agenda-entry-text-mode (&optional arg)
7284 "Toggle entry text mode in an agenda buffer."
7285 (interactive "P")
7286 (setq org-agenda-entry-text-mode (or (integerp arg)
7287 (not org-agenda-entry-text-mode)))
7288 (org-agenda-entry-text-hide)
7289 (and org-agenda-entry-text-mode
7290 (let ((org-agenda-entry-text-maxlines
7291 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7292 (org-agenda-entry-text-show)))
7293 (org-agenda-set-mode-name)
7294 (message "Entry text mode is %s. Maximum number of lines is %d"
7295 (if org-agenda-entry-text-mode "on" "off")
7296 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7298 (defun org-agenda-clockreport-mode (&optional with-filter)
7299 "Toggle clocktable mode in an agenda buffer.
7300 With prefix arg WITH-FILTER, make the clocktable respect the current
7301 agenda filter."
7302 (interactive "P")
7303 (org-agenda-check-type t 'agenda)
7304 (if with-filter
7305 (setq org-agenda-clockreport-mode 'with-filter)
7306 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7307 (org-agenda-set-mode-name)
7308 (org-agenda-redo)
7309 (message "Clocktable mode is %s"
7310 (if org-agenda-clockreport-mode "on" "off")))
7312 (defun org-agenda-log-mode (&optional special)
7313 "Toggle log mode in an agenda buffer.
7314 With argument SPECIAL, show all possible log items, not only the ones
7315 configured in `org-agenda-log-mode-items'.
7316 With a double `C-u' prefix arg, show *only* log items, nothing else."
7317 (interactive "P")
7318 (org-agenda-check-type t 'agenda 'timeline)
7319 (setq org-agenda-show-log
7320 (cond
7321 ((equal special '(16)) 'only)
7322 ((eq special 'clockcheck)
7323 (if (eq org-agenda-show-log 'clockcheck)
7324 nil 'clockcheck))
7325 (special '(closed clock state))
7326 (t (not org-agenda-show-log))))
7327 (org-agenda-set-mode-name)
7328 (org-agenda-redo)
7329 (message "Log mode is %s"
7330 (if org-agenda-show-log "on" "off")))
7332 (defun org-agenda-archives-mode (&optional with-files)
7333 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7334 When called with a prefix argument, include all archive files as well."
7335 (interactive "P")
7336 (setq org-agenda-archives-mode
7337 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7338 (org-agenda-set-mode-name)
7339 (org-agenda-redo)
7340 (message
7341 "%s"
7342 (cond
7343 ((eq org-agenda-archives-mode nil)
7344 "No archives are included")
7345 ((eq org-agenda-archives-mode 'trees)
7346 (format "Trees with :%s: tag are included" org-archive-tag))
7347 ((eq org-agenda-archives-mode t)
7348 (format "Trees with :%s: tag and all active archive files are included"
7349 org-archive-tag)))))
7351 (defun org-agenda-toggle-diary ()
7352 "Toggle diary inclusion in an agenda buffer."
7353 (interactive)
7354 (org-agenda-check-type t 'agenda)
7355 (setq org-agenda-include-diary (not org-agenda-include-diary))
7356 (org-agenda-redo)
7357 (org-agenda-set-mode-name)
7358 (message "Diary inclusion turned %s"
7359 (if org-agenda-include-diary "on" "off")))
7361 (defun org-agenda-toggle-deadlines ()
7362 "Toggle inclusion of entries with a deadline in an agenda buffer."
7363 (interactive)
7364 (org-agenda-check-type t 'agenda)
7365 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7366 (org-agenda-redo)
7367 (org-agenda-set-mode-name)
7368 (message "Deadlines inclusion turned %s"
7369 (if org-agenda-include-deadlines "on" "off")))
7371 (defun org-agenda-toggle-time-grid ()
7372 "Toggle time grid in an agenda buffer."
7373 (interactive)
7374 (org-agenda-check-type t 'agenda)
7375 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7376 (org-agenda-redo)
7377 (org-agenda-set-mode-name)
7378 (message "Time-grid turned %s"
7379 (if org-agenda-use-time-grid "on" "off")))
7381 (defun org-agenda-set-mode-name ()
7382 "Set the mode name to indicate all the small mode settings."
7383 (setq mode-name
7384 (list "Org-Agenda"
7385 (if (get 'org-agenda-files 'org-restrict) " []" "")
7387 '(:eval (org-agenda-span-name org-agenda-current-span))
7388 (if org-agenda-follow-mode " Follow" "")
7389 (if org-agenda-entry-text-mode " ETxt" "")
7390 (if org-agenda-include-diary " Diary" "")
7391 (if org-agenda-include-deadlines " Ddl" "")
7392 (if org-agenda-use-time-grid " Grid" "")
7393 (if (and (boundp 'org-habit-show-habits)
7394 org-habit-show-habits) " Habit" "")
7395 (cond
7396 ((consp org-agenda-show-log) " LogAll")
7397 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7398 (org-agenda-show-log " Log")
7399 (t ""))
7400 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7401 :preset-filter))
7402 '(:eval (org-propertize
7403 (concat " <"
7404 (mapconcat
7405 'identity
7406 (append
7407 (get 'org-agenda-category-filter :preset-filter)
7408 org-agenda-category-filter)
7410 ">")
7411 'face 'org-agenda-filter-category
7412 'help-echo "Category used in filtering"))
7414 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7415 :preset-filter))
7416 '(:eval (org-propertize
7417 (concat " {"
7418 (mapconcat
7419 'identity
7420 (append
7421 (get 'org-agenda-tag-filter :preset-filter)
7422 org-agenda-tag-filter)
7424 "}")
7425 'face 'org-agenda-filter-tags
7426 'help-echo "Tags used in filtering"))
7428 (if org-agenda-archives-mode
7429 (if (eq org-agenda-archives-mode t)
7430 " Archives"
7431 (format " :%s:" org-archive-tag))
7433 (if org-agenda-clockreport-mode
7434 (if (eq org-agenda-clockreport-mode 'with-filter)
7435 " Clock{}" " Clock")
7436 "")))
7437 (force-mode-line-update))
7439 (defun org-agenda-post-command-hook ()
7440 (setq org-agenda-type
7441 (or (get-text-property (point) 'org-agenda-type)
7442 (get-text-property (max (point-min) (1- (point)))
7443 'org-agenda-type))))
7445 (defun org-agenda-next-line ()
7446 "Move cursor to the next line, and show if follow mode is active."
7447 (interactive)
7448 (call-interactively 'next-line)
7449 (org-agenda-do-context-action))
7451 (defun org-agenda-previous-line ()
7452 "Move cursor to the previous line, and show if follow-mode is active."
7453 (interactive)
7454 (call-interactively 'previous-line)
7455 (org-agenda-do-context-action))
7457 (defun org-agenda-next-item (n)
7458 "Move cursor to next agenda item."
7459 (interactive "p")
7460 (let ((col (current-column)))
7461 (dotimes (c n)
7462 (when (next-single-property-change (point-at-eol) 'org-marker)
7463 (move-end-of-line 1)
7464 (goto-char (next-single-property-change (point) 'org-marker))))
7465 (org-move-to-column col))
7466 (org-agenda-do-context-action))
7468 (defun org-agenda-previous-item (n)
7469 "Move cursor to next agenda item."
7470 (interactive "p")
7471 (dotimes (c n)
7472 (let ((col (current-column))
7473 (goto (save-excursion
7474 (move-end-of-line 0)
7475 (previous-single-property-change (point) 'org-marker))))
7476 (if goto (goto-char goto))
7477 (org-move-to-column col)))
7478 (org-agenda-do-context-action))
7480 (defun org-agenda-do-context-action ()
7481 "Show outline path and, maybe, follow mode window."
7482 (let ((m (org-get-at-bol 'org-marker)))
7483 (when (and (markerp m) (marker-buffer m))
7484 (and org-agenda-follow-mode
7485 (if org-agenda-follow-indirect
7486 (org-agenda-tree-to-indirect-buffer)
7487 (org-agenda-show)))
7488 (and org-agenda-show-outline-path
7489 (org-with-point-at m (org-display-outline-path t))))))
7491 (defun org-agenda-show-priority ()
7492 "Show the priority of the current item.
7493 This priority is composed of the main priority given with the [#A] cookies,
7494 and by additional input from the age of a schedules or deadline entry."
7495 (interactive)
7496 (let* ((pri (org-get-at-bol 'priority)))
7497 (message "Priority is %d" (if pri pri -1000))))
7499 (defun org-agenda-show-tags ()
7500 "Show the tags applicable to the current item."
7501 (interactive)
7502 (let* ((tags (org-get-at-bol 'tags)))
7503 (if tags
7504 (message "Tags are :%s:"
7505 (org-no-properties (mapconcat 'identity tags ":")))
7506 (message "No tags associated with this line"))))
7508 (defun org-agenda-goto (&optional highlight)
7509 "Go to the Org-mode file which contains the item at point."
7510 (interactive)
7511 (let* ((marker (or (org-get-at-bol 'org-marker)
7512 (org-agenda-error)))
7513 (buffer (marker-buffer marker))
7514 (pos (marker-position marker)))
7515 (switch-to-buffer-other-window buffer)
7516 (widen)
7517 (push-mark)
7518 (goto-char pos)
7519 (when (derived-mode-p 'org-mode)
7520 (org-show-context 'agenda)
7521 (save-excursion
7522 (and (outline-next-heading)
7523 (org-flag-heading nil)))) ; show the next heading
7524 (when (outline-invisible-p)
7525 (show-entry)) ; display invisible text
7526 (recenter (/ (window-height) 2))
7527 (run-hooks 'org-agenda-after-show-hook)
7528 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7530 (defvar org-agenda-after-show-hook nil
7531 "Normal hook run after an item has been shown from the agenda.
7532 Point is in the buffer where the item originated.")
7534 (defun org-agenda-kill ()
7535 "Kill the entry or subtree belonging to the current agenda entry."
7536 (interactive)
7537 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7538 (let* ((bufname-orig (buffer-name))
7539 (marker (or (org-get-at-bol 'org-marker)
7540 (org-agenda-error)))
7541 (buffer (marker-buffer marker))
7542 (pos (marker-position marker))
7543 (type (org-get-at-bol 'type))
7544 dbeg dend (n 0) conf)
7545 (org-with-remote-undo buffer
7546 (with-current-buffer buffer
7547 (save-excursion
7548 (goto-char pos)
7549 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7550 (setq dbeg (progn (org-back-to-heading t) (point))
7551 dend (org-end-of-subtree t t))
7552 (setq dbeg (point-at-bol)
7553 dend (min (point-max) (1+ (point-at-eol)))))
7554 (goto-char dbeg)
7555 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7556 (setq conf (or (eq t org-agenda-confirm-kill)
7557 (and (numberp org-agenda-confirm-kill)
7558 (> n org-agenda-confirm-kill))))
7559 (and conf
7560 (not (y-or-n-p
7561 (format "Delete entry with %d lines in buffer \"%s\"? "
7562 n (buffer-name buffer))))
7563 (error "Abort"))
7564 (let ((org-agenda-buffer-name bufname-orig))
7565 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7566 (with-current-buffer buffer (delete-region dbeg dend))
7567 (message "Agenda item and source killed"))))
7569 (defvar org-archive-default-command) ; defined in org-archive.el
7570 (defun org-agenda-archive-default ()
7571 "Archive the entry or subtree belonging to the current agenda entry."
7572 (interactive)
7573 (require 'org-archive)
7574 (org-agenda-archive-with org-archive-default-command))
7576 (defun org-agenda-archive-default-with-confirmation ()
7577 "Archive the entry or subtree belonging to the current agenda entry."
7578 (interactive)
7579 (require 'org-archive)
7580 (org-agenda-archive-with org-archive-default-command 'confirm))
7582 (defun org-agenda-archive ()
7583 "Archive the entry or subtree belonging to the current agenda entry."
7584 (interactive)
7585 (org-agenda-archive-with 'org-archive-subtree))
7587 (defun org-agenda-archive-to-archive-sibling ()
7588 "Move the entry to the archive sibling."
7589 (interactive)
7590 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7592 (defun org-agenda-archive-with (cmd &optional confirm)
7593 "Move the entry to the archive sibling."
7594 (interactive)
7595 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7596 (let* ((bufname-orig (buffer-name))
7597 (marker (or (org-get-at-bol 'org-marker)
7598 (org-agenda-error)))
7599 (buffer (marker-buffer marker))
7600 (pos (marker-position marker)))
7601 (org-with-remote-undo buffer
7602 (with-current-buffer buffer
7603 (if (derived-mode-p 'org-mode)
7604 (if (and confirm
7605 (not (y-or-n-p "Archive this subtree or entry? ")))
7606 (error "Abort")
7607 (save-excursion
7608 (goto-char pos)
7609 (let ((org-agenda-buffer-name bufname-orig))
7610 (org-remove-subtree-entries-from-agenda))
7611 (org-back-to-heading t)
7612 (funcall cmd)))
7613 (error "Archiving works only in Org-mode files"))))))
7615 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7616 "Remove all lines in the agenda that correspond to a given subtree.
7617 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7618 If this information is not given, the function uses the tree at point."
7619 (let ((buf (or buf (current-buffer))) m p)
7620 (save-excursion
7621 (unless (and beg end)
7622 (org-back-to-heading t)
7623 (setq beg (point))
7624 (org-end-of-subtree t)
7625 (setq end (point)))
7626 (set-buffer (get-buffer org-agenda-buffer-name))
7627 (save-excursion
7628 (goto-char (point-max))
7629 (beginning-of-line 1)
7630 (while (not (bobp))
7631 (when (and (setq m (org-get-at-bol 'org-marker))
7632 (equal buf (marker-buffer m))
7633 (setq p (marker-position m))
7634 (>= p beg)
7635 (< p end))
7636 (let ((inhibit-read-only t))
7637 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7638 (beginning-of-line 0))))))
7640 (defun org-agenda-refile (&optional goto rfloc no-update)
7641 "Refile the item at point."
7642 (interactive "P")
7643 (if (equal goto '(16))
7644 (org-refile-goto-last-stored)
7645 (let* ((buffer-orig (buffer-name))
7646 (marker (or (org-get-at-bol 'org-hd-marker)
7647 (org-agenda-error)))
7648 (buffer (marker-buffer marker))
7649 (pos (marker-position marker))
7650 (rfloc (or rfloc
7651 (org-refile-get-location
7652 (if goto "Goto" "Refile to") buffer
7653 org-refile-allow-creating-parent-nodes))))
7654 (with-current-buffer buffer
7655 (save-excursion
7656 (save-restriction
7657 (widen)
7658 (goto-char marker)
7659 (let ((org-agenda-buffer-name buffer-orig))
7660 (org-remove-subtree-entries-from-agenda))
7661 (org-refile goto buffer rfloc)))))
7662 (unless no-update (org-agenda-redo))))
7664 (defun org-agenda-open-link (&optional arg)
7665 "Follow the link in the current line, if any.
7666 This looks for a link in the displayed line in the agenda. It also looks
7667 at the text of the entry itself."
7668 (interactive "P")
7669 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7670 (org-get-at-bol 'org-marker)))
7671 (buffer (and marker (marker-buffer marker)))
7672 (prefix (buffer-substring
7673 (point-at-bol) (point-at-eol))))
7674 (cond
7675 (buffer
7676 (with-current-buffer buffer
7677 (save-excursion
7678 (save-restriction
7679 (widen)
7680 (goto-char marker)
7681 (org-offer-links-in-entry arg prefix)))))
7682 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7683 (save-excursion
7684 (beginning-of-line 1)
7685 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7686 (org-open-link-from-string (match-string 1)))
7687 (t (error "No link to open here")))))
7689 (defun org-agenda-copy-local-variable (var)
7690 "Get a variable from a referenced buffer and install it here."
7691 (let ((m (org-get-at-bol 'org-marker)))
7692 (when (and m (buffer-live-p (marker-buffer m)))
7693 (org-set-local var (with-current-buffer (marker-buffer m)
7694 (symbol-value var))))))
7696 (defun org-agenda-switch-to (&optional delete-other-windows)
7697 "Go to the Org-mode file which contains the item at point."
7698 (interactive)
7699 (if (and org-return-follows-link
7700 (not (org-get-at-bol 'org-marker))
7701 (org-in-regexp org-bracket-link-regexp))
7702 (org-open-link-from-string (match-string 0))
7703 (let* ((marker (or (org-get-at-bol 'org-marker)
7704 (org-agenda-error)))
7705 (buffer (marker-buffer marker))
7706 (pos (marker-position marker)))
7707 (org-pop-to-buffer-same-window buffer)
7708 (and delete-other-windows (delete-other-windows))
7709 (widen)
7710 (goto-char pos)
7711 (when (derived-mode-p 'org-mode)
7712 (org-show-context 'agenda)
7713 (save-excursion
7714 (and (outline-next-heading)
7715 (org-flag-heading nil))) ; show the next heading
7716 (when (outline-invisible-p)
7717 (show-entry)) ; display invisible text
7718 (run-hooks 'org-agenda-after-show-hook)))))
7720 (defun org-agenda-goto-mouse (ev)
7721 "Go to the Org-mode file which contains the item at the mouse click."
7722 (interactive "e")
7723 (mouse-set-point ev)
7724 (org-agenda-goto))
7726 (defun org-agenda-show (&optional full-entry)
7727 "Display the Org-mode file which contains the item at point.
7728 With prefix argument FULL-ENTRY, make the entire entry visible
7729 if it was hidden in the outline."
7730 (interactive "P")
7731 (let ((win (selected-window)))
7732 (if full-entry
7733 (let ((org-show-entry-below t))
7734 (org-agenda-goto t))
7735 (org-agenda-goto t))
7736 (select-window win)))
7738 (defvar org-agenda-show-window nil)
7739 (defun org-agenda-show-and-scroll-up (&optional arg)
7740 "Display the Org-mode file which contains the item at point.
7741 When called repeatedly, scroll the window that is displaying the buffer.
7742 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7743 `show-subtree' to display the item, so that drawers and logbooks stay
7744 folded."
7745 (interactive "P")
7746 (let ((win (selected-window)))
7747 (if (and (window-live-p org-agenda-show-window)
7748 (eq this-command last-command))
7749 (progn
7750 (select-window org-agenda-show-window)
7751 (ignore-errors (scroll-up)))
7752 (org-agenda-goto t)
7753 (if arg (org-show-entry) (show-subtree))
7754 (setq org-agenda-show-window (selected-window)))
7755 (select-window win)))
7757 (defun org-agenda-show-scroll-down ()
7758 "Scroll down the window showing the agenda."
7759 (interactive)
7760 (let ((win (selected-window)))
7761 (when (window-live-p org-agenda-show-window)
7762 (select-window org-agenda-show-window)
7763 (ignore-errors (scroll-down))
7764 (select-window win))))
7766 (defun org-agenda-show-1 (&optional more)
7767 "Display the Org-mode file which contains the item at point.
7768 The prefix arg selects the amount of information to display:
7770 0 hide the subtree
7771 1 just show the entry according to defaults.
7772 2 show the children view
7773 3 show the subtree view
7774 4 show the entire subtree and any LOGBOOK drawers
7775 5 show the entire subtree and any drawers
7776 With prefix argument FULL-ENTRY, make the entire entry visible
7777 if it was hidden in the outline."
7778 (interactive "p")
7779 (let ((win (selected-window)))
7780 (org-agenda-goto t)
7781 (org-recenter-heading 1)
7782 (cond
7783 ((= more 0)
7784 (hide-subtree)
7785 (save-excursion
7786 (org-back-to-heading)
7787 (run-hook-with-args 'org-cycle-hook 'folded))
7788 (message "Remote: FOLDED"))
7789 ((and (org-called-interactively-p 'any) (= more 1))
7790 (message "Remote: show with default settings"))
7791 ((= more 2)
7792 (show-entry)
7793 (show-children)
7794 (save-excursion
7795 (org-back-to-heading)
7796 (run-hook-with-args 'org-cycle-hook 'children))
7797 (message "Remote: CHILDREN"))
7798 ((= more 3)
7799 (show-subtree)
7800 (save-excursion
7801 (org-back-to-heading)
7802 (run-hook-with-args 'org-cycle-hook 'subtree))
7803 (message "Remote: SUBTREE"))
7804 ((= more 4)
7805 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7806 (org-drawer-regexp
7807 (concat "^[ \t]*:\\("
7808 (mapconcat 'regexp-quote org-drawers "\\|")
7809 "\\):[ \t]*$")))
7810 (show-subtree)
7811 (save-excursion
7812 (org-back-to-heading)
7813 (org-cycle-hide-drawers 'subtree)))
7814 (message "Remote: SUBTREE AND LOGBOOK"))
7815 ((> more 4)
7816 (show-subtree)
7817 (message "Remote: SUBTREE AND ALL DRAWERS")))
7818 (select-window win)))
7820 (defun org-recenter-heading (n)
7821 (save-excursion
7822 (org-back-to-heading)
7823 (recenter n)))
7825 (defvar org-agenda-cycle-counter nil)
7826 (defun org-agenda-cycle-show (&optional n)
7827 "Show the current entry in another window, with default settings.
7828 Default settings are taken from `org-show-hierarchy-above' and siblings.
7829 When use repeatedly in immediate succession, the remote entry will cycle
7830 through visibility
7832 children -> subtree -> folded
7834 When called with a numeric prefix arg, that arg will be passed through to
7835 `org-agenda-show-1'. For the interpretation of that argument, see the
7836 docstring of `org-agenda-show-1'."
7837 (interactive "P")
7838 (if (integerp n)
7839 (setq org-agenda-cycle-counter n)
7840 (if (not (eq last-command this-command))
7841 (setq org-agenda-cycle-counter 1)
7842 (if (equal org-agenda-cycle-counter 0)
7843 (setq org-agenda-cycle-counter 2)
7844 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7845 (if (> org-agenda-cycle-counter 3)
7846 (setq org-agenda-cycle-counter 0)))))
7847 (org-agenda-show-1 org-agenda-cycle-counter))
7849 (defun org-agenda-recenter (arg)
7850 "Display the Org-mode file which contains the item at point and recenter."
7851 (interactive "P")
7852 (let ((win (selected-window)))
7853 (org-agenda-goto t)
7854 (recenter arg)
7855 (select-window win)))
7857 (defun org-agenda-show-mouse (ev)
7858 "Display the Org-mode file which contains the item at the mouse click."
7859 (interactive "e")
7860 (mouse-set-point ev)
7861 (org-agenda-show))
7863 (defun org-agenda-check-no-diary ()
7864 "Check if the entry is a diary link and abort if yes."
7865 (if (org-get-at-bol 'org-agenda-diary-link)
7866 (org-agenda-error)))
7868 (defun org-agenda-error ()
7869 (error "Command not allowed in this line"))
7871 (defun org-agenda-tree-to-indirect-buffer ()
7872 "Show the subtree corresponding to the current entry in an indirect buffer.
7873 This calls the command `org-tree-to-indirect-buffer' from the original
7874 Org-mode buffer.
7875 With numerical prefix arg ARG, go up to this level and then take that tree.
7876 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7877 use the dedicated frame)."
7878 (interactive)
7879 (if (and current-prefix-arg (listp current-prefix-arg))
7880 (org-agenda-do-tree-to-indirect-buffer)
7881 (let ((agenda-window (selected-window))
7882 (indirect-window
7883 (and org-last-indirect-buffer
7884 (get-buffer-window org-last-indirect-buffer))))
7885 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7886 (unwind-protect
7887 (progn
7888 (unless (and indirect-window (window-live-p indirect-window))
7889 (setq indirect-window (split-window agenda-window)))
7890 (select-window indirect-window)
7891 (switch-to-buffer org-last-indirect-buffer :norecord)
7892 (fit-window-to-buffer indirect-window))
7893 (select-window (get-buffer-window org-agenda-buffer-name))))))
7895 (defun org-agenda-do-tree-to-indirect-buffer ()
7896 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7897 (org-agenda-check-no-diary)
7898 (let* ((marker (or (org-get-at-bol 'org-marker)
7899 (org-agenda-error)))
7900 (buffer (marker-buffer marker))
7901 (pos (marker-position marker)))
7902 (with-current-buffer buffer
7903 (save-excursion
7904 (goto-char pos)
7905 (call-interactively 'org-tree-to-indirect-buffer)))))
7907 (defvar org-last-heading-marker (make-marker)
7908 "Marker pointing to the headline that last changed its TODO state
7909 by a remote command from the agenda.")
7911 (defun org-agenda-todo-nextset ()
7912 "Switch TODO entry to next sequence."
7913 (interactive)
7914 (org-agenda-todo 'nextset))
7916 (defun org-agenda-todo-previousset ()
7917 "Switch TODO entry to previous sequence."
7918 (interactive)
7919 (org-agenda-todo 'previousset))
7921 (defun org-agenda-todo (&optional arg)
7922 "Cycle TODO state of line at point, also in Org-mode file.
7923 This changes the line at point, all other lines in the agenda referring to
7924 the same tree node, and the headline of the tree node in the Org-mode file."
7925 (interactive "P")
7926 (org-agenda-check-no-diary)
7927 (let* ((col (current-column))
7928 (marker (or (org-get-at-bol 'org-marker)
7929 (org-agenda-error)))
7930 (buffer (marker-buffer marker))
7931 (pos (marker-position marker))
7932 (hdmarker (org-get-at-bol 'org-hd-marker))
7933 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7934 (inhibit-read-only t)
7935 org-agenda-headline-snapshot-before-repeat newhead just-one)
7936 (org-with-remote-undo buffer
7937 (with-current-buffer buffer
7938 (widen)
7939 (goto-char pos)
7940 (org-show-context 'agenda)
7941 (save-excursion
7942 (and (outline-next-heading)
7943 (org-flag-heading nil))) ; show the next heading
7944 (let ((current-prefix-arg arg))
7945 (call-interactively 'org-todo))
7946 (and (bolp) (forward-char 1))
7947 (setq newhead (org-get-heading))
7948 (when (and (org-bound-and-true-p
7949 org-agenda-headline-snapshot-before-repeat)
7950 (not (equal org-agenda-headline-snapshot-before-repeat
7951 newhead))
7952 todayp)
7953 (setq newhead org-agenda-headline-snapshot-before-repeat
7954 just-one t))
7955 (save-excursion
7956 (org-back-to-heading)
7957 (move-marker org-last-heading-marker (point))))
7958 (beginning-of-line 1)
7959 (save-excursion
7960 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7961 (org-move-to-column col))))
7963 (defun org-agenda-add-note (&optional arg)
7964 "Add a time-stamped note to the entry at point."
7965 (interactive "P")
7966 (org-agenda-check-no-diary)
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 (hdmarker (org-get-at-bol 'org-hd-marker))
7972 (inhibit-read-only t))
7973 (with-current-buffer buffer
7974 (widen)
7975 (goto-char pos)
7976 (org-show-context 'agenda)
7977 (save-excursion
7978 (and (outline-next-heading)
7979 (org-flag-heading nil))) ; show the next heading
7980 (org-add-note))))
7982 (defun org-agenda-change-all-lines (newhead hdmarker
7983 &optional fixface just-this)
7984 "Change all lines in the agenda buffer which match HDMARKER.
7985 The new content of the line will be NEWHEAD (as modified by
7986 `org-agenda-format-item'). HDMARKER is checked with
7987 `equal' against all `org-hd-marker' text properties in the file.
7988 If FIXFACE is non-nil, the face of each item is modified according to
7989 the new TODO state.
7990 If JUST-THIS is non-nil, change just the current line, not all.
7991 If FORCE-TAGS is non nil, the car of it returns the new tags."
7992 (let* ((inhibit-read-only t)
7993 (line (org-current-line))
7994 (org-agenda-buffer (current-buffer))
7995 (thetags (with-current-buffer (marker-buffer hdmarker)
7996 (save-excursion (save-restriction (widen)
7997 (goto-char hdmarker)
7998 (org-get-tags-at)))))
7999 props m pl undone-face done-face finish new dotime cat tags)
8000 (save-excursion
8001 (goto-char (point-max))
8002 (beginning-of-line 1)
8003 (while (not finish)
8004 (setq finish (bobp))
8005 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8006 (or (not just-this) (= (org-current-line) line))
8007 (equal m hdmarker))
8008 (setq props (text-properties-at (point))
8009 dotime (org-get-at-bol 'dotime)
8010 cat (org-get-at-bol 'org-category)
8011 tags thetags
8013 (let ((org-prefix-format-compiled
8014 (or (get-text-property (point) 'format)
8015 org-prefix-format-compiled))
8016 (extra (org-get-at-bol 'extra)))
8017 (with-current-buffer (marker-buffer hdmarker)
8018 (save-excursion
8019 (save-restriction
8020 (widen)
8021 (org-agenda-format-item extra newhead cat tags dotime)))))
8022 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8023 undone-face (org-get-at-bol 'undone-face)
8024 done-face (org-get-at-bol 'done-face))
8025 (beginning-of-line 1)
8026 (cond
8027 ((equal new "")
8028 (and (looking-at ".*\n?") (replace-match "")))
8029 ((looking-at ".*")
8030 (replace-match new t t)
8031 (beginning-of-line 1)
8032 (add-text-properties (point-at-bol) (point-at-eol) props)
8033 (when fixface
8034 (add-text-properties
8035 (point-at-bol) (point-at-eol)
8036 (list 'face
8037 (if org-last-todo-state-is-todo
8038 undone-face done-face))))
8039 (org-agenda-highlight-todo 'line)
8040 (beginning-of-line 1))
8041 (t (error "Line update did not work"))))
8042 (beginning-of-line 0)))
8043 (org-agenda-finalize)))
8045 (defun org-agenda-align-tags (&optional line)
8046 "Align all tags in agenda items to `org-agenda-tags-column'."
8047 (let ((inhibit-read-only t) l c)
8048 (save-excursion
8049 (goto-char (if line (point-at-bol) (point-min)))
8050 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8051 (if line (point-at-eol) nil) t)
8052 (add-text-properties
8053 (match-beginning 2) (match-end 2)
8054 (list 'face (delq nil (let ((prop (get-text-property
8055 (match-beginning 2) 'face)))
8056 (or (listp prop) (setq prop (list prop)))
8057 (if (memq 'org-tag prop)
8058 prop
8059 (cons 'org-tag prop))))))
8060 (setq l (- (match-end 2) (match-beginning 2))
8061 c (if (< org-agenda-tags-column 0)
8062 (- (abs org-agenda-tags-column) l)
8063 org-agenda-tags-column))
8064 (delete-region (match-beginning 1) (match-end 1))
8065 (goto-char (match-beginning 1))
8066 (insert (org-add-props
8067 (make-string (max 1 (- c (current-column))) ?\ )
8068 (plist-put (copy-sequence (text-properties-at (point)))
8069 'face nil))))
8070 (goto-char (point-min))
8071 (org-font-lock-add-tag-faces (point-max)))))
8073 (defun org-agenda-priority-up ()
8074 "Increase the priority of line at point, also in Org-mode file."
8075 (interactive)
8076 (org-agenda-priority 'up))
8078 (defun org-agenda-priority-down ()
8079 "Decrease the priority of line at point, also in Org-mode file."
8080 (interactive)
8081 (org-agenda-priority 'down))
8083 (defun org-agenda-priority (&optional force-direction)
8084 "Set the priority of line at point, also in Org-mode file.
8085 This changes the line at point, all other lines in the agenda referring to
8086 the same tree node, and the headline of the tree node in the Org-mode file."
8087 (interactive)
8088 (unless org-enable-priority-commands
8089 (error "Priority commands are disabled"))
8090 (org-agenda-check-no-diary)
8091 (let* ((marker (or (org-get-at-bol 'org-marker)
8092 (org-agenda-error)))
8093 (hdmarker (org-get-at-bol 'org-hd-marker))
8094 (buffer (marker-buffer hdmarker))
8095 (pos (marker-position hdmarker))
8096 (inhibit-read-only t)
8097 newhead)
8098 (org-with-remote-undo buffer
8099 (with-current-buffer buffer
8100 (widen)
8101 (goto-char pos)
8102 (org-show-context 'agenda)
8103 (save-excursion
8104 (and (outline-next-heading)
8105 (org-flag-heading nil))) ; show the next heading
8106 (funcall 'org-priority force-direction)
8107 (end-of-line 1)
8108 (setq newhead (org-get-heading)))
8109 (org-agenda-change-all-lines newhead hdmarker)
8110 (beginning-of-line 1))))
8112 ;; FIXME: should fix the tags property of the agenda line.
8113 (defun org-agenda-set-tags (&optional tag onoff)
8114 "Set tags for the current headline."
8115 (interactive)
8116 (org-agenda-check-no-diary)
8117 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8118 (call-interactively 'org-change-tag-in-region)
8119 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8120 (org-agenda-error)))
8121 (buffer (marker-buffer hdmarker))
8122 (pos (marker-position hdmarker))
8123 (inhibit-read-only t)
8124 newhead)
8125 (org-with-remote-undo buffer
8126 (with-current-buffer buffer
8127 (widen)
8128 (goto-char pos)
8129 (save-excursion
8130 (org-show-context 'agenda))
8131 (save-excursion
8132 (and (outline-next-heading)
8133 (org-flag-heading nil))) ; show the next heading
8134 (goto-char pos)
8135 (if tag
8136 (org-toggle-tag tag onoff)
8137 (call-interactively 'org-set-tags))
8138 (end-of-line 1)
8139 (setq newhead (org-get-heading)))
8140 (org-agenda-change-all-lines newhead hdmarker)
8141 (beginning-of-line 1)))))
8143 (defun org-agenda-set-property ()
8144 "Set a property for the current headline."
8145 (interactive)
8146 (org-agenda-check-no-diary)
8147 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8148 (org-agenda-error)))
8149 (buffer (marker-buffer hdmarker))
8150 (pos (marker-position hdmarker))
8151 (inhibit-read-only t)
8152 newhead)
8153 (org-with-remote-undo buffer
8154 (with-current-buffer buffer
8155 (widen)
8156 (goto-char pos)
8157 (save-excursion
8158 (org-show-context 'agenda))
8159 (save-excursion
8160 (and (outline-next-heading)
8161 (org-flag-heading nil))) ; show the next heading
8162 (goto-char pos)
8163 (call-interactively 'org-set-property)))))
8165 (defun org-agenda-set-effort ()
8166 "Set the effort property for the current headline."
8167 (interactive)
8168 (org-agenda-check-no-diary)
8169 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8170 (org-agenda-error)))
8171 (buffer (marker-buffer hdmarker))
8172 (pos (marker-position hdmarker))
8173 (inhibit-read-only t)
8174 newhead)
8175 (org-with-remote-undo buffer
8176 (with-current-buffer buffer
8177 (widen)
8178 (goto-char pos)
8179 (save-excursion
8180 (org-show-context 'agenda))
8181 (save-excursion
8182 (and (outline-next-heading)
8183 (org-flag-heading nil))) ; show the next heading
8184 (goto-char pos)
8185 (call-interactively 'org-set-effort)
8186 (end-of-line 1)
8187 (setq newhead (org-get-heading)))
8188 (org-agenda-change-all-lines newhead hdmarker))))
8190 (defun org-agenda-toggle-archive-tag ()
8191 "Toggle the archive tag for the current entry."
8192 (interactive)
8193 (org-agenda-check-no-diary)
8194 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8195 (org-agenda-error)))
8196 (buffer (marker-buffer hdmarker))
8197 (pos (marker-position hdmarker))
8198 (inhibit-read-only t)
8199 newhead)
8200 (org-with-remote-undo buffer
8201 (with-current-buffer buffer
8202 (widen)
8203 (goto-char pos)
8204 (org-show-context 'agenda)
8205 (save-excursion
8206 (and (outline-next-heading)
8207 (org-flag-heading nil))) ; show the next heading
8208 (call-interactively 'org-toggle-archive-tag)
8209 (end-of-line 1)
8210 (setq newhead (org-get-heading)))
8211 (org-agenda-change-all-lines newhead hdmarker)
8212 (beginning-of-line 1))))
8214 (defun org-agenda-do-date-later (arg)
8215 (interactive "P")
8216 (cond
8217 ((or (equal arg '(16))
8218 (memq last-command
8219 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8220 (setq this-command 'org-agenda-date-later-minutes)
8221 (org-agenda-date-later-minutes 1))
8222 ((or (equal arg '(4))
8223 (memq last-command
8224 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8225 (setq this-command 'org-agenda-date-later-hours)
8226 (org-agenda-date-later-hours 1))
8228 (org-agenda-date-later (prefix-numeric-value arg)))))
8230 (defun org-agenda-do-date-earlier (arg)
8231 (interactive "P")
8232 (cond
8233 ((or (equal arg '(16))
8234 (memq last-command
8235 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8236 (setq this-command 'org-agenda-date-earlier-minutes)
8237 (org-agenda-date-earlier-minutes 1))
8238 ((or (equal arg '(4))
8239 (memq last-command
8240 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8241 (setq this-command 'org-agenda-date-earlier-hours)
8242 (org-agenda-date-earlier-hours 1))
8244 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8246 (defun org-agenda-date-later (arg &optional what)
8247 "Change the date of this item to ARG day(s) later."
8248 (interactive "p")
8249 (org-agenda-check-type t 'agenda 'timeline)
8250 (org-agenda-check-no-diary)
8251 (let* ((marker (or (org-get-at-bol 'org-marker)
8252 (org-agenda-error)))
8253 (buffer (marker-buffer marker))
8254 (pos (marker-position marker))
8255 cdate today)
8256 (org-with-remote-undo buffer
8257 (with-current-buffer buffer
8258 (widen)
8259 (goto-char pos)
8260 (if (not (org-at-timestamp-p))
8261 (error "Cannot find time stamp"))
8262 (when (and org-agenda-move-date-from-past-immediately-to-today
8263 (equal arg 1)
8264 (or (not what) (eq what 'day))
8265 (not (save-match-data (org-at-date-range-p))))
8266 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8267 cdate (calendar-absolute-from-gregorian
8268 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8269 today (org-today))
8270 (if (> today cdate)
8271 ;; immediately shift to today
8272 (setq arg (- today cdate))))
8273 (org-timestamp-change arg (or what 'day))
8274 (when (and (org-at-date-range-p)
8275 (re-search-backward org-tr-regexp-both (point-at-bol)))
8276 (let ((end org-last-changed-timestamp))
8277 (org-timestamp-change arg (or what 'day))
8278 (setq org-last-changed-timestamp
8279 (concat org-last-changed-timestamp "--" end)))))
8280 (org-agenda-show-new-time marker org-last-changed-timestamp))
8281 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8283 (defun org-agenda-date-earlier (arg &optional what)
8284 "Change the date of this item to ARG day(s) earlier."
8285 (interactive "p")
8286 (org-agenda-date-later (- arg) what))
8288 (defun org-agenda-date-later-minutes (arg)
8289 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8290 (interactive "p")
8291 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8292 (org-agenda-date-later arg 'minute))
8294 (defun org-agenda-date-earlier-minutes (arg)
8295 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8296 (interactive "p")
8297 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8298 (org-agenda-date-earlier arg 'minute))
8300 (defun org-agenda-date-later-hours (arg)
8301 "Change the time of this item, in hour steps."
8302 (interactive "p")
8303 (org-agenda-date-later arg 'hour))
8305 (defun org-agenda-date-earlier-hours (arg)
8306 "Change the time of this item, in hour steps."
8307 (interactive "p")
8308 (org-agenda-date-earlier arg 'hour))
8310 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8311 "Show new date stamp via text properties."
8312 ;; We use text properties to make this undoable
8313 (let ((inhibit-read-only t)
8314 (buffer-invisibility-spec))
8315 (setq stamp (concat " " prefix " => " stamp))
8316 (save-excursion
8317 (goto-char (point-max))
8318 (while (not (bobp))
8319 (when (equal marker (org-get-at-bol 'org-marker))
8320 (org-move-to-column (- (window-width) (length stamp)) t)
8321 (org-agenda-fix-tags-filter-overlays-at (point))
8322 (if (featurep 'xemacs)
8323 ;; Use `duplicable' property to trigger undo recording
8324 (let ((ex (make-extent nil nil))
8325 (gl (make-glyph stamp)))
8326 (set-glyph-face gl 'secondary-selection)
8327 (set-extent-properties
8328 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8329 (insert-extent ex (1- (point)) (point-at-eol)))
8330 (add-text-properties
8331 (1- (point)) (point-at-eol)
8332 (list 'display (org-add-props stamp nil
8333 'face 'secondary-selection))))
8334 (beginning-of-line 1))
8335 (beginning-of-line 0)))))
8337 (defun org-agenda-date-prompt (arg)
8338 "Change the date of this item. Date is prompted for, with default today.
8339 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8340 be used to request time specification in the time stamp."
8341 (interactive "P")
8342 (org-agenda-check-type t 'agenda 'timeline)
8343 (org-agenda-check-no-diary)
8344 (let* ((marker (or (org-get-at-bol 'org-marker)
8345 (org-agenda-error)))
8346 (buffer (marker-buffer marker))
8347 (pos (marker-position marker)))
8348 (org-with-remote-undo buffer
8349 (with-current-buffer buffer
8350 (widen)
8351 (goto-char pos)
8352 (if (not (org-at-timestamp-p t))
8353 (error "Cannot find time stamp"))
8354 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8355 (org-agenda-show-new-time marker org-last-changed-timestamp))
8356 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8358 (defun org-agenda-schedule (arg &optional time)
8359 "Schedule the item at point.
8360 ARG is passed through to `org-schedule'."
8361 (interactive "P")
8362 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8363 (org-agenda-check-no-diary)
8364 (let* ((marker (or (org-get-at-bol 'org-marker)
8365 (org-agenda-error)))
8366 (type (marker-insertion-type marker))
8367 (buffer (marker-buffer marker))
8368 (pos (marker-position marker))
8369 (org-insert-labeled-timestamps-at-point nil)
8371 (set-marker-insertion-type marker t)
8372 (org-with-remote-undo buffer
8373 (with-current-buffer buffer
8374 (widen)
8375 (goto-char pos)
8376 (setq ts (org-schedule arg time)))
8377 (org-agenda-show-new-time marker ts "S"))
8378 (message "Item scheduled for %s" ts)))
8380 (defun org-agenda-deadline (arg &optional time)
8381 "Schedule the item at point.
8382 ARG is passed through to `org-deadline'."
8383 (interactive "P")
8384 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8385 (org-agenda-check-no-diary)
8386 (let* ((marker (or (org-get-at-bol 'org-marker)
8387 (org-agenda-error)))
8388 (buffer (marker-buffer marker))
8389 (pos (marker-position marker))
8390 (org-insert-labeled-timestamps-at-point nil)
8392 (org-with-remote-undo buffer
8393 (with-current-buffer buffer
8394 (widen)
8395 (goto-char pos)
8396 (setq ts (org-deadline arg time)))
8397 (org-agenda-show-new-time marker ts "D"))
8398 (message "Deadline for this item set to %s" ts)))
8400 (defun org-agenda-clock-in (&optional arg)
8401 "Start the clock on the currently selected item."
8402 (interactive "P")
8403 (org-agenda-check-no-diary)
8404 (if (equal arg '(4))
8405 (org-clock-in arg)
8406 (let* ((marker (or (org-get-at-bol 'org-marker)
8407 (org-agenda-error)))
8408 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8409 marker))
8410 (pos (marker-position marker))
8411 newhead)
8412 (org-with-remote-undo (marker-buffer marker)
8413 (with-current-buffer (marker-buffer marker)
8414 (widen)
8415 (goto-char pos)
8416 (org-show-context 'agenda)
8417 (org-show-entry)
8418 (org-cycle-hide-drawers 'children)
8419 (org-clock-in arg)
8420 (setq newhead (org-get-heading)))
8421 (org-agenda-change-all-lines newhead hdmarker)))))
8423 (defun org-agenda-clock-out ()
8424 "Stop the currently running clock."
8425 (interactive)
8426 (unless (marker-buffer org-clock-marker)
8427 (error "No running clock"))
8428 (let ((marker (make-marker)) newhead)
8429 (org-with-remote-undo (marker-buffer org-clock-marker)
8430 (with-current-buffer (marker-buffer org-clock-marker)
8431 (save-excursion
8432 (save-restriction
8433 (widen)
8434 (goto-char org-clock-marker)
8435 (org-back-to-heading t)
8436 (move-marker marker (point))
8437 (org-clock-out)
8438 (setq newhead (org-get-heading))))))
8439 (org-agenda-change-all-lines newhead marker)
8440 (move-marker marker nil)))
8442 (defun org-agenda-clock-cancel (&optional arg)
8443 "Cancel the currently running clock."
8444 (interactive "P")
8445 (unless (marker-buffer org-clock-marker)
8446 (error "No running clock"))
8447 (org-with-remote-undo (marker-buffer org-clock-marker)
8448 (org-clock-cancel)))
8450 (defun org-agenda-clock-goto ()
8451 "Jump to the currently clocked in task within the agenda.
8452 If the currently clocked in task is not listed in the agenda
8453 buffer, display it in another window."
8454 (interactive)
8455 (let (pos)
8456 (mapc (lambda (o)
8457 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8458 (setq pos (overlay-start o))))
8459 (overlays-in (point-min) (point-max)))
8460 (cond (pos (goto-char pos))
8461 ;; If the currently clocked entry is not in the agenda
8462 ;; buffer, we visit it in another window:
8463 (org-clock-current-task
8464 (org-switch-to-buffer-other-window (org-clock-goto)))
8465 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8467 (defun org-agenda-diary-entry-in-org-file ()
8468 "Make a diary entry in the file `org-agenda-diary-file'."
8469 (let (d1 d2 char (text "") dp1 dp2)
8470 (if (equal (buffer-name) "*Calendar*")
8471 (setq d1 (calendar-cursor-to-date t)
8472 d2 (car calendar-mark-ring))
8473 (setq dp1 (get-text-property (point-at-bol) 'day))
8474 (unless dp1 (error "No date defined in current line"))
8475 (setq d1 (calendar-gregorian-from-absolute dp1)
8476 d2 (and (ignore-errors (mark))
8477 (save-excursion
8478 (goto-char (mark))
8479 (setq dp2 (get-text-property (point-at-bol) 'day)))
8480 (calendar-gregorian-from-absolute dp2))))
8481 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8482 (setq char (read-char-exclusive))
8483 (cond
8484 ((equal char ?d)
8485 (setq text (read-string "Day entry: "))
8486 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8487 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8488 ((equal char ?a)
8489 (setq d1 (list (car d1) (nth 1 d1)
8490 (read-number (format "Reference year [%d]: " (nth 2 d1))
8491 (nth 2 d1))))
8492 (setq text (read-string "Anniversary (use %d to show years): "))
8493 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8494 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8495 ((equal char ?b)
8496 (setq text (read-string "Block entry: "))
8497 (unless (and d1 d2 (not (equal d1 d2)))
8498 (error "No block of days selected"))
8499 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8500 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8501 ((equal char ?j)
8502 (org-switch-to-buffer-other-window
8503 (find-file-noselect org-agenda-diary-file))
8504 (require 'org-datetree)
8505 (org-datetree-find-date-create d1)
8506 (org-reveal t))
8507 (t (error "Invalid selection character `%c'" char)))))
8509 (defcustom org-agenda-insert-diary-strategy 'date-tree
8510 "Where in `org-agenda-diary-file' should new entries be added?
8511 Valid values:
8513 date-tree in the date tree, as child of the date
8514 top-level as top-level entries at the end of the file."
8515 :group 'org-agenda
8516 :type '(choice
8517 (const :tag "in a date tree" date-tree)
8518 (const :tag "as top level at end of file" top-level)))
8520 (defcustom org-agenda-insert-diary-extract-time nil
8521 "Non-nil means extract any time specification from the diary entry."
8522 :group 'org-agenda
8523 :version "24.1"
8524 :type 'boolean)
8526 (defcustom org-agenda-bulk-mark-char ">"
8527 "A single-character string to be used as the bulk mark."
8528 :group 'org-agenda
8529 :version "24.1"
8530 :type 'string)
8532 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8533 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8534 If TEXT is not empty, it will become the headline of the new entry, and
8535 the resulting entry will not be shown. When TEXT is empty, switch to
8536 `org-agenda-diary-file' and let the user finish the entry there."
8537 (let ((cw (current-window-configuration)))
8538 (org-switch-to-buffer-other-window
8539 (find-file-noselect org-agenda-diary-file))
8540 (widen)
8541 (goto-char (point-min))
8542 (cond
8543 ((eq type 'anniversary)
8544 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8545 (progn
8546 (or (org-at-heading-p t)
8547 (progn
8548 (outline-next-heading)
8549 (insert "* Anniversaries\n\n")
8550 (beginning-of-line -1)))))
8551 (outline-next-heading)
8552 (org-back-over-empty-lines)
8553 (backward-char 1)
8554 (insert "\n")
8555 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8556 (nth 2 d1) (car d1) (nth 1 d1) text)))
8557 ((eq type 'day)
8558 (let ((org-prefix-has-time t)
8559 (org-agenda-time-leading-zero t)
8560 fmt time time2)
8561 (if org-agenda-insert-diary-extract-time
8562 ;; Use org-agenda-format-item to parse text for a time-range and
8563 ;; remove it. FIXME: This is a hack, we should refactor
8564 ;; that function to make time extraction available separately
8565 (setq fmt (org-agenda-format-item nil text nil nil t)
8566 time (get-text-property 0 'time fmt)
8567 time2 (if (> (length time) 0)
8568 ;; split-string removes trailing ...... if
8569 ;; no end time given. First space
8570 ;; separates time from date.
8571 (concat " " (car (split-string time "\\.")))
8572 nil)
8573 text (get-text-property 0 'txt fmt)))
8574 (if (eq org-agenda-insert-diary-strategy 'top-level)
8575 (org-agenda-insert-diary-as-top-level text)
8576 (require 'org-datetree)
8577 (org-datetree-find-date-create d1)
8578 (org-agenda-insert-diary-make-new-entry text))
8579 (org-insert-time-stamp (org-time-from-absolute
8580 (calendar-absolute-from-gregorian d1))
8581 nil nil nil nil time2))
8582 (end-of-line 0))
8583 ((eq type 'block)
8584 (if (> (calendar-absolute-from-gregorian d1)
8585 (calendar-absolute-from-gregorian d2))
8586 (setq d1 (prog1 d2 (setq d2 d1))))
8587 (if (eq org-agenda-insert-diary-strategy 'top-level)
8588 (org-agenda-insert-diary-as-top-level text)
8589 (require 'org-datetree)
8590 (org-datetree-find-date-create d1)
8591 (org-agenda-insert-diary-make-new-entry text))
8592 (org-insert-time-stamp (org-time-from-absolute
8593 (calendar-absolute-from-gregorian d1)))
8594 (insert "--")
8595 (org-insert-time-stamp (org-time-from-absolute
8596 (calendar-absolute-from-gregorian d2)))
8597 (end-of-line 0)))
8598 (if (string-match "\\S-" text)
8599 (progn
8600 (set-window-configuration cw)
8601 (message "%s entry added to %s"
8602 (capitalize (symbol-name type))
8603 (abbreviate-file-name org-agenda-diary-file)))
8604 (org-reveal t)
8605 (message "Please finish entry here"))))
8607 (defun org-agenda-insert-diary-as-top-level (text)
8608 "Make new entry as a top-level entry at the end of the file.
8609 Add TEXT as headline, and position the cursor in the second line so that
8610 a timestamp can be added there."
8611 (widen)
8612 (goto-char (point-max))
8613 (or (bolp) (insert "\n"))
8614 (insert "* " text "\n")
8615 (if org-adapt-indentation (org-indent-to-column 2)))
8617 (defun org-agenda-insert-diary-make-new-entry (text)
8618 "Make new entry as last child of current entry.
8619 Add TEXT as headline, and position the cursor in the second line so that
8620 a timestamp can be added there."
8621 (let ((org-show-following-heading t)
8622 (org-show-siblings t)
8623 (org-show-hierarchy-above t)
8624 (org-show-entry-below t)
8625 col)
8626 (outline-next-heading)
8627 (org-back-over-empty-lines)
8628 (or (looking-at "[ \t]*$")
8629 (progn (insert "\n") (backward-char 1)))
8630 (org-insert-heading nil t)
8631 (org-do-demote)
8632 (setq col (current-column))
8633 (insert text "\n")
8634 (if org-adapt-indentation (org-indent-to-column col))
8635 (let ((org-show-following-heading t)
8636 (org-show-siblings t)
8637 (org-show-hierarchy-above t)
8638 (org-show-entry-below t))
8639 (org-show-context))))
8641 (defun org-agenda-diary-entry ()
8642 "Make a diary entry, like the `i' command from the calendar.
8643 All the standard commands work: block, weekly etc.
8644 When `org-agenda-diary-file' points to a file,
8645 `org-agenda-diary-entry-in-org-file' is called instead to create
8646 entries in that Org-mode file."
8647 (interactive)
8648 (org-agenda-check-type t 'agenda 'timeline)
8649 (if (not (eq org-agenda-diary-file 'diary-file))
8650 (org-agenda-diary-entry-in-org-file)
8651 (require 'diary-lib)
8652 (let* ((char (progn
8653 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8654 (read-char-exclusive)))
8655 (cmd (cdr (assoc char
8656 '((?d . insert-diary-entry)
8657 (?w . insert-weekly-diary-entry)
8658 (?m . insert-monthly-diary-entry)
8659 (?y . insert-yearly-diary-entry)
8660 (?a . insert-anniversary-diary-entry)
8661 (?b . insert-block-diary-entry)
8662 (?c . insert-cyclic-diary-entry)))))
8663 (oldf (symbol-function 'calendar-cursor-to-date))
8664 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8665 (point (point))
8666 (mark (or (mark t) (point))))
8667 (unless cmd
8668 (error "No command associated with <%c>" char))
8669 (unless (and (get-text-property point 'day)
8670 (or (not (equal ?b char))
8671 (get-text-property mark 'day)))
8672 (error "Don't know which date to use for diary entry"))
8673 ;; We implement this by hacking the `calendar-cursor-to-date' function
8674 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8675 (let ((calendar-mark-ring
8676 (list (calendar-gregorian-from-absolute
8677 (or (get-text-property mark 'day)
8678 (get-text-property point 'day))))))
8679 (unwind-protect
8680 (progn
8681 (fset 'calendar-cursor-to-date
8682 (lambda (&optional error dummy)
8683 (calendar-gregorian-from-absolute
8684 (get-text-property point 'day))))
8685 (call-interactively cmd))
8686 (fset 'calendar-cursor-to-date oldf))))))
8688 (defun org-agenda-execute-calendar-command (cmd)
8689 "Execute a calendar command from the agenda, with the date associated to
8690 the cursor position."
8691 (org-agenda-check-type t 'agenda 'timeline)
8692 (require 'diary-lib)
8693 (unless (get-text-property (point) 'day)
8694 (error "Don't know which date to use for calendar command"))
8695 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8696 (point (point))
8697 (date (calendar-gregorian-from-absolute
8698 (get-text-property point 'day)))
8699 ;; the following 2 vars are needed in the calendar
8700 (displayed-month (car date))
8701 (displayed-year (nth 2 date)))
8702 (unwind-protect
8703 (progn
8704 (fset 'calendar-cursor-to-date
8705 (lambda (&optional error dummy)
8706 (calendar-gregorian-from-absolute
8707 (get-text-property point 'day))))
8708 (call-interactively cmd))
8709 (fset 'calendar-cursor-to-date oldf))))
8711 (defun org-agenda-phases-of-moon ()
8712 "Display the phases of the moon for the 3 months around the cursor date."
8713 (interactive)
8714 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8716 (defun org-agenda-holidays ()
8717 "Display the holidays for the 3 months around the cursor date."
8718 (interactive)
8719 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8721 (defvar calendar-longitude) ; defined in calendar.el
8722 (defvar calendar-latitude) ; defined in calendar.el
8723 (defvar calendar-location-name) ; defined in calendar.el
8725 (defun org-agenda-sunrise-sunset (arg)
8726 "Display sunrise and sunset for the cursor date.
8727 Latitude and longitude can be specified with the variables
8728 `calendar-latitude' and `calendar-longitude'. When called with prefix
8729 argument, latitude and longitude will be prompted for."
8730 (interactive "P")
8731 (require 'solar)
8732 (let ((calendar-longitude (if arg nil calendar-longitude))
8733 (calendar-latitude (if arg nil calendar-latitude))
8734 (calendar-location-name
8735 (if arg "the given coordinates" calendar-location-name)))
8736 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8738 (defun org-agenda-goto-calendar ()
8739 "Open the Emacs calendar with the date at the cursor."
8740 (interactive)
8741 (org-agenda-check-type t 'agenda 'timeline)
8742 (let* ((day (or (get-text-property (point) 'day)
8743 (error "Don't know which date to open in calendar")))
8744 (date (calendar-gregorian-from-absolute day))
8745 (calendar-move-hook nil)
8746 (calendar-view-holidays-initially-flag nil)
8747 (calendar-view-diary-initially-flag nil))
8748 (calendar)
8749 (calendar-goto-date date)))
8751 ;;;###autoload
8752 (defun org-calendar-goto-agenda ()
8753 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8754 This is a command that has to be installed in `calendar-mode-map'."
8755 (interactive)
8756 (org-agenda-list nil (calendar-absolute-from-gregorian
8757 (calendar-cursor-to-date))
8758 nil))
8760 (defun org-agenda-convert-date ()
8761 (interactive)
8762 (org-agenda-check-type t 'agenda 'timeline)
8763 (let ((day (get-text-property (point) 'day))
8764 date s)
8765 (unless day
8766 (error "Don't know which date to convert"))
8767 (setq date (calendar-gregorian-from-absolute day))
8768 (setq s (concat
8769 "Gregorian: " (calendar-date-string date) "\n"
8770 "ISO: " (calendar-iso-date-string date) "\n"
8771 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8772 "Julian: " (calendar-julian-date-string date) "\n"
8773 "Astron. JD: " (calendar-astro-date-string date)
8774 " (Julian date number at noon UTC)\n"
8775 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8776 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8777 "French: " (calendar-french-date-string date) "\n"
8778 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8779 "Mayan: " (calendar-mayan-date-string date) "\n"
8780 "Coptic: " (calendar-coptic-date-string date) "\n"
8781 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8782 "Persian: " (calendar-persian-date-string date) "\n"
8783 "Chinese: " (calendar-chinese-date-string date) "\n"))
8784 (with-output-to-temp-buffer "*Dates*"
8785 (princ s))
8786 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8788 ;;; Bulk commands
8790 (defun org-agenda-bulk-marked-p ()
8791 (eq (get-char-property (point-at-bol) 'type)
8792 'org-marked-entry-overlay))
8794 (defun org-agenda-bulk-mark (&optional arg)
8795 "Mark the entry at point for future bulk action."
8796 (interactive "p")
8797 (dotimes (i (or arg 1))
8798 (unless (org-get-at-bol 'org-agenda-diary-link)
8799 (let* ((m (org-get-at-bol 'org-hd-marker))
8801 (unless (org-agenda-bulk-marked-p)
8802 (unless m (error "Nothing to mark at point"))
8803 (push m org-agenda-bulk-marked-entries)
8804 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8805 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8806 (org-get-todo-face "TODO")
8807 'evaporate)
8808 (overlay-put ov 'type 'org-marked-entry-overlay))
8809 (beginning-of-line 2)
8810 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8811 (beginning-of-line 2))
8812 (message "%d entries marked for bulk action"
8813 (length org-agenda-bulk-marked-entries))))))
8815 (defun org-agenda-bulk-mark-all ()
8816 "Mark all entries for future agenda bulk action."
8817 (interactive)
8818 (org-agenda-bulk-mark-regexp "."))
8820 (defun org-agenda-bulk-mark-regexp (regexp)
8821 "Mark entries matching REGEXP for future agenda bulk action."
8822 (interactive "sMark entries matching regexp: ")
8823 (let ((entries-marked 0))
8824 (save-excursion
8825 (goto-char (point-min))
8826 (goto-char (next-single-property-change (point) 'txt))
8827 (while (re-search-forward regexp nil t)
8828 (when (string-match regexp (get-text-property (point) 'txt))
8829 (setq entries-marked (1+ entries-marked))
8830 (call-interactively 'org-agenda-bulk-mark))))
8831 (if (not entries-marked)
8832 (message "No entry matching this regexp."))))
8834 (defun org-agenda-bulk-unmark (&optional arg)
8835 "Unmark the entry at point for future bulk action."
8836 (interactive "P")
8837 (if arg
8838 (org-agenda-bulk-unmark-all)
8839 (cond ((org-agenda-bulk-marked-p)
8840 (org-agenda-bulk-remove-overlays
8841 (point-at-bol) (+ 2 (point-at-bol)))
8842 (setq org-agenda-bulk-marked-entries
8843 (delete (org-get-at-bol 'org-hd-marker)
8844 org-agenda-bulk-marked-entries))
8845 (beginning-of-line 2)
8846 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8847 (beginning-of-line 2))
8848 (message "%d entries left marked for bulk action"
8849 (length org-agenda-bulk-marked-entries)))
8850 (t (message "No entry to unmark here")))))
8852 (defun org-agenda-bulk-toggle ()
8853 "Toggle marking the entry at point for bulk action."
8854 (interactive)
8855 (if (org-agenda-bulk-marked-p)
8856 (org-agenda-bulk-unmark)
8857 (org-agenda-bulk-mark)))
8859 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8860 "Remove the mark overlays between BEG and END in the agenda buffer.
8861 BEG and END default to the buffer limits.
8863 This only removes the overlays, it does not remove the markers
8864 from the list in `org-agenda-bulk-marked-entries'."
8865 (interactive)
8866 (mapc (lambda (ov)
8867 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8868 (delete-overlay ov)))
8869 (overlays-in (or beg (point-min)) (or end (point-max)))))
8871 (defun org-agenda-bulk-unmark-all ()
8872 "Remove all marks in the agenda buffer.
8873 This will remove the markers and the overlays."
8874 (interactive)
8875 (if (null org-agenda-bulk-marked-entries)
8876 (message "No entry to unmark")
8877 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8878 (setq org-agenda-bulk-marked-entries nil)
8879 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8881 (defcustom org-agenda-persistent-marks nil
8882 "Non-nil means marked items will stay marked after a bulk action.
8883 You can toggle this interactively by typing `p' when prompted for a
8884 bulk action."
8885 :group 'org-agenda
8886 :version "24.1"
8887 :type 'boolean)
8889 (defun org-agenda-bulk-action (&optional arg)
8890 "Execute an remote-editing action on all marked entries.
8891 The prefix arg is passed through to the command if possible."
8892 (interactive "P")
8893 ;; Make sure we have markers, and only valid ones
8894 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8895 (mapc
8896 (lambda (m)
8897 (unless (and (markerp m)
8898 (marker-buffer m)
8899 (buffer-live-p (marker-buffer m))
8900 (marker-position m))
8901 (error "Marker %s for bulk command is invalid" m)))
8902 org-agenda-bulk-marked-entries)
8904 ;; Prompt for the bulk command
8905 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8906 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
8907 "[S]catter [f]unction "
8908 (when org-agenda-bulk-custom-functions
8909 (concat " Custom: ["
8910 (mapconcat (lambda(f) (char-to-string (car f)))
8911 org-agenda-bulk-custom-functions "")
8912 "]"))))
8913 (catch 'exit
8914 (let* ((action (read-char-exclusive))
8915 (org-log-refile (if org-log-refile 'time nil))
8916 (entries (reverse org-agenda-bulk-marked-entries))
8917 (org-overriding-default-time
8918 (if (get-text-property (point) 'org-agenda-date-header)
8919 (org-get-cursor-date)))
8920 redo-at-end
8921 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8922 (cond
8923 ((equal action ?p)
8924 (let ((org-agenda-persistent-marks
8925 (not org-agenda-persistent-marks)))
8926 (org-agenda-bulk-action)
8927 (throw 'exit nil)))
8929 ((equal action ?$)
8930 (setq cmd '(org-agenda-archive)))
8932 ((equal action ?A)
8933 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8935 ((member action '(?r ?w))
8936 (setq rfloc (org-refile-get-location
8937 "Refile to"
8938 (marker-buffer (car entries))
8939 org-refile-allow-creating-parent-nodes))
8940 (if (nth 3 rfloc)
8941 (setcar (nthcdr 3 rfloc)
8942 (move-marker (make-marker) (nth 3 rfloc)
8943 (or (get-file-buffer (nth 1 rfloc))
8944 (find-buffer-visiting (nth 1 rfloc))
8945 (error "This should not happen")))))
8947 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8948 redo-at-end t))
8950 ((equal action ?t)
8951 (setq state (org-icompleting-read
8952 "Todo state: "
8953 (with-current-buffer (marker-buffer (car entries))
8954 (mapcar 'list org-todo-keywords-1))))
8955 (setq cmd `(let ((org-inhibit-blocking t)
8956 (org-inhibit-logging 'note))
8957 (org-agenda-todo ,state))))
8959 ((memq action '(?- ?+))
8960 (setq tag (org-icompleting-read
8961 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8962 (with-current-buffer (marker-buffer (car entries))
8963 (delq nil
8964 (mapcar (lambda (x)
8965 (if (stringp (car x)) x)) org-tag-alist)))))
8966 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8968 ((memq action '(?s ?d))
8969 (let* ((time
8970 (unless arg
8971 (org-read-date
8972 nil nil nil
8973 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
8974 org-overriding-default-time)))
8975 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8976 (setq cmd `(eval '(,c1 arg ,time)))))
8978 ((equal action ?S)
8979 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8980 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8981 (let ((days (read-number
8982 (format "Scatter tasks across how many %sdays: "
8983 (if arg "week" "")) 7)))
8984 (setq cmd
8985 `(let ((distance (1+ (random ,days))))
8986 (if arg
8987 (let ((dist distance)
8988 (day-of-week
8989 (calendar-day-of-week
8990 (calendar-gregorian-from-absolute (org-today)))))
8991 (dotimes (i (1+ dist))
8992 (while (member day-of-week org-agenda-weekend-days)
8993 (incf distance)
8994 (incf day-of-week)
8995 (if (= day-of-week 7)
8996 (setq day-of-week 0)))
8997 (incf day-of-week)
8998 (if (= day-of-week 7)
8999 (setq day-of-week 0)))))
9000 ;; silently fail when try to replan a sexp entry
9001 (condition-case nil
9002 (let* ((date (calendar-gregorian-from-absolute
9003 (+ (org-today) distance)))
9004 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9005 (nth 2 date))))
9006 (org-agenda-schedule nil time))
9007 (error nil)))))))
9009 ((assoc action org-agenda-bulk-custom-functions)
9010 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9011 redo-at-end t))
9013 ((equal action ?f)
9014 (setq cmd (list (intern
9015 (org-icompleting-read "Function: "
9016 obarray 'fboundp t nil nil)))))
9018 (t (error "Invalid bulk action")))
9020 ;; Sort the markers, to make sure that parents are handled before children
9021 (setq entries (sort entries
9022 (lambda (a b)
9023 (cond
9024 ((equal (marker-buffer a) (marker-buffer b))
9025 (< (marker-position a) (marker-position b)))
9027 (string< (buffer-name (marker-buffer a))
9028 (buffer-name (marker-buffer b))))))))
9030 ;; Now loop over all markers and apply cmd
9031 (while (setq e (pop entries))
9032 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9033 (if (not pos)
9034 (progn (message "Skipping removed entry at %s" e)
9035 (setq cntskip (1+ cntskip)))
9036 (goto-char pos)
9037 (let (org-loop-over-headlines-in-active-region)
9038 (eval cmd))
9039 (setq cnt (1+ cnt))))
9040 (when redo-at-end (org-agenda-redo))
9041 (unless org-agenda-persistent-marks
9042 (org-agenda-bulk-unmark-all))
9043 (message "Acted on %d entries%s%s"
9045 (if (= cntskip 0)
9047 (format ", skipped %d (disappeared before their turn)"
9048 cntskip))
9049 (if (not org-agenda-persistent-marks)
9050 "" " (kept marked)"))))))
9052 (defun org-agenda-capture ()
9053 "Call `org-capture' with the date at point."
9054 (interactive)
9055 (if (not (eq major-mode 'org-agenda-mode))
9056 (error "You cannot do this outside of agenda buffers")
9057 (let ((org-overriding-default-time
9058 (org-get-cursor-date)))
9059 (call-interactively 'org-capture))))
9061 ;;; Flagging notes
9063 (defun org-agenda-show-the-flagging-note ()
9064 "Display the flagging note in the other window.
9065 When called a second time in direct sequence, offer to remove the FLAGGING
9066 tag and (if present) the flagging note."
9067 (interactive)
9068 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9069 (win (selected-window))
9070 note heading newhead)
9071 (unless hdmarker
9072 (error "No linked entry at point"))
9073 (if (and (eq this-command last-command)
9074 (y-or-n-p "Unflag and remove any flagging note? "))
9075 (progn
9076 (org-agenda-remove-flag hdmarker)
9077 (let ((win (get-buffer-window "*Flagging Note*")))
9078 (and win (delete-window win)))
9079 (message "Entry unflagged"))
9080 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9081 (unless note
9082 (error "No flagging note"))
9083 (org-kill-new note)
9084 (org-switch-to-buffer-other-window "*Flagging Note*")
9085 (erase-buffer)
9086 (insert note)
9087 (goto-char (point-min))
9088 (while (re-search-forward "\\\\n" nil t)
9089 (replace-match "\n" t t))
9090 (goto-char (point-min))
9091 (select-window win)
9092 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9094 (defun org-agenda-remove-flag (marker)
9095 "Remove the FLAGGED tag and any flagging note in the entry."
9096 (let (newhead)
9097 (org-with-point-at marker
9098 (org-toggle-tag "FLAGGED" 'off)
9099 (org-entry-delete nil "THEFLAGGINGNOTE")
9100 (setq newhead (org-get-heading)))
9101 (org-agenda-change-all-lines newhead marker)
9102 (message "Entry unflagged")))
9104 (defun org-agenda-get-any-marker (&optional pos)
9105 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9106 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9108 ;;; Appointment reminders
9110 (defvar appt-time-msg-list) ; defined in appt.el
9112 ;;;###autoload
9113 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9114 "Activate appointments found in `org-agenda-files'.
9115 With a \\[universal-argument] prefix, refresh the list of
9116 appointments.
9118 If FILTER is t, interactively prompt the user for a regular
9119 expression, and filter out entries that don't match it.
9121 If FILTER is a string, use this string as a regular expression
9122 for filtering entries out.
9124 If FILTER is a function, filter out entries against which
9125 calling the function returns nil. This function takes one
9126 argument: an entry from `org-agenda-get-day-entries'.
9128 FILTER can also be an alist with the car of each cell being
9129 either 'headline or 'category. For example:
9131 '((headline \"IMPORTANT\")
9132 (category \"Work\"))
9134 will only add headlines containing IMPORTANT or headlines
9135 belonging to the \"Work\" category.
9137 ARGS are symbols indicating what kind of entries to consider.
9138 By default `org-agenda-to-appt' will use :deadline, :scheduled
9139 and :timestamp entries. See the docstring of `org-diary' for
9140 details and examples.
9142 If an entry as a APPT_WARNTIME property, its value will be used
9143 to override `appt-message-warning-time'."
9144 (interactive "P")
9145 (if refresh (setq appt-time-msg-list nil))
9146 (if (eq filter t)
9147 (setq filter (read-from-minibuffer "Regexp filter: ")))
9148 (let* ((cnt 0) ; count added events
9149 (scope (or args '(:deadline :scheduled :timestamp)))
9150 (org-agenda-new-buffers nil)
9151 (org-deadline-warning-days 0)
9152 ;; Do not use `org-today' here because appt only takes
9153 ;; time and without date as argument, so it may pass wrong
9154 ;; information otherwise
9155 (today (org-date-to-gregorian
9156 (time-to-days (current-time))))
9157 (org-agenda-restrict nil)
9158 (files (org-agenda-files 'unrestricted)) entries file
9159 (org-agenda-buffer nil))
9160 ;; Get all entries which may contain an appt
9161 (org-agenda-prepare-buffers files)
9162 (while (setq file (pop files))
9163 (setq entries
9164 (delq nil
9165 (append entries
9166 (apply 'org-agenda-get-day-entries
9167 file today scope)))))
9168 ;; Map thru entries and find if we should filter them out
9169 (mapc
9170 (lambda(x)
9171 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9172 (cat (get-text-property 1 'org-category x))
9173 (tod (get-text-property 1 'time-of-day x))
9174 (ok (or (null filter)
9175 (and (stringp filter) (string-match filter evt))
9176 (and (functionp filter) (funcall filter x))
9177 (and (listp filter)
9178 (let ((cat-filter (cadr (assoc 'category filter)))
9179 (evt-filter (cadr (assoc 'headline filter))))
9180 (or (and (stringp cat-filter)
9181 (string-match cat-filter cat))
9182 (and (stringp evt-filter)
9183 (string-match evt-filter evt)))))))
9184 (wrn (get-text-property 1 'warntime x)))
9185 ;; FIXME: Shall we remove text-properties for the appt text?
9186 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9187 (when (and ok tod)
9188 (setq tod (concat "00" (number-to-string tod))
9189 tod (when (string-match
9190 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9191 (concat (match-string 1 tod) ":"
9192 (match-string 2 tod))))
9193 (if (version< emacs-version "23.3")
9194 (appt-add tod evt)
9195 (appt-add tod evt wrn))
9196 (setq cnt (1+ cnt))))) entries)
9197 (org-release-buffers org-agenda-new-buffers)
9198 (if (eq cnt 0)
9199 (message "No event to add")
9200 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9202 (defun org-agenda-todayp (date)
9203 "Does DATE mean today, when considering `org-extend-today-until'?"
9204 (let ((today (org-today))
9205 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9206 date)))
9207 (eq date today)))
9209 (defun org-agenda-todo-yesterday (&optional arg)
9210 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9211 (interactive "P")
9212 (let* ((hour (third (decode-time
9213 (org-current-time))))
9214 (org-extend-today-until (1+ hour)))
9215 (org-agenda-todo arg)))
9217 (provide 'org-agenda)
9219 ;;; org-agenda.el ends here