Version number bump to 6.00pre-3
[org-mode.git] / lisp / org-agenda.el
bloba725d835c20e8911b1c1f6ee5f1e7b289ea0a729
1 ;;; org-agenda.el --- The table editor for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 6.00pre-3
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 ;; This file contains the code for creating and using the Agenda for Org-mode.
32 ;;; Code:
34 (require 'org)
35 (eval-when-compile
36 (require 'calendar))
38 (declare-function add-to-diary-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" (&optional 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 (defvar calendar-mode-map)
58 ;; Defined somewhere in this file, but used before definition.
59 (defvar org-agenda-buffer-name)
60 (defvar org-agenda-overriding-header)
61 (defvar entry)
62 (defvar date)
63 (defvar org-agenda-undo-list)
64 (defvar org-agenda-pending-undo-list)
65 (defvar original-date) ; dynamically scoped, calendar.el does scope this
67 (defcustom org-agenda-confirm-kill 1
68 "When set, remote killing from the agenda buffer needs confirmation.
69 When t, a confirmation is always needed. When a number N, confirmation is
70 only needed when the text to be killed contains more than N non-white lines."
71 :group 'org-agenda
72 :type '(choice
73 (const :tag "Never" nil)
74 (const :tag "Always" t)
75 (number :tag "When more than N lines")))
77 (defcustom org-agenda-compact-blocks nil
78 "Non-nil means, make the block agenda more compact.
79 This is done by leaving out unnecessary lines."
80 :group 'org-agenda
81 :type nil)
83 (defgroup org-agenda-export nil
84 "Options concerning exporting agenda views in Org-mode."
85 :tag "Org Agenda Export"
86 :group 'org-agenda)
88 (defcustom org-agenda-with-colors t
89 "Non-nil means, use colors in agenda views."
90 :group 'org-agenda-export
91 :type 'boolean)
93 (defcustom org-agenda-exporter-settings nil
94 "Alist of variable/value pairs that should be active during agenda export.
95 This is a good place to set uptions for ps-print and for htmlize."
96 :group 'org-agenda-export
97 :type '(repeat
98 (list
99 (variable)
100 (sexp :tag "Value"))))
102 (defcustom org-agenda-export-html-style ""
103 "The style specification for exported HTML Agenda files.
104 If this variable contains a string, it will replace the default <style>
105 section as produced by `htmlize'.
106 Since there are different ways of setting style information, this variable
107 needs to contain the full HTML structure to provide a style, including the
108 surrounding HTML tags. The style specifications should include definitions
109 the fonts used by the agenda, here is an example:
111 <style type=\"text/css\">
112 p { font-weight: normal; color: gray; }
113 .org-agenda-structure {
114 font-size: 110%;
115 color: #003399;
116 font-weight: 600;
118 .org-todo {
119 color: #cc6666;
120 font-weight: bold;
122 .org-done {
123 color: #339933;
125 .title { text-align: center; }
126 .todo, .deadline { color: red; }
127 .done { color: green; }
128 </style>
130 or, if you want to keep the style in a file,
132 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
134 As the value of this option simply gets inserted into the HTML <head> header,
135 you can \"misuse\" it to also add other text to the header. However,
136 <style>...</style> is required, if not present the variable will be ignored."
137 :group 'org-agenda-export
138 :group 'org-export-html
139 :type 'string)
141 (defgroup org-agenda-custom-commands nil
142 "Options concerning agenda views in Org-mode."
143 :tag "Org Agenda Custom Commands"
144 :group 'org-agenda)
146 (defconst org-sorting-choice
147 '(choice
148 (const time-up) (const time-down)
149 (const category-keep) (const category-up) (const category-down)
150 (const tag-down) (const tag-up)
151 (const priority-up) (const priority-down))
152 "Sorting choices.")
154 (defconst org-agenda-custom-commands-local-options
155 `(repeat :tag "Local settings for this command. Remember to quote values"
156 (choice :tag "Setting"
157 (list :tag "Any variable"
158 (variable :tag "Variable")
159 (sexp :tag "Value"))
160 (list :tag "Files to be searched"
161 (const org-agenda-files)
162 (list
163 (const :format "" quote)
164 (repeat
165 (file))))
166 (list :tag "Sorting strategy"
167 (const org-agenda-sorting-strategy)
168 (list
169 (const :format "" quote)
170 (repeat
171 ,org-sorting-choice)))
172 (list :tag "Prefix format"
173 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
174 (string))
175 (list :tag "Number of days in agenda"
176 (const org-agenda-ndays)
177 (integer :value 1))
178 (list :tag "Fixed starting date"
179 (const org-agenda-start-day)
180 (string :value "2007-11-01"))
181 (list :tag "Start on day of week"
182 (const org-agenda-start-on-weekday)
183 (choice :value 1
184 (const :tag "Today" nil)
185 (number :tag "Weekday No.")))
186 (list :tag "Include data from diary"
187 (const org-agenda-include-diary)
188 (boolean))
189 (list :tag "Deadline Warning days"
190 (const org-deadline-warning-days)
191 (integer :value 1))
192 (list :tag "Standard skipping condition"
193 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
194 (const org-agenda-skip-function)
195 (list
196 (const :format "" quote)
197 (list
198 (choice
199 :tag "Skiping range"
200 (const :tag "Skip entry" org-agenda-skip-entry-if)
201 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
202 (repeat :inline t :tag "Conditions for skipping"
203 (choice
204 :tag "Condition type"
205 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
206 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
207 (const :tag "scheduled" 'scheduled)
208 (const :tag "not scheduled" 'notscheduled)
209 (const :tag "deadline" 'deadline)
210 (const :tag "no deadline" 'notdeadline))))))
211 (list :tag "Non-standard skipping condition"
212 :value (org-agenda-skip-function)
213 (list
214 (const org-agenda-skip-function)
215 (sexp :tag "Function or form (quoted!)")))))
216 "Selection of examples for agenda command settings.
217 This will be spliced into the custom type of
218 `org-agenda-custom-commands'.")
221 (defcustom org-agenda-custom-commands nil
222 "Custom commands for the agenda.
223 These commands will be offered on the splash screen displayed by the
224 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
226 (key desc type match settings files)
228 key The key (one or more characters as a string) to be associated
229 with the command.
230 desc A description of the command, when omitted or nil, a default
231 description is built using MATCH.
232 type The command type, any of the following symbols:
233 agenda The daily/weekly agenda.
234 todo Entries with a specific TODO keyword, in all agenda files.
235 search Entries containing search words entry or headline.
236 tags Tags/Property/TODO match in all agenda files.
237 tags-todo Tags/P/T match in all agenda files, TODO entries only.
238 todo-tree Sparse tree of specific TODO keyword in *current* file.
239 tags-tree Sparse tree with all tags matches in *current* file.
240 occur-tree Occur sparse tree for *current* file.
241 ... A user-defined function.
242 match What to search for:
243 - a single keyword for TODO keyword searches
244 - a tags match expression for tags searches
245 - a word search expression for text searches.
246 - a regular expression for occur searches
247 For all other commands, this should be the empty string.
248 settings A list of option settings, similar to that in a let form, so like
249 this: ((opt1 val1) (opt2 val2) ...). The values will be
250 evaluated at the moment of execution, so quote them when needed.
251 files A list of files file to write the produced agenda buffer to
252 with the command `org-store-agenda-views'.
253 If a file name ends in \".html\", an HTML version of the buffer
254 is written out. If it ends in \".ps\", a postscript version is
255 produced. Otherwide, only the plain text is written to the file.
257 You can also define a set of commands, to create a composite agenda buffer.
258 In this case, an entry looks like this:
260 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
262 where
264 desc A description string to be displayed in the dispatcher menu.
265 cmd An agenda command, similar to the above. However, tree commands
266 are no allowed, but instead you can get agenda and global todo list.
267 So valid commands for a set are:
268 (agenda \"\" settings)
269 (alltodo \"\" settings)
270 (stuck \"\" settings)
271 (todo \"match\" settings files)
272 (search \"match\" settings files)
273 (tags \"match\" settings files)
274 (tags-todo \"match\" settings files)
276 Each command can carry a list of options, and another set of options can be
277 given for the whole set of commands. Individual command options take
278 precedence over the general options.
280 When using several characters as key to a command, the first characters
281 are prefix commands. For the dispatcher to display useful information, you
282 should provide a description for the prefix, like
284 (setq org-agenda-custom-commands
285 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
286 (\"hl\" tags \"+HOME+Lisa\")
287 (\"hp\" tags \"+HOME+Peter\")
288 (\"hk\" tags \"+HOME+Kim\")))"
289 :group 'org-agenda-custom-commands
290 :type `(repeat
291 (choice :value ("x" "Describe command here" tags "" nil)
292 (list :tag "Single command"
293 (string :tag "Access Key(s) ")
294 (option (string :tag "Description"))
295 (choice
296 (const :tag "Agenda" agenda)
297 (const :tag "TODO list" alltodo)
298 (const :tag "Search words" search)
299 (const :tag "Stuck projects" stuck)
300 (const :tag "Tags search (all agenda files)" tags)
301 (const :tag "Tags search of TODO entries (all agenda files)" tags-todo)
302 (const :tag "TODO keyword search (all agenda files)" todo)
303 (const :tag "Tags sparse tree (current buffer)" tags-tree)
304 (const :tag "TODO keyword tree (current buffer)" todo-tree)
305 (const :tag "Occur tree (current buffer)" occur-tree)
306 (sexp :tag "Other, user-defined function"))
307 (string :tag "Match (only for some commands)")
308 ,org-agenda-custom-commands-local-options
309 (option (repeat :tag "Export" (file :tag "Export to"))))
310 (list :tag "Command series, all agenda files"
311 (string :tag "Access Key(s)")
312 (string :tag "Description ")
313 (repeat :tag "Component"
314 (choice
315 (list :tag "Agenda"
316 (const :format "" agenda)
317 (const :tag "" :format "" "")
318 ,org-agenda-custom-commands-local-options)
319 (list :tag "TODO list (all keywords)"
320 (const :format "" alltodo)
321 (const :tag "" :format "" "")
322 ,org-agenda-custom-commands-local-options)
323 (list :tag "Search words"
324 (const :format "" search)
325 (string :tag "Match")
326 ,org-agenda-custom-commands-local-options)
327 (list :tag "Stuck projects"
328 (const :format "" stuck)
329 (const :tag "" :format "" "")
330 ,org-agenda-custom-commands-local-options)
331 (list :tag "Tags search"
332 (const :format "" tags)
333 (string :tag "Match")
334 ,org-agenda-custom-commands-local-options)
335 (list :tag "Tags search, TODO entries only"
336 (const :format "" tags-todo)
337 (string :tag "Match")
338 ,org-agenda-custom-commands-local-options)
339 (list :tag "TODO keyword search"
340 (const :format "" todo)
341 (string :tag "Match")
342 ,org-agenda-custom-commands-local-options)
343 (list :tag "Other, user-defined function"
344 (symbol :tag "function")
345 (string :tag "Match")
346 ,org-agenda-custom-commands-local-options)))
348 (repeat :tag "Settings for entire command set"
349 (list (variable :tag "Any variable")
350 (sexp :tag "Value")))
351 (option (repeat :tag "Export" (file :tag "Export to"))))
352 (cons :tag "Prefix key documentation"
353 (string :tag "Access Key(s)")
354 (string :tag "Description ")))))
356 (defcustom org-agenda-query-register ?o
357 "The register holding the current query string.
358 The prupose of this is that if you construct a query string interactively,
359 you can then use it to define a custom command."
360 :group 'org-agenda-custom-commands
361 :type 'character)
363 (defcustom org-stuck-projects
364 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
365 "How to identify stuck projects.
366 This is a list of four items:
367 1. A tags/todo matcher string that is used to identify a project.
368 The entire tree below a headline matched by this is considered one project.
369 2. A list of TODO keywords identifying non-stuck projects.
370 If the project subtree contains any headline with one of these todo
371 keywords, the project is considered to be not stuck. If you specify
372 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
373 3. A list of tags identifying non-stuck projects.
374 If the project subtree contains any headline with one of these tags,
375 the project is considered to be not stuck. If you specify \"*\" as
376 a tag, any tag will mark the project unstuck.
377 4. An arbitrary regular expression matching non-stuck projects.
379 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
380 or `C-c a #' to produce the list."
381 :group 'org-agenda-custom-commands
382 :type '(list
383 (string :tag "Tags/TODO match to identify a project")
384 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
385 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
386 (regexp :tag "Projects are *not* stuck if this regexp matches\ninside the subtree")))
389 (defgroup org-agenda-skip nil
390 "Options concerning skipping parts of agenda files."
391 :tag "Org Agenda Skip"
392 :group 'org-agenda)
394 (defcustom org-agenda-todo-list-sublevels t
395 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
396 When nil, the sublevels of a TODO entry are not checked, resulting in
397 potentially much shorter TODO lists."
398 :group 'org-agenda-skip
399 :group 'org-todo
400 :type 'boolean)
402 (defcustom org-agenda-todo-ignore-with-date nil
403 "Non-nil means, don't show entries with a date in the global todo list.
404 You can use this if you prefer to mark mere appointments with a TODO keyword,
405 but don't want them to show up in the TODO list.
406 When this is set, it also covers deadlines and scheduled items, the settings
407 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
408 will be ignored."
409 :group 'org-agenda-skip
410 :group 'org-todo
411 :type 'boolean)
413 (defcustom org-agenda-todo-ignore-scheduled nil
414 "Non-nil means, don't show scheduled entries in the global todo list.
415 The idea behind this is that by scheduling it, you have already taken care
416 of this item.
417 See also `org-agenda-todo-ignore-with-date'."
418 :group 'org-agenda-skip
419 :group 'org-todo
420 :type 'boolean)
422 (defcustom org-agenda-todo-ignore-deadlines nil
423 "Non-nil means, don't show near deadline entries in the global todo list.
424 Near means closer than `org-deadline-warning-days' days.
425 The idea behind this is that such items will appear in the agenda anyway.
426 See also `org-agenda-todo-ignore-with-date'."
427 :group 'org-agenda-skip
428 :group 'org-todo
429 :type 'boolean)
431 (defcustom org-agenda-skip-scheduled-if-done nil
432 "Non-nil means don't show scheduled items in agenda when they are done.
433 This is relevant for the daily/weekly agenda, not for the TODO list. And
434 it applies only to the actual date of the scheduling. Warnings about
435 an item with a past scheduling dates are always turned off when the item
436 is DONE."
437 :group 'org-agenda-skip
438 :type 'boolean)
440 (defcustom org-agenda-skip-deadline-if-done nil
441 "Non-nil means don't show deadines when the corresponding item is done.
442 When nil, the deadline is still shown and should give you a happy feeling.
443 This is relevant for the daily/weekly agenda. And it applied only to the
444 actualy date of the deadline. Warnings about approching and past-due
445 deadlines are always turned off when the item is DONE."
446 :group 'org-agenda-skip
447 :type 'boolean)
449 (defcustom org-agenda-skip-timestamp-if-done nil
450 "Non-nil means don't select item by timestamp or -range if it is DONE."
451 :group 'org-agenda-skip
452 :type 'boolean)
454 (defcustom org-timeline-show-empty-dates 3
455 "Non-nil means, `org-timeline' also shows dates without an entry.
456 When nil, only the days which actually have entries are shown.
457 When t, all days between the first and the last date are shown.
458 When an integer, show also empty dates, but if there is a gap of more than
459 N days, just insert a special line indicating the size of the gap."
460 :group 'org-agenda-skip
461 :type '(choice
462 (const :tag "None" nil)
463 (const :tag "All" t)
464 (number :tag "at most")))
467 (defgroup org-agenda-startup nil
468 "Options concerning initial settings in the Agenda in Org Mode."
469 :tag "Org Agenda Startup"
470 :group 'org-agenda)
472 (defcustom org-finalize-agenda-hook nil
473 "Hook run just before displaying an agenda buffer."
474 :group 'org-agenda-startup
475 :type 'hook)
477 (defcustom org-agenda-mouse-1-follows-link nil
478 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
479 A longer mouse click will still set point. Does not work on XEmacs.
480 Needs to be set before org.el is loaded."
481 :group 'org-agenda-startup
482 :type 'boolean)
484 (defcustom org-agenda-start-with-follow-mode nil
485 "The initial value of follow-mode in a newly created agenda window."
486 :group 'org-agenda-startup
487 :type 'boolean)
489 (defgroup org-agenda-windows nil
490 "Options concerning the windows used by the Agenda in Org Mode."
491 :tag "Org Agenda Windows"
492 :group 'org-agenda)
494 (defcustom org-agenda-window-setup 'reorganize-frame
495 "How the agenda buffer should be displayed.
496 Possible values for this option are:
498 current-window Show agenda in the current window, keeping all other windows.
499 other-frame Use `switch-to-buffer-other-frame' to display agenda.
500 other-window Use `switch-to-buffer-other-window' to display agenda.
501 reorganize-frame Show only two windows on the current frame, the current
502 window and the agenda.
503 See also the variable `org-agenda-restore-windows-after-quit'."
504 :group 'org-agenda-windows
505 :type '(choice
506 (const current-window)
507 (const other-frame)
508 (const other-window)
509 (const reorganize-frame)))
511 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
512 "The min and max height of the agenda window as a fraction of frame height.
513 The value of the variable is a cons cell with two numbers between 0 and 1.
514 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
515 :group 'org-agenda-windows
516 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
518 (defcustom org-agenda-restore-windows-after-quit nil
519 "Non-nil means, restore window configuration open exiting agenda.
520 Before the window configuration is changed for displaying the agenda,
521 the current status is recorded. When the agenda is exited with
522 `q' or `x' and this option is set, the old state is restored. If
523 `org-agenda-window-setup' is `other-frame', the value of this
524 option will be ignored.."
525 :group 'org-agenda-windows
526 :type 'boolean)
528 (defgroup org-agenda-daily/weekly nil
529 "Options concerning the daily/weekly agenda."
530 :tag "Org Agenda Daily/Weekly"
531 :group 'org-agenda)
533 (defcustom org-agenda-ndays 7
534 "Number of days to include in overview display.
535 Should be 1 or 7."
536 :group 'org-agenda-daily/weekly
537 :type 'number)
539 (defcustom org-agenda-start-on-weekday 1
540 "Non-nil means, start the overview always on the specified weekday.
541 0 denotes Sunday, 1 denotes Monday etc.
542 When nil, always start on the current day."
543 :group 'org-agenda-daily/weekly
544 :type '(choice (const :tag "Today" nil)
545 (number :tag "Weekday No.")))
547 (defcustom org-agenda-show-all-dates t
548 "Non-nil means, `org-agenda' shows every day in the selected range.
549 When nil, only the days which actually have entries are shown."
550 :group 'org-agenda-daily/weekly
551 :type 'boolean)
553 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
554 "Format string for displaying dates in the agenda.
555 Used by the daily/weekly agenda and by the timeline. This should be
556 a format string understood by `format-time-string', or a function returning
557 the formatted date as a string. The function must take a single argument,
558 a calendar-style date list like (month day year)."
559 :group 'org-agenda-daily/weekly
560 :type '(choice
561 (string :tag "Format string")
562 (function :tag "Function")))
564 (defun org-agenda-format-date-aligned (date)
565 "Format a date string for display in the daily/weekly agenda, or timeline.
566 This function makes sure that dates are aligned for easy reading."
567 (require 'cal-iso)
568 (let* ((dayname (calendar-day-name date))
569 (day (extract-calendar-day date))
570 (day-of-week (calendar-day-of-week date))
571 (month (extract-calendar-month date))
572 (monthname (calendar-month-name month))
573 (year (extract-calendar-year date))
574 (iso-week (org-days-to-iso-week
575 (calendar-absolute-from-gregorian date)))
576 (weekyear (cond ((and (= month 1) (>= iso-week 52))
577 (1- year))
578 ((and (= month 12) (<= iso-week 1))
579 (1+ year))
580 (t year)))
581 (weekstring (if (= day-of-week 1)
582 (format " W%02d" iso-week)
583 "")))
584 (format "%-10s %2d %s %4d%s"
585 dayname day monthname year weekstring)))
587 (defcustom org-agenda-include-diary nil
588 "If non-nil, include in the agenda entries from the Emacs Calendar's diary."
589 :group 'org-agenda-daily/weekly
590 :type 'boolean)
592 (defcustom org-agenda-include-all-todo nil
593 "Set means weekly/daily agenda will always contain all TODO entries.
594 The TODO entries will be listed at the top of the agenda, before
595 the entries for specific days."
596 :group 'org-agenda-daily/weekly
597 :type 'boolean)
599 (defcustom org-agenda-repeating-timestamp-show-all t
600 "Non-nil means, show all occurences of a repeating stamp in the agenda.
601 When nil, only one occurence is shown, either today or the
602 nearest into the future."
603 :group 'org-agenda-daily/weekly
604 :type 'boolean)
606 (defcustom org-scheduled-past-days 10000
607 "No. of days to continue listing scheduled items that are not marked DONE.
608 When an item is scheduled on a date, it shows up in the agenda on this
609 day and will be listed until it is marked done for the number of days
610 given here."
611 :group 'org-agenda-daily/weekly
612 :type 'number)
614 (defcustom org-agenda-start-with-clockreport-mode nil
615 "The initial value of clockreport-mode in a newly created agenda window."
616 :group 'org-agenda-startup
617 :group 'org-agenda-daily/weekly
618 :type 'boolean)
620 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
621 "Property list with parameters for the clocktable in clockreport mode.
622 This is the display mode that shows a clock table in the daily/weekly
623 agenda, the properties for this dynamic block can be set here.
624 The usual clocktable parameters are allowed here, but you cannot set
625 the properties :name, :tstart, :tend, :block, and :scope - these will
626 be overwritten to make sure the content accurately reflects the
627 current display in the agenda."
628 :group 'org-agenda-daily/weekly
629 :type 'plist)
632 (defgroup org-agenda-time-grid nil
633 "Options concerning the time grid in the Org-mode Agenda."
634 :tag "Org Agenda Time Grid"
635 :group 'org-agenda)
637 (defcustom org-agenda-use-time-grid t
638 "Non-nil means, show a time grid in the agenda schedule.
639 A time grid is a set of lines for specific times (like every two hours between
640 8:00 and 20:00). The items scheduled for a day at specific times are
641 sorted in between these lines.
642 For details about when the grid will be shown, and what it will look like, see
643 the variable `org-agenda-time-grid'."
644 :group 'org-agenda-time-grid
645 :type 'boolean)
647 (defcustom org-agenda-time-grid
648 '((daily today require-timed)
649 "----------------"
650 (800 1000 1200 1400 1600 1800 2000))
652 "The settings for time grid for agenda display.
653 This is a list of three items. The first item is again a list. It contains
654 symbols specifying conditions when the grid should be displayed:
656 daily if the agenda shows a single day
657 weekly if the agenda shows an entire week
658 today show grid on current date, independent of daily/weekly display
659 require-timed show grid only if at least one item has a time specification
661 The second item is a string which will be places behing the grid time.
663 The third item is a list of integers, indicating the times that should have
664 a grid line."
665 :group 'org-agenda-time-grid
666 :type
667 '(list
668 (set :greedy t :tag "Grid Display Options"
669 (const :tag "Show grid in single day agenda display" daily)
670 (const :tag "Show grid in weekly agenda display" weekly)
671 (const :tag "Always show grid for today" today)
672 (const :tag "Show grid only if any timed entries are present"
673 require-timed)
674 (const :tag "Skip grid times already present in an entry"
675 remove-match))
676 (string :tag "Grid String")
677 (repeat :tag "Grid Times" (integer :tag "Time"))))
679 (defgroup org-agenda-sorting nil
680 "Options concerning sorting in the Org-mode Agenda."
681 :tag "Org Agenda Sorting"
682 :group 'org-agenda)
684 (defcustom org-agenda-sorting-strategy
685 '((agenda time-up category-keep priority-down)
686 (todo category-keep priority-down)
687 (tags category-keep priority-down)
688 (search category-keep))
689 "Sorting structure for the agenda items of a single day.
690 This is a list of symbols which will be used in sequence to determine
691 if an entry should be listed before another entry. The following
692 symbols are recognized:
694 time-up Put entries with time-of-day indications first, early first
695 time-down Put entries with time-of-day indications first, late first
696 category-keep Keep the default order of categories, corresponding to the
697 sequence in `org-agenda-files'.
698 category-up Sort alphabetically by category, A-Z.
699 category-down Sort alphabetically by category, Z-A.
700 tag-up Sort alphabetically by last tag, A-Z.
701 tag-down Sort alphabetically by last tag, Z-A.
702 priority-up Sort numerically by priority, high priority last.
703 priority-down Sort numerically by priority, high priority first.
705 The different possibilities will be tried in sequence, and testing stops
706 if one comparison returns a \"not-equal\". For example, the default
707 '(time-up category-keep priority-down)
708 means: Pull out all entries having a specified time of day and sort them,
709 in order to make a time schedule for the current day the first thing in the
710 agenda listing for the day. Of the entries without a time indication, keep
711 the grouped in categories, don't sort the categories, but keep them in
712 the sequence given in `org-agenda-files'. Within each category sort by
713 priority.
715 Leaving out `category-keep' would mean that items will be sorted across
716 categories by priority.
718 Instead of a single list, this can also be a set of list for specific
719 contents, with a context symbol in the car of the list, any of
720 `agenda', `todo', `tags' for the corresponding agenda views."
721 :group 'org-agenda-sorting
722 :type `(choice
723 (repeat :tag "General" ,org-sorting-choice)
724 (list :tag "Individually"
725 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
726 (repeat ,org-sorting-choice))
727 (cons (const :tag "Strategy for TODO lists" todo)
728 (repeat ,org-sorting-choice))
729 (cons (const :tag "Strategy for Tags matches" tags)
730 (repeat ,org-sorting-choice)))))
732 (defcustom org-sort-agenda-notime-is-late t
733 "Non-nil means, items without time are considered late.
734 This is only relevant for sorting. When t, items which have no explicit
735 time like 15:30 will be considered as 99:01, i.e. later than any items which
736 do have a time. When nil, the default time is before 0:00. You can use this
737 option to decide if the schedule for today should come before or after timeless
738 agenda entries."
739 :group 'org-agenda-sorting
740 :type 'boolean)
742 (defgroup org-agenda-line-format nil
743 "Options concerning the entry prefix in the Org-mode agenda display."
744 :tag "Org Agenda Line Format"
745 :group 'org-agenda)
747 (defcustom org-agenda-prefix-format
748 '((agenda . " %-12:c%?-12t% s")
749 (timeline . " % s")
750 (todo . " %-12:c")
751 (tags . " %-12:c")
752 (search . " %-12:c"))
753 "Format specifications for the prefix of items in the agenda views.
754 An alist with four entries, for the different agenda types. The keys to the
755 sublists are `agenda', `timeline', `todo', and `tags'. The values
756 are format strings.
757 This format works similar to a printf format, with the following meaning:
759 %c the category of the item, \"Diary\" for entries from the diary, or
760 as given by the CATEGORY keyword or derived from the file name.
761 %T the *last* tag of the item. Last because inherited tags come
762 first in the list.
763 %t the time-of-day specification if one applies to the entry, in the
764 format HH:MM
765 %s Scheduling/Deadline information, a short string
767 All specifiers work basically like the standard `%s' of printf, but may
768 contain two additional characters: A question mark just after the `%' and
769 a whitespace/punctuation character just before the final letter.
771 If the first character after `%' is a question mark, the entire field
772 will only be included if the corresponding value applies to the
773 current entry. This is useful for fields which should have fixed
774 width when present, but zero width when absent. For example,
775 \"%?-12t\" will result in a 12 character time field if a time of the
776 day is specified, but will completely disappear in entries which do
777 not contain a time.
779 If there is punctuation or whitespace character just before the final
780 format letter, this character will be appended to the field value if
781 the value is not empty. For example, the format \"%-12:c\" leads to
782 \"Diary: \" if the category is \"Diary\". If the category were be
783 empty, no additional colon would be interted.
785 The default value of this option is \" %-12:c%?-12t% s\", meaning:
786 - Indent the line with two space characters
787 - Give the category in a 12 chars wide field, padded with whitespace on
788 the right (because of `-'). Append a colon if there is a category
789 (because of `:').
790 - If there is a time-of-day, put it into a 12 chars wide field. If no
791 time, don't put in an empty field, just skip it (because of '?').
792 - Finally, put the scheduling information and append a whitespace.
794 As another example, if you don't want the time-of-day of entries in
795 the prefix, you could use:
797 (setq org-agenda-prefix-format \" %-11:c% s\")
799 See also the variables `org-agenda-remove-times-when-in-prefix' and
800 `org-agenda-remove-tags'."
801 :type '(choice
802 (string :tag "General format")
803 (list :greedy t :tag "View dependent"
804 (cons (const agenda) (string :tag "Format"))
805 (cons (const timeline) (string :tag "Format"))
806 (cons (const todo) (string :tag "Format"))
807 (cons (const tags) (string :tag "Format"))
808 (cons (const search) (string :tag "Format"))))
809 :group 'org-agenda-line-format)
811 (defvar org-prefix-format-compiled nil
812 "The compiled version of the most recently used prefix format.
813 See the variable `org-agenda-prefix-format'.")
815 (defcustom org-agenda-todo-keyword-format "%-1s"
816 "Format for the TODO keyword in agenda lines.
817 Set this to something like \"%-12s\" if you want all TODO keywords
818 to occupy a fixed space in the agenda display."
819 :group 'org-agenda-line-format
820 :type 'string)
822 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
823 "Text preceeding scheduled items in the agenda view.
824 This is a list with two strings. The first applies when the item is
825 scheduled on the current day. The second applies when it has been scheduled
826 previously, it may contain a %d to capture how many days ago the item was
827 scheduled."
828 :group 'org-agenda-line-format
829 :type '(list
830 (string :tag "Scheduled today ")
831 (string :tag "Scheduled previously")))
833 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
834 "Text preceeding deadline items in the agenda view.
835 This is a list with two strings. The first applies when the item has its
836 deadline on the current day. The second applies when it is in the past or
837 in the future, it may contain %d to capture how many days away the deadline
838 is (was)."
839 :group 'org-agenda-line-format
840 :type '(list
841 (string :tag "Deadline today ")
842 (choice :tag "Deadline relative"
843 (string :tag "Format string")
844 (function))))
846 (defcustom org-agenda-remove-times-when-in-prefix t
847 "Non-nil means, remove duplicate time specifications in agenda items.
848 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
849 time-of-day specification in a headline or diary entry is extracted and
850 placed into the prefix. If this option is non-nil, the original specification
851 \(a timestamp or -range, or just a plain time(range) specification like
852 11:30-4pm) will be removed for agenda display. This makes the agenda less
853 cluttered.
854 The option can be t or nil. It may also be the symbol `beg', indicating
855 that the time should only be removed what it is located at the beginning of
856 the headline/diary entry."
857 :group 'org-agenda-line-format
858 :type '(choice
859 (const :tag "Always" t)
860 (const :tag "Never" nil)
861 (const :tag "When at beginning of entry" beg)))
864 (defcustom org-agenda-default-appointment-duration nil
865 "Default duration for appointments that only have a starting time.
866 When nil, no duration is specified in such cases.
867 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
868 :group 'org-agenda-line-format
869 :type '(choice
870 (integer :tag "Minutes")
871 (const :tag "No default duration")))
874 (defcustom org-agenda-remove-tags nil
875 "Non-nil means, remove the tags from the headline copy in the agenda.
876 When this is the symbol `prefix', only remove tags when
877 `org-agenda-prefix-format' contains a `%T' specifier."
878 :group 'org-agenda-line-format
879 :type '(choice
880 (const :tag "Always" t)
881 (const :tag "Never" nil)
882 (const :tag "When prefix format contains %T" prefix)))
884 (if (fboundp 'defvaralias)
885 (defvaralias 'org-agenda-remove-tags-when-in-prefix
886 'org-agenda-remove-tags))
888 (defcustom org-agenda-tags-column -80
889 "Shift tags in agenda items to this column.
890 If this number is positive, it specifies the column. If it is negative,
891 it means that the tags should be flushright to that column. For example,
892 -80 works well for a normal 80 character screen."
893 :group 'org-agenda-line-format
894 :type 'integer)
896 (if (fboundp 'defvaralias)
897 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
899 (defcustom org-agenda-fontify-priorities t
900 "Non-nil means, highlight low and high priorities in agenda.
901 When t, the highest priority entries are bold, lowest priority italic.
902 This may also be an association list of priority faces. The face may be
903 a names face, or a list like `(:background \"Red\")'."
904 :group 'org-agenda-line-format
905 :type '(choice
906 (const :tag "Never" nil)
907 (const :tag "Defaults" t)
908 (repeat :tag "Specify"
909 (list (character :tag "Priority" :value ?A)
910 (sexp :tag "face")))))
913 (eval-when-compile
914 (require 'cl))
915 (require 'org)
927 (defun org-add-agenda-custom-command (entry)
928 "Replace or add a command in `org-agenda-custom-commands'.
929 This is mostly for hacking and trying a new command - once the command
930 works you probably want to add it to `org-agenda-custom-commands' for good."
931 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
932 (if ass
933 (setcdr ass (cdr entry))
934 (push entry org-agenda-custom-commands))))
936 ;;; Define the Org-agenda-mode
938 (defvar org-agenda-mode-map (make-sparse-keymap)
939 "Keymap for `org-agenda-mode'.")
941 (defvar org-agenda-menu) ; defined later in this file.
942 (defvar org-agenda-follow-mode nil)
943 (defvar org-agenda-clockreport-mode nil)
944 (defvar org-agenda-show-log nil)
945 (defvar org-agenda-redo-command nil)
946 (defvar org-agenda-query-string nil)
947 (defvar org-agenda-mode-hook nil)
948 (defvar org-agenda-type nil)
949 (defvar org-agenda-force-single-file nil)
951 (defun org-agenda-mode ()
952 "Mode for time-sorted view on action items in Org-mode files.
954 The following commands are available:
956 \\{org-agenda-mode-map}"
957 (interactive)
958 (kill-all-local-variables)
959 (setq org-agenda-undo-list nil
960 org-agenda-pending-undo-list nil)
961 (setq major-mode 'org-agenda-mode)
962 ;; Keep global-font-lock-mode from turning on font-lock-mode
963 (org-set-local 'font-lock-global-modes (list 'not major-mode))
964 (setq mode-name "Org-Agenda")
965 (use-local-map org-agenda-mode-map)
966 (easy-menu-add org-agenda-menu)
967 (if org-startup-truncated (setq truncate-lines t))
968 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
969 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
970 ;; Make sure properties are removed when copying text
971 (when (boundp 'buffer-substring-filters)
972 (org-set-local 'buffer-substring-filters
973 (cons (lambda (x)
974 (set-text-properties 0 (length x) nil x) x)
975 buffer-substring-filters)))
976 (unless org-agenda-keep-modes
977 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
978 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
979 org-agenda-show-log nil))
980 (easy-menu-change
981 '("Agenda") "Agenda Files"
982 (append
983 (list
984 (vector
985 (if (get 'org-agenda-files 'org-restrict)
986 "Restricted to single file"
987 "Edit File List")
988 '(org-edit-agenda-file-list)
989 (not (get 'org-agenda-files 'org-restrict)))
990 "--")
991 (mapcar 'org-file-menu-entry (org-agenda-files))))
992 (org-agenda-set-mode-name)
993 (apply
994 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
995 (list 'org-agenda-mode-hook)))
997 (substitute-key-definition 'undo 'org-agenda-undo
998 org-agenda-mode-map global-map)
999 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1000 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1001 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1002 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1003 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1004 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1005 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1006 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1007 (org-defkey org-agenda-mode-map " " 'org-agenda-show)
1008 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1009 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1010 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1011 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1012 (org-defkey org-agenda-mode-map "b" 'org-agenda-tree-to-indirect-buffer)
1013 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1014 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1015 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1016 (org-defkey org-agenda-mode-map "a" 'org-agenda-toggle-archive-tag)
1017 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1018 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1019 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1020 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1021 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1022 (org-defkey org-agenda-mode-map "m" 'org-agenda-month-view)
1023 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1024 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1025 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1026 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-date-later)
1027 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-date-earlier)
1028 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-date-later)
1029 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-date-earlier)
1031 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1032 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1033 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1034 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1035 (while l (org-defkey org-agenda-mode-map
1036 (int-to-string (pop l)) 'digit-argument)))
1038 (org-defkey org-agenda-mode-map "f" 'org-agenda-follow-mode)
1039 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1040 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1041 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1042 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1043 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1044 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1045 (org-defkey org-agenda-mode-map "e" 'org-agenda-execute)
1046 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1047 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1048 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1049 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1050 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1051 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1052 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1053 (org-defkey org-agenda-mode-map "n" 'next-line)
1054 (org-defkey org-agenda-mode-map "p" 'previous-line)
1055 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1056 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1057 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1058 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1059 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1060 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1061 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1062 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1063 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1064 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1065 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1066 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1067 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1068 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1069 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1070 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1071 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1072 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1073 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1074 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1075 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1076 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1077 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1078 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1079 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1080 (org-defkey org-agenda-mode-map [(right)] 'org-agenda-later)
1081 (org-defkey org-agenda-mode-map [(left)] 'org-agenda-earlier)
1082 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1084 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1085 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1086 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1087 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1089 (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
1090 "Local keymap for agenda entries from Org-mode.")
1092 (org-defkey org-agenda-keymap
1093 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1094 (org-defkey org-agenda-keymap
1095 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1096 (when org-agenda-mouse-1-follows-link
1097 (org-defkey org-agenda-keymap [follow-link] 'mouse-face))
1098 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1099 '("Agenda"
1100 ("Agenda Files")
1101 "--"
1102 ["Show" org-agenda-show t]
1103 ["Go To (other window)" org-agenda-goto t]
1104 ["Go To (this window)" org-agenda-switch-to t]
1105 ["Follow Mode" org-agenda-follow-mode
1106 :style toggle :selected org-agenda-follow-mode :active t]
1107 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1108 "--"
1109 ["Cycle TODO" org-agenda-todo t]
1110 ["Archive subtree" org-agenda-archive t]
1111 ["Delete subtree" org-agenda-kill t]
1112 ["Add note" org-agenda-add-note t]
1113 "--"
1114 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1115 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1116 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1117 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)]
1118 "--"
1119 ("Tags and Properties"
1120 ["Show all Tags" org-agenda-show-tags t]
1121 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1122 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1123 "--"
1124 ["Column View" org-columns t])
1125 ("Date/Schedule"
1126 ["Schedule" org-agenda-schedule t]
1127 ["Set Deadline" org-agenda-deadline t]
1128 "--"
1129 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1130 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1131 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1132 ("Clock"
1133 ["Clock in" org-agenda-clock-in t]
1134 ["Clock out" org-agenda-clock-out t]
1135 ["Clock cancel" org-agenda-clock-cancel t]
1136 ["Goto running clock" org-clock-goto t])
1137 ("Priority"
1138 ["Set Priority" org-agenda-priority t]
1139 ["Increase Priority" org-agenda-priority-up t]
1140 ["Decrease Priority" org-agenda-priority-down t]
1141 ["Show Priority" org-agenda-show-priority t])
1142 ("Calendar/Diary"
1143 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1144 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1145 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1146 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1147 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1148 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1149 "--"
1150 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t])
1151 "--"
1152 ("View"
1153 ["Day View" org-agenda-day-view :active (org-agenda-check-type nil 'agenda)
1154 :style radio :selected (equal org-agenda-ndays 1)]
1155 ["Week View" org-agenda-week-view :active (org-agenda-check-type nil 'agenda)
1156 :style radio :selected (equal org-agenda-ndays 7)]
1157 ["Month View" org-agenda-month-view :active (org-agenda-check-type nil 'agenda)
1158 :style radio :selected (member org-agenda-ndays '(28 29 30 31))]
1159 ["Year View" org-agenda-year-view :active (org-agenda-check-type nil 'agenda)
1160 :style radio :selected (member org-agenda-ndays '(365 366))]
1161 "--"
1162 ["Show Logbook entries" org-agenda-log-mode
1163 :style toggle :selected org-agenda-show-log :active (org-agenda-check-type nil 'agenda 'timeline)]
1164 ["Show clock report" org-agenda-clockreport-mode
1165 :style toggle :selected org-agenda-clockreport-mode :active (org-agenda-check-type nil 'agenda)]
1166 ["Include Diary" org-agenda-toggle-diary
1167 :style toggle :selected org-agenda-include-diary :active (org-agenda-check-type nil 'agenda)]
1168 ["Use Time Grid" org-agenda-toggle-time-grid
1169 :style toggle :selected org-agenda-use-time-grid :active (org-agenda-check-type nil 'agenda)])
1170 ["Write view to file" org-write-agenda t]
1171 ["Rebuild buffer" org-agenda-redo t]
1172 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1173 "--"
1174 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1175 "--"
1176 ["Quit" org-agenda-quit t]
1177 ["Exit and Release Buffers" org-agenda-exit t]
1180 ;;; Agenda undo
1182 (defvar org-agenda-allow-remote-undo t
1183 "Non-nil means, allow remote undo from the agenda buffer.")
1184 (defvar org-agenda-undo-list nil
1185 "List of undoable operations in the agenda since last refresh.")
1186 (defvar org-agenda-undo-has-started-in nil
1187 "Buffers that have already seen `undo-start' in the current undo sequence.")
1188 (defvar org-agenda-pending-undo-list nil
1189 "In a series of undo commands, this is the list of remaning undo items.")
1192 (defun org-agenda-undo ()
1193 "Undo a remote editing step in the agenda.
1194 This undoes changes both in the agenda buffer and in the remote buffer
1195 that have been changed along."
1196 (interactive)
1197 (or org-agenda-allow-remote-undo
1198 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1199 (if (not (eq this-command last-command))
1200 (setq org-agenda-undo-has-started-in nil
1201 org-agenda-pending-undo-list org-agenda-undo-list))
1202 (if (not org-agenda-pending-undo-list)
1203 (error "No further undo information"))
1204 (let* ((entry (pop org-agenda-pending-undo-list))
1205 buf line cmd rembuf)
1206 (setq cmd (pop entry) line (pop entry))
1207 (setq rembuf (nth 2 entry))
1208 (org-with-remote-undo rembuf
1209 (while (bufferp (setq buf (pop entry)))
1210 (if (pop entry)
1211 (with-current-buffer buf
1212 (let ((last-undo-buffer buf)
1213 (inhibit-read-only t))
1214 (unless (memq buf org-agenda-undo-has-started-in)
1215 (push buf org-agenda-undo-has-started-in)
1216 (make-local-variable 'pending-undo-list)
1217 (undo-start))
1218 (while (and pending-undo-list
1219 (listp pending-undo-list)
1220 (not (car pending-undo-list)))
1221 (pop pending-undo-list))
1222 (undo-more 1))))))
1223 (goto-line line)
1224 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1226 (defun org-verify-change-for-undo (l1 l2)
1227 "Verify that a real change occurred between the undo lists L1 and L2."
1228 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1229 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1230 (not (eq l1 l2)))
1232 ;;; Agenda dispatch
1234 (defvar org-agenda-restrict nil)
1235 (defvar org-agenda-restrict-begin (make-marker))
1236 (defvar org-agenda-restrict-end (make-marker))
1237 (defvar org-agenda-last-dispatch-buffer nil)
1238 (defvar org-agenda-overriding-restriction nil)
1240 ;;;###autoload
1241 (defun org-agenda (arg &optional keys restriction)
1242 "Dispatch agenda commands to collect entries to the agenda buffer.
1243 Prompts for a command to execute. Any prefix arg will be passed
1244 on to the selected command. The default selections are:
1246 a Call `org-agenda-list' to display the agenda for current day or week.
1247 t Call `org-todo-list' to display the global todo list.
1248 T Call `org-todo-list' to display the global todo list, select only
1249 entries with a specific TODO keyword (the user gets a prompt).
1250 m Call `org-tags-view' to display headlines with tags matching
1251 a condition (the user is prompted for the condition).
1252 M Like `m', but select only TODO entries, no ordinary headlines.
1253 L Create a timeline for the current buffer.
1254 e Export views to associated files.
1256 More commands can be added by configuring the variable
1257 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1258 searches can be pre-defined in this way.
1260 If the current buffer is in Org-mode and visiting a file, you can also
1261 first press `<' once to indicate that the agenda should be temporarily
1262 \(until the next use of \\[org-agenda]) restricted to the current file.
1263 Pressing `<' twice means to restrict to the current subtree or region
1264 \(if active)."
1265 (interactive "P")
1266 (catch 'exit
1267 (let* ((prefix-descriptions nil)
1268 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1269 (org-agenda-custom-commands
1270 ;; normalize different versions
1271 (delq nil
1272 (mapcar
1273 (lambda (x)
1274 (cond ((stringp (cdr x))
1275 (push x prefix-descriptions)
1276 nil)
1277 ((stringp (nth 1 x)) x)
1278 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1279 (t (cons (car x) (cons "" (cdr x))))))
1280 org-agenda-custom-commands)))
1281 (buf (current-buffer))
1282 (bfn (buffer-file-name (buffer-base-buffer)))
1283 entry key type match lprops ans)
1284 ;; Turn off restriction unless there is an overriding one
1285 (unless org-agenda-overriding-restriction
1286 (put 'org-agenda-files 'org-restrict nil)
1287 (setq org-agenda-restrict nil)
1288 (move-marker org-agenda-restrict-begin nil)
1289 (move-marker org-agenda-restrict-end nil))
1290 ;; Delete old local properties
1291 (put 'org-agenda-redo-command 'org-lprops nil)
1292 ;; Remember where this call originated
1293 (setq org-agenda-last-dispatch-buffer (current-buffer))
1294 (unless keys
1295 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1296 keys (car ans)
1297 restriction (cdr ans)))
1298 ;; Estabish the restriction, if any
1299 (when (and (not org-agenda-overriding-restriction) restriction)
1300 (put 'org-agenda-files 'org-restrict (list bfn))
1301 (cond
1302 ((eq restriction 'region)
1303 (setq org-agenda-restrict t)
1304 (move-marker org-agenda-restrict-begin (region-beginning))
1305 (move-marker org-agenda-restrict-end (region-end)))
1306 ((eq restriction 'subtree)
1307 (save-excursion
1308 (setq org-agenda-restrict t)
1309 (org-back-to-heading t)
1310 (move-marker org-agenda-restrict-begin (point))
1311 (move-marker org-agenda-restrict-end
1312 (progn (org-end-of-subtree t)))))))
1314 (require 'calendar) ; FIXME: can we avoid this for some commands?
1315 ;; For example the todo list should not need it (but does...)
1316 (cond
1317 ((setq entry (assoc keys org-agenda-custom-commands))
1318 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1319 (progn
1320 (setq type (nth 2 entry) match (nth 3 entry) lprops (nth 4 entry))
1321 (put 'org-agenda-redo-command 'org-lprops lprops)
1322 (cond
1323 ((eq type 'agenda)
1324 (org-let lprops '(org-agenda-list current-prefix-arg)))
1325 ((eq type 'alltodo)
1326 (org-let lprops '(org-todo-list current-prefix-arg)))
1327 ((eq type 'search)
1328 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1329 ((eq type 'stuck)
1330 (org-let lprops '(org-agenda-list-stuck-projects
1331 current-prefix-arg)))
1332 ((eq type 'tags)
1333 (org-let lprops '(org-tags-view current-prefix-arg match)))
1334 ((eq type 'tags-todo)
1335 (org-let lprops '(org-tags-view '(4) match)))
1336 ((eq type 'todo)
1337 (org-let lprops '(org-todo-list match)))
1338 ((eq type 'tags-tree)
1339 (org-check-for-org-mode)
1340 (org-let lprops '(org-tags-sparse-tree current-prefix-arg match)))
1341 ((eq type 'todo-tree)
1342 (org-check-for-org-mode)
1343 (org-let lprops
1344 '(org-occur (concat "^" outline-regexp "[ \t]*"
1345 (regexp-quote match) "\\>"))))
1346 ((eq type 'occur-tree)
1347 (org-check-for-org-mode)
1348 (org-let lprops '(org-occur match)))
1349 ((functionp type)
1350 (org-let lprops '(funcall type match)))
1351 ((fboundp type)
1352 (org-let lprops '(funcall type match)))
1353 (t (error "Invalid custom agenda command type %s" type))))
1354 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1355 ((equal keys "C")
1356 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1357 (customize-variable 'org-agenda-custom-commands))
1358 ((equal keys "a") (call-interactively 'org-agenda-list))
1359 ((equal keys "s") (call-interactively 'org-search-view))
1360 ((equal keys "t") (call-interactively 'org-todo-list))
1361 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1362 ((equal keys "m") (call-interactively 'org-tags-view))
1363 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1364 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1365 ((equal keys "L")
1366 (unless (org-mode-p)
1367 (error "This is not an Org-mode file"))
1368 (unless restriction
1369 (put 'org-agenda-files 'org-restrict (list bfn))
1370 (org-call-with-arg 'org-timeline arg)))
1371 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1372 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1373 ((equal keys "!") (customize-variable 'org-stuck-projects))
1374 (t (error "Invalid agenda key"))))))
1376 (defun org-agenda-normalize-custom-commands (cmds)
1377 (delq nil
1378 (mapcar
1379 (lambda (x)
1380 (cond ((stringp (cdr x)) nil)
1381 ((stringp (nth 1 x)) x)
1382 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1383 (t (cons (car x) (cons "" (cdr x))))))
1384 cmds)))
1386 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1387 "The user interface for selecting an agenda command."
1388 (catch 'exit
1389 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1390 (restrict-ok (and bfn (org-mode-p)))
1391 (region-p (org-region-active-p))
1392 (custom org-agenda-custom-commands)
1393 (selstring "")
1394 restriction second-time
1395 c entry key type match prefixes rmheader header-end custom1 desc)
1396 (save-window-excursion
1397 (delete-other-windows)
1398 (org-switch-to-buffer-other-window " *Agenda Commands*")
1399 (erase-buffer)
1400 (insert (eval-when-compile
1401 (let ((header
1403 Press key for an agenda command: < Buffer,subtree/region restriction
1404 -------------------------------- > Remove restriction
1405 a Agenda for current week or day e Export agenda views
1406 t List of all TODO entries T Entries with special TODO kwd
1407 m Match a TAGS query M Like m, but only TODO entries
1408 L Timeline for current buffer # List stuck projects (!=configure)
1409 s Search for keywords C Configure custom agenda commands
1410 / Multi-occur
1412 (start 0))
1413 (while (string-match
1414 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1415 header start)
1416 (setq start (match-end 0))
1417 (add-text-properties (match-beginning 2) (match-end 2)
1418 '(face bold) header))
1419 header)))
1420 (setq header-end (move-marker (make-marker) (point)))
1421 (while t
1422 (setq custom1 custom)
1423 (when (eq rmheader t)
1424 (goto-line 1)
1425 (re-search-forward ":" nil t)
1426 (delete-region (match-end 0) (point-at-eol))
1427 (forward-char 1)
1428 (looking-at "-+")
1429 (delete-region (match-end 0) (point-at-eol))
1430 (move-marker header-end (match-end 0)))
1431 (goto-char header-end)
1432 (delete-region (point) (point-max))
1433 (while (setq entry (pop custom1))
1434 (setq key (car entry) desc (nth 1 entry)
1435 type (nth 2 entry) match (nth 3 entry))
1436 (if (> (length key) 1)
1437 (add-to-list 'prefixes (string-to-char key))
1438 (insert
1439 (format
1440 "\n%-4s%-14s: %s"
1441 (org-add-props (copy-sequence key)
1442 '(face bold))
1443 (cond
1444 ((string-match "\\S-" desc) desc)
1445 ((eq type 'agenda) "Agenda for current week or day")
1446 ((eq type 'alltodo) "List of all TODO entries")
1447 ((eq type 'search) "Word search")
1448 ((eq type 'stuck) "List of stuck projects")
1449 ((eq type 'todo) "TODO keyword")
1450 ((eq type 'tags) "Tags query")
1451 ((eq type 'tags-todo) "Tags (TODO)")
1452 ((eq type 'tags-tree) "Tags tree")
1453 ((eq type 'todo-tree) "TODO kwd tree")
1454 ((eq type 'occur-tree) "Occur tree")
1455 ((functionp type) (if (symbolp type)
1456 (symbol-name type)
1457 "Lambda expression"))
1458 (t "???"))
1459 (cond
1460 ((stringp match)
1461 (org-add-props match nil 'face 'org-warning))
1462 (match
1463 (format "set of %d commands" (length match)))
1464 (t ""))))))
1465 (when prefixes
1466 (mapc (lambda (x)
1467 (insert
1468 (format "\n%s %s"
1469 (org-add-props (char-to-string x)
1470 nil 'face 'bold)
1471 (or (cdr (assoc (concat selstring (char-to-string x))
1472 prefix-descriptions))
1473 "Prefix key"))))
1474 prefixes))
1475 (goto-char (point-min))
1476 (when (fboundp 'fit-window-to-buffer)
1477 (if second-time
1478 (if (not (pos-visible-in-window-p (point-max)))
1479 (fit-window-to-buffer))
1480 (setq second-time t)
1481 (fit-window-to-buffer)))
1482 (message "Press key for agenda command%s:"
1483 (if (or restrict-ok org-agenda-overriding-restriction)
1484 (if org-agenda-overriding-restriction
1485 " (restriction lock active)"
1486 (if restriction
1487 (format " (restricted to %s)" restriction)
1488 " (unrestricted)"))
1489 ""))
1490 (setq c (read-char-exclusive))
1491 (message "")
1492 (cond
1493 ((assoc (char-to-string c) custom)
1494 (setq selstring (concat selstring (char-to-string c)))
1495 (throw 'exit (cons selstring restriction)))
1496 ((memq c prefixes)
1497 (setq selstring (concat selstring (char-to-string c))
1498 prefixes nil
1499 rmheader (or rmheader t)
1500 custom (delq nil (mapcar
1501 (lambda (x)
1502 (if (or (= (length (car x)) 1)
1503 (/= (string-to-char (car x)) c))
1505 (cons (substring (car x) 1) (cdr x))))
1506 custom))))
1507 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
1508 (message "Restriction is only possible in Org-mode buffers")
1509 (ding) (sit-for 1))
1510 ((eq c ?1)
1511 (org-agenda-remove-restriction-lock 'noupdate)
1512 (setq restriction 'buffer))
1513 ((eq c ?0)
1514 (org-agenda-remove-restriction-lock 'noupdate)
1515 (setq restriction (if region-p 'region 'subtree)))
1516 ((eq c ?<)
1517 (org-agenda-remove-restriction-lock 'noupdate)
1518 (setq restriction
1519 (cond
1520 ((eq restriction 'buffer)
1521 (if region-p 'region 'subtree))
1522 ((memq restriction '(subtree region))
1523 nil)
1524 (t 'buffer))))
1525 ((eq c ?>)
1526 (org-agenda-remove-restriction-lock 'noupdate)
1527 (setq restriction nil))
1528 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/)))
1529 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
1530 ((and (> (length selstring) 0) (eq c ?\d))
1531 (delete-window)
1532 (org-agenda-get-restriction-and-command prefix-descriptions))
1534 ((equal c ?q) (error "Abort"))
1535 (t (error "Invalid key %c" c))))))))
1537 (defun org-run-agenda-series (name series)
1538 (org-prepare-agenda name)
1539 (let* ((org-agenda-multi t)
1540 (redo (list 'org-run-agenda-series name (list 'quote series)))
1541 (cmds (car series))
1542 (gprops (nth 1 series))
1543 match ;; The byte compiler incorrectly complains about this. Keep it!
1544 cmd type lprops)
1545 (while (setq cmd (pop cmds))
1546 (setq type (car cmd) match (nth 1 cmd) lprops (nth 2 cmd))
1547 (cond
1548 ((eq type 'agenda)
1549 (org-let2 gprops lprops
1550 '(call-interactively 'org-agenda-list)))
1551 ((eq type 'alltodo)
1552 (org-let2 gprops lprops
1553 '(call-interactively 'org-todo-list)))
1554 ((eq type 'search)
1555 (org-let2 gprops lprops
1556 '(org-search-view current-prefix-arg match nil)))
1557 ((eq type 'stuck)
1558 (org-let2 gprops lprops
1559 '(call-interactively 'org-agenda-list-stuck-projects)))
1560 ((eq type 'tags)
1561 (org-let2 gprops lprops
1562 '(org-tags-view current-prefix-arg match)))
1563 ((eq type 'tags-todo)
1564 (org-let2 gprops lprops
1565 '(org-tags-view '(4) match)))
1566 ((eq type 'todo)
1567 (org-let2 gprops lprops
1568 '(org-todo-list match)))
1569 ((fboundp type)
1570 (org-let2 gprops lprops
1571 '(funcall type match)))
1572 (t (error "Invalid type in command series"))))
1573 (widen)
1574 (setq org-agenda-redo-command redo)
1575 (goto-char (point-min)))
1576 (org-finalize-agenda))
1578 ;;;###autoload
1579 (defmacro org-batch-agenda (cmd-key &rest parameters)
1580 "Run an agenda command in batch mode and send the result to STDOUT.
1581 If CMD-KEY is a string of length 1, it is used as a key in
1582 `org-agenda-custom-commands' and triggers this command. If it is a
1583 longer string it is used as a tags/todo match string.
1584 Paramters are alternating variable names and values that will be bound
1585 before running the agenda command."
1586 (let (pars)
1587 (while parameters
1588 (push (list (pop parameters) (if parameters (pop parameters))) pars))
1589 (if (> (length cmd-key) 2)
1590 (eval (list 'let (nreverse pars)
1591 (list 'org-tags-view nil cmd-key)))
1592 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
1593 (set-buffer org-agenda-buffer-name)
1594 (princ (org-encode-for-stdout (buffer-string)))))
1596 (defun org-encode-for-stdout (string)
1597 (if (fboundp 'encode-coding-string)
1598 (encode-coding-string string buffer-file-coding-system)
1599 string))
1601 (defvar org-agenda-info nil)
1603 ;;;###autoload
1604 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
1605 "Run an agenda command in batch mode and send the result to STDOUT.
1606 If CMD-KEY is a string of length 1, it is used as a key in
1607 `org-agenda-custom-commands' and triggers this command. If it is a
1608 longer string it is used as a tags/todo match string.
1609 Paramters are alternating variable names and values that will be bound
1610 before running the agenda command.
1612 The output gives a line for each selected agenda item. Each
1613 item is a list of comma-separated values, like this:
1615 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1617 category The category of the item
1618 head The headline, without TODO kwd, TAGS and PRIORITY
1619 type The type of the agenda entry, can be
1620 todo selected in TODO match
1621 tagsmatch selected in tags match
1622 diary imported from diary
1623 deadline a deadline on given date
1624 scheduled scheduled on given date
1625 timestamp entry has timestamp on given date
1626 closed entry was closed on given date
1627 upcoming-deadline warning about deadline
1628 past-scheduled forwarded scheduled item
1629 block entry has date block including g. date
1630 todo The todo keyword, if any
1631 tags All tags including inherited ones, separated by colons
1632 date The relevant date, like 2007-2-14
1633 time The time, like 15:00-16:50
1634 extra Sting with extra planning info
1635 priority-l The priority letter if any was given
1636 priority-n The computed numerical priority
1637 agenda-day The day in the agenda where this is listed"
1639 (let (pars)
1640 (while parameters
1641 (push (list (pop parameters) (if parameters (pop parameters))) pars))
1642 (push (list 'org-agenda-remove-tags t) pars)
1643 (if (> (length cmd-key) 2)
1644 (eval (list 'let (nreverse pars)
1645 (list 'org-tags-view nil cmd-key)))
1646 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
1647 (set-buffer org-agenda-buffer-name)
1648 (let* ((lines (org-split-string (buffer-string) "\n"))
1649 line)
1650 (while (setq line (pop lines))
1651 (catch 'next
1652 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
1653 (setq org-agenda-info
1654 (org-fix-agenda-info (text-properties-at 0 line)))
1655 (princ
1656 (org-encode-for-stdout
1657 (mapconcat 'org-agenda-export-csv-mapper
1658 '(org-category txt type todo tags date time-of-day extra
1659 priority-letter priority agenda-day)
1660 ",")))
1661 (princ "\n"))))))
1663 (defun org-fix-agenda-info (props)
1664 "Make sure all properties on an agenda item have a canonical form,
1665 so the export commands can easily use it."
1666 (let (tmp re)
1667 (when (setq tmp (plist-get props 'tags))
1668 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
1669 (when (setq tmp (plist-get props 'date))
1670 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
1671 (let ((calendar-date-display-form '(year "-" month "-" day)))
1672 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
1674 (setq tmp (calendar-date-string tmp)))
1675 (setq props (plist-put props 'date tmp)))
1676 (when (setq tmp (plist-get props 'day))
1677 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
1678 (let ((calendar-date-display-form '(year "-" month "-" day)))
1679 (setq tmp (calendar-date-string tmp)))
1680 (setq props (plist-put props 'day tmp))
1681 (setq props (plist-put props 'agenda-day tmp)))
1682 (when (setq tmp (plist-get props 'txt))
1683 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
1684 (plist-put props 'priority-letter (match-string 1 tmp))
1685 (setq tmp (replace-match "" t t tmp)))
1686 (when (and (setq re (plist-get props 'org-todo-regexp))
1687 (setq re (concat "\\`\\.*" re " ?"))
1688 (string-match re tmp))
1689 (plist-put props 'todo (match-string 1 tmp))
1690 (setq tmp (replace-match "" t t tmp)))
1691 (plist-put props 'txt tmp)))
1692 props)
1694 (defun org-agenda-export-csv-mapper (prop)
1695 (let ((res (plist-get org-agenda-info prop)))
1696 (setq res
1697 (cond
1698 ((not res) "")
1699 ((stringp res) res)
1700 (t (prin1-to-string res))))
1701 (while (string-match "," res)
1702 (setq res (replace-match ";" t t res)))
1703 (org-trim res)))
1706 ;;;###autoload
1707 (defun org-store-agenda-views (&rest parameters)
1708 (interactive)
1709 (eval (list 'org-batch-store-agenda-views)))
1711 ;; FIXME, why is this a macro?????
1712 ;;;###autoload
1713 (defmacro org-batch-store-agenda-views (&rest parameters)
1714 "Run all custom agenda commands that have a file argument."
1715 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
1716 (pop-up-frames nil)
1717 (dir default-directory)
1718 pars cmd thiscmdkey files opts)
1719 (while parameters
1720 (push (list (pop parameters) (if parameters (pop parameters))) pars))
1721 (setq pars (reverse pars))
1722 (save-window-excursion
1723 (while cmds
1724 (setq cmd (pop cmds)
1725 thiscmdkey (car cmd)
1726 opts (nth 4 cmd)
1727 files (nth 5 cmd))
1728 (if (stringp files) (setq files (list files)))
1729 (when files
1730 (eval (list 'let (append org-agenda-exporter-settings opts pars)
1731 (list 'org-agenda nil thiscmdkey)))
1732 (set-buffer org-agenda-buffer-name)
1733 (while files
1734 (eval (list 'let (append org-agenda-exporter-settings opts pars)
1735 (list 'org-write-agenda
1736 (expand-file-name (pop files) dir) t))))
1737 (and (get-buffer org-agenda-buffer-name)
1738 (kill-buffer org-agenda-buffer-name)))))))
1740 (defun org-write-agenda (file &optional nosettings)
1741 "Write the current buffer (an agenda view) as a file.
1742 Depending on the extension of the file name, plain text (.txt),
1743 HTML (.html or .htm) or Postscript (.ps) is produced.
1744 If the extension is .ics, run icalendar export over all files used
1745 to construct the agenda and limit the export to entries listed in the
1746 agenda now.
1747 If NOSETTINGS is given, do not scope the settings of
1748 `org-agenda-exporter-settings' into the export commands. This is used when
1749 the settings have already been scoped and we do not wish to overrule other,
1750 higher priority settings."
1751 (interactive "FWrite agenda to file: ")
1752 (if (not (file-writable-p file))
1753 (error "Cannot write agenda to file %s" file))
1754 (cond
1755 ((string-match "\\.html?\\'" file) (require 'htmlize))
1756 ((string-match "\\.ps\\'" file) (require 'ps-print)))
1757 (org-let (if nosettings nil org-agenda-exporter-settings)
1758 '(save-excursion
1759 (save-window-excursion
1760 (cond
1761 ((string-match "\\.html?\\'" file)
1762 (set-buffer (htmlize-buffer (current-buffer)))
1764 (when (and org-agenda-export-html-style
1765 (string-match "<style>" org-agenda-export-html-style))
1766 ;; replace <style> section with org-agenda-export-html-style
1767 (goto-char (point-min))
1768 (kill-region (- (search-forward "<style") 6)
1769 (search-forward "</style>"))
1770 (insert org-agenda-export-html-style))
1771 (write-file file)
1772 (kill-buffer (current-buffer))
1773 (message "HTML written to %s" file))
1774 ((string-match "\\.ps\\'" file)
1775 (ps-print-buffer-with-faces file)
1776 (message "Postscript written to %s" file))
1777 ((string-match "\\.ics\\'" file)
1778 (let ((org-agenda-marker-table
1779 (org-create-marker-find-array
1780 (org-agenda-collect-markers)))
1781 (org-icalendar-verify-function 'org-check-agenda-marker-table)
1782 (org-combined-agenda-icalendar-file file))
1783 (apply 'org-export-icalendar 'combine (org-agenda-files))))
1785 (let ((bs (buffer-string)))
1786 (find-file file)
1787 (insert bs)
1788 (save-buffer 0)
1789 (kill-buffer (current-buffer))
1790 (message "Plain text written to %s" file))))))
1791 (set-buffer org-agenda-buffer-name)))
1793 (defun org-agenda-collect-markers ()
1794 "Collect the markers pointing to entries in the agenda buffer."
1795 (let (m markers)
1796 (save-excursion
1797 (goto-char (point-min))
1798 (while (not (eobp))
1799 (when (setq m (or (get-text-property (point) 'org-hd-marker)
1800 (get-text-property (point) 'org-marker)))
1801 (push m markers))
1802 (beginning-of-line 2)))
1803 (nreverse markers)))
1805 (defun org-create-marker-find-array (marker-list)
1806 "Create a alist of files names with all marker positions in that file."
1807 (let (f tbl m a p)
1808 (while (setq m (pop marker-list))
1809 (setq p (marker-position m)
1810 f (buffer-file-name (or (buffer-base-buffer
1811 (marker-buffer m))
1812 (marker-buffer m))))
1813 (if (setq a (assoc f tbl))
1814 (push (marker-position m) (cdr a))
1815 (push (list f p) tbl)))
1816 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
1817 tbl)))
1819 (defvar org-agenda-marker-table nil) ; dyamically scoped parameter
1820 (defun org-check-agenda-marker-table ()
1821 "Check of the current entry is on the marker list."
1822 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
1824 (and (setq a (assoc file org-agenda-marker-table))
1825 (save-match-data
1826 (save-excursion
1827 (org-back-to-heading t)
1828 (member (point) (cdr a)))))))
1830 (defun org-check-for-org-mode ()
1831 "Make sure current buffer is in org-mode. Error if not."
1832 (or (org-mode-p)
1833 (error "Cannot execute org-mode agenda command on buffer in %s."
1834 major-mode)))
1836 (defun org-fit-agenda-window ()
1837 "Fit the window to the buffer size."
1838 (and (memq org-agenda-window-setup '(reorganize-frame))
1839 (fboundp 'fit-window-to-buffer)
1840 (fit-window-to-buffer
1842 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
1843 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
1845 ;;; Agenda prepare and finalize
1847 (defvar org-agenda-multi nil) ; dynammically scoped
1848 (defvar org-agenda-buffer-name "*Org Agenda*")
1849 (defvar org-pre-agenda-window-conf nil)
1850 (defvar org-agenda-name nil)
1851 (defun org-prepare-agenda (&optional name)
1852 (setq org-todo-keywords-for-agenda nil)
1853 (setq org-done-keywords-for-agenda nil)
1854 (if org-agenda-multi
1855 (progn
1856 (setq buffer-read-only nil)
1857 (goto-char (point-max))
1858 (unless (or (bobp) org-agenda-compact-blocks)
1859 (insert "\n" (make-string (window-width) ?=) "\n"))
1860 (narrow-to-region (point) (point-max)))
1861 (org-agenda-reset-markers)
1862 (org-prepare-agenda-buffers (org-agenda-files))
1863 (setq org-todo-keywords-for-agenda
1864 (org-uniquify org-todo-keywords-for-agenda))
1865 (setq org-done-keywords-for-agenda
1866 (org-uniquify org-done-keywords-for-agenda))
1867 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
1868 (awin (get-buffer-window abuf)))
1869 (cond
1870 ((equal (current-buffer) abuf) nil)
1871 (awin (select-window awin))
1872 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
1873 ((equal org-agenda-window-setup 'current-window)
1874 (switch-to-buffer abuf))
1875 ((equal org-agenda-window-setup 'other-window)
1876 (org-switch-to-buffer-other-window abuf))
1877 ((equal org-agenda-window-setup 'other-frame)
1878 (switch-to-buffer-other-frame abuf))
1879 ((equal org-agenda-window-setup 'reorganize-frame)
1880 (delete-other-windows)
1881 (org-switch-to-buffer-other-window abuf))))
1882 (setq buffer-read-only nil)
1883 (erase-buffer)
1884 (org-agenda-mode)
1885 (and name (not org-agenda-name)
1886 (org-set-local 'org-agenda-name name)))
1887 (setq buffer-read-only nil))
1889 (defun org-finalize-agenda ()
1890 "Finishing touch for the agenda buffer, called just before displaying it."
1891 (unless org-agenda-multi
1892 (save-excursion
1893 (let ((inhibit-read-only t))
1894 (goto-char (point-min))
1895 (while (org-activate-bracket-links (point-max))
1896 (add-text-properties (match-beginning 0) (match-end 0)
1897 '(face org-link)))
1898 (org-agenda-align-tags)
1899 (unless org-agenda-with-colors
1900 (remove-text-properties (point-min) (point-max) '(face nil))))
1901 (if (and (boundp 'org-overriding-columns-format)
1902 org-overriding-columns-format)
1903 (org-set-local 'org-overriding-columns-format
1904 org-overriding-columns-format))
1905 (if (and (boundp 'org-agenda-view-columns-initially)
1906 org-agenda-view-columns-initially)
1907 (org-agenda-columns))
1908 (when org-agenda-fontify-priorities
1909 (org-fontify-priorities))
1910 (run-hooks 'org-finalize-agenda-hook)
1911 (setq org-agenda-type (get-text-property (point) 'org-agenda-type))
1914 (defun org-fontify-priorities ()
1915 "Make highest priority lines bold, and lowest italic."
1916 (interactive)
1917 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
1918 (org-delete-overlay o)))
1919 (org-overlays-in (point-min) (point-max)))
1920 (save-excursion
1921 (let ((inhibit-read-only t)
1922 b e p ov h l)
1923 (goto-char (point-min))
1924 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
1925 (setq h (or (get-char-property (point) 'org-highest-priority)
1926 org-highest-priority)
1927 l (or (get-char-property (point) 'org-lowest-priority)
1928 org-lowest-priority)
1929 p (string-to-char (match-string 1))
1930 b (match-beginning 0) e (point-at-eol)
1931 ov (org-make-overlay b e))
1932 (org-overlay-put
1933 ov 'face
1934 (cond ((listp org-agenda-fontify-priorities)
1935 (cdr (assoc p org-agenda-fontify-priorities)))
1936 ((equal p l) 'italic)
1937 ((equal p h) 'bold)))
1938 (org-overlay-put ov 'org-type 'org-priority)))))
1941 (defvar org-agenda-skip-function nil
1942 "Function to be called at each match during agenda construction.
1943 If this function returns nil, the current match should not be skipped.
1944 Otherwise, the function must return a position from where the search
1945 should be continued.
1946 This may also be a Lisp form, it will be evaluated.
1947 Never set this variable using `setq' or so, because then it will apply
1948 to all future agenda commands. Instead, bind it with `let' to scope
1949 it dynamically into the agenda-constructing command. A good way to set
1950 it is through options in org-agenda-custom-commands.")
1952 (defun org-agenda-skip ()
1953 "Throw to `:skip' in places that should be skipped.
1954 Also moves point to the end of the skipped region, so that search can
1955 continue from there."
1956 (let ((p (point-at-bol)) to fp)
1957 (and org-agenda-skip-archived-trees
1958 (get-text-property p :org-archived)
1959 (org-end-of-subtree t)
1960 (throw :skip t))
1961 (and (get-text-property p :org-comment)
1962 (org-end-of-subtree t)
1963 (throw :skip t))
1964 (if (equal (char-after p) ?#) (throw :skip t))
1965 (when (and (or (setq fp (functionp org-agenda-skip-function))
1966 (consp org-agenda-skip-function))
1967 (setq to (save-excursion
1968 (save-match-data
1969 (if fp
1970 (funcall org-agenda-skip-function)
1971 (eval org-agenda-skip-function))))))
1972 (goto-char to)
1973 (throw :skip t))))
1975 (defvar org-agenda-markers nil
1976 "List of all currently active markers created by `org-agenda'.")
1977 (defvar org-agenda-last-marker-time (time-to-seconds (current-time))
1978 "Creation time of the last agenda marker.")
1980 (defun org-agenda-new-marker (&optional pos)
1981 "Return a new agenda marker.
1982 Org-mode keeps a list of these markers and resets them when they are
1983 no longer in use."
1984 (let ((m (copy-marker (or pos (point)))))
1985 (setq org-agenda-last-marker-time (time-to-seconds (current-time)))
1986 (push m org-agenda-markers)
1989 (defun org-agenda-reset-markers ()
1990 "Reset markers created by `org-agenda'."
1991 (while org-agenda-markers
1992 (move-marker (pop org-agenda-markers) nil)))
1994 ;;; Agenda timeline
1996 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
1998 (defun org-timeline (&optional include-all)
1999 "Show a time-sorted view of the entries in the current org file.
2000 Only entries with a time stamp of today or later will be listed. With
2001 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2002 under the current date.
2003 If the buffer contains an active region, only check the region for
2004 dates."
2005 (interactive "P")
2006 (require 'calendar)
2007 (org-compile-prefix-format 'timeline)
2008 (org-set-sorting-strategy 'timeline)
2009 (let* ((dopast t)
2010 (dotodo include-all)
2011 (doclosed org-agenda-show-log)
2012 (entry buffer-file-name)
2013 (date (calendar-current-date))
2014 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2015 (end (if (org-region-active-p) (region-end) (point-max)))
2016 (day-numbers (org-get-all-dates beg end 'no-ranges
2017 t doclosed ; always include today
2018 org-timeline-show-empty-dates))
2019 (org-deadline-warning-days 0)
2020 (org-agenda-only-exact-dates t)
2021 (today (time-to-days (current-time)))
2022 (past t)
2023 args
2024 s e rtn d emptyp)
2025 (setq org-agenda-redo-command
2026 (list 'progn
2027 (list 'org-switch-to-buffer-other-window (current-buffer))
2028 (list 'org-timeline (list 'quote include-all))))
2029 (if (not dopast)
2030 ;; Remove past dates from the list of dates.
2031 (setq day-numbers (delq nil (mapcar (lambda(x)
2032 (if (>= x today) x nil))
2033 day-numbers))))
2034 (org-prepare-agenda (concat "Timeline "
2035 (file-name-nondirectory buffer-file-name)))
2036 (if doclosed (push :closed args))
2037 (push :timestamp args)
2038 (push :deadline args)
2039 (push :scheduled args)
2040 (push :sexp args)
2041 (if dotodo (push :todo args))
2042 (while (setq d (pop day-numbers))
2043 (if (and (listp d) (eq (car d) :omitted))
2044 (progn
2045 (setq s (point))
2046 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2047 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2048 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2049 (if (and (>= d today)
2050 dopast
2051 past)
2052 (progn
2053 (setq past nil)
2054 (insert (make-string 79 ?-) "\n")))
2055 (setq date (calendar-gregorian-from-absolute d))
2056 (setq s (point))
2057 (setq rtn (and (not emptyp)
2058 (apply 'org-agenda-get-day-entries entry
2059 date args)))
2060 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2061 (progn
2062 (insert
2063 (if (stringp org-agenda-format-date)
2064 (format-time-string org-agenda-format-date
2065 (org-time-from-absolute date))
2066 (funcall org-agenda-format-date date))
2067 "\n")
2068 (put-text-property s (1- (point)) 'face 'org-agenda-structure)
2069 (put-text-property s (1- (point)) 'org-date-line t)
2070 (if (equal d today)
2071 (put-text-property s (1- (point)) 'org-today t))
2072 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2073 (put-text-property s (1- (point)) 'day d)))))
2074 (goto-char (point-min))
2075 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2076 (point-min)))
2077 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2078 (org-finalize-agenda)
2079 (setq buffer-read-only t)))
2081 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2082 "Return a list of all relevant day numbers from BEG to END buffer positions.
2083 If NO-RANGES is non-nil, include only the start and end dates of a range,
2084 not every single day in the range. If FORCE-TODAY is non-nil, make
2085 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2086 inactive time stamps (those in square brackets) are included.
2087 When EMPTY is non-nil, also include days without any entries."
2088 (let ((re (concat
2089 (if pre-re pre-re "")
2090 (if inactive org-ts-regexp-both org-ts-regexp)))
2091 dates dates1 date day day1 day2 ts1 ts2)
2092 (if force-today
2093 (setq dates (list (time-to-days (current-time)))))
2094 (save-excursion
2095 (goto-char beg)
2096 (while (re-search-forward re end t)
2097 (setq day (time-to-days (org-time-string-to-time
2098 (substring (match-string 1) 0 10))))
2099 (or (memq day dates) (push day dates)))
2100 (unless no-ranges
2101 (goto-char beg)
2102 (while (re-search-forward org-tr-regexp end t)
2103 (setq ts1 (substring (match-string 1) 0 10)
2104 ts2 (substring (match-string 2) 0 10)
2105 day1 (time-to-days (org-time-string-to-time ts1))
2106 day2 (time-to-days (org-time-string-to-time ts2)))
2107 (while (< (setq day1 (1+ day1)) day2)
2108 (or (memq day1 dates) (push day1 dates)))))
2109 (setq dates (sort dates '<))
2110 (when empty
2111 (while (setq day (pop dates))
2112 (setq day2 (car dates))
2113 (push day dates1)
2114 (when (and day2 empty)
2115 (if (or (eq empty t)
2116 (and (numberp empty) (<= (- day2 day) empty)))
2117 (while (< (setq day (1+ day)) day2)
2118 (push (list day) dates1))
2119 (push (cons :omitted (- day2 day)) dates1))))
2120 (setq dates (nreverse dates1)))
2121 dates)))
2123 ;;; Agenda Daily/Weekly
2125 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2126 (defvar org-agenda-start-day nil) ; dynamically scoped parameter
2127 (defvar org-agenda-last-arguments nil
2128 "The arguments of the previous call to org-agenda")
2129 (defvar org-starting-day nil) ; local variable in the agenda buffer
2130 (defvar org-agenda-span nil) ; local variable in the agenda buffer
2131 (defvar org-include-all-loc nil) ; local variable
2132 (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
2134 ;;;###autoload
2135 (defun org-agenda-list (&optional include-all start-day ndays)
2136 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2137 The view will be for the current day or week, but from the overview buffer
2138 you will be able to go to other days/weeks.
2140 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2141 all unfinished TODO items will also be shown, before the agenda.
2142 This feature is considered obsolete, please use the TODO list or a block
2143 agenda instead.
2145 With a numeric prefix argument in an interactive call, the agenda will
2146 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2147 the number of days. NDAYS defaults to `org-agenda-ndays'.
2149 START-DAY defaults to TODAY, or to the most recent match for the weekday
2150 given in `org-agenda-start-on-weekday'."
2151 (interactive "P")
2152 (if (and (integerp include-all) (> include-all 0))
2153 (setq ndays include-all include-all nil))
2154 (setq ndays (or ndays org-agenda-ndays)
2155 start-day (or start-day org-agenda-start-day))
2156 (if org-agenda-overriding-arguments
2157 (setq include-all (car org-agenda-overriding-arguments)
2158 start-day (nth 1 org-agenda-overriding-arguments)
2159 ndays (nth 2 org-agenda-overriding-arguments)))
2160 (if (stringp start-day)
2161 ;; Convert to an absolute day number
2162 (setq start-day (time-to-days (org-read-date nil t start-day))))
2163 (setq org-agenda-last-arguments (list include-all start-day ndays))
2164 (org-compile-prefix-format 'agenda)
2165 (org-set-sorting-strategy 'agenda)
2166 (require 'calendar)
2167 (let* ((org-agenda-start-on-weekday
2168 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
2169 org-agenda-start-on-weekday nil))
2170 (thefiles (org-agenda-files))
2171 (files thefiles)
2172 (today (time-to-days
2173 (time-subtract (current-time)
2174 (list 0 (* 3600 org-extend-today-until) 0))))
2175 (sd (or start-day today))
2176 (start (if (or (null org-agenda-start-on-weekday)
2177 (< org-agenda-ndays 7))
2179 (let* ((nt (calendar-day-of-week
2180 (calendar-gregorian-from-absolute sd)))
2181 (n1 org-agenda-start-on-weekday)
2182 (d (- nt n1)))
2183 (- sd (+ (if (< d 0) 7 0) d)))))
2184 (day-numbers (list start))
2185 (day-cnt 0)
2186 (inhibit-redisplay (not debug-on-error))
2187 s e rtn rtnall file date d start-pos end-pos todayp nd
2188 clocktable-start clocktable-end)
2189 (setq org-agenda-redo-command
2190 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
2191 ;; Make the list of days
2192 (setq ndays (or ndays org-agenda-ndays)
2193 nd ndays)
2194 (while (> ndays 1)
2195 (push (1+ (car day-numbers)) day-numbers)
2196 (setq ndays (1- ndays)))
2197 (setq day-numbers (nreverse day-numbers))
2198 (setq clocktable-start (car day-numbers)
2199 clocktable-end (1+ (or (org-last day-numbers) 0)))
2200 (org-prepare-agenda "Day/Week")
2201 (org-set-local 'org-starting-day (car day-numbers))
2202 (org-set-local 'org-include-all-loc include-all)
2203 (org-set-local 'org-agenda-span
2204 (org-agenda-ndays-to-span nd))
2205 (when (and (or include-all org-agenda-include-all-todo)
2206 (member today day-numbers))
2207 (setq files thefiles
2208 rtnall nil)
2209 (while (setq file (pop files))
2210 (catch 'nextfile
2211 (org-check-agenda-file file)
2212 (setq date (calendar-gregorian-from-absolute today)
2213 rtn (org-agenda-get-day-entries
2214 file date :todo))
2215 (setq rtnall (append rtnall rtn))))
2216 (when rtnall
2217 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2218 (add-text-properties (point-min) (1- (point))
2219 (list 'face 'org-agenda-structure))
2220 (insert (org-finalize-agenda-entries rtnall) "\n")))
2221 (unless org-agenda-compact-blocks
2222 (let* ((d1 (car day-numbers))
2223 (d2 (org-last day-numbers))
2224 (w1 (org-days-to-iso-week d1))
2225 (w2 (org-days-to-iso-week d2)))
2226 (setq s (point))
2227 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
2228 "-agenda"
2229 (if (< (- d2 d1) 350)
2230 (if (= w1 w2)
2231 (format " (W%02d)" w1)
2232 (format " (W%02d-W%02d)" w1 w2))
2234 ":\n"))
2235 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
2236 'org-date-line t)))
2237 (while (setq d (pop day-numbers))
2238 (setq date (calendar-gregorian-from-absolute d)
2239 s (point))
2240 (if (or (setq todayp (= d today))
2241 (and (not start-pos) (= d sd)))
2242 (setq start-pos (point))
2243 (if (and start-pos (not end-pos))
2244 (setq end-pos (point))))
2245 (setq files thefiles
2246 rtnall nil)
2247 (while (setq file (pop files))
2248 (catch 'nextfile
2249 (org-check-agenda-file file)
2250 (if org-agenda-show-log
2251 (setq rtn (org-agenda-get-day-entries
2252 file date
2253 :deadline :scheduled :timestamp :sexp :closed))
2254 (setq rtn (org-agenda-get-day-entries
2255 file date
2256 :deadline :scheduled :sexp :timestamp)))
2257 (setq rtnall (append rtnall rtn))))
2258 (if org-agenda-include-diary
2259 (progn
2260 (require 'diary-lib)
2261 (setq rtn (org-get-entries-from-diary date))
2262 (setq rtnall (append rtnall rtn))))
2263 (if (or rtnall org-agenda-show-all-dates)
2264 (progn
2265 (setq day-cnt (1+ day-cnt))
2266 (insert
2267 (if (stringp org-agenda-format-date)
2268 (format-time-string org-agenda-format-date
2269 (org-time-from-absolute date))
2270 (funcall org-agenda-format-date date))
2271 "\n")
2272 (put-text-property s (1- (point)) 'face 'org-agenda-structure)
2273 (put-text-property s (1- (point)) 'org-date-line t)
2274 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
2275 (if todayp (put-text-property s (1- (point)) 'org-today t))
2276 (if rtnall (insert
2277 (org-finalize-agenda-entries
2278 (org-agenda-add-time-grid-maybe
2279 rtnall nd todayp))
2280 "\n"))
2281 (put-text-property s (1- (point)) 'day d)
2282 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
2283 (when (and org-agenda-clockreport-mode clocktable-start)
2284 (let ((org-agenda-files (org-agenda-files))
2285 ;; the above line is to ensure the restricted range!
2286 (p org-agenda-clockreport-parameter-plist)
2287 tbl)
2288 (setq p (org-plist-delete p :block))
2289 (setq p (plist-put p :tstart clocktable-start))
2290 (setq p (plist-put p :tend clocktable-end))
2291 (setq p (plist-put p :scope 'agenda))
2292 (setq tbl (apply 'org-get-clocktable p))
2293 (insert tbl)))
2294 (goto-char (point-min))
2295 (org-fit-agenda-window)
2296 (unless (and (pos-visible-in-window-p (point-min))
2297 (pos-visible-in-window-p (point-max)))
2298 (goto-char (1- (point-max)))
2299 (recenter -1)
2300 (if (not (pos-visible-in-window-p (or start-pos 1)))
2301 (progn
2302 (goto-char (or start-pos 1))
2303 (recenter 1))))
2304 (goto-char (or start-pos 1))
2305 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
2306 (org-finalize-agenda)
2307 (setq buffer-read-only t)
2308 (message "")))
2310 (defun org-agenda-ndays-to-span (n)
2311 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
2313 ;;; Agenda word search
2315 (defvar org-agenda-search-history nil)
2316 (defvar org-todo-only nil)
2318 (defvar org-search-syntax-table nil
2319 "Special syntax table for org-mode search.
2320 In this table, we have single quotes not as word constituents, to
2321 that when \"+Ameli\" is searchd as a work, it will also match \"Ameli's\"")
2323 (defun org-search-syntax-table ()
2324 (unless org-search-syntax-table
2325 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
2326 (modify-syntax-entry ?' "." org-search-syntax-table)
2327 (modify-syntax-entry ?` "." org-search-syntax-table))
2328 org-search-syntax-table)
2330 ;;;###autoload
2331 (defun org-search-view (&optional todo-only string edit-at)
2332 "Show all entries that contain words or regular expressions.
2333 If the first character of the search string is an asterisks,
2334 search only the headlines.
2336 With optional prefix argument TODO-ONLY, only consider entries that are
2337 TODO entries. The argument STRING can be used to pass a default search
2338 string into this function. If EDIT-AT is non-nil, it means that the
2339 user should get a chance to edit this string, with cursor at position
2340 EDIT-AT.
2342 The search string is broken into \"words\" by splitting at whitespace.
2343 The individual words are then interpreted as a boolean expression with
2344 logical AND. Words prefixed with a minus must not occur in the entry.
2345 Words without a prefix or prefixed with a plus must occur in the entry.
2346 Matching is case-insensitive and the words are enclosed by word delimiters.
2348 Words enclosed by curly braces are interpreted as regular expressions
2349 that must or must not match in the entry.
2351 If the search string starts with an asterisk, search only in headlines.
2352 If (possibly after the leading star) the search string starts with an
2353 exclamation mark, this also means to look at TODO entries only, an effect
2354 that can also be achieved with a prefix argument.
2356 This command searches the agenda files, and in addition the files listed
2357 in `org-agenda-text-search-extra-files'."
2358 (interactive "P")
2359 (org-compile-prefix-format 'search)
2360 (org-set-sorting-strategy 'search)
2361 (org-prepare-agenda "SEARCH")
2362 (let* ((props (list 'face nil
2363 'done-face 'org-done
2364 'org-not-done-regexp org-not-done-regexp
2365 'org-todo-regexp org-todo-regexp
2366 'mouse-face 'highlight
2367 'keymap org-agenda-keymap
2368 'help-echo (format "mouse-2 or RET jump to location")))
2369 regexp rtn rtnall files file pos
2370 marker priority category tags c neg re
2371 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
2372 (unless (and (not edit-at)
2373 (stringp string)
2374 (string-match "\\S-" string))
2375 (setq string (read-string "[+-]Word/{Regexp} ...: "
2376 (cond
2377 ((integerp edit-at) (cons string edit-at))
2378 (edit-at string))
2379 'org-agenda-search-history)))
2380 (org-set-local 'org-todo-only todo-only)
2381 (setq org-agenda-redo-command
2382 (list 'org-search-view (if todo-only t nil) string
2383 '(if current-prefix-arg 1 nil)))
2384 (setq org-agenda-query-string string)
2386 (if (equal (string-to-char string) ?*)
2387 (setq hdl-only t
2388 words (substring string 1))
2389 (setq words string))
2390 (when (equal (string-to-char words) ?!)
2391 (setq todo-only t
2392 words (substring words 1)))
2393 (setq words (org-split-string words))
2394 (mapc (lambda (w)
2395 (setq c (string-to-char w))
2396 (if (equal c ?-)
2397 (setq neg t w (substring w 1))
2398 (if (equal c ?+)
2399 (setq neg nil w (substring w 1))
2400 (setq neg nil)))
2401 (if (string-match "\\`{.*}\\'" w)
2402 (setq re (substring w 1 -1))
2403 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
2404 (if neg (push re regexps-) (push re regexps+)))
2405 words)
2406 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
2407 (if (not regexps+)
2408 (setq regexp (concat "^" org-outline-regexp))
2409 (setq regexp (pop regexps+))
2410 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
2411 regexp))))
2412 (setq files (append (org-agenda-files) org-agenda-text-search-extra-files)
2413 rtnall nil)
2414 (while (setq file (pop files))
2415 (setq ee nil)
2416 (catch 'nextfile
2417 (org-check-agenda-file file)
2418 (setq buffer (if (file-exists-p file)
2419 (org-get-agenda-file-buffer file)
2420 (error "No such file %s" file)))
2421 (if (not buffer)
2422 ;; If file does not exist, make sure an error message is sent
2423 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
2424 file))))
2425 (with-current-buffer buffer
2426 (with-syntax-table (org-search-syntax-table)
2427 (unless (org-mode-p)
2428 (error "Agenda file %s is not in `org-mode'" file))
2429 (let ((case-fold-search t))
2430 (save-excursion
2431 (save-restriction
2432 (if org-agenda-restrict
2433 (narrow-to-region org-agenda-restrict-begin
2434 org-agenda-restrict-end)
2435 (widen))
2436 (goto-char (point-min))
2437 (unless (or (org-on-heading-p)
2438 (outline-next-heading))
2439 (throw 'nextfile t))
2440 (goto-char (max (point-min) (1- (point))))
2441 (while (re-search-forward regexp nil t)
2442 (org-back-to-heading t)
2443 (skip-chars-forward "* ")
2444 (setq beg (point-at-bol)
2445 beg1 (point)
2446 end (progn (outline-next-heading) (point)))
2447 (catch :skip
2448 (goto-char beg)
2449 (org-agenda-skip)
2450 (setq str (buffer-substring-no-properties
2451 (point-at-bol)
2452 (if hdl-only (point-at-eol) end)))
2453 (mapc (lambda (wr) (when (string-match wr str)
2454 (goto-char (1- end))
2455 (throw :skip t)))
2456 regexps-)
2457 (mapc (lambda (wr) (unless (string-match wr str)
2458 (goto-char (1- end))
2459 (throw :skip t)))
2460 (if todo-only
2461 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
2462 regexps+)
2463 regexps+))
2464 (goto-char beg)
2465 (setq marker (org-agenda-new-marker (point))
2466 category (org-get-category)
2467 tags (org-get-tags-at (point))
2468 txt (org-format-agenda-item
2470 (buffer-substring-no-properties
2471 beg1 (point-at-eol))
2472 category tags))
2473 (org-add-props txt props
2474 'org-marker marker 'org-hd-marker marker
2475 'org-todo-regexp org-todo-regexp
2476 'priority 1000 'org-category category
2477 'type "search")
2478 (push txt ee)
2479 (goto-char (1- end))))))))))
2480 (setq rtn (nreverse ee))
2481 (setq rtnall (append rtnall rtn)))
2482 (if org-agenda-overriding-header
2483 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
2484 nil 'face 'org-agenda-structure) "\n")
2485 (insert "Search words: ")
2486 (add-text-properties (point-min) (1- (point))
2487 (list 'face 'org-agenda-structure))
2488 (setq pos (point))
2489 (insert string "\n")
2490 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
2491 (setq pos (point))
2492 (unless org-agenda-multi
2493 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
2494 (add-text-properties pos (1- (point))
2495 (list 'face 'org-agenda-structure))))
2496 (when rtnall
2497 (insert (org-finalize-agenda-entries rtnall) "\n"))
2498 (goto-char (point-min))
2499 (org-fit-agenda-window)
2500 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
2501 (org-finalize-agenda)
2502 (setq buffer-read-only t)))
2504 ;;; Agenda TODO list
2506 (defvar org-select-this-todo-keyword nil)
2507 (defvar org-last-arg nil)
2509 ;;;###autoload
2510 (defun org-todo-list (arg)
2511 "Show all TODO entries from all agenda file in a single list.
2512 The prefix arg can be used to select a specific TODO keyword and limit
2513 the list to these. When using \\[universal-argument], you will be prompted
2514 for a keyword. A numeric prefix directly selects the Nth keyword in
2515 `org-todo-keywords-1'."
2516 (interactive "P")
2517 (require 'calendar)
2518 (org-compile-prefix-format 'todo)
2519 (org-set-sorting-strategy 'todo)
2520 (org-prepare-agenda "TODO")
2521 (let* ((today (time-to-days (current-time)))
2522 (date (calendar-gregorian-from-absolute today))
2523 (kwds org-todo-keywords-for-agenda)
2524 (completion-ignore-case t)
2525 (org-select-this-todo-keyword
2526 (if (stringp arg) arg
2527 (and arg (integerp arg) (> arg 0)
2528 (nth (1- arg) kwds))))
2529 rtn rtnall files file pos)
2530 (when (equal arg '(4))
2531 (setq org-select-this-todo-keyword
2532 (completing-read "Keyword (or KWD1|K2D2|...): "
2533 (mapcar 'list kwds) nil nil)))
2534 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
2535 (org-set-local 'org-last-arg arg)
2536 (setq org-agenda-redo-command
2537 '(org-todo-list (or current-prefix-arg org-last-arg)))
2538 (setq files (org-agenda-files)
2539 rtnall nil)
2540 (while (setq file (pop files))
2541 (catch 'nextfile
2542 (org-check-agenda-file file)
2543 (setq rtn (org-agenda-get-day-entries file date :todo))
2544 (setq rtnall (append rtnall rtn))))
2545 (if org-agenda-overriding-header
2546 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
2547 nil 'face 'org-agenda-structure) "\n")
2548 (insert "Global list of TODO items of type: ")
2549 (add-text-properties (point-min) (1- (point))
2550 (list 'face 'org-agenda-structure))
2551 (setq pos (point))
2552 (insert (or org-select-this-todo-keyword "ALL") "\n")
2553 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
2554 (setq pos (point))
2555 (unless org-agenda-multi
2556 (insert "Available with `N r': (0)ALL")
2557 (let ((n 0) s)
2558 (mapc (lambda (x)
2559 (setq s (format "(%d)%s" (setq n (1+ n)) x))
2560 (if (> (+ (current-column) (string-width s) 1) (frame-width))
2561 (insert "\n "))
2562 (insert " " s))
2563 kwds))
2564 (insert "\n"))
2565 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
2566 (when rtnall
2567 (insert (org-finalize-agenda-entries rtnall) "\n"))
2568 (goto-char (point-min))
2569 (org-fit-agenda-window)
2570 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
2571 (org-finalize-agenda)
2572 (setq buffer-read-only t)))
2574 ;;; Agenda tags match
2576 ;;;###autoload
2577 (defun org-tags-view (&optional todo-only match)
2578 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
2579 The prefix arg TODO-ONLY limits the search to TODO entries."
2580 (interactive "P")
2581 (org-compile-prefix-format 'tags)
2582 (org-set-sorting-strategy 'tags)
2583 (let* ((org-tags-match-list-sublevels
2584 (if todo-only t org-tags-match-list-sublevels))
2585 (completion-ignore-case t)
2586 rtn rtnall files file pos matcher
2587 buffer)
2588 (setq matcher (org-make-tags-matcher match)
2589 match (car matcher) matcher (cdr matcher))
2590 (org-prepare-agenda (concat "TAGS " match))
2591 (setq org-agenda-query-string match)
2592 (setq org-agenda-redo-command
2593 (list 'org-tags-view (list 'quote todo-only)
2594 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
2595 (setq files (org-agenda-files)
2596 rtnall nil)
2597 (while (setq file (pop files))
2598 (catch 'nextfile
2599 (org-check-agenda-file file)
2600 (setq buffer (if (file-exists-p file)
2601 (org-get-agenda-file-buffer file)
2602 (error "No such file %s" file)))
2603 (if (not buffer)
2604 ;; If file does not exist, merror message to agenda
2605 (setq rtn (list
2606 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
2607 rtnall (append rtnall rtn))
2608 (with-current-buffer buffer
2609 (unless (org-mode-p)
2610 (error "Agenda file %s is not in `org-mode'" file))
2611 (save-excursion
2612 (save-restriction
2613 (if org-agenda-restrict
2614 (narrow-to-region org-agenda-restrict-begin
2615 org-agenda-restrict-end)
2616 (widen))
2617 (setq rtn (org-scan-tags 'agenda matcher todo-only))
2618 (setq rtnall (append rtnall rtn))))))))
2619 (if org-agenda-overriding-header
2620 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
2621 nil 'face 'org-agenda-structure) "\n")
2622 (insert "Headlines with TAGS match: ")
2623 (add-text-properties (point-min) (1- (point))
2624 (list 'face 'org-agenda-structure))
2625 (setq pos (point))
2626 (insert match "\n")
2627 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
2628 (setq pos (point))
2629 (unless org-agenda-multi
2630 (insert "Press `C-u r' to search again with new search string\n"))
2631 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
2632 (when rtnall
2633 (insert (org-finalize-agenda-entries rtnall) "\n"))
2634 (goto-char (point-min))
2635 (org-fit-agenda-window)
2636 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
2637 (org-finalize-agenda)
2638 (setq buffer-read-only t)))
2640 ;;; Agenda Finding stuck projects
2642 (defvar org-agenda-skip-regexp nil
2643 "Regular expression used in skipping subtrees for the agenda.
2644 This is basically a temporary global variable that can be set and then
2645 used by user-defined selections using `org-agenda-skip-function'.")
2647 (defvar org-agenda-overriding-header nil
2648 "When this is set during todo and tags searches, will replace header.")
2650 (defun org-agenda-skip-subtree-when-regexp-matches ()
2651 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
2652 If yes, it returns the end position of this tree, causing agenda commands
2653 to skip this subtree. This is a function that can be put into
2654 `org-agenda-skip-function' for the duration of a command."
2655 (let ((end (save-excursion (org-end-of-subtree t)))
2656 skip)
2657 (save-excursion
2658 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
2659 (and skip end)))
2661 (defun org-agenda-skip-entry-if (&rest conditions)
2662 "Skip entry if any of CONDITIONS is true.
2663 See `org-agenda-skip-if' for details."
2664 (org-agenda-skip-if nil conditions))
2666 (defun org-agenda-skip-subtree-if (&rest conditions)
2667 "Skip entry if any of CONDITIONS is true.
2668 See `org-agenda-skip-if' for details."
2669 (org-agenda-skip-if t conditions))
2671 (defun org-agenda-skip-if (subtree conditions)
2672 "Checks current entity for CONDITIONS.
2673 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
2674 the entry, i.e. the text before the next heading is checked.
2676 CONDITIONS is a list of symbols, boolean OR is used to combine the results
2677 from different tests. Valid conditions are:
2679 scheduled Check if there is a scheduled cookie
2680 notscheduled Check if there is no scheduled cookie
2681 deadline Check if there is a deadline
2682 notdeadline Check if there is no deadline
2683 regexp Check if regexp matches
2684 notregexp Check if regexp does not match.
2686 The regexp is taken from the conditions list, it must come right after
2687 the `regexp' or `notregexp' element.
2689 If any of these conditions is met, this function returns the end point of
2690 the entity, causing the search to continue from there. This is a function
2691 that can be put into `org-agenda-skip-function' for the duration of a command."
2692 (let (beg end m)
2693 (org-back-to-heading t)
2694 (setq beg (point)
2695 end (if subtree
2696 (progn (org-end-of-subtree t) (point))
2697 (progn (outline-next-heading) (1- (point)))))
2698 (goto-char beg)
2699 (and
2701 (and (memq 'scheduled conditions)
2702 (re-search-forward org-scheduled-time-regexp end t))
2703 (and (memq 'notscheduled conditions)
2704 (not (re-search-forward org-scheduled-time-regexp end t)))
2705 (and (memq 'deadline conditions)
2706 (re-search-forward org-deadline-time-regexp end t))
2707 (and (memq 'notdeadline conditions)
2708 (not (re-search-forward org-deadline-time-regexp end t)))
2709 (and (setq m (memq 'regexp conditions))
2710 (stringp (nth 1 m))
2711 (re-search-forward (nth 1 m) end t))
2712 (and (setq m (memq 'notregexp conditions))
2713 (stringp (nth 1 m))
2714 (not (re-search-forward (nth 1 m) end t))))
2715 end)))
2717 ;;;###autoload
2718 (defun org-agenda-list-stuck-projects (&rest ignore)
2719 "Create agenda view for projects that are stuck.
2720 Stuck projects are project that have no next actions. For the definitions
2721 of what a project is and how to check if it stuck, customize the variable
2722 `org-stuck-projects'.
2723 MATCH is being ignored."
2724 (interactive)
2725 (let* ((org-agenda-skip-function 'org-agenda-skip-subtree-when-regexp-matches)
2726 ;; We could have used org-agenda-skip-if here.
2727 (org-agenda-overriding-header "List of stuck projects: ")
2728 (matcher (nth 0 org-stuck-projects))
2729 (todo (nth 1 org-stuck-projects))
2730 (todo-wds (if (member "*" todo)
2731 (progn
2732 (org-prepare-agenda-buffers (org-agenda-files))
2733 (org-delete-all
2734 org-done-keywords-for-agenda
2735 (copy-sequence org-todo-keywords-for-agenda)))
2736 todo))
2737 (todo-re (concat "^\\*+[ \t]+\\("
2738 (mapconcat 'identity todo-wds "\\|")
2739 "\\)\\>"))
2740 (tags (nth 2 org-stuck-projects))
2741 (tags-re (if (member "*" tags)
2742 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
2743 (concat "^\\*+ .*:\\("
2744 (mapconcat 'identity tags "\\|")
2745 (org-re "\\):[[:alnum:]_@:]*[ \t]*$"))))
2746 (gen-re (nth 3 org-stuck-projects))
2747 (re-list
2748 (delq nil
2749 (list
2750 (if todo todo-re)
2751 (if tags tags-re)
2752 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
2753 gen-re)))))
2754 (setq org-agenda-skip-regexp
2755 (if re-list
2756 (mapconcat 'identity re-list "\\|")
2757 (error "No information how to identify unstuck projects")))
2758 (org-tags-view nil matcher)
2759 (with-current-buffer org-agenda-buffer-name
2760 (setq org-agenda-redo-command
2761 '(org-agenda-list-stuck-projects
2762 (or current-prefix-arg org-last-arg))))))
2764 ;;; Diary integration
2766 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
2767 (defvar list-diary-entries-hook)
2769 (defun org-get-entries-from-diary (date)
2770 "Get the (Emacs Calendar) diary entries for DATE."
2771 (require 'diary-lib)
2772 (let* ((fancy-diary-buffer "*temporary-fancy-diary-buffer*")
2773 (diary-display-hook '(fancy-diary-display))
2774 (pop-up-frames nil)
2775 (list-diary-entries-hook
2776 (cons 'org-diary-default-entry list-diary-entries-hook))
2777 (diary-file-name-prefix-function nil) ; turn this feature off
2778 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
2779 entries
2780 (org-disable-agenda-to-diary t))
2781 (save-excursion
2782 (save-window-excursion
2783 (funcall (if (fboundp 'diary-list-entries)
2784 'diary-list-entries 'list-diary-entries)
2785 date 1)))
2786 (if (not (get-buffer fancy-diary-buffer))
2787 (setq entries nil)
2788 (with-current-buffer fancy-diary-buffer
2789 (setq buffer-read-only nil)
2790 (if (zerop (buffer-size))
2791 ;; No entries
2792 (setq entries nil)
2793 ;; Omit the date and other unnecessary stuff
2794 (org-agenda-cleanup-fancy-diary)
2795 ;; Add prefix to each line and extend the text properties
2796 (if (zerop (buffer-size))
2797 (setq entries nil)
2798 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
2799 (set-buffer-modified-p nil)
2800 (kill-buffer fancy-diary-buffer)))
2801 (when entries
2802 (setq entries (org-split-string entries "\n"))
2803 (setq entries
2804 (mapcar
2805 (lambda (x)
2806 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
2807 ;; Extend the text properties to the beginning of the line
2808 (org-add-props x (text-properties-at (1- (length x)) x)
2809 'type "diary" 'date date))
2810 entries)))))
2812 (defun org-agenda-cleanup-fancy-diary ()
2813 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
2814 This gets rid of the date, the underline under the date, and
2815 the dummy entry installed by `org-mode' to ensure non-empty diary for each
2816 date. It also removes lines that contain only whitespace."
2817 (goto-char (point-min))
2818 (if (looking-at ".*?:[ \t]*")
2819 (progn
2820 (replace-match "")
2821 (re-search-forward "\n=+$" nil t)
2822 (replace-match "")
2823 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
2824 (re-search-forward "\n=+$" nil t)
2825 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
2826 (goto-char (point-min))
2827 (while (re-search-forward "^ +\n" nil t)
2828 (replace-match ""))
2829 (goto-char (point-min))
2830 (if (re-search-forward "^Org-mode dummy\n?" nil t)
2831 (replace-match "")))
2833 ;; Make sure entries from the diary have the right text properties.
2834 (eval-after-load "diary-lib"
2835 '(if (boundp 'diary-modify-entry-list-string-function)
2836 ;; We can rely on the hook, nothing to do
2838 ;; Hook not avaiable, must use advice to make this work
2839 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
2840 "Make the position visible."
2841 (if (and org-disable-agenda-to-diary ;; called from org-agenda
2842 (stringp string)
2843 buffer-file-name)
2844 (setq string (org-modify-diary-entry-string string))))))
2846 (defun org-modify-diary-entry-string (string)
2847 "Add text properties to string, allowing org-mode to act on it."
2848 (org-add-props string nil
2849 'mouse-face 'highlight
2850 'keymap org-agenda-keymap
2851 'help-echo (if buffer-file-name
2852 (format "mouse-2 or RET jump to diary file %s"
2853 (abbreviate-file-name buffer-file-name))
2855 'org-agenda-diary-link t
2856 'org-marker (org-agenda-new-marker (point-at-bol))))
2858 (defun org-diary-default-entry ()
2859 "Add a dummy entry to the diary.
2860 Needed to avoid empty dates which mess up holiday display."
2861 ;; Catch the error if dealing with the new add-to-diary-alist
2862 (when org-disable-agenda-to-diary
2863 (condition-case nil
2864 (add-to-diary-list original-date "Org-mode dummy" "")
2865 (error
2866 (add-to-diary-list original-date "Org-mode dummy" "" nil)))))
2868 ;;;###autoload
2869 (defun org-diary (&rest args)
2870 "Return diary information from org-files.
2871 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
2872 It accesses org files and extracts information from those files to be
2873 listed in the diary. The function accepts arguments specifying what
2874 items should be listed. The following arguments are allowed:
2876 :timestamp List the headlines of items containing a date stamp or
2877 date range matching the selected date. Deadlines will
2878 also be listed, on the expiration day.
2880 :sexp List entries resulting from diary-like sexps.
2882 :deadline List any deadlines past due, or due within
2883 `org-deadline-warning-days'. The listing occurs only
2884 in the diary for *today*, not at any other date. If
2885 an entry is marked DONE, it is no longer listed.
2887 :scheduled List all items which are scheduled for the given date.
2888 The diary for *today* also contains items which were
2889 scheduled earlier and are not yet marked DONE.
2891 :todo List all TODO items from the org-file. This may be a
2892 long list - so this is not turned on by default.
2893 Like deadlines, these entries only show up in the
2894 diary for *today*, not at any other date.
2896 The call in the diary file should look like this:
2898 &%%(org-diary) ~/path/to/some/orgfile.org
2900 Use a separate line for each org file to check. Or, if you omit the file name,
2901 all files listed in `org-agenda-files' will be checked automatically:
2903 &%%(org-diary)
2905 If you don't give any arguments (as in the example above), the default
2906 arguments (:deadline :scheduled :timestamp :sexp) are used.
2907 So the example above may also be written as
2909 &%%(org-diary :deadline :timestamp :sexp :scheduled)
2911 The function expects the lisp variables `entry' and `date' to be provided
2912 by the caller, because this is how the calendar works. Don't use this
2913 function from a program - use `org-agenda-get-day-entries' instead."
2914 (when (> (- (time-to-seconds (current-time))
2915 org-agenda-last-marker-time)
2917 (org-agenda-reset-markers))
2918 (org-compile-prefix-format 'agenda)
2919 (org-set-sorting-strategy 'agenda)
2920 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
2921 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
2922 (list entry)
2923 (org-agenda-files t)))
2924 file rtn results)
2925 (org-prepare-agenda-buffers files)
2926 ;; If this is called during org-agenda, don't return any entries to
2927 ;; the calendar. Org Agenda will list these entries itself.
2928 (if org-disable-agenda-to-diary (setq files nil))
2929 (while (setq file (pop files))
2930 (setq rtn (apply 'org-agenda-get-day-entries file date args))
2931 (setq results (append results rtn)))
2932 (if results
2933 (concat (org-finalize-agenda-entries results) "\n"))))
2935 ;;; Agenda entry finders
2937 (defun org-agenda-get-day-entries (file date &rest args)
2938 "Does the work for `org-diary' and `org-agenda'.
2939 FILE is the path to a file to be checked for entries. DATE is date like
2940 the one returned by `calendar-current-date'. ARGS are symbols indicating
2941 which kind of entries should be extracted. For details about these, see
2942 the documentation of `org-diary'."
2943 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
2944 (let* ((org-startup-folded nil)
2945 (org-startup-align-all-tables nil)
2946 (buffer (if (file-exists-p file)
2947 (org-get-agenda-file-buffer file)
2948 (error "No such file %s" file)))
2949 arg results rtn)
2950 (if (not buffer)
2951 ;; If file does not exist, make sure an error message ends up in diary
2952 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
2953 (with-current-buffer buffer
2954 (unless (org-mode-p)
2955 (error "Agenda file %s is not in `org-mode'" file))
2956 (let ((case-fold-search nil))
2957 (save-excursion
2958 (save-restriction
2959 (if org-agenda-restrict
2960 (narrow-to-region org-agenda-restrict-begin
2961 org-agenda-restrict-end)
2962 (widen))
2963 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
2964 (while (setq arg (pop args))
2965 (cond
2966 ((and (eq arg :todo)
2967 (equal date (calendar-current-date)))
2968 (setq rtn (org-agenda-get-todos))
2969 (setq results (append results rtn)))
2970 ((eq arg :timestamp)
2971 (setq rtn (org-agenda-get-blocks))
2972 (setq results (append results rtn))
2973 (setq rtn (org-agenda-get-timestamps))
2974 (setq results (append results rtn)))
2975 ((eq arg :sexp)
2976 (setq rtn (org-agenda-get-sexps))
2977 (setq results (append results rtn)))
2978 ((eq arg :scheduled)
2979 (setq rtn (org-agenda-get-scheduled))
2980 (setq results (append results rtn)))
2981 ((eq arg :closed)
2982 (setq rtn (org-agenda-get-closed))
2983 (setq results (append results rtn)))
2984 ((eq arg :deadline)
2985 (setq rtn (org-agenda-get-deadlines))
2986 (setq results (append results rtn))))))))
2987 results))))
2989 (defun org-agenda-get-todos ()
2990 "Return the TODO information for agenda display."
2991 (let* ((props (list 'face nil
2992 'done-face 'org-done
2993 'org-not-done-regexp org-not-done-regexp
2994 'org-todo-regexp org-todo-regexp
2995 'mouse-face 'highlight
2996 'keymap org-agenda-keymap
2997 'help-echo
2998 (format "mouse-2 or RET jump to org file %s"
2999 (abbreviate-file-name buffer-file-name))))
3000 (regexp (concat "^\\*+[ \t]+\\("
3001 (if org-select-this-todo-keyword
3002 (if (equal org-select-this-todo-keyword "*")
3003 org-todo-regexp
3004 (concat "\\<\\("
3005 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
3006 "\\)\\>"))
3007 org-not-done-regexp)
3008 "[^\n\r]*\\)"))
3009 marker priority category tags
3010 ee txt beg end)
3011 (goto-char (point-min))
3012 (while (re-search-forward regexp nil t)
3013 (catch :skip
3014 (save-match-data
3015 (beginning-of-line)
3016 (setq beg (point) end (progn (outline-next-heading) (point)))
3017 (when (or (and org-agenda-todo-ignore-with-date (goto-char beg)
3018 (re-search-forward org-ts-regexp end t))
3019 (and org-agenda-todo-ignore-scheduled (goto-char beg)
3020 (re-search-forward org-scheduled-time-regexp end t))
3021 (and org-agenda-todo-ignore-deadlines (goto-char beg)
3022 (re-search-forward org-deadline-time-regexp end t)
3023 (org-deadline-close (match-string 1))))
3024 (goto-char (1+ beg))
3025 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
3026 (throw :skip nil)))
3027 (goto-char beg)
3028 (org-agenda-skip)
3029 (goto-char (match-beginning 1))
3030 (setq marker (org-agenda-new-marker (match-beginning 0))
3031 category (org-get-category)
3032 tags (org-get-tags-at (point))
3033 txt (org-format-agenda-item "" (match-string 1) category tags)
3034 priority (1+ (org-get-priority txt)))
3035 (org-add-props txt props
3036 'org-marker marker 'org-hd-marker marker
3037 'priority priority 'org-category category
3038 'type "todo")
3039 (push txt ee)
3040 (if org-agenda-todo-list-sublevels
3041 (goto-char (match-end 1))
3042 (org-end-of-subtree 'invisible))))
3043 (nreverse ee)))
3045 (defconst org-agenda-no-heading-message
3046 "No heading for this item in buffer or region.")
3048 (defun org-agenda-get-timestamps ()
3049 "Return the date stamp information for agenda display."
3050 (let* ((props (list 'face nil
3051 'org-not-done-regexp org-not-done-regexp
3052 'org-todo-regexp org-todo-regexp
3053 'mouse-face 'highlight
3054 'keymap org-agenda-keymap
3055 'help-echo
3056 (format "mouse-2 or RET jump to org file %s"
3057 (abbreviate-file-name buffer-file-name))))
3058 (d1 (calendar-absolute-from-gregorian date))
3059 (remove-re
3060 (concat
3061 (regexp-quote
3062 (format-time-string
3063 "<%Y-%m-%d"
3064 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
3065 ".*?>"))
3066 (regexp
3067 (concat
3068 (regexp-quote
3069 (substring
3070 (format-time-string
3071 (car org-time-stamp-formats)
3072 (apply 'encode-time ; DATE bound by calendar
3073 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
3074 0 11))
3075 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3076 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3077 marker hdmarker deadlinep scheduledp donep tmp priority category
3078 ee txt timestr tags b0 b3 e3 head)
3079 (goto-char (point-min))
3080 (while (re-search-forward regexp nil t)
3081 (setq b0 (match-beginning 0)
3082 b3 (match-beginning 3) e3 (match-end 3))
3083 (catch :skip
3084 (and (org-at-date-range-p) (throw :skip nil))
3085 (org-agenda-skip)
3086 (if (and (match-end 1)
3087 (not (= d1 (org-time-string-to-absolute
3088 (match-string 1) d1 nil
3089 org-agenda-repeating-timestamp-show-all))))
3090 (throw :skip nil))
3091 (if (and e3
3092 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
3093 (throw :skip nil))
3094 (setq marker (org-agenda-new-marker b0)
3095 category (org-get-category b0)
3096 tmp (buffer-substring (max (point-min)
3097 (- b0 org-ds-keyword-length))
3099 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
3100 deadlinep (string-match org-deadline-regexp tmp)
3101 scheduledp (string-match org-scheduled-regexp tmp)
3102 donep (org-entry-is-done-p))
3103 (if (or scheduledp deadlinep) (throw :skip t))
3104 (if (string-match ">" timestr)
3105 ;; substring should only run to end of time stamp
3106 (setq timestr (substring timestr 0 (match-end 0))))
3107 (save-excursion
3108 (if (re-search-backward "^\\*+ " nil t)
3109 (progn
3110 (goto-char (match-beginning 0))
3111 (setq hdmarker (org-agenda-new-marker)
3112 tags (org-get-tags-at))
3113 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3114 (setq head (match-string 1))
3115 (and org-agenda-skip-timestamp-if-done donep (throw :skip t))
3116 (setq txt (org-format-agenda-item
3117 nil head category tags timestr nil
3118 remove-re)))
3119 (setq txt org-agenda-no-heading-message))
3120 (setq priority (org-get-priority txt))
3121 (org-add-props txt props
3122 'org-marker marker 'org-hd-marker hdmarker)
3123 (org-add-props txt nil 'priority priority
3124 'org-category category 'date date
3125 'type "timestamp")
3126 (push txt ee))
3127 (outline-next-heading)))
3128 (nreverse ee)))
3130 (defun org-agenda-get-sexps ()
3131 "Return the sexp information for agenda display."
3132 (require 'diary-lib)
3133 (let* ((props (list 'face nil
3134 'mouse-face 'highlight
3135 'keymap org-agenda-keymap
3136 'help-echo
3137 (format "mouse-2 or RET jump to org file %s"
3138 (abbreviate-file-name buffer-file-name))))
3139 (regexp "^&?%%(")
3140 marker category ee txt tags entry result beg b sexp sexp-entry)
3141 (goto-char (point-min))
3142 (while (re-search-forward regexp nil t)
3143 (catch :skip
3144 (org-agenda-skip)
3145 (setq beg (match-beginning 0))
3146 (goto-char (1- (match-end 0)))
3147 (setq b (point))
3148 (forward-sexp 1)
3149 (setq sexp (buffer-substring b (point)))
3150 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
3151 (org-trim (match-string 1))
3152 ""))
3153 (setq result (org-diary-sexp-entry sexp sexp-entry date))
3154 (when result
3155 (setq marker (org-agenda-new-marker beg)
3156 category (org-get-category beg))
3158 (if (string-match "\\S-" result)
3159 (setq txt result)
3160 (setq txt "SEXP entry returned empty string"))
3162 (setq txt (org-format-agenda-item
3163 "" txt category tags 'time))
3164 (org-add-props txt props 'org-marker marker)
3165 (org-add-props txt nil
3166 'org-category category 'date date
3167 'type "sexp")
3168 (push txt ee))))
3169 (nreverse ee)))
3171 (defun org-agenda-get-closed ()
3172 "Return the logged TODO entries for agenda display."
3173 (let* ((props (list 'mouse-face 'highlight
3174 'org-not-done-regexp org-not-done-regexp
3175 'org-todo-regexp org-todo-regexp
3176 'keymap org-agenda-keymap
3177 'help-echo
3178 (format "mouse-2 or RET jump to org file %s"
3179 (abbreviate-file-name buffer-file-name))))
3180 (regexp (concat
3181 "\\<\\(" org-closed-string "\\|" org-clock-string "\\) *\\["
3182 (regexp-quote
3183 (substring
3184 (format-time-string
3185 (car org-time-stamp-formats)
3186 (apply 'encode-time ; DATE bound by calendar
3187 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
3188 1 11))))
3189 marker hdmarker priority category tags closedp
3190 ee txt timestr)
3191 (goto-char (point-min))
3192 (while (re-search-forward regexp nil t)
3193 (catch :skip
3194 (org-agenda-skip)
3195 (setq marker (org-agenda-new-marker (match-beginning 0))
3196 closedp (equal (match-string 1) org-closed-string)
3197 category (org-get-category (match-beginning 0))
3198 timestr (buffer-substring (match-beginning 0) (point-at-eol))
3199 ;; donep (org-entry-is-done-p)
3201 (if (string-match "\\]" timestr)
3202 ;; substring should only run to end of time stamp
3203 (setq timestr (substring timestr 0 (match-end 0))))
3204 (save-excursion
3205 (if (re-search-backward "^\\*+ " nil t)
3206 (progn
3207 (goto-char (match-beginning 0))
3208 (setq hdmarker (org-agenda-new-marker)
3209 tags (org-get-tags-at))
3210 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3211 (setq txt (org-format-agenda-item
3212 (if closedp "Closed: " "Clocked: ")
3213 (match-string 1) category tags timestr)))
3214 (setq txt org-agenda-no-heading-message))
3215 (setq priority 100000)
3216 (org-add-props txt props
3217 'org-marker marker 'org-hd-marker hdmarker 'face 'org-done
3218 'priority priority 'org-category category
3219 'type "closed" 'date date
3220 'undone-face 'org-warning 'done-face 'org-done)
3221 (push txt ee))
3222 (goto-char (point-at-eol))))
3223 (nreverse ee)))
3225 (defun org-agenda-get-deadlines ()
3226 "Return the deadline information for agenda display."
3227 (let* ((props (list 'mouse-face 'highlight
3228 'org-not-done-regexp org-not-done-regexp
3229 'org-todo-regexp org-todo-regexp
3230 'keymap org-agenda-keymap
3231 'help-echo
3232 (format "mouse-2 or RET jump to org file %s"
3233 (abbreviate-file-name buffer-file-name))))
3234 (regexp org-deadline-time-regexp)
3235 (todayp (equal date (calendar-current-date))) ; DATE bound by calendar
3236 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
3237 d2 diff dfrac wdays pos pos1 category tags
3238 ee txt head face s upcomingp donep timestr)
3239 (goto-char (point-min))
3240 (while (re-search-forward regexp nil t)
3241 (catch :skip
3242 (org-agenda-skip)
3243 (setq s (match-string 1)
3244 pos (1- (match-beginning 1))
3245 d2 (org-time-string-to-absolute
3246 (match-string 1) d1 'past
3247 org-agenda-repeating-timestamp-show-all)
3248 diff (- d2 d1)
3249 wdays (org-get-wdays s)
3250 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
3251 upcomingp (and todayp (> diff 0)))
3252 ;; When to show a deadline in the calendar:
3253 ;; If the expiration is within wdays warning time.
3254 ;; Past-due deadlines are only shown on the current date
3255 (if (or (and (<= diff wdays)
3256 (and todayp (not org-agenda-only-exact-dates)))
3257 (= diff 0))
3258 (save-excursion
3259 (setq category (org-get-category))
3260 (if (re-search-backward "^\\*+[ \t]+" nil t)
3261 (progn
3262 (goto-char (match-end 0))
3263 (setq pos1 (match-beginning 0))
3264 (setq tags (org-get-tags-at pos1))
3265 (setq head (buffer-substring-no-properties
3266 (point)
3267 (progn (skip-chars-forward "^\r\n")
3268 (point))))
3269 (setq donep (string-match org-looking-at-done-regexp head))
3270 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
3271 (setq timestr
3272 (concat (substring s (match-beginning 1)) " "))
3273 (setq timestr 'time))
3274 (if (and donep
3275 (or org-agenda-skip-deadline-if-done
3276 (not (= diff 0))))
3277 (setq txt nil)
3278 (setq txt (org-format-agenda-item
3279 (if (= diff 0)
3280 (car org-agenda-deadline-leaders)
3281 (if (functionp (nth 1 org-agenda-deadline-leaders))
3282 (funcall (nth 1 org-agenda-deadline-leaders) diff date)
3283 (format (nth 1 org-agenda-deadline-leaders)
3284 diff)))
3285 head category tags timestr))))
3286 (setq txt org-agenda-no-heading-message))
3287 (when txt
3288 (setq face (org-agenda-deadline-face dfrac wdays))
3289 (org-add-props txt props
3290 'org-marker (org-agenda-new-marker pos)
3291 'org-hd-marker (org-agenda-new-marker pos1)
3292 'priority (+ (- diff)
3293 (org-get-priority txt))
3294 'org-category category
3295 'type (if upcomingp "upcoming-deadline" "deadline")
3296 'date (if upcomingp date d2)
3297 'face (if donep 'org-done face)
3298 'undone-face face 'done-face 'org-done)
3299 (push txt ee))))))
3300 (nreverse ee)))
3302 (defun org-agenda-deadline-face (fraction &optional wdays)
3303 "Return the face to displaying a deadline item.
3304 FRACTION is what fraction of the head-warning time has passed."
3305 (if (equal wdays 0) (setq fraction 1.))
3306 (let ((faces org-agenda-deadline-faces) f)
3307 (catch 'exit
3308 (while (setq f (pop faces))
3309 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
3311 (defun org-agenda-get-scheduled ()
3312 "Return the scheduled information for agenda display."
3313 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3314 'org-todo-regexp org-todo-regexp
3315 'done-face 'org-done
3316 'mouse-face 'highlight
3317 'keymap org-agenda-keymap
3318 'help-echo
3319 (format "mouse-2 or RET jump to org file %s"
3320 (abbreviate-file-name buffer-file-name))))
3321 (regexp org-scheduled-time-regexp)
3322 (todayp (equal date (calendar-current-date))) ; DATE bound by calendar
3323 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
3324 d2 diff pos pos1 category tags
3325 ee txt head pastschedp donep face timestr s)
3326 (goto-char (point-min))
3327 (while (re-search-forward regexp nil t)
3328 (catch :skip
3329 (org-agenda-skip)
3330 (setq s (match-string 1)
3331 pos (1- (match-beginning 1))
3332 d2 (org-time-string-to-absolute
3333 (match-string 1) d1 'past
3334 org-agenda-repeating-timestamp-show-all)
3335 diff (- d2 d1))
3336 (setq pastschedp (and todayp (< diff 0)))
3337 ;; When to show a scheduled item in the calendar:
3338 ;; If it is on or past the date.
3339 (if (or (and (< diff 0)
3340 (< (abs diff) org-scheduled-past-days)
3341 (and todayp (not org-agenda-only-exact-dates)))
3342 (= diff 0))
3343 (save-excursion
3344 (setq category (org-get-category))
3345 (if (re-search-backward "^\\*+[ \t]+" nil t)
3346 (progn
3347 (goto-char (match-end 0))
3348 (setq pos1 (match-beginning 0))
3349 (setq tags (org-get-tags-at))
3350 (setq head (buffer-substring-no-properties
3351 (point)
3352 (progn (skip-chars-forward "^\r\n") (point))))
3353 (setq donep (string-match org-looking-at-done-regexp head))
3354 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
3355 (setq timestr
3356 (concat (substring s (match-beginning 1)) " "))
3357 (setq timestr 'time))
3358 (if (and donep
3359 (or org-agenda-skip-scheduled-if-done
3360 (not (= diff 0))))
3361 (setq txt nil)
3362 (setq txt (org-format-agenda-item
3363 (if (= diff 0)
3364 (car org-agenda-scheduled-leaders)
3365 (format (nth 1 org-agenda-scheduled-leaders)
3366 (- 1 diff)))
3367 head category tags timestr))))
3368 (setq txt org-agenda-no-heading-message))
3369 (when txt
3370 (setq face (if pastschedp
3371 'org-scheduled-previously
3372 'org-scheduled-today))
3373 (org-add-props txt props
3374 'undone-face face
3375 'face (if donep 'org-done face)
3376 'org-marker (org-agenda-new-marker pos)
3377 'org-hd-marker (org-agenda-new-marker pos1)
3378 'type (if pastschedp "past-scheduled" "scheduled")
3379 'date (if pastschedp d2 date)
3380 'priority (+ 94 (- 5 diff) (org-get-priority txt))
3381 'org-category category)
3382 (push txt ee))))))
3383 (nreverse ee)))
3385 (defun org-agenda-get-blocks ()
3386 "Return the date-range information for agenda display."
3387 (let* ((props (list 'face nil
3388 'org-not-done-regexp org-not-done-regexp
3389 'org-todo-regexp org-todo-regexp
3390 'mouse-face 'highlight
3391 'keymap org-agenda-keymap
3392 'help-echo
3393 (format "mouse-2 or RET jump to org file %s"
3394 (abbreviate-file-name buffer-file-name))))
3395 (regexp org-tr-regexp)
3396 (d0 (calendar-absolute-from-gregorian date))
3397 marker hdmarker ee txt d1 d2 s1 s2 timestr category tags pos
3398 donep head)
3399 (goto-char (point-min))
3400 (while (re-search-forward regexp nil t)
3401 (catch :skip
3402 (org-agenda-skip)
3403 (setq pos (point))
3404 (setq timestr (match-string 0)
3405 s1 (match-string 1)
3406 s2 (match-string 2)
3407 d1 (time-to-days (org-time-string-to-time s1))
3408 d2 (time-to-days (org-time-string-to-time s2)))
3409 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
3410 ;; Only allow days between the limits, because the normal
3411 ;; date stamps will catch the limits.
3412 (save-excursion
3413 (setq marker (org-agenda-new-marker (point)))
3414 (setq category (org-get-category))
3415 (if (re-search-backward "^\\*+ " nil t)
3416 (progn
3417 (goto-char (match-beginning 0))
3418 (setq hdmarker (org-agenda-new-marker (point)))
3419 (setq tags (org-get-tags-at))
3420 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3421 (setq head (match-string 1))
3422 (and org-agenda-skip-timestamp-if-done
3423 (org-entry-is-done-p)
3424 (throw :skip t))
3425 (setq txt (org-format-agenda-item
3426 (format (if (= d1 d2) "" "(%d/%d): ")
3427 (1+ (- d0 d1)) (1+ (- d2 d1)))
3428 head category tags
3429 (if (= d0 d1) timestr))))
3430 (setq txt org-agenda-no-heading-message))
3431 (org-add-props txt props
3432 'org-marker marker 'org-hd-marker hdmarker
3433 'type "block" 'date date
3434 'priority (org-get-priority txt) 'org-category category)
3435 (push txt ee)))
3436 (goto-char pos)))
3437 ;; Sort the entries by expiration date.
3438 (nreverse ee)))
3440 ;;; Agenda presentation and sorting
3442 (defvar org-prefix-has-time nil
3443 "A flag, set by `org-compile-prefix-format'.
3444 The flag is set if the currently compiled format contains a `%t'.")
3445 (defvar org-prefix-has-tag nil
3446 "A flag, set by `org-compile-prefix-format'.
3447 The flag is set if the currently compiled format contains a `%T'.")
3449 (defun org-format-agenda-item (extra txt &optional category tags dotime
3450 noprefix remove-re)
3451 "Format TXT to be inserted into the agenda buffer.
3452 In particular, it adds the prefix and corresponding text properties. EXTRA
3453 must be a string and replaces the `%s' specifier in the prefix format.
3454 CATEGORY (string, symbol or nil) may be used to overrule the default
3455 category taken from local variable or file name. It will replace the `%c'
3456 specifier in the format. DOTIME, when non-nil, indicates that a
3457 time-of-day should be extracted from TXT for sorting of this entry, and for
3458 the `%t' specifier in the format. When DOTIME is a string, this string is
3459 searched for a time before TXT is. NOPREFIX is a flag and indicates that
3460 only the correctly processes TXT should be returned - this is used by
3461 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
3462 Any match of REMOVE-RE will be removed from TXT."
3463 (save-match-data
3464 ;; Diary entries sometimes have extra whitespace at the beginning
3465 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
3466 (let* ((category (or category
3467 org-category
3468 (if buffer-file-name
3469 (file-name-sans-extension
3470 (file-name-nondirectory buffer-file-name))
3471 "")))
3472 (tag (if tags (nth (1- (length tags)) tags) ""))
3473 time ; time and tag are needed for the eval of the prefix format
3474 (ts (if dotime (concat (if (stringp dotime) dotime "") txt)))
3475 (time-of-day (and dotime (org-get-time-of-day ts)))
3476 stamp plain s0 s1 s2 rtn srp)
3477 (when (and dotime time-of-day org-prefix-has-time)
3478 ;; Extract starting and ending time and move them to prefix
3479 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
3480 (setq plain (string-match org-plain-time-of-day-regexp ts)))
3481 (setq s0 (match-string 0 ts)
3482 srp (and stamp (match-end 3))
3483 s1 (match-string (if plain 1 2) ts)
3484 s2 (match-string (if plain 8 (if srp 4 6)) ts))
3486 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
3487 ;; them, we might want to remove them there to avoid duplication.
3488 ;; The user can turn this off with a variable.
3489 (if (and org-agenda-remove-times-when-in-prefix (or stamp plain)
3490 (string-match (concat (regexp-quote s0) " *") txt)
3491 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
3492 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
3493 (= (match-beginning 0) 0)
3495 (setq txt (replace-match "" nil nil txt))))
3496 ;; Normalize the time(s) to 24 hour
3497 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
3498 (if s2 (setq s2 (org-get-time-of-day s2 'string t))))
3500 (when (and s1 (not s2) org-agenda-default-appointment-duration
3501 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
3502 (let ((m (+ (string-to-number (match-string 2 s1))
3503 (* 60 (string-to-number (match-string 1 s1)))
3504 org-agenda-default-appointment-duration))
3506 (setq h (/ m 60) m (- m (* h 60)))
3507 (setq s2 (format "%02d:%02d" h m))))
3509 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
3510 txt)
3511 ;; Tags are in the string
3512 (if (or (eq org-agenda-remove-tags t)
3513 (and org-agenda-remove-tags
3514 org-prefix-has-tag))
3515 (setq txt (replace-match "" t t txt))
3516 (setq txt (replace-match
3517 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
3518 (match-string 2 txt))
3519 t t txt))))
3521 (when remove-re
3522 (while (string-match remove-re txt)
3523 (setq txt (replace-match "" t t txt))))
3525 ;; Create the final string
3526 (if noprefix
3527 (setq rtn txt)
3528 ;; Prepare the variables needed in the eval of the compiled format
3529 (setq time (cond (s2 (concat s1 "-" s2))
3530 (s1 (concat s1 "......"))
3531 (t ""))
3532 extra (or extra "")
3533 category (if (symbolp category) (symbol-name category) category))
3534 ;; Evaluate the compiled format
3535 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
3537 ;; And finally add the text properties
3538 (org-add-props rtn nil
3539 'org-category (downcase category) 'tags tags
3540 'org-highest-priority org-highest-priority
3541 'org-lowest-priority org-lowest-priority
3542 'prefix-length (- (length rtn) (length txt))
3543 'time-of-day time-of-day
3544 'txt txt
3545 'time time
3546 'extra extra
3547 'dotime dotime))))
3549 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
3550 (defvar org-agenda-sorting-strategy-selected nil)
3552 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
3553 (catch 'exit
3554 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
3555 ((and todayp (member 'today (car org-agenda-time-grid))))
3556 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
3557 ((member 'weekly (car org-agenda-time-grid)))
3558 (t (throw 'exit list)))
3559 (let* ((have (delq nil (mapcar
3560 (lambda (x) (get-text-property 1 'time-of-day x))
3561 list)))
3562 (string (nth 1 org-agenda-time-grid))
3563 (gridtimes (nth 2 org-agenda-time-grid))
3564 (req (car org-agenda-time-grid))
3565 (remove (member 'remove-match req))
3566 new time)
3567 (if (and (member 'require-timed req) (not have))
3568 ;; don't show empty grid
3569 (throw 'exit list))
3570 (while (setq time (pop gridtimes))
3571 (unless (and remove (member time have))
3572 (setq time (int-to-string time))
3573 (push (org-format-agenda-item
3574 nil string "" nil
3575 (concat (substring time 0 -2) ":" (substring time -2)))
3576 new)
3577 (put-text-property
3578 1 (length (car new)) 'face 'org-time-grid (car new))))
3579 (if (member 'time-up org-agenda-sorting-strategy-selected)
3580 (append new list)
3581 (append list new)))))
3583 (defun org-compile-prefix-format (key)
3584 "Compile the prefix format into a Lisp form that can be evaluated.
3585 The resulting form is returned and stored in the variable
3586 `org-prefix-format-compiled'."
3587 (setq org-prefix-has-time nil org-prefix-has-tag nil)
3588 (let ((s (cond
3589 ((stringp org-agenda-prefix-format)
3590 org-agenda-prefix-format)
3591 ((assq key org-agenda-prefix-format)
3592 (cdr (assq key org-agenda-prefix-format)))
3593 (t " %-12:c%?-12t% s")))
3594 (start 0)
3595 varform vars var e c f opt)
3596 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cts]\\)"
3597 s start)
3598 (setq var (cdr (assoc (match-string 4 s)
3599 '(("c" . category) ("t" . time) ("s" . extra)
3600 ("T" . tag))))
3601 c (or (match-string 3 s) "")
3602 opt (match-beginning 1)
3603 start (1+ (match-beginning 0)))
3604 (if (equal var 'time) (setq org-prefix-has-time t))
3605 (if (equal var 'tag) (setq org-prefix-has-tag t))
3606 (setq f (concat "%" (match-string 2 s) "s"))
3607 (if opt
3608 (setq varform
3609 `(if (equal "" ,var)
3611 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
3612 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c)))))
3613 (setq s (replace-match "%s" t nil s))
3614 (push varform vars))
3615 (setq vars (nreverse vars))
3616 (setq org-prefix-format-compiled `(format ,s ,@vars))))
3618 (defun org-set-sorting-strategy (key)
3619 (if (symbolp (car org-agenda-sorting-strategy))
3620 ;; the old format
3621 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
3622 (setq org-agenda-sorting-strategy-selected
3623 (or (cdr (assq key org-agenda-sorting-strategy))
3624 (cdr (assq 'agenda org-agenda-sorting-strategy))
3625 '(time-up category-keep priority-down)))))
3627 (defun org-get-time-of-day (s &optional string mod24)
3628 "Check string S for a time of day.
3629 If found, return it as a military time number between 0 and 2400.
3630 If not found, return nil.
3631 The optional STRING argument forces conversion into a 5 character wide string
3632 HH:MM."
3633 (save-match-data
3634 (when
3635 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
3636 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
3637 (let* ((h (string-to-number (match-string 1 s)))
3638 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
3639 (ampm (if (match-end 4) (downcase (match-string 4 s))))
3640 (am-p (equal ampm "am"))
3641 (h1 (cond ((not ampm) h)
3642 ((= h 12) (if am-p 0 12))
3643 (t (+ h (if am-p 0 12)))))
3644 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
3645 (mod h1 24) h1))
3646 (t0 (+ (* 100 h2) m))
3647 (t1 (concat (if (>= h1 24) "+" " ")
3648 (if (< t0 100) "0" "")
3649 (if (< t0 10) "0" "")
3650 (int-to-string t0))))
3651 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
3653 (defun org-finalize-agenda-entries (list &optional nosort)
3654 "Sort and concatenate the agenda items."
3655 (setq list (mapcar 'org-agenda-highlight-todo list))
3656 (if nosort
3657 list
3658 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
3660 (defun org-agenda-highlight-todo (x)
3661 (let (re pl)
3662 (if (eq x 'line)
3663 (save-excursion
3664 (beginning-of-line 1)
3665 (setq re (get-text-property (point) 'org-todo-regexp))
3666 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length) 0)))
3667 (when (looking-at (concat "[ \t]*\\.*" re " +"))
3668 (add-text-properties (match-beginning 0) (match-end 0)
3669 (list 'face (org-get-todo-face 0)))
3670 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
3671 (delete-region (match-beginning 1) (1- (match-end 0)))
3672 (goto-char (match-beginning 1))
3673 (insert (format org-agenda-todo-keyword-format s)))))
3674 (setq re (concat (get-text-property 0 'org-todo-regexp x))
3675 pl (get-text-property 0 'prefix-length x))
3676 (when (and re
3677 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
3678 x (or pl 0)) pl))
3679 (add-text-properties
3680 (or (match-end 1) (match-end 0)) (match-end 0)
3681 (list 'face (org-get-todo-face (match-string 2 x)))
3683 (setq x (concat (substring x 0 (match-end 1))
3684 (format org-agenda-todo-keyword-format
3685 (match-string 2 x))
3687 (substring x (match-end 3)))))
3688 x)))
3690 (defsubst org-cmp-priority (a b)
3691 "Compare the priorities of string A and B."
3692 (let ((pa (or (get-text-property 1 'priority a) 0))
3693 (pb (or (get-text-property 1 'priority b) 0)))
3694 (cond ((> pa pb) +1)
3695 ((< pa pb) -1)
3696 (t nil))))
3698 (defsubst org-cmp-category (a b)
3699 "Compare the string values of categories of strings A and B."
3700 (let ((ca (or (get-text-property 1 'org-category a) ""))
3701 (cb (or (get-text-property 1 'org-category b) "")))
3702 (cond ((string-lessp ca cb) -1)
3703 ((string-lessp cb ca) +1)
3704 (t nil))))
3706 (defsubst org-cmp-tag (a b)
3707 "Compare the string values of categories of strings A and B."
3708 (let ((ta (car (last (get-text-property 1 'tags a))))
3709 (tb (car (last (get-text-property 1 'tags b)))))
3710 (cond ((not ta) +1)
3711 ((not tb) -1)
3712 ((string-lessp ta tb) -1)
3713 ((string-lessp tb ta) +1)
3714 (t nil))))
3716 (defsubst org-cmp-time (a b)
3717 "Compare the time-of-day values of strings A and B."
3718 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
3719 (ta (or (get-text-property 1 'time-of-day a) def))
3720 (tb (or (get-text-property 1 'time-of-day b) def)))
3721 (cond ((< ta tb) -1)
3722 ((< tb ta) +1)
3723 (t nil))))
3725 (defun org-entries-lessp (a b)
3726 "Predicate for sorting agenda entries."
3727 ;; The following variables will be used when the form is evaluated.
3728 ;; So even though the compiler complains, keep them.
3729 (let* ((time-up (org-cmp-time a b))
3730 (time-down (if time-up (- time-up) nil))
3731 (priority-up (org-cmp-priority a b))
3732 (priority-down (if priority-up (- priority-up) nil))
3733 (category-up (org-cmp-category a b))
3734 (category-down (if category-up (- category-up) nil))
3735 (category-keep (if category-up +1 nil))
3736 (tag-up (org-cmp-tag a b))
3737 (tag-down (if tag-up (- tag-up) nil)))
3738 (cdr (assoc
3739 (eval (cons 'or org-agenda-sorting-strategy-selected))
3740 '((-1 . t) (1 . nil) (nil . nil))))))
3742 ;;; Agenda restriction lock
3744 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
3745 "Overlay to mark the headline to which arenda commands are restricted.")
3746 (org-overlay-put org-agenda-restriction-lock-overlay
3747 'face 'org-agenda-restriction-lock)
3748 (org-overlay-put org-agenda-restriction-lock-overlay
3749 'help-echo "Agendas are currently limited to this subtree.")
3750 (org-detach-overlay org-agenda-restriction-lock-overlay)
3752 (defun org-agenda-set-restriction-lock (&optional type)
3753 "Set restriction lock for agenda, to current subtree or file.
3754 Restriction will be the file if TYPE is `file', or if type is the
3755 universal prefix '(4), or if the cursor is before the first headline
3756 in the file. Otherwise, restriction will be to the current subtree."
3757 (interactive "P")
3758 (and (equal type '(4)) (setq type 'file))
3759 (setq type (cond
3760 (type type)
3761 ((org-at-heading-p) 'subtree)
3762 ((condition-case nil (org-back-to-heading t) (error nil))
3763 'subtree)
3764 (t 'file)))
3765 (if (eq type 'subtree)
3766 (progn
3767 (setq org-agenda-restrict t)
3768 (setq org-agenda-overriding-restriction 'subtree)
3769 (put 'org-agenda-files 'org-restrict
3770 (list (buffer-file-name (buffer-base-buffer))))
3771 (org-back-to-heading t)
3772 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
3773 (move-marker org-agenda-restrict-begin (point))
3774 (move-marker org-agenda-restrict-end
3775 (save-excursion (org-end-of-subtree t)))
3776 (message "Locking agenda restriction to subtree"))
3777 (put 'org-agenda-files 'org-restrict
3778 (list (buffer-file-name (buffer-base-buffer))))
3779 (setq org-agenda-restrict nil)
3780 (setq org-agenda-overriding-restriction 'file)
3781 (move-marker org-agenda-restrict-begin nil)
3782 (move-marker org-agenda-restrict-end nil)
3783 (message "Locking agenda restriction to file"))
3784 (setq current-prefix-arg nil)
3785 (org-agenda-maybe-redo))
3787 (defun org-agenda-remove-restriction-lock (&optional noupdate)
3788 "Remove the agenda restriction lock."
3789 (interactive "P")
3790 (org-detach-overlay org-agenda-restriction-lock-overlay)
3791 (org-detach-overlay org-speedbar-restriction-lock-overlay)
3792 (setq org-agenda-overriding-restriction nil)
3793 (setq org-agenda-restrict nil)
3794 (put 'org-agenda-files 'org-restrict nil)
3795 (move-marker org-agenda-restrict-begin nil)
3796 (move-marker org-agenda-restrict-end nil)
3797 (setq current-prefix-arg nil)
3798 (message "Agenda restriction lock removed")
3799 (or noupdate (org-agenda-maybe-redo)))
3801 (defun org-agenda-maybe-redo ()
3802 "If there is any window showing the agenda view, update it."
3803 (let ((w (get-buffer-window org-agenda-buffer-name t))
3804 (w0 (selected-window)))
3805 (when w
3806 (select-window w)
3807 (org-agenda-redo)
3808 (select-window w0)
3809 (if org-agenda-overriding-restriction
3810 (message "Agenda view shifted to new %s restriction"
3811 org-agenda-overriding-restriction)
3812 (message "Agenda restriction lock removed")))))
3814 ;;; Agenda commands
3816 (defun org-agenda-check-type (error &rest types)
3817 "Check if agenda buffer is of allowed type.
3818 If ERROR is non-nil, throw an error, otherwise just return nil."
3819 (if (memq org-agenda-type types)
3821 (if error
3822 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
3823 nil)))
3825 (defun org-agenda-quit ()
3826 "Exit agenda by removing the window or the buffer."
3827 (interactive)
3828 (let ((buf (current-buffer)))
3829 (if (not (one-window-p)) (delete-window))
3830 (kill-buffer buf)
3831 (org-agenda-reset-markers)
3832 (org-columns-remove-overlays))
3833 ;; Maybe restore the pre-agenda window configuration.
3834 (and org-agenda-restore-windows-after-quit
3835 (not (eq org-agenda-window-setup 'other-frame))
3836 org-pre-agenda-window-conf
3837 (set-window-configuration org-pre-agenda-window-conf)))
3839 (defun org-agenda-exit ()
3840 "Exit agenda by removing the window or the buffer.
3841 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
3842 Org-mode buffers visited directly by the user will not be touched."
3843 (interactive)
3844 (org-release-buffers org-agenda-new-buffers)
3845 (setq org-agenda-new-buffers nil)
3846 (org-agenda-quit))
3848 (defun org-agenda-execute (arg)
3849 "Execute another agenda command, keeping same window.\\<global-map>
3850 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
3851 (interactive "P")
3852 (let ((org-agenda-window-setup 'current-window))
3853 (org-agenda arg)))
3855 (defun org-save-all-org-buffers ()
3856 "Save all Org-mode buffers without user confirmation."
3857 (interactive)
3858 (message "Saving all Org-mode buffers...")
3859 (save-some-buffers t 'org-mode-p)
3860 (message "Saving all Org-mode buffers... done"))
3862 (defun org-agenda-redo ()
3863 "Rebuild Agenda.
3864 When this is the global TODO list, a prefix argument will be interpreted."
3865 (interactive)
3866 (let* ((org-agenda-keep-modes t)
3867 (line (org-current-line))
3868 (window-line (- line (org-current-line (window-start))))
3869 (lprops (get 'org-agenda-redo-command 'org-lprops)))
3870 (message "Rebuilding agenda buffer...")
3871 (org-let lprops '(eval org-agenda-redo-command))
3872 (setq org-agenda-undo-list nil
3873 org-agenda-pending-undo-list nil)
3874 (message "Rebuilding agenda buffer...done")
3875 (goto-line line)
3876 (recenter window-line)))
3878 (defun org-agenda-manipulate-query-add ()
3879 "Manipulate the query by adding a search term with positive selection.
3880 Positive selection means, the term must be matched for selection of an entry."
3881 (interactive)
3882 (org-agenda-manipulate-query ?\[))
3883 (defun org-agenda-manipulate-query-subtract ()
3884 "Manipulate the query by adding a search term with negative selection.
3885 Negative selection means, term must not be matched for selection of an entry."
3886 (interactive)
3887 (org-agenda-manipulate-query ?\]))
3888 (defun org-agenda-manipulate-query-add-re ()
3889 "Manipulate the query by adding a search regexp with positive selection.
3890 Positive selection means, the regexp must match for selection of an entry."
3891 (interactive)
3892 (org-agenda-manipulate-query ?\{))
3893 (defun org-agenda-manipulate-query-subtract-re ()
3894 "Manipulate the query by adding a search regexp with negative selection.
3895 Negative selection means, regexp must not match for selection of an entry."
3896 (interactive)
3897 (org-agenda-manipulate-query ?\}))
3898 (defun org-agenda-manipulate-query (char)
3899 (cond
3900 ((eq org-agenda-type 'search)
3901 (org-add-to-string
3902 'org-agenda-query-string
3903 (cdr (assoc char '((?\[ . " +") (?\] . " -")
3904 (?\{ . " +{}") (?\} . " -{}")))))
3905 (setq org-agenda-redo-command
3906 (list 'org-search-view
3907 org-todo-only
3908 org-agenda-query-string
3909 (+ (length org-agenda-query-string)
3910 (if (member char '(?\{ ?\})) 0 1))))
3911 (set-register org-agenda-query-register org-agenda-query-string)
3912 (org-agenda-redo))
3913 (t (error "Canot manipulate query for %s-type agenda buffers"
3914 org-agenda-type))))
3916 (defun org-add-to-string (var string)
3917 (set var (concat (symbol-value var) string)))
3919 (defun org-agenda-goto-date (date)
3920 "Jump to DATE in agenda."
3921 (interactive (list (org-read-date)))
3922 (org-agenda-list nil date))
3924 (defun org-agenda-goto-today ()
3925 "Go to today."
3926 (interactive)
3927 (org-agenda-check-type t 'timeline 'agenda)
3928 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
3929 (cond
3930 (tdpos (goto-char tdpos))
3931 ((eq org-agenda-type 'agenda)
3932 (let* ((sd (time-to-days
3933 (time-subtract (current-time)
3934 (list 0 (* 3600 org-extend-today-until) 0))))
3935 (comp (org-agenda-compute-time-span sd org-agenda-span))
3936 (org-agenda-overriding-arguments org-agenda-last-arguments))
3937 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
3938 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
3939 (org-agenda-redo)
3940 (org-agenda-find-same-or-today-or-agenda)))
3941 (t (error "Cannot find today")))))
3943 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
3944 (goto-char
3945 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
3946 (text-property-any (point-min) (point-max) 'org-today t)
3947 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
3948 (point-min))))
3950 (defun org-agenda-later (arg)
3951 "Go forward in time by thee current span.
3952 With prefix ARG, go forward that many times the current span."
3953 (interactive "p")
3954 (org-agenda-check-type t 'agenda)
3955 (let* ((span org-agenda-span)
3956 (sd org-starting-day)
3957 (greg (calendar-gregorian-from-absolute sd))
3958 (cnt (get-text-property (point) 'org-day-cnt))
3959 greg2 nd)
3960 (cond
3961 ((eq span 'day)
3962 (setq sd (+ arg sd) nd 1))
3963 ((eq span 'week)
3964 (setq sd (+ (* 7 arg) sd) nd 7))
3965 ((eq span 'month)
3966 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
3967 sd (calendar-absolute-from-gregorian greg2))
3968 (setcar greg2 (1+ (car greg2)))
3969 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
3970 ((eq span 'year)
3971 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
3972 sd (calendar-absolute-from-gregorian greg2))
3973 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
3974 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
3975 (let ((org-agenda-overriding-arguments
3976 (list (car org-agenda-last-arguments) sd nd t)))
3977 (org-agenda-redo)
3978 (org-agenda-find-same-or-today-or-agenda cnt))))
3980 (defun org-agenda-earlier (arg)
3981 "Go backward in time by the current span.
3982 With prefix ARG, go backward that many times the current span."
3983 (interactive "p")
3984 (org-agenda-later (- arg)))
3986 (defun org-agenda-day-view (&optional day-of-year)
3987 "Switch to daily view for agenda.
3988 With argument DAY-OF-YEAR, switch to that day of the year."
3989 (interactive "P")
3990 (setq org-agenda-ndays 1)
3991 (org-agenda-change-time-span 'day day-of-year))
3992 (defun org-agenda-week-view (&optional iso-week)
3993 "Switch to daily view for agenda.
3994 With argument ISO-WEEK, switch to the corresponding ISO week.
3995 If ISO-WEEK has more then 2 digits, only the last two encode the
3996 week. Any digits before this encode a year. So 200712 means
3997 week 12 of year 2007. Years in the range 1938-2037 can also be
3998 written as 2-digit years."
3999 (interactive "P")
4000 (setq org-agenda-ndays 7)
4001 (org-agenda-change-time-span 'week iso-week))
4002 (defun org-agenda-month-view (&optional month)
4003 "Switch to daily view for agenda.
4004 With argument MONTH, switch to that month."
4005 (interactive "P")
4006 (org-agenda-change-time-span 'month month))
4007 (defun org-agenda-year-view (&optional year)
4008 "Switch to daily view for agenda.
4009 With argument YEAR, switch to that year.
4010 If MONTH has more then 2 digits, only the last two encode the
4011 month. Any digits before this encode a year. So 200712 means
4012 December year 2007. Years in the range 1938-2037 can also be
4013 written as 2-digit years."
4014 (interactive "P")
4015 (when year
4016 (setq year (org-small-year-to-year year)))
4017 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4018 (org-agenda-change-time-span 'year year)
4019 (error "Abort")))
4021 (defun org-agenda-change-time-span (span &optional n)
4022 "Change the agenda view to SPAN.
4023 SPAN may be `day', `week', `month', `year'."
4024 (org-agenda-check-type t 'agenda)
4025 (if (and (not n) (equal org-agenda-span span))
4026 (error "Viewing span is already \"%s\"" span))
4027 (let* ((sd (or (get-text-property (point) 'day)
4028 org-starting-day))
4029 (computed (org-agenda-compute-time-span sd span n))
4030 (org-agenda-overriding-arguments
4031 (list (car org-agenda-last-arguments)
4032 (car computed) (cdr computed) t)))
4033 (org-agenda-redo)
4034 (org-agenda-find-same-or-today-or-agenda))
4035 (org-agenda-set-mode-name)
4036 (message "Switched to %s view" span))
4038 (defun org-agenda-compute-time-span (sd span &optional n)
4039 "Compute starting date and number of days for agenda.
4040 SPAN may be `day', `week', `month', `year'. The return value
4041 is a cons cell with the starting date and the number of days,
4042 so that the date SD will be in that range."
4043 (let* ((greg (calendar-gregorian-from-absolute sd))
4044 (dg (nth 1 greg))
4045 (mg (car greg))
4046 (yg (nth 2 greg))
4047 nd w1 y1 m1 thisweek)
4048 (cond
4049 ((eq span 'day)
4050 (when n
4051 (setq sd (+ (calendar-absolute-from-gregorian
4052 (list mg 1 yg))
4053 n -1)))
4054 (setq nd 1))
4055 ((eq span 'week)
4056 (let* ((nt (calendar-day-of-week
4057 (calendar-gregorian-from-absolute sd)))
4058 (d (if org-agenda-start-on-weekday
4059 (- nt org-agenda-start-on-weekday)
4060 0)))
4061 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
4062 (when n
4063 (require 'cal-iso)
4064 (setq thisweek (car (calendar-iso-from-absolute sd)))
4065 (when (> n 99)
4066 (setq y1 (org-small-year-to-year (/ n 100))
4067 n (mod n 100)))
4068 (setq sd
4069 (calendar-absolute-from-iso
4070 (list n 1
4071 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
4072 (setq nd 7)))
4073 ((eq span 'month)
4074 (when (and n (> n 99))
4075 (setq y1 (org-small-year-to-year (/ n 100))
4076 n (mod n 100)))
4077 (setq sd (calendar-absolute-from-gregorian
4078 (list (or n mg) 1 (or y1 yg)))
4079 nd (- (calendar-absolute-from-gregorian
4080 (list (1+ (or n mg)) 1 (or y1 yg)))
4081 sd)))
4082 ((eq span 'year)
4083 (setq sd (calendar-absolute-from-gregorian
4084 (list 1 1 (or n yg)))
4085 nd (- (calendar-absolute-from-gregorian
4086 (list 1 1 (1+ (or n yg))))
4087 sd))))
4088 (cons sd nd)))
4090 (defun org-agenda-next-date-line (&optional arg)
4091 "Jump to the next line indicating a date in agenda buffer."
4092 (interactive "p")
4093 (org-agenda-check-type t 'agenda 'timeline)
4094 (beginning-of-line 1)
4095 ;; This does not work if user makes date format that starts with a blank
4096 (if (looking-at "^\\S-") (forward-char 1))
4097 (if (not (re-search-forward "^\\S-" nil t arg))
4098 (progn
4099 (backward-char 1)
4100 (error "No next date after this line in this buffer")))
4101 (goto-char (match-beginning 0)))
4103 (defun org-agenda-previous-date-line (&optional arg)
4104 "Jump to the previous line indicating a date in agenda buffer."
4105 (interactive "p")
4106 (org-agenda-check-type t 'agenda 'timeline)
4107 (beginning-of-line 1)
4108 (if (not (re-search-backward "^\\S-" nil t arg))
4109 (error "No previous date before this line in this buffer")))
4111 ;; Initialize the highlight
4112 (defvar org-hl (org-make-overlay 1 1))
4113 (org-overlay-put org-hl 'face 'highlight)
4115 (defun org-highlight (begin end &optional buffer)
4116 "Highlight a region with overlay."
4117 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
4118 org-hl begin end (or buffer (current-buffer))))
4120 (defun org-unhighlight ()
4121 "Detach overlay INDEX."
4122 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
4124 ;; FIXME this is currently not used.
4125 (defun org-highlight-until-next-command (beg end &optional buffer)
4126 "Move the highlight overlay to BEG/END, remove it before the next command."
4127 (org-highlight beg end buffer)
4128 (add-hook 'pre-command-hook 'org-unhighlight-once))
4129 (defun org-unhighlight-once ()
4130 "Remove the highlight from its position, and this function from the hook."
4131 (remove-hook 'pre-command-hook 'org-unhighlight-once)
4132 (org-unhighlight))
4134 (defun org-agenda-follow-mode ()
4135 "Toggle follow mode in an agenda buffer."
4136 (interactive)
4137 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
4138 (org-agenda-set-mode-name)
4139 (message "Follow mode is %s"
4140 (if org-agenda-follow-mode "on" "off")))
4142 (defun org-agenda-clockreport-mode ()
4143 "Toggle clocktable mode in an agenda buffer."
4144 (interactive)
4145 (org-agenda-check-type t 'agenda)
4146 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
4147 (org-agenda-set-mode-name)
4148 (org-agenda-redo)
4149 (message "Clocktable mode is %s"
4150 (if org-agenda-clockreport-mode "on" "off")))
4152 (defun org-agenda-log-mode ()
4153 "Toggle log mode in an agenda buffer."
4154 (interactive)
4155 (org-agenda-check-type t 'agenda 'timeline)
4156 (setq org-agenda-show-log (not org-agenda-show-log))
4157 (org-agenda-set-mode-name)
4158 (org-agenda-redo)
4159 (message "Log mode is %s"
4160 (if org-agenda-show-log "on" "off")))
4162 (defun org-agenda-toggle-diary ()
4163 "Toggle diary inclusion in an agenda buffer."
4164 (interactive)
4165 (org-agenda-check-type t 'agenda)
4166 (setq org-agenda-include-diary (not org-agenda-include-diary))
4167 (org-agenda-redo)
4168 (org-agenda-set-mode-name)
4169 (message "Diary inclusion turned %s"
4170 (if org-agenda-include-diary "on" "off")))
4172 (defun org-agenda-toggle-time-grid ()
4173 "Toggle time grid in an agenda buffer."
4174 (interactive)
4175 (org-agenda-check-type t 'agenda)
4176 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
4177 (org-agenda-redo)
4178 (org-agenda-set-mode-name)
4179 (message "Time-grid turned %s"
4180 (if org-agenda-use-time-grid "on" "off")))
4182 (defun org-agenda-set-mode-name ()
4183 "Set the mode name to indicate all the small mode settings."
4184 (setq mode-name
4185 (concat "Org-Agenda"
4186 (if (equal org-agenda-ndays 1) " Day" "")
4187 (if (equal org-agenda-ndays 7) " Week" "")
4188 (if org-agenda-follow-mode " Follow" "")
4189 (if org-agenda-include-diary " Diary" "")
4190 (if org-agenda-use-time-grid " Grid" "")
4191 (if org-agenda-show-log " Log" "")
4192 (if org-agenda-clockreport-mode " Clock" "")))
4193 (force-mode-line-update))
4195 (defun org-agenda-post-command-hook ()
4196 (and (eolp) (not (bolp)) (backward-char 1))
4197 (setq org-agenda-type (get-text-property (point) 'org-agenda-type))
4198 (if (and org-agenda-follow-mode
4199 (get-text-property (point) 'org-marker))
4200 (org-agenda-show)))
4202 (defun org-agenda-show-priority ()
4203 "Show the priority of the current item.
4204 This priority is composed of the main priority given with the [#A] cookies,
4205 and by additional input from the age of a schedules or deadline entry."
4206 (interactive)
4207 (let* ((pri (get-text-property (point-at-bol) 'priority)))
4208 (message "Priority is %d" (if pri pri -1000))))
4210 (defun org-agenda-show-tags ()
4211 "Show the tags applicable to the current item."
4212 (interactive)
4213 (let* ((tags (get-text-property (point-at-bol) 'tags)))
4214 (if tags
4215 (message "Tags are :%s:"
4216 (org-no-properties (mapconcat 'identity tags ":")))
4217 (message "No tags associated with this line"))))
4219 (defun org-agenda-goto (&optional highlight)
4220 "Go to the Org-mode file which contains the item at point."
4221 (interactive)
4222 (let* ((marker (or (get-text-property (point) 'org-marker)
4223 (org-agenda-error)))
4224 (buffer (marker-buffer marker))
4225 (pos (marker-position marker)))
4226 (switch-to-buffer-other-window buffer)
4227 (widen)
4228 (goto-char pos)
4229 (when (org-mode-p)
4230 (org-show-context 'agenda)
4231 (save-excursion
4232 (and (outline-next-heading)
4233 (org-flag-heading nil)))) ; show the next heading
4234 (recenter (/ (window-height) 2))
4235 (run-hooks 'org-agenda-after-show-hook)
4236 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
4238 (defvar org-agenda-after-show-hook nil
4239 "Normal hook run after an item has been shown from the agenda.
4240 Point is in the buffer where the item originated.")
4242 (defun org-agenda-kill ()
4243 "Kill the entry or subtree belonging to the current agenda entry."
4244 (interactive)
4245 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
4246 (let* ((marker (or (get-text-property (point) 'org-marker)
4247 (org-agenda-error)))
4248 (buffer (marker-buffer marker))
4249 (pos (marker-position marker))
4250 (type (get-text-property (point) 'type))
4251 dbeg dend (n 0) conf)
4252 (org-with-remote-undo buffer
4253 (with-current-buffer buffer
4254 (save-excursion
4255 (goto-char pos)
4256 (if (and (org-mode-p) (not (member type '("sexp"))))
4257 (setq dbeg (progn (org-back-to-heading t) (point))
4258 dend (org-end-of-subtree t t))
4259 (setq dbeg (point-at-bol)
4260 dend (min (point-max) (1+ (point-at-eol)))))
4261 (goto-char dbeg)
4262 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
4263 (setq conf (or (eq t org-agenda-confirm-kill)
4264 (and (numberp org-agenda-confirm-kill)
4265 (> n org-agenda-confirm-kill))))
4266 (and conf
4267 (not (y-or-n-p
4268 (format "Delete entry with %d lines in buffer \"%s\"? "
4269 n (buffer-name buffer))))
4270 (error "Abort"))
4271 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
4272 (with-current-buffer buffer (delete-region dbeg dend))
4273 (message "Agenda item and source killed"))))
4275 (defun org-agenda-archive ()
4276 "Kill the entry or subtree belonging to the current agenda entry."
4277 (interactive)
4278 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
4279 (let* ((marker (or (get-text-property (point) 'org-marker)
4280 (org-agenda-error)))
4281 (buffer (marker-buffer marker))
4282 (pos (marker-position marker)))
4283 (org-with-remote-undo buffer
4284 (with-current-buffer buffer
4285 (if (org-mode-p)
4286 (save-excursion
4287 (goto-char pos)
4288 (org-remove-subtree-entries-from-agenda)
4289 (org-back-to-heading t)
4290 (org-archive-subtree))
4291 (error "Archiving works only in Org-mode files"))))))
4293 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
4294 "Remove all lines in the agenda that correspond to a given subtree.
4295 The subtree is the one in buffer BUF, starting at BEG and ending at END.
4296 If this information is not given, the function uses the tree at point."
4297 (let ((buf (or buf (current-buffer))) m p)
4298 (save-excursion
4299 (unless (and beg end)
4300 (org-back-to-heading t)
4301 (setq beg (point))
4302 (org-end-of-subtree t)
4303 (setq end (point)))
4304 (set-buffer (get-buffer org-agenda-buffer-name))
4305 (save-excursion
4306 (goto-char (point-max))
4307 (beginning-of-line 1)
4308 (while (not (bobp))
4309 (when (and (setq m (get-text-property (point) 'org-marker))
4310 (equal buf (marker-buffer m))
4311 (setq p (marker-position m))
4312 (>= p beg)
4313 (<= p end))
4314 (let ((inhibit-read-only t))
4315 (delete-region (point-at-bol) (1+ (point-at-eol)))))
4316 (beginning-of-line 0))))))
4318 (defun org-agenda-open-link ()
4319 "Follow the link in the current line, if any."
4320 (interactive)
4321 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local)
4322 (save-excursion
4323 (save-restriction
4324 (narrow-to-region (point-at-bol) (point-at-eol))
4325 (org-open-at-point))))
4327 (defun org-agenda-copy-local-variable (var)
4328 "Get a variable from a referenced buffer and install it here."
4329 (let ((m (get-text-property (point) 'org-marker)))
4330 (when (and m (buffer-live-p (marker-buffer m)))
4331 (org-set-local var (with-current-buffer (marker-buffer m)
4332 (symbol-value var))))))
4334 (defun org-agenda-switch-to (&optional delete-other-windows)
4335 "Go to the Org-mode file which contains the item at point."
4336 (interactive)
4337 (let* ((marker (or (get-text-property (point) 'org-marker)
4338 (org-agenda-error)))
4339 (buffer (marker-buffer marker))
4340 (pos (marker-position marker)))
4341 (switch-to-buffer buffer)
4342 (and delete-other-windows (delete-other-windows))
4343 (widen)
4344 (goto-char pos)
4345 (when (org-mode-p)
4346 (org-show-context 'agenda)
4347 (save-excursion
4348 (and (outline-next-heading)
4349 (org-flag-heading nil)))))) ; show the next heading
4351 (defun org-agenda-goto-mouse (ev)
4352 "Go to the Org-mode file which contains the item at the mouse click."
4353 (interactive "e")
4354 (mouse-set-point ev)
4355 (org-agenda-goto))
4357 (defun org-agenda-show ()
4358 "Display the Org-mode file which contains the item at point."
4359 (interactive)
4360 (let ((win (selected-window)))
4361 (org-agenda-goto t)
4362 (select-window win)))
4364 (defun org-agenda-recenter (arg)
4365 "Display the Org-mode file which contains the item at point and recenter."
4366 (interactive "P")
4367 (let ((win (selected-window)))
4368 (org-agenda-goto t)
4369 (recenter arg)
4370 (select-window win)))
4372 (defun org-agenda-show-mouse (ev)
4373 "Display the Org-mode file which contains the item at the mouse click."
4374 (interactive "e")
4375 (mouse-set-point ev)
4376 (org-agenda-show))
4378 (defun org-agenda-check-no-diary ()
4379 "Check if the entry is a diary link and abort if yes."
4380 (if (get-text-property (point) 'org-agenda-diary-link)
4381 (org-agenda-error)))
4383 (defun org-agenda-error ()
4384 (error "Command not allowed in this line"))
4386 (defun org-agenda-tree-to-indirect-buffer ()
4387 "Show the subtree corresponding to the current entry in an indirect buffer.
4388 This calls the command `org-tree-to-indirect-buffer' from the original
4389 Org-mode buffer.
4390 With numerical prefix arg ARG, go up to this level and then take that tree.
4391 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
4392 dedicated frame)."
4393 (interactive)
4394 (org-agenda-check-no-diary)
4395 (let* ((marker (or (get-text-property (point) 'org-marker)
4396 (org-agenda-error)))
4397 (buffer (marker-buffer marker))
4398 (pos (marker-position marker)))
4399 (with-current-buffer buffer
4400 (save-excursion
4401 (goto-char pos)
4402 (call-interactively 'org-tree-to-indirect-buffer)))))
4404 (defvar org-last-heading-marker (make-marker)
4405 "Marker pointing to the headline that last changed its TODO state
4406 by a remote command from the agenda.")
4408 (defun org-agenda-todo-nextset ()
4409 "Switch TODO entry to next sequence."
4410 (interactive)
4411 (org-agenda-todo 'nextset))
4413 (defun org-agenda-todo-previousset ()
4414 "Switch TODO entry to previous sequence."
4415 (interactive)
4416 (org-agenda-todo 'previousset))
4418 (defun org-agenda-todo (&optional arg)
4419 "Cycle TODO state of line at point, also in Org-mode file.
4420 This changes the line at point, all other lines in the agenda referring to
4421 the same tree node, and the headline of the tree node in the Org-mode file."
4422 (interactive "P")
4423 (org-agenda-check-no-diary)
4424 (let* ((col (current-column))
4425 (marker (or (get-text-property (point) 'org-marker)
4426 (org-agenda-error)))
4427 (buffer (marker-buffer marker))
4428 (pos (marker-position marker))
4429 (hdmarker (get-text-property (point) 'org-hd-marker))
4430 (inhibit-read-only t)
4431 newhead)
4432 (org-with-remote-undo buffer
4433 (with-current-buffer buffer
4434 (widen)
4435 (goto-char pos)
4436 (org-show-context 'agenda)
4437 (save-excursion
4438 (and (outline-next-heading)
4439 (org-flag-heading nil))) ; show the next heading
4440 (org-todo arg)
4441 (and (bolp) (forward-char 1))
4442 (setq newhead (org-get-heading))
4443 (save-excursion
4444 (org-back-to-heading)
4445 (move-marker org-last-heading-marker (point))))
4446 (beginning-of-line 1)
4447 (save-excursion
4448 (org-agenda-change-all-lines newhead hdmarker 'fixface))
4449 (move-to-column col))))
4451 (defun org-agenda-add-note (&optional arg)
4452 "Add a time-stamped note to the entry at point."
4453 (interactive "P")
4454 (org-agenda-check-no-diary)
4455 (let* ((marker (or (get-text-property (point) 'org-marker)
4456 (org-agenda-error)))
4457 (buffer (marker-buffer marker))
4458 (pos (marker-position marker))
4459 (hdmarker (get-text-property (point) 'org-hd-marker))
4460 (inhibit-read-only t))
4461 (with-current-buffer buffer
4462 (widen)
4463 (goto-char pos)
4464 (org-show-context 'agenda)
4465 (save-excursion
4466 (and (outline-next-heading)
4467 (org-flag-heading nil))) ; show the next heading
4468 (org-add-note))))
4470 (defun org-agenda-change-all-lines (newhead hdmarker &optional fixface)
4471 "Change all lines in the agenda buffer which match HDMARKER.
4472 The new content of the line will be NEWHEAD (as modified by
4473 `org-format-agenda-item'). HDMARKER is checked with
4474 `equal' against all `org-hd-marker' text properties in the file.
4475 If FIXFACE is non-nil, the face of each item is modified acording to
4476 the new TODO state."
4477 (let* ((inhibit-read-only t)
4478 props m pl undone-face done-face finish new dotime cat tags)
4479 (save-excursion
4480 (goto-char (point-max))
4481 (beginning-of-line 1)
4482 (while (not finish)
4483 (setq finish (bobp))
4484 (when (and (setq m (get-text-property (point) 'org-hd-marker))
4485 (equal m hdmarker))
4486 (setq props (text-properties-at (point))
4487 dotime (get-text-property (point) 'dotime)
4488 cat (get-text-property (point) 'org-category)
4489 tags (get-text-property (point) 'tags)
4490 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
4491 pl (get-text-property (point) 'prefix-length)
4492 undone-face (get-text-property (point) 'undone-face)
4493 done-face (get-text-property (point) 'done-face))
4494 (move-to-column pl)
4495 (cond
4496 ((equal new "")
4497 (beginning-of-line 1)
4498 (and (looking-at ".*\n?") (replace-match "")))
4499 ((looking-at ".*")
4500 (replace-match new t t)
4501 (beginning-of-line 1)
4502 (add-text-properties (point-at-bol) (point-at-eol) props)
4503 (when fixface
4504 (add-text-properties
4505 (point-at-bol) (point-at-eol)
4506 (list 'face
4507 (if org-last-todo-state-is-todo
4508 undone-face done-face))))
4509 (org-agenda-highlight-todo 'line)
4510 (beginning-of-line 1))
4511 (t (error "Line update did not work"))))
4512 (beginning-of-line 0)))
4513 (org-finalize-agenda)))
4515 (defun org-agenda-align-tags (&optional line)
4516 "Align all tags in agenda items to `org-agenda-tags-column'."
4517 (let ((inhibit-read-only t) l c)
4518 (save-excursion
4519 (goto-char (if line (point-at-bol) (point-min)))
4520 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4521 (if line (point-at-eol) nil) t)
4522 (add-text-properties
4523 (match-beginning 2) (match-end 2)
4524 (list 'face (delq nil (list 'org-tag (get-text-property
4525 (match-beginning 2) 'face)))))
4526 (setq l (- (match-end 2) (match-beginning 2))
4527 c (if (< org-agenda-tags-column 0)
4528 (- (abs org-agenda-tags-column) l)
4529 org-agenda-tags-column))
4530 (delete-region (match-beginning 1) (match-end 1))
4531 (goto-char (match-beginning 1))
4532 (insert (org-add-props
4533 (make-string (max 1 (- c (current-column))) ?\ )
4534 (text-properties-at (point))))))))
4536 (defun org-agenda-priority-up ()
4537 "Increase the priority of line at point, also in Org-mode file."
4538 (interactive)
4539 (org-agenda-priority 'up))
4541 (defun org-agenda-priority-down ()
4542 "Decrease the priority of line at point, also in Org-mode file."
4543 (interactive)
4544 (org-agenda-priority 'down))
4546 (defun org-agenda-priority (&optional force-direction)
4547 "Set the priority of line at point, also in Org-mode file.
4548 This changes the line at point, all other lines in the agenda referring to
4549 the same tree node, and the headline of the tree node in the Org-mode file."
4550 (interactive)
4551 (org-agenda-check-no-diary)
4552 (let* ((marker (or (get-text-property (point) 'org-marker)
4553 (org-agenda-error)))
4554 (hdmarker (get-text-property (point) 'org-hd-marker))
4555 (buffer (marker-buffer hdmarker))
4556 (pos (marker-position hdmarker))
4557 (inhibit-read-only t)
4558 newhead)
4559 (org-with-remote-undo buffer
4560 (with-current-buffer buffer
4561 (widen)
4562 (goto-char pos)
4563 (org-show-context 'agenda)
4564 (save-excursion
4565 (and (outline-next-heading)
4566 (org-flag-heading nil))) ; show the next heading
4567 (funcall 'org-priority force-direction)
4568 (end-of-line 1)
4569 (setq newhead (org-get-heading)))
4570 (org-agenda-change-all-lines newhead hdmarker)
4571 (beginning-of-line 1))))
4573 ;; FIXME: should fix the tags property of the agenda line.
4574 (defun org-agenda-set-tags ()
4575 "Set tags for the current headline."
4576 (interactive)
4577 (org-agenda-check-no-diary)
4578 (if (and (org-region-active-p) (interactive-p))
4579 (call-interactively 'org-change-tag-in-region)
4580 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4581 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
4582 (org-agenda-error)))
4583 (buffer (marker-buffer hdmarker))
4584 (pos (marker-position hdmarker))
4585 (inhibit-read-only t)
4586 newhead)
4587 (org-with-remote-undo buffer
4588 (with-current-buffer buffer
4589 (widen)
4590 (goto-char pos)
4591 (save-excursion
4592 (org-show-context 'agenda))
4593 (save-excursion
4594 (and (outline-next-heading)
4595 (org-flag-heading nil))) ; show the next heading
4596 (goto-char pos)
4597 (call-interactively 'org-set-tags)
4598 (end-of-line 1)
4599 (setq newhead (org-get-heading)))
4600 (org-agenda-change-all-lines newhead hdmarker)
4601 (beginning-of-line 1)))))
4603 (defun org-agenda-toggle-archive-tag ()
4604 "Toggle the archive tag for the current entry."
4605 (interactive)
4606 (org-agenda-check-no-diary)
4607 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4608 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker)
4609 (org-agenda-error)))
4610 (buffer (marker-buffer hdmarker))
4611 (pos (marker-position hdmarker))
4612 (inhibit-read-only t)
4613 newhead)
4614 (org-with-remote-undo buffer
4615 (with-current-buffer buffer
4616 (widen)
4617 (goto-char pos)
4618 (org-show-context 'agenda)
4619 (save-excursion
4620 (and (outline-next-heading)
4621 (org-flag-heading nil))) ; show the next heading
4622 (call-interactively 'org-toggle-archive-tag)
4623 (end-of-line 1)
4624 (setq newhead (org-get-heading)))
4625 (org-agenda-change-all-lines newhead hdmarker)
4626 (beginning-of-line 1))))
4628 (defun org-agenda-date-later (arg &optional what)
4629 "Change the date of this item to one day later."
4630 (interactive "p")
4631 (org-agenda-check-type t 'agenda 'timeline)
4632 (org-agenda-check-no-diary)
4633 (let* ((marker (or (get-text-property (point) 'org-marker)
4634 (org-agenda-error)))
4635 (buffer (marker-buffer marker))
4636 (pos (marker-position marker)))
4637 (org-with-remote-undo buffer
4638 (with-current-buffer buffer
4639 (widen)
4640 (goto-char pos)
4641 (if (not (org-at-timestamp-p))
4642 (error "Cannot find time stamp"))
4643 (org-timestamp-change arg (or what 'day)))
4644 (org-agenda-show-new-time marker org-last-changed-timestamp))
4645 (message "Time stamp changed to %s" org-last-changed-timestamp)))
4647 (defun org-agenda-date-earlier (arg &optional what)
4648 "Change the date of this item to one day earlier."
4649 (interactive "p")
4650 (org-agenda-date-later (- arg) what))
4652 (defun org-agenda-show-new-time (marker stamp &optional prefix)
4653 "Show new date stamp via text properties."
4654 ;; We use text properties to make this undoable
4655 (let ((inhibit-read-only t))
4656 (setq stamp (concat " " prefix " => " stamp))
4657 (save-excursion
4658 (goto-char (point-max))
4659 (while (not (bobp))
4660 (when (equal marker (get-text-property (point) 'org-marker))
4661 (move-to-column (- (window-width) (length stamp)) t)
4662 (if (featurep 'xemacs)
4663 ;; Use `duplicable' property to trigger undo recording
4664 (let ((ex (make-extent nil nil))
4665 (gl (make-glyph stamp)))
4666 (set-glyph-face gl 'secondary-selection)
4667 (set-extent-properties
4668 ex (list 'invisible t 'end-glyph gl 'duplicable t))
4669 (insert-extent ex (1- (point)) (point-at-eol)))
4670 (add-text-properties
4671 (1- (point)) (point-at-eol)
4672 (list 'display (org-add-props stamp nil
4673 'face 'secondary-selection))))
4674 (beginning-of-line 1))
4675 (beginning-of-line 0)))))
4677 (defun org-agenda-date-prompt (arg)
4678 "Change the date of this item. Date is prompted for, with default today.
4679 The prefix ARG is passed to the `org-time-stamp' command and can therefore
4680 be used to request time specification in the time stamp."
4681 (interactive "P")
4682 (org-agenda-check-type t 'agenda 'timeline)
4683 (org-agenda-check-no-diary)
4684 (let* ((marker (or (get-text-property (point) 'org-marker)
4685 (org-agenda-error)))
4686 (buffer (marker-buffer marker))
4687 (pos (marker-position marker)))
4688 (org-with-remote-undo buffer
4689 (with-current-buffer buffer
4690 (widen)
4691 (goto-char pos)
4692 (if (not (org-at-timestamp-p))
4693 (error "Cannot find time stamp"))
4694 (org-time-stamp arg)
4695 (message "Time stamp changed to %s" org-last-changed-timestamp)))))
4697 (defun org-agenda-schedule (arg)
4698 "Schedule the item at point."
4699 (interactive "P")
4700 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
4701 (org-agenda-check-no-diary)
4702 (let* ((marker (or (get-text-property (point) 'org-marker)
4703 (org-agenda-error)))
4704 (type (marker-insertion-type marker))
4705 (buffer (marker-buffer marker))
4706 (pos (marker-position marker))
4707 (org-insert-labeled-timestamps-at-point nil)
4709 (when type (message "%s" type) (sit-for 3))
4710 (set-marker-insertion-type marker t)
4711 (org-with-remote-undo buffer
4712 (with-current-buffer buffer
4713 (widen)
4714 (goto-char pos)
4715 (setq ts (org-schedule arg)))
4716 (org-agenda-show-new-time marker ts "S"))
4717 (message "Item scheduled for %s" ts)))
4719 (defun org-agenda-deadline (arg)
4720 "Schedule the item at point."
4721 (interactive "P")
4722 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
4723 (org-agenda-check-no-diary)
4724 (let* ((marker (or (get-text-property (point) 'org-marker)
4725 (org-agenda-error)))
4726 (buffer (marker-buffer marker))
4727 (pos (marker-position marker))
4728 (org-insert-labeled-timestamps-at-point nil)
4730 (org-with-remote-undo buffer
4731 (with-current-buffer buffer
4732 (widen)
4733 (goto-char pos)
4734 (setq ts (org-deadline arg)))
4735 (org-agenda-show-new-time marker ts "S"))
4736 (message "Deadline for this item set to %s" ts)))
4739 (defun org-agenda-clock-in (&optional arg)
4740 "Start the clock on the currently selected item."
4741 (interactive "P")
4742 (org-agenda-check-no-diary)
4743 (let* ((marker (or (get-text-property (point) 'org-marker)
4744 (org-agenda-error)))
4745 (pos (marker-position marker)))
4746 (org-with-remote-undo (marker-buffer marker)
4747 (with-current-buffer (marker-buffer marker)
4748 (widen)
4749 (goto-char pos)
4750 (org-clock-in)))))
4752 (defun org-agenda-clock-out (&optional arg)
4753 "Stop the currently running clock."
4754 (interactive "P")
4755 (unless (marker-buffer org-clock-marker)
4756 (error "No running clock"))
4757 (org-with-remote-undo (marker-buffer org-clock-marker)
4758 (org-clock-out)))
4760 (defun org-agenda-clock-cancel (&optional arg)
4761 "Cancel the currently running clock."
4762 (interactive "P")
4763 (unless (marker-buffer org-clock-marker)
4764 (error "No running clock"))
4765 (org-with-remote-undo (marker-buffer org-clock-marker)
4766 (org-clock-cancel)))
4768 (defun org-agenda-diary-entry ()
4769 "Make a diary entry, like the `i' command from the calendar.
4770 All the standard commands work: block, weekly etc."
4771 (interactive)
4772 (org-agenda-check-type t 'agenda 'timeline)
4773 (require 'diary-lib)
4774 (let* ((char (progn
4775 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
4776 (read-char-exclusive)))
4777 (cmd (cdr (assoc char
4778 '((?d . insert-diary-entry)
4779 (?w . insert-weekly-diary-entry)
4780 (?m . insert-monthly-diary-entry)
4781 (?y . insert-yearly-diary-entry)
4782 (?a . insert-anniversary-diary-entry)
4783 (?b . insert-block-diary-entry)
4784 (?c . insert-cyclic-diary-entry)))))
4785 (oldf (symbol-function 'calendar-cursor-to-date))
4786 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
4787 (point (point))
4788 (mark (or (mark t) (point))))
4789 (unless cmd
4790 (error "No command associated with <%c>" char))
4791 (unless (and (get-text-property point 'day)
4792 (or (not (equal ?b char))
4793 (get-text-property mark 'day)))
4794 (error "Don't know which date to use for diary entry"))
4795 ;; We implement this by hacking the `calendar-cursor-to-date' function
4796 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
4797 (let ((calendar-mark-ring
4798 (list (calendar-gregorian-from-absolute
4799 (or (get-text-property mark 'day)
4800 (get-text-property point 'day))))))
4801 (unwind-protect
4802 (progn
4803 (fset 'calendar-cursor-to-date
4804 (lambda (&optional error)
4805 (calendar-gregorian-from-absolute
4806 (get-text-property point 'day))))
4807 (call-interactively cmd))
4808 (fset 'calendar-cursor-to-date oldf)))))
4811 (defun org-agenda-execute-calendar-command (cmd)
4812 "Execute a calendar command from the agenda, with the date associated to
4813 the cursor position."
4814 (org-agenda-check-type t 'agenda 'timeline)
4815 (require 'diary-lib)
4816 (unless (get-text-property (point) 'day)
4817 (error "Don't know which date to use for calendar command"))
4818 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
4819 (point (point))
4820 (date (calendar-gregorian-from-absolute
4821 (get-text-property point 'day)))
4822 ;; the following 3 vars are needed in the calendar
4823 (displayed-day (extract-calendar-day date))
4824 (displayed-month (extract-calendar-month date))
4825 (displayed-year (extract-calendar-year date)))
4826 (unwind-protect
4827 (progn
4828 (fset 'calendar-cursor-to-date
4829 (lambda (&optional error)
4830 (calendar-gregorian-from-absolute
4831 (get-text-property point 'day))))
4832 (call-interactively cmd))
4833 (fset 'calendar-cursor-to-date oldf))))
4835 (defun org-agenda-phases-of-moon ()
4836 "Display the phases of the moon for the 3 months around the cursor date."
4837 (interactive)
4838 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
4840 (defun org-agenda-holidays ()
4841 "Display the holidays for the 3 months around the cursor date."
4842 (interactive)
4843 (org-agenda-execute-calendar-command 'list-calendar-holidays))
4845 (defvar calendar-longitude)
4846 (defvar calendar-latitude)
4847 (defvar calendar-location-name)
4849 (defun org-agenda-sunrise-sunset (arg)
4850 "Display sunrise and sunset for the cursor date.
4851 Latitude and longitude can be specified with the variables
4852 `calendar-latitude' and `calendar-longitude'. When called with prefix
4853 argument, latitude and longitude will be prompted for."
4854 (interactive "P")
4855 (require 'solar)
4856 (let ((calendar-longitude (if arg nil calendar-longitude))
4857 (calendar-latitude (if arg nil calendar-latitude))
4858 (calendar-location-name
4859 (if arg "the given coordinates" calendar-location-name)))
4860 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
4862 (defun org-agenda-goto-calendar ()
4863 "Open the Emacs calendar with the date at the cursor."
4864 (interactive)
4865 (org-agenda-check-type t 'agenda 'timeline)
4866 (let* ((day (or (get-text-property (point) 'day)
4867 (error "Don't know which date to open in calendar")))
4868 (date (calendar-gregorian-from-absolute day))
4869 (calendar-move-hook nil)
4870 (view-calendar-holidays-initially nil)
4871 (view-diary-entries-initially nil))
4872 (calendar)
4873 (calendar-goto-date date)))
4875 ;;;###autoload
4876 (defun org-calendar-goto-agenda ()
4877 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
4878 This is a command that has to be installed in `calendar-mode-map'."
4879 (interactive)
4880 (org-agenda-list nil (calendar-absolute-from-gregorian
4881 (calendar-cursor-to-date))
4882 nil))
4884 (defun org-agenda-convert-date ()
4885 (interactive)
4886 (org-agenda-check-type t 'agenda 'timeline)
4887 (let ((day (get-text-property (point) 'day))
4888 date s)
4889 (unless day
4890 (error "Don't know which date to convert"))
4891 (setq date (calendar-gregorian-from-absolute day))
4892 (setq s (concat
4893 "Gregorian: " (calendar-date-string date) "\n"
4894 "ISO: " (calendar-iso-date-string date) "\n"
4895 "Day of Yr: " (calendar-day-of-year-string date) "\n"
4896 "Julian: " (calendar-julian-date-string date) "\n"
4897 "Astron. JD: " (calendar-astro-date-string date)
4898 " (Julian date number at noon UTC)\n"
4899 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
4900 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
4901 "French: " (calendar-french-date-string date) "\n"
4902 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
4903 "Mayan: " (calendar-mayan-date-string date) "\n"
4904 "Coptic: " (calendar-coptic-date-string date) "\n"
4905 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
4906 "Persian: " (calendar-persian-date-string date) "\n"
4907 "Chinese: " (calendar-chinese-date-string date) "\n"))
4908 (with-output-to-temp-buffer "*Dates*"
4909 (princ s))
4910 (if (fboundp 'fit-window-to-buffer)
4911 (fit-window-to-buffer (get-buffer-window "*Dates*")))))
4914 ;;; Appointment reminders
4916 (defvar appt-time-msg-list)
4918 ;;;###autoload
4919 (defun org-agenda-to-appt (&optional refresh filter)
4920 "Activate appointments found in `org-agenda-files'.
4921 With a \\[universal-argument] prefix, refresh the list of
4922 appointements.
4924 If FILTER is t, interactively prompt the user for a regular
4925 expression, and filter out entries that don't match it.
4927 If FILTER is a string, use this string as a regular expression
4928 for filtering entries out.
4930 FILTER can also be an alist with the car of each cell being
4931 either 'headline or 'category. For example:
4933 '((headline \"IMPORTANT\")
4934 (category \"Work\"))
4936 will only add headlines containing IMPORTANT or headlines
4937 belonging to the \"Work\" category."
4938 (interactive "P")
4939 (require 'calendar)
4940 (if refresh (setq appt-time-msg-list nil))
4941 (if (eq filter t)
4942 (setq filter (read-from-minibuffer "Regexp filter: ")))
4943 (let* ((cnt 0) ; count added events
4944 (org-agenda-new-buffers nil)
4945 (org-deadline-warning-days 0)
4946 (today (org-date-to-gregorian
4947 (time-to-days (current-time))))
4948 (files (org-agenda-files)) entries file)
4949 ;; Get all entries which may contain an appt
4950 (while (setq file (pop files))
4951 (setq entries
4952 (append entries
4953 (org-agenda-get-day-entries
4954 file today :timestamp :scheduled :deadline))))
4955 (setq entries (delq nil entries))
4956 ;; Map thru entries and find if we should filter them out
4957 (mapc
4958 (lambda(x)
4959 (let* ((evt (org-trim (get-text-property 1 'txt x)))
4960 (cat (get-text-property 1 'org-category x))
4961 (tod (get-text-property 1 'time-of-day x))
4962 (ok (or (null filter)
4963 (and (stringp filter) (string-match filter evt))
4964 (and (listp filter)
4965 (or (string-match
4966 (cadr (assoc 'category filter)) cat)
4967 (string-match
4968 (cadr (assoc 'headline filter)) evt))))))
4969 ;; FIXME: Shall we remove text-properties for the appt text?
4970 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
4971 (when (and ok tod)
4972 (setq tod (number-to-string tod)
4973 tod (when (string-match
4974 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)" tod)
4975 (concat (match-string 1 tod) ":"
4976 (match-string 2 tod))))
4977 (appt-add tod evt)
4978 (setq cnt (1+ cnt))))) entries)
4979 (org-release-buffers org-agenda-new-buffers)
4980 (if (eq cnt 0)
4981 (message "No event to add")
4982 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
4984 (provide 'org-agenda)
4986 ;;; org-agenda.el ends here