Avoid calling `goto-line' from lisp programs
[org-mode.git] / lisp / org-agenda.el
blob0600e71f3b4fdc31527ef9edd952680091f3bfd7
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 6.29trans
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl)
36 (require 'calendar))
38 (declare-function diary-add-to-list "diary-lib"
39 (date string specifier &optional marker globcolor literal))
40 (declare-function calendar-absolute-from-iso "cal-iso" (date))
41 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
42 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
43 (declare-function calendar-check-holidays "holidays" (date))
44 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
45 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
46 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
47 (declare-function calendar-french-date-string "cal-french" (&optional date))
48 (declare-function calendar-goto-date "cal-move" (date))
49 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
50 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
51 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
52 (declare-function calendar-iso-from-absolute "cal-iso" (date))
53 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
54 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
55 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
56 (declare-function org-columns-quit "org-colview" ())
57 (defvar calendar-mode-map)
59 ;; Defined somewhere in this file, but used before definition.
60 (defvar org-agenda-buffer-name)
61 (defvar org-agenda-overriding-header)
62 (defvar entry)
63 (defvar date)
64 (defvar org-agenda-undo-list)
65 (defvar org-agenda-pending-undo-list)
66 (defvar original-date) ; dynamically scoped, calendar.el does scope this
68 (defcustom org-agenda-confirm-kill 1
69 "When set, remote killing from the agenda buffer needs confirmation.
70 When t, a confirmation is always needed. When a number N, confirmation is
71 only needed when the text to be killed contains more than N non-white lines."
72 :group 'org-agenda
73 :type '(choice
74 (const :tag "Never" nil)
75 (const :tag "Always" t)
76 (integer :tag "When more than N lines")))
78 (defcustom org-agenda-compact-blocks nil
79 "Non-nil means, make the block agenda more compact.
80 This is done by leaving out unnecessary lines."
81 :group 'org-agenda
82 :type 'boolean)
84 (defcustom org-agenda-block-separator ?=
85 "The separator between blocks in the agenda.
86 If this is a string, it will be used as the separator, with a newline added.
87 If it is a character, it will be repeated to fill the window width."
88 :group 'org-agenda
89 :type '(choice
90 (character)
91 (string)))
93 (defgroup org-agenda-export nil
94 "Options concerning exporting agenda views in Org-mode."
95 :tag "Org Agenda Export"
96 :group 'org-agenda)
98 (defcustom org-agenda-with-colors t
99 "Non-nil means, use colors in agenda views."
100 :group 'org-agenda-export
101 :type 'boolean)
103 (defcustom org-agenda-exporter-settings nil
104 "Alist of variable/value pairs that should be active during agenda export.
105 This is a good place to set options for ps-print and for htmlize.
106 Note that the way this is implemented, the values will be evaluated
107 before assigned to the variables. So make sure to quote values you do
108 *not* want evaluated, for example
110 (setq org-agenda-exporter-settings
111 '((ps-print-color-p 'black-white)))"
112 :group 'org-agenda-export
113 :type '(repeat
114 (list
115 (variable)
116 (sexp :tag "Value"))))
118 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
119 "Hook run in temporary buffer before writing it to an export file.
120 A useful function is `org-agenda-add-entry-text'."
121 :group 'org-agenda-export
122 :type 'hook
123 :options '(org-agenda-add-entry-text))
125 (defcustom org-agenda-add-entry-text-maxlines 0
126 "Maximum number of entry text lines to be added to agenda.
127 This is only relevant when `org-agenda-add-entry-text' is part of
128 `org-agenda-before-write-hook', which it is by default.
129 When this is 0, nothing will happen. When it is greater than 0, it
130 specifies the maximum number of lines that will be added for each entry
131 that is listed in the agenda view.
133 Note that this variable is not used during display, only when exporting
134 the agenda. For agenda display, see org-agenda-entry-text-mode and the
135 variable `org-agenda-entry-text-maxlines'."
136 :group 'org-agenda
137 :type 'integer)
139 (defcustom org-agenda-add-entry-text-descriptive-links t
140 "Non-nil means, export org-links as descriptive links in agenda added text.
141 This variable applies to the text added to the agenda when
142 `org-agenda-add-entry-text-maxlines' is larger than 0.
143 When this variable nil, the URL will (also) be shown."
144 :group 'org-agenda
145 :type 'boolean)
147 (defcustom org-agenda-export-html-style ""
148 "The style specification for exported HTML Agenda files.
149 If this variable contains a string, it will replace the default <style>
150 section as produced by `htmlize'.
151 Since there are different ways of setting style information, this variable
152 needs to contain the full HTML structure to provide a style, including the
153 surrounding HTML tags. The style specifications should include definitions
154 the fonts used by the agenda, here is an example:
156 <style type=\"text/css\">
157 p { font-weight: normal; color: gray; }
158 .org-agenda-structure {
159 font-size: 110%;
160 color: #003399;
161 font-weight: 600;
163 .org-todo {
164 color: #cc6666;
165 font-weight: bold;
167 .org-agenda-done {
168 color: #339933;
170 .org-done {
171 color: #339933;
173 .title { text-align: center; }
174 .todo, .deadline { color: red; }
175 .done { color: green; }
176 </style>
178 or, if you want to keep the style in a file,
180 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
182 As the value of this option simply gets inserted into the HTML <head> header,
183 you can \"misuse\" it to also add other text to the header. However,
184 <style>...</style> is required, if not present the variable will be ignored."
185 :group 'org-agenda-export
186 :group 'org-export-html
187 :type 'string)
189 (defgroup org-agenda-custom-commands nil
190 "Options concerning agenda views in Org-mode."
191 :tag "Org Agenda Custom Commands"
192 :group 'org-agenda)
194 (defconst org-sorting-choice
195 '(choice
196 (const time-up) (const time-down)
197 (const category-keep) (const category-up) (const category-down)
198 (const tag-down) (const tag-up)
199 (const priority-up) (const priority-down)
200 (const todo-state-up) (const todo-state-down)
201 (const effort-up) (const effort-down)
202 (const user-defined-up) (const user-defined-down))
203 "Sorting choices.")
205 (defconst org-agenda-custom-commands-local-options
206 `(repeat :tag "Local settings for this command. Remember to quote values"
207 (choice :tag "Setting"
208 (list :tag "Heading for this block"
209 (const org-agenda-overriding-header)
210 (string :tag "Headline"))
211 (list :tag "Files to be searched"
212 (const org-agenda-files)
213 (list
214 (const :format "" quote)
215 (repeat (file))))
216 (list :tag "Sorting strategy"
217 (const org-agenda-sorting-strategy)
218 (list
219 (const :format "" quote)
220 (repeat
221 ,org-sorting-choice)))
222 (list :tag "Prefix format"
223 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
224 (string))
225 (list :tag "Number of days in agenda"
226 (const org-agenda-ndays)
227 (integer :value 1))
228 (list :tag "Fixed starting date"
229 (const org-agenda-start-day)
230 (string :value "2007-11-01"))
231 (list :tag "Start on day of week"
232 (const org-agenda-start-on-weekday)
233 (choice :value 1
234 (const :tag "Today" nil)
235 (integer :tag "Weekday No.")))
236 (list :tag "Include data from diary"
237 (const org-agenda-include-diary)
238 (boolean))
239 (list :tag "Deadline Warning days"
240 (const org-deadline-warning-days)
241 (integer :value 1))
242 (list :tag "Tags filter preset"
243 (const org-agenda-filter-preset)
244 (list
245 (const :format "" quote)
246 (repeat
247 (string :tag "+tag or -tag"))))
248 (list :tag "Standard skipping condition"
249 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
250 (const org-agenda-skip-function)
251 (list
252 (const :format "" quote)
253 (list
254 (choice
255 :tag "Skipping range"
256 (const :tag "Skip entry" org-agenda-skip-entry-if)
257 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
258 (repeat :inline t :tag "Conditions for skipping"
259 (choice
260 :tag "Condition type"
261 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
262 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
263 (const :tag "scheduled" 'scheduled)
264 (const :tag "not scheduled" 'notscheduled)
265 (const :tag "deadline" 'deadline)
266 (const :tag "no deadline" 'notdeadline)
267 (const :tag "timestamp" 'timestamp)
268 (const :tag "no timestamp" 'nottimestamp))))))
269 (list :tag "Non-standard skipping condition"
270 :value (org-agenda-skip-function)
271 (const org-agenda-skip-function)
272 (sexp :tag "Function or form (quoted!)"))
273 (list :tag "Any variable"
274 (variable :tag "Variable")
275 (sexp :tag "Value (sexp)"))))
276 "Selection of examples for agenda command settings.
277 This will be spliced into the custom type of
278 `org-agenda-custom-commands'.")
281 (defcustom org-agenda-custom-commands nil
282 "Custom commands for the agenda.
283 These commands will be offered on the splash screen displayed by the
284 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
286 (key desc type match settings files)
288 key The key (one or more characters as a string) to be associated
289 with the command.
290 desc A description of the command, when omitted or nil, a default
291 description is built using MATCH.
292 type The command type, any of the following symbols:
293 agenda The daily/weekly agenda.
294 todo Entries with a specific TODO keyword, in all agenda files.
295 search Entries containing search words entry or headline.
296 tags Tags/Property/TODO match in all agenda files.
297 tags-todo Tags/P/T match in all agenda files, TODO entries only.
298 todo-tree Sparse tree of specific TODO keyword in *current* file.
299 tags-tree Sparse tree with all tags matches in *current* file.
300 occur-tree Occur sparse tree for *current* file.
301 ... A user-defined function.
302 match What to search for:
303 - a single keyword for TODO keyword searches
304 - a tags match expression for tags searches
305 - a word search expression for text searches.
306 - a regular expression for occur searches
307 For all other commands, this should be the empty string.
308 settings A list of option settings, similar to that in a let form, so like
309 this: ((opt1 val1) (opt2 val2) ...). The values will be
310 evaluated at the moment of execution, so quote them when needed.
311 files A list of files file to write the produced agenda buffer to
312 with the command `org-store-agenda-views'.
313 If a file name ends in \".html\", an HTML version of the buffer
314 is written out. If it ends in \".ps\", a postscript version is
315 produced. Otherwise, only the plain text is written to the file.
317 You can also define a set of commands, to create a composite agenda buffer.
318 In this case, an entry looks like this:
320 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
322 where
324 desc A description string to be displayed in the dispatcher menu.
325 cmd An agenda command, similar to the above. However, tree commands
326 are no allowed, but instead you can get agenda and global todo list.
327 So valid commands for a set are:
328 (agenda \"\" settings)
329 (alltodo \"\" settings)
330 (stuck \"\" settings)
331 (todo \"match\" settings files)
332 (search \"match\" settings files)
333 (tags \"match\" settings files)
334 (tags-todo \"match\" settings files)
336 Each command can carry a list of options, and another set of options can be
337 given for the whole set of commands. Individual command options take
338 precedence over the general options.
340 When using several characters as key to a command, the first characters
341 are prefix commands. For the dispatcher to display useful information, you
342 should provide a description for the prefix, like
344 (setq org-agenda-custom-commands
345 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
346 (\"hl\" tags \"+HOME+Lisa\")
347 (\"hp\" tags \"+HOME+Peter\")
348 (\"hk\" tags \"+HOME+Kim\")))"
349 :group 'org-agenda-custom-commands
350 :type `(repeat
351 (choice :value ("x" "Describe command here" tags "" nil)
352 (list :tag "Single command"
353 (string :tag "Access Key(s) ")
354 (option (string :tag "Description"))
355 (choice
356 (const :tag "Agenda" agenda)
357 (const :tag "TODO list" alltodo)
358 (const :tag "Search words" search)
359 (const :tag "Stuck projects" stuck)
360 (const :tag "Tags/Property match (all agenda files)" tags)
361 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
362 (const :tag "TODO keyword search (all agenda files)" todo)
363 (const :tag "Tags sparse tree (current buffer)" tags-tree)
364 (const :tag "TODO keyword tree (current buffer)" todo-tree)
365 (const :tag "Occur tree (current buffer)" occur-tree)
366 (sexp :tag "Other, user-defined function"))
367 (string :tag "Match (only for some commands)")
368 ,org-agenda-custom-commands-local-options
369 (option (repeat :tag "Export" (file :tag "Export to"))))
370 (list :tag "Command series, all agenda files"
371 (string :tag "Access Key(s)")
372 (string :tag "Description ")
373 (repeat :tag "Component"
374 (choice
375 (list :tag "Agenda"
376 (const :format "" agenda)
377 (const :tag "" :format "" "")
378 ,org-agenda-custom-commands-local-options)
379 (list :tag "TODO list (all keywords)"
380 (const :format "" alltodo)
381 (const :tag "" :format "" "")
382 ,org-agenda-custom-commands-local-options)
383 (list :tag "Search words"
384 (const :format "" search)
385 (string :tag "Match")
386 ,org-agenda-custom-commands-local-options)
387 (list :tag "Stuck projects"
388 (const :format "" stuck)
389 (const :tag "" :format "" "")
390 ,org-agenda-custom-commands-local-options)
391 (list :tag "Tags search"
392 (const :format "" tags)
393 (string :tag "Match")
394 ,org-agenda-custom-commands-local-options)
395 (list :tag "Tags search, TODO entries only"
396 (const :format "" tags-todo)
397 (string :tag "Match")
398 ,org-agenda-custom-commands-local-options)
399 (list :tag "TODO keyword search"
400 (const :format "" todo)
401 (string :tag "Match")
402 ,org-agenda-custom-commands-local-options)
403 (list :tag "Other, user-defined function"
404 (symbol :tag "function")
405 (string :tag "Match")
406 ,org-agenda-custom-commands-local-options)))
408 (repeat :tag "Settings for entire command set"
409 (list (variable :tag "Any variable")
410 (sexp :tag "Value")))
411 (option (repeat :tag "Export" (file :tag "Export to"))))
412 (cons :tag "Prefix key documentation"
413 (string :tag "Access Key(s)")
414 (string :tag "Description ")))))
416 (defcustom org-agenda-query-register ?o
417 "The register holding the current query string.
418 The purpose of this is that if you construct a query string interactively,
419 you can then use it to define a custom command."
420 :group 'org-agenda-custom-commands
421 :type 'character)
423 (defcustom org-stuck-projects
424 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
425 "How to identify stuck projects.
426 This is a list of four items:
427 1. A tags/todo/property matcher string that is used to identify a project.
428 See the manual for a description of tag and property searches.
429 The entire tree below a headline matched by this is considered one project.
430 2. A list of TODO keywords identifying non-stuck projects.
431 If the project subtree contains any headline with one of these todo
432 keywords, the project is considered to be not stuck. If you specify
433 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
434 3. A list of tags identifying non-stuck projects.
435 If the project subtree contains any headline with one of these tags,
436 the project is considered to be not stuck. If you specify \"*\" as
437 a tag, any tag will mark the project unstuck. Note that this is about
438 the explicit presence of a tag somewhere in the subtree, inherited
439 tags to not count here. If inherited tags make a project not stuck,
440 use \"-TAG\" in the tags part of the matcher under (1.) above.
441 4. An arbitrary regular expression matching non-stuck projects.
443 If the project turns out to be not stuck, search continues also in the
444 subtree to see if any of the subtasks have project status.
446 See also the variable `org-tags-match-list-sublevels' which applies
447 to projects matched by this search as well.
449 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
450 or `C-c a #' to produce the list."
451 :group 'org-agenda-custom-commands
452 :type '(list
453 (string :tag "Tags/TODO match to identify a project")
454 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
455 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
456 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
458 (defcustom org-agenda-filter-effort-default-operator "<"
459 "The default operator for effort estimate filtering.
460 If you select an effort estimate limit without first pressing an operator,
461 this one will be used."
462 :group 'org-agenda-custom-commands
463 :type '(choice (const :tag "less or equal" "<")
464 (const :tag "greater or equal"">")
465 (const :tag "equal" "=")))
467 (defgroup org-agenda-skip nil
468 "Options concerning skipping parts of agenda files."
469 :tag "Org Agenda Skip"
470 :group 'org-agenda)
471 (defgroup org-agenda-daily/weekly nil
472 "Options concerning the daily/weekly agenda."
473 :tag "Org Agenda Daily/Weekly"
474 :group 'org-agenda)
475 (defgroup org-agenda-todo-list nil
476 "Options concerning the global todo list agenda view."
477 :tag "Org Agenda Todo List"
478 :group 'org-agenda)
479 (defgroup org-agenda-match-view nil
480 "Options concerning the general tags/property/todo match agenda view."
481 :tag "Org Agenda Match View"
482 :group 'org-agenda)
484 (defvar org-agenda-archives-mode nil
485 "Non-nil means, the agenda will include archived items.
486 If this is the symbol `trees', trees in the selected agenda scope
487 that are marked with the ARCHIVE tag will be included anyway. When this is
488 t, also all archive files associated with the current selection of agenda
489 files will be included.")
491 (defcustom org-agenda-skip-comment-trees t
492 "Non-nil means, skip trees that start with the COMMENT keyword.
493 When nil, these trees are also scanned by agenda commands."
494 :group 'org-agenda-skip
495 :type 'boolean)
497 (defcustom org-agenda-todo-list-sublevels t
498 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
499 When nil, the sublevels of a TODO entry are not checked, resulting in
500 potentially much shorter TODO lists."
501 :group 'org-agenda-skip
502 :group 'org-agenda-todo-list
503 :type 'boolean)
505 (defcustom org-agenda-todo-ignore-with-date nil
506 "Non-nil means, don't show entries with a date in the global todo list.
507 You can use this if you prefer to mark mere appointments with a TODO keyword,
508 but don't want them to show up in the TODO list.
509 When this is set, it also covers deadlines and scheduled items, the settings
510 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
511 will be ignored.
512 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
513 :group 'org-agenda-skip
514 :group 'org-agenda-todo-list
515 :type 'boolean)
517 (defcustom org-agenda-todo-ignore-scheduled nil
518 "Non-nil means, don't show scheduled entries in the global todo list.
519 The idea behind this is that by scheduling it, you have already taken care
520 of this item.
521 See also `org-agenda-todo-ignore-with-date'.
522 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
523 :group 'org-agenda-skip
524 :group 'org-agenda-todo-list
525 :type 'boolean)
527 (defcustom org-agenda-todo-ignore-deadlines nil
528 "Non-nil means, don't show near deadline entries in the global todo list.
529 Near means closer than `org-deadline-warning-days' days.
530 The idea behind this is that such items will appear in the agenda anyway.
531 See also `org-agenda-todo-ignore-with-date'.
532 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
533 :group 'org-agenda-skip
534 :group 'org-agenda-todo-list
535 :type 'boolean)
537 (defcustom org-agenda-tags-todo-honor-ignore-options nil
538 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
539 The variables
540 `org-agenda-todo-ignore-with-date',
541 `org-agenda-todo-ignore-scheduled'
542 `org-agenda-todo-ignore-deadlines'
543 make the global TODO list skip entries that have time stamps of certain
544 kinds. If this option is set, the same options will also apply for the
545 tags-todo search, which is the general tags/property matcher
546 restricted to unfinished TODO entries only."
547 :group 'org-agenda-skip
548 :group 'org-agenda-todo-list
549 :group 'org-agenda-match-view
550 :type 'boolean)
552 (defcustom org-agenda-skip-scheduled-if-done nil
553 "Non-nil means don't show scheduled items in agenda when they are done.
554 This is relevant for the daily/weekly agenda, not for the TODO list. And
555 it applies only to the actual date of the scheduling. Warnings about
556 an item with a past scheduling dates are always turned off when the item
557 is DONE."
558 :group 'org-agenda-skip
559 :group 'org-agenda-daily/weekly
560 :type 'boolean)
562 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
563 "Non-nil means skip scheduling line if same entry shows because of deadline.
564 In the agenda of today, an entry can show up multiple times because
565 it is both scheduled and has a nearby deadline, and maybe a plain time
566 stamp as well.
567 When this variable is t, then only the deadline is shown and the fact that
568 the entry is scheduled today or was scheduled previously is not shown.
569 When this variable is nil, the entry will be shown several times. When
570 the variable is the symbol `not-today', then skip scheduled previously,
571 but not scheduled today."
572 :group 'org-agenda-skip
573 :group 'org-agenda-daily/weekly
574 :type '(choice
575 (const :tag "Never" nil)
576 (const :tag "Always" t)
577 (const :tag "Not when scheduled today" not-today)))
579 (defcustom org-agenda-skip-deadline-if-done nil
580 "Non-nil means don't show deadlines when the corresponding item is done.
581 When nil, the deadline is still shown and should give you a happy feeling.
582 This is relevant for the daily/weekly agenda. And it applied only to the
583 actually date of the deadline. Warnings about approaching and past-due
584 deadlines are always turned off when the item is DONE."
585 :group 'org-agenda-skip
586 :group 'org-agenda-daily/weekly
587 :type 'boolean)
589 (defcustom org-agenda-skip-additional-timestamps-same-entry t
590 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
591 When non-nil, after the search for timestamps has matched once in an
592 entry, the rest of the entry will not be searched."
593 :group 'org-agenda-skip
594 :type 'boolean)
596 (defcustom org-agenda-skip-timestamp-if-done nil
597 "Non-nil means don't select item by timestamp or -range if it is DONE."
598 :group 'org-agenda-skip
599 :group 'org-agenda-daily/weekly
600 :type 'boolean)
602 (defcustom org-agenda-dim-blocked-tasks t
603 "Non-nil means, dim blocked tasks in the agenda display.
604 This causes some overhead during agenda construction, but if you
605 have turned on `org-enforce-todo-dependencies',
606 `org-enforce-todo-checkbox-dependencies', or any other blocking
607 mechanism, this will create useful feedback in the agenda.
609 Instead ot t, this variable can also have the value `invisible'.
610 Then blocked tasks will be invisible and only become visible when
611 they become unblocked. An exemption to this behavior is when a task is
612 blocked because of unchecked checkboxes below it. Since checkboxes do
613 not show up in the agenda views, making this task invisible you remove any
614 trace from agenda views that there is something to do. Therefore, a task
615 that is blocked because of checkboxes will never be made invisible, it
616 will only be dimmed."
617 :group 'org-agenda-daily/weekly
618 :group 'org-agenda-todo-list
619 :type '(choice
620 (const :tag "Do not dim" nil)
621 (const :tag "Dim to a grey face" t)
622 (const :tag "Make invisibe" invisible)))
624 (defcustom org-timeline-show-empty-dates 3
625 "Non-nil means, `org-timeline' also shows dates without an entry.
626 When nil, only the days which actually have entries are shown.
627 When t, all days between the first and the last date are shown.
628 When an integer, show also empty dates, but if there is a gap of more than
629 N days, just insert a special line indicating the size of the gap."
630 :group 'org-agenda-skip
631 :type '(choice
632 (const :tag "None" nil)
633 (const :tag "All" t)
634 (integer :tag "at most")))
636 (defgroup org-agenda-startup nil
637 "Options concerning initial settings in the Agenda in Org Mode."
638 :tag "Org Agenda Startup"
639 :group 'org-agenda)
641 (defcustom org-finalize-agenda-hook nil
642 "Hook run just before displaying an agenda buffer."
643 :group 'org-agenda-startup
644 :type 'hook)
646 (defcustom org-agenda-mouse-1-follows-link nil
647 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
648 A longer mouse click will still set point. Does not work on XEmacs.
649 Needs to be set before org.el is loaded."
650 :group 'org-agenda-startup
651 :type 'boolean)
653 (defcustom org-agenda-start-with-follow-mode nil
654 "The initial value of follow-mode in a newly created agenda window."
655 :group 'org-agenda-startup
656 :type 'boolean)
658 (defcustom org-agenda-start-with-entry-text-mode nil
659 "The initial value of entry-text-mode in a newly created agenda window."
660 :group 'org-agenda-startup
661 :type 'boolean)
663 (defcustom org-agenda-entry-text-maxlines 5
664 "Number of text lines to be added when `E' is presed in the agenda.
666 Note that this variable only used during agenda display. Add add entry text
667 when exporting the agenda, configure the variable
668 `org-agenda-add-entry-ext-maxlines'."
669 :group 'org-agenda
670 :type 'integer)
672 (defvar org-agenda-include-inactive-timestamps nil
673 "Non-nil means, include inactive time stamps in agenda and timeline.")
675 (defgroup org-agenda-windows nil
676 "Options concerning the windows used by the Agenda in Org Mode."
677 :tag "Org Agenda Windows"
678 :group 'org-agenda)
680 (defcustom org-agenda-window-setup 'reorganize-frame
681 "How the agenda buffer should be displayed.
682 Possible values for this option are:
684 current-window Show agenda in the current window, keeping all other windows.
685 other-frame Use `switch-to-buffer-other-frame' to display agenda.
686 other-window Use `switch-to-buffer-other-window' to display agenda.
687 reorganize-frame Show only two windows on the current frame, the current
688 window and the agenda.
689 See also the variable `org-agenda-restore-windows-after-quit'."
690 :group 'org-agenda-windows
691 :type '(choice
692 (const current-window)
693 (const other-frame)
694 (const other-window)
695 (const reorganize-frame)))
697 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
698 "The min and max height of the agenda window as a fraction of frame height.
699 The value of the variable is a cons cell with two numbers between 0 and 1.
700 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
701 :group 'org-agenda-windows
702 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
704 (defcustom org-agenda-restore-windows-after-quit nil
705 "Non-nil means, restore window configuration open exiting agenda.
706 Before the window configuration is changed for displaying the agenda,
707 the current status is recorded. When the agenda is exited with
708 `q' or `x' and this option is set, the old state is restored. If
709 `org-agenda-window-setup' is `other-frame', the value of this
710 option will be ignored.."
711 :group 'org-agenda-windows
712 :type 'boolean)
714 (defcustom org-agenda-ndays 7
715 "Number of days to include in overview display.
716 Should be 1 or 7.
717 Custom commands can set this variable in the options section."
718 :group 'org-agenda-daily/weekly
719 :type 'integer)
721 (defcustom org-agenda-start-on-weekday 1
722 "Non-nil means, start the overview always on the specified weekday.
723 0 denotes Sunday, 1 denotes Monday etc.
724 When nil, always start on the current day.
725 Custom commands can set this variable in the options section."
726 :group 'org-agenda-daily/weekly
727 :type '(choice (const :tag "Today" nil)
728 (integer :tag "Weekday No.")))
730 (defcustom org-agenda-show-all-dates t
731 "Non-nil means, `org-agenda' shows every day in the selected range.
732 When nil, only the days which actually have entries are shown."
733 :group 'org-agenda-daily/weekly
734 :type 'boolean)
736 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
737 "Format string for displaying dates in the agenda.
738 Used by the daily/weekly agenda and by the timeline. This should be
739 a format string understood by `format-time-string', or a function returning
740 the formatted date as a string. The function must take a single argument,
741 a calendar-style date list like (month day year)."
742 :group 'org-agenda-daily/weekly
743 :type '(choice
744 (string :tag "Format string")
745 (function :tag "Function")))
747 (defun org-agenda-format-date-aligned (date)
748 "Format a date string for display in the daily/weekly agenda, or timeline.
749 This function makes sure that dates are aligned for easy reading."
750 (require 'cal-iso)
751 (let* ((dayname (calendar-day-name date))
752 (day (cadr date))
753 (day-of-week (calendar-day-of-week date))
754 (month (car date))
755 (monthname (calendar-month-name month))
756 (year (nth 2 date))
757 (iso-week (org-days-to-iso-week
758 (calendar-absolute-from-gregorian date)))
759 (weekyear (cond ((and (= month 1) (>= iso-week 52))
760 (1- year))
761 ((and (= month 12) (<= iso-week 1))
762 (1+ year))
763 (t year)))
764 (weekstring (if (= day-of-week 1)
765 (format " W%02d" iso-week)
766 "")))
767 (format "%-10s %2d %s %4d%s"
768 dayname day monthname year weekstring)))
770 (defcustom org-agenda-weekend-days '(6 0)
771 "Which days are weekend?
772 These days get the special face `org-agenda-date-weekend' in the agenda
773 and timeline buffers."
774 :group 'org-agenda-daily/weekly
775 :type '(set :greedy t
776 (const :tag "Monday" 1)
777 (const :tag "Tuesday" 2)
778 (const :tag "Wednesday" 3)
779 (const :tag "Thursday" 4)
780 (const :tag "Friday" 5)
781 (const :tag "Saturday" 6)
782 (const :tag "Sunday" 0)))
784 (defcustom org-agenda-include-diary nil
785 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
786 Custom commands can set this variable in the options section."
787 :group 'org-agenda-daily/weekly
788 :type 'boolean)
790 (defcustom org-agenda-include-all-todo nil
791 "Set means weekly/daily agenda will always contain all TODO entries.
792 The TODO entries will be listed at the top of the agenda, before
793 the entries for specific days.
794 This option is deprecated, it is better to define a block agenda instead."
795 :group 'org-agenda-daily/weekly
796 :type 'boolean)
798 (defcustom org-agenda-repeating-timestamp-show-all t
799 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
800 When nil, only one occurrence is shown, either today or the
801 nearest into the future."
802 :group 'org-agenda-daily/weekly
803 :type 'boolean)
805 (defcustom org-scheduled-past-days 10000
806 "No. of days to continue listing scheduled items that are not marked DONE.
807 When an item is scheduled on a date, it shows up in the agenda on this
808 day and will be listed until it is marked done for the number of days
809 given here."
810 :group 'org-agenda-daily/weekly
811 :type 'integer)
813 (defcustom org-agenda-log-mode-items '(closed clock)
814 "List of items that should be shown in agenda log mode.
815 This list may contain the following symbols:
817 closed Show entries that have been closed on that day.
818 clock Show entries that have received clocked time on that day.
819 state Show all logged state changes.
820 Note that instead of changing this variable, you can also press `C-u l' in
821 the agenda to display all available LOG items temporarily."
822 :group 'org-agenda-daily/weekly
823 :type '(set :greedy t (const closed) (const clock) (const state)))
825 (defcustom org-agenda-log-mode-add-notes t
826 "Non-nil means, add first line of notes to log entries in agenda views.
827 If a log item like a state change or a clock entry is associated with
828 notes, the first line of these notes will be added to the entry in the
829 agenda display."
830 :group 'org-agenda-daily/weekly
831 :type 'boolean)
833 (defcustom org-agenda-start-with-log-mode nil
834 "The initial value of log-mode in a newly created agenda window."
835 :group 'org-agenda-startup
836 :group 'org-agenda-daily/weekly
837 :type 'boolean)
839 (defcustom org-agenda-start-with-clockreport-mode nil
840 "The initial value of clockreport-mode in a newly created agenda window."
841 :group 'org-agenda-startup
842 :group 'org-agenda-daily/weekly
843 :type 'boolean)
845 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
846 "Property list with parameters for the clocktable in clockreport mode.
847 This is the display mode that shows a clock table in the daily/weekly
848 agenda, the properties for this dynamic block can be set here.
849 The usual clocktable parameters are allowed here, but you cannot set
850 the properties :name, :tstart, :tend, :block, and :scope - these will
851 be overwritten to make sure the content accurately reflects the
852 current display in the agenda."
853 :group 'org-agenda-daily/weekly
854 :type 'plist)
857 (defgroup org-agenda-time-grid nil
858 "Options concerning the time grid in the Org-mode Agenda."
859 :tag "Org Agenda Time Grid"
860 :group 'org-agenda)
862 (defcustom org-agenda-search-headline-for-time t
863 "Non-nil means, search headline for a time-of-day.
864 If the headline contains a time-of-day in one format or another, it will
865 be used to sort the entry into the time sequence of items for a day.
866 Some people have time stamps in the headline that refer to the creation
867 time or so, and then this produces an unwanted side effect. If this is
868 the case for your, use this variable to turn off searching the headline
869 for a time."
870 :group 'org-agenda-time-grid
871 :type 'boolean)
873 (defcustom org-agenda-use-time-grid t
874 "Non-nil means, show a time grid in the agenda schedule.
875 A time grid is a set of lines for specific times (like every two hours between
876 8:00 and 20:00). The items scheduled for a day at specific times are
877 sorted in between these lines.
878 For details about when the grid will be shown, and what it will look like, see
879 the variable `org-agenda-time-grid'."
880 :group 'org-agenda-time-grid
881 :type 'boolean)
883 (defcustom org-agenda-time-grid
884 '((daily today require-timed)
885 "----------------"
886 (800 1000 1200 1400 1600 1800 2000))
888 "The settings for time grid for agenda display.
889 This is a list of three items. The first item is again a list. It contains
890 symbols specifying conditions when the grid should be displayed:
892 daily if the agenda shows a single day
893 weekly if the agenda shows an entire week
894 today show grid on current date, independent of daily/weekly display
895 require-timed show grid only if at least one item has a time specification
897 The second item is a string which will be placed behind the grid time.
899 The third item is a list of integers, indicating the times that should have
900 a grid line."
901 :group 'org-agenda-time-grid
902 :type
903 '(list
904 (set :greedy t :tag "Grid Display Options"
905 (const :tag "Show grid in single day agenda display" daily)
906 (const :tag "Show grid in weekly agenda display" weekly)
907 (const :tag "Always show grid for today" today)
908 (const :tag "Show grid only if any timed entries are present"
909 require-timed)
910 (const :tag "Skip grid times already present in an entry"
911 remove-match))
912 (string :tag "Grid String")
913 (repeat :tag "Grid Times" (integer :tag "Time"))))
915 (defgroup org-agenda-sorting nil
916 "Options concerning sorting in the Org-mode Agenda."
917 :tag "Org Agenda Sorting"
918 :group 'org-agenda)
920 (defcustom org-agenda-sorting-strategy
921 '((agenda time-up priority-down category-keep)
922 (todo priority-down category-keep)
923 (tags priority-down category-keep)
924 (search category-keep))
925 "Sorting structure for the agenda items of a single day.
926 This is a list of symbols which will be used in sequence to determine
927 if an entry should be listed before another entry. The following
928 symbols are recognized:
930 time-up Put entries with time-of-day indications first, early first
931 time-down Put entries with time-of-day indications first, late first
932 category-keep Keep the default order of categories, corresponding to the
933 sequence in `org-agenda-files'.
934 category-up Sort alphabetically by category, A-Z.
935 category-down Sort alphabetically by category, Z-A.
936 tag-up Sort alphabetically by last tag, A-Z.
937 tag-down Sort alphabetically by last tag, Z-A.
938 priority-up Sort numerically by priority, high priority last.
939 priority-down Sort numerically by priority, high priority first.
940 todo-state-up Sort by todo state, tasks that are done last.
941 todo-state-down Sort by todo state, tasks that are done first.
942 effort-up Sort numerically by estimated effort, high effort last.
943 effort-down Sort numerically by estimated effort, high effort first.
944 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
945 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
947 The different possibilities will be tried in sequence, and testing stops
948 if one comparison returns a \"not-equal\". For example, the default
949 '(time-up category-keep priority-down)
950 means: Pull out all entries having a specified time of day and sort them,
951 in order to make a time schedule for the current day the first thing in the
952 agenda listing for the day. Of the entries without a time indication, keep
953 the grouped in categories, don't sort the categories, but keep them in
954 the sequence given in `org-agenda-files'. Within each category sort by
955 priority.
957 Leaving out `category-keep' would mean that items will be sorted across
958 categories by priority.
960 Instead of a single list, this can also be a set of list for specific
961 contents, with a context symbol in the car of the list, any of
962 `agenda', `todo', `tags' for the corresponding agenda views.
964 Custom commands can bind this variable in the options section."
965 :group 'org-agenda-sorting
966 :type `(choice
967 (repeat :tag "General" ,org-sorting-choice)
968 (list :tag "Individually"
969 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
970 (repeat ,org-sorting-choice))
971 (cons (const :tag "Strategy for TODO lists" todo)
972 (repeat ,org-sorting-choice))
973 (cons (const :tag "Strategy for Tags matches" tags)
974 (repeat ,org-sorting-choice)))))
976 (defcustom org-agenda-cmp-user-defined nil
977 "A function to define the comparison `user-defined'.
978 This function must receive two arguments, agenda entry a and b.
979 If a>b, return +1. If a<b, return -1. If they are equal as seen by
980 the user comparison, return nil.
981 When this is defined, you can make `user-defined-up' and `user-defined-down'
982 part of an agenda sorting strategy."
983 :group 'org-agenda-sorting
984 :type 'symbol)
986 (defcustom org-sort-agenda-notime-is-late t
987 "Non-nil means, items without time are considered late.
988 This is only relevant for sorting. When t, items which have no explicit
989 time like 15:30 will be considered as 99:01, i.e. later than any items which
990 do have a time. When nil, the default time is before 0:00. You can use this
991 option to decide if the schedule for today should come before or after timeless
992 agenda entries."
993 :group 'org-agenda-sorting
994 :type 'boolean)
996 (defcustom org-sort-agenda-noeffort-is-high t
997 "Non-nil means, items without effort estimate are sorted as high effort.
998 This also applies when filtering an agenda view with respect to the
999 < or > effort operator. Then, tasks with no effort defined will be treated
1000 as tasks with high effort.
1001 When nil, such items are sorted as 0 minutes effort."
1002 :group 'org-agenda-sorting
1003 :type 'boolean)
1005 (defgroup org-agenda-line-format nil
1006 "Options concerning the entry prefix in the Org-mode agenda display."
1007 :tag "Org Agenda Line Format"
1008 :group 'org-agenda)
1010 (defcustom org-agenda-prefix-format
1011 '((agenda . " %-12:c%?-12t% s")
1012 (timeline . " % s")
1013 (todo . " %-12:c")
1014 (tags . " %-12:c")
1015 (search . " %-12:c"))
1016 "Format specifications for the prefix of items in the agenda views.
1017 An alist with four entries, for the different agenda types. The keys to the
1018 sublists are `agenda', `timeline', `todo', and `tags'. The values
1019 are format strings.
1020 This format works similar to a printf format, with the following meaning:
1022 %c the category of the item, \"Diary\" for entries from the diary, or
1023 as given by the CATEGORY keyword or derived from the file name.
1024 %T the *last* tag of the item. Last because inherited tags come
1025 first in the list.
1026 %t the time-of-day specification if one applies to the entry, in the
1027 format HH:MM
1028 %s Scheduling/Deadline information, a short string
1030 All specifiers work basically like the standard `%s' of printf, but may
1031 contain two additional characters: A question mark just after the `%' and
1032 a whitespace/punctuation character just before the final letter.
1034 If the first character after `%' is a question mark, the entire field
1035 will only be included if the corresponding value applies to the
1036 current entry. This is useful for fields which should have fixed
1037 width when present, but zero width when absent. For example,
1038 \"%?-12t\" will result in a 12 character time field if a time of the
1039 day is specified, but will completely disappear in entries which do
1040 not contain a time.
1042 If there is punctuation or whitespace character just before the final
1043 format letter, this character will be appended to the field value if
1044 the value is not empty. For example, the format \"%-12:c\" leads to
1045 \"Diary: \" if the category is \"Diary\". If the category were be
1046 empty, no additional colon would be interted.
1048 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1049 - Indent the line with two space characters
1050 - Give the category in a 12 chars wide field, padded with whitespace on
1051 the right (because of `-'). Append a colon if there is a category
1052 (because of `:').
1053 - If there is a time-of-day, put it into a 12 chars wide field. If no
1054 time, don't put in an empty field, just skip it (because of '?').
1055 - Finally, put the scheduling information and append a whitespace.
1057 As another example, if you don't want the time-of-day of entries in
1058 the prefix, you could use:
1060 (setq org-agenda-prefix-format \" %-11:c% s\")
1062 See also the variables `org-agenda-remove-times-when-in-prefix' and
1063 `org-agenda-remove-tags'.
1065 Custom commands can set this variable in the options section."
1066 :type '(choice
1067 (string :tag "General format")
1068 (list :greedy t :tag "View dependent"
1069 (cons (const agenda) (string :tag "Format"))
1070 (cons (const timeline) (string :tag "Format"))
1071 (cons (const todo) (string :tag "Format"))
1072 (cons (const tags) (string :tag "Format"))
1073 (cons (const search) (string :tag "Format"))))
1074 :group 'org-agenda-line-format)
1076 (defvar org-prefix-format-compiled nil
1077 "The compiled version of the most recently used prefix format.
1078 See the variable `org-agenda-prefix-format'.")
1080 (defcustom org-agenda-todo-keyword-format "%-1s"
1081 "Format for the TODO keyword in agenda lines.
1082 Set this to something like \"%-12s\" if you want all TODO keywords
1083 to occupy a fixed space in the agenda display."
1084 :group 'org-agenda-line-format
1085 :type 'string)
1087 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1088 "Text preceding timerange entries in the agenda view.
1089 This is a list with two strings. The first applies when the range
1090 is entirely on one day. The second applies if the range spans several days.
1091 The strings may have two \"%d\" format specifiers which will be filled
1092 with the sequence number of the days, and the total number of days in the
1093 range, respectively."
1094 :group 'org-agenda-line-format
1095 :type '(list
1096 (string :tag "Deadline today ")
1097 (choice :tag "Deadline relative"
1098 (string :tag "Format string")
1099 (function))))
1101 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1102 "Text preceeding scheduled items in the agenda view.
1103 This is a list with two strings. The first applies when the item is
1104 scheduled on the current day. The second applies when it has been scheduled
1105 previously, it may contain a %d indicating that this is the nth time that
1106 this item is scheduled, due to automatic rescheduling of unfinished items
1107 for the following day. So this number is one larger than the number of days
1108 that passed since this item was scheduled first."
1109 :group 'org-agenda-line-format
1110 :type '(list
1111 (string :tag "Scheduled today ")
1112 (string :tag "Scheduled previously")))
1114 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1115 "Text preceeding deadline items in the agenda view.
1116 This is a list with two strings. The first applies when the item has its
1117 deadline on the current day. The second applies when it is in the past or
1118 in the future, it may contain %d to capture how many days away the deadline
1119 is (was)."
1120 :group 'org-agenda-line-format
1121 :type '(list
1122 (string :tag "Deadline today ")
1123 (choice :tag "Deadline relative"
1124 (string :tag "Format string")
1125 (function))))
1127 (defcustom org-agenda-remove-times-when-in-prefix t
1128 "Non-nil means, remove duplicate time specifications in agenda items.
1129 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1130 time-of-day specification in a headline or diary entry is extracted and
1131 placed into the prefix. If this option is non-nil, the original specification
1132 \(a timestamp or -range, or just a plain time(range) specification like
1133 11:30-4pm) will be removed for agenda display. This makes the agenda less
1134 cluttered.
1135 The option can be t or nil. It may also be the symbol `beg', indicating
1136 that the time should only be removed what it is located at the beginning of
1137 the headline/diary entry."
1138 :group 'org-agenda-line-format
1139 :type '(choice
1140 (const :tag "Always" t)
1141 (const :tag "Never" nil)
1142 (const :tag "When at beginning of entry" beg)))
1145 (defcustom org-agenda-default-appointment-duration nil
1146 "Default duration for appointments that only have a starting time.
1147 When nil, no duration is specified in such cases.
1148 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1149 :group 'org-agenda-line-format
1150 :type '(choice
1151 (integer :tag "Minutes")
1152 (const :tag "No default duration")))
1154 (defcustom org-agenda-show-inherited-tags t
1155 "Non-nil means, show inherited tags in each agenda line."
1156 :group 'org-agenda-line-format
1157 :type 'boolean)
1159 (defcustom org-agenda-remove-tags nil
1160 "Non-nil means, remove the tags from the headline copy in the agenda.
1161 When this is the symbol `prefix', only remove tags when
1162 `org-agenda-prefix-format' contains a `%T' specifier."
1163 :group 'org-agenda-line-format
1164 :type '(choice
1165 (const :tag "Always" t)
1166 (const :tag "Never" nil)
1167 (const :tag "When prefix format contains %T" prefix)))
1169 (if (fboundp 'defvaralias)
1170 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1171 'org-agenda-remove-tags))
1173 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1174 "Shift tags in agenda items to this column.
1175 If this number is positive, it specifies the column. If it is negative,
1176 it means that the tags should be flushright to that column. For example,
1177 -80 works well for a normal 80 character screen."
1178 :group 'org-agenda-line-format
1179 :type 'integer)
1181 (if (fboundp 'defvaralias)
1182 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1184 (defcustom org-agenda-fontify-priorities 'cookies
1185 "Non-nil means, highlight low and high priorities in agenda.
1186 When t, the highest priority entries are bold, lowest priority italic.
1187 However, settings in org-priority-faces will overrule these faces.
1188 When this variable is the symbol `cookies', only fontify the
1189 cookies, not the entire task.
1190 This may also be an association list of priority faces, whose
1191 keys are the character values of `org-highest-priority',
1192 `org-default-priority', and `org-lowest-priority' (the default values
1193 are ?A, ?B, and ?C, respectively). The face may be a named face,
1194 or a list like `(:background \"Red\")'."
1195 :group 'org-agenda-line-format
1196 :type '(choice
1197 (const :tag "Never" nil)
1198 (const :tag "Defaults" t)
1199 (const :tag "Cookies only" cookies)
1200 (repeat :tag "Specify"
1201 (list (character :tag "Priority" :value ?A)
1202 (sexp :tag "face")))))
1204 (defgroup org-agenda-column-view nil
1205 "Options concerning column view in the agenda."
1206 :tag "Org Agenda Column View"
1207 :group 'org-agenda)
1209 (defcustom org-agenda-columns-show-summaries t
1210 "Non-nil means, show summaries for columns displayed in the agenda view."
1211 :group 'org-agenda-column-view
1212 :type 'boolean)
1214 (defcustom org-agenda-columns-remove-prefix-from-item t
1215 "Non-nil means, remove the prefix from a headline for agenda column view.
1216 The special ITEM field in the columns format contains the current line, with
1217 all information shown in other columns (like the TODO state or a tag).
1218 When this variable is non-nil, also the agenda prefix will be removed from
1219 the content of the ITEM field, to make sure as much as possible of the
1220 headline can be shown in the limited width of the field."
1221 :group 'org-agenda
1222 :type 'boolean)
1224 (defcustom org-agenda-columns-compute-summary-properties t
1225 "Non-nil means, recompute all summary properties before column view.
1226 When column view in the agenda is listing properties that have a summary
1227 operator, it can go to all relevant buffers and recompute the summaries
1228 there. This can mean overhead for the agenda column view, but is necessary
1229 to have thing up to date.
1230 As a special case, a CLOCKSUM property also makes sure that the clock
1231 computations are current."
1232 :group 'org-agenda-column-view
1233 :type 'boolean)
1235 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1236 "Non-nil means, the duration of an appointment will add to day effort.
1237 The property to which appointment durations will be added is the one given
1238 in the option `org-effort-property'. If an appointment does not have
1239 an end time, `org-agenda-default-appointment-duration' will be used. If that
1240 is not set, an appointment without end time will not contribute to the time
1241 estimate."
1242 :group 'org-agenda-column-view
1243 :type 'boolean)
1245 (eval-when-compile
1246 (require 'cl))
1247 (require 'org)
1249 (defun org-add-agenda-custom-command (entry)
1250 "Replace or add a command in `org-agenda-custom-commands'.
1251 This is mostly for hacking and trying a new command - once the command
1252 works you probably want to add it to `org-agenda-custom-commands' for good."
1253 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1254 (if ass
1255 (setcdr ass (cdr entry))
1256 (push entry org-agenda-custom-commands))))
1258 ;;; Define the Org-agenda-mode
1260 (defvar org-agenda-mode-map (make-sparse-keymap)
1261 "Keymap for `org-agenda-mode'.")
1263 (defvar org-agenda-menu) ; defined later in this file.
1264 (defvar org-agenda-restrict) ; defined later in this file.
1265 (defvar org-agenda-follow-mode nil)
1266 (defvar org-agenda-entry-text-mode nil)
1267 (defvar org-agenda-clockreport-mode nil)
1268 (defvar org-agenda-show-log nil)
1269 (defvar org-agenda-redo-command nil)
1270 (defvar org-agenda-query-string nil)
1271 (defvar org-agenda-mode-hook nil
1272 "Hook for org-agenda-mode, run after the mode is turned on.")
1273 (defvar org-agenda-type nil)
1274 (defvar org-agenda-force-single-file nil)
1275 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1277 (defun org-agenda-mode ()
1278 "Mode for time-sorted view on action items in Org-mode files.
1280 The following commands are available:
1282 \\{org-agenda-mode-map}"
1283 (interactive)
1284 (kill-all-local-variables)
1285 (setq org-agenda-undo-list nil
1286 org-agenda-pending-undo-list nil
1287 org-agenda-bulk-marked-entries nil)
1288 (setq major-mode 'org-agenda-mode)
1289 ;; Keep global-font-lock-mode from turning on font-lock-mode
1290 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1291 (setq mode-name "Org-Agenda")
1292 (use-local-map org-agenda-mode-map)
1293 (easy-menu-add org-agenda-menu)
1294 (if org-startup-truncated (setq truncate-lines t))
1295 (org-set-local 'line-move-visual nil)
1296 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1297 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1298 ;; Make sure properties are removed when copying text
1299 (when (boundp 'buffer-substring-filters)
1300 (org-set-local 'buffer-substring-filters
1301 (cons (lambda (x)
1302 (set-text-properties 0 (length x) nil x) x)
1303 buffer-substring-filters)))
1304 (unless org-agenda-keep-modes
1305 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1306 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1307 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1308 org-agenda-show-log org-agenda-start-with-log-mode))
1310 (easy-menu-change
1311 '("Agenda") "Agenda Files"
1312 (append
1313 (list
1314 (vector
1315 (if (get 'org-agenda-files 'org-restrict)
1316 "Restricted to single file"
1317 "Edit File List")
1318 '(org-edit-agenda-file-list)
1319 (not (get 'org-agenda-files 'org-restrict)))
1320 "--")
1321 (mapcar 'org-file-menu-entry (org-agenda-files))))
1322 (org-agenda-set-mode-name)
1323 (apply
1324 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1325 (list 'org-agenda-mode-hook)))
1327 (substitute-key-definition 'undo 'org-agenda-undo
1328 org-agenda-mode-map global-map)
1329 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1330 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1331 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1332 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1333 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1334 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1335 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1336 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1337 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1338 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1339 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1340 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1341 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1342 (org-defkey org-agenda-mode-map "A" 'org-agenda-archive-to-archive-sibling)
1343 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1344 (org-defkey org-agenda-mode-map " " 'org-agenda-show)
1345 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1346 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1347 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1348 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1349 (org-defkey org-agenda-mode-map "b" 'org-agenda-tree-to-indirect-buffer)
1350 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1351 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1352 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1353 (org-defkey org-agenda-mode-map "a" 'org-agenda-toggle-archive-tag)
1354 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1355 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1356 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1357 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1358 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1359 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1360 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1361 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1362 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1363 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1364 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1365 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1366 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1367 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1368 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1370 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1371 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1372 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1373 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1374 (while l (org-defkey org-agenda-mode-map
1375 (int-to-string (pop l)) 'digit-argument)))
1377 (org-defkey org-agenda-mode-map "f" 'org-agenda-follow-mode)
1378 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1379 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1380 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1381 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1382 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1383 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1384 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1385 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1386 (org-defkey org-agenda-mode-map "e" 'org-agenda-execute)
1387 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1388 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1389 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1390 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1391 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1392 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1393 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1394 (org-defkey org-agenda-mode-map "n" 'next-line)
1395 (org-defkey org-agenda-mode-map "p" 'previous-line)
1396 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1397 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1398 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1399 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1400 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1401 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1402 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1403 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1404 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1405 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1406 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1407 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1408 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1409 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1410 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1411 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1412 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1413 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1414 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1415 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1416 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1417 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1418 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1419 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1420 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1421 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1422 (org-defkey org-agenda-mode-map [(right)] 'org-agenda-later)
1423 (org-defkey org-agenda-mode-map [(left)] 'org-agenda-earlier)
1424 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1425 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1427 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1428 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1429 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1430 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1431 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1432 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1433 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1435 (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
1436 "Local keymap for agenda entries from Org-mode.")
1438 (org-defkey org-agenda-keymap
1439 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1440 (org-defkey org-agenda-keymap
1441 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1442 (when org-agenda-mouse-1-follows-link
1443 (org-defkey org-agenda-keymap [follow-link] 'mouse-face))
1444 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1445 '("Agenda"
1446 ("Agenda Files")
1447 "--"
1448 ["Show" org-agenda-show t]
1449 ["Go To (other window)" org-agenda-goto t]
1450 ["Go To (this window)" org-agenda-switch-to t]
1451 ["Follow Mode" org-agenda-follow-mode
1452 :style toggle :selected org-agenda-follow-mode :active t]
1453 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1454 "--"
1455 ["Cycle TODO" org-agenda-todo t]
1456 ("Archive and Refile"
1457 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1458 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1459 ["Archive subtree" org-agenda-archive t]
1460 ["Refile" org-agenda-refile t])
1461 ["Delete subtree" org-agenda-kill t]
1462 ("Bulk action"
1463 ["Toggle mark entry" org-agenda-bulk-mark t]
1464 ["Act on all marked" org-agenda-bulk-action t]
1465 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1466 "--"
1467 ["Add note" org-agenda-add-note t]
1468 "--"
1469 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1470 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1471 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1472 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)]
1473 "--"
1474 ("Tags and Properties"
1475 ["Show all Tags" org-agenda-show-tags t]
1476 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1477 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1478 "--"
1479 ["Column View" org-columns t])
1480 ("Date/Schedule"
1481 ["Schedule" org-agenda-schedule t]
1482 ["Set Deadline" org-agenda-deadline t]
1483 "--"
1484 ["Mark item" org-agenda-action :active t :keys "k m"]
1485 ["Show mark item" org-agenda-action :active t :keys "k v"]
1486 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1487 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1488 "--"
1489 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1490 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1491 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1492 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1493 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1494 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1495 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1496 ("Clock"
1497 ["Clock in" org-agenda-clock-in t]
1498 ["Clock out" org-agenda-clock-out t]
1499 ["Clock cancel" org-agenda-clock-cancel t]
1500 ["Goto running clock" org-clock-goto t])
1501 ("Priority"
1502 ["Set Priority" org-agenda-priority t]
1503 ["Increase Priority" org-agenda-priority-up t]
1504 ["Decrease Priority" org-agenda-priority-down t]
1505 ["Show Priority" org-agenda-show-priority t])
1506 ("Calendar/Diary"
1507 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1508 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1509 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1510 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1511 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1512 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1513 "--"
1514 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t])
1515 "--"
1516 ("View"
1517 ["Day View" org-agenda-day-view
1518 :active (org-agenda-check-type nil 'agenda)
1519 :style radio :selected (equal org-agenda-ndays 1)
1520 :keys "v d (or just d)"]
1521 ["Week View" org-agenda-week-view
1522 :active (org-agenda-check-type nil 'agenda)
1523 :style radio :selected (equal org-agenda-ndays 7)
1524 :keys "v w (or just w)"]
1525 ["Month View" org-agenda-month-view
1526 :active (org-agenda-check-type nil 'agenda)
1527 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1528 :keys "v m"]
1529 ["Year View" org-agenda-year-view
1530 :active (org-agenda-check-type nil 'agenda)
1531 :style radio :selected (member org-agenda-ndays '(365 366))
1532 :keys "v y"]
1533 "--"
1534 ["Include Diary" org-agenda-toggle-diary
1535 :style toggle :selected org-agenda-include-diary
1536 :active (org-agenda-check-type nil 'agenda)]
1537 ["Use Time Grid" org-agenda-toggle-time-grid
1538 :style toggle :selected org-agenda-use-time-grid
1539 :active (org-agenda-check-type nil 'agenda)]
1540 "--"
1541 ["Show clock report" org-agenda-clockreport-mode
1542 :style toggle :selected org-agenda-clockreport-mode
1543 :active (org-agenda-check-type nil 'agenda)]
1544 ["Show some entry text" org-agenda-entry-text-mode
1545 :style toggle :selected org-agenda-entry-text-mode
1546 :active t]
1547 "--"
1548 ["Show Logbook entries" org-agenda-log-mode
1549 :style toggle :selected org-agenda-show-log
1550 :active (org-agenda-check-type nil 'agenda 'timeline)
1551 :keys "v l (or just l)"]
1552 ["Include archived trees" org-agenda-archives-mode
1553 :style toggle :selected org-agenda-archives-mode :active t
1554 :keys "v a"]
1555 ["Include archive files" (org-agenda-archives-mode t)
1556 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1557 :keys "v A"]
1558 "--"
1559 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1560 ["Write view to file" org-write-agenda t]
1561 ["Rebuild buffer" org-agenda-redo t]
1562 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1563 "--"
1564 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1565 "--"
1566 ["Quit" org-agenda-quit t]
1567 ["Exit and Release Buffers" org-agenda-exit t]
1570 ;;; Agenda undo
1572 (defvar org-agenda-allow-remote-undo t
1573 "Non-nil means, allow remote undo from the agenda buffer.")
1574 (defvar org-agenda-undo-list nil
1575 "List of undoable operations in the agenda since last refresh.")
1576 (defvar org-agenda-undo-has-started-in nil
1577 "Buffers that have already seen `undo-start' in the current undo sequence.")
1578 (defvar org-agenda-pending-undo-list nil
1579 "In a series of undo commands, this is the list of remaining undo items.")
1582 (defun org-agenda-undo ()
1583 "Undo a remote editing step in the agenda.
1584 This undoes changes both in the agenda buffer and in the remote buffer
1585 that have been changed along."
1586 (interactive)
1587 (or org-agenda-allow-remote-undo
1588 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1589 (if (not (eq this-command last-command))
1590 (setq org-agenda-undo-has-started-in nil
1591 org-agenda-pending-undo-list org-agenda-undo-list))
1592 (if (not org-agenda-pending-undo-list)
1593 (error "No further undo information"))
1594 (let* ((entry (pop org-agenda-pending-undo-list))
1595 buf line cmd rembuf)
1596 (setq cmd (pop entry) line (pop entry))
1597 (setq rembuf (nth 2 entry))
1598 (org-with-remote-undo rembuf
1599 (while (bufferp (setq buf (pop entry)))
1600 (if (pop entry)
1601 (with-current-buffer buf
1602 (let ((last-undo-buffer buf)
1603 (inhibit-read-only t))
1604 (unless (memq buf org-agenda-undo-has-started-in)
1605 (push buf org-agenda-undo-has-started-in)
1606 (make-local-variable 'pending-undo-list)
1607 (undo-start))
1608 (while (and pending-undo-list
1609 (listp pending-undo-list)
1610 (not (car pending-undo-list)))
1611 (pop pending-undo-list))
1612 (undo-more 1))))))
1613 (org-goto-line line)
1614 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1616 (defun org-verify-change-for-undo (l1 l2)
1617 "Verify that a real change occurred between the undo lists L1 and L2."
1618 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1619 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1620 (not (eq l1 l2)))
1622 ;;; Agenda dispatch
1624 (defvar org-agenda-restrict nil)
1625 (defvar org-agenda-restrict-begin (make-marker))
1626 (defvar org-agenda-restrict-end (make-marker))
1627 (defvar org-agenda-last-dispatch-buffer nil)
1628 (defvar org-agenda-overriding-restriction nil)
1630 ;;;###autoload
1631 (defun org-agenda (&optional arg keys restriction)
1632 "Dispatch agenda commands to collect entries to the agenda buffer.
1633 Prompts for a command to execute. Any prefix arg will be passed
1634 on to the selected command. The default selections are:
1636 a Call `org-agenda-list' to display the agenda for current day or week.
1637 t Call `org-todo-list' to display the global todo list.
1638 T Call `org-todo-list' to display the global todo list, select only
1639 entries with a specific TODO keyword (the user gets a prompt).
1640 m Call `org-tags-view' to display headlines with tags matching
1641 a condition (the user is prompted for the condition).
1642 M Like `m', but select only TODO entries, no ordinary headlines.
1643 L Create a timeline for the current buffer.
1644 e Export views to associated files.
1645 s Search entries for keywords.
1646 / Multi occur accros all agenda files and also files listed
1647 in `org-agenda-text-search-extra-files'.
1648 < Restrict agenda commands to buffer, subtree, or region.
1649 Press several times to get the desired effect.
1650 > Remove a previous restriction.
1651 # List \"stuck\" projects.
1652 ! Configure what \"stuck\" means.
1653 C Configure custom agenda commands.
1655 More commands can be added by configuring the variable
1656 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1657 searches can be pre-defined in this way.
1659 If the current buffer is in Org-mode and visiting a file, you can also
1660 first press `<' once to indicate that the agenda should be temporarily
1661 \(until the next use of \\[org-agenda]) restricted to the current file.
1662 Pressing `<' twice means to restrict to the current subtree or region
1663 \(if active)."
1664 (interactive "P")
1665 (catch 'exit
1666 (let* ((prefix-descriptions nil)
1667 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1668 (org-agenda-custom-commands
1669 ;; normalize different versions
1670 (delq nil
1671 (mapcar
1672 (lambda (x)
1673 (cond ((stringp (cdr x))
1674 (push x prefix-descriptions)
1675 nil)
1676 ((stringp (nth 1 x)) x)
1677 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1678 (t (cons (car x) (cons "" (cdr x))))))
1679 org-agenda-custom-commands)))
1680 (buf (current-buffer))
1681 (bfn (buffer-file-name (buffer-base-buffer)))
1682 entry key type match lprops ans)
1683 ;; Turn off restriction unless there is an overriding one
1684 (unless org-agenda-overriding-restriction
1685 (put 'org-agenda-files 'org-restrict nil)
1686 (setq org-agenda-restrict nil)
1687 (move-marker org-agenda-restrict-begin nil)
1688 (move-marker org-agenda-restrict-end nil))
1689 ;; Delete old local properties
1690 (put 'org-agenda-redo-command 'org-lprops nil)
1691 ;; Remember where this call originated
1692 (setq org-agenda-last-dispatch-buffer (current-buffer))
1693 (unless keys
1694 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1695 keys (car ans)
1696 restriction (cdr ans)))
1697 ;; Estabish the restriction, if any
1698 (when (and (not org-agenda-overriding-restriction) restriction)
1699 (put 'org-agenda-files 'org-restrict (list bfn))
1700 (cond
1701 ((eq restriction 'region)
1702 (setq org-agenda-restrict t)
1703 (move-marker org-agenda-restrict-begin (region-beginning))
1704 (move-marker org-agenda-restrict-end (region-end)))
1705 ((eq restriction 'subtree)
1706 (save-excursion
1707 (setq org-agenda-restrict t)
1708 (org-back-to-heading t)
1709 (move-marker org-agenda-restrict-begin (point))
1710 (move-marker org-agenda-restrict-end
1711 (progn (org-end-of-subtree t)))))))
1713 (require 'calendar) ; FIXME: can we avoid this for some commands?
1714 ;; For example the todo list should not need it (but does...)
1715 (cond
1716 ((setq entry (assoc keys org-agenda-custom-commands))
1717 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1718 (progn
1719 (setq type (nth 2 entry) match (nth 3 entry) lprops (nth 4 entry))
1720 (put 'org-agenda-redo-command 'org-lprops lprops)
1721 (cond
1722 ((eq type 'agenda)
1723 (org-let lprops '(org-agenda-list current-prefix-arg)))
1724 ((eq type 'alltodo)
1725 (org-let lprops '(org-todo-list current-prefix-arg)))
1726 ((eq type 'search)
1727 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1728 ((eq type 'stuck)
1729 (org-let lprops '(org-agenda-list-stuck-projects
1730 current-prefix-arg)))
1731 ((eq type 'tags)
1732 (org-let lprops '(org-tags-view current-prefix-arg match)))
1733 ((eq type 'tags-todo)
1734 (org-let lprops '(org-tags-view '(4) match)))
1735 ((eq type 'todo)
1736 (org-let lprops '(org-todo-list match)))
1737 ((eq type 'tags-tree)
1738 (org-check-for-org-mode)
1739 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1740 ((eq type 'todo-tree)
1741 (org-check-for-org-mode)
1742 (org-let lprops
1743 '(org-occur (concat "^" outline-regexp "[ \t]*"
1744 (regexp-quote match) "\\>"))))
1745 ((eq type 'occur-tree)
1746 (org-check-for-org-mode)
1747 (org-let lprops '(org-occur match)))
1748 ((functionp type)
1749 (org-let lprops '(funcall type match)))
1750 ((fboundp type)
1751 (org-let lprops '(funcall type match)))
1752 (t (error "Invalid custom agenda command type %s" type))))
1753 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1754 ((equal keys "C")
1755 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1756 (customize-variable 'org-agenda-custom-commands))
1757 ((equal keys "a") (call-interactively 'org-agenda-list))
1758 ((equal keys "s") (call-interactively 'org-search-view))
1759 ((equal keys "t") (call-interactively 'org-todo-list))
1760 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1761 ((equal keys "m") (call-interactively 'org-tags-view))
1762 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1763 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1764 ((equal keys "L")
1765 (unless (org-mode-p)
1766 (error "This is not an Org-mode file"))
1767 (unless restriction
1768 (put 'org-agenda-files 'org-restrict (list bfn))
1769 (org-call-with-arg 'org-timeline arg)))
1770 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1771 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1772 ((equal keys "!") (customize-variable 'org-stuck-projects))
1773 (t (error "Invalid agenda key"))))))
1775 (defun org-agenda-normalize-custom-commands (cmds)
1776 (delq nil
1777 (mapcar
1778 (lambda (x)
1779 (cond ((stringp (cdr x)) nil)
1780 ((stringp (nth 1 x)) x)
1781 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1782 (t (cons (car x) (cons "" (cdr x))))))
1783 cmds)))
1785 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1786 "The user interface for selecting an agenda command."
1787 (catch 'exit
1788 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1789 (restrict-ok (and bfn (org-mode-p)))
1790 (region-p (org-region-active-p))
1791 (custom org-agenda-custom-commands)
1792 (selstring "")
1793 restriction second-time
1794 c entry key type match prefixes rmheader header-end custom1 desc)
1795 (save-window-excursion
1796 (delete-other-windows)
1797 (org-switch-to-buffer-other-window " *Agenda Commands*")
1798 (erase-buffer)
1799 (insert (eval-when-compile
1800 (let ((header
1802 Press key for an agenda command: < Buffer, subtree/region restriction
1803 -------------------------------- > Remove restriction
1804 a Agenda for current week or day e Export agenda views
1805 t List of all TODO entries T Entries with special TODO kwd
1806 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1807 L Timeline for current buffer # List stuck projects (!=configure)
1808 s Search for keywords C Configure custom agenda commands
1809 / Multi-occur
1811 (start 0))
1812 (while (string-match
1813 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1814 header start)
1815 (setq start (match-end 0))
1816 (add-text-properties (match-beginning 2) (match-end 2)
1817 '(face bold) header))
1818 header)))
1819 (setq header-end (move-marker (make-marker) (point)))
1820 (while t
1821 (setq custom1 custom)
1822 (when (eq rmheader t)
1823 (org-goto-line 1)
1824 (re-search-forward ":" nil t)
1825 (delete-region (match-end 0) (point-at-eol))
1826 (forward-char 1)
1827 (looking-at "-+")
1828 (delete-region (match-end 0) (point-at-eol))
1829 (move-marker header-end (match-end 0)))
1830 (goto-char header-end)
1831 (delete-region (point) (point-max))
1832 (while (setq entry (pop custom1))
1833 (setq key (car entry) desc (nth 1 entry)
1834 type (nth 2 entry)
1835 match (nth 3 entry))
1836 (if (> (length key) 1)
1837 (add-to-list 'prefixes (string-to-char key))
1838 (insert
1839 (format
1840 "\n%-4s%-14s: %s"
1841 (org-add-props (copy-sequence key)
1842 '(face bold))
1843 (cond
1844 ((string-match "\\S-" desc) desc)
1845 ((eq type 'agenda) "Agenda for current week or day")
1846 ((eq type 'alltodo) "List of all TODO entries")
1847 ((eq type 'search) "Word search")
1848 ((eq type 'stuck) "List of stuck projects")
1849 ((eq type 'todo) "TODO keyword")
1850 ((eq type 'tags) "Tags query")
1851 ((eq type 'tags-todo) "Tags (TODO)")
1852 ((eq type 'tags-tree) "Tags tree")
1853 ((eq type 'todo-tree) "TODO kwd tree")
1854 ((eq type 'occur-tree) "Occur tree")
1855 ((functionp type) (if (symbolp type)
1856 (symbol-name type)
1857 "Lambda expression"))
1858 (t "???"))
1859 (cond
1860 ((stringp match)
1861 (setq match (copy-sequence match))
1862 (org-add-props match nil 'face 'org-warning))
1863 (match
1864 (format "set of %d commands" (length match)))
1865 (t ""))))))
1866 (when prefixes
1867 (mapc (lambda (x)
1868 (insert
1869 (format "\n%s %s"
1870 (org-add-props (char-to-string x)
1871 nil 'face 'bold)
1872 (or (cdr (assoc (concat selstring (char-to-string x))
1873 prefix-descriptions))
1874 "Prefix key"))))
1875 prefixes))
1876 (goto-char (point-min))
1877 (if second-time
1878 (if (not (pos-visible-in-window-p (point-max)))
1879 (org-fit-window-to-buffer))
1880 (setq second-time t)
1881 (org-fit-window-to-buffer))
1882 (message "Press key for agenda command%s:"
1883 (if (or restrict-ok org-agenda-overriding-restriction)
1884 (if org-agenda-overriding-restriction
1885 " (restriction lock active)"
1886 (if restriction
1887 (format " (restricted to %s)" restriction)
1888 " (unrestricted)"))
1889 ""))
1890 (setq c (read-char-exclusive))
1891 (message "")
1892 (cond
1893 ((assoc (char-to-string c) custom)
1894 (setq selstring (concat selstring (char-to-string c)))
1895 (throw 'exit (cons selstring restriction)))
1896 ((memq c prefixes)
1897 (setq selstring (concat selstring (char-to-string c))
1898 prefixes nil
1899 rmheader (or rmheader t)
1900 custom (delq nil (mapcar
1901 (lambda (x)
1902 (if (or (= (length (car x)) 1)
1903 (/= (string-to-char (car x)) c))
1905 (cons (substring (car x) 1) (cdr x))))
1906 custom))))
1907 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
1908 (message "Restriction is only possible in Org-mode buffers")
1909 (ding) (sit-for 1))
1910 ((eq c ?1)
1911 (org-agenda-remove-restriction-lock 'noupdate)
1912 (setq restriction 'buffer))
1913 ((eq c ?0)
1914 (org-agenda-remove-restriction-lock 'noupdate)
1915 (setq restriction (if region-p 'region 'subtree)))
1916 ((eq c ?<)
1917 (org-agenda-remove-restriction-lock 'noupdate)
1918 (setq restriction
1919 (cond
1920 ((eq restriction 'buffer)
1921 (if region-p 'region 'subtree))
1922 ((memq restriction '(subtree region))
1923 nil)
1924 (t 'buffer))))
1925 ((eq c ?>)
1926 (org-agenda-remove-restriction-lock 'noupdate)
1927 (setq restriction nil))
1928 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/)))
1929 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
1930 ((and (> (length selstring) 0) (eq c ?\d))
1931 (delete-window)
1932 (org-agenda-get-restriction-and-command prefix-descriptions))
1934 ((equal c ?q) (error "Abort"))
1935 (t (error "Invalid key %c" c))))))))
1937 (defun org-run-agenda-series (name series)
1938 (org-let (nth 1 series) '(org-prepare-agenda name))
1939 (let* ((org-agenda-multi t)
1940 (redo (list 'org-run-agenda-series name (list 'quote series)))
1941 (cmds (car series))
1942 (gprops (nth 1 series))
1943 match ;; The byte compiler incorrectly complains about this. Keep it!
1944 cmd type lprops)
1945 (while (setq cmd (pop cmds))
1946 (setq type (car cmd) match (nth 1 cmd) lprops (nth 2 cmd))
1947 (cond
1948 ((eq type 'agenda)
1949 (org-let2 gprops lprops
1950 '(call-interactively 'org-agenda-list)))
1951 ((eq type 'alltodo)
1952 (org-let2 gprops lprops
1953 '(call-interactively 'org-todo-list)))
1954 ((eq type 'search)
1955 (org-let2 gprops lprops
1956 '(org-search-view current-prefix-arg match nil)))
1957 ((eq type 'stuck)
1958 (org-let2 gprops lprops
1959 '(call-interactively 'org-agenda-list-stuck-projects)))
1960 ((eq type 'tags)
1961 (org-let2 gprops lprops
1962 '(org-tags-view current-prefix-arg match)))
1963 ((eq type 'tags-todo)
1964 (org-let2 gprops lprops
1965 '(org-tags-view '(4) match)))
1966 ((eq type 'todo)
1967 (org-let2 gprops lprops
1968 '(org-todo-list match)))
1969 ((fboundp type)
1970 (org-let2 gprops lprops
1971 '(funcall type match)))
1972 (t (error "Invalid type in command series"))))
1973 (widen)
1974 (setq org-agenda-redo-command redo)
1975 (goto-char (point-min)))
1976 (org-fit-agenda-window)
1977 (org-let (nth 1 series) '(org-finalize-agenda)))
1979 ;;;###autoload
1980 (defmacro org-batch-agenda (cmd-key &rest parameters)
1981 "Run an agenda command in batch mode and send the result to STDOUT.
1982 If CMD-KEY is a string of length 1, it is used as a key in
1983 `org-agenda-custom-commands' and triggers this command. If it is a
1984 longer string it is used as a tags/todo match string.
1985 Paramters are alternating variable names and values that will be bound
1986 before running the agenda command."
1987 (let (pars)
1988 (while parameters
1989 (push (list (pop parameters) (if parameters (pop parameters))) pars))
1990 (if (> (length cmd-key) 2)
1991 (eval (list 'let (nreverse pars)
1992 (list 'org-tags-view nil cmd-key)))
1993 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
1994 (set-buffer org-agenda-buffer-name)
1995 (princ (org-encode-for-stdout (buffer-string)))))
1997 (defun org-encode-for-stdout (string)
1998 (if (fboundp 'encode-coding-string)
1999 (encode-coding-string string buffer-file-coding-system)
2000 string))
2002 (defvar org-agenda-info nil)
2004 ;;;###autoload
2005 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2006 "Run an agenda command in batch mode and send the result to STDOUT.
2007 If CMD-KEY is a string of length 1, it is used as a key in
2008 `org-agenda-custom-commands' and triggers this command. If it is a
2009 longer string it is used as a tags/todo match string.
2010 Paramters are alternating variable names and values that will be bound
2011 before running the agenda command.
2013 The output gives a line for each selected agenda item. Each
2014 item is a list of comma-separated values, like this:
2016 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2018 category The category of the item
2019 head The headline, without TODO kwd, TAGS and PRIORITY
2020 type The type of the agenda entry, can be
2021 todo selected in TODO match
2022 tagsmatch selected in tags match
2023 diary imported from diary
2024 deadline a deadline on given date
2025 scheduled scheduled on given date
2026 timestamp entry has timestamp on given date
2027 closed entry was closed on given date
2028 upcoming-deadline warning about deadline
2029 past-scheduled forwarded scheduled item
2030 block entry has date block including g. date
2031 todo The todo keyword, if any
2032 tags All tags including inherited ones, separated by colons
2033 date The relevant date, like 2007-2-14
2034 time The time, like 15:00-16:50
2035 extra Sting with extra planning info
2036 priority-l The priority letter if any was given
2037 priority-n The computed numerical priority
2038 agenda-day The day in the agenda where this is listed"
2040 (let (pars)
2041 (while parameters
2042 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2043 (push (list 'org-agenda-remove-tags t) pars)
2044 (if (> (length cmd-key) 2)
2045 (eval (list 'let (nreverse pars)
2046 (list 'org-tags-view nil cmd-key)))
2047 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2048 (set-buffer org-agenda-buffer-name)
2049 (let* ((lines (org-split-string (buffer-string) "\n"))
2050 line)
2051 (while (setq line (pop lines))
2052 (catch 'next
2053 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2054 (setq org-agenda-info
2055 (org-fix-agenda-info (text-properties-at 0 line)))
2056 (princ
2057 (org-encode-for-stdout
2058 (mapconcat 'org-agenda-export-csv-mapper
2059 '(org-category txt type todo tags date time-of-day extra
2060 priority-letter priority agenda-day)
2061 ",")))
2062 (princ "\n"))))))
2064 (defun org-fix-agenda-info (props)
2065 "Make sure all properties on an agenda item have a canonical form,
2066 so the export commands can easily use it."
2067 (let (tmp re)
2068 (when (setq tmp (plist-get props 'tags))
2069 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2070 (when (setq tmp (plist-get props 'date))
2071 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2072 (let ((calendar-date-display-form '(year "-" month "-" day)))
2073 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2075 (setq tmp (calendar-date-string tmp)))
2076 (setq props (plist-put props 'date tmp)))
2077 (when (setq tmp (plist-get props 'day))
2078 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2079 (let ((calendar-date-display-form '(year "-" month "-" day)))
2080 (setq tmp (calendar-date-string tmp)))
2081 (setq props (plist-put props 'day tmp))
2082 (setq props (plist-put props 'agenda-day tmp)))
2083 (when (setq tmp (plist-get props 'txt))
2084 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2085 (plist-put props 'priority-letter (match-string 1 tmp))
2086 (setq tmp (replace-match "" t t tmp)))
2087 (when (and (setq re (plist-get props 'org-todo-regexp))
2088 (setq re (concat "\\`\\.*" re " ?"))
2089 (string-match re tmp))
2090 (plist-put props 'todo (match-string 1 tmp))
2091 (setq tmp (replace-match "" t t tmp)))
2092 (plist-put props 'txt tmp)))
2093 props)
2095 (defun org-agenda-export-csv-mapper (prop)
2096 (let ((res (plist-get org-agenda-info prop)))
2097 (setq res
2098 (cond
2099 ((not res) "")
2100 ((stringp res) res)
2101 (t (prin1-to-string res))))
2102 (while (string-match "," res)
2103 (setq res (replace-match ";" t t res)))
2104 (org-trim res)))
2107 ;;;###autoload
2108 (defun org-store-agenda-views (&rest parameters)
2109 (interactive)
2110 (eval (list 'org-batch-store-agenda-views)))
2112 ;; FIXME, why is this a macro?????
2113 ;;;###autoload
2114 (defmacro org-batch-store-agenda-views (&rest parameters)
2115 "Run all custom agenda commands that have a file argument."
2116 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2117 (pop-up-frames nil)
2118 (dir default-directory)
2119 pars cmd thiscmdkey files opts cmd-or-set)
2120 (while parameters
2121 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2122 (setq pars (reverse pars))
2123 (save-window-excursion
2124 (while cmds
2125 (setq cmd (pop cmds)
2126 thiscmdkey (car cmd)
2127 cmd-or-set (nth 2 cmd)
2128 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2129 files (nth (if (listp cmd-or-set) 4 5) cmd))
2130 (if (stringp files) (setq files (list files)))
2131 (when files
2132 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2133 (list 'org-agenda nil thiscmdkey)))
2134 (set-buffer org-agenda-buffer-name)
2135 (while files
2136 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2137 (list 'org-write-agenda
2138 (expand-file-name (pop files) dir) nil t))))
2139 (and (get-buffer org-agenda-buffer-name)
2140 (kill-buffer org-agenda-buffer-name)))))))
2142 (defun org-write-agenda (file &optional open nosettings)
2143 "Write the current buffer (an agenda view) as a file.
2144 Depending on the extension of the file name, plain text (.txt),
2145 HTML (.html or .htm) or Postscript (.ps) is produced.
2146 If the extension is .ics, run icalendar export over all files used
2147 to construct the agenda and limit the export to entries listed in the
2148 agenda now.
2149 With prefic argument OPEN, open the new file immediately.
2150 If NOSETTINGS is given, do not scope the settings of
2151 `org-agenda-exporter-settings' into the export commands. This is used when
2152 the settings have already been scoped and we do not wish to overrule other,
2153 higher priority settings."
2154 (interactive "FWrite agenda to file: \nP")
2155 (if (not (file-writable-p file))
2156 (error "Cannot write agenda to file %s" file))
2157 (cond
2158 ((string-match "\\.html?\\'" file) (require 'htmlize))
2159 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2160 (org-let (if nosettings nil org-agenda-exporter-settings)
2161 '(save-excursion
2162 (save-window-excursion
2163 (org-agenda-mark-filtered-text)
2164 (let ((bs (copy-sequence (buffer-string))) beg)
2165 (org-agenda-unmark-filtered-text)
2166 (with-temp-buffer
2167 (insert bs)
2168 (org-agenda-remove-marked-text 'org-filtered)
2169 (while (setq beg (text-property-any (point-min) (point-max)
2170 'org-filtered t))
2171 (delete-region
2172 beg (or (next-single-property-change beg 'org-filtered)
2173 (point-max))))
2174 (run-hooks 'org-agenda-before-write-hook)
2175 (cond
2176 ((string-match "\\.html?\\'" file)
2177 (set-buffer (htmlize-buffer (current-buffer)))
2179 (when (and org-agenda-export-html-style
2180 (string-match "<style>" org-agenda-export-html-style))
2181 ;; replace <style> section with org-agenda-export-html-style
2182 (goto-char (point-min))
2183 (kill-region (- (search-forward "<style") 6)
2184 (search-forward "</style>"))
2185 (insert org-agenda-export-html-style))
2186 (write-file file)
2187 (kill-buffer (current-buffer))
2188 (message "HTML written to %s" file))
2189 ((string-match "\\.ps\\'" file)
2190 (require 'ps-print)
2191 (flet ((ps-get-buffer-name () "Agenda View"))
2192 (ps-print-buffer-with-faces file))
2193 (message "Postscript written to %s" file))
2194 ((string-match "\\.pdf\\'" file)
2195 (require 'ps-print)
2196 (flet ((ps-get-buffer-name () "Agenda View"))
2197 (ps-print-buffer-with-faces
2198 (concat (file-name-sans-extension file) ".ps")))
2199 (call-process "ps2pdf" nil nil nil
2200 (expand-file-name
2201 (concat (file-name-sans-extension file) ".ps"))
2202 (expand-file-name file))
2203 (message "PDF written to %s" file))
2204 ((string-match "\\.ics\\'" file)
2205 (require 'org-icalendar)
2206 (let ((org-agenda-marker-table
2207 (org-create-marker-find-array
2208 (org-agenda-collect-markers)))
2209 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2210 (org-combined-agenda-icalendar-file file))
2211 (apply 'org-export-icalendar 'combine
2212 (org-agenda-files nil 'ifmode))))
2214 (let ((bs (buffer-string)))
2215 (find-file file)
2216 (erase-buffer)
2217 (insert bs)
2218 (save-buffer 0)
2219 (kill-buffer (current-buffer))
2220 (message "Plain text written to %s" file))))))))
2221 (set-buffer org-agenda-buffer-name))
2222 (when open (org-open-file file)))
2224 (defvar org-agenda-filter-overlays nil)
2226 (defun org-agenda-mark-filtered-text ()
2227 "Mark all text hidden by filtering with a text property."
2228 (let ((inhibit-read-only t))
2229 (mapc
2230 (lambda (o)
2231 (when (equal (org-overlay-buffer o) (current-buffer))
2232 (put-text-property
2233 (org-overlay-start o) (org-overlay-end o)
2234 'org-filtered t)))
2235 org-agenda-filter-overlays)))
2237 (defun org-agenda-unmark-filtered-text ()
2238 "Remove the filtering text property."
2239 (let ((inhibit-read-only t))
2240 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2242 (defun org-agenda-remove-marked-text (property &optional value)
2243 "Delete all text marked with VALUE of PROPERTY.
2244 VALUE defaults to t."
2245 (let (beg)
2246 (setq value (or value t))
2247 (while (setq beg (text-property-any (point-min) (point-max)
2248 property value))
2249 (delete-region
2250 beg (or (next-single-property-change beg 'org-filtered)
2251 (point-max))))))
2253 (defun org-agenda-add-entry-text ()
2254 "Add entry text to agenda lines.
2255 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2256 entry text following headings shown in the agenda.
2257 Drawers will be excluded, also the line with scheduling/deadline info."
2258 (when (> org-agenda-add-entry-text-maxlines 0)
2259 (let (m txt drawer-re kwd-time-re ind)
2260 (goto-char (point-min))
2261 (while (not (eobp))
2262 (if (not (setq m (get-text-property (point) 'org-hd-marker)))
2263 (beginning-of-line 2)
2264 (setq txt (org-agenda-get-some-entry-text
2265 m org-agenda-add-entry-text-maxlines))
2266 (end-of-line 1)
2267 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2269 (defun org-agenda-get-some-entry-text (marker n-lines)
2270 "Extract entry text from MARKER, at most N-LINES lines.
2271 This will ignore drawers etc, just get the text."
2272 (let (txt)
2273 (save-excursion
2274 (with-current-buffer (marker-buffer marker)
2275 (if (not (org-mode-p))
2276 (setq txt "")
2277 (save-excursion
2278 (save-restriction
2279 (widen)
2280 (goto-char marker)
2281 (beginning-of-line 2)
2282 (setq txt (buffer-substring
2283 (point)
2284 (progn (outline-next-heading) (point)))
2285 drawer-re org-drawer-regexp
2286 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2287 ".*\n?"))
2288 (with-temp-buffer
2289 (insert txt)
2290 (when org-agenda-add-entry-text-descriptive-links
2291 (goto-char (point-min))
2292 (while (org-activate-bracket-links (point-max))
2293 (add-text-properties (match-beginning 0) (match-end 0)
2294 '(face org-link))))
2295 (goto-char (point-min))
2296 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2297 (set-text-properties (match-beginning 0) (match-end 0)
2298 nil))
2299 (goto-char (point-min))
2300 (while (re-search-forward drawer-re nil t)
2301 (delete-region
2302 (match-beginning 0)
2303 (progn (re-search-forward
2304 "^[ \t]*:END:.*\n?" nil 'move)
2305 (point))))
2306 (goto-char (point-min))
2307 (while (re-search-forward kwd-time-re nil t)
2308 (replace-match ""))
2309 (if (re-search-forward "[ \t\n]+\\'" nil t)
2310 (replace-match ""))
2311 (goto-char (point-min))
2312 ;; find min indentation
2313 (goto-char (point-min))
2314 (untabify (point-min) (point-max))
2315 (setq ind (org-get-indentation))
2316 (while (not (eobp))
2317 (unless (looking-at "[ \t]*$")
2318 (setq ind (min ind (org-get-indentation))))
2319 (beginning-of-line 2))
2320 (goto-char (point-min))
2321 (while (not (eobp))
2322 (unless (looking-at "[ \t]*$")
2323 (move-to-column ind)
2324 (delete-region (point-at-bol) (point)))
2325 (beginning-of-line 2))
2326 (goto-char (point-min))
2327 (while (and (not (eobp)) (re-search-forward "^" nil t))
2328 (replace-match " > "))
2329 (goto-char (point-min))
2330 (while (looking-at "[ \t]*\n") (replace-match ""))
2331 (goto-char (point-max))
2332 (when (> (org-current-line)
2333 n-lines)
2334 (org-goto-line (1+ n-lines))
2335 (backward-char 1))
2336 (setq txt (buffer-substring (point-min) (point)))))))))
2337 txt))
2339 (defun org-agenda-collect-markers ()
2340 "Collect the markers pointing to entries in the agenda buffer."
2341 (let (m markers)
2342 (save-excursion
2343 (goto-char (point-min))
2344 (while (not (eobp))
2345 (when (setq m (or (get-text-property (point) 'org-hd-marker)
2346 (get-text-property (point) 'org-marker)))
2347 (push m markers))
2348 (beginning-of-line 2)))
2349 (nreverse markers)))
2351 (defun org-create-marker-find-array (marker-list)
2352 "Create a alist of files names with all marker positions in that file."
2353 (let (f tbl m a p)
2354 (while (setq m (pop marker-list))
2355 (setq p (marker-position m)
2356 f (buffer-file-name (or (buffer-base-buffer
2357 (marker-buffer m))
2358 (marker-buffer m))))
2359 (if (setq a (assoc f tbl))
2360 (push (marker-position m) (cdr a))
2361 (push (list f p) tbl)))
2362 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2363 tbl)))
2365 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2366 (defun org-check-agenda-marker-table ()
2367 "Check of the current entry is on the marker list."
2368 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2370 (and (setq a (assoc file org-agenda-marker-table))
2371 (save-match-data
2372 (save-excursion
2373 (org-back-to-heading t)
2374 (member (point) (cdr a)))))))
2376 (defun org-check-for-org-mode ()
2377 "Make sure current buffer is in org-mode. Error if not."
2378 (or (org-mode-p)
2379 (error "Cannot execute org-mode agenda command on buffer in %s."
2380 major-mode)))
2382 (defun org-fit-agenda-window ()
2383 "Fit the window to the buffer size."
2384 (and (memq org-agenda-window-setup '(reorganize-frame))
2385 (fboundp 'fit-window-to-buffer)
2386 (org-fit-window-to-buffer
2388 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2389 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2391 ;;; Agenda prepare and finalize
2393 (defvar org-agenda-multi nil) ; dynamically scoped
2394 (defvar org-agenda-buffer-name "*Org Agenda*")
2395 (defvar org-pre-agenda-window-conf nil)
2396 (defvar org-agenda-columns-active nil)
2397 (defvar org-agenda-name nil)
2398 (defvar org-agenda-filter nil)
2399 (defvar org-agenda-filter-preset nil
2400 "A preset of the tags filter used for secondary agenda filtering.
2401 This must be a list of strings, each string must be a single tag preceeded
2402 by \"+\" or \"-\".
2403 This variable should not be set directly, but agenda custom commands can
2404 bind it in the options section.")
2406 (defun org-prepare-agenda (&optional name)
2407 (setq org-todo-keywords-for-agenda nil)
2408 (setq org-done-keywords-for-agenda nil)
2409 (setq org-agenda-filter nil)
2410 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2411 (if org-agenda-multi
2412 (progn
2413 (setq buffer-read-only nil)
2414 (goto-char (point-max))
2415 (unless (or (bobp) org-agenda-compact-blocks)
2416 (insert "\n"
2417 (if (stringp org-agenda-block-separator)
2418 org-agenda-block-separator
2419 (make-string (window-width) org-agenda-block-separator))
2420 "\n"))
2421 (narrow-to-region (point) (point-max)))
2422 (org-agenda-reset-markers)
2423 (setq org-agenda-contributing-files nil)
2424 (setq org-agenda-columns-active nil)
2425 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2426 (setq org-todo-keywords-for-agenda
2427 (org-uniquify org-todo-keywords-for-agenda))
2428 (setq org-done-keywords-for-agenda
2429 (org-uniquify org-done-keywords-for-agenda))
2430 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2431 (awin (get-buffer-window abuf)))
2432 (cond
2433 ((equal (current-buffer) abuf) nil)
2434 (awin (select-window awin))
2435 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2436 ((equal org-agenda-window-setup 'current-window)
2437 (switch-to-buffer abuf))
2438 ((equal org-agenda-window-setup 'other-window)
2439 (org-switch-to-buffer-other-window abuf))
2440 ((equal org-agenda-window-setup 'other-frame)
2441 (switch-to-buffer-other-frame abuf))
2442 ((equal org-agenda-window-setup 'reorganize-frame)
2443 (delete-other-windows)
2444 (org-switch-to-buffer-other-window abuf))))
2445 (setq buffer-read-only nil)
2446 (let ((inhibit-read-only t)) (erase-buffer))
2447 (org-agenda-mode)
2448 (and name (not org-agenda-name)
2449 (org-set-local 'org-agenda-name name)))
2450 (setq buffer-read-only nil))
2452 (defun org-finalize-agenda ()
2453 "Finishing touch for the agenda buffer, called just before displaying it."
2454 (unless org-agenda-multi
2455 (save-excursion
2456 (let ((inhibit-read-only t))
2457 (goto-char (point-min))
2458 (while (org-activate-bracket-links (point-max))
2459 (add-text-properties (match-beginning 0) (match-end 0)
2460 '(face org-link)))
2461 (org-agenda-align-tags)
2462 (unless org-agenda-with-colors
2463 (remove-text-properties (point-min) (point-max) '(face nil))))
2464 (if (and (boundp 'org-agenda-overriding-columns-format)
2465 org-agenda-overriding-columns-format)
2466 (org-set-local 'org-agenda-overriding-columns-format
2467 org-agenda-overriding-columns-format))
2468 (if (and (boundp 'org-agenda-view-columns-initially)
2469 org-agenda-view-columns-initially)
2470 (org-agenda-columns))
2471 (when org-agenda-fontify-priorities
2472 (org-agenda-fontify-priorities))
2473 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2474 (org-agenda-dim-blocked-tasks))
2475 (org-agenda-mark-clocking-task)
2476 (when org-agenda-entry-text-mode
2477 (org-agenda-entry-text-hide)
2478 (org-agenda-entry-text-show))
2479 (run-hooks 'org-finalize-agenda-hook)
2480 (setq org-agenda-type (get-text-property (point) 'org-agenda-type))
2481 (when (get 'org-agenda-filter :preset-filter)
2482 (org-agenda-filter-apply org-agenda-filter))
2485 (defun org-agenda-mark-clocking-task ()
2486 "Mark the current clock entry in the agenda if it is present."
2487 (mapc (lambda (o)
2488 (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
2489 (org-delete-overlay o)))
2490 (org-overlays-in (point-min) (point-max)))
2491 (when (marker-buffer org-clock-hd-marker)
2492 (save-excursion
2493 (goto-char (point-min))
2494 (let (s ov)
2495 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2496 (goto-char s)
2497 (when (equal (get-text-property (point) 'org-hd-marker)
2498 org-clock-hd-marker)
2499 (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2500 (org-overlay-put ov 'type 'org-agenda-clocking)
2501 (org-overlay-put ov 'face 'org-agenda-clocking)
2502 (org-overlay-put ov 'help-echo
2503 "The clock is running in this item")))))))
2505 (defun org-agenda-fontify-priorities ()
2506 "Make highest priority lines bold, and lowest italic."
2507 (interactive)
2508 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
2509 (org-delete-overlay o)))
2510 (org-overlays-in (point-min) (point-max)))
2511 (save-excursion
2512 (let ((inhibit-read-only t)
2513 b e p ov h l)
2514 (goto-char (point-min))
2515 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2516 (setq h (or (get-char-property (point) 'org-highest-priority)
2517 org-highest-priority)
2518 l (or (get-char-property (point) 'org-lowest-priority)
2519 org-lowest-priority)
2520 p (string-to-char (match-string 1))
2521 b (match-beginning 0)
2522 e (if (eq org-agenda-fontify-priorities 'cookies)
2523 (match-end 0)
2524 (point-at-eol))
2525 ov (org-make-overlay b e))
2526 (org-overlay-put
2527 ov 'face
2528 (cond ((cdr (assoc p org-priority-faces)))
2529 ((and (listp org-agenda-fontify-priorities)
2530 (cdr (assoc p org-agenda-fontify-priorities))))
2531 ((equal p l) 'italic)
2532 ((equal p h) 'bold)))
2533 (org-overlay-put ov 'org-type 'org-priority)))))
2535 (defun org-agenda-dim-blocked-tasks ()
2536 "Dim currently blocked TODO's in the agenda display."
2537 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
2538 (org-delete-overlay o)))
2539 (org-overlays-in (point-min) (point-max)))
2540 (save-excursion
2541 (let ((inhibit-read-only t)
2542 (org-depend-tag-blocked nil)
2543 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2544 org-blocked-by-checkboxes
2545 invis1 b e p ov h l)
2546 (goto-char (point-min))
2547 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2548 (and pos (goto-char (1+ pos))))
2549 (setq org-blocked-by-checkboxes nil invis1 invis)
2550 (let ((marker (get-text-property (point) 'org-hd-marker)))
2551 (when (and marker
2552 (not (with-current-buffer (marker-buffer marker)
2553 (save-excursion
2554 (goto-char marker)
2555 (if (org-entry-get nil "NOBLOCKING")
2556 t ;; Never block this entry
2557 (run-hook-with-args-until-failure
2558 'org-blocker-hook
2559 (list :type 'todo-state-change
2560 :position marker
2561 :from 'todo
2562 :to 'done)))))))
2563 (if org-blocked-by-checkboxes (setq invis1 nil))
2564 (setq b (if invis1 (max (point-min) (1- (point))) (point))
2565 e (point-at-eol)
2566 ov (org-make-overlay b e))
2567 (if invis1
2568 (org-overlay-put ov 'invisible t)
2569 (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2570 (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
2572 (defvar org-agenda-skip-function nil
2573 "Function to be called at each match during agenda construction.
2574 If this function returns nil, the current match should not be skipped.
2575 Otherwise, the function must return a position from where the search
2576 should be continued.
2577 This may also be a Lisp form, it will be evaluated.
2578 Never set this variable using `setq' or so, because then it will apply
2579 to all future agenda commands. Instead, bind it with `let' to scope
2580 it dynamically into the agenda-constructing command. A good way to set
2581 it is through options in org-agenda-custom-commands.")
2583 (defun org-agenda-skip ()
2584 "Throw to `:skip' in places that should be skipped.
2585 Also moves point to the end of the skipped region, so that search can
2586 continue from there."
2587 (let ((p (point-at-bol)) to fp)
2588 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2589 (get-text-property p :org-archived)
2590 (org-end-of-subtree t)
2591 (throw :skip t))
2592 (and org-agenda-skip-comment-trees
2593 (get-text-property p :org-comment)
2594 (org-end-of-subtree t)
2595 (throw :skip t))
2596 (if (equal (char-after p) ?#) (throw :skip t))
2597 (when (and (or (setq fp (functionp org-agenda-skip-function))
2598 (consp org-agenda-skip-function))
2599 (setq to (save-excursion
2600 (save-match-data
2601 (if fp
2602 (funcall org-agenda-skip-function)
2603 (eval org-agenda-skip-function))))))
2604 (goto-char to)
2605 (throw :skip t))))
2607 (defvar org-agenda-markers nil
2608 "List of all currently active markers created by `org-agenda'.")
2609 (defvar org-agenda-last-marker-time (time-to-seconds (current-time))
2610 "Creation time of the last agenda marker.")
2612 (defun org-agenda-new-marker (&optional pos)
2613 "Return a new agenda marker.
2614 Org-mode keeps a list of these markers and resets them when they are
2615 no longer in use."
2616 (let ((m (copy-marker (or pos (point)))))
2617 (setq org-agenda-last-marker-time (time-to-seconds (current-time)))
2618 (push m org-agenda-markers)
2621 (defun org-agenda-reset-markers ()
2622 "Reset markers created by `org-agenda'."
2623 (while org-agenda-markers
2624 (move-marker (pop org-agenda-markers) nil)))
2626 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2627 "Save relative positions of markers in region."
2628 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2629 org-agenda-markers))
2631 ;;; Entry text mode
2633 (defun org-agenda-entry-text-show-here ()
2634 "Add some text from te entry as context to the current line."
2635 (let (m txt o)
2636 (setq m (get-text-property (point) 'org-hd-marker))
2637 (unless (marker-buffer m)
2638 (error "No marker points to an entry here"))
2639 (setq txt (concat "\n" (org-no-properties
2640 (org-agenda-get-some-entry-text
2641 m org-agenda-entry-text-maxlines))))
2642 (when (string-match "\\S-" txt)
2643 (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
2644 (org-overlay-put o 'evaporate t)
2645 (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
2646 (org-overlay-put o 'after-string txt))))
2648 (defun org-agenda-entry-text-show ()
2649 "Add entry context for all agenda lines."
2650 (interactive)
2651 (save-excursion
2652 (goto-char (point-max))
2653 (beginning-of-line 1)
2654 (while (not (bobp))
2655 (when (get-text-property (point) 'org-hd-marker)
2656 (org-agenda-entry-text-show-here))
2657 (beginning-of-line 0))))
2659 (defun org-agenda-entry-text-hide ()
2660 "Remove any shown entry context."
2661 (delq nil
2662 (mapcar (lambda (o)
2663 (if (eq (org-overlay-get o 'org-overlay-type)
2664 'agenda-entry-content)
2665 (progn (org-delete-overlay o) t)))
2666 (org-overlays-in (point-min) (point-max)))))
2668 ;;; Agenda timeline
2670 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2672 (defun org-timeline (&optional include-all)
2673 "Show a time-sorted view of the entries in the current org file.
2674 Only entries with a time stamp of today or later will be listed. With
2675 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2676 under the current date.
2677 If the buffer contains an active region, only check the region for
2678 dates."
2679 (interactive "P")
2680 (require 'calendar)
2681 (org-compile-prefix-format 'timeline)
2682 (org-set-sorting-strategy 'timeline)
2683 (let* ((dopast t)
2684 (dotodo include-all)
2685 (doclosed org-agenda-show-log)
2686 (entry buffer-file-name)
2687 (date (calendar-current-date))
2688 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2689 (end (if (org-region-active-p) (region-end) (point-max)))
2690 (day-numbers (org-get-all-dates beg end 'no-ranges
2691 t doclosed ; always include today
2692 org-timeline-show-empty-dates))
2693 (org-deadline-warning-days 0)
2694 (org-agenda-only-exact-dates t)
2695 (today (time-to-days (current-time)))
2696 (past t)
2697 args
2698 s e rtn d emptyp wd)
2699 (setq org-agenda-redo-command
2700 (list 'progn
2701 (list 'org-switch-to-buffer-other-window (current-buffer))
2702 (list 'org-timeline (list 'quote include-all))))
2703 (if (not dopast)
2704 ;; Remove past dates from the list of dates.
2705 (setq day-numbers (delq nil (mapcar (lambda(x)
2706 (if (>= x today) x nil))
2707 day-numbers))))
2708 (org-prepare-agenda (concat "Timeline "
2709 (file-name-nondirectory buffer-file-name)))
2710 (if doclosed (push :closed args))
2711 (push :timestamp args)
2712 (push :deadline args)
2713 (push :scheduled args)
2714 (push :sexp args)
2715 (if dotodo (push :todo args))
2716 (while (setq d (pop day-numbers))
2717 (if (and (listp d) (eq (car d) :omitted))
2718 (progn
2719 (setq s (point))
2720 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2721 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2722 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2723 (if (and (>= d today)
2724 dopast
2725 past)
2726 (progn
2727 (setq past nil)
2728 (insert (make-string 79 ?-) "\n")))
2729 (setq date (calendar-gregorian-from-absolute d)
2730 wd (calendar-day-of-week date))
2731 (setq s (point))
2732 (setq rtn (and (not emptyp)
2733 (apply 'org-agenda-get-day-entries entry
2734 date args)))
2735 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2736 (progn
2737 (insert
2738 (if (stringp org-agenda-format-date)
2739 (format-time-string org-agenda-format-date
2740 (org-time-from-absolute date))
2741 (funcall org-agenda-format-date date))
2742 "\n")
2743 (put-text-property s (1- (point)) 'face
2744 (if (member wd org-agenda-weekend-days)
2745 'org-agenda-date-weekend
2746 'org-agenda-date))
2747 (put-text-property s (1- (point)) 'org-date-line t)
2748 (if (equal d today)
2749 (put-text-property s (1- (point)) 'org-today t))
2750 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2751 (put-text-property s (1- (point)) 'day d)))))
2752 (goto-char (point-min))
2753 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2754 (point-min)))
2755 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2756 (org-finalize-agenda)
2757 (setq buffer-read-only t)))
2759 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2760 "Return a list of all relevant day numbers from BEG to END buffer positions.
2761 If NO-RANGES is non-nil, include only the start and end dates of a range,
2762 not every single day in the range. If FORCE-TODAY is non-nil, make
2763 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2764 inactive time stamps (those in square brackets) are included.
2765 When EMPTY is non-nil, also include days without any entries."
2766 (let ((re (concat
2767 (if pre-re pre-re "")
2768 (if inactive org-ts-regexp-both org-ts-regexp)))
2769 dates dates1 date day day1 day2 ts1 ts2)
2770 (if force-today
2771 (setq dates (list (time-to-days (current-time)))))
2772 (save-excursion
2773 (goto-char beg)
2774 (while (re-search-forward re end t)
2775 (setq day (time-to-days (org-time-string-to-time
2776 (substring (match-string 1) 0 10))))
2777 (or (memq day dates) (push day dates)))
2778 (unless no-ranges
2779 (goto-char beg)
2780 (while (re-search-forward org-tr-regexp end t)
2781 (setq ts1 (substring (match-string 1) 0 10)
2782 ts2 (substring (match-string 2) 0 10)
2783 day1 (time-to-days (org-time-string-to-time ts1))
2784 day2 (time-to-days (org-time-string-to-time ts2)))
2785 (while (< (setq day1 (1+ day1)) day2)
2786 (or (memq day1 dates) (push day1 dates)))))
2787 (setq dates (sort dates '<))
2788 (when empty
2789 (while (setq day (pop dates))
2790 (setq day2 (car dates))
2791 (push day dates1)
2792 (when (and day2 empty)
2793 (if (or (eq empty t)
2794 (and (numberp empty) (<= (- day2 day) empty)))
2795 (while (< (setq day (1+ day)) day2)
2796 (push (list day) dates1))
2797 (push (cons :omitted (- day2 day)) dates1))))
2798 (setq dates (nreverse dates1)))
2799 dates)))
2801 ;;; Agenda Daily/Weekly
2803 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2804 (defvar org-agenda-start-day nil ; dynamically scoped parameter
2805 "Custom commands can set this variable in the options section.")
2806 (defvar org-agenda-last-arguments nil
2807 "The arguments of the previous call to org-agenda")
2808 (defvar org-starting-day nil) ; local variable in the agenda buffer
2809 (defvar org-agenda-span nil) ; local variable in the agenda buffer
2810 (defvar org-include-all-loc nil) ; local variable
2811 (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
2813 ;;;###autoload
2814 (defun org-agenda-list (&optional include-all start-day ndays)
2815 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2816 The view will be for the current day or week, but from the overview buffer
2817 you will be able to go to other days/weeks.
2819 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2820 all unfinished TODO items will also be shown, before the agenda.
2821 This feature is considered obsolete, please use the TODO list or a block
2822 agenda instead.
2824 With a numeric prefix argument in an interactive call, the agenda will
2825 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2826 the number of days. NDAYS defaults to `org-agenda-ndays'.
2828 START-DAY defaults to TODAY, or to the most recent match for the weekday
2829 given in `org-agenda-start-on-weekday'."
2830 (interactive "P")
2831 (if (and (integerp include-all) (> include-all 0))
2832 (setq ndays include-all include-all nil))
2833 (setq ndays (or ndays org-agenda-ndays)
2834 start-day (or start-day org-agenda-start-day))
2835 (if org-agenda-overriding-arguments
2836 (setq include-all (car org-agenda-overriding-arguments)
2837 start-day (nth 1 org-agenda-overriding-arguments)
2838 ndays (nth 2 org-agenda-overriding-arguments)))
2839 (if (stringp start-day)
2840 ;; Convert to an absolute day number
2841 (setq start-day (time-to-days (org-read-date nil t start-day))))
2842 (setq org-agenda-last-arguments (list include-all start-day ndays))
2843 (org-compile-prefix-format 'agenda)
2844 (org-set-sorting-strategy 'agenda)
2845 (require 'calendar)
2846 (let* ((org-agenda-start-on-weekday
2847 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
2848 org-agenda-start-on-weekday nil))
2849 (thefiles (org-agenda-files nil 'ifmode))
2850 (files thefiles)
2851 (today (time-to-days
2852 (time-subtract (current-time)
2853 (list 0 (* 3600 org-extend-today-until) 0))))
2854 (sd (or start-day today))
2855 (start (if (or (null org-agenda-start-on-weekday)
2856 (< org-agenda-ndays 7))
2858 (let* ((nt (calendar-day-of-week
2859 (calendar-gregorian-from-absolute sd)))
2860 (n1 org-agenda-start-on-weekday)
2861 (d (- nt n1)))
2862 (- sd (+ (if (< d 0) 7 0) d)))))
2863 (day-numbers (list start))
2864 (day-cnt 0)
2865 (inhibit-redisplay (not debug-on-error))
2866 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2867 clocktable-start clocktable-end)
2868 (setq org-agenda-redo-command
2869 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
2870 ;; Make the list of days
2871 (setq ndays (or ndays org-agenda-ndays)
2872 nd ndays)
2873 (while (> ndays 1)
2874 (push (1+ (car day-numbers)) day-numbers)
2875 (setq ndays (1- ndays)))
2876 (setq day-numbers (nreverse day-numbers))
2877 (setq clocktable-start (car day-numbers)
2878 clocktable-end (1+ (or (org-last day-numbers) 0)))
2879 (org-prepare-agenda "Day/Week")
2880 (org-set-local 'org-starting-day (car day-numbers))
2881 (org-set-local 'org-include-all-loc include-all)
2882 (org-set-local 'org-agenda-span
2883 (org-agenda-ndays-to-span nd))
2884 (when (and (or include-all org-agenda-include-all-todo)
2885 (member today day-numbers))
2886 (setq files thefiles
2887 rtnall nil)
2888 (while (setq file (pop files))
2889 (catch 'nextfile
2890 (org-check-agenda-file file)
2891 (setq date (calendar-gregorian-from-absolute today)
2892 rtn (org-agenda-get-day-entries
2893 file date :todo))
2894 (setq rtnall (append rtnall rtn))))
2895 (when rtnall
2896 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2897 (add-text-properties (point-min) (1- (point))
2898 (list 'face 'org-agenda-structure))
2899 (insert (org-finalize-agenda-entries rtnall) "\n")))
2900 (unless org-agenda-compact-blocks
2901 (let* ((d1 (car day-numbers))
2902 (d2 (org-last day-numbers))
2903 (w1 (org-days-to-iso-week d1))
2904 (w2 (org-days-to-iso-week d2)))
2905 (setq s (point))
2906 (if org-agenda-overriding-header
2907 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
2908 nil 'face 'org-agenda-structure) "\n")
2909 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
2910 "-agenda"
2911 (if (< (- d2 d1) 350)
2912 (if (= w1 w2)
2913 (format " (W%02d)" w1)
2914 (format " (W%02d-W%02d)" w1 w2))
2916 ":\n")))
2917 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
2918 'org-date-line t)))
2919 (while (setq d (pop day-numbers))
2920 (setq date (calendar-gregorian-from-absolute d)
2921 wd (calendar-day-of-week date)
2922 s (point))
2923 (if (or (setq todayp (= d today))
2924 (and (not start-pos) (= d sd)))
2925 (setq start-pos (point))
2926 (if (and start-pos (not end-pos))
2927 (setq end-pos (point))))
2928 (setq files thefiles
2929 rtnall nil)
2930 (while (setq file (pop files))
2931 (catch 'nextfile
2932 (org-check-agenda-file file)
2933 (cond
2934 ((eq org-agenda-show-log 'only)
2935 (setq rtn (org-agenda-get-day-entries
2936 file date :closed)))
2937 (org-agenda-show-log
2938 (setq rtn (org-agenda-get-day-entries
2939 file date
2940 :deadline :scheduled :timestamp :sexp :closed)))
2942 (setq rtn (org-agenda-get-day-entries
2943 file date
2944 :deadline :scheduled :sexp :timestamp))))
2945 (setq rtnall (append rtnall rtn))))
2946 (if org-agenda-include-diary
2947 (let ((org-agenda-search-headline-for-time t))
2948 (require 'diary-lib)
2949 (setq rtn (org-get-entries-from-diary date))
2950 (setq rtnall (append rtnall rtn))))
2951 (if (or rtnall org-agenda-show-all-dates)
2952 (progn
2953 (setq day-cnt (1+ day-cnt))
2954 (insert
2955 (if (stringp org-agenda-format-date)
2956 (format-time-string org-agenda-format-date
2957 (org-time-from-absolute date))
2958 (funcall org-agenda-format-date date))
2959 "\n")
2960 (put-text-property s (1- (point)) 'face
2961 (if (member wd org-agenda-weekend-days)
2962 'org-agenda-date-weekend
2963 'org-agenda-date))
2964 (put-text-property s (1- (point)) 'org-date-line t)
2965 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
2966 (when todayp
2967 (put-text-property s (1- (point)) 'org-today t)
2968 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
2969 (if rtnall (insert
2970 (org-finalize-agenda-entries
2971 (org-agenda-add-time-grid-maybe
2972 rtnall nd todayp))
2973 "\n"))
2974 (put-text-property s (1- (point)) 'day d)
2975 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
2976 (when (and org-agenda-clockreport-mode clocktable-start)
2977 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
2978 ;; the above line is to ensure the restricted range!
2979 (p org-agenda-clockreport-parameter-plist)
2980 tbl)
2981 (setq p (org-plist-delete p :block))
2982 (setq p (plist-put p :tstart clocktable-start))
2983 (setq p (plist-put p :tend clocktable-end))
2984 (setq p (plist-put p :scope 'agenda))
2985 (setq tbl (apply 'org-get-clocktable p))
2986 (insert tbl)))
2987 (goto-char (point-min))
2988 (or org-agenda-multi (org-fit-agenda-window))
2989 (unless (and (pos-visible-in-window-p (point-min))
2990 (pos-visible-in-window-p (point-max)))
2991 (goto-char (1- (point-max)))
2992 (recenter -1)
2993 (if (not (pos-visible-in-window-p (or start-pos 1)))
2994 (progn
2995 (goto-char (or start-pos 1))
2996 (recenter 1))))
2997 (goto-char (or start-pos 1))
2998 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
2999 (org-finalize-agenda)
3000 (setq buffer-read-only t)
3001 (message "")))
3003 (defun org-agenda-ndays-to-span (n)
3004 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3006 ;;; Agenda word search
3008 (defvar org-agenda-search-history nil)
3009 (defvar org-todo-only nil)
3011 (defvar org-search-syntax-table nil
3012 "Special syntax table for org-mode search.
3013 In this table, we have single quotes not as word constituents, to
3014 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3016 (defun org-search-syntax-table ()
3017 (unless org-search-syntax-table
3018 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3019 (modify-syntax-entry ?' "." org-search-syntax-table)
3020 (modify-syntax-entry ?` "." org-search-syntax-table))
3021 org-search-syntax-table)
3023 ;;;###autoload
3024 (defun org-search-view (&optional todo-only string edit-at)
3025 "Show all entries that contain words or regular expressions.
3026 If the first character of the search string is an asterisks,
3027 search only the headlines.
3029 With optional prefix argument TODO-ONLY, only consider entries that are
3030 TODO entries. The argument STRING can be used to pass a default search
3031 string into this function. If EDIT-AT is non-nil, it means that the
3032 user should get a chance to edit this string, with cursor at position
3033 EDIT-AT.
3035 The search string is broken into \"words\" by splitting at whitespace.
3036 The individual words are then interpreted as a boolean expression with
3037 logical AND. Words prefixed with a minus must not occur in the entry.
3038 Words without a prefix or prefixed with a plus must occur in the entry.
3039 Matching is case-insensitive and the words are enclosed by word delimiters.
3041 Words enclosed by curly braces are interpreted as regular expressions
3042 that must or must not match in the entry.
3044 If the search string starts with an asterisk, search only in headlines.
3045 If (possibly after the leading star) the search string starts with an
3046 exclamation mark, this also means to look at TODO entries only, an effect
3047 that can also be achieved with a prefix argument.
3049 This command searches the agenda files, and in addition the files listed
3050 in `org-agenda-text-search-extra-files'."
3051 (interactive "P")
3052 (org-compile-prefix-format 'search)
3053 (org-set-sorting-strategy 'search)
3054 (org-prepare-agenda "SEARCH")
3055 (let* ((props (list 'face nil
3056 'done-face 'org-agenda-done
3057 'org-not-done-regexp org-not-done-regexp
3058 'org-todo-regexp org-todo-regexp
3059 'org-complex-heading-regexp org-complex-heading-regexp
3060 'mouse-face 'highlight
3061 'keymap org-agenda-keymap
3062 'help-echo (format "mouse-2 or RET jump to location")))
3063 regexp rtn rtnall files file pos
3064 marker category tags c neg re
3065 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3066 (unless (and (not edit-at)
3067 (stringp string)
3068 (string-match "\\S-" string))
3069 (setq string (read-string "[+-]Word/{Regexp} ...: "
3070 (cond
3071 ((integerp edit-at) (cons string edit-at))
3072 (edit-at string))
3073 'org-agenda-search-history)))
3074 (org-set-local 'org-todo-only todo-only)
3075 (setq org-agenda-redo-command
3076 (list 'org-search-view (if todo-only t nil) string
3077 '(if current-prefix-arg 1 nil)))
3078 (setq org-agenda-query-string string)
3080 (if (equal (string-to-char string) ?*)
3081 (setq hdl-only t
3082 words (substring string 1))
3083 (setq words string))
3084 (when (equal (string-to-char words) ?!)
3085 (setq todo-only t
3086 words (substring words 1)))
3087 (setq words (org-split-string words))
3088 (mapc (lambda (w)
3089 (setq c (string-to-char w))
3090 (if (equal c ?-)
3091 (setq neg t w (substring w 1))
3092 (if (equal c ?+)
3093 (setq neg nil w (substring w 1))
3094 (setq neg nil)))
3095 (if (string-match "\\`{.*}\\'" w)
3096 (setq re (substring w 1 -1))
3097 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
3098 (if neg (push re regexps-) (push re regexps+)))
3099 words)
3100 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3101 (if (not regexps+)
3102 (setq regexp (concat "^" org-outline-regexp))
3103 (setq regexp (pop regexps+))
3104 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3105 regexp))))
3106 (setq files (org-agenda-files nil 'ifmode))
3107 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3108 (pop org-agenda-text-search-extra-files)
3109 (setq files (org-add-archive-files files)))
3110 (setq files (append files org-agenda-text-search-extra-files)
3111 rtnall nil)
3112 (while (setq file (pop files))
3113 (setq ee nil)
3114 (catch 'nextfile
3115 (org-check-agenda-file file)
3116 (setq buffer (if (file-exists-p file)
3117 (org-get-agenda-file-buffer file)
3118 (error "No such file %s" file)))
3119 (if (not buffer)
3120 ;; If file does not exist, make sure an error message is sent
3121 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3122 file))))
3123 (with-current-buffer buffer
3124 (with-syntax-table (org-search-syntax-table)
3125 (unless (org-mode-p)
3126 (error "Agenda file %s is not in `org-mode'" file))
3127 (let ((case-fold-search t))
3128 (save-excursion
3129 (save-restriction
3130 (if org-agenda-restrict
3131 (narrow-to-region org-agenda-restrict-begin
3132 org-agenda-restrict-end)
3133 (widen))
3134 (goto-char (point-min))
3135 (unless (or (org-on-heading-p)
3136 (outline-next-heading))
3137 (throw 'nextfile t))
3138 (goto-char (max (point-min) (1- (point))))
3139 (while (re-search-forward regexp nil t)
3140 (org-back-to-heading t)
3141 (skip-chars-forward "* ")
3142 (setq beg (point-at-bol)
3143 beg1 (point)
3144 end (progn (outline-next-heading) (point)))
3145 (catch :skip
3146 (goto-char beg)
3147 (org-agenda-skip)
3148 (setq str (buffer-substring-no-properties
3149 (point-at-bol)
3150 (if hdl-only (point-at-eol) end)))
3151 (mapc (lambda (wr) (when (string-match wr str)
3152 (goto-char (1- end))
3153 (throw :skip t)))
3154 regexps-)
3155 (mapc (lambda (wr) (unless (string-match wr str)
3156 (goto-char (1- end))
3157 (throw :skip t)))
3158 (if todo-only
3159 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3160 regexps+)
3161 regexps+))
3162 (goto-char beg)
3163 (setq marker (org-agenda-new-marker (point))
3164 category (org-get-category)
3165 tags (org-get-tags-at (point))
3166 txt (org-format-agenda-item
3168 (buffer-substring-no-properties
3169 beg1 (point-at-eol))
3170 category tags))
3171 (org-add-props txt props
3172 'org-marker marker 'org-hd-marker marker
3173 'org-todo-regexp org-todo-regexp
3174 'org-complex-heading-regexp org-complex-heading-regexp
3175 'priority 1000 'org-category category
3176 'type "search")
3177 (push txt ee)
3178 (goto-char (1- end))))))))))
3179 (setq rtn (nreverse ee))
3180 (setq rtnall (append rtnall rtn)))
3181 (if org-agenda-overriding-header
3182 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3183 nil 'face 'org-agenda-structure) "\n")
3184 (insert "Search words: ")
3185 (add-text-properties (point-min) (1- (point))
3186 (list 'face 'org-agenda-structure))
3187 (setq pos (point))
3188 (insert string "\n")
3189 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3190 (setq pos (point))
3191 (unless org-agenda-multi
3192 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3193 (add-text-properties pos (1- (point))
3194 (list 'face 'org-agenda-structure))))
3195 (when rtnall
3196 (insert (org-finalize-agenda-entries rtnall) "\n"))
3197 (goto-char (point-min))
3198 (or org-agenda-multi (org-fit-agenda-window))
3199 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3200 (org-finalize-agenda)
3201 (setq buffer-read-only t)))
3203 ;;; Agenda TODO list
3205 (defvar org-select-this-todo-keyword nil)
3206 (defvar org-last-arg nil)
3208 ;;;###autoload
3209 (defun org-todo-list (arg)
3210 "Show all TODO entries from all agenda file in a single list.
3211 The prefix arg can be used to select a specific TODO keyword and limit
3212 the list to these. When using \\[universal-argument], you will be prompted
3213 for a keyword. A numeric prefix directly selects the Nth keyword in
3214 `org-todo-keywords-1'."
3215 (interactive "P")
3216 (require 'calendar)
3217 (org-compile-prefix-format 'todo)
3218 (org-set-sorting-strategy 'todo)
3219 (org-prepare-agenda "TODO")
3220 (let* ((today (time-to-days (current-time)))
3221 (date (calendar-gregorian-from-absolute today))
3222 (kwds org-todo-keywords-for-agenda)
3223 (completion-ignore-case t)
3224 (org-select-this-todo-keyword
3225 (if (stringp arg) arg
3226 (and arg (integerp arg) (> arg 0)
3227 (nth (1- arg) kwds))))
3228 rtn rtnall files file pos)
3229 (when (equal arg '(4))
3230 (setq org-select-this-todo-keyword
3231 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3232 (mapcar 'list kwds) nil nil)))
3233 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3234 (org-set-local 'org-last-arg arg)
3235 (setq org-agenda-redo-command
3236 '(org-todo-list (or current-prefix-arg org-last-arg)))
3237 (setq files (org-agenda-files nil 'ifmode)
3238 rtnall nil)
3239 (while (setq file (pop files))
3240 (catch 'nextfile
3241 (org-check-agenda-file file)
3242 (setq rtn (org-agenda-get-day-entries file date :todo))
3243 (setq rtnall (append rtnall rtn))))
3244 (if org-agenda-overriding-header
3245 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3246 nil 'face 'org-agenda-structure) "\n")
3247 (insert "Global list of TODO items of type: ")
3248 (add-text-properties (point-min) (1- (point))
3249 (list 'face 'org-agenda-structure))
3250 (setq pos (point))
3251 (insert (or org-select-this-todo-keyword "ALL") "\n")
3252 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3253 (setq pos (point))
3254 (unless org-agenda-multi
3255 (insert "Available with `N r': (0)ALL")
3256 (let ((n 0) s)
3257 (mapc (lambda (x)
3258 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3259 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3260 (insert "\n "))
3261 (insert " " s))
3262 kwds))
3263 (insert "\n"))
3264 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3265 (when rtnall
3266 (insert (org-finalize-agenda-entries rtnall) "\n"))
3267 (goto-char (point-min))
3268 (or org-agenda-multi (org-fit-agenda-window))
3269 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3270 (org-finalize-agenda)
3271 (setq buffer-read-only t)))
3273 ;;; Agenda tags match
3275 ;;;###autoload
3276 (defun org-tags-view (&optional todo-only match)
3277 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3278 The prefix arg TODO-ONLY limits the search to TODO entries."
3279 (interactive "P")
3280 (org-compile-prefix-format 'tags)
3281 (org-set-sorting-strategy 'tags)
3282 (let* ((org-tags-match-list-sublevels
3283 ;?????? (if todo-only t org-tags-match-list-sublevels))
3284 org-tags-match-list-sublevels)
3285 (completion-ignore-case t)
3286 rtn rtnall files file pos matcher
3287 buffer)
3288 (setq matcher (org-make-tags-matcher match)
3289 match (car matcher) matcher (cdr matcher))
3290 (org-prepare-agenda (concat "TAGS " match))
3291 (setq org-agenda-query-string match)
3292 (setq org-agenda-redo-command
3293 (list 'org-tags-view (list 'quote todo-only)
3294 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3295 (setq files (org-agenda-files nil 'ifmode)
3296 rtnall nil)
3297 (while (setq file (pop files))
3298 (catch 'nextfile
3299 (org-check-agenda-file file)
3300 (setq buffer (if (file-exists-p file)
3301 (org-get-agenda-file-buffer file)
3302 (error "No such file %s" file)))
3303 (if (not buffer)
3304 ;; If file does not exist, error message to agenda
3305 (setq rtn (list
3306 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3307 rtnall (append rtnall rtn))
3308 (with-current-buffer buffer
3309 (unless (org-mode-p)
3310 (error "Agenda file %s is not in `org-mode'" file))
3311 (save-excursion
3312 (save-restriction
3313 (if org-agenda-restrict
3314 (narrow-to-region org-agenda-restrict-begin
3315 org-agenda-restrict-end)
3316 (widen))
3317 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3318 (setq rtnall (append rtnall rtn))))))))
3319 (if org-agenda-overriding-header
3320 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3321 nil 'face 'org-agenda-structure) "\n")
3322 (insert "Headlines with TAGS match: ")
3323 (add-text-properties (point-min) (1- (point))
3324 (list 'face 'org-agenda-structure))
3325 (setq pos (point))
3326 (insert match "\n")
3327 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3328 (setq pos (point))
3329 (unless org-agenda-multi
3330 (insert "Press `C-u r' to search again with new search string\n"))
3331 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3332 (when rtnall
3333 (insert (org-finalize-agenda-entries rtnall) "\n"))
3334 (goto-char (point-min))
3335 (or org-agenda-multi (org-fit-agenda-window))
3336 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3337 (org-finalize-agenda)
3338 (setq buffer-read-only t)))
3340 ;;; Agenda Finding stuck projects
3342 (defvar org-agenda-skip-regexp nil
3343 "Regular expression used in skipping subtrees for the agenda.
3344 This is basically a temporary global variable that can be set and then
3345 used by user-defined selections using `org-agenda-skip-function'.")
3347 (defvar org-agenda-overriding-header nil
3348 "When this is set during todo and tags searches, will replace header.
3349 This variable should not be set directly, but custom commands can bind it
3350 in the options section.")
3352 (defun org-agenda-skip-entry-when-regexp-matches ()
3353 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3354 If yes, it returns the end position of this entry, causing agenda commands
3355 to skip the entry but continuing the search in the subtree. This is a
3356 function that can be put into `org-agenda-skip-function' for the duration
3357 of a command."
3358 (let ((end (save-excursion (org-end-of-subtree t)))
3359 skip)
3360 (save-excursion
3361 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3362 (and skip end)))
3364 (defun org-agenda-skip-subtree-when-regexp-matches ()
3365 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3366 If yes, it returns the end position of this tree, causing agenda commands
3367 to skip this subtree. This is a function that can be put into
3368 `org-agenda-skip-function' for the duration of a command."
3369 (let ((end (save-excursion (org-end-of-subtree t)))
3370 skip)
3371 (save-excursion
3372 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3373 (and skip end)))
3375 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3376 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3377 If yes, it returns the end position of the current entry (NOT the tree),
3378 causing agenda commands to skip the entry but continuing the search in
3379 the subtree. This is a function that can be put into
3380 `org-agenda-skip-function' for the duration of a command. An important
3381 use of this function is for the stuck project list."
3382 (let ((end (save-excursion (org-end-of-subtree t)))
3383 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3384 skip)
3385 (save-excursion
3386 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3387 (and skip entry-end)))
3389 (defun org-agenda-skip-entry-if (&rest conditions)
3390 "Skip entry if any of CONDITIONS is true.
3391 See `org-agenda-skip-if' for details."
3392 (org-agenda-skip-if nil conditions))
3394 (defun org-agenda-skip-subtree-if (&rest conditions)
3395 "Skip entry if any of CONDITIONS is true.
3396 See `org-agenda-skip-if' for details."
3397 (org-agenda-skip-if t conditions))
3399 (defun org-agenda-skip-if (subtree conditions)
3400 "Checks current entity for CONDITIONS.
3401 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3402 the entry, i.e. the text before the next heading is checked.
3404 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3405 from different tests. Valid conditions are:
3407 scheduled Check if there is a scheduled cookie
3408 notscheduled Check if there is no scheduled cookie
3409 deadline Check if there is a deadline
3410 notdeadline Check if there is no deadline
3411 timestamp Check if there is a timestamp (also deadline or scheduled)
3412 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3413 regexp Check if regexp matches
3414 notregexp Check if regexp does not match.
3416 The regexp is taken from the conditions list, it must come right after
3417 the `regexp' or `notregexp' element.
3419 If any of these conditions is met, this function returns the end point of
3420 the entity, causing the search to continue from there. This is a function
3421 that can be put into `org-agenda-skip-function' for the duration of a command."
3422 (let (beg end m)
3423 (org-back-to-heading t)
3424 (setq beg (point)
3425 end (if subtree
3426 (progn (org-end-of-subtree t) (point))
3427 (progn (outline-next-heading) (1- (point)))))
3428 (goto-char beg)
3429 (and
3431 (and (memq 'scheduled conditions)
3432 (re-search-forward org-scheduled-time-regexp end t))
3433 (and (memq 'notscheduled conditions)
3434 (not (re-search-forward org-scheduled-time-regexp end t)))
3435 (and (memq 'deadline conditions)
3436 (re-search-forward org-deadline-time-regexp end t))
3437 (and (memq 'notdeadline conditions)
3438 (not (re-search-forward org-deadline-time-regexp end t)))
3439 (and (memq 'timestamp conditions)
3440 (re-search-forward org-ts-regexp end t))
3441 (and (memq 'nottimestamp conditions)
3442 (not (re-search-forward org-ts-regexp end t)))
3443 (and (setq m (memq 'regexp conditions))
3444 (stringp (nth 1 m))
3445 (re-search-forward (nth 1 m) end t))
3446 (and (setq m (memq 'notregexp conditions))
3447 (stringp (nth 1 m))
3448 (not (re-search-forward (nth 1 m) end t))))
3449 end)))
3451 ;;;###autoload
3452 (defun org-agenda-list-stuck-projects (&rest ignore)
3453 "Create agenda view for projects that are stuck.
3454 Stuck projects are project that have no next actions. For the definitions
3455 of what a project is and how to check if it stuck, customize the variable
3456 `org-stuck-projects'.
3457 MATCH is being ignored."
3458 (interactive)
3459 (let* ((org-agenda-skip-function
3460 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3461 ;; We could have used org-agenda-skip-if here.
3462 (org-agenda-overriding-header
3463 (or org-agenda-overriding-header "List of stuck projects: "))
3464 (matcher (nth 0 org-stuck-projects))
3465 (todo (nth 1 org-stuck-projects))
3466 (todo-wds (if (member "*" todo)
3467 (progn
3468 (org-prepare-agenda-buffers (org-agenda-files
3469 nil 'ifmode))
3470 (org-delete-all
3471 org-done-keywords-for-agenda
3472 (copy-sequence org-todo-keywords-for-agenda)))
3473 todo))
3474 (todo-re (concat "^\\*+[ \t]+\\("
3475 (mapconcat 'identity todo-wds "\\|")
3476 "\\)\\>"))
3477 (tags (nth 2 org-stuck-projects))
3478 (tags-re (if (member "*" tags)
3479 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3480 (if tags
3481 (concat "^\\*+ .*:\\("
3482 (mapconcat 'identity tags "\\|")
3483 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3484 (gen-re (nth 3 org-stuck-projects))
3485 (re-list
3486 (delq nil
3487 (list
3488 (if todo todo-re)
3489 (if tags tags-re)
3490 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3491 gen-re)))))
3492 (setq org-agenda-skip-regexp
3493 (if re-list
3494 (mapconcat 'identity re-list "\\|")
3495 (error "No information how to identify unstuck projects")))
3496 (org-tags-view nil matcher)
3497 (with-current-buffer org-agenda-buffer-name
3498 (setq org-agenda-redo-command
3499 '(org-agenda-list-stuck-projects
3500 (or current-prefix-arg org-last-arg))))))
3502 ;;; Diary integration
3504 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3505 (defvar list-diary-entries-hook)
3507 (defun org-get-entries-from-diary (date)
3508 "Get the (Emacs Calendar) diary entries for DATE."
3509 (require 'diary-lib)
3510 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3511 (fancy-diary-buffer diary-fancy-buffer)
3512 (diary-display-hook '(fancy-diary-display))
3513 (diary-display-function 'fancy-diary-display)
3514 (pop-up-frames nil)
3515 (list-diary-entries-hook
3516 (cons 'org-diary-default-entry list-diary-entries-hook))
3517 (diary-file-name-prefix-function nil) ; turn this feature off
3518 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3519 entries
3520 (org-disable-agenda-to-diary t))
3521 (save-excursion
3522 (save-window-excursion
3523 (funcall (if (fboundp 'diary-list-entries)
3524 'diary-list-entries 'list-diary-entries)
3525 date 1)))
3526 (if (not (get-buffer diary-fancy-buffer))
3527 (setq entries nil)
3528 (with-current-buffer diary-fancy-buffer
3529 (setq buffer-read-only nil)
3530 (if (zerop (buffer-size))
3531 ;; No entries
3532 (setq entries nil)
3533 ;; Omit the date and other unnecessary stuff
3534 (org-agenda-cleanup-fancy-diary)
3535 ;; Add prefix to each line and extend the text properties
3536 (if (zerop (buffer-size))
3537 (setq entries nil)
3538 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
3539 (set-buffer-modified-p nil)
3540 (kill-buffer diary-fancy-buffer)))
3541 (when entries
3542 (setq entries (org-split-string entries "\n"))
3543 (setq entries
3544 (mapcar
3545 (lambda (x)
3546 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
3547 ;; Extend the text properties to the beginning of the line
3548 (org-add-props x (text-properties-at (1- (length x)) x)
3549 'type "diary" 'date date))
3550 entries)))))
3552 (defvar org-agenda-cleanup-fancy-diary-hook nil
3553 "Hook run when the fancy diary buffer is cleaned up.")
3555 (defun org-agenda-cleanup-fancy-diary ()
3556 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3557 This gets rid of the date, the underline under the date, and
3558 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3559 date. It also removes lines that contain only whitespace."
3560 (goto-char (point-min))
3561 (if (looking-at ".*?:[ \t]*")
3562 (progn
3563 (replace-match "")
3564 (re-search-forward "\n=+$" nil t)
3565 (replace-match "")
3566 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
3567 (re-search-forward "\n=+$" nil t)
3568 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3569 (goto-char (point-min))
3570 (while (re-search-forward "^ +\n" nil t)
3571 (replace-match ""))
3572 (goto-char (point-min))
3573 (if (re-search-forward "^Org-mode dummy\n?" nil t)
3574 (replace-match ""))
3575 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
3577 ;; Make sure entries from the diary have the right text properties.
3578 (eval-after-load "diary-lib"
3579 '(if (boundp 'diary-modify-entry-list-string-function)
3580 ;; We can rely on the hook, nothing to do
3582 ;; Hook not available, must use advice to make this work
3583 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
3584 "Make the position visible."
3585 (if (and org-disable-agenda-to-diary ;; called from org-agenda
3586 (stringp string)
3587 buffer-file-name)
3588 (setq string (org-modify-diary-entry-string string))))))
3590 (defun org-modify-diary-entry-string (string)
3591 "Add text properties to string, allowing org-mode to act on it."
3592 (org-add-props string nil
3593 'mouse-face 'highlight
3594 'keymap org-agenda-keymap
3595 'help-echo (if buffer-file-name
3596 (format "mouse-2 or RET jump to diary file %s"
3597 (abbreviate-file-name buffer-file-name))
3599 'org-agenda-diary-link t
3600 'org-marker (org-agenda-new-marker (point-at-bol))))
3602 (defun org-diary-default-entry ()
3603 "Add a dummy entry to the diary.
3604 Needed to avoid empty dates which mess up holiday display."
3605 ;; Catch the error if dealing with the new add-to-diary-alist
3606 (when org-disable-agenda-to-diary
3607 (condition-case nil
3608 (org-add-to-diary-list original-date "Org-mode dummy" "")
3609 (error
3610 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
3612 (defun org-add-to-diary-list (&rest args)
3613 (if (fboundp 'diary-add-to-list)
3614 (apply 'diary-add-to-list args)
3615 (apply 'add-to-diary-list args)))
3617 ;;;###autoload
3618 (defun org-diary (&rest args)
3619 "Return diary information from org-files.
3620 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3621 It accesses org files and extracts information from those files to be
3622 listed in the diary. The function accepts arguments specifying what
3623 items should be listed. The following arguments are allowed:
3625 :timestamp List the headlines of items containing a date stamp or
3626 date range matching the selected date. Deadlines will
3627 also be listed, on the expiration day.
3629 :sexp List entries resulting from diary-like sexps.
3631 :deadline List any deadlines past due, or due within
3632 `org-deadline-warning-days'. The listing occurs only
3633 in the diary for *today*, not at any other date. If
3634 an entry is marked DONE, it is no longer listed.
3636 :scheduled List all items which are scheduled for the given date.
3637 The diary for *today* also contains items which were
3638 scheduled earlier and are not yet marked DONE.
3640 :todo List all TODO items from the org-file. This may be a
3641 long list - so this is not turned on by default.
3642 Like deadlines, these entries only show up in the
3643 diary for *today*, not at any other date.
3645 The call in the diary file should look like this:
3647 &%%(org-diary) ~/path/to/some/orgfile.org
3649 Use a separate line for each org file to check. Or, if you omit the file name,
3650 all files listed in `org-agenda-files' will be checked automatically:
3652 &%%(org-diary)
3654 If you don't give any arguments (as in the example above), the default
3655 arguments (:deadline :scheduled :timestamp :sexp) are used.
3656 So the example above may also be written as
3658 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3660 The function expects the lisp variables `entry' and `date' to be provided
3661 by the caller, because this is how the calendar works. Don't use this
3662 function from a program - use `org-agenda-get-day-entries' instead."
3663 (when (> (- (time-to-seconds (current-time))
3664 org-agenda-last-marker-time)
3666 (org-agenda-reset-markers))
3667 (org-compile-prefix-format 'agenda)
3668 (org-set-sorting-strategy 'agenda)
3669 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3670 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
3671 (list entry)
3672 (org-agenda-files t)))
3673 file rtn results)
3674 (org-prepare-agenda-buffers files)
3675 ;; If this is called during org-agenda, don't return any entries to
3676 ;; the calendar. Org Agenda will list these entries itself.
3677 (if org-disable-agenda-to-diary (setq files nil))
3678 (while (setq file (pop files))
3679 (setq rtn (apply 'org-agenda-get-day-entries file date args))
3680 (setq results (append results rtn)))
3681 (if results
3682 (concat (org-finalize-agenda-entries results) "\n"))))
3684 ;;; Agenda entry finders
3686 (defun org-agenda-get-day-entries (file date &rest args)
3687 "Does the work for `org-diary' and `org-agenda'.
3688 FILE is the path to a file to be checked for entries. DATE is date like
3689 the one returned by `calendar-current-date'. ARGS are symbols indicating
3690 which kind of entries should be extracted. For details about these, see
3691 the documentation of `org-diary'."
3692 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3693 (let* ((org-startup-folded nil)
3694 (org-startup-align-all-tables nil)
3695 (buffer (if (file-exists-p file)
3696 (org-get-agenda-file-buffer file)
3697 (error "No such file %s" file)))
3698 arg results rtn deadline-results)
3699 (if (not buffer)
3700 ;; If file does not exist, make sure an error message ends up in diary
3701 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3702 (with-current-buffer buffer
3703 (unless (org-mode-p)
3704 (error "Agenda file %s is not in `org-mode'" file))
3705 (let ((case-fold-search nil))
3706 (save-excursion
3707 (save-restriction
3708 (if org-agenda-restrict
3709 (narrow-to-region org-agenda-restrict-begin
3710 org-agenda-restrict-end)
3711 (widen))
3712 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3713 (while (setq arg (pop args))
3714 (cond
3715 ((and (eq arg :todo)
3716 (equal date (calendar-current-date)))
3717 (setq rtn (org-agenda-get-todos))
3718 (setq results (append results rtn)))
3719 ((eq arg :timestamp)
3720 (setq rtn (org-agenda-get-blocks))
3721 (setq results (append results rtn))
3722 (setq rtn (org-agenda-get-timestamps))
3723 (setq results (append results rtn)))
3724 ((eq arg :sexp)
3725 (setq rtn (org-agenda-get-sexps))
3726 (setq results (append results rtn)))
3727 ((eq arg :scheduled)
3728 (setq rtn (org-agenda-get-scheduled deadline-results))
3729 (setq results (append results rtn)))
3730 ((eq arg :closed)
3731 (setq rtn (org-agenda-get-progress))
3732 (setq results (append results rtn)))
3733 ((eq arg :deadline)
3734 (setq rtn (org-agenda-get-deadlines))
3735 (setq deadline-results (copy-sequence rtn))
3736 (setq results (append results rtn))))))))
3737 results))))
3739 (defun org-agenda-get-todos ()
3740 "Return the TODO information for agenda display."
3741 (let* ((props (list 'face nil
3742 'done-face 'org-agenda-done
3743 'org-not-done-regexp org-not-done-regexp
3744 'org-todo-regexp org-todo-regexp
3745 'org-complex-heading-regexp org-complex-heading-regexp
3746 'mouse-face 'highlight
3747 'keymap org-agenda-keymap
3748 'help-echo
3749 (format "mouse-2 or RET jump to org file %s"
3750 (abbreviate-file-name buffer-file-name))))
3751 (regexp (concat "^\\*+[ \t]+\\("
3752 (if org-select-this-todo-keyword
3753 (if (equal org-select-this-todo-keyword "*")
3754 org-todo-regexp
3755 (concat "\\<\\("
3756 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
3757 "\\)\\>"))
3758 org-not-done-regexp)
3759 "[^\n\r]*\\)"))
3760 marker priority category tags todo-state
3761 ee txt beg end)
3762 (goto-char (point-min))
3763 (while (re-search-forward regexp nil t)
3764 (catch :skip
3765 (save-match-data
3766 (beginning-of-line)
3767 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
3768 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
3769 (goto-char (1+ beg))
3770 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
3771 (throw :skip nil)))
3772 (goto-char beg)
3773 (org-agenda-skip)
3774 (goto-char (match-beginning 1))
3775 (setq marker (org-agenda-new-marker (match-beginning 0))
3776 category (org-get-category)
3777 txt (match-string 1)
3778 tags (org-get-tags-at (point))
3779 txt (org-format-agenda-item "" txt category tags)
3780 priority (1+ (org-get-priority txt))
3781 todo-state (org-get-todo-state))
3782 (org-add-props txt props
3783 'org-marker marker 'org-hd-marker marker
3784 'priority priority 'org-category category
3785 'type "todo" 'todo-state todo-state)
3786 (push txt ee)
3787 (if org-agenda-todo-list-sublevels
3788 (goto-char (match-end 1))
3789 (org-end-of-subtree 'invisible))))
3790 (nreverse ee)))
3792 ;;;###autoload
3793 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
3794 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3795 (when (or org-agenda-todo-ignore-with-date
3796 org-agenda-todo-ignore-scheduled
3797 org-agenda-todo-ignore-deadlines)
3798 (setq end (or end (save-excursion (outline-next-heading) (point))))
3799 (save-excursion
3800 (or (and org-agenda-todo-ignore-with-date
3801 (re-search-forward org-ts-regexp end t))
3802 (and org-agenda-todo-ignore-scheduled
3803 (re-search-forward org-scheduled-time-regexp end t))
3804 (and org-agenda-todo-ignore-deadlines
3805 (re-search-forward org-deadline-time-regexp end t)
3806 (org-deadline-close (match-string 1)))))))
3808 (defconst org-agenda-no-heading-message
3809 "No heading for this item in buffer or region.")
3811 (defun org-agenda-get-timestamps ()
3812 "Return the date stamp information for agenda display."
3813 (let* ((props (list 'face nil
3814 'org-not-done-regexp org-not-done-regexp
3815 'org-todo-regexp org-todo-regexp
3816 'org-complex-heading-regexp org-complex-heading-regexp
3817 'mouse-face 'highlight
3818 'keymap org-agenda-keymap
3819 'help-echo
3820 (format "mouse-2 or RET jump to org file %s"
3821 (abbreviate-file-name buffer-file-name))))
3822 (d1 (calendar-absolute-from-gregorian date))
3823 (remove-re
3824 (concat
3825 (regexp-quote
3826 (format-time-string
3827 "<%Y-%m-%d"
3828 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
3829 ".*?>"))
3830 (regexp
3831 (concat
3832 (if org-agenda-include-inactive-timestamps "[[<]" "<")
3833 (regexp-quote
3834 (substring
3835 (format-time-string
3836 (car org-time-stamp-formats)
3837 (apply 'encode-time ; DATE bound by calendar
3838 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
3839 1 11))
3840 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3841 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3842 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3843 donep tmp priority category ee txt timestr tags b0 b3 e3 head
3844 todo-state end-of-match)
3845 (goto-char (point-min))
3846 (while (setq end-of-match (re-search-forward regexp nil t))
3847 (setq b0 (match-beginning 0)
3848 b3 (match-beginning 3) e3 (match-end 3))
3849 (catch :skip
3850 (and (org-at-date-range-p) (throw :skip nil))
3851 (org-agenda-skip)
3852 (if (and (match-end 1)
3853 (not (= d1 (org-time-string-to-absolute
3854 (match-string 1) d1 nil
3855 org-agenda-repeating-timestamp-show-all))))
3856 (throw :skip nil))
3857 (if (and e3
3858 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
3859 (throw :skip nil))
3860 (setq tmp (buffer-substring (max (point-min)
3861 (- b0 org-ds-keyword-length))
3863 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
3864 inactivep (= (char-after b0) ?\[)
3865 deadlinep (string-match org-deadline-regexp tmp)
3866 scheduledp (string-match org-scheduled-regexp tmp)
3867 closedp (and org-agenda-include-inactive-timestamps
3868 (string-match org-closed-string tmp))
3869 clockp (and org-agenda-include-inactive-timestamps
3870 (or (string-match org-clock-string tmp)
3871 (string-match "]-+\\'" tmp)))
3872 todo-state (org-get-todo-state)
3873 donep (member todo-state org-done-keywords))
3874 (if (or scheduledp deadlinep closedp clockp
3875 (and donep org-agenda-skip-timestamp-if-done))
3876 (throw :skip t))
3877 (if (string-match ">" timestr)
3878 ;; substring should only run to end of time stamp
3879 (setq timestr (substring timestr 0 (match-end 0))))
3880 (setq marker (org-agenda-new-marker b0)
3881 category (org-get-category b0))
3882 (save-excursion
3883 (if (not (re-search-backward "^\\*+ " nil t))
3884 (setq txt org-agenda-no-heading-message)
3885 (goto-char (match-beginning 0))
3886 (setq hdmarker (org-agenda-new-marker)
3887 tags (org-get-tags-at))
3888 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3889 (setq head (match-string 1))
3890 (setq txt (org-format-agenda-item
3891 (if inactivep "[" nil)
3892 head category tags timestr nil
3893 remove-re)))
3894 (setq priority (org-get-priority txt))
3895 (org-add-props txt props
3896 'org-marker marker 'org-hd-marker hdmarker)
3897 (org-add-props txt nil 'priority priority
3898 'org-category category 'date date
3899 'todo-state todo-state
3900 'type "timestamp")
3901 (push txt ee))
3902 (if org-agenda-skip-additional-timestamps-same-entry
3903 (outline-next-heading)
3904 (goto-char end-of-match))))
3905 (nreverse ee)))
3907 (defun org-agenda-get-sexps ()
3908 "Return the sexp information for agenda display."
3909 (require 'diary-lib)
3910 (let* ((props (list 'face nil
3911 'mouse-face 'highlight
3912 'keymap org-agenda-keymap
3913 'help-echo
3914 (format "mouse-2 or RET jump to org file %s"
3915 (abbreviate-file-name buffer-file-name))))
3916 (regexp "^&?%%(")
3917 marker category ee txt tags entry result beg b sexp sexp-entry
3918 todo-state)
3919 (goto-char (point-min))
3920 (while (re-search-forward regexp nil t)
3921 (catch :skip
3922 (org-agenda-skip)
3923 (setq beg (match-beginning 0))
3924 (goto-char (1- (match-end 0)))
3925 (setq b (point))
3926 (forward-sexp 1)
3927 (setq sexp (buffer-substring b (point)))
3928 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
3929 (org-trim (match-string 1))
3930 ""))
3931 (setq result (org-diary-sexp-entry sexp sexp-entry date))
3932 (when result
3933 (setq marker (org-agenda-new-marker beg)
3934 category (org-get-category beg)
3935 todo-state (org-get-todo-state))
3937 (if (string-match "\\S-" result)
3938 (setq txt result)
3939 (setq txt "SEXP entry returned empty string"))
3941 (setq txt (org-format-agenda-item
3942 "" txt category tags 'time))
3943 (org-add-props txt props 'org-marker marker)
3944 (org-add-props txt nil
3945 'org-category category 'date date 'todo-state todo-state
3946 'type "sexp")
3947 (push txt ee))))
3948 (nreverse ee)))
3950 (defalias 'org-get-closed 'org-agenda-get-progress)
3951 (defun org-agenda-get-progress ()
3952 "Return the logged TODO entries for agenda display."
3953 (let* ((props (list 'mouse-face 'highlight
3954 'org-not-done-regexp org-not-done-regexp
3955 'org-todo-regexp org-todo-regexp
3956 'org-complex-heading-regexp org-complex-heading-regexp
3957 'keymap org-agenda-keymap
3958 'help-echo
3959 (format "mouse-2 or RET jump to org file %s"
3960 (abbreviate-file-name buffer-file-name))))
3961 (items (if (consp org-agenda-show-log)
3962 org-agenda-show-log
3963 org-agenda-log-mode-items))
3964 (parts
3965 (delq nil
3966 (list
3967 (if (memq 'closed items) (concat "\\<" org-closed-string))
3968 (if (memq 'clock items) (concat "\\<" org-clock-string))
3969 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
3970 (parts-re (if parts (mapconcat 'identity parts "\\|")
3971 (error "`org-agenda-log-mode-items' is empty")))
3972 (regexp (concat
3973 "\\(" parts-re "\\)"
3974 " *\\["
3975 (regexp-quote
3976 (substring
3977 (format-time-string
3978 (car org-time-stamp-formats)
3979 (apply 'encode-time ; DATE bound by calendar
3980 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
3981 1 11))))
3982 (org-agenda-search-headline-for-time nil)
3983 marker hdmarker priority category tags closedp statep clockp state
3984 ee txt extra timestr rest clocked)
3985 (goto-char (point-min))
3986 (while (re-search-forward regexp nil t)
3987 (catch :skip
3988 (org-agenda-skip)
3989 (setq marker (org-agenda-new-marker (match-beginning 0))
3990 closedp (equal (match-string 1) org-closed-string)
3991 statep (equal (string-to-char (match-string 1)) ?-)
3992 clockp (not (or closedp statep))
3993 state (and statep (match-string 2))
3994 category (org-get-category (match-beginning 0))
3995 timestr (buffer-substring (match-beginning 0) (point-at-eol))
3997 (when (string-match "\\]" timestr)
3998 ;; substring should only run to end of time stamp
3999 (setq rest (substring timestr (match-end 0))
4000 timestr (substring timestr 0 (match-end 0)))
4001 (if (and (not closedp) (not statep)
4002 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4003 (progn (setq timestr (concat (substring timestr 0 -1)
4004 "-" (match-string 1 rest) "]"))
4005 (setq clocked (match-string 2 rest)))
4006 (setq clocked "-")))
4007 (save-excursion
4008 (cond
4009 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4010 (statep
4011 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4012 (setq extra (match-string 1))))
4013 (clockp
4014 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4015 (setq extra (match-string 1))))
4016 (t (setq extra nil)))
4017 (if (not (re-search-backward "^\\*+ " nil t))
4018 (setq txt org-agenda-no-heading-message)
4019 (goto-char (match-beginning 0))
4020 (setq hdmarker (org-agenda-new-marker)
4021 tags (org-get-tags-at))
4022 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4023 (setq txt (match-string 1))
4024 (when extra
4025 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4026 (setq txt (concat (substring txt 0 (match-beginning 1))
4027 " - " extra " " (match-string 2 txt)))
4028 (setq txt (concat txt " - " extra))))
4029 (setq txt (org-format-agenda-item
4030 (cond
4031 (closedp "Closed: ")
4032 (statep (concat "State: (" state ")"))
4033 (t (concat "Clocked: (" clocked ")")))
4034 txt category tags timestr)))
4035 (setq priority 100000)
4036 (org-add-props txt props
4037 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4038 'priority priority 'org-category category
4039 'type "closed" 'date date
4040 'undone-face 'org-warning 'done-face 'org-agenda-done)
4041 (push txt ee))
4042 (goto-char (point-at-eol))))
4043 (nreverse ee)))
4045 (defun org-agenda-get-deadlines ()
4046 "Return the deadline information for agenda display."
4047 (let* ((props (list 'mouse-face 'highlight
4048 'org-not-done-regexp org-not-done-regexp
4049 'org-todo-regexp org-todo-regexp
4050 'org-complex-heading-regexp org-complex-heading-regexp
4051 'keymap org-agenda-keymap
4052 'help-echo
4053 (format "mouse-2 or RET jump to org file %s"
4054 (abbreviate-file-name buffer-file-name))))
4055 (regexp org-deadline-time-regexp)
4056 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4057 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4058 d2 diff dfrac wdays pos pos1 category tags
4059 ee txt head face s todo-state upcomingp donep timestr)
4060 (goto-char (point-min))
4061 (while (re-search-forward regexp nil t)
4062 (catch :skip
4063 (org-agenda-skip)
4064 (setq s (match-string 1)
4065 txt nil
4066 pos (1- (match-beginning 1))
4067 d2 (org-time-string-to-absolute
4068 (match-string 1) d1 'past
4069 org-agenda-repeating-timestamp-show-all)
4070 diff (- d2 d1)
4071 wdays (org-get-wdays s)
4072 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4073 upcomingp (and todayp (> diff 0)))
4074 ;; When to show a deadline in the calendar:
4075 ;; If the expiration is within wdays warning time.
4076 ;; Past-due deadlines are only shown on the current date
4077 (if (or (and (<= diff wdays)
4078 (and todayp (not org-agenda-only-exact-dates)))
4079 (= diff 0))
4080 (save-excursion
4081 (setq todo-state (org-get-todo-state))
4082 (setq donep (member todo-state org-done-keywords))
4083 (if (and donep
4084 (or org-agenda-skip-deadline-if-done
4085 (not (= diff 0))))
4086 (setq txt nil)
4087 (setq category (org-get-category))
4088 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4089 (setq txt org-agenda-no-heading-message)
4090 (goto-char (match-end 0))
4091 (setq pos1 (match-beginning 0))
4092 (setq tags (org-get-tags-at pos1))
4093 (setq head (buffer-substring-no-properties
4094 (point)
4095 (progn (skip-chars-forward "^\r\n")
4096 (point))))
4097 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4098 (setq timestr
4099 (concat (substring s (match-beginning 1)) " "))
4100 (setq timestr 'time))
4101 (setq txt (org-format-agenda-item
4102 (if (= diff 0)
4103 (car org-agenda-deadline-leaders)
4104 (if (functionp
4105 (nth 1 org-agenda-deadline-leaders))
4106 (funcall
4107 (nth 1 org-agenda-deadline-leaders)
4108 diff date)
4109 (format (nth 1 org-agenda-deadline-leaders)
4110 diff)))
4111 head category tags
4112 (if (not (= diff 0)) nil timestr)))))
4113 (when txt
4114 (setq face (org-agenda-deadline-face dfrac wdays))
4115 (org-add-props txt props
4116 'org-marker (org-agenda-new-marker pos)
4117 'org-hd-marker (org-agenda-new-marker pos1)
4118 'priority (+ (- diff)
4119 (org-get-priority txt))
4120 'org-category category
4121 'todo-state todo-state
4122 'type (if upcomingp "upcoming-deadline" "deadline")
4123 'date (if upcomingp date d2)
4124 'face (if donep 'org-agenda-done face)
4125 'undone-face face 'done-face 'org-agenda-done)
4126 (push txt ee))))))
4127 (nreverse ee)))
4129 (defun org-agenda-deadline-face (fraction &optional wdays)
4130 "Return the face to displaying a deadline item.
4131 FRACTION is what fraction of the head-warning time has passed."
4132 (if (equal wdays 0) (setq fraction 1.))
4133 (let ((faces org-agenda-deadline-faces) f)
4134 (catch 'exit
4135 (while (setq f (pop faces))
4136 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4138 (defun org-agenda-get-scheduled (&optional deadline-results)
4139 "Return the scheduled information for agenda display."
4140 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4141 'org-todo-regexp org-todo-regexp
4142 'org-complex-heading-regexp org-complex-heading-regexp
4143 'done-face 'org-agenda-done
4144 'mouse-face 'highlight
4145 'keymap org-agenda-keymap
4146 'help-echo
4147 (format "mouse-2 or RET jump to org file %s"
4148 (abbreviate-file-name buffer-file-name))))
4149 (regexp org-scheduled-time-regexp)
4150 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4151 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4153 (deadline-position-alist
4154 (mapcar (lambda (a) (and (setq mm (get-text-property
4155 0 'org-hd-marker a))
4156 (cons (marker-position mm) a)))
4157 deadline-results))
4158 d2 diff pos pos1 category tags donep
4159 ee txt head pastschedp todo-state face timestr s)
4160 (goto-char (point-min))
4161 (while (re-search-forward regexp nil t)
4162 (catch :skip
4163 (org-agenda-skip)
4164 (setq s (match-string 1)
4165 txt nil
4166 pos (1- (match-beginning 1))
4167 d2 (org-time-string-to-absolute
4168 (match-string 1) d1 'past
4169 org-agenda-repeating-timestamp-show-all)
4170 diff (- d2 d1))
4171 (setq pastschedp (and todayp (< diff 0)))
4172 ;; When to show a scheduled item in the calendar:
4173 ;; If it is on or past the date.
4174 (if (or (and (< diff 0)
4175 (< (abs diff) org-scheduled-past-days)
4176 (and todayp (not org-agenda-only-exact-dates)))
4177 (= diff 0))
4178 (save-excursion
4179 (setq todo-state (org-get-todo-state))
4180 (setq donep (member todo-state org-done-keywords))
4181 (if (and donep
4182 (or org-agenda-skip-scheduled-if-done
4183 (not (= diff 0))))
4184 (setq txt nil)
4185 (setq category (org-get-category))
4186 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4187 (setq txt org-agenda-no-heading-message)
4188 (goto-char (match-end 0))
4189 (setq pos1 (match-beginning 0))
4190 (if (and
4191 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4192 (and org-agenda-skip-scheduled-if-deadline-is-shown
4193 pastschedp))
4194 (setq mm (assoc pos1 deadline-position-alist)))
4195 (throw :skip nil))
4196 (setq tags (org-get-tags-at))
4197 (setq head (buffer-substring-no-properties
4198 (point)
4199 (progn (skip-chars-forward "^\r\n") (point))))
4200 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4201 (setq timestr
4202 (concat (substring s (match-beginning 1)) " "))
4203 (setq timestr 'time))
4204 (setq txt (org-format-agenda-item
4205 (if (= diff 0)
4206 (car org-agenda-scheduled-leaders)
4207 (format (nth 1 org-agenda-scheduled-leaders)
4208 (- 1 diff)))
4209 head category tags
4210 (if (not (= diff 0)) nil timestr)))))
4211 (when txt
4212 (setq face
4213 (cond
4214 (pastschedp 'org-scheduled-previously)
4215 (todayp 'org-scheduled-today)
4216 (t 'org-scheduled)))
4217 (org-add-props txt props
4218 'undone-face face
4219 'face (if donep 'org-agenda-done face)
4220 'org-marker (org-agenda-new-marker pos)
4221 'org-hd-marker (org-agenda-new-marker pos1)
4222 'type (if pastschedp "past-scheduled" "scheduled")
4223 'date (if pastschedp d2 date)
4224 'priority (+ 94 (- 5 diff) (org-get-priority txt))
4225 'org-category category
4226 'todo-state todo-state)
4227 (push txt ee))))))
4228 (nreverse ee)))
4230 (defun org-agenda-get-blocks ()
4231 "Return the date-range information for agenda display."
4232 (let* ((props (list 'face nil
4233 'org-not-done-regexp org-not-done-regexp
4234 'org-todo-regexp org-todo-regexp
4235 'org-complex-heading-regexp org-complex-heading-regexp
4236 'mouse-face 'highlight
4237 'keymap org-agenda-keymap
4238 'help-echo
4239 (format "mouse-2 or RET jump to org file %s"
4240 (abbreviate-file-name buffer-file-name))))
4241 (regexp org-tr-regexp)
4242 (d0 (calendar-absolute-from-gregorian date))
4243 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4244 head donep)
4245 (goto-char (point-min))
4246 (while (re-search-forward regexp nil t)
4247 (catch :skip
4248 (org-agenda-skip)
4249 (setq pos (point))
4250 (setq timestr (match-string 0)
4251 s1 (match-string 1)
4252 s2 (match-string 2)
4253 d1 (time-to-days (org-time-string-to-time s1))
4254 d2 (time-to-days (org-time-string-to-time s2)))
4255 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4256 ;; Only allow days between the limits, because the normal
4257 ;; date stamps will catch the limits.
4258 (save-excursion
4259 (setq todo-state (org-get-todo-state))
4260 (setq donep (member todo-state org-done-keywords))
4261 (if (and donep org-agenda-skip-timestamp-if-done)
4262 (throw :skip t))
4263 (setq marker (org-agenda-new-marker (point)))
4264 (setq category (org-get-category))
4265 (if (not (re-search-backward "^\\*+ " nil t))
4266 (setq txt org-agenda-no-heading-message)
4267 (goto-char (match-beginning 0))
4268 (setq hdmarker (org-agenda-new-marker (point)))
4269 (setq tags (org-get-tags-at))
4270 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4271 (setq head (match-string 1))
4272 (setq txt (org-format-agenda-item
4273 (format
4274 (nth (if (= d1 d2) 0 1)
4275 org-agenda-timerange-leaders)
4276 (1+ (- d0 d1)) (1+ (- d2 d1)))
4277 head category tags
4278 (if (= d0 d1) timestr))))
4279 (org-add-props txt props
4280 'org-marker marker 'org-hd-marker hdmarker
4281 'type "block" 'date date
4282 'todo-state todo-state
4283 'priority (org-get-priority txt) 'org-category category)
4284 (push txt ee)))
4285 (goto-char pos)))
4286 ;; Sort the entries by expiration date.
4287 (nreverse ee)))
4289 ;;; Agenda presentation and sorting
4291 (defvar org-prefix-has-time nil
4292 "A flag, set by `org-compile-prefix-format'.
4293 The flag is set if the currently compiled format contains a `%t'.")
4294 (defvar org-prefix-has-tag nil
4295 "A flag, set by `org-compile-prefix-format'.
4296 The flag is set if the currently compiled format contains a `%T'.")
4297 (defvar org-prefix-has-effort nil
4298 "A flag, set by `org-compile-prefix-format'.
4299 The flag is set if the currently compiled format contains a `%e'.")
4301 (defun org-format-agenda-item (extra txt &optional category tags dotime
4302 noprefix remove-re)
4303 "Format TXT to be inserted into the agenda buffer.
4304 In particular, it adds the prefix and corresponding text properties. EXTRA
4305 must be a string and replaces the `%s' specifier in the prefix format.
4306 CATEGORY (string, symbol or nil) may be used to overrule the default
4307 category taken from local variable or file name. It will replace the `%c'
4308 specifier in the format. DOTIME, when non-nil, indicates that a
4309 time-of-day should be extracted from TXT for sorting of this entry, and for
4310 the `%t' specifier in the format. When DOTIME is a string, this string is
4311 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4312 only the correctly processes TXT should be returned - this is used by
4313 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4314 Any match of REMOVE-RE will be removed from TXT."
4315 (save-match-data
4316 ;; Diary entries sometimes have extra whitespace at the beginning
4317 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4318 (when org-agenda-show-inherited-tags
4319 ;; Fix the tags part in txt
4320 (setq txt (org-agenda-add-inherited-tags txt tags)))
4321 (let* ((category (or category
4322 org-category
4323 (if buffer-file-name
4324 (file-name-sans-extension
4325 (file-name-nondirectory buffer-file-name))
4326 "")))
4327 ;; time, tag, effort are needed for the eval of the prefix format
4328 (tag (if tags (nth (1- (length tags)) tags) ""))
4329 time effort neffort
4330 (ts (if dotime (concat
4331 (if (stringp dotime) dotime "")
4332 (and org-agenda-search-headline-for-time txt))))
4333 (time-of-day (and dotime (org-get-time-of-day ts)))
4334 stamp plain s0 s1 s2 t1 t2 rtn srp
4335 duration)
4336 (and (org-mode-p) buffer-file-name
4337 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4338 (when (and dotime time-of-day)
4339 ;; Extract starting and ending time and move them to prefix
4340 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4341 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4342 (setq s0 (match-string 0 ts)
4343 srp (and stamp (match-end 3))
4344 s1 (match-string (if plain 1 2) ts)
4345 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4347 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4348 ;; them, we might want to remove them there to avoid duplication.
4349 ;; The user can turn this off with a variable.
4350 (if (and org-prefix-has-time
4351 org-agenda-remove-times-when-in-prefix (or stamp plain)
4352 (string-match (concat (regexp-quote s0) " *") txt)
4353 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4354 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4355 (= (match-beginning 0) 0)
4357 (setq txt (replace-match "" nil nil txt))))
4358 ;; Normalize the time(s) to 24 hour
4359 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4360 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4361 ;; Compute the duration
4362 (when s1
4363 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4364 (string-to-number (substring s1 3)))
4365 t2 (cond
4366 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4367 (string-to-number (substring s2 3))))
4368 (org-agenda-default-appointment-duration
4369 (+ t1 org-agenda-default-appointment-duration))
4370 (t nil)))
4371 (setq duration (if t2 (- t2 t1)))))
4373 (when (and s1 (not s2) org-agenda-default-appointment-duration
4374 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4375 (let ((m (+ (string-to-number (match-string 2 s1))
4376 (* 60 (string-to-number (match-string 1 s1)))
4377 org-agenda-default-appointment-duration))
4379 (setq h (/ m 60) m (- m (* h 60)))
4380 (setq s2 (format "%02d:%02d" h m))))
4382 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4383 txt)
4384 ;; Tags are in the string
4385 (if (or (eq org-agenda-remove-tags t)
4386 (and org-agenda-remove-tags
4387 org-prefix-has-tag))
4388 (setq txt (replace-match "" t t txt))
4389 (setq txt (replace-match
4390 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4391 (match-string 2 txt))
4392 t t txt))))
4393 (when (org-mode-p)
4394 (setq effort
4395 (condition-case nil
4396 (org-get-effort
4397 (or (get-text-property 0 'org-hd-marker txt)
4398 (get-text-property 0 'org-marker txt)))
4399 (error nil)))
4400 (when effort
4401 (setq neffort (org-hh:mm-string-to-minutes effort)
4402 effort (setq effort (concat "[" effort"]" )))))
4404 (when remove-re
4405 (while (string-match remove-re txt)
4406 (setq txt (replace-match "" t t txt))))
4408 ;; Create the final string
4409 (if noprefix
4410 (setq rtn txt)
4411 ;; Prepare the variables needed in the eval of the compiled format
4412 (setq time (cond (s2 (concat s1 "-" s2))
4413 (s1 (concat s1 "......"))
4414 (t ""))
4415 extra (or extra "")
4416 category (if (symbolp category) (symbol-name category) category))
4417 ;; Evaluate the compiled format
4418 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4420 ;; And finally add the text properties
4421 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4422 (org-add-props rtn nil
4423 'org-category (downcase category)
4424 'tags (mapcar 'org-downcase-keep-props tags)
4425 'org-highest-priority org-highest-priority
4426 'org-lowest-priority org-lowest-priority
4427 'prefix-length (- (length rtn) (length txt))
4428 'time-of-day time-of-day
4429 'duration duration
4430 'effort effort
4431 'effort-minutes neffort
4432 'txt txt
4433 'time time
4434 'extra extra
4435 'dotime dotime))))
4437 (defun org-agenda-add-inherited-tags (txt tags)
4438 "Remove tags string from TXT, and add complete list of tags.
4439 The new list includes inherited tags. If any inherited tags are present,
4440 a double colon separates inherited tags from local tags."
4441 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4442 (setq txt (substring txt 0 (match-beginning 0))))
4443 (when tags
4444 (let ((have-i (get-text-property 0 'inherited (car tags)))
4446 (setq txt (concat txt " :"
4447 (mapconcat
4448 (lambda (x)
4449 (setq i (get-text-property 0 'inherited x))
4450 (if (and have-i (not i))
4451 (progn
4452 (setq have-i nil)
4453 (concat ":" x))
4455 tags ":")
4456 (if have-i "::" ":")))))
4457 txt)
4459 (defun org-downcase-keep-props (s)
4460 (let ((props (text-properties-at 0 s)))
4461 (setq s (downcase s))
4462 (add-text-properties 0 (length s) props s)
4465 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
4466 (defvar org-agenda-sorting-strategy-selected nil)
4468 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
4469 (catch 'exit
4470 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
4471 ((and todayp (member 'today (car org-agenda-time-grid))))
4472 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
4473 ((member 'weekly (car org-agenda-time-grid)))
4474 (t (throw 'exit list)))
4475 (let* ((have (delq nil (mapcar
4476 (lambda (x) (get-text-property 1 'time-of-day x))
4477 list)))
4478 (string (nth 1 org-agenda-time-grid))
4479 (gridtimes (nth 2 org-agenda-time-grid))
4480 (req (car org-agenda-time-grid))
4481 (remove (member 'remove-match req))
4482 new time)
4483 (if (and (member 'require-timed req) (not have))
4484 ;; don't show empty grid
4485 (throw 'exit list))
4486 (while (setq time (pop gridtimes))
4487 (unless (and remove (member time have))
4488 (setq time (int-to-string time))
4489 (push (org-format-agenda-item
4490 nil string "" nil
4491 (concat (substring time 0 -2) ":" (substring time -2)))
4492 new)
4493 (put-text-property
4494 1 (length (car new)) 'face 'org-time-grid (car new))))
4495 (if (member 'time-up org-agenda-sorting-strategy-selected)
4496 (append new list)
4497 (append list new)))))
4499 (defun org-compile-prefix-format (key)
4500 "Compile the prefix format into a Lisp form that can be evaluated.
4501 The resulting form is returned and stored in the variable
4502 `org-prefix-format-compiled'."
4503 (setq org-prefix-has-time nil org-prefix-has-tag nil
4504 org-prefix-has-effort nil)
4505 (let ((s (cond
4506 ((stringp org-agenda-prefix-format)
4507 org-agenda-prefix-format)
4508 ((assq key org-agenda-prefix-format)
4509 (cdr (assq key org-agenda-prefix-format)))
4510 (t " %-12:c%?-12t% s")))
4511 (start 0)
4512 varform vars var e c f opt)
4513 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4514 s start)
4515 (setq var (cdr (assoc (match-string 4 s)
4516 '(("c" . category) ("t" . time) ("s" . extra)
4517 ("T" . tag) ("e" . effort))))
4518 c (or (match-string 3 s) "")
4519 opt (match-beginning 1)
4520 start (1+ (match-beginning 0)))
4521 (if (equal var 'time) (setq org-prefix-has-time t))
4522 (if (equal var 'tag) (setq org-prefix-has-tag t))
4523 (if (equal var 'effort) (setq org-prefix-has-effort t))
4524 (setq f (concat "%" (match-string 2 s) "s"))
4525 (if opt
4526 (setq varform
4527 `(if (equal "" ,var)
4529 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
4530 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c)))))
4531 (setq s (replace-match "%s" t nil s))
4532 (push varform vars))
4533 (setq vars (nreverse vars))
4534 (setq org-prefix-format-compiled `(format ,s ,@vars))))
4536 (defun org-set-sorting-strategy (key)
4537 (if (symbolp (car org-agenda-sorting-strategy))
4538 ;; the old format
4539 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
4540 (setq org-agenda-sorting-strategy-selected
4541 (or (cdr (assq key org-agenda-sorting-strategy))
4542 (cdr (assq 'agenda org-agenda-sorting-strategy))
4543 '(time-up category-keep priority-down)))))
4545 (defun org-get-time-of-day (s &optional string mod24)
4546 "Check string S for a time of day.
4547 If found, return it as a military time number between 0 and 2400.
4548 If not found, return nil.
4549 The optional STRING argument forces conversion into a 5 character wide string
4550 HH:MM."
4551 (save-match-data
4552 (when
4553 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
4554 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
4555 (let* ((h (string-to-number (match-string 1 s)))
4556 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
4557 (ampm (if (match-end 4) (downcase (match-string 4 s))))
4558 (am-p (equal ampm "am"))
4559 (h1 (cond ((not ampm) h)
4560 ((= h 12) (if am-p 0 12))
4561 (t (+ h (if am-p 0 12)))))
4562 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
4563 (mod h1 24) h1))
4564 (t0 (+ (* 100 h2) m))
4565 (t1 (concat (if (>= h1 24) "+" " ")
4566 (if (< t0 100) "0" "")
4567 (if (< t0 10) "0" "")
4568 (int-to-string t0))))
4569 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
4571 (defun org-finalize-agenda-entries (list &optional nosort)
4572 "Sort and concatenate the agenda items."
4573 (setq list (mapcar 'org-agenda-highlight-todo list))
4574 (if nosort
4575 list
4576 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
4578 (defun org-agenda-highlight-todo (x)
4579 (let ((org-done-keywords org-done-keywords-for-agenda)
4580 re pl)
4581 (if (eq x 'line)
4582 (save-excursion
4583 (beginning-of-line 1)
4584 (setq re (get-text-property (point) 'org-todo-regexp))
4585 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length) 0)))
4586 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
4587 (add-text-properties (match-beginning 0) (match-end 1)
4588 (list 'face (org-get-todo-face 1)))
4589 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4590 (delete-region (match-beginning 1) (1- (match-end 0)))
4591 (goto-char (match-beginning 1))
4592 (insert (format org-agenda-todo-keyword-format s)))))
4593 (setq re (concat (get-text-property 0 'org-todo-regexp x))
4594 pl (get-text-property 0 'prefix-length x))
4595 (when (and re
4596 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
4597 x (or pl 0)) pl))
4598 (add-text-properties
4599 (or (match-end 1) (match-end 0)) (match-end 0)
4600 (list 'face (org-get-todo-face (match-string 2 x)))
4602 (setq x (concat (substring x 0 (match-end 1))
4603 (format org-agenda-todo-keyword-format
4604 (match-string 2 x))
4606 (substring x (match-end 3)))))
4607 x)))
4609 (defsubst org-cmp-priority (a b)
4610 "Compare the priorities of string A and B."
4611 (let ((pa (or (get-text-property 1 'priority a) 0))
4612 (pb (or (get-text-property 1 'priority b) 0)))
4613 (cond ((> pa pb) +1)
4614 ((< pa pb) -1)
4615 (t nil))))
4617 (defsubst org-cmp-effort (a b)
4618 "Compare the priorities of string A and B."
4619 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
4620 (ea (or (get-text-property 1 'effort-minutes a) def))
4621 (eb (or (get-text-property 1 'effort-minutes b) def)))
4622 (cond ((> ea eb) +1)
4623 ((< ea eb) -1)
4624 (t nil))))
4626 (defsubst org-cmp-category (a b)
4627 "Compare the string values of categories of strings A and B."
4628 (let ((ca (or (get-text-property 1 'org-category a) ""))
4629 (cb (or (get-text-property 1 'org-category b) "")))
4630 (cond ((string-lessp ca cb) -1)
4631 ((string-lessp cb ca) +1)
4632 (t nil))))
4634 (defsubst org-cmp-todo-state (a b)
4635 "Compare the todo states of strings A and B."
4636 (let* ((ma (or (get-text-property 1 'org-marker a)
4637 (get-text-property 1 'org-hd-marker a)))
4638 (mb (or (get-text-property 1 'org-marker b)
4639 (get-text-property 1 'org-hd-marker b)))
4640 (fa (and ma (marker-buffer ma)))
4641 (fb (and mb (marker-buffer mb)))
4642 (todo-kwds
4643 (or (and fa (with-current-buffer fa org-todo-keywords-1))
4644 (and fb (with-current-buffer fb org-todo-keywords-1))))
4645 (ta (or (get-text-property 1 'todo-state a) ""))
4646 (tb (or (get-text-property 1 'todo-state b) ""))
4647 (la (- (length (member ta todo-kwds))))
4648 (lb (- (length (member tb todo-kwds))))
4649 (donepa (member ta org-done-keywords-for-agenda))
4650 (donepb (member tb org-done-keywords-for-agenda)))
4651 (cond ((and donepa (not donepb)) -1)
4652 ((and (not donepa) donepb) +1)
4653 ((< la lb) -1)
4654 ((< lb la) +1)
4655 (t nil))))
4657 (defsubst org-cmp-tag (a b)
4658 "Compare the string values of the first tags of A and B."
4659 (let ((ta (car (last (get-text-property 1 'tags a))))
4660 (tb (car (last (get-text-property 1 'tags b)))))
4661 (cond ((not ta) +1)
4662 ((not tb) -1)
4663 ((string-lessp ta tb) -1)
4664 ((string-lessp tb ta) +1)
4665 (t nil))))
4667 (defsubst org-cmp-time (a b)
4668 "Compare the time-of-day values of strings A and B."
4669 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
4670 (ta (or (get-text-property 1 'time-of-day a) def))
4671 (tb (or (get-text-property 1 'time-of-day b) def)))
4672 (cond ((< ta tb) -1)
4673 ((< tb ta) +1)
4674 (t nil))))
4676 (defun org-entries-lessp (a b)
4677 "Predicate for sorting agenda entries."
4678 ;; The following variables will be used when the form is evaluated.
4679 ;; So even though the compiler complains, keep them.
4680 (let* ((time-up (org-cmp-time a b))
4681 (time-down (if time-up (- time-up) nil))
4682 (priority-up (org-cmp-priority a b))
4683 (priority-down (if priority-up (- priority-up) nil))
4684 (effort-up (org-cmp-effort a b))
4685 (effort-down (if effort-up (- effort-up) nil))
4686 (category-up (org-cmp-category a b))
4687 (category-down (if category-up (- category-up) nil))
4688 (category-keep (if category-up +1 nil))
4689 (tag-up (org-cmp-tag a b))
4690 (tag-down (if tag-up (- tag-up) nil))
4691 (todo-state-up (org-cmp-todo-state a b))
4692 (todo-state-down (if todo-state-up (- todo-state-up) nil))
4693 user-defined-up user-defined-down)
4694 (if (and org-agenda-cmp-user-defined
4695 (functionp org-agenda-cmp-user-defined))
4696 (setq user-defined-up
4697 (funcall org-agenda-cmp-user-defined a b)
4698 user-defined-down (if user-defined-up (- user-defined-up) nil)))
4699 (cdr (assoc
4700 (eval (cons 'or org-agenda-sorting-strategy-selected))
4701 '((-1 . t) (1 . nil) (nil . nil))))))
4703 ;;; Agenda restriction lock
4705 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
4706 "Overlay to mark the headline to which arenda commands are restricted.")
4707 (org-overlay-put org-agenda-restriction-lock-overlay
4708 'face 'org-agenda-restriction-lock)
4709 (org-overlay-put org-agenda-restriction-lock-overlay
4710 'help-echo "Agendas are currently limited to this subtree.")
4711 (org-detach-overlay org-agenda-restriction-lock-overlay)
4713 (defun org-agenda-set-restriction-lock (&optional type)
4714 "Set restriction lock for agenda, to current subtree or file.
4715 Restriction will be the file if TYPE is `file', or if type is the
4716 universal prefix '(4), or if the cursor is before the first headline
4717 in the file. Otherwise, restriction will be to the current subtree."
4718 (interactive "P")
4719 (and (equal type '(4)) (setq type 'file))
4720 (setq type (cond
4721 (type type)
4722 ((org-at-heading-p) 'subtree)
4723 ((condition-case nil (org-back-to-heading t) (error nil))
4724 'subtree)
4725 (t 'file)))
4726 (if (eq type 'subtree)
4727 (progn
4728 (setq org-agenda-restrict t)
4729 (setq org-agenda-overriding-restriction 'subtree)
4730 (put 'org-agenda-files 'org-restrict
4731 (list (buffer-file-name (buffer-base-buffer))))
4732 (org-back-to-heading t)
4733 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
4734 (move-marker org-agenda-restrict-begin (point))
4735 (move-marker org-agenda-restrict-end
4736 (save-excursion (org-end-of-subtree t)))
4737 (message "Locking agenda restriction to subtree"))
4738 (put 'org-agenda-files 'org-restrict
4739 (list (buffer-file-name (buffer-base-buffer))))
4740 (setq org-agenda-restrict nil)
4741 (setq org-agenda-overriding-restriction 'file)
4742 (move-marker org-agenda-restrict-begin nil)
4743 (move-marker org-agenda-restrict-end nil)
4744 (message "Locking agenda restriction to file"))
4745 (setq current-prefix-arg nil)
4746 (org-agenda-maybe-redo))
4748 (defun org-agenda-remove-restriction-lock (&optional noupdate)
4749 "Remove the agenda restriction lock."
4750 (interactive "P")
4751 (org-detach-overlay org-agenda-restriction-lock-overlay)
4752 (org-detach-overlay org-speedbar-restriction-lock-overlay)
4753 (setq org-agenda-overriding-restriction nil)
4754 (setq org-agenda-restrict nil)
4755 (put 'org-agenda-files 'org-restrict nil)
4756 (move-marker org-agenda-restrict-begin nil)
4757 (move-marker org-agenda-restrict-end nil)
4758 (setq current-prefix-arg nil)
4759 (message "Agenda restriction lock removed")
4760 (or noupdate (org-agenda-maybe-redo)))
4762 (defun org-agenda-maybe-redo ()
4763 "If there is any window showing the agenda view, update it."
4764 (let ((w (get-buffer-window org-agenda-buffer-name t))
4765 (w0 (selected-window)))
4766 (when w
4767 (select-window w)
4768 (org-agenda-redo)
4769 (select-window w0)
4770 (if org-agenda-overriding-restriction
4771 (message "Agenda view shifted to new %s restriction"
4772 org-agenda-overriding-restriction)
4773 (message "Agenda restriction lock removed")))))
4775 ;;; Agenda commands
4777 (defun org-agenda-check-type (error &rest types)
4778 "Check if agenda buffer is of allowed type.
4779 If ERROR is non-nil, throw an error, otherwise just return nil."
4780 (if (memq org-agenda-type types)
4782 (if error
4783 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
4784 nil)))
4786 (defun org-agenda-quit ()
4787 "Exit agenda by removing the window or the buffer."
4788 (interactive)
4789 (if org-agenda-columns-active
4790 (org-columns-quit)
4791 (let ((buf (current-buffer)))
4792 (and (not (eq org-agenda-window-setup 'current-window))
4793 (not (one-window-p))
4794 (delete-window))
4795 (kill-buffer buf)
4796 (org-agenda-reset-markers)
4797 (org-columns-remove-overlays)
4798 (setq org-agenda-archives-mode nil))
4799 ;; Maybe restore the pre-agenda window configuration.
4800 (and org-agenda-restore-windows-after-quit
4801 (not (eq org-agenda-window-setup 'other-frame))
4802 org-pre-agenda-window-conf
4803 (set-window-configuration org-pre-agenda-window-conf))))
4805 (defun org-agenda-exit ()
4806 "Exit agenda by removing the window or the buffer.
4807 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
4808 Org-mode buffers visited directly by the user will not be touched."
4809 (interactive)
4810 (org-release-buffers org-agenda-new-buffers)
4811 (setq org-agenda-new-buffers nil)
4812 (org-agenda-quit))
4814 (defun org-agenda-execute (arg)
4815 "Execute another agenda command, keeping same window.\\<global-map>
4816 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
4817 (interactive "P")
4818 (let ((org-agenda-window-setup 'current-window))
4819 (org-agenda arg)))
4821 (defun org-agenda-redo ()
4822 "Rebuild Agenda.
4823 When this is the global TODO list, a prefix argument will be interpreted."
4824 (interactive)
4825 (let* ((org-agenda-keep-modes t)
4826 (filter org-agenda-filter)
4827 (preset (get 'org-agenda-filter :preset-filter))
4828 (cols org-agenda-columns-active)
4829 (line (org-current-line))
4830 (window-line (- line (org-current-line (window-start))))
4831 (lprops (get 'org-agenda-redo-command 'org-lprops)))
4832 (put 'org-agenda-filter :preset-filter nil)
4833 (and cols (org-columns-quit))
4834 (message "Rebuilding agenda buffer...")
4835 (org-let lprops '(eval org-agenda-redo-command))
4836 (setq org-agenda-undo-list nil
4837 org-agenda-pending-undo-list nil)
4838 (message "Rebuilding agenda buffer...done")
4839 (put 'org-agenda-filter :preset-filter preset)
4840 (and (or filter preset) (org-agenda-filter-apply filter))
4841 (and cols (interactive-p) (org-agenda-columns))
4842 (org-goto-line line)
4843 (recenter window-line)))
4846 (defvar org-global-tags-completion-table nil)
4847 (defvar org-agenda-filter-form nil)
4848 (defun org-agenda-filter-by-tag (strip &optional char narrow)
4849 "Keep only those lines in the agenda buffer that have a specific tag.
4850 The tag is selected with its fast selection letter, as configured.
4851 With prefix argument STRIP, remove all lines that do have the tag.
4852 A lisp caller can specify CHAR. NARROW means that the new tag should be
4853 used to narrow the search - the interactive user can also press `-' or `+'
4854 to switch to narrowing."
4855 (interactive "P")
4856 (let* ((alist org-tag-alist-for-agenda)
4857 (tag-chars (mapconcat
4858 (lambda (x) (if (cdr x) (char-to-string (cdr x)) ""))
4859 alist ""))
4860 (efforts (org-split-string
4861 (or (cdr (assoc (concat org-effort-property "_ALL")
4862 org-global-properties))
4863 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
4864 (effort-op org-agenda-filter-effort-default-operator)
4865 (effort-prompt "")
4866 (inhibit-read-only t)
4867 (current org-agenda-filter)
4868 char a n tag)
4869 (unless char
4870 (message
4871 "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
4872 (if narrow "Narrow" "Filter") tag-chars)
4873 (setq char (read-char)))
4874 (when (member char '(?+ ?-))
4875 ;; Narrowing down
4876 (cond ((equal char ?-) (setq strip t narrow t))
4877 ((equal char ?+) (setq strip nil narrow t)))
4878 (message
4879 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
4880 (setq char (read-char)))
4881 (when (member char '(?< ?> ?= ??))
4882 ;; An effort operator
4883 (setq effort-op (char-to-string char))
4884 (setq alist nil) ; to make sure it will be interpreted as effort.
4885 (unless (equal char ??)
4886 (loop for i from 0 to 9 do
4887 (setq effort-prompt
4888 (concat
4889 effort-prompt " ["
4890 (if (= i 9) "0" (int-to-string (1+ i)))
4891 "]" (nth i efforts))))
4892 (message "Effort%s: %s " effort-op effort-prompt)
4893 (setq char (read-char))
4894 (when (or (< char ?0) (> char ?9))
4895 (error "Need 1-9,0 to select effort" ))))
4896 (when (equal char ?\t)
4897 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
4898 (org-set-local 'org-global-tags-completion-table
4899 (org-global-tags-completion-table)))
4900 (let ((completion-ignore-case t))
4901 (setq tag (org-icompleting-read
4902 "Tag: " org-global-tags-completion-table))))
4903 (cond
4904 ((equal char ?/)
4905 (org-agenda-filter-by-tag-show-all)
4906 (when (get 'org-agenda-filter :preset-filter)
4907 (org-agenda-filter-apply org-agenda-filter)))
4908 ((or (equal char ?\ )
4909 (setq a (rassoc char alist))
4910 (and (>= char ?0) (<= char ?9)
4911 (setq n (if (= char ?0) 9 (- char ?0 1))
4912 tag (concat effort-op (nth n efforts))
4913 a (cons tag nil)))
4914 (and (= char ??)
4915 (setq tag "?eff")
4916 a (cons tag nil))
4917 (and tag (setq a (cons tag nil))))
4918 (org-agenda-filter-by-tag-show-all)
4919 (setq tag (car a))
4920 (setq org-agenda-filter
4921 (cons (concat (if strip "-" "+") tag)
4922 (if narrow current nil)))
4923 (org-agenda-filter-apply org-agenda-filter))
4924 (t (error "Invalid tag selection character %c" char)))))
4926 (defun org-agenda-filter-by-tag-refine (strip &optional char)
4927 "Refine the current filter. See `org-agenda-filter-by-tag."
4928 (interactive "P")
4929 (org-agenda-filter-by-tag strip char 'refine))
4931 (defun org-agenda-filter-make-matcher ()
4932 "Create the form that tests a line for the agenda filter."
4933 (let (f f1)
4934 (dolist (x (append (get 'org-agenda-filter :preset-filter)
4935 org-agenda-filter))
4936 (if (member x '("-" "+"))
4937 (setq f1 '(not tags))
4938 (if (string-match "[<=>?]" x)
4939 (setq f1 (org-agenda-filter-effort-form x))
4940 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
4941 (if (equal (string-to-char x) ?-)
4942 (setq f1 (list 'not f1))))
4943 (push f1 f))
4944 (cons 'and (nreverse f))))
4946 (defun org-agenda-filter-effort-form (e)
4947 "Return the form to compare the effort of the current line with what E says.
4948 E looks line \"+<2:25\"."
4949 (let (op)
4950 (setq e (substring e 1))
4951 (setq op (string-to-char e) e (substring e 1))
4952 (setq op (cond ((equal op ?<) '<=)
4953 ((equal op ?>) '>=)
4954 ((equal op ??) op)
4955 (t '=)))
4956 (list 'org-agenda-compare-effort (list 'quote op)
4957 (org-hh:mm-string-to-minutes e))))
4959 (defun org-agenda-compare-effort (op value)
4960 "Compare the effort of the current line with VALUE, using OP.
4961 If the line does not have an effort defined, return nil."
4962 (let ((eff (get-text-property (point) 'effort-minutes)))
4963 (if (equal op ??)
4964 (not eff)
4965 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
4966 value))))
4968 (defun org-agenda-filter-apply (filter)
4969 "Set FILTER as the new agenda filter and apply it."
4970 (let (tags)
4971 (setq org-agenda-filter filter
4972 org-agenda-filter-form (org-agenda-filter-make-matcher))
4973 (org-agenda-set-mode-name)
4974 (save-excursion
4975 (goto-char (point-min))
4976 (while (not (eobp))
4977 (if (get-text-property (point) 'org-marker)
4978 (progn
4979 (setq tags (get-text-property (point) 'tags)) ; used in eval
4980 (if (not (eval org-agenda-filter-form))
4981 (org-agenda-filter-by-tag-hide-line))
4982 (beginning-of-line 2))
4983 (beginning-of-line 2))))))
4985 (defun org-agenda-filter-by-tag-hide-line ()
4986 (let (ov)
4987 (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
4988 (point-at-eol)))
4989 (org-overlay-put ov 'invisible t)
4990 (org-overlay-put ov 'type 'tags-filter)
4991 (push ov org-agenda-filter-overlays)))
4993 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
4994 (setq pos (or pos (point)))
4995 (save-excursion
4996 (dolist (ov (org-overlays-at pos))
4997 (when (and (org-overlay-get ov 'invisible)
4998 (eq (org-overlay-get ov 'type) 'tags-filter))
4999 (goto-char pos)
5000 (if (< (org-overlay-start ov) (point-at-eol))
5001 (org-move-overlay ov (point-at-eol)
5002 (org-overlay-end ov)))))))
5004 (defun org-agenda-filter-by-tag-show-all ()
5005 (mapc 'org-delete-overlay org-agenda-filter-overlays)
5006 (setq org-agenda-filter-overlays nil)
5007 (setq org-agenda-filter nil)
5008 (setq org-agenda-filter-form nil)
5009 (org-agenda-set-mode-name))
5011 (defun org-agenda-manipulate-query-add ()
5012 "Manipulate the query by adding a search term with positive selection.
5013 Positive selection means, the term must be matched for selection of an entry."
5014 (interactive)
5015 (org-agenda-manipulate-query ?\[))
5016 (defun org-agenda-manipulate-query-subtract ()
5017 "Manipulate the query by adding a search term with negative selection.
5018 Negative selection means, term must not be matched for selection of an entry."
5019 (interactive)
5020 (org-agenda-manipulate-query ?\]))
5021 (defun org-agenda-manipulate-query-add-re ()
5022 "Manipulate the query by adding a search regexp with positive selection.
5023 Positive selection means, the regexp must match for selection of an entry."
5024 (interactive)
5025 (org-agenda-manipulate-query ?\{))
5026 (defun org-agenda-manipulate-query-subtract-re ()
5027 "Manipulate the query by adding a search regexp with negative selection.
5028 Negative selection means, regexp must not match for selection of an entry."
5029 (interactive)
5030 (org-agenda-manipulate-query ?\}))
5031 (defun org-agenda-manipulate-query (char)
5032 (cond
5033 ((memq org-agenda-type '(timeline agenda))
5034 (let ((org-agenda-include-inactive-timestamps t))
5035 (org-agenda-redo))
5036 (message "Display now includes inactive timestamps as well"))
5037 ((eq org-agenda-type 'search)
5038 (org-add-to-string
5039 'org-agenda-query-string
5040 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5041 (?\{ . " +{}") (?\} . " -{}")))))
5042 (setq org-agenda-redo-command
5043 (list 'org-search-view
5044 org-todo-only
5045 org-agenda-query-string
5046 (+ (length org-agenda-query-string)
5047 (if (member char '(?\{ ?\})) 0 1))))
5048 (set-register org-agenda-query-register org-agenda-query-string)
5049 (org-agenda-redo))
5050 (t (error "Cannot manipulate query for %s-type agenda buffers"
5051 org-agenda-type))))
5053 (defun org-add-to-string (var string)
5054 (set var (concat (symbol-value var) string)))
5056 (defun org-agenda-goto-date (date)
5057 "Jump to DATE in agenda."
5058 (interactive (list (org-read-date)))
5059 (org-agenda-list nil date))
5061 (defun org-agenda-goto-today ()
5062 "Go to today."
5063 (interactive)
5064 (org-agenda-check-type t 'timeline 'agenda)
5065 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5066 (cond
5067 (tdpos (goto-char tdpos))
5068 ((eq org-agenda-type 'agenda)
5069 (let* ((sd (time-to-days
5070 (time-subtract (current-time)
5071 (list 0 (* 3600 org-extend-today-until) 0))))
5072 (comp (org-agenda-compute-time-span sd org-agenda-span))
5073 (org-agenda-overriding-arguments org-agenda-last-arguments))
5074 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5075 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5076 (org-agenda-redo)
5077 (org-agenda-find-same-or-today-or-agenda)))
5078 (t (error "Cannot find today")))))
5080 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5081 (goto-char
5082 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5083 (text-property-any (point-min) (point-max) 'org-today t)
5084 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5085 (point-min))))
5087 (defun org-agenda-later (arg)
5088 "Go forward in time by thee current span.
5089 With prefix ARG, go forward that many times the current span."
5090 (interactive "p")
5091 (org-agenda-check-type t 'agenda)
5092 (let* ((span org-agenda-span)
5093 (sd org-starting-day)
5094 (greg (calendar-gregorian-from-absolute sd))
5095 (cnt (get-text-property (point) 'org-day-cnt))
5096 greg2 nd)
5097 (cond
5098 ((eq span 'day)
5099 (setq sd (+ arg sd) nd 1))
5100 ((eq span 'week)
5101 (setq sd (+ (* 7 arg) sd) nd 7))
5102 ((eq span 'month)
5103 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5104 sd (calendar-absolute-from-gregorian greg2))
5105 (setcar greg2 (1+ (car greg2)))
5106 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5107 ((eq span 'year)
5108 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5109 sd (calendar-absolute-from-gregorian greg2))
5110 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5111 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5112 (let ((org-agenda-overriding-arguments
5113 (list (car org-agenda-last-arguments) sd nd t)))
5114 (org-agenda-redo)
5115 (org-agenda-find-same-or-today-or-agenda cnt))))
5117 (defun org-agenda-earlier (arg)
5118 "Go backward in time by the current span.
5119 With prefix ARG, go backward that many times the current span."
5120 (interactive "p")
5121 (org-agenda-later (- arg)))
5123 (defun org-agenda-view-mode-dispatch ()
5124 "Call one of the view mode commands."
5125 (interactive)
5126 (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
5127 clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
5128 (let ((a (read-char-exclusive)))
5129 (case a
5130 (?d (call-interactively 'org-agenda-day-view))
5131 (?w (call-interactively 'org-agenda-week-view))
5132 (?m (call-interactively 'org-agenda-month-view))
5133 (?y (call-interactively 'org-agenda-year-view))
5134 (?l (call-interactively 'org-agenda-log-mode))
5135 (?f (call-interactively 'org-agenda-follow-mode))
5136 (?a (call-interactively 'org-agenda-archives-mode))
5137 (?A (org-agenda-archives-mode 'files))
5138 (?R (call-interactively 'org-agenda-clockreport-mode))
5139 (?E (call-interactively 'org-agenda-entry-text-mode))
5140 (?G (call-interactively 'org-agenda-toggle-time-grid))
5141 (?D (call-interactively 'org-agenda-toggle-diary))
5142 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5143 (org-agenda-check-type t 'timeline 'agenda)
5144 (org-agenda-redo))
5145 (message "Display now includes inactive timestamps as well"))
5146 (?q (message "Abort"))
5147 (otherwise (error "Invalid key" )))))
5149 (defun org-agenda-day-view (&optional day-of-year)
5150 "Switch to daily view for agenda.
5151 With argument DAY-OF-YEAR, switch to that day of the year."
5152 (interactive "P")
5153 (setq org-agenda-ndays 1)
5154 (org-agenda-change-time-span 'day day-of-year))
5155 (defun org-agenda-week-view (&optional iso-week)
5156 "Switch to daily view for agenda.
5157 With argument ISO-WEEK, switch to the corresponding ISO week.
5158 If ISO-WEEK has more then 2 digits, only the last two encode the
5159 week. Any digits before this encode a year. So 200712 means
5160 week 12 of year 2007. Years in the range 1938-2037 can also be
5161 written as 2-digit years."
5162 (interactive "P")
5163 (setq org-agenda-ndays 7)
5164 (org-agenda-change-time-span 'week iso-week))
5165 (defun org-agenda-month-view (&optional month)
5166 "Switch to monthly view for agenda.
5167 With argument MONTH, switch to that month."
5168 (interactive "P")
5169 (org-agenda-change-time-span 'month month))
5170 (defun org-agenda-year-view (&optional year)
5171 "Switch to yearly view for agenda.
5172 With argument YEAR, switch to that year.
5173 If MONTH has more then 2 digits, only the last two encode the
5174 month. Any digits before this encode a year. So 200712 means
5175 December year 2007. Years in the range 1938-2037 can also be
5176 written as 2-digit years."
5177 (interactive "P")
5178 (when year
5179 (setq year (org-small-year-to-year year)))
5180 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5181 (org-agenda-change-time-span 'year year)
5182 (error "Abort")))
5184 (defun org-agenda-change-time-span (span &optional n)
5185 "Change the agenda view to SPAN.
5186 SPAN may be `day', `week', `month', `year'."
5187 (org-agenda-check-type t 'agenda)
5188 (if (and (not n) (equal org-agenda-span span))
5189 (error "Viewing span is already \"%s\"" span))
5190 (let* ((sd (or (get-text-property (point) 'day)
5191 org-starting-day))
5192 (computed (org-agenda-compute-time-span sd span n))
5193 (org-agenda-overriding-arguments
5194 (list (car org-agenda-last-arguments)
5195 (car computed) (cdr computed) t)))
5196 (org-agenda-redo)
5197 (org-agenda-find-same-or-today-or-agenda))
5198 (org-agenda-set-mode-name)
5199 (message "Switched to %s view" span))
5201 (defun org-agenda-compute-time-span (sd span &optional n)
5202 "Compute starting date and number of days for agenda.
5203 SPAN may be `day', `week', `month', `year'. The return value
5204 is a cons cell with the starting date and the number of days,
5205 so that the date SD will be in that range."
5206 (let* ((greg (calendar-gregorian-from-absolute sd))
5207 (dg (nth 1 greg))
5208 (mg (car greg))
5209 (yg (nth 2 greg))
5210 nd w1 y1 m1 thisweek)
5211 (cond
5212 ((eq span 'day)
5213 (when n
5214 (setq sd (+ (calendar-absolute-from-gregorian
5215 (list mg 1 yg))
5216 n -1)))
5217 (setq nd 1))
5218 ((eq span 'week)
5219 (let* ((nt (calendar-day-of-week
5220 (calendar-gregorian-from-absolute sd)))
5221 (d (if org-agenda-start-on-weekday
5222 (- nt org-agenda-start-on-weekday)
5223 0)))
5224 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5225 (when n
5226 (require 'cal-iso)
5227 (setq thisweek (car (calendar-iso-from-absolute sd)))
5228 (when (> n 99)
5229 (setq y1 (org-small-year-to-year (/ n 100))
5230 n (mod n 100)))
5231 (setq sd
5232 (calendar-absolute-from-iso
5233 (list n 1
5234 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5235 (setq nd 7)))
5236 ((eq span 'month)
5237 (when (and n (> n 99))
5238 (setq y1 (org-small-year-to-year (/ n 100))
5239 n (mod n 100)))
5240 (setq sd (calendar-absolute-from-gregorian
5241 (list (or n mg) 1 (or y1 yg)))
5242 nd (- (calendar-absolute-from-gregorian
5243 (list (1+ (or n mg)) 1 (or y1 yg)))
5244 sd)))
5245 ((eq span 'year)
5246 (setq sd (calendar-absolute-from-gregorian
5247 (list 1 1 (or n yg)))
5248 nd (- (calendar-absolute-from-gregorian
5249 (list 1 1 (1+ (or n yg))))
5250 sd))))
5251 (cons sd nd)))
5253 (defun org-agenda-next-date-line (&optional arg)
5254 "Jump to the next line indicating a date in agenda buffer."
5255 (interactive "p")
5256 (org-agenda-check-type t 'agenda 'timeline)
5257 (beginning-of-line 1)
5258 ;; This does not work if user makes date format that starts with a blank
5259 (if (looking-at "^\\S-") (forward-char 1))
5260 (if (not (re-search-forward "^\\S-" nil t arg))
5261 (progn
5262 (backward-char 1)
5263 (error "No next date after this line in this buffer")))
5264 (goto-char (match-beginning 0)))
5266 (defun org-agenda-previous-date-line (&optional arg)
5267 "Jump to the previous line indicating a date in agenda buffer."
5268 (interactive "p")
5269 (org-agenda-check-type t 'agenda 'timeline)
5270 (beginning-of-line 1)
5271 (if (not (re-search-backward "^\\S-" nil t arg))
5272 (error "No previous date before this line in this buffer")))
5274 ;; Initialize the highlight
5275 (defvar org-hl (org-make-overlay 1 1))
5276 (org-overlay-put org-hl 'face 'highlight)
5278 (defun org-highlight (begin end &optional buffer)
5279 "Highlight a region with overlay."
5280 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5281 org-hl begin end (or buffer (current-buffer))))
5283 (defun org-unhighlight ()
5284 "Detach overlay INDEX."
5285 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5287 ;; FIXME this is currently not used.
5288 (defun org-highlight-until-next-command (beg end &optional buffer)
5289 "Move the highlight overlay to BEG/END, remove it before the next command."
5290 (org-highlight beg end buffer)
5291 (add-hook 'pre-command-hook 'org-unhighlight-once))
5292 (defun org-unhighlight-once ()
5293 "Remove the highlight from its position, and this function from the hook."
5294 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5295 (org-unhighlight))
5297 (defun org-agenda-follow-mode ()
5298 "Toggle follow mode in an agenda buffer."
5299 (interactive)
5300 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5301 (org-agenda-set-mode-name)
5302 (message "Follow mode is %s"
5303 (if org-agenda-follow-mode "on" "off")))
5305 (defun org-agenda-entry-text-mode (&optional arg)
5306 "Toggle entry text mode in an agenda buffer."
5307 (interactive "P")
5308 (if (integerp arg)
5309 (setq org-agenda-entry-text-mode t)
5310 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5311 (org-agenda-entry-text-hide)
5312 (and org-agenda-entry-text-mode
5313 (let ((org-agenda-entry-text-maxlines
5314 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5315 (org-agenda-entry-text-show)))
5316 (org-agenda-set-mode-name)
5317 (message "Entry text mode is %s. Maximum number of lines is %d"
5318 (if org-agenda-entry-text-mode "on" "off")
5319 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5321 (defun org-agenda-clockreport-mode ()
5322 "Toggle clocktable mode in an agenda buffer."
5323 (interactive)
5324 (org-agenda-check-type t 'agenda)
5325 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5326 (org-agenda-set-mode-name)
5327 (org-agenda-redo)
5328 (message "Clocktable mode is %s"
5329 (if org-agenda-clockreport-mode "on" "off")))
5331 (defun org-agenda-log-mode (&optional special)
5332 "Toggle log mode in an agenda buffer.
5333 With argument SPECIAL, show all possible log items, not only the ones
5334 configured in `org-agenda-log-mode-items'.
5335 With a double `C-u' prefix arg, show *only* log items, nothing else."
5336 (interactive "P")
5337 (org-agenda-check-type t 'agenda 'timeline)
5338 (setq org-agenda-show-log
5339 (if (equal special '(16))
5340 'only
5341 (if special '(closed clock state)
5342 (not org-agenda-show-log))))
5343 (org-agenda-set-mode-name)
5344 (org-agenda-redo)
5345 (message "Log mode is %s"
5346 (if org-agenda-show-log "on" "off")))
5348 (defun org-agenda-archives-mode (&optional with-files)
5349 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5350 When called with a prefix argument, include all archive files as well."
5351 (interactive "P")
5352 (setq org-agenda-archives-mode
5353 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5354 (org-agenda-set-mode-name)
5355 (org-agenda-redo)
5356 (message
5357 "%s"
5358 (cond
5359 ((eq org-agenda-archives-mode nil)
5360 "No archives are included")
5361 ((eq org-agenda-archives-mode 'trees)
5362 (format "Trees with :%s: tag are included" org-archive-tag))
5363 ((eq org-agenda-archives-mode t)
5364 (format "Trees with :%s: tag and all active archive files are included"
5365 org-archive-tag)))))
5367 (defun org-agenda-toggle-diary ()
5368 "Toggle diary inclusion in an agenda buffer."
5369 (interactive)
5370 (org-agenda-check-type t 'agenda)
5371 (setq org-agenda-include-diary (not org-agenda-include-diary))
5372 (org-agenda-redo)
5373 (org-agenda-set-mode-name)
5374 (message "Diary inclusion turned %s"
5375 (if org-agenda-include-diary "on" "off")))
5377 (defun org-agenda-toggle-time-grid ()
5378 "Toggle time grid in an agenda buffer."
5379 (interactive)
5380 (org-agenda-check-type t 'agenda)
5381 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5382 (org-agenda-redo)
5383 (org-agenda-set-mode-name)
5384 (message "Time-grid turned %s"
5385 (if org-agenda-use-time-grid "on" "off")))
5387 (defun org-agenda-set-mode-name ()
5388 "Set the mode name to indicate all the small mode settings."
5389 (setq mode-name
5390 (concat "Org-Agenda"
5391 (if (equal org-agenda-ndays 1) " Day" "")
5392 (if (equal org-agenda-ndays 7) " Week" "")
5393 (if org-agenda-follow-mode " Follow" "")
5394 (if org-agenda-entry-text-mode " ETxt" "")
5395 (if org-agenda-include-diary " Diary" "")
5396 (if org-agenda-use-time-grid " Grid" "")
5397 (if (consp org-agenda-show-log) " LogAll"
5398 (if org-agenda-show-log " Log" ""))
5399 (if (or org-agenda-filter (get 'org-agenda-filter
5400 :preset-filter))
5401 (concat " {" (mapconcat
5402 'identity
5403 (append (get 'org-agenda-filter
5404 :preset-filter)
5405 org-agenda-filter) "") "}")
5407 (if org-agenda-archives-mode
5408 (if (eq org-agenda-archives-mode t)
5409 " Archives"
5410 (format " :%s:" org-archive-tag))
5412 (if org-agenda-clockreport-mode " Clock" "")))
5413 (force-mode-line-update))
5415 (defun org-agenda-post-command-hook ()
5416 (and (eolp) (not (bolp)) (backward-char 1))
5417 (setq org-agenda-type
5418 (or (get-text-property (point) 'org-agenda-type)
5419 (get-text-property (max (point-min) (1- (point)))
5420 'org-agenda-type)))
5421 (if (and org-agenda-follow-mode
5422 (get-text-property (point) 'org-marker))
5423 (org-agenda-show)))
5425 (defun org-agenda-show-priority ()
5426 "Show the priority of the current item.
5427 This priority is composed of the main priority given with the [#A] cookies,
5428 and by additional input from the age of a schedules or deadline entry."
5429 (interactive)
5430 (let* ((pri (get-text-property (point-at-bol) 'priority)))
5431 (message "Priority is %d" (if pri pri -1000))))
5433 (defun org-agenda-show-tags ()
5434 "Show the tags applicable to the current item."
5435 (interactive)
5436 (let* ((tags (get-text-property (point-at-bol) 'tags)))
5437 (if tags
5438 (message "Tags are :%s:"
5439 (org-no-properties (mapconcat 'identity tags ":")))
5440 (message "No tags associated with this line"))))
5442 (defun org-agenda-goto (&optional highlight)
5443 "Go to the Org-mode file which contains the item at point."
5444 (interactive)
5445 (let* ((marker (or (get-text-property (point) 'org-marker)
5446 (org-agenda-error)))
5447 (buffer (marker-buffer marker))
5448 (pos (marker-position marker)))
5449 (switch-to-buffer-other-window buffer)
5450 (widen)
5451 (goto-char pos)
5452 (when (org-mode-p)
5453 (org-show-context 'agenda)
5454 (save-excursion
5455 (and (outline-next-heading)
5456 (org-flag-heading nil)))) ; show the next heading
5457 (recenter (/ (window-height) 2))
5458 (run-hooks 'org-agenda-after-show-hook)
5459 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
5461 (defvar org-agenda-after-show-hook nil
5462 "Normal hook run after an item has been shown from the agenda.
5463 Point is in the buffer where the item originated.")
5465 (defun org-agenda-kill ()
5466 "Kill the entry or subtree belonging to the current agenda entry."
5467 (interactive)
5468 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5469 (let* ((marker (or (get-text-property (point) 'org-marker)
5470 (org-agenda-error)))
5471 (buffer (marker-buffer marker))
5472 (pos (marker-position marker))
5473 (type (get-text-property (point) 'type))
5474 dbeg dend (n 0) conf)
5475 (org-with-remote-undo buffer
5476 (with-current-buffer buffer
5477 (save-excursion
5478 (goto-char pos)
5479 (if (and (org-mode-p) (not (member type '("sexp"))))
5480 (setq dbeg (progn (org-back-to-heading t) (point))
5481 dend (org-end-of-subtree t t))
5482 (setq dbeg (point-at-bol)
5483 dend (min (point-max) (1+ (point-at-eol)))))
5484 (goto-char dbeg)
5485 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
5486 (setq conf (or (eq t org-agenda-confirm-kill)
5487 (and (numberp org-agenda-confirm-kill)
5488 (> n org-agenda-confirm-kill))))
5489 (and conf
5490 (not (y-or-n-p
5491 (format "Delete entry with %d lines in buffer \"%s\"? "
5492 n (buffer-name buffer))))
5493 (error "Abort"))
5494 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
5495 (with-current-buffer buffer (delete-region dbeg dend))
5496 (message "Agenda item and source killed"))))
5498 (defun org-agenda-archive ()
5499 "Archive the entry or subtree belonging to the current agenda entry."
5500 (interactive)
5501 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5502 (let* ((marker (or (get-text-property (point) 'org-marker)
5503 (org-agenda-error)))
5504 (buffer (marker-buffer marker))
5505 (pos (marker-position marker)))
5506 (org-with-remote-undo buffer
5507 (with-current-buffer buffer
5508 (if (org-mode-p)
5509 (save-excursion
5510 (goto-char pos)
5511 (org-remove-subtree-entries-from-agenda)
5512 (org-back-to-heading t)
5513 (org-archive-subtree))
5514 (error "Archiving works only in Org-mode files"))))))
5516 (defun org-agenda-archive-to-archive-sibling ()
5517 "Move the entry to the archive sibling."
5518 (interactive)
5519 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5520 (let* ((marker (or (get-text-property (point) 'org-marker)
5521 (org-agenda-error)))
5522 (buffer (marker-buffer marker))
5523 (pos (marker-position marker)))
5524 (org-with-remote-undo buffer
5525 (with-current-buffer buffer
5526 (if (org-mode-p)
5527 (save-excursion
5528 (goto-char pos)
5529 (org-remove-subtree-entries-from-agenda)
5530 (org-back-to-heading t)
5531 (org-archive-to-archive-sibling))
5532 (error "Archiving works only in Org-mode files"))))))
5534 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
5535 "Remove all lines in the agenda that correspond to a given subtree.
5536 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5537 If this information is not given, the function uses the tree at point."
5538 (let ((buf (or buf (current-buffer))) m p)
5539 (save-excursion
5540 (unless (and beg end)
5541 (org-back-to-heading t)
5542 (setq beg (point))
5543 (org-end-of-subtree t)
5544 (setq end (point)))
5545 (set-buffer (get-buffer org-agenda-buffer-name))
5546 (save-excursion
5547 (goto-char (point-max))
5548 (beginning-of-line 1)
5549 (while (not (bobp))
5550 (when (and (setq m (get-text-property (point) 'org-marker))
5551 (equal buf (marker-buffer m))
5552 (setq p (marker-position m))
5553 (>= p beg)
5554 (< p end))
5555 (let ((inhibit-read-only t))
5556 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5557 (beginning-of-line 0))))))
5559 (defun org-agenda-refile (&optional goto rfloc)
5560 "Refile the item at point."
5561 (interactive "P")
5562 (if (equal goto '(16))
5563 (org-refile-goto-last-stored)
5564 (let* ((marker (or (get-text-property (point) 'org-hd-marker)
5565 (org-agenda-error)))
5566 (buffer (marker-buffer marker))
5567 (pos (marker-position marker))
5568 (rfloc (or rfloc
5569 (org-refile-get-location
5570 (if goto "Goto: " "Refile to: ") buffer
5571 org-refile-allow-creating-parent-nodes))))
5572 (with-current-buffer buffer
5573 (save-excursion
5574 (save-restriction
5575 (widen)
5576 (goto-char marker)
5577 (org-remove-subtree-entries-from-agenda)
5578 (org-refile goto buffer rfloc)))))))
5580 (defun org-agenda-open-link (&optional arg)
5581 "Follow the link in the current line, if any.
5582 This looks for a link in the displayed lin in the agenda. It also looks
5583 at the text of the entry itself."
5584 (interactive "P")
5585 (let* ((marker (or (get-text-property (point) 'org-hd-marker)
5586 (get-text-property (point) 'org-marker)))
5587 (buffer (and marker (marker-buffer marker)))
5588 (txt (concat (buffer-substring (point-at-bol) (point-at-eol))
5589 "\n"
5590 (and marker
5591 (org-agenda-get-some-entry-text marker 100))))
5592 (re (concat "\\(" org-bracket-link-regexp "\\)\\|"
5593 "\\(" org-angle-link-re "\\)\\|"
5594 "\\(" org-plain-link-re "\\)"))
5595 links c link (cnt 0))
5596 (with-temp-buffer
5597 (insert txt)
5598 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local)
5599 (goto-char (point-min))
5600 (while (re-search-forward re nil t)
5601 (push (match-string 0) links))
5602 (setq links (reverse links))
5603 (unless links (error "No links"))
5605 (unless (and (integerp arg) (>= (length links) arg))
5606 (save-excursion
5607 (save-window-excursion
5608 (delete-other-windows)
5609 (with-output-to-temp-buffer "*Select Link*"
5610 (princ "Select link\n\n")
5611 (mapc (lambda (l) (princ (format "[%d] %s\n" (incf cnt) l)))
5612 links))
5613 (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
5614 (message "Select link to open:")
5615 (setq c (read-char-exclusive))
5616 (and (get-buffer "*Select Link*") (kill-buffer "*Select Link*"))))
5617 (setq arg (- c ?0)))
5619 (unless (and (integerp arg) (>= (length links) arg))
5620 (error "Invalid link selection"))
5621 (setq link (nth (1- arg) links)
5622 arg nil)
5623 (with-current-buffer (or buffer (current-buffer))
5624 (org-open-link-from-string link)))))
5626 (defun org-agenda-copy-local-variable (var)
5627 "Get a variable from a referenced buffer and install it here."
5628 (let ((m (get-text-property (point) 'org-marker)))
5629 (when (and m (buffer-live-p (marker-buffer m)))
5630 (org-set-local var (with-current-buffer (marker-buffer m)
5631 (symbol-value var))))))
5633 (defun org-agenda-switch-to (&optional delete-other-windows)
5634 "Go to the Org-mode file which contains the item at point."
5635 (interactive)
5636 (let* ((marker (or (get-text-property (point) 'org-marker)
5637 (org-agenda-error)))
5638 (buffer (marker-buffer marker))
5639 (pos (marker-position marker)))
5640 (switch-to-buffer buffer)
5641 (and delete-other-windows (delete-other-windows))
5642 (widen)
5643 (goto-char pos)
5644 (when (org-mode-p)
5645 (org-show-context 'agenda)
5646 (save-excursion
5647 (and (outline-next-heading)
5648 (org-flag-heading nil)))))) ; show the next heading
5650 (defun org-agenda-goto-mouse (ev)
5651 "Go to the Org-mode file which contains the item at the mouse click."
5652 (interactive "e")
5653 (mouse-set-point ev)
5654 (org-agenda-goto))
5656 (defun org-agenda-show (&optional full-entry)
5657 "Display the Org-mode file which contains the item at point.
5658 With prefix argument FULL-ENTRY, make the entire entry visible
5659 if it was hidden in the outline."
5660 (interactive "P")
5661 (let ((win (selected-window)))
5662 (if full-entry
5663 (let ((org-show-entry-below t))
5664 (org-agenda-goto t))
5665 (org-agenda-goto t))
5666 (select-window win)))
5668 (defun org-agenda-show-1 (&optional more)
5669 "Display the Org-mode file which contains the item at point.
5670 The prefix arg causes further revieling:
5672 0 hide the subtree
5673 1 just show the entry according to defaults.
5674 2 show the text below the heading
5675 3 show the entire subtree
5676 4 show the entire subtree and any LOGBOOK drawers
5677 5 show the entire subtree and any drawers
5678 With prefix argument FULL-ENTRY, make the entire entry visible
5679 if it was hidden in the outline."
5680 (interactive "p")
5681 (let ((win (selected-window)))
5682 (org-agenda-goto t)
5683 (org-recenter-heading 1)
5684 (cond
5685 ((= more 0)
5686 (hide-subtree)
5687 (message "Remote: hide subtree"))
5688 ((and (interactive-p) (= more 1))
5689 (message "Remote: show with default settings"))
5690 ((= more 2)
5691 (show-entry)
5692 (save-excursion
5693 (org-back-to-heading)
5694 (org-cycle-hide-drawers 'children))
5695 (message "Remote: show entry"))
5696 ((= more 3)
5697 (show-subtree)
5698 (save-excursion
5699 (org-back-to-heading)
5700 (org-cycle-hide-drawers 'subtree))
5701 (message "Remote: show subtree"))
5702 ((= more 4)
5703 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
5704 (org-drawer-regexp
5705 (concat "^[ \t]*:\\("
5706 (mapconcat 'regexp-quote org-drawers "\\|")
5707 "\\):[ \t]*$")))
5708 (show-subtree)
5709 (save-excursion
5710 (org-back-to-heading)
5711 (org-cycle-hide-drawers 'subtree)))
5712 (message "Remote: show subtree and LOGBOOK"))
5713 ((> more 4)
5714 (show-subtree)
5715 (message "Remote: show subtree and LOGBOOK")))
5716 (select-window win)))
5718 (defun org-recenter-heading (n)
5719 (save-excursion
5720 (org-back-to-heading)
5721 (recenter n)))
5723 (defvar org-agenda-cycle-counter nil)
5724 (defun org-agenda-cycle-show (n)
5725 "Show the current entry in another window, with default settings.
5726 Default settings are taken from `org-show-hierarchy-above' and siblings.
5727 When use repeadedly in immediate succession, the remote entry will cycle
5728 through visibility
5730 entry -> subtree -> subtree with logbook"
5731 (interactive "p")
5732 (when (and (= n 1)
5733 (not (eq last-command this-command)))
5734 (setq org-agenda-cycle-counter 0))
5735 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
5736 (if (> org-agenda-cycle-counter 4)
5737 (setq org-agenda-cycle-counter 0))
5738 (org-agenda-show-1 org-agenda-cycle-counter))
5740 (defun org-agenda-recenter (arg)
5741 "Display the Org-mode file which contains the item at point and recenter."
5742 (interactive "P")
5743 (let ((win (selected-window)))
5744 (org-agenda-goto t)
5745 (recenter arg)
5746 (select-window win)))
5748 (defun org-agenda-show-mouse (ev)
5749 "Display the Org-mode file which contains the item at the mouse click."
5750 (interactive "e")
5751 (mouse-set-point ev)
5752 (org-agenda-show))
5754 (defun org-agenda-check-no-diary ()
5755 "Check if the entry is a diary link and abort if yes."
5756 (if (get-text-property (point) 'org-agenda-diary-link)
5757 (org-agenda-error)))
5759 (defun org-agenda-error ()
5760 (error "Command not allowed in this line"))
5762 (defun org-agenda-tree-to-indirect-buffer ()
5763 "Show the subtree corresponding to the current entry in an indirect buffer.
5764 This calls the command `org-tree-to-indirect-buffer' from the original
5765 Org-mode buffer.
5766 With numerical prefix arg ARG, go up to this level and then take that tree.
5767 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
5768 dedicated frame)."
5769 (interactive)
5770 (org-agenda-check-no-diary)
5771 (let* ((marker (or (get-text-property (point) 'org-marker)
5772 (org-agenda-error)))
5773 (buffer (marker-buffer marker))
5774 (pos (marker-position marker)))
5775 (with-current-buffer buffer
5776 (save-excursion
5777 (goto-char pos)
5778 (call-interactively 'org-tree-to-indirect-buffer)))))
5780 (defvar org-last-heading-marker (make-marker)
5781 "Marker pointing to the headline that last changed its TODO state
5782 by a remote command from the agenda.")
5784 (defun org-agenda-todo-nextset ()
5785 "Switch TODO entry to next sequence."
5786 (interactive)
5787 (org-agenda-todo 'nextset))
5789 (defun org-agenda-todo-previousset ()
5790 "Switch TODO entry to previous sequence."
5791 (interactive)
5792 (org-agenda-todo 'previousset))
5794 (defun org-agenda-todo (&optional arg)
5795 "Cycle TODO state of line at point, also in Org-mode file.
5796 This changes the line at point, all other lines in the agenda referring to
5797 the same tree node, and the headline of the tree node in the Org-mode file."
5798 (interactive "P")
5799 (org-agenda-check-no-diary)
5800 (let* ((col (current-column))
5801 (marker (or (get-text-property (point) 'org-marker)
5802 (org-agenda-error)))
5803 (buffer (marker-buffer marker))
5804 (pos (marker-position marker))
5805 (hdmarker (get-text-property (point) 'org-hd-marker))
5806 (todayp (equal (get-text-property (point) 'day)
5807 (time-to-days (current-time))))
5808 (inhibit-read-only t)
5809 org-agenda-headline-snapshot-before-repeat newhead just-one)
5810 (org-with-remote-undo buffer
5811 (with-current-buffer buffer
5812 (widen)
5813 (goto-char pos)
5814 (org-show-context 'agenda)
5815 (save-excursion
5816 (and (outline-next-heading)
5817 (org-flag-heading nil))) ; show the next heading
5818 (let ((current-prefix-arg arg))
5819 (call-interactively 'org-todo))
5820 (and (bolp) (forward-char 1))
5821 (setq newhead (org-get-heading))
5822 (when (and (org-bound-and-true-p
5823 org-agenda-headline-snapshot-before-repeat)
5824 (not (equal org-agenda-headline-snapshot-before-repeat
5825 newhead))
5826 todayp)
5827 (setq newhead org-agenda-headline-snapshot-before-repeat
5828 just-one t))
5829 (save-excursion
5830 (org-back-to-heading)
5831 (move-marker org-last-heading-marker (point))))
5832 (beginning-of-line 1)
5833 (save-excursion
5834 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
5835 (org-move-to-column col))))
5837 (defun org-agenda-add-note (&optional arg)
5838 "Add a time-stamped note to the entry at point."
5839 (interactive "P")
5840 (org-agenda-check-no-diary)
5841 (let* ((marker (or (get-text-property (point) 'org-marker)
5842 (org-agenda-error)))
5843 (buffer (marker-buffer marker))
5844 (pos (marker-position marker))
5845 (hdmarker (get-text-property (point) 'org-hd-marker))
5846 (inhibit-read-only t))
5847 (with-current-buffer buffer
5848 (widen)
5849 (goto-char pos)
5850 (org-show-context 'agenda)
5851 (save-excursion
5852 (and (outline-next-heading)
5853 (org-flag-heading nil))) ; show the next heading
5854 (org-add-note))))
5856 (defun org-agenda-change-all-lines (newhead hdmarker
5857 &optional fixface just-this)
5858 "Change all lines in the agenda buffer which match HDMARKER.
5859 The new content of the line will be NEWHEAD (as modified by
5860 `org-format-agenda-item'). HDMARKER is checked with
5861 `equal' against all `org-hd-marker' text properties in the file.
5862 If FIXFACE is non-nil, the face of each item is modified according to
5863 the new TODO state.
5864 If JUST-THIS is non-nil, change just the current line, not all.
5865 If FORCE-TAGS is non nil, the car of it returns the new tags."
5866 (let* ((inhibit-read-only t)
5867 (line (org-current-line))
5868 (thetags (with-current-buffer (marker-buffer hdmarker)
5869 (save-excursion (save-restriction (widen)
5870 (goto-char hdmarker)
5871 (org-get-tags-at)))))
5872 props m pl undone-face done-face finish new dotime cat tags)
5873 (save-excursion
5874 (goto-char (point-max))
5875 (beginning-of-line 1)
5876 (while (not finish)
5877 (setq finish (bobp))
5878 (when (and (setq m (get-text-property (point) 'org-hd-marker))
5879 (or (not just-this) (= (org-current-line) line))
5880 (equal m hdmarker))
5881 (setq props (text-properties-at (point))
5882 dotime (get-text-property (point) 'dotime)
5883 cat (get-text-property (point) 'org-category)
5884 tags thetags
5885 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
5886 pl (get-text-property (point) 'prefix-length)
5887 undone-face (get-text-property (point) 'undone-face)
5888 done-face (get-text-property (point) 'done-face))
5889 (org-move-to-column pl)
5890 (cond
5891 ((equal new "")
5892 (beginning-of-line 1)
5893 (and (looking-at ".*\n?") (replace-match "")))
5894 ((looking-at ".*")
5895 (replace-match new t t)
5896 (beginning-of-line 1)
5897 (add-text-properties (point-at-bol) (point-at-eol) props)
5898 (when fixface
5899 (add-text-properties
5900 (point-at-bol) (point-at-eol)
5901 (list 'face
5902 (if org-last-todo-state-is-todo
5903 undone-face done-face))))
5904 (org-agenda-highlight-todo 'line)
5905 (beginning-of-line 1))
5906 (t (error "Line update did not work"))))
5907 (beginning-of-line 0)))
5908 (org-finalize-agenda)))
5910 (defun org-agenda-align-tags (&optional line)
5911 "Align all tags in agenda items to `org-agenda-tags-column'."
5912 (let ((inhibit-read-only t) l c)
5913 (save-excursion
5914 (goto-char (if line (point-at-bol) (point-min)))
5915 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
5916 (if line (point-at-eol) nil) t)
5917 (add-text-properties
5918 (match-beginning 2) (match-end 2)
5919 (list 'face (delq nil (let ((prop (get-text-property
5920 (match-beginning 2) 'face)))
5921 (or (listp prop) (setq prop (list prop)))
5922 (if (memq 'org-tag prop)
5923 prop
5924 (cons 'org-tag prop))))))
5925 (setq l (- (match-end 2) (match-beginning 2))
5926 c (if (< org-agenda-tags-column 0)
5927 (- (abs org-agenda-tags-column) l)
5928 org-agenda-tags-column))
5929 (delete-region (match-beginning 1) (match-end 1))
5930 (goto-char (match-beginning 1))
5931 (insert (org-add-props
5932 (make-string (max 1 (- c (current-column))) ?\ )
5933 (text-properties-at (point)))))
5934 (goto-char (point-min))
5935 (org-font-lock-add-tag-faces (point-max)))))
5937 (defun org-agenda-priority-up ()
5938 "Increase the priority of line at point, also in Org-mode file."
5939 (interactive)
5940 (org-agenda-priority 'up))
5942 (defun org-agenda-priority-down ()
5943 "Decrease the priority of line at point, also in Org-mode file."
5944 (interactive)
5945 (org-agenda-priority 'down))
5947 (defun org-agenda-priority (&optional force-direction)
5948 "Set the priority of line at point, also in Org-mode file.
5949 This changes the line at point, all other lines in the agenda referring to
5950 the same tree node, and the headline of the tree node in the Org-mode file."
5951 (interactive)
5952 (unless org-enable-priority-commands
5953 (error "Priority commands are disabled"))
5954 (org-agenda-check-no-diary)
5955 (let* ((marker (or (get-text-property (point) 'org-marker)
5956 (org-agenda-error)))
5957 (hdmarker (get-text-property (point) 'org-hd-marker))
5958 (buffer (marker-buffer hdmarker))
5959 (pos (marker-position hdmarker))
5960 (inhibit-read-only t)
5961 newhead)
5962 (org-with-remote-undo buffer
5963 (with-current-buffer buffer
5964 (widen)
5965 (goto-char pos)
5966 (org-show-context 'agenda)
5967 (save-excursion
5968 (and (outline-next-heading)
5969 (org-flag-heading nil))) ; show the next heading
5970 (funcall 'org-priority force-direction)
5971 (end-of-line 1)
5972 (setq newhead (org-get-heading)))
5973 (org-agenda-change-all-lines newhead hdmarker)
5974 (beginning-of-line 1))))
5976 ;; FIXME: should fix the tags property of the agenda line.
5977 (defun org-agenda-set-tags (&optional tag onoff)
5978 "Set tags for the current headline."
5979 (interactive)
5980 (org-agenda-check-no-diary)
5981 (if (and (org-region-active-p) (interactive-p))
5982 (call-interactively 'org-change-tag-in-region)
5983 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5984 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
5985 (org-agenda-error)))
5986 (buffer (marker-buffer hdmarker))
5987 (pos (marker-position hdmarker))
5988 (inhibit-read-only t)
5989 newhead)
5990 (org-with-remote-undo buffer
5991 (with-current-buffer buffer
5992 (widen)
5993 (goto-char pos)
5994 (save-excursion
5995 (org-show-context 'agenda))
5996 (save-excursion
5997 (and (outline-next-heading)
5998 (org-flag-heading nil))) ; show the next heading
5999 (goto-char pos)
6000 (if tag
6001 (org-toggle-tag tag onoff)
6002 (call-interactively 'org-set-tags))
6003 (end-of-line 1)
6004 (setq newhead (org-get-heading)))
6005 (org-agenda-change-all-lines newhead hdmarker)
6006 (beginning-of-line 1)))))
6008 (defun org-agenda-toggle-archive-tag ()
6009 "Toggle the archive tag for the current entry."
6010 (interactive)
6011 (org-agenda-check-no-diary)
6012 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6013 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
6014 (org-agenda-error)))
6015 (buffer (marker-buffer hdmarker))
6016 (pos (marker-position hdmarker))
6017 (inhibit-read-only t)
6018 newhead)
6019 (org-with-remote-undo buffer
6020 (with-current-buffer buffer
6021 (widen)
6022 (goto-char pos)
6023 (org-show-context 'agenda)
6024 (save-excursion
6025 (and (outline-next-heading)
6026 (org-flag-heading nil))) ; show the next heading
6027 (call-interactively 'org-toggle-archive-tag)
6028 (end-of-line 1)
6029 (setq newhead (org-get-heading)))
6030 (org-agenda-change-all-lines newhead hdmarker)
6031 (beginning-of-line 1))))
6033 (defun org-agenda-do-date-later (arg)
6034 (interactive "P")
6035 (cond
6036 ((or (equal arg '(16))
6037 (memq last-command
6038 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6039 (setq this-command 'org-agenda-date-later-minutes)
6040 (org-agenda-date-later-minutes 1))
6041 ((or (equal arg '(4))
6042 (memq last-command
6043 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6044 (setq this-command 'org-agenda-date-later-hours)
6045 (org-agenda-date-later-hours 1))
6047 (org-agenda-date-later (prefix-numeric-value arg)))))
6049 (defun org-agenda-do-date-earlier (arg)
6050 (interactive "P")
6051 (cond
6052 ((or (equal arg '(16))
6053 (memq last-command
6054 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6055 (setq this-command 'org-agenda-date-earlier-minutes)
6056 (org-agenda-date-earlier-minutes 1))
6057 ((or (equal arg '(4))
6058 (memq last-command
6059 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6060 (setq this-command 'org-agenda-date-earlier-hours)
6061 (org-agenda-date-earlier-hours 1))
6063 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6065 (defun org-agenda-date-later (arg &optional what)
6066 "Change the date of this item to one day later."
6067 (interactive "p")
6068 (org-agenda-check-type t 'agenda 'timeline)
6069 (org-agenda-check-no-diary)
6070 (let* ((marker (or (get-text-property (point) 'org-marker)
6071 (org-agenda-error)))
6072 (buffer (marker-buffer marker))
6073 (pos (marker-position marker)))
6074 (org-with-remote-undo buffer
6075 (with-current-buffer buffer
6076 (widen)
6077 (goto-char pos)
6078 (if (not (org-at-timestamp-p))
6079 (error "Cannot find time stamp"))
6080 (org-timestamp-change arg (or what 'day)))
6081 (org-agenda-show-new-time marker org-last-changed-timestamp))
6082 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6084 (defun org-agenda-date-earlier (arg &optional what)
6085 "Change the date of this item to one day earlier."
6086 (interactive "p")
6087 (org-agenda-date-later (- arg) what))
6089 (defun org-agenda-date-later-minutes (arg)
6090 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6091 (interactive "p")
6092 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6093 (org-agenda-date-later arg 'minute))
6095 (defun org-agenda-date-earlier-minutes (arg)
6096 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6097 (interactive "p")
6098 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6099 (org-agenda-date-earlier arg 'minute))
6101 (defun org-agenda-date-later-hours (arg)
6102 "Change the time of this item, in hour steps."
6103 (interactive "p")
6104 (org-agenda-date-later arg 'hour))
6106 (defun org-agenda-date-earlier-hours (arg)
6107 "Change the time of this item, in hour steps."
6108 (interactive "p")
6109 (org-agenda-date-earlier arg 'hour))
6111 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6112 "Show new date stamp via text properties."
6113 ;; We use text properties to make this undoable
6114 (let ((inhibit-read-only t)
6115 (buffer-invisibility-spec))
6116 (setq stamp (concat " " prefix " => " stamp))
6117 (save-excursion
6118 (goto-char (point-max))
6119 (while (not (bobp))
6120 (when (equal marker (get-text-property (point) 'org-marker))
6121 (org-move-to-column (- (window-width) (length stamp)) t)
6122 (org-agenda-fix-tags-filter-overlays-at (point))
6123 (if (featurep 'xemacs)
6124 ;; Use `duplicable' property to trigger undo recording
6125 (let ((ex (make-extent nil nil))
6126 (gl (make-glyph stamp)))
6127 (set-glyph-face gl 'secondary-selection)
6128 (set-extent-properties
6129 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6130 (insert-extent ex (1- (point)) (point-at-eol)))
6131 (add-text-properties
6132 (1- (point)) (point-at-eol)
6133 (list 'display (org-add-props stamp nil
6134 'face 'secondary-selection))))
6135 (beginning-of-line 1))
6136 (beginning-of-line 0)))))
6138 (defun org-agenda-date-prompt (arg)
6139 "Change the date of this item. Date is prompted for, with default today.
6140 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6141 be used to request time specification in the time stamp."
6142 (interactive "P")
6143 (org-agenda-check-type t 'agenda 'timeline)
6144 (org-agenda-check-no-diary)
6145 (let* ((marker (or (get-text-property (point) 'org-marker)
6146 (org-agenda-error)))
6147 (buffer (marker-buffer marker))
6148 (pos (marker-position marker)))
6149 (org-with-remote-undo buffer
6150 (with-current-buffer buffer
6151 (widen)
6152 (goto-char pos)
6153 (if (not (org-at-timestamp-p))
6154 (error "Cannot find time stamp"))
6155 (org-time-stamp arg)
6156 (message "Time stamp changed to %s" org-last-changed-timestamp)))))
6158 (defun org-agenda-schedule (arg)
6159 "Schedule the item at point."
6160 (interactive "P")
6161 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6162 (org-agenda-check-no-diary)
6163 (let* ((marker (or (get-text-property (point) 'org-marker)
6164 (org-agenda-error)))
6165 (type (marker-insertion-type marker))
6166 (buffer (marker-buffer marker))
6167 (pos (marker-position marker))
6168 (org-insert-labeled-timestamps-at-point nil)
6170 (set-marker-insertion-type marker t)
6171 (org-with-remote-undo buffer
6172 (with-current-buffer buffer
6173 (widen)
6174 (goto-char pos)
6175 (setq ts (org-schedule arg)))
6176 (org-agenda-show-new-time marker ts "S"))
6177 (message "Item scheduled for %s" ts)))
6179 (defun org-agenda-deadline (arg)
6180 "Schedule the item at point."
6181 (interactive "P")
6182 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6183 (org-agenda-check-no-diary)
6184 (let* ((marker (or (get-text-property (point) 'org-marker)
6185 (org-agenda-error)))
6186 (buffer (marker-buffer marker))
6187 (pos (marker-position marker))
6188 (org-insert-labeled-timestamps-at-point nil)
6190 (org-with-remote-undo buffer
6191 (with-current-buffer buffer
6192 (widen)
6193 (goto-char pos)
6194 (setq ts (org-deadline arg)))
6195 (org-agenda-show-new-time marker ts "S"))
6196 (message "Deadline for this item set to %s" ts)))
6198 (defun org-agenda-action ()
6199 "Select entry for agenda action, or execute an agenda action.
6200 This command prompts for another letter. Valid inputs are:
6202 m Mark the entry at point for an agenda action
6203 s Schedule the marked entry to the date at the cursor
6204 d Set the deadline of the marked entry to the date at the cursor
6205 r Call `org-remember' with cursor date as the default date
6206 SPC Show marked entry in other window
6207 TAB Visit marked entry in other window
6209 The cursor may be at a date in the calendar, or in the Org agenda."
6210 (interactive)
6211 (let (ans)
6212 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6213 (setq ans (read-char-exclusive))
6214 (cond
6215 ((equal ans ?m)
6216 ;; Mark this entry
6217 (if (eq major-mode 'org-agenda-mode)
6218 (let ((m (or (get-text-property (point) 'org-hd-marker)
6219 (get-text-property (point) 'org-marker))))
6220 (if m
6221 (progn
6222 (move-marker org-agenda-action-marker
6223 (marker-position m) (marker-buffer m))
6224 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6225 (error "Don't know which entry to mark")))
6226 (error "This command works only in the agenda")))
6227 ((equal ans ?s)
6228 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6229 ((equal ans ?d)
6230 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6231 ((equal ans ?r)
6232 (org-agenda-do-action '(org-remember) t))
6233 ((equal ans ?\ )
6234 (let ((cw (selected-window)))
6235 (org-switch-to-buffer-other-window
6236 (marker-buffer org-agenda-action-marker))
6237 (goto-char org-agenda-action-marker)
6238 (org-show-context 'agenda)
6239 (select-window cw)))
6240 ((equal ans ?\C-i)
6241 (org-switch-to-buffer-other-window
6242 (marker-buffer org-agenda-action-marker))
6243 (goto-char org-agenda-action-marker)
6244 (org-show-context 'agenda))
6245 (t (error "Invalid agenda action %c" ans)))))
6247 (defun org-agenda-do-action (form &optional current-buffer)
6248 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6249 (let ((org-overriding-default-time (org-get-cursor-date)))
6250 (if current-buffer
6251 (eval form)
6252 (if (not (marker-buffer org-agenda-action-marker))
6253 (error "No entry has bee selected for agenda action")
6254 (with-current-buffer (marker-buffer org-agenda-action-marker)
6255 (save-excursion
6256 (save-restriction
6257 (widen)
6258 (goto-char org-agenda-action-marker)
6259 (eval form))))))))
6261 (defun org-agenda-clock-in (&optional arg)
6262 "Start the clock on the currently selected item."
6263 (interactive "P")
6264 (org-agenda-check-no-diary)
6265 (if (equal arg '(4))
6266 (org-clock-in arg)
6267 (let* ((marker (or (get-text-property (point) 'org-marker)
6268 (org-agenda-error)))
6269 (hdmarker (or (get-text-property (point) 'org-hd-marker)
6270 marker))
6271 (pos (marker-position marker))
6272 newhead)
6273 (org-with-remote-undo (marker-buffer marker)
6274 (with-current-buffer (marker-buffer marker)
6275 (widen)
6276 (goto-char pos)
6277 (org-show-context 'agenda)
6278 (org-show-entry)
6279 (org-cycle-hide-drawers 'children)
6280 (org-clock-in arg)
6281 (setq newhead (org-get-heading)))
6282 (org-agenda-change-all-lines newhead hdmarker)))))
6284 (defun org-agenda-clock-out (&optional arg)
6285 "Stop the currently running clock."
6286 (interactive "P")
6287 (unless (marker-buffer org-clock-marker)
6288 (error "No running clock"))
6289 (let ((marker (make-marker)) newhead)
6290 (org-with-remote-undo (marker-buffer org-clock-marker)
6291 (with-current-buffer (marker-buffer org-clock-marker)
6292 (save-excursion
6293 (save-restriction
6294 (widen)
6295 (goto-char org-clock-marker)
6296 (org-back-to-heading t)
6297 (move-marker marker (point))
6298 (org-clock-out)
6299 (setq newhead (org-get-heading))))))
6300 (org-agenda-change-all-lines newhead marker)
6301 (move-marker marker nil)))
6303 (defun org-agenda-clock-cancel (&optional arg)
6304 "Cancel the currently running clock."
6305 (interactive "P")
6306 (unless (marker-buffer org-clock-marker)
6307 (error "No running clock"))
6308 (org-with-remote-undo (marker-buffer org-clock-marker)
6309 (org-clock-cancel)))
6311 (defun org-agenda-diary-entry ()
6312 "Make a diary entry, like the `i' command from the calendar.
6313 All the standard commands work: block, weekly etc."
6314 (interactive)
6315 (org-agenda-check-type t 'agenda 'timeline)
6316 (require 'diary-lib)
6317 (let* ((char (progn
6318 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6319 (read-char-exclusive)))
6320 (cmd (cdr (assoc char
6321 '((?d . insert-diary-entry)
6322 (?w . insert-weekly-diary-entry)
6323 (?m . insert-monthly-diary-entry)
6324 (?y . insert-yearly-diary-entry)
6325 (?a . insert-anniversary-diary-entry)
6326 (?b . insert-block-diary-entry)
6327 (?c . insert-cyclic-diary-entry)))))
6328 (oldf (symbol-function 'calendar-cursor-to-date))
6329 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6330 (point (point))
6331 (mark (or (mark t) (point))))
6332 (unless cmd
6333 (error "No command associated with <%c>" char))
6334 (unless (and (get-text-property point 'day)
6335 (or (not (equal ?b char))
6336 (get-text-property mark 'day)))
6337 (error "Don't know which date to use for diary entry"))
6338 ;; We implement this by hacking the `calendar-cursor-to-date' function
6339 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6340 (let ((calendar-mark-ring
6341 (list (calendar-gregorian-from-absolute
6342 (or (get-text-property mark 'day)
6343 (get-text-property point 'day))))))
6344 (unwind-protect
6345 (progn
6346 (fset 'calendar-cursor-to-date
6347 (lambda (&optional error dummy)
6348 (calendar-gregorian-from-absolute
6349 (get-text-property point 'day))))
6350 (call-interactively cmd))
6351 (fset 'calendar-cursor-to-date oldf)))))
6353 (defun org-agenda-execute-calendar-command (cmd)
6354 "Execute a calendar command from the agenda, with the date associated to
6355 the cursor position."
6356 (org-agenda-check-type t 'agenda 'timeline)
6357 (require 'diary-lib)
6358 (unless (get-text-property (point) 'day)
6359 (error "Don't know which date to use for calendar command"))
6360 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
6361 (point (point))
6362 (date (calendar-gregorian-from-absolute
6363 (get-text-property point 'day)))
6364 ;; the following 2 vars are needed in the calendar
6365 (displayed-month (car date))
6366 (displayed-year (nth 2 date)))
6367 (unwind-protect
6368 (progn
6369 (fset 'calendar-cursor-to-date
6370 (lambda (&optional error dummy)
6371 (calendar-gregorian-from-absolute
6372 (get-text-property point 'day))))
6373 (call-interactively cmd))
6374 (fset 'calendar-cursor-to-date oldf))))
6376 (defun org-agenda-phases-of-moon ()
6377 "Display the phases of the moon for the 3 months around the cursor date."
6378 (interactive)
6379 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
6381 (defun org-agenda-holidays ()
6382 "Display the holidays for the 3 months around the cursor date."
6383 (interactive)
6384 (org-agenda-execute-calendar-command 'list-calendar-holidays))
6386 (defvar calendar-longitude)
6387 (defvar calendar-latitude)
6388 (defvar calendar-location-name)
6390 (defun org-agenda-sunrise-sunset (arg)
6391 "Display sunrise and sunset for the cursor date.
6392 Latitude and longitude can be specified with the variables
6393 `calendar-latitude' and `calendar-longitude'. When called with prefix
6394 argument, latitude and longitude will be prompted for."
6395 (interactive "P")
6396 (require 'solar)
6397 (let ((calendar-longitude (if arg nil calendar-longitude))
6398 (calendar-latitude (if arg nil calendar-latitude))
6399 (calendar-location-name
6400 (if arg "the given coordinates" calendar-location-name)))
6401 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
6403 (defun org-agenda-goto-calendar ()
6404 "Open the Emacs calendar with the date at the cursor."
6405 (interactive)
6406 (org-agenda-check-type t 'agenda 'timeline)
6407 (let* ((day (or (get-text-property (point) 'day)
6408 (error "Don't know which date to open in calendar")))
6409 (date (calendar-gregorian-from-absolute day))
6410 (calendar-move-hook nil)
6411 (calendar-view-holidays-initially-flag nil)
6412 (calendar-view-diary-initially-flag nil)
6413 (view-calendar-holidays-initially nil)
6414 (view-diary-entries-initially nil))
6415 (calendar)
6416 (calendar-goto-date date)))
6418 ;;;###autoload
6419 (defun org-calendar-goto-agenda ()
6420 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6421 This is a command that has to be installed in `calendar-mode-map'."
6422 (interactive)
6423 (org-agenda-list nil (calendar-absolute-from-gregorian
6424 (calendar-cursor-to-date))
6425 nil))
6427 (defun org-agenda-convert-date ()
6428 (interactive)
6429 (org-agenda-check-type t 'agenda 'timeline)
6430 (let ((day (get-text-property (point) 'day))
6431 date s)
6432 (unless day
6433 (error "Don't know which date to convert"))
6434 (setq date (calendar-gregorian-from-absolute day))
6435 (setq s (concat
6436 "Gregorian: " (calendar-date-string date) "\n"
6437 "ISO: " (calendar-iso-date-string date) "\n"
6438 "Day of Yr: " (calendar-day-of-year-string date) "\n"
6439 "Julian: " (calendar-julian-date-string date) "\n"
6440 "Astron. JD: " (calendar-astro-date-string date)
6441 " (Julian date number at noon UTC)\n"
6442 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
6443 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
6444 "French: " (calendar-french-date-string date) "\n"
6445 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
6446 "Mayan: " (calendar-mayan-date-string date) "\n"
6447 "Coptic: " (calendar-coptic-date-string date) "\n"
6448 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
6449 "Persian: " (calendar-persian-date-string date) "\n"
6450 "Chinese: " (calendar-chinese-date-string date) "\n"))
6451 (with-output-to-temp-buffer "*Dates*"
6452 (princ s))
6453 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6455 ;;; Bulk commands
6457 (defvar org-agenda-bulk-marked-entries nil
6458 "List of markers that refer to marked entries in the agenda.")
6460 (defun org-agenda-bulk-marked-p ()
6461 (eq (get-char-property (point-at-bol) 'type)
6462 'org-marked-entry-overlay))
6464 (defun org-agenda-bulk-mark ()
6465 "Mark the entry at point for future bulk action."
6466 (interactive)
6467 (org-agenda-check-no-diary)
6468 (let* ((m (get-text-property (point) 'org-hd-marker))
6470 (unless (org-agenda-bulk-marked-p)
6471 (unless m (error "Nothing to mark at point"))
6472 (push m org-agenda-bulk-marked-entries)
6473 (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
6474 (org-overlay-display ov ">>"
6475 (org-get-todo-face "TODO")
6476 'evaporate)
6477 (org-overlay-put ov 'type 'org-marked-entry-overlay))
6478 (beginning-of-line 2)
6479 (message "%d entries marked for bulk action"
6480 (length org-agenda-bulk-marked-entries))))
6482 (defun org-agenda-bulk-unmark ()
6483 "Unmark the entry at point for future bulk action."
6484 (interactive)
6485 (when (org-agenda-bulk-marked-p)
6486 (org-agenda-bulk-remove-overlays
6487 (point-at-bol) (+ 2 (point-at-bol)))
6488 (setq org-agenda-bulk-marked-entries
6489 (delete (get-text-property (point-at-bol) 'org-hd-marker)
6490 org-agenda-bulk-marked-entries)))
6491 (beginning-of-line 2)
6492 (message "%d entries marked for bulk action"
6493 (length org-agenda-bulk-marked-entries)))
6495 (defun org-agenda-bulk-toggle ()
6496 "Toggle marking the entry at point for bulk action."
6497 (interactive)
6498 (if (org-agenda-bulk-marked-p)
6499 (org-agenda-bulk-unmark)
6500 (org-agenda-bulk-mark)))
6502 (defun org-agenda-bulk-remove-overlays (&optional beg end)
6503 "Remove the mark overlays between BEG and END in the agenda buffer.
6504 BEG and END default to the buffer limits.
6506 This only removes the overlays, it does not remove the markers
6507 from the list in `org-agenda-bulk-marked-entries'."
6508 (interactive)
6509 (mapc (lambda (ov)
6510 (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
6511 (org-delete-overlay ov)))
6512 (org-overlays-in (or beg (point-min)) (or end (point-max)))))
6514 (defun org-agenda-bulk-remove-all-marks ()
6515 "Remove all marks in the agenda buffer.
6516 This will remove the markers, and the overlays."
6517 (interactive)
6518 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
6519 (setq org-agenda-bulk-marked-entries nil)
6520 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
6522 (defun org-agenda-bulk-action ()
6523 "Execute an remote-editing action on all marked entries."
6524 (interactive)
6525 (unless org-agenda-bulk-marked-entries
6526 (error "No entries are marked"))
6527 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
6528 (let* ((action (read-char-exclusive))
6529 (entries (reverse org-agenda-bulk-marked-entries))
6530 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
6531 (cond
6532 ((equal action ?$)
6533 (setq cmd '(org-agenda-archive)))
6535 ((equal action ?A)
6536 (setq cmd '(org-agenda-archive-to-archive-sibling)))
6538 ((member action '(?r ?w))
6539 (setq rfloc (org-refile-get-location
6540 "Refile to: "
6541 (marker-buffer (car org-agenda-bulk-marked-entries))
6542 org-refile-allow-creating-parent-nodes))
6543 (setcar (nthcdr 3 rfloc)
6544 (move-marker (make-marker) (nth 3 rfloc)
6545 (or (get-file-buffer (nth 1 rfloc))
6546 (find-buffer-visiting (nth 1 rfloc))
6547 (error "This should not happen"))))
6549 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
6551 ((equal action ?t)
6552 (setq state (org-icompleting-read
6553 "Todo state: "
6554 (with-current-buffer (marker-buffer (car entries))
6555 (mapcar 'list org-todo-keywords-1))))
6556 (setq cmd `(let ((org-inhibit-blocking t)
6557 (org-inhibit-logging 'note))
6558 (org-agenda-todo ,state))))
6560 ((memq action '(?- ?+))
6561 (setq tag (org-icompleting-read
6562 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
6563 (with-current-buffer (marker-buffer (car entries))
6564 (delq nil
6565 (mapcar (lambda (x)
6566 (if (stringp (car x)) x)) org-tag-alist)))))
6567 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
6569 ((memq action '(?s ?d))
6570 (let* ((date (org-read-date
6571 nil nil nil
6572 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
6573 (ans org-read-date-final-answer)
6574 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
6575 (setq cmd `(let* ((bound (fboundp 'read-string))
6576 (old (and bound (symbol-function 'read-string))))
6577 (unwind-protect
6578 (progn
6579 (fset 'read-string (lambda (&rest ignore) ,ans))
6580 (call-interactively ',c1))
6581 (if bound
6582 (fset 'read-string old)
6583 (fmakunbound 'read-string)))))))
6584 (t (error "Invalid bulk action")))
6586 ;; Sort the markers, to make sure that parents are handled before children
6587 (setq entries (sort entries
6588 (lambda (a b)
6589 (cond
6590 ((equal (marker-buffer a) (marker-buffer b))
6591 (< (marker-position a) (marker-position b)))
6593 (string< (buffer-name (marker-buffer a))
6594 (buffer-name (marker-buffer b))))))))
6596 ;; Now loop over all markers and apply cmd
6597 (while (setq e (pop entries))
6598 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
6599 (if (not pos)
6600 (progn (message "Skipping removed entry at %s" e)
6601 (setq cntskip (1+ cntskip)))
6602 (goto-char pos)
6603 (eval cmd)
6604 (setq org-agenda-bulk-marked-entries
6605 (delete e org-agenda-bulk-marked-entries))
6606 (setq cnt (1+ cnt))))
6607 (setq org-agenda-bulk-marked-entries nil)
6608 (org-agenda-bulk-remove-all-marks)
6609 (message "Acted on %d entries%s"
6611 (if (= cntskip 0)
6613 (format ", skipped %d (disappeared before their turn)"
6614 cntskip)))))
6616 ;;; Appointment reminders
6618 (defvar appt-time-msg-list)
6620 ;;;###autoload
6621 (defun org-agenda-to-appt (&optional refresh filter)
6622 "Activate appointments found in `org-agenda-files'.
6623 With a \\[universal-argument] prefix, refresh the list of
6624 appointments.
6626 If FILTER is t, interactively prompt the user for a regular
6627 expression, and filter out entries that don't match it.
6629 If FILTER is a string, use this string as a regular expression
6630 for filtering entries out.
6632 FILTER can also be an alist with the car of each cell being
6633 either 'headline or 'category. For example:
6635 '((headline \"IMPORTANT\")
6636 (category \"Work\"))
6638 will only add headlines containing IMPORTANT or headlines
6639 belonging to the \"Work\" category."
6640 (interactive "P")
6641 (require 'calendar)
6642 (if refresh (setq appt-time-msg-list nil))
6643 (if (eq filter t)
6644 (setq filter (read-from-minibuffer "Regexp filter: ")))
6645 (let* ((cnt 0) ; count added events
6646 (org-agenda-new-buffers nil)
6647 (org-deadline-warning-days 0)
6648 (today (org-date-to-gregorian
6649 (time-to-days (current-time))))
6650 (org-agenda-restrict nil)
6651 (files (org-agenda-files 'unrestricted)) entries file)
6652 ;; Get all entries which may contain an appt
6653 (org-prepare-agenda-buffers files)
6654 (while (setq file (pop files))
6655 (setq entries
6656 (append entries
6657 (org-agenda-get-day-entries
6658 file today :timestamp :scheduled :deadline))))
6659 (setq entries (delq nil entries))
6660 ;; Map thru entries and find if we should filter them out
6661 (mapc
6662 (lambda(x)
6663 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
6664 (cat (get-text-property 1 'org-category x))
6665 (tod (get-text-property 1 'time-of-day x))
6666 (ok (or (null filter)
6667 (and (stringp filter) (string-match filter evt))
6668 (and (listp filter)
6669 (or (string-match
6670 (cadr (assoc 'category filter)) cat)
6671 (string-match
6672 (cadr (assoc 'headline filter)) evt))))))
6673 ;; FIXME: Shall we remove text-properties for the appt text?
6674 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
6675 (when (and ok tod)
6676 (setq tod (concat "00" (number-to-string tod))
6677 tod (when (string-match
6678 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
6679 (concat (match-string 1 tod) ":"
6680 (match-string 2 tod))))
6681 (appt-add tod evt)
6682 (setq cnt (1+ cnt))))) entries)
6683 (org-release-buffers org-agenda-new-buffers)
6684 (if (eq cnt 0)
6685 (message "No event to add")
6686 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
6688 (defun org-agenda-todayp (date)
6689 "Does DATE mean today, when considering `org-extend-today-until'?"
6690 (let (today h)
6691 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
6692 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
6693 (setq h (nth 2 (decode-time (current-time))))
6694 (or (and (>= h org-extend-today-until)
6695 (= date today))
6696 (and (< h org-extend-today-until)
6697 (= date (1- today))))))
6699 (provide 'org-agenda)
6701 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
6703 ;;; org-agenda.el ends here