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
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)
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; This file contains the code for creating and using the Agenda for Org-mode.
39 (declare-function add-to-diary-list
"diary-lib"
40 (date string specifier
&optional marker globcolor literal
))
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
)
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."
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."
83 (defgroup org-agenda-export nil
84 "Options concerning exporting agenda views in Org-mode."
85 :tag
"Org Agenda Export"
88 (defcustom org-agenda-with-colors t
89 "Non-nil means, use colors in agenda views."
90 :group
'org-agenda-export
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
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 {
125 .title { text-align: center; }
126 .todo, .deadline { color: red; }
127 .done { color: green; }
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
141 (defgroup org-agenda-custom-commands nil
142 "Options concerning agenda views in Org-mode."
143 :tag
"Org Agenda Custom Commands"
146 (defconst org-sorting-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
))
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")
160 (list :tag
"Files to be searched"
161 (const org-agenda-files
)
163 (const :format
"" quote
)
166 (list :tag
"Sorting strategy"
167 (const org-agenda-sorting-strategy
)
169 (const :format
"" quote
)
171 ,org-sorting-choice
)))
172 (list :tag
"Prefix format"
173 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
175 (list :tag
"Number of days in agenda"
176 (const org-agenda-ndays
)
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
)
184 (const :tag
"Today" nil
)
185 (number :tag
"Weekday No.")))
186 (list :tag
"Include data from diary"
187 (const org-agenda-include-diary
)
189 (list :tag
"Deadline Warning days"
190 (const org-deadline-warning-days
)
192 (list :tag
"Standard skipping condition"
193 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
194 (const org-agenda-skip-function
)
196 (const :format
"" quote
)
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"
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)
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
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)
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
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"))
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"
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
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
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"
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
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'
409 :group
'org-agenda-skip
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
417 See also `org-agenda-todo-ignore-with-date'."
418 :group
'org-agenda-skip
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
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
437 :group
'org-agenda-skip
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
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
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
462 (const :tag
"None" nil
)
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"
472 (defcustom org-finalize-agenda-hook nil
473 "Hook run just before displaying an agenda buffer."
474 :group
'org-agenda-startup
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
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
489 (defgroup org-agenda-windows nil
490 "Options concerning the windows used by the Agenda in Org Mode."
491 :tag
"Org Agenda Windows"
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
506 (const current-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
528 (defgroup org-agenda-daily
/weekly nil
529 "Options concerning the daily/weekly agenda."
530 :tag
"Org Agenda Daily/Weekly"
533 (defcustom org-agenda-ndays
7
534 "Number of days to include in overview display.
536 :group
'org-agenda-daily
/weekly
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
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
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."
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))
578 ((and (= month
12) (<= iso-week
1))
581 (weekstring (if (= day-of-week
1)
582 (format " W%02d" iso-week
)
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
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
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
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
611 :group
'org-agenda-daily
/weekly
614 (defgroup org-agenda-time-grid nil
615 "Options concerning the time grid in the Org-mode Agenda."
616 :tag
"Org Agenda Time Grid"
619 (defcustom org-agenda-use-time-grid t
620 "Non-nil means, show a time grid in the agenda schedule.
621 A time grid is a set of lines for specific times (like every two hours between
622 8:00 and 20:00). The items scheduled for a day at specific times are
623 sorted in between these lines.
624 For details about when the grid will be shown, and what it will look like, see
625 the variable `org-agenda-time-grid'."
626 :group
'org-agenda-time-grid
629 (defcustom org-agenda-time-grid
630 '((daily today require-timed
)
632 (800 1000 1200 1400 1600 1800 2000))
634 "The settings for time grid for agenda display.
635 This is a list of three items. The first item is again a list. It contains
636 symbols specifying conditions when the grid should be displayed:
638 daily if the agenda shows a single day
639 weekly if the agenda shows an entire week
640 today show grid on current date, independent of daily/weekly display
641 require-timed show grid only if at least one item has a time specification
643 The second item is a string which will be places behing the grid time.
645 The third item is a list of integers, indicating the times that should have
647 :group
'org-agenda-time-grid
650 (set :greedy t
:tag
"Grid Display Options"
651 (const :tag
"Show grid in single day agenda display" daily
)
652 (const :tag
"Show grid in weekly agenda display" weekly
)
653 (const :tag
"Always show grid for today" today
)
654 (const :tag
"Show grid only if any timed entries are present"
656 (const :tag
"Skip grid times already present in an entry"
658 (string :tag
"Grid String")
659 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
661 (defgroup org-agenda-sorting nil
662 "Options concerning sorting in the Org-mode Agenda."
663 :tag
"Org Agenda Sorting"
666 (defcustom org-agenda-sorting-strategy
667 '((agenda time-up category-keep priority-down
)
668 (todo category-keep priority-down
)
669 (tags category-keep priority-down
)
670 (search category-keep
))
671 "Sorting structure for the agenda items of a single day.
672 This is a list of symbols which will be used in sequence to determine
673 if an entry should be listed before another entry. The following
674 symbols are recognized:
676 time-up Put entries with time-of-day indications first, early first
677 time-down Put entries with time-of-day indications first, late first
678 category-keep Keep the default order of categories, corresponding to the
679 sequence in `org-agenda-files'.
680 category-up Sort alphabetically by category, A-Z.
681 category-down Sort alphabetically by category, Z-A.
682 tag-up Sort alphabetically by last tag, A-Z.
683 tag-down Sort alphabetically by last tag, Z-A.
684 priority-up Sort numerically by priority, high priority last.
685 priority-down Sort numerically by priority, high priority first.
687 The different possibilities will be tried in sequence, and testing stops
688 if one comparison returns a \"not-equal\". For example, the default
689 '(time-up category-keep priority-down)
690 means: Pull out all entries having a specified time of day and sort them,
691 in order to make a time schedule for the current day the first thing in the
692 agenda listing for the day. Of the entries without a time indication, keep
693 the grouped in categories, don't sort the categories, but keep them in
694 the sequence given in `org-agenda-files'. Within each category sort by
697 Leaving out `category-keep' would mean that items will be sorted across
698 categories by priority.
700 Instead of a single list, this can also be a set of list for specific
701 contents, with a context symbol in the car of the list, any of
702 `agenda', `todo', `tags' for the corresponding agenda views."
703 :group
'org-agenda-sorting
705 (repeat :tag
"General" ,org-sorting-choice
)
706 (list :tag
"Individually"
707 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
708 (repeat ,org-sorting-choice
))
709 (cons (const :tag
"Strategy for TODO lists" todo
)
710 (repeat ,org-sorting-choice
))
711 (cons (const :tag
"Strategy for Tags matches" tags
)
712 (repeat ,org-sorting-choice
)))))
714 (defcustom org-sort-agenda-notime-is-late t
715 "Non-nil means, items without time are considered late.
716 This is only relevant for sorting. When t, items which have no explicit
717 time like 15:30 will be considered as 99:01, i.e. later than any items which
718 do have a time. When nil, the default time is before 0:00. You can use this
719 option to decide if the schedule for today should come before or after timeless
721 :group
'org-agenda-sorting
724 (defgroup org-agenda-line-format nil
725 "Options concerning the entry prefix in the Org-mode agenda display."
726 :tag
"Org Agenda Line Format"
729 (defcustom org-agenda-prefix-format
730 '((agenda .
" %-12:c%?-12t% s")
734 (search .
" %-12:c"))
735 "Format specifications for the prefix of items in the agenda views.
736 An alist with four entries, for the different agenda types. The keys to the
737 sublists are `agenda', `timeline', `todo', and `tags'. The values
739 This format works similar to a printf format, with the following meaning:
741 %c the category of the item, \"Diary\" for entries from the diary, or
742 as given by the CATEGORY keyword or derived from the file name.
743 %T the *last* tag of the item. Last because inherited tags come
745 %t the time-of-day specification if one applies to the entry, in the
747 %s Scheduling/Deadline information, a short string
749 All specifiers work basically like the standard `%s' of printf, but may
750 contain two additional characters: A question mark just after the `%' and
751 a whitespace/punctuation character just before the final letter.
753 If the first character after `%' is a question mark, the entire field
754 will only be included if the corresponding value applies to the
755 current entry. This is useful for fields which should have fixed
756 width when present, but zero width when absent. For example,
757 \"%?-12t\" will result in a 12 character time field if a time of the
758 day is specified, but will completely disappear in entries which do
761 If there is punctuation or whitespace character just before the final
762 format letter, this character will be appended to the field value if
763 the value is not empty. For example, the format \"%-12:c\" leads to
764 \"Diary: \" if the category is \"Diary\". If the category were be
765 empty, no additional colon would be interted.
767 The default value of this option is \" %-12:c%?-12t% s\", meaning:
768 - Indent the line with two space characters
769 - Give the category in a 12 chars wide field, padded with whitespace on
770 the right (because of `-'). Append a colon if there is a category
772 - If there is a time-of-day, put it into a 12 chars wide field. If no
773 time, don't put in an empty field, just skip it (because of '?').
774 - Finally, put the scheduling information and append a whitespace.
776 As another example, if you don't want the time-of-day of entries in
777 the prefix, you could use:
779 (setq org-agenda-prefix-format \" %-11:c% s\")
781 See also the variables `org-agenda-remove-times-when-in-prefix' and
782 `org-agenda-remove-tags'."
784 (string :tag
"General format")
785 (list :greedy t
:tag
"View dependent"
786 (cons (const agenda
) (string :tag
"Format"))
787 (cons (const timeline
) (string :tag
"Format"))
788 (cons (const todo
) (string :tag
"Format"))
789 (cons (const tags
) (string :tag
"Format"))
790 (cons (const search
) (string :tag
"Format"))))
791 :group
'org-agenda-line-format
)
793 (defvar org-prefix-format-compiled nil
794 "The compiled version of the most recently used prefix format.
795 See the variable `org-agenda-prefix-format'.")
797 (defcustom org-agenda-todo-keyword-format
"%-1s"
798 "Format for the TODO keyword in agenda lines.
799 Set this to something like \"%-12s\" if you want all TODO keywords
800 to occupy a fixed space in the agenda display."
801 :group
'org-agenda-line-format
804 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
805 "Text preceeding scheduled items in the agenda view.
806 This is a list with two strings. The first applies when the item is
807 scheduled on the current day. The second applies when it has been scheduled
808 previously, it may contain a %d to capture how many days ago the item was
810 :group
'org-agenda-line-format
812 (string :tag
"Scheduled today ")
813 (string :tag
"Scheduled previously")))
815 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
816 "Text preceeding deadline items in the agenda view.
817 This is a list with two strings. The first applies when the item has its
818 deadline on the current day. The second applies when it is in the past or
819 in the future, it may contain %d to capture how many days away the deadline
821 :group
'org-agenda-line-format
823 (string :tag
"Deadline today ")
824 (string :tag
"Deadline relative")))
826 (defcustom org-agenda-remove-times-when-in-prefix t
827 "Non-nil means, remove duplicate time specifications in agenda items.
828 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
829 time-of-day specification in a headline or diary entry is extracted and
830 placed into the prefix. If this option is non-nil, the original specification
831 \(a timestamp or -range, or just a plain time(range) specification like
832 11:30-4pm) will be removed for agenda display. This makes the agenda less
834 The option can be t or nil. It may also be the symbol `beg', indicating
835 that the time should only be removed what it is located at the beginning of
836 the headline/diary entry."
837 :group
'org-agenda-line-format
839 (const :tag
"Always" t
)
840 (const :tag
"Never" nil
)
841 (const :tag
"When at beginning of entry" beg
)))
844 (defcustom org-agenda-default-appointment-duration nil
845 "Default duration for appointments that only have a starting time.
846 When nil, no duration is specified in such cases.
847 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
848 :group
'org-agenda-line-format
850 (integer :tag
"Minutes")
851 (const :tag
"No default duration")))
854 (defcustom org-agenda-remove-tags nil
855 "Non-nil means, remove the tags from the headline copy in the agenda.
856 When this is the symbol `prefix', only remove tags when
857 `org-agenda-prefix-format' contains a `%T' specifier."
858 :group
'org-agenda-line-format
860 (const :tag
"Always" t
)
861 (const :tag
"Never" nil
)
862 (const :tag
"When prefix format contains %T" prefix
)))
864 (if (fboundp 'defvaralias
)
865 (defvaralias 'org-agenda-remove-tags-when-in-prefix
866 'org-agenda-remove-tags
))
868 (defcustom org-agenda-tags-column -
80
869 "Shift tags in agenda items to this column.
870 If this number is positive, it specifies the column. If it is negative,
871 it means that the tags should be flushright to that column. For example,
872 -80 works well for a normal 80 character screen."
873 :group
'org-agenda-line-format
876 (if (fboundp 'defvaralias
)
877 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
879 (defcustom org-agenda-fontify-priorities t
880 "Non-nil means, highlight low and high priorities in agenda.
881 When t, the highest priority entries are bold, lowest priority italic.
882 This may also be an association list of priority faces. The face may be
883 a names face, or a list like `(:background \"Red\")'."
884 :group
'org-agenda-line-format
886 (const :tag
"Never" nil
)
887 (const :tag
"Defaults" t
)
888 (repeat :tag
"Specify"
889 (list (character :tag
"Priority" :value ?A
)
890 (sexp :tag
"face")))))
907 (defun org-add-agenda-custom-command (entry)
908 "Replace or add a command in `org-agenda-custom-commands'.
909 This is mostly for hacking and trying a new command - once the command
910 works you probably want to add it to `org-agenda-custom-commands' for good."
911 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
913 (setcdr ass
(cdr entry
))
914 (push entry org-agenda-custom-commands
))))
916 ;;; Define the Org-agenda-mode
918 (defvar org-agenda-mode-map
(make-sparse-keymap)
919 "Keymap for `org-agenda-mode'.")
921 (defvar org-agenda-menu
) ; defined later in this file.
922 (defvar org-agenda-follow-mode nil
)
923 (defvar org-agenda-show-log nil
)
924 (defvar org-agenda-redo-command nil
)
925 (defvar org-agenda-query-string nil
)
926 (defvar org-agenda-mode-hook nil
)
927 (defvar org-agenda-type nil
)
928 (defvar org-agenda-force-single-file nil
)
930 (defun org-agenda-mode ()
931 "Mode for time-sorted view on action items in Org-mode files.
933 The following commands are available:
935 \\{org-agenda-mode-map}"
937 (kill-all-local-variables)
938 (setq org-agenda-undo-list nil
939 org-agenda-pending-undo-list nil
)
940 (setq major-mode
'org-agenda-mode
)
941 ;; Keep global-font-lock-mode from turning on font-lock-mode
942 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
943 (setq mode-name
"Org-Agenda")
944 (use-local-map org-agenda-mode-map
)
945 (easy-menu-add org-agenda-menu
)
946 (if org-startup-truncated
(setq truncate-lines t
))
947 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
948 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
949 ;; Make sure properties are removed when copying text
950 (when (boundp 'buffer-substring-filters
)
951 (org-set-local 'buffer-substring-filters
953 (set-text-properties 0 (length x
) nil x
) x
)
954 buffer-substring-filters
)))
955 (unless org-agenda-keep-modes
956 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
957 org-agenda-show-log nil
))
959 '("Agenda") "Agenda Files"
963 (if (get 'org-agenda-files
'org-restrict
)
964 "Restricted to single file"
966 '(org-edit-agenda-file-list)
967 (not (get 'org-agenda-files
'org-restrict
)))
969 (mapcar 'org-file-menu-entry
(org-agenda-files))))
970 (org-agenda-set-mode-name)
972 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
973 (list 'org-agenda-mode-hook
)))
975 (substitute-key-definition 'undo
'org-agenda-undo
976 org-agenda-mode-map global-map
)
977 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
978 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
979 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
980 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
981 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
982 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
983 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
984 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
985 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
986 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
987 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
988 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
989 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
990 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
991 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
992 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
993 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
994 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
995 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
996 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
997 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
998 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
999 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1000 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1001 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1002 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-date-later
)
1003 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-date-earlier
)
1004 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-date-later
)
1005 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-date-earlier
)
1007 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1008 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1009 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1010 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1011 (while l
(org-defkey org-agenda-mode-map
1012 (int-to-string (pop l
)) 'digit-argument
)))
1014 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1015 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1016 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1017 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1018 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1019 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1020 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1021 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1022 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1023 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1024 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1025 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1026 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1027 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1028 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1029 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1030 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1031 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1032 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1033 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1034 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1035 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1036 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1037 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1038 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1039 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1040 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1041 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1042 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1043 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1044 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1045 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1046 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1047 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1048 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1049 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1050 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1051 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1052 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1053 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1054 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1055 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1056 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1057 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1059 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1060 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1061 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1062 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1064 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1065 "Local keymap for agenda entries from Org-mode.")
1067 (org-defkey org-agenda-keymap
1068 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1069 (org-defkey org-agenda-keymap
1070 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1071 (when org-agenda-mouse-1-follows-link
1072 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1073 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1077 ["Show" org-agenda-show t
]
1078 ["Go To (other window)" org-agenda-goto t
]
1079 ["Go To (this window)" org-agenda-switch-to t
]
1080 ["Follow Mode" org-agenda-follow-mode
1081 :style toggle
:selected org-agenda-follow-mode
:active t
]
1082 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1084 ["Cycle TODO" org-agenda-todo t
]
1085 ["Archive subtree" org-agenda-archive t
]
1086 ["Delete subtree" org-agenda-kill t
]
1088 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1089 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1090 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1091 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1093 ("Tags and Properties"
1094 ["Show all Tags" org-agenda-show-tags t
]
1095 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1096 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1098 ["Column View" org-columns t
])
1100 ["Schedule" org-agenda-schedule t
]
1101 ["Set Deadline" org-agenda-deadline t
]
1103 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1104 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1105 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1107 ["Clock in" org-agenda-clock-in t
]
1108 ["Clock out" org-agenda-clock-out t
]
1109 ["Clock cancel" org-agenda-clock-cancel t
]
1110 ["Goto running clock" org-clock-goto t
])
1112 ["Set Priority" org-agenda-priority t
]
1113 ["Increase Priority" org-agenda-priority-up t
]
1114 ["Decrease Priority" org-agenda-priority-down t
]
1115 ["Show Priority" org-agenda-show-priority t
])
1117 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1118 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1119 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1120 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1121 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1122 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1124 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1127 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1128 :style radio
:selected
(equal org-agenda-ndays
1)]
1129 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1130 :style radio
:selected
(equal org-agenda-ndays
7)]
1131 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1132 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1133 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1134 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1136 ["Show Logbook entries" org-agenda-log-mode
1137 :style toggle
:selected org-agenda-show-log
:active
(org-agenda-check-type nil
'agenda
'timeline
)]
1138 ["Include Diary" org-agenda-toggle-diary
1139 :style toggle
:selected org-agenda-include-diary
:active
(org-agenda-check-type nil
'agenda
)]
1140 ["Use Time Grid" org-agenda-toggle-time-grid
1141 :style toggle
:selected org-agenda-use-time-grid
:active
(org-agenda-check-type nil
'agenda
)])
1142 ["Write view to file" org-write-agenda t
]
1143 ["Rebuild buffer" org-agenda-redo t
]
1144 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1146 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1148 ["Quit" org-agenda-quit t
]
1149 ["Exit and Release Buffers" org-agenda-exit t
]
1154 (defvar org-agenda-allow-remote-undo t
1155 "Non-nil means, allow remote undo from the agenda buffer.")
1156 (defvar org-agenda-undo-list nil
1157 "List of undoable operations in the agenda since last refresh.")
1158 (defvar org-agenda-undo-has-started-in nil
1159 "Buffers that have already seen `undo-start' in the current undo sequence.")
1160 (defvar org-agenda-pending-undo-list nil
1161 "In a series of undo commands, this is the list of remaning undo items.")
1164 (defun org-agenda-undo ()
1165 "Undo a remote editing step in the agenda.
1166 This undoes changes both in the agenda buffer and in the remote buffer
1167 that have been changed along."
1169 (or org-agenda-allow-remote-undo
1170 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1171 (if (not (eq this-command last-command
))
1172 (setq org-agenda-undo-has-started-in nil
1173 org-agenda-pending-undo-list org-agenda-undo-list
))
1174 (if (not org-agenda-pending-undo-list
)
1175 (error "No further undo information"))
1176 (let* ((entry (pop org-agenda-pending-undo-list
))
1177 buf line cmd rembuf
)
1178 (setq cmd
(pop entry
) line
(pop entry
))
1179 (setq rembuf
(nth 2 entry
))
1180 (org-with-remote-undo rembuf
1181 (while (bufferp (setq buf
(pop entry
)))
1183 (with-current-buffer buf
1184 (let ((last-undo-buffer buf
)
1185 (inhibit-read-only t
))
1186 (unless (memq buf org-agenda-undo-has-started-in
)
1187 (push buf org-agenda-undo-has-started-in
)
1188 (make-local-variable 'pending-undo-list
)
1190 (while (and pending-undo-list
1191 (listp pending-undo-list
)
1192 (not (car pending-undo-list
)))
1193 (pop pending-undo-list
))
1196 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1198 (defun org-verify-change-for-undo (l1 l2
)
1199 "Verify that a real change occurred between the undo lists L1 and L2."
1200 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1201 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1206 (defvar org-agenda-restrict nil
)
1207 (defvar org-agenda-restrict-begin
(make-marker))
1208 (defvar org-agenda-restrict-end
(make-marker))
1209 (defvar org-agenda-last-dispatch-buffer nil
)
1210 (defvar org-agenda-overriding-restriction nil
)
1213 (defun org-agenda (arg &optional keys restriction
)
1214 "Dispatch agenda commands to collect entries to the agenda buffer.
1215 Prompts for a command to execute. Any prefix arg will be passed
1216 on to the selected command. The default selections are:
1218 a Call `org-agenda-list' to display the agenda for current day or week.
1219 t Call `org-todo-list' to display the global todo list.
1220 T Call `org-todo-list' to display the global todo list, select only
1221 entries with a specific TODO keyword (the user gets a prompt).
1222 m Call `org-tags-view' to display headlines with tags matching
1223 a condition (the user is prompted for the condition).
1224 M Like `m', but select only TODO entries, no ordinary headlines.
1225 L Create a timeline for the current buffer.
1226 e Export views to associated files.
1228 More commands can be added by configuring the variable
1229 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1230 searches can be pre-defined in this way.
1232 If the current buffer is in Org-mode and visiting a file, you can also
1233 first press `<' once to indicate that the agenda should be temporarily
1234 \(until the next use of \\[org-agenda]) restricted to the current file.
1235 Pressing `<' twice means to restrict to the current subtree or region
1239 (let* ((prefix-descriptions nil
)
1240 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1241 (org-agenda-custom-commands
1242 ;; normalize different versions
1246 (cond ((stringp (cdr x
))
1247 (push x prefix-descriptions
)
1249 ((stringp (nth 1 x
)) x
)
1250 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1251 (t (cons (car x
) (cons "" (cdr x
))))))
1252 org-agenda-custom-commands
)))
1253 (buf (current-buffer))
1254 (bfn (buffer-file-name (buffer-base-buffer)))
1255 entry key type match lprops ans
)
1256 ;; Turn off restriction unless there is an overriding one
1257 (unless org-agenda-overriding-restriction
1258 (put 'org-agenda-files
'org-restrict nil
)
1259 (setq org-agenda-restrict nil
)
1260 (move-marker org-agenda-restrict-begin nil
)
1261 (move-marker org-agenda-restrict-end nil
))
1262 ;; Delete old local properties
1263 (put 'org-agenda-redo-command
'org-lprops nil
)
1264 ;; Remember where this call originated
1265 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1267 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1269 restriction
(cdr ans
)))
1270 ;; Estabish the restriction, if any
1271 (when (and (not org-agenda-overriding-restriction
) restriction
)
1272 (put 'org-agenda-files
'org-restrict
(list bfn
))
1274 ((eq restriction
'region
)
1275 (setq org-agenda-restrict t
)
1276 (move-marker org-agenda-restrict-begin
(region-beginning))
1277 (move-marker org-agenda-restrict-end
(region-end)))
1278 ((eq restriction
'subtree
)
1280 (setq org-agenda-restrict t
)
1281 (org-back-to-heading t
)
1282 (move-marker org-agenda-restrict-begin
(point))
1283 (move-marker org-agenda-restrict-end
1284 (progn (org-end-of-subtree t
)))))))
1286 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1287 ;; For example the todo list should not need it (but does...)
1289 ((setq entry
(assoc keys org-agenda-custom-commands
))
1290 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1292 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1293 (put 'org-agenda-redo-command
'org-lprops lprops
)
1296 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1298 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1300 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1302 (org-let lprops
'(org-agenda-list-stuck-projects
1303 current-prefix-arg
)))
1305 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1306 ((eq type
'tags-todo
)
1307 (org-let lprops
'(org-tags-view '(4) match
)))
1309 (org-let lprops
'(org-todo-list match
)))
1310 ((eq type
'tags-tree
)
1311 (org-check-for-org-mode)
1312 (org-let lprops
'(org-tags-sparse-tree current-prefix-arg match
)))
1313 ((eq type
'todo-tree
)
1314 (org-check-for-org-mode)
1316 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1317 (regexp-quote match
) "\\>"))))
1318 ((eq type
'occur-tree
)
1319 (org-check-for-org-mode)
1320 (org-let lprops
'(org-occur match
)))
1322 (org-let lprops
'(funcall type match
)))
1324 (org-let lprops
'(funcall type match
)))
1325 (t (error "Invalid custom agenda command type %s" type
))))
1326 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1328 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1329 (customize-variable 'org-agenda-custom-commands
))
1330 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1331 ((equal keys
"s") (call-interactively 'org-search-view
))
1332 ((equal keys
"t") (call-interactively 'org-todo-list
))
1333 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1334 ((equal keys
"m") (call-interactively 'org-tags-view
))
1335 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1336 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1338 (unless (org-mode-p)
1339 (error "This is not an Org-mode file"))
1341 (put 'org-agenda-files
'org-restrict
(list bfn
))
1342 (org-call-with-arg 'org-timeline arg
)))
1343 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1344 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1345 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1346 (t (error "Invalid agenda key"))))))
1348 (defun org-agenda-normalize-custom-commands (cmds)
1352 (cond ((stringp (cdr x
)) nil
)
1353 ((stringp (nth 1 x
)) x
)
1354 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1355 (t (cons (car x
) (cons "" (cdr x
))))))
1358 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1359 "The user interface for selecting an agenda command."
1361 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1362 (restrict-ok (and bfn
(org-mode-p)))
1363 (region-p (org-region-active-p))
1364 (custom org-agenda-custom-commands
)
1366 restriction second-time
1367 c entry key type match prefixes rmheader header-end custom1 desc
)
1368 (save-window-excursion
1369 (delete-other-windows)
1370 (org-switch-to-buffer-other-window " *Agenda Commands*")
1372 (insert (eval-when-compile
1375 Press key for an agenda command: < Buffer,subtree/region restriction
1376 -------------------------------- > Remove restriction
1377 a Agenda for current week or day e Export agenda views
1378 t List of all TODO entries T Entries with special TODO kwd
1379 m Match a TAGS query M Like m, but only TODO entries
1380 L Timeline for current buffer # List stuck projects (!=configure)
1381 s Search for keywords C Configure custom agenda commands
1385 (while (string-match
1386 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1388 (setq start
(match-end 0))
1389 (add-text-properties (match-beginning 2) (match-end 2)
1390 '(face bold
) header
))
1392 (setq header-end
(move-marker (make-marker) (point)))
1394 (setq custom1 custom
)
1395 (when (eq rmheader t
)
1397 (re-search-forward ":" nil t
)
1398 (delete-region (match-end 0) (point-at-eol))
1401 (delete-region (match-end 0) (point-at-eol))
1402 (move-marker header-end
(match-end 0)))
1403 (goto-char header-end
)
1404 (delete-region (point) (point-max))
1405 (while (setq entry
(pop custom1
))
1406 (setq key
(car entry
) desc
(nth 1 entry
)
1407 type
(nth 2 entry
) match
(nth 3 entry
))
1408 (if (> (length key
) 1)
1409 (add-to-list 'prefixes
(string-to-char key
))
1413 (org-add-props (copy-sequence key
)
1416 ((string-match "\\S-" desc
) desc
)
1417 ((eq type
'agenda
) "Agenda for current week or day")
1418 ((eq type
'alltodo
) "List of all TODO entries")
1419 ((eq type
'search
) "Word search")
1420 ((eq type
'stuck
) "List of stuck projects")
1421 ((eq type
'todo
) "TODO keyword")
1422 ((eq type
'tags
) "Tags query")
1423 ((eq type
'tags-todo
) "Tags (TODO)")
1424 ((eq type
'tags-tree
) "Tags tree")
1425 ((eq type
'todo-tree
) "TODO kwd tree")
1426 ((eq type
'occur-tree
) "Occur tree")
1427 ((functionp type
) (if (symbolp type
)
1429 "Lambda expression"))
1433 (org-add-props match nil
'face
'org-warning
))
1435 (format "set of %d commands" (length match
)))
1441 (org-add-props (char-to-string x
)
1443 (or (cdr (assoc (concat selstring
(char-to-string x
))
1444 prefix-descriptions
))
1447 (goto-char (point-min))
1448 (when (fboundp 'fit-window-to-buffer
)
1450 (if (not (pos-visible-in-window-p (point-max)))
1451 (fit-window-to-buffer))
1452 (setq second-time t
)
1453 (fit-window-to-buffer)))
1454 (message "Press key for agenda command%s:"
1455 (if (or restrict-ok org-agenda-overriding-restriction
)
1456 (if org-agenda-overriding-restriction
1457 " (restriction lock active)"
1459 (format " (restricted to %s)" restriction
)
1462 (setq c
(read-char-exclusive))
1465 ((assoc (char-to-string c
) custom
)
1466 (setq selstring
(concat selstring
(char-to-string c
)))
1467 (throw 'exit
(cons selstring restriction
)))
1469 (setq selstring
(concat selstring
(char-to-string c
))
1471 rmheader
(or rmheader t
)
1472 custom
(delq nil
(mapcar
1474 (if (or (= (length (car x
)) 1)
1475 (/= (string-to-char (car x
)) c
))
1477 (cons (substring (car x
) 1) (cdr x
))))
1479 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1480 (message "Restriction is only possible in Org-mode buffers")
1483 (org-agenda-remove-restriction-lock 'noupdate
)
1484 (setq restriction
'buffer
))
1486 (org-agenda-remove-restriction-lock 'noupdate
)
1487 (setq restriction
(if region-p
'region
'subtree
)))
1489 (org-agenda-remove-restriction-lock 'noupdate
)
1492 ((eq restriction
'buffer
)
1493 (if region-p
'region
'subtree
))
1494 ((memq restriction
'(subtree region
))
1498 (org-agenda-remove-restriction-lock 'noupdate
)
1499 (setq restriction nil
))
1500 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1501 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1502 ((and (> (length selstring
) 0) (eq c ?\d
))
1504 (org-agenda-get-restriction-and-command prefix-descriptions
))
1506 ((equal c ?q
) (error "Abort"))
1507 (t (error "Invalid key %c" c
))))))))
1509 (defun org-run-agenda-series (name series
)
1510 (org-prepare-agenda name
)
1511 (let* ((org-agenda-multi t
)
1512 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1514 (gprops (nth 1 series
))
1515 match
;; The byte compiler incorrectly complains about this. Keep it!
1517 (while (setq cmd
(pop cmds
))
1518 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1521 (org-let2 gprops lprops
1522 '(call-interactively 'org-agenda-list
)))
1524 (org-let2 gprops lprops
1525 '(call-interactively 'org-todo-list
)))
1527 (org-let2 gprops lprops
1528 '(org-search-view current-prefix-arg match nil
)))
1530 (org-let2 gprops lprops
1531 '(call-interactively 'org-agenda-list-stuck-projects
)))
1533 (org-let2 gprops lprops
1534 '(org-tags-view current-prefix-arg match
)))
1535 ((eq type
'tags-todo
)
1536 (org-let2 gprops lprops
1537 '(org-tags-view '(4) match
)))
1539 (org-let2 gprops lprops
1540 '(org-todo-list match
)))
1542 (org-let2 gprops lprops
1543 '(funcall type match
)))
1544 (t (error "Invalid type in command series"))))
1546 (setq org-agenda-redo-command redo
)
1547 (goto-char (point-min)))
1548 (org-finalize-agenda))
1551 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1552 "Run an agenda command in batch mode and send the result to STDOUT.
1553 If CMD-KEY is a string of length 1, it is used as a key in
1554 `org-agenda-custom-commands' and triggers this command. If it is a
1555 longer string it is used as a tags/todo match string.
1556 Paramters are alternating variable names and values that will be bound
1557 before running the agenda command."
1560 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1561 (if (> (length cmd-key
) 2)
1562 (eval (list 'let
(nreverse pars
)
1563 (list 'org-tags-view nil cmd-key
)))
1564 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1565 (set-buffer org-agenda-buffer-name
)
1566 (princ (org-encode-for-stdout (buffer-string)))))
1568 (defun org-encode-for-stdout (string)
1569 (if (fboundp 'encode-coding-string
)
1570 (encode-coding-string string buffer-file-coding-system
)
1573 (defvar org-agenda-info nil
)
1576 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1577 "Run an agenda command in batch mode and send the result to STDOUT.
1578 If CMD-KEY is a string of length 1, it is used as a key in
1579 `org-agenda-custom-commands' and triggers this command. If it is a
1580 longer string it is used as a tags/todo match string.
1581 Paramters are alternating variable names and values that will be bound
1582 before running the agenda command.
1584 The output gives a line for each selected agenda item. Each
1585 item is a list of comma-separated values, like this:
1587 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1589 category The category of the item
1590 head The headline, without TODO kwd, TAGS and PRIORITY
1591 type The type of the agenda entry, can be
1592 todo selected in TODO match
1593 tagsmatch selected in tags match
1594 diary imported from diary
1595 deadline a deadline on given date
1596 scheduled scheduled on given date
1597 timestamp entry has timestamp on given date
1598 closed entry was closed on given date
1599 upcoming-deadline warning about deadline
1600 past-scheduled forwarded scheduled item
1601 block entry has date block including g. date
1602 todo The todo keyword, if any
1603 tags All tags including inherited ones, separated by colons
1604 date The relevant date, like 2007-2-14
1605 time The time, like 15:00-16:50
1606 extra Sting with extra planning info
1607 priority-l The priority letter if any was given
1608 priority-n The computed numerical priority
1609 agenda-day The day in the agenda where this is listed"
1613 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1614 (push (list 'org-agenda-remove-tags t
) pars
)
1615 (if (> (length cmd-key
) 2)
1616 (eval (list 'let
(nreverse pars
)
1617 (list 'org-tags-view nil cmd-key
)))
1618 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1619 (set-buffer org-agenda-buffer-name
)
1620 (let* ((lines (org-split-string (buffer-string) "\n"))
1622 (while (setq line
(pop lines
))
1624 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1625 (setq org-agenda-info
1626 (org-fix-agenda-info (text-properties-at 0 line
)))
1628 (org-encode-for-stdout
1629 (mapconcat 'org-agenda-export-csv-mapper
1630 '(org-category txt type todo tags date time-of-day extra
1631 priority-letter priority agenda-day
)
1635 (defun org-fix-agenda-info (props)
1636 "Make sure all properties on an agenda item have a canonical form,
1637 so the export commands can easily use it."
1639 (when (setq tmp
(plist-get props
'tags
))
1640 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1641 (when (setq tmp
(plist-get props
'date
))
1642 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1643 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1644 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
1646 (setq tmp
(calendar-date-string tmp
)))
1647 (setq props
(plist-put props
'date tmp
)))
1648 (when (setq tmp
(plist-get props
'day
))
1649 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1650 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1651 (setq tmp
(calendar-date-string tmp
)))
1652 (setq props
(plist-put props
'day tmp
))
1653 (setq props
(plist-put props
'agenda-day tmp
)))
1654 (when (setq tmp
(plist-get props
'txt
))
1655 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
1656 (plist-put props
'priority-letter
(match-string 1 tmp
))
1657 (setq tmp
(replace-match "" t t tmp
)))
1658 (when (and (setq re
(plist-get props
'org-todo-regexp
))
1659 (setq re
(concat "\\`\\.*" re
" ?"))
1660 (string-match re tmp
))
1661 (plist-put props
'todo
(match-string 1 tmp
))
1662 (setq tmp
(replace-match "" t t tmp
)))
1663 (plist-put props
'txt tmp
)))
1666 (defun org-agenda-export-csv-mapper (prop)
1667 (let ((res (plist-get org-agenda-info prop
)))
1672 (t (prin1-to-string res
))))
1673 (while (string-match "," res
)
1674 (setq res
(replace-match ";" t t res
)))
1679 (defun org-store-agenda-views (&rest parameters
)
1681 (eval (list 'org-batch-store-agenda-views
)))
1683 ;; FIXME, why is this a macro?????
1685 (defmacro org-batch-store-agenda-views
(&rest parameters
)
1686 "Run all custom agenda commands that have a file argument."
1687 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
1689 (dir default-directory
)
1690 pars cmd thiscmdkey files opts
)
1692 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1693 (setq pars
(reverse pars
))
1694 (save-window-excursion
1696 (setq cmd
(pop cmds
)
1697 thiscmdkey
(car cmd
)
1700 (if (stringp files
) (setq files
(list files
)))
1702 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1703 (list 'org-agenda nil thiscmdkey
)))
1704 (set-buffer org-agenda-buffer-name
)
1706 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1707 (list 'org-write-agenda
1708 (expand-file-name (pop files
) dir
) t
))))
1709 (and (get-buffer org-agenda-buffer-name
)
1710 (kill-buffer org-agenda-buffer-name
)))))))
1712 (defun org-write-agenda (file &optional nosettings
)
1713 "Write the current buffer (an agenda view) as a file.
1714 Depending on the extension of the file name, plain text (.txt),
1715 HTML (.html or .htm) or Postscript (.ps) is produced.
1716 If the extension is .ics, run icalendar export over all files used
1717 to construct the agenda and limit the export to entries listed in the
1719 If NOSETTINGS is given, do not scope the settings of
1720 `org-agenda-exporter-settings' into the export commands. This is used when
1721 the settings have already been scoped and we do not wish to overrule other,
1722 higher priority settings."
1723 (interactive "FWrite agenda to file: ")
1724 (if (not (file-writable-p file
))
1725 (error "Cannot write agenda to file %s" file
))
1727 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
1728 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
1729 (org-let (if nosettings nil org-agenda-exporter-settings
)
1731 (save-window-excursion
1733 ((string-match "\\.html?\\'" file
)
1734 (set-buffer (htmlize-buffer (current-buffer)))
1736 (when (and org-agenda-export-html-style
1737 (string-match "<style>" org-agenda-export-html-style
))
1738 ;; replace <style> section with org-agenda-export-html-style
1739 (goto-char (point-min))
1740 (kill-region (- (search-forward "<style") 6)
1741 (search-forward "</style>"))
1742 (insert org-agenda-export-html-style
))
1744 (kill-buffer (current-buffer))
1745 (message "HTML written to %s" file
))
1746 ((string-match "\\.ps\\'" file
)
1747 (ps-print-buffer-with-faces file
)
1748 (message "Postscript written to %s" file
))
1749 ((string-match "\\.ics\\'" file
)
1750 (let ((org-agenda-marker-table
1751 (org-create-marker-find-array
1752 (org-agenda-collect-markers)))
1753 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
1754 (org-combined-agenda-icalendar-file file
))
1755 (apply 'org-export-icalendar
'combine
(org-agenda-files))))
1757 (let ((bs (buffer-string)))
1761 (kill-buffer (current-buffer))
1762 (message "Plain text written to %s" file
))))))
1763 (set-buffer org-agenda-buffer-name
)))
1765 (defun org-agenda-collect-markers ()
1766 "Collect the markers pointing to entries in the agenda buffer."
1769 (goto-char (point-min))
1771 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
1772 (get-text-property (point) 'org-marker
)))
1774 (beginning-of-line 2)))
1775 (nreverse markers
)))
1777 (defun org-create-marker-find-array (marker-list)
1778 "Create a alist of files names with all marker positions in that file."
1780 (while (setq m
(pop marker-list
))
1781 (setq p
(marker-position m
)
1782 f
(buffer-file-name (or (buffer-base-buffer
1784 (marker-buffer m
))))
1785 (if (setq a
(assoc f tbl
))
1786 (push (marker-position m
) (cdr a
))
1787 (push (list f p
) tbl
)))
1788 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
1791 (defvar org-agenda-marker-table nil
) ; dyamically scoped parameter
1792 (defun org-check-agenda-marker-table ()
1793 "Check of the current entry is on the marker list."
1794 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
1796 (and (setq a
(assoc file org-agenda-marker-table
))
1799 (org-back-to-heading t
)
1800 (member (point) (cdr a
)))))))
1802 (defun org-check-for-org-mode ()
1803 "Make sure current buffer is in org-mode. Error if not."
1805 (error "Cannot execute org-mode agenda command on buffer in %s."
1808 (defun org-fit-agenda-window ()
1809 "Fit the window to the buffer size."
1810 (and (memq org-agenda-window-setup
'(reorganize-frame))
1811 (fboundp 'fit-window-to-buffer
)
1812 (fit-window-to-buffer
1814 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
1815 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
1817 ;;; Agenda prepare and finalize
1819 (defvar org-agenda-multi nil
) ; dynammically scoped
1820 (defvar org-agenda-buffer-name
"*Org Agenda*")
1821 (defvar org-pre-agenda-window-conf nil
)
1822 (defvar org-agenda-name nil
)
1823 (defun org-prepare-agenda (&optional name
)
1824 (setq org-todo-keywords-for-agenda nil
)
1825 (setq org-done-keywords-for-agenda nil
)
1826 (if org-agenda-multi
1828 (setq buffer-read-only nil
)
1829 (goto-char (point-max))
1830 (unless (or (bobp) org-agenda-compact-blocks
)
1831 (insert "\n" (make-string (window-width) ?
=) "\n"))
1832 (narrow-to-region (point) (point-max)))
1833 (org-agenda-reset-markers)
1834 (org-prepare-agenda-buffers (org-agenda-files))
1835 (setq org-todo-keywords-for-agenda
1836 (org-uniquify org-todo-keywords-for-agenda
))
1837 (setq org-done-keywords-for-agenda
1838 (org-uniquify org-done-keywords-for-agenda
))
1839 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
1840 (awin (get-buffer-window abuf
)))
1842 ((equal (current-buffer) abuf
) nil
)
1843 (awin (select-window awin
))
1844 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
1845 ((equal org-agenda-window-setup
'current-window
)
1846 (switch-to-buffer abuf
))
1847 ((equal org-agenda-window-setup
'other-window
)
1848 (org-switch-to-buffer-other-window abuf
))
1849 ((equal org-agenda-window-setup
'other-frame
)
1850 (switch-to-buffer-other-frame abuf
))
1851 ((equal org-agenda-window-setup
'reorganize-frame
)
1852 (delete-other-windows)
1853 (org-switch-to-buffer-other-window abuf
))))
1854 (setq buffer-read-only nil
)
1857 (and name
(not org-agenda-name
)
1858 (org-set-local 'org-agenda-name name
)))
1859 (setq buffer-read-only nil
))
1861 (defun org-finalize-agenda ()
1862 "Finishing touch for the agenda buffer, called just before displaying it."
1863 (unless org-agenda-multi
1865 (let ((inhibit-read-only t
))
1866 (goto-char (point-min))
1867 (while (org-activate-bracket-links (point-max))
1868 (add-text-properties (match-beginning 0) (match-end 0)
1870 (org-agenda-align-tags)
1871 (unless org-agenda-with-colors
1872 (remove-text-properties (point-min) (point-max) '(face nil
))))
1873 (if (and (boundp 'org-overriding-columns-format
)
1874 org-overriding-columns-format
)
1875 (org-set-local 'org-overriding-columns-format
1876 org-overriding-columns-format
))
1877 (if (and (boundp 'org-agenda-view-columns-initially
)
1878 org-agenda-view-columns-initially
)
1879 (org-agenda-columns))
1880 (when org-agenda-fontify-priorities
1881 (org-fontify-priorities))
1882 (run-hooks 'org-finalize-agenda-hook
)
1883 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
1886 (defun org-fontify-priorities ()
1887 "Make highest priority lines bold, and lowest italic."
1889 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
1890 (org-delete-overlay o
)))
1891 (org-overlays-in (point-min) (point-max)))
1893 (let ((inhibit-read-only t
)
1895 (goto-char (point-min))
1896 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
1897 (setq h
(or (get-char-property (point) 'org-highest-priority
)
1898 org-highest-priority
)
1899 l
(or (get-char-property (point) 'org-lowest-priority
)
1900 org-lowest-priority
)
1901 p
(string-to-char (match-string 1))
1902 b
(match-beginning 0) e
(point-at-eol)
1903 ov
(org-make-overlay b e
))
1906 (cond ((listp org-agenda-fontify-priorities
)
1907 (cdr (assoc p org-agenda-fontify-priorities
)))
1908 ((equal p l
) 'italic
)
1909 ((equal p h
) 'bold
)))
1910 (org-overlay-put ov
'org-type
'org-priority
)))))
1913 (defvar org-agenda-skip-function nil
1914 "Function to be called at each match during agenda construction.
1915 If this function returns nil, the current match should not be skipped.
1916 Otherwise, the function must return a position from where the search
1917 should be continued.
1918 This may also be a Lisp form, it will be evaluated.
1919 Never set this variable using `setq' or so, because then it will apply
1920 to all future agenda commands. Instead, bind it with `let' to scope
1921 it dynamically into the agenda-constructing command. A good way to set
1922 it is through options in org-agenda-custom-commands.")
1924 (defun org-agenda-skip ()
1925 "Throw to `:skip' in places that should be skipped.
1926 Also moves point to the end of the skipped region, so that search can
1927 continue from there."
1928 (let ((p (point-at-bol)) to fp
)
1929 (and org-agenda-skip-archived-trees
1930 (get-text-property p
:org-archived
)
1931 (org-end-of-subtree t
)
1933 (and (get-text-property p
:org-comment
)
1934 (org-end-of-subtree t
)
1936 (if (equal (char-after p
) ?
#) (throw :skip t
))
1937 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
1938 (consp org-agenda-skip-function
))
1939 (setq to
(save-excursion
1942 (funcall org-agenda-skip-function
)
1943 (eval org-agenda-skip-function
))))))
1947 (defvar org-agenda-markers nil
1948 "List of all currently active markers created by `org-agenda'.")
1949 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
1950 "Creation time of the last agenda marker.")
1952 (defun org-agenda-new-marker (&optional pos
)
1953 "Return a new agenda marker.
1954 Org-mode keeps a list of these markers and resets them when they are
1956 (let ((m (copy-marker (or pos
(point)))))
1957 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
1958 (push m org-agenda-markers
)
1961 (defun org-agenda-reset-markers ()
1962 "Reset markers created by `org-agenda'."
1963 (while org-agenda-markers
1964 (move-marker (pop org-agenda-markers
) nil
)))
1968 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
1970 (defun org-timeline (&optional include-all
)
1971 "Show a time-sorted view of the entries in the current org file.
1972 Only entries with a time stamp of today or later will be listed. With
1973 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
1974 under the current date.
1975 If the buffer contains an active region, only check the region for
1979 (org-compile-prefix-format 'timeline
)
1980 (org-set-sorting-strategy 'timeline
)
1982 (dotodo include-all
)
1983 (doclosed org-agenda-show-log
)
1984 (entry buffer-file-name
)
1985 (date (calendar-current-date))
1986 (beg (if (org-region-active-p) (region-beginning) (point-min)))
1987 (end (if (org-region-active-p) (region-end) (point-max)))
1988 (day-numbers (org-get-all-dates beg end
'no-ranges
1989 t doclosed
; always include today
1990 org-timeline-show-empty-dates
))
1991 (org-deadline-warning-days 0)
1992 (org-agenda-only-exact-dates t
)
1993 (today (time-to-days (current-time)))
1997 (setq org-agenda-redo-command
1999 (list 'org-switch-to-buffer-other-window
(current-buffer))
2000 (list 'org-timeline
(list 'quote include-all
))))
2002 ;; Remove past dates from the list of dates.
2003 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2004 (if (>= x today
) x nil
))
2006 (org-prepare-agenda (concat "Timeline "
2007 (file-name-nondirectory buffer-file-name
)))
2008 (if doclosed
(push :closed args
))
2009 (push :timestamp args
)
2010 (push :deadline args
)
2011 (push :scheduled args
)
2013 (if dotodo
(push :todo args
))
2014 (while (setq d
(pop day-numbers
))
2015 (if (and (listp d
) (eq (car d
) :omitted
))
2018 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2019 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2020 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2021 (if (and (>= d today
)
2026 (insert (make-string 79 ?-
) "\n")))
2027 (setq date
(calendar-gregorian-from-absolute d
))
2029 (setq rtn
(and (not emptyp
)
2030 (apply 'org-agenda-get-day-entries entry
2032 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2035 (if (stringp org-agenda-format-date
)
2036 (format-time-string org-agenda-format-date
2037 (org-time-from-absolute date
))
2038 (funcall org-agenda-format-date date
))
2040 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
)
2041 (put-text-property s
(1- (point)) 'org-date-line t
)
2043 (put-text-property s
(1- (point)) 'org-today t
))
2044 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2045 (put-text-property s
(1- (point)) 'day d
)))))
2046 (goto-char (point-min))
2047 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2049 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2050 (org-finalize-agenda)
2051 (setq buffer-read-only t
)))
2053 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2054 "Return a list of all relevant day numbers from BEG to END buffer positions.
2055 If NO-RANGES is non-nil, include only the start and end dates of a range,
2056 not every single day in the range. If FORCE-TODAY is non-nil, make
2057 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2058 inactive time stamps (those in square brackets) are included.
2059 When EMPTY is non-nil, also include days without any entries."
2061 (if pre-re pre-re
"")
2062 (if inactive org-ts-regexp-both org-ts-regexp
)))
2063 dates dates1 date day day1 day2 ts1 ts2
)
2065 (setq dates
(list (time-to-days (current-time)))))
2068 (while (re-search-forward re end t
)
2069 (setq day
(time-to-days (org-time-string-to-time
2070 (substring (match-string 1) 0 10))))
2071 (or (memq day dates
) (push day dates
)))
2074 (while (re-search-forward org-tr-regexp end t
)
2075 (setq ts1
(substring (match-string 1) 0 10)
2076 ts2
(substring (match-string 2) 0 10)
2077 day1
(time-to-days (org-time-string-to-time ts1
))
2078 day2
(time-to-days (org-time-string-to-time ts2
)))
2079 (while (< (setq day1
(1+ day1
)) day2
)
2080 (or (memq day1 dates
) (push day1 dates
)))))
2081 (setq dates
(sort dates
'<))
2083 (while (setq day
(pop dates
))
2084 (setq day2
(car dates
))
2086 (when (and day2 empty
)
2087 (if (or (eq empty t
)
2088 (and (numberp empty
) (<= (- day2 day
) empty
)))
2089 (while (< (setq day
(1+ day
)) day2
)
2090 (push (list day
) dates1
))
2091 (push (cons :omitted
(- day2 day
)) dates1
))))
2092 (setq dates
(nreverse dates1
)))
2095 ;;; Agenda Daily/Weekly
2097 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2098 (defvar org-agenda-start-day nil
) ; dynamically scoped parameter
2099 (defvar org-agenda-last-arguments nil
2100 "The arguments of the previous call to org-agenda")
2101 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2102 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2103 (defvar org-include-all-loc nil
) ; local variable
2104 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2107 (defun org-agenda-list (&optional include-all start-day ndays
)
2108 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2109 The view will be for the current day or week, but from the overview buffer
2110 you will be able to go to other days/weeks.
2112 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2113 all unfinished TODO items will also be shown, before the agenda.
2114 This feature is considered obsolete, please use the TODO list or a block
2117 With a numeric prefix argument in an interactive call, the agenda will
2118 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2119 the number of days. NDAYS defaults to `org-agenda-ndays'.
2121 START-DAY defaults to TODAY, or to the most recent match for the weekday
2122 given in `org-agenda-start-on-weekday'."
2124 (if (and (integerp include-all
) (> include-all
0))
2125 (setq ndays include-all include-all nil
))
2126 (setq ndays
(or ndays org-agenda-ndays
)
2127 start-day
(or start-day org-agenda-start-day
))
2128 (if org-agenda-overriding-arguments
2129 (setq include-all
(car org-agenda-overriding-arguments
)
2130 start-day
(nth 1 org-agenda-overriding-arguments
)
2131 ndays
(nth 2 org-agenda-overriding-arguments
)))
2132 (if (stringp start-day
)
2133 ;; Convert to an absolute day number
2134 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2135 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2136 (org-compile-prefix-format 'agenda
)
2137 (org-set-sorting-strategy 'agenda
)
2139 (let* ((org-agenda-start-on-weekday
2140 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2141 org-agenda-start-on-weekday nil
))
2142 (thefiles (org-agenda-files))
2144 (today (time-to-days
2145 (time-subtract (current-time)
2146 (list 0 (* 3600 org-extend-today-until
) 0))))
2147 (sd (or start-day today
))
2148 (start (if (or (null org-agenda-start-on-weekday
)
2149 (< org-agenda-ndays
7))
2151 (let* ((nt (calendar-day-of-week
2152 (calendar-gregorian-from-absolute sd
)))
2153 (n1 org-agenda-start-on-weekday
)
2155 (- sd
(+ (if (< d
0) 7 0) d
)))))
2156 (day-numbers (list start
))
2158 (inhibit-redisplay (not debug-on-error
))
2159 s e rtn rtnall file date d start-pos end-pos todayp nd
)
2160 (setq org-agenda-redo-command
2161 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2162 ;; Make the list of days
2163 (setq ndays
(or ndays org-agenda-ndays
)
2166 (push (1+ (car day-numbers
)) day-numbers
)
2167 (setq ndays
(1- ndays
)))
2168 (setq day-numbers
(nreverse day-numbers
))
2169 (org-prepare-agenda "Day/Week")
2170 (org-set-local 'org-starting-day
(car day-numbers
))
2171 (org-set-local 'org-include-all-loc include-all
)
2172 (org-set-local 'org-agenda-span
2173 (org-agenda-ndays-to-span nd
))
2174 (when (and (or include-all org-agenda-include-all-todo
)
2175 (member today day-numbers
))
2176 (setq files thefiles
2178 (while (setq file
(pop files
))
2180 (org-check-agenda-file file
)
2181 (setq date
(calendar-gregorian-from-absolute today
)
2182 rtn
(org-agenda-get-day-entries
2184 (setq rtnall
(append rtnall rtn
))))
2186 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2187 (add-text-properties (point-min) (1- (point))
2188 (list 'face
'org-agenda-structure
))
2189 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2190 (unless org-agenda-compact-blocks
2191 (let* ((d1 (car day-numbers
))
2192 (d2 (org-last day-numbers
))
2193 (w1 (org-days-to-iso-week d1
))
2194 (w2 (org-days-to-iso-week d2
)))
2196 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2198 (if (< (- d2 d1
) 350)
2200 (format " (W%02d)" w1
)
2201 (format " (W%02d-W%02d)" w1 w2
))
2204 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2206 (while (setq d
(pop day-numbers
))
2207 (setq date
(calendar-gregorian-from-absolute d
)
2209 (if (or (setq todayp
(= d today
))
2210 (and (not start-pos
) (= d sd
)))
2211 (setq start-pos
(point))
2212 (if (and start-pos
(not end-pos
))
2213 (setq end-pos
(point))))
2214 (setq files thefiles
2216 (while (setq file
(pop files
))
2218 (org-check-agenda-file file
)
2219 (if org-agenda-show-log
2220 (setq rtn
(org-agenda-get-day-entries
2222 :deadline
:scheduled
:timestamp
:sexp
:closed
))
2223 (setq rtn
(org-agenda-get-day-entries
2225 :deadline
:scheduled
:sexp
:timestamp
)))
2226 (setq rtnall
(append rtnall rtn
))))
2227 (if org-agenda-include-diary
2229 (require 'diary-lib
)
2230 (setq rtn
(org-get-entries-from-diary date
))
2231 (setq rtnall
(append rtnall rtn
))))
2232 (if (or rtnall org-agenda-show-all-dates
)
2234 (setq day-cnt
(1+ day-cnt
))
2236 (if (stringp org-agenda-format-date
)
2237 (format-time-string org-agenda-format-date
2238 (org-time-from-absolute date
))
2239 (funcall org-agenda-format-date date
))
2241 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
)
2242 (put-text-property s
(1- (point)) 'org-date-line t
)
2243 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2244 (if todayp
(put-text-property s
(1- (point)) 'org-today t
))
2246 (org-finalize-agenda-entries
2247 (org-agenda-add-time-grid-maybe
2250 (put-text-property s
(1- (point)) 'day d
)
2251 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2252 (goto-char (point-min))
2253 (org-fit-agenda-window)
2254 (unless (and (pos-visible-in-window-p (point-min))
2255 (pos-visible-in-window-p (point-max)))
2256 (goto-char (1- (point-max)))
2258 (if (not (pos-visible-in-window-p (or start-pos
1)))
2260 (goto-char (or start-pos
1))
2262 (goto-char (or start-pos
1))
2263 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2264 (org-finalize-agenda)
2265 (setq buffer-read-only t
)
2268 (defun org-agenda-ndays-to-span (n)
2269 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2271 ;;; Agenda word search
2273 (defvar org-agenda-search-history nil
)
2274 (defvar org-todo-only nil
)
2276 (defvar org-search-syntax-table nil
2277 "Special syntax table for org-mode search.
2278 In this table, we have single quotes not as word constituents, to
2279 that when \"+Ameli\" is searchd as a work, it will also match \"Ameli's\"")
2281 (defun org-search-syntax-table ()
2282 (unless org-search-syntax-table
2283 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2284 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2285 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2286 org-search-syntax-table
)
2289 (defun org-search-view (&optional todo-only string edit-at
)
2290 "Show all entries that contain words or regular expressions.
2291 If the first character of the search string is an asterisks,
2292 search only the headlines.
2294 With optional prefix argument TODO-ONLY, only consider entries that are
2295 TODO entries. The argument STRING can be used to pass a default search
2296 string into this function. If EDIT-AT is non-nil, it means that the
2297 user should get a chance to edit this string, with cursor at position
2300 The search string is broken into \"words\" by splitting at whitespace.
2301 The individual words are then interpreted as a boolean expression with
2302 logical AND. Words prefixed with a minus must not occur in the entry.
2303 Words without a prefix or prefixed with a plus must occur in the entry.
2304 Matching is case-insensitive and the words are enclosed by word delimiters.
2306 Words enclosed by curly braces are interpreted as regular expressions
2307 that must or must not match in the entry.
2309 If the search string starts with an asterisk, search only in headlines.
2310 If (possibly after the leading star) the search string starts with an
2311 exclamation mark, this also means to look at TODO entries only, an effect
2312 that can also be achieved with a prefix argument.
2314 This command searches the agenda files, and in addition the files listed
2315 in `org-agenda-text-search-extra-files'."
2317 (org-compile-prefix-format 'search
)
2318 (org-set-sorting-strategy 'search
)
2319 (org-prepare-agenda "SEARCH")
2320 (let* ((props (list 'face nil
2321 'done-face
'org-done
2322 'org-not-done-regexp org-not-done-regexp
2323 'org-todo-regexp org-todo-regexp
2324 'mouse-face
'highlight
2325 'keymap org-agenda-keymap
2326 'help-echo
(format "mouse-2 or RET jump to location")))
2327 regexp rtn rtnall files file pos
2328 marker priority category tags c neg re
2329 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2330 (unless (and (not edit-at
)
2332 (string-match "\\S-" string
))
2333 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2335 ((integerp edit-at
) (cons string edit-at
))
2337 'org-agenda-search-history
)))
2338 (org-set-local 'org-todo-only todo-only
)
2339 (setq org-agenda-redo-command
2340 (list 'org-search-view
(if todo-only t nil
) string
2341 '(if current-prefix-arg
1 nil
)))
2342 (setq org-agenda-query-string string
)
2344 (if (equal (string-to-char string
) ?
*)
2346 words
(substring string
1))
2347 (setq words string
))
2348 (when (equal (string-to-char words
) ?
!)
2350 words
(substring words
1)))
2351 (setq words
(org-split-string words
))
2353 (setq c
(string-to-char w
))
2355 (setq neg t w
(substring w
1))
2357 (setq neg nil w
(substring w
1))
2359 (if (string-match "\\`{.*}\\'" w
)
2360 (setq re
(substring w
1 -
1))
2361 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2362 (if neg
(push re regexps-
) (push re regexps
+)))
2364 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2366 (setq regexp
(concat "^" org-outline-regexp
))
2367 (setq regexp
(pop regexps
+))
2368 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2370 (setq files
(append (org-agenda-files) org-agenda-text-search-extra-files
)
2372 (while (setq file
(pop files
))
2375 (org-check-agenda-file file
)
2376 (setq buffer
(if (file-exists-p file
)
2377 (org-get-agenda-file-buffer file
)
2378 (error "No such file %s" file
)))
2380 ;; If file does not exist, make sure an error message is sent
2381 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2383 (with-current-buffer buffer
2384 (with-syntax-table (org-search-syntax-table)
2385 (unless (org-mode-p)
2386 (error "Agenda file %s is not in `org-mode'" file
))
2387 (let ((case-fold-search t
))
2390 (if org-agenda-restrict
2391 (narrow-to-region org-agenda-restrict-begin
2392 org-agenda-restrict-end
)
2394 (goto-char (point-min))
2395 (unless (or (org-on-heading-p)
2396 (outline-next-heading))
2397 (throw 'nextfile t
))
2398 (goto-char (max (point-min) (1- (point))))
2399 (while (re-search-forward regexp nil t
)
2400 (org-back-to-heading t
)
2401 (skip-chars-forward "* ")
2402 (setq beg
(point-at-bol)
2404 end
(progn (outline-next-heading) (point)))
2408 (setq str
(buffer-substring-no-properties
2410 (if hdl-only
(point-at-eol) end
)))
2411 (mapc (lambda (wr) (when (string-match wr str
)
2412 (goto-char (1- end
))
2415 (mapc (lambda (wr) (unless (string-match wr str
)
2416 (goto-char (1- end
))
2419 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
2423 (setq marker
(org-agenda-new-marker (point))
2424 category
(org-get-category)
2425 tags
(org-get-tags-at (point))
2426 txt
(org-format-agenda-item
2428 (buffer-substring-no-properties
2429 beg1
(point-at-eol))
2431 (org-add-props txt props
2432 'org-marker marker
'org-hd-marker marker
2433 'org-todo-regexp org-todo-regexp
2434 'priority
1000 'org-category category
2437 (goto-char (1- end
))))))))))
2438 (setq rtn
(nreverse ee
))
2439 (setq rtnall
(append rtnall rtn
)))
2440 (if org-agenda-overriding-header
2441 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2442 nil
'face
'org-agenda-structure
) "\n")
2443 (insert "Search words: ")
2444 (add-text-properties (point-min) (1- (point))
2445 (list 'face
'org-agenda-structure
))
2447 (insert string
"\n")
2448 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2450 (unless org-agenda-multi
2451 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
2452 (add-text-properties pos
(1- (point))
2453 (list 'face
'org-agenda-structure
))))
2455 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2456 (goto-char (point-min))
2457 (org-fit-agenda-window)
2458 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
2459 (org-finalize-agenda)
2460 (setq buffer-read-only t
)))
2462 ;;; Agenda TODO list
2464 (defvar org-select-this-todo-keyword nil
)
2465 (defvar org-last-arg nil
)
2468 (defun org-todo-list (arg)
2469 "Show all TODO entries from all agenda file in a single list.
2470 The prefix arg can be used to select a specific TODO keyword and limit
2471 the list to these. When using \\[universal-argument], you will be prompted
2472 for a keyword. A numeric prefix directly selects the Nth keyword in
2473 `org-todo-keywords-1'."
2476 (org-compile-prefix-format 'todo
)
2477 (org-set-sorting-strategy 'todo
)
2478 (org-prepare-agenda "TODO")
2479 (let* ((today (time-to-days (current-time)))
2480 (date (calendar-gregorian-from-absolute today
))
2481 (kwds org-todo-keywords-for-agenda
)
2482 (completion-ignore-case t
)
2483 (org-select-this-todo-keyword
2484 (if (stringp arg
) arg
2485 (and arg
(integerp arg
) (> arg
0)
2486 (nth (1- arg
) kwds
))))
2487 rtn rtnall files file pos
)
2488 (when (equal arg
'(4))
2489 (setq org-select-this-todo-keyword
2490 (completing-read "Keyword (or KWD1|K2D2|...): "
2491 (mapcar 'list kwds
) nil nil
)))
2492 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
2493 (org-set-local 'org-last-arg arg
)
2494 (setq org-agenda-redo-command
2495 '(org-todo-list (or current-prefix-arg org-last-arg
)))
2496 (setq files
(org-agenda-files)
2498 (while (setq file
(pop files
))
2500 (org-check-agenda-file file
)
2501 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
2502 (setq rtnall
(append rtnall rtn
))))
2503 (if org-agenda-overriding-header
2504 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2505 nil
'face
'org-agenda-structure
) "\n")
2506 (insert "Global list of TODO items of type: ")
2507 (add-text-properties (point-min) (1- (point))
2508 (list 'face
'org-agenda-structure
))
2510 (insert (or org-select-this-todo-keyword
"ALL") "\n")
2511 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2513 (unless org-agenda-multi
2514 (insert "Available with `N r': (0)ALL")
2517 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
2518 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
2523 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2525 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2526 (goto-char (point-min))
2527 (org-fit-agenda-window)
2528 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
2529 (org-finalize-agenda)
2530 (setq buffer-read-only t
)))
2532 ;;; Agenda tags match
2535 (defun org-tags-view (&optional todo-only match
)
2536 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
2537 The prefix arg TODO-ONLY limits the search to TODO entries."
2539 (org-compile-prefix-format 'tags
)
2540 (org-set-sorting-strategy 'tags
)
2541 (let* ((org-tags-match-list-sublevels
2542 (if todo-only t org-tags-match-list-sublevels
))
2543 (completion-ignore-case t
)
2544 rtn rtnall files file pos matcher
2546 (setq matcher
(org-make-tags-matcher match
)
2547 match
(car matcher
) matcher
(cdr matcher
))
2548 (org-prepare-agenda (concat "TAGS " match
))
2549 (setq org-agenda-query-string match
)
2550 (setq org-agenda-redo-command
2551 (list 'org-tags-view
(list 'quote todo-only
)
2552 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
2553 (setq files
(org-agenda-files)
2555 (while (setq file
(pop files
))
2557 (org-check-agenda-file file
)
2558 (setq buffer
(if (file-exists-p file
)
2559 (org-get-agenda-file-buffer file
)
2560 (error "No such file %s" file
)))
2562 ;; If file does not exist, merror message to agenda
2564 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
2565 rtnall
(append rtnall rtn
))
2566 (with-current-buffer buffer
2567 (unless (org-mode-p)
2568 (error "Agenda file %s is not in `org-mode'" file
))
2571 (if org-agenda-restrict
2572 (narrow-to-region org-agenda-restrict-begin
2573 org-agenda-restrict-end
)
2575 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
2576 (setq rtnall
(append rtnall rtn
))))))))
2577 (if org-agenda-overriding-header
2578 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2579 nil
'face
'org-agenda-structure
) "\n")
2580 (insert "Headlines with TAGS match: ")
2581 (add-text-properties (point-min) (1- (point))
2582 (list 'face
'org-agenda-structure
))
2585 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2587 (unless org-agenda-multi
2588 (insert "Press `C-u r' to search again with new search string\n"))
2589 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2591 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2592 (goto-char (point-min))
2593 (org-fit-agenda-window)
2594 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
2595 (org-finalize-agenda)
2596 (setq buffer-read-only t
)))
2598 ;;; Agenda Finding stuck projects
2600 (defvar org-agenda-skip-regexp nil
2601 "Regular expression used in skipping subtrees for the agenda.
2602 This is basically a temporary global variable that can be set and then
2603 used by user-defined selections using `org-agenda-skip-function'.")
2605 (defvar org-agenda-overriding-header nil
2606 "When this is set during todo and tags searches, will replace header.")
2608 (defun org-agenda-skip-subtree-when-regexp-matches ()
2609 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
2610 If yes, it returns the end position of this tree, causing agenda commands
2611 to skip this subtree. This is a function that can be put into
2612 `org-agenda-skip-function' for the duration of a command."
2613 (let ((end (save-excursion (org-end-of-subtree t
)))
2616 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
2619 (defun org-agenda-skip-entry-if (&rest conditions
)
2620 "Skip entry if any of CONDITIONS is true.
2621 See `org-agenda-skip-if' for details."
2622 (org-agenda-skip-if nil conditions
))
2624 (defun org-agenda-skip-subtree-if (&rest conditions
)
2625 "Skip entry if any of CONDITIONS is true.
2626 See `org-agenda-skip-if' for details."
2627 (org-agenda-skip-if t conditions
))
2629 (defun org-agenda-skip-if (subtree conditions
)
2630 "Checks current entity for CONDITIONS.
2631 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
2632 the entry, i.e. the text before the next heading is checked.
2634 CONDITIONS is a list of symbols, boolean OR is used to combine the results
2635 from different tests. Valid conditions are:
2637 scheduled Check if there is a scheduled cookie
2638 notscheduled Check if there is no scheduled cookie
2639 deadline Check if there is a deadline
2640 notdeadline Check if there is no deadline
2641 regexp Check if regexp matches
2642 notregexp Check if regexp does not match.
2644 The regexp is taken from the conditions list, it must come right after
2645 the `regexp' or `notregexp' element.
2647 If any of these conditions is met, this function returns the end point of
2648 the entity, causing the search to continue from there. This is a function
2649 that can be put into `org-agenda-skip-function' for the duration of a command."
2651 (org-back-to-heading t
)
2654 (progn (org-end-of-subtree t
) (point))
2655 (progn (outline-next-heading) (1- (point)))))
2659 (and (memq 'scheduled conditions
)
2660 (re-search-forward org-scheduled-time-regexp end t
))
2661 (and (memq 'notscheduled conditions
)
2662 (not (re-search-forward org-scheduled-time-regexp end t
)))
2663 (and (memq 'deadline conditions
)
2664 (re-search-forward org-deadline-time-regexp end t
))
2665 (and (memq 'notdeadline conditions
)
2666 (not (re-search-forward org-deadline-time-regexp end t
)))
2667 (and (setq m
(memq 'regexp conditions
))
2669 (re-search-forward (nth 1 m
) end t
))
2670 (and (setq m
(memq 'notregexp conditions
))
2672 (not (re-search-forward (nth 1 m
) end t
))))
2676 (defun org-agenda-list-stuck-projects (&rest ignore
)
2677 "Create agenda view for projects that are stuck.
2678 Stuck projects are project that have no next actions. For the definitions
2679 of what a project is and how to check if it stuck, customize the variable
2680 `org-stuck-projects'.
2681 MATCH is being ignored."
2683 (let* ((org-agenda-skip-function 'org-agenda-skip-subtree-when-regexp-matches
)
2684 ;; FIXME: we could have used org-agenda-skip-if here.
2685 (org-agenda-overriding-header "List of stuck projects: ")
2686 (matcher (nth 0 org-stuck-projects
))
2687 (todo (nth 1 org-stuck-projects
))
2688 (todo-wds (if (member "*" todo
)
2690 (org-prepare-agenda-buffers (org-agenda-files))
2692 org-done-keywords-for-agenda
2693 (copy-sequence org-todo-keywords-for-agenda
)))
2695 (todo-re (concat "^\\*+[ \t]+\\("
2696 (mapconcat 'identity todo-wds
"\\|")
2698 (tags (nth 2 org-stuck-projects
))
2699 (tags-re (if (member "*" tags
)
2700 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
2701 (concat "^\\*+ .*:\\("
2702 (mapconcat 'identity tags
"\\|")
2703 (org-re "\\):[[:alnum:]_@:]*[ \t]*$"))))
2704 (gen-re (nth 3 org-stuck-projects
))
2710 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
2712 (setq org-agenda-skip-regexp
2714 (mapconcat 'identity re-list
"\\|")
2715 (error "No information how to identify unstuck projects")))
2716 (org-tags-view nil matcher
)
2717 (with-current-buffer org-agenda-buffer-name
2718 (setq org-agenda-redo-command
2719 '(org-agenda-list-stuck-projects
2720 (or current-prefix-arg org-last-arg
))))))
2722 ;;; Diary integration
2724 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
2725 (defvar list-diary-entries-hook
)
2727 (defun org-get-entries-from-diary (date)
2728 "Get the (Emacs Calendar) diary entries for DATE."
2729 (require 'diary-lib
)
2730 (let* ((fancy-diary-buffer "*temporary-fancy-diary-buffer*")
2731 (diary-display-hook '(fancy-diary-display))
2733 (list-diary-entries-hook
2734 (cons 'org-diary-default-entry list-diary-entries-hook
))
2735 (diary-file-name-prefix-function nil
) ; turn this feature off
2736 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
2738 (org-disable-agenda-to-diary t
))
2740 (save-window-excursion
2741 (funcall (if (fboundp 'diary-list-entries
)
2742 'diary-list-entries
'list-diary-entries
)
2744 (if (not (get-buffer fancy-diary-buffer
))
2746 (with-current-buffer fancy-diary-buffer
2747 (setq buffer-read-only nil
)
2748 (if (zerop (buffer-size))
2751 ;; Omit the date and other unnecessary stuff
2752 (org-agenda-cleanup-fancy-diary)
2753 ;; Add prefix to each line and extend the text properties
2754 (if (zerop (buffer-size))
2756 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
2757 (set-buffer-modified-p nil
)
2758 (kill-buffer fancy-diary-buffer
)))
2760 (setq entries
(org-split-string entries
"\n"))
2764 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
2765 ;; Extend the text properties to the beginning of the line
2766 (org-add-props x
(text-properties-at (1- (length x
)) x
)
2767 'type
"diary" 'date date
))
2770 (defun org-agenda-cleanup-fancy-diary ()
2771 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
2772 This gets rid of the date, the underline under the date, and
2773 the dummy entry installed by `org-mode' to ensure non-empty diary for each
2774 date. It also removes lines that contain only whitespace."
2775 (goto-char (point-min))
2776 (if (looking-at ".*?:[ \t]*")
2779 (re-search-forward "\n=+$" nil t
)
2781 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
2782 (re-search-forward "\n=+$" nil t
)
2783 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
2784 (goto-char (point-min))
2785 (while (re-search-forward "^ +\n" nil t
)
2787 (goto-char (point-min))
2788 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
2789 (replace-match "")))
2791 ;; Make sure entries from the diary have the right text properties.
2792 (eval-after-load "diary-lib"
2793 '(if (boundp 'diary-modify-entry-list-string-function
)
2794 ;; We can rely on the hook, nothing to do
2796 ;; Hook not avaiable, must use advice to make this work
2797 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
2798 "Make the position visible."
2799 (if (and org-disable-agenda-to-diary
;; called from org-agenda
2802 (setq string
(org-modify-diary-entry-string string
))))))
2804 (defun org-modify-diary-entry-string (string)
2805 "Add text properties to string, allowing org-mode to act on it."
2806 (org-add-props string nil
2807 'mouse-face
'highlight
2808 'keymap org-agenda-keymap
2809 'help-echo
(if buffer-file-name
2810 (format "mouse-2 or RET jump to diary file %s"
2811 (abbreviate-file-name buffer-file-name
))
2813 'org-agenda-diary-link t
2814 'org-marker
(org-agenda-new-marker (point-at-bol))))
2816 (defun org-diary-default-entry ()
2817 "Add a dummy entry to the diary.
2818 Needed to avoid empty dates which mess up holiday display."
2819 ;; Catch the error if dealing with the new add-to-diary-alist
2820 (when org-disable-agenda-to-diary
2822 (add-to-diary-list original-date
"Org-mode dummy" "")
2824 (add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
2827 (defun org-diary (&rest args
)
2828 "Return diary information from org-files.
2829 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
2830 It accesses org files and extracts information from those files to be
2831 listed in the diary. The function accepts arguments specifying what
2832 items should be listed. The following arguments are allowed:
2834 :timestamp List the headlines of items containing a date stamp or
2835 date range matching the selected date. Deadlines will
2836 also be listed, on the expiration day.
2838 :sexp List entries resulting from diary-like sexps.
2840 :deadline List any deadlines past due, or due within
2841 `org-deadline-warning-days'. The listing occurs only
2842 in the diary for *today*, not at any other date. If
2843 an entry is marked DONE, it is no longer listed.
2845 :scheduled List all items which are scheduled for the given date.
2846 The diary for *today* also contains items which were
2847 scheduled earlier and are not yet marked DONE.
2849 :todo List all TODO items from the org-file. This may be a
2850 long list - so this is not turned on by default.
2851 Like deadlines, these entries only show up in the
2852 diary for *today*, not at any other date.
2854 The call in the diary file should look like this:
2856 &%%(org-diary) ~/path/to/some/orgfile.org
2858 Use a separate line for each org file to check. Or, if you omit the file name,
2859 all files listed in `org-agenda-files' will be checked automatically:
2863 If you don't give any arguments (as in the example above), the default
2864 arguments (:deadline :scheduled :timestamp :sexp) are used.
2865 So the example above may also be written as
2867 &%%(org-diary :deadline :timestamp :sexp :scheduled)
2869 The function expects the lisp variables `entry' and `date' to be provided
2870 by the caller, because this is how the calendar works. Don't use this
2871 function from a program - use `org-agenda-get-day-entries' instead."
2872 (when (> (- (time-to-seconds (current-time))
2873 org-agenda-last-marker-time
)
2875 (org-agenda-reset-markers))
2876 (org-compile-prefix-format 'agenda
)
2877 (org-set-sorting-strategy 'agenda
)
2878 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
2879 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
2881 (org-agenda-files t
)))
2883 (org-prepare-agenda-buffers files
)
2884 ;; If this is called during org-agenda, don't return any entries to
2885 ;; the calendar. Org Agenda will list these entries itself.
2886 (if org-disable-agenda-to-diary
(setq files nil
))
2887 (while (setq file
(pop files
))
2888 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
2889 (setq results
(append results rtn
)))
2891 (concat (org-finalize-agenda-entries results
) "\n"))))
2893 ;;; Agenda entry finders
2895 (defun org-agenda-get-day-entries (file date
&rest args
)
2896 "Does the work for `org-diary' and `org-agenda'.
2897 FILE is the path to a file to be checked for entries. DATE is date like
2898 the one returned by `calendar-current-date'. ARGS are symbols indicating
2899 which kind of entries should be extracted. For details about these, see
2900 the documentation of `org-diary'."
2901 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
2902 (let* ((org-startup-folded nil
)
2903 (org-startup-align-all-tables nil
)
2904 (buffer (if (file-exists-p file
)
2905 (org-get-agenda-file-buffer file
)
2906 (error "No such file %s" file
)))
2909 ;; If file does not exist, make sure an error message ends up in diary
2910 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
2911 (with-current-buffer buffer
2912 (unless (org-mode-p)
2913 (error "Agenda file %s is not in `org-mode'" file
))
2914 (let ((case-fold-search nil
))
2917 (if org-agenda-restrict
2918 (narrow-to-region org-agenda-restrict-begin
2919 org-agenda-restrict-end
)
2921 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
2922 (while (setq arg
(pop args
))
2924 ((and (eq arg
:todo
)
2925 (equal date
(calendar-current-date)))
2926 (setq rtn
(org-agenda-get-todos))
2927 (setq results
(append results rtn
)))
2928 ((eq arg
:timestamp
)
2929 (setq rtn
(org-agenda-get-blocks))
2930 (setq results
(append results rtn
))
2931 (setq rtn
(org-agenda-get-timestamps))
2932 (setq results
(append results rtn
)))
2934 (setq rtn
(org-agenda-get-sexps))
2935 (setq results
(append results rtn
)))
2936 ((eq arg
:scheduled
)
2937 (setq rtn
(org-agenda-get-scheduled))
2938 (setq results
(append results rtn
)))
2940 (setq rtn
(org-agenda-get-closed))
2941 (setq results
(append results rtn
)))
2943 (setq rtn
(org-agenda-get-deadlines))
2944 (setq results
(append results rtn
))))))))
2947 (defun org-agenda-get-todos ()
2948 "Return the TODO information for agenda display."
2949 (let* ((props (list 'face nil
2950 'done-face
'org-done
2951 'org-not-done-regexp org-not-done-regexp
2952 'org-todo-regexp org-todo-regexp
2953 'mouse-face
'highlight
2954 'keymap org-agenda-keymap
2956 (format "mouse-2 or RET jump to org file %s"
2957 (abbreviate-file-name buffer-file-name
))))
2958 ;; FIXME: get rid of the \n at some point but watch out
2959 (regexp (concat "^\\*+[ \t]+\\("
2960 (if org-select-this-todo-keyword
2961 (if (equal org-select-this-todo-keyword
"*")
2964 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
2966 org-not-done-regexp
)
2968 marker priority category tags
2970 (goto-char (point-min))
2971 (while (re-search-forward regexp nil t
)
2975 (setq beg
(point) end
(progn (outline-next-heading) (point)))
2976 (when (or (and org-agenda-todo-ignore-with-date
(goto-char beg
)
2977 (re-search-forward org-ts-regexp end t
))
2978 (and org-agenda-todo-ignore-scheduled
(goto-char beg
)
2979 (re-search-forward org-scheduled-time-regexp end t
))
2980 (and org-agenda-todo-ignore-deadlines
(goto-char beg
)
2981 (re-search-forward org-deadline-time-regexp end t
)
2982 (org-deadline-close (match-string 1))))
2983 (goto-char (1+ beg
))
2984 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
2988 (goto-char (match-beginning 1))
2989 (setq marker
(org-agenda-new-marker (match-beginning 0))
2990 category
(org-get-category)
2991 tags
(org-get-tags-at (point))
2992 txt
(org-format-agenda-item "" (match-string 1) category tags
)
2993 priority
(1+ (org-get-priority txt
)))
2994 (org-add-props txt props
2995 'org-marker marker
'org-hd-marker marker
2996 'priority priority
'org-category category
2999 (if org-agenda-todo-list-sublevels
3000 (goto-char (match-end 1))
3001 (org-end-of-subtree 'invisible
))))
3004 (defconst org-agenda-no-heading-message
3005 "No heading for this item in buffer or region.")
3007 (defun org-agenda-get-timestamps ()
3008 "Return the date stamp information for agenda display."
3009 (let* ((props (list 'face nil
3010 'org-not-done-regexp org-not-done-regexp
3011 'org-todo-regexp org-todo-regexp
3012 'mouse-face
'highlight
3013 'keymap org-agenda-keymap
3015 (format "mouse-2 or RET jump to org file %s"
3016 (abbreviate-file-name buffer-file-name
))))
3017 (d1 (calendar-absolute-from-gregorian date
))
3023 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3030 (car org-time-stamp-formats
)
3031 (apply 'encode-time
; DATE bound by calendar
3032 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3034 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3035 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3036 marker hdmarker deadlinep scheduledp donep tmp priority category
3037 ee txt timestr tags b0 b3 e3 head
)
3038 (goto-char (point-min))
3039 (while (re-search-forward regexp nil t
)
3040 (setq b0
(match-beginning 0)
3041 b3
(match-beginning 3) e3
(match-end 3))
3043 (and (org-at-date-range-p) (throw :skip nil
))
3045 (if (and (match-end 1)
3046 (not (= d1
(org-time-string-to-absolute
3047 (match-string 1) d1 nil
3048 org-agenda-repeating-timestamp-show-all
))))
3051 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3053 (setq marker
(org-agenda-new-marker b0
)
3054 category
(org-get-category b0
)
3055 tmp
(buffer-substring (max (point-min)
3056 (- b0 org-ds-keyword-length
))
3058 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3059 deadlinep
(string-match org-deadline-regexp tmp
)
3060 scheduledp
(string-match org-scheduled-regexp tmp
)
3061 donep
(org-entry-is-done-p))
3062 (if (or scheduledp deadlinep
) (throw :skip t
))
3063 (if (string-match ">" timestr
)
3064 ;; substring should only run to end of time stamp
3065 (setq timestr
(substring timestr
0 (match-end 0))))
3067 (if (re-search-backward "^\\*+ " nil t
)
3069 (goto-char (match-beginning 0))
3070 (setq hdmarker
(org-agenda-new-marker)
3071 tags
(org-get-tags-at))
3072 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3073 (setq head
(match-string 1))
3074 (and org-agenda-skip-timestamp-if-done donep
(throw :skip t
))
3075 (setq txt
(org-format-agenda-item
3076 nil head category tags timestr nil
3078 (setq txt org-agenda-no-heading-message
))
3079 (setq priority
(org-get-priority txt
))
3080 (org-add-props txt props
3081 'org-marker marker
'org-hd-marker hdmarker
)
3082 (org-add-props txt nil
'priority priority
3083 'org-category category
'date date
3086 (outline-next-heading)))
3089 (defun org-agenda-get-sexps ()
3090 "Return the sexp information for agenda display."
3091 (require 'diary-lib
)
3092 (let* ((props (list 'face nil
3093 'mouse-face
'highlight
3094 'keymap org-agenda-keymap
3096 (format "mouse-2 or RET jump to org file %s"
3097 (abbreviate-file-name buffer-file-name
))))
3099 marker category ee txt tags entry result beg b sexp sexp-entry
)
3100 (goto-char (point-min))
3101 (while (re-search-forward regexp nil t
)
3104 (setq beg
(match-beginning 0))
3105 (goto-char (1- (match-end 0)))
3108 (setq sexp
(buffer-substring b
(point)))
3109 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3110 (org-trim (match-string 1))
3112 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3114 (setq marker
(org-agenda-new-marker beg
)
3115 category
(org-get-category beg
))
3117 (if (string-match "\\S-" result
)
3119 (setq txt
"SEXP entry returned empty string"))
3121 (setq txt
(org-format-agenda-item
3122 "" txt category tags
'time
))
3123 (org-add-props txt props
'org-marker marker
)
3124 (org-add-props txt nil
3125 'org-category category
'date date
3130 (defun org-agenda-get-closed ()
3131 "Return the logged TODO entries for agenda display."
3132 (let* ((props (list 'mouse-face
'highlight
3133 'org-not-done-regexp org-not-done-regexp
3134 'org-todo-regexp org-todo-regexp
3135 'keymap org-agenda-keymap
3137 (format "mouse-2 or RET jump to org file %s"
3138 (abbreviate-file-name buffer-file-name
))))
3140 "\\<\\(" org-closed-string
"\\|" org-clock-string
"\\) *\\["
3144 (car org-time-stamp-formats
)
3145 (apply 'encode-time
; DATE bound by calendar
3146 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3148 marker hdmarker priority category tags closedp
3150 (goto-char (point-min))
3151 (while (re-search-forward regexp nil t
)
3154 (setq marker
(org-agenda-new-marker (match-beginning 0))
3155 closedp
(equal (match-string 1) org-closed-string
)
3156 category
(org-get-category (match-beginning 0))
3157 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3158 ;; donep (org-entry-is-done-p)
3160 (if (string-match "\\]" timestr
)
3161 ;; substring should only run to end of time stamp
3162 (setq timestr
(substring timestr
0 (match-end 0))))
3164 (if (re-search-backward "^\\*+ " nil t
)
3166 (goto-char (match-beginning 0))
3167 (setq hdmarker
(org-agenda-new-marker)
3168 tags
(org-get-tags-at))
3169 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3170 (setq txt
(org-format-agenda-item
3171 (if closedp
"Closed: " "Clocked: ")
3172 (match-string 1) category tags timestr
)))
3173 (setq txt org-agenda-no-heading-message
))
3174 (setq priority
100000)
3175 (org-add-props txt props
3176 'org-marker marker
'org-hd-marker hdmarker
'face
'org-done
3177 'priority priority
'org-category category
3178 'type
"closed" 'date date
3179 'undone-face
'org-warning
'done-face
'org-done
)
3181 (goto-char (point-at-eol))))
3184 (defun org-agenda-get-deadlines ()
3185 "Return the deadline information for agenda display."
3186 (let* ((props (list 'mouse-face
'highlight
3187 'org-not-done-regexp org-not-done-regexp
3188 'org-todo-regexp org-todo-regexp
3189 'keymap org-agenda-keymap
3191 (format "mouse-2 or RET jump to org file %s"
3192 (abbreviate-file-name buffer-file-name
))))
3193 (regexp org-deadline-time-regexp
)
3194 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
3195 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3196 d2 diff dfrac wdays pos pos1 category tags
3197 ee txt head face s upcomingp donep timestr
)
3198 (goto-char (point-min))
3199 (while (re-search-forward regexp nil t
)
3202 (setq s
(match-string 1)
3203 pos
(1- (match-beginning 1))
3204 d2
(org-time-string-to-absolute
3205 (match-string 1) d1
'past
3206 org-agenda-repeating-timestamp-show-all
)
3208 wdays
(org-get-wdays s
)
3209 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3210 upcomingp
(and todayp
(> diff
0)))
3211 ;; When to show a deadline in the calendar:
3212 ;; If the expiration is within wdays warning time.
3213 ;; Past-due deadlines are only shown on the current date
3214 (if (or (and (<= diff wdays
)
3215 (and todayp
(not org-agenda-only-exact-dates
)))
3218 (setq category
(org-get-category))
3219 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3221 (goto-char (match-end 0))
3222 (setq pos1
(match-beginning 0))
3223 (setq tags
(org-get-tags-at pos1
))
3224 (setq head
(buffer-substring-no-properties
3226 (progn (skip-chars-forward "^\r\n")
3228 (setq donep
(string-match org-looking-at-done-regexp head
))
3229 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3231 (concat (substring s
(match-beginning 1)) " "))
3232 (setq timestr
'time
))
3234 (or org-agenda-skip-deadline-if-done
3237 (setq txt
(org-format-agenda-item
3239 (car org-agenda-deadline-leaders
)
3240 (format (nth 1 org-agenda-deadline-leaders
)
3242 head category tags timestr
))))
3243 (setq txt org-agenda-no-heading-message
))
3245 (setq face
(org-agenda-deadline-face dfrac wdays
))
3246 (org-add-props txt props
3247 'org-marker
(org-agenda-new-marker pos
)
3248 'org-hd-marker
(org-agenda-new-marker pos1
)
3249 'priority
(+ (- diff
)
3250 (org-get-priority txt
))
3251 'org-category category
3252 'type
(if upcomingp
"upcoming-deadline" "deadline")
3253 'date
(if upcomingp date d2
)
3254 'face
(if donep
'org-done face
)
3255 'undone-face face
'done-face
'org-done
)
3259 (defun org-agenda-deadline-face (fraction &optional wdays
)
3260 "Return the face to displaying a deadline item.
3261 FRACTION is what fraction of the head-warning time has passed."
3262 (if (equal wdays
0) (setq fraction
1.
))
3263 (let ((faces org-agenda-deadline-faces
) f
)
3265 (while (setq f
(pop faces
))
3266 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3268 (defun org-agenda-get-scheduled ()
3269 "Return the scheduled information for agenda display."
3270 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3271 'org-todo-regexp org-todo-regexp
3272 'done-face
'org-done
3273 'mouse-face
'highlight
3274 'keymap org-agenda-keymap
3276 (format "mouse-2 or RET jump to org file %s"
3277 (abbreviate-file-name buffer-file-name
))))
3278 (regexp org-scheduled-time-regexp
)
3279 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
3280 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3281 d2 diff pos pos1 category tags
3282 ee txt head pastschedp donep face timestr s
)
3283 (goto-char (point-min))
3284 (while (re-search-forward regexp nil t
)
3287 (setq s
(match-string 1)
3288 pos
(1- (match-beginning 1))
3289 d2
(org-time-string-to-absolute
3290 (match-string 1) d1
'past
3291 org-agenda-repeating-timestamp-show-all
)
3293 (setq pastschedp
(and todayp
(< diff
0)))
3294 ;; When to show a scheduled item in the calendar:
3295 ;; If it is on or past the date.
3296 (if (or (and (< diff
0)
3297 (< (abs diff
) org-scheduled-past-days
)
3298 (and todayp
(not org-agenda-only-exact-dates
)))
3301 (setq category
(org-get-category))
3302 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3304 (goto-char (match-end 0))
3305 (setq pos1
(match-beginning 0))
3306 (setq tags
(org-get-tags-at))
3307 (setq head
(buffer-substring-no-properties
3309 (progn (skip-chars-forward "^\r\n") (point))))
3310 (setq donep
(string-match org-looking-at-done-regexp head
))
3311 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3313 (concat (substring s
(match-beginning 1)) " "))
3314 (setq timestr
'time
))
3316 (or org-agenda-skip-scheduled-if-done
3319 (setq txt
(org-format-agenda-item
3321 (car org-agenda-scheduled-leaders
)
3322 (format (nth 1 org-agenda-scheduled-leaders
)
3324 head category tags timestr
))))
3325 (setq txt org-agenda-no-heading-message
))
3327 (setq face
(if pastschedp
3328 'org-scheduled-previously
3329 'org-scheduled-today
))
3330 (org-add-props txt props
3332 'face
(if donep
'org-done face
)
3333 'org-marker
(org-agenda-new-marker pos
)
3334 'org-hd-marker
(org-agenda-new-marker pos1
)
3335 'type
(if pastschedp
"past-scheduled" "scheduled")
3336 'date
(if pastschedp d2 date
)
3337 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
3338 'org-category category
)
3342 (defun org-agenda-get-blocks ()
3343 "Return the date-range information for agenda display."
3344 (let* ((props (list 'face nil
3345 'org-not-done-regexp org-not-done-regexp
3346 'org-todo-regexp org-todo-regexp
3347 'mouse-face
'highlight
3348 'keymap org-agenda-keymap
3350 (format "mouse-2 or RET jump to org file %s"
3351 (abbreviate-file-name buffer-file-name
))))
3352 (regexp org-tr-regexp
)
3353 (d0 (calendar-absolute-from-gregorian date
))
3354 marker hdmarker ee txt d1 d2 s1 s2 timestr category tags pos
3356 (goto-char (point-min))
3357 (while (re-search-forward regexp nil t
)
3361 (setq timestr
(match-string 0)
3364 d1
(time-to-days (org-time-string-to-time s1
))
3365 d2
(time-to-days (org-time-string-to-time s2
)))
3366 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
3367 ;; Only allow days between the limits, because the normal
3368 ;; date stamps will catch the limits.
3370 (setq marker
(org-agenda-new-marker (point)))
3371 (setq category
(org-get-category))
3372 (if (re-search-backward "^\\*+ " nil t
)
3374 (goto-char (match-beginning 0))
3375 (setq hdmarker
(org-agenda-new-marker (point)))
3376 (setq tags
(org-get-tags-at))
3377 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3378 (setq head
(match-string 1))
3379 (and org-agenda-skip-timestamp-if-done
3380 (org-entry-is-done-p)
3382 (setq txt
(org-format-agenda-item
3383 (format (if (= d1 d2
) "" "(%d/%d): ")
3384 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
3386 (if (= d0 d1
) timestr
))))
3387 (setq txt org-agenda-no-heading-message
))
3388 (org-add-props txt props
3389 'org-marker marker
'org-hd-marker hdmarker
3390 'type
"block" 'date date
3391 'priority
(org-get-priority txt
) 'org-category category
)
3394 ;; Sort the entries by expiration date.
3397 ;;; Agenda presentation and sorting
3399 (defconst org-plain-time-of-day-regexp
3402 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3405 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3407 "Regular expression to match a plain time or time range.
3408 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3409 groups carry important information:
3411 1 the first time, range or not
3412 8 the second time, if it is a range.")
3414 (defconst org-plain-time-extension-regexp
3417 "\\(\\(:\\([0-5][0-9]\\([AaPp][Mm]\\)?\\)\\)\\|\\([AaPp][Mm]\\)\\)\\>\\)"
3418 "\\+\\([0-9]+\\)\\(:\\([0-5][0-9]\\)\\)?")
3419 "Regular expression to match a time range like 13:30+2:10 = 13:30-15:40.
3420 Examples: 11:45 or 8am-13:15 or 2:45-2:45pm. After a match, the following
3421 groups carry important information:
3424 9 minutes of duration")
3426 (defconst org-stamp-time-of-day-regexp
3428 "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} +\\sw+ +\\)"
3429 "\\([012][0-9]:[0-5][0-9]\\(-\\([012][0-9]:[0-5][0-9]\\)\\)?[^\n\r>]*?\\)>"
3431 "<\\1\\([012][0-9]:[0-5][0-9]\\)>\\)?")
3432 "Regular expression to match a timestamp time or time range.
3433 After a match, the following groups carry important information:
3435 1 date plus weekday, for backreferencing to make sure both times on same day
3436 2 the first time, range or not
3437 4 the second time, if it is a range.")
3439 (defvar org-prefix-has-time nil
3440 "A flag, set by `org-compile-prefix-format'.
3441 The flag is set if the currently compiled format contains a `%t'.")
3442 (defvar org-prefix-has-tag nil
3443 "A flag, set by `org-compile-prefix-format'.
3444 The flag is set if the currently compiled format contains a `%T'.")
3446 (defun org-format-agenda-item (extra txt
&optional category tags dotime
3448 "Format TXT to be inserted into the agenda buffer.
3449 In particular, it adds the prefix and corresponding text properties. EXTRA
3450 must be a string and replaces the `%s' specifier in the prefix format.
3451 CATEGORY (string, symbol or nil) may be used to overrule the default
3452 category taken from local variable or file name. It will replace the `%c'
3453 specifier in the format. DOTIME, when non-nil, indicates that a
3454 time-of-day should be extracted from TXT for sorting of this entry, and for
3455 the `%t' specifier in the format. When DOTIME is a string, this string is
3456 searched for a time before TXT is. NOPREFIX is a flag and indicates that
3457 only the correctly processes TXT should be returned - this is used by
3458 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
3459 Any match of REMOVE-RE will be removed from TXT."
3461 ;; Diary entries sometimes have extra whitespace at the beginning
3462 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
3463 (let* ((category (or category
3465 (if buffer-file-name
3466 (file-name-sans-extension
3467 (file-name-nondirectory buffer-file-name
))
3469 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
3470 time
; time and tag are needed for the eval of the prefix format
3471 (ts (if dotime
(concat (if (stringp dotime
) dotime
"") txt
)))
3472 (time-of-day (and dotime
(org-get-time-of-day ts
)))
3473 stamp plain s0 s1 s2 rtn srp
)
3474 (when (and dotime time-of-day org-prefix-has-time
)
3475 ;; Extract starting and ending time and move them to prefix
3476 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
3477 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
3478 (setq s0
(match-string 0 ts
)
3479 srp
(and stamp
(match-end 3))
3480 s1
(match-string (if plain
1 2) ts
)
3481 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
3483 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
3484 ;; them, we might want to remove them there to avoid duplication.
3485 ;; The user can turn this off with a variable.
3486 (if (and org-agenda-remove-times-when-in-prefix
(or stamp plain
)
3487 (string-match (concat (regexp-quote s0
) " *") txt
)
3488 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
3489 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
3490 (= (match-beginning 0) 0)
3492 (setq txt
(replace-match "" nil nil txt
))))
3493 ;; Normalize the time(s) to 24 hour
3494 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
3495 (if s2
(setq s2
(org-get-time-of-day s2
'string t
))))
3497 (when (and s1
(not s2
) org-agenda-default-appointment-duration
3498 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
3499 (let ((m (+ (string-to-number (match-string 2 s1
))
3500 (* 60 (string-to-number (match-string 1 s1
)))
3501 org-agenda-default-appointment-duration
))
3503 (setq h
(/ m
60) m
(- m
(* h
60)))
3504 (setq s2
(format "%02d:%02d" h m
))))
3506 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
3508 ;; Tags are in the string
3509 (if (or (eq org-agenda-remove-tags t
)
3510 (and org-agenda-remove-tags
3511 org-prefix-has-tag
))
3512 (setq txt
(replace-match "" t t txt
))
3513 (setq txt
(replace-match
3514 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
3515 (match-string 2 txt
))
3519 (while (string-match remove-re txt
)
3520 (setq txt
(replace-match "" t t txt
))))
3522 ;; Create the final string
3525 ;; Prepare the variables needed in the eval of the compiled format
3526 (setq time
(cond (s2 (concat s1
"-" s2
))
3527 (s1 (concat s1
"......"))
3530 category
(if (symbolp category
) (symbol-name category
) category
))
3531 ;; Evaluate the compiled format
3532 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
3534 ;; And finally add the text properties
3535 (org-add-props rtn nil
3536 'org-category
(downcase category
) 'tags tags
3537 'org-highest-priority org-highest-priority
3538 'org-lowest-priority org-lowest-priority
3539 'prefix-length
(- (length rtn
) (length txt
))
3540 'time-of-day time-of-day
3546 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
3547 (defvar org-agenda-sorting-strategy-selected nil
)
3549 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
3551 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
3552 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
3553 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
3554 ((member 'weekly
(car org-agenda-time-grid
)))
3555 (t (throw 'exit list
)))
3556 (let* ((have (delq nil
(mapcar
3557 (lambda (x) (get-text-property 1 'time-of-day x
))
3559 (string (nth 1 org-agenda-time-grid
))
3560 (gridtimes (nth 2 org-agenda-time-grid
))
3561 (req (car org-agenda-time-grid
))
3562 (remove (member 'remove-match req
))
3564 (if (and (member 'require-timed req
) (not have
))
3565 ;; don't show empty grid
3567 (while (setq time
(pop gridtimes
))
3568 (unless (and remove
(member time have
))
3569 (setq time
(int-to-string time
))
3570 (push (org-format-agenda-item
3572 (concat (substring time
0 -
2) ":" (substring time -
2)))
3575 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
3576 (if (member 'time-up org-agenda-sorting-strategy-selected
)
3578 (append list new
)))))
3580 (defun org-compile-prefix-format (key)
3581 "Compile the prefix format into a Lisp form that can be evaluated.
3582 The resulting form is returned and stored in the variable
3583 `org-prefix-format-compiled'."
3584 (setq org-prefix-has-time nil org-prefix-has-tag nil
)
3586 ((stringp org-agenda-prefix-format
)
3587 org-agenda-prefix-format
)
3588 ((assq key org-agenda-prefix-format
)
3589 (cdr (assq key org-agenda-prefix-format
)))
3590 (t " %-12:c%?-12t% s")))
3592 varform vars var e c f opt
)
3593 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cts]\\)"
3595 (setq var
(cdr (assoc (match-string 4 s
)
3596 '(("c" . category
) ("t" . time
) ("s" . extra
)
3598 c
(or (match-string 3 s
) "")
3599 opt
(match-beginning 1)
3600 start
(1+ (match-beginning 0)))
3601 (if (equal var
'time
) (setq org-prefix-has-time t
))
3602 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
3603 (setq f
(concat "%" (match-string 2 s
) "s"))
3606 `(if (equal "" ,var
)
3608 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
3609 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
3610 (setq s
(replace-match "%s" t nil s
))
3611 (push varform vars
))
3612 (setq vars
(nreverse vars
))
3613 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
3615 (defun org-set-sorting-strategy (key)
3616 (if (symbolp (car org-agenda-sorting-strategy
))
3618 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
3619 (setq org-agenda-sorting-strategy-selected
3620 (or (cdr (assq key org-agenda-sorting-strategy
))
3621 (cdr (assq 'agenda org-agenda-sorting-strategy
))
3622 '(time-up category-keep priority-down
)))))
3624 (defun org-get-time-of-day (s &optional string mod24
)
3625 "Check string S for a time of day.
3626 If found, return it as a military time number between 0 and 2400.
3627 If not found, return nil.
3628 The optional STRING argument forces conversion into a 5 character wide string
3632 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
3633 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
3634 (let* ((h (string-to-number (match-string 1 s
)))
3635 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
3636 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
3637 (am-p (equal ampm
"am"))
3638 (h1 (cond ((not ampm
) h
)
3639 ((= h
12) (if am-p
0 12))
3640 (t (+ h
(if am-p
0 12)))))
3641 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
3643 (t0 (+ (* 100 h2
) m
))
3644 (t1 (concat (if (>= h1
24) "+" " ")
3645 (if (< t0
100) "0" "")
3646 (if (< t0
10) "0" "")
3647 (int-to-string t0
))))
3648 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
3650 (defun org-finalize-agenda-entries (list &optional nosort
)
3651 "Sort and concatenate the agenda items."
3652 (setq list
(mapcar 'org-agenda-highlight-todo list
))
3655 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
3657 (defun org-agenda-highlight-todo (x)
3661 (beginning-of-line 1)
3662 (setq re
(get-text-property (point) 'org-todo-regexp
))
3663 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
3664 (when (looking-at (concat "[ \t]*\\.*" re
" +"))
3665 (add-text-properties (match-beginning 0) (match-end 0)
3666 (list 'face
(org-get-todo-face 0)))
3667 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
3668 (delete-region (match-beginning 1) (1- (match-end 0)))
3669 (goto-char (match-beginning 1))
3670 (insert (format org-agenda-todo-keyword-format s
)))))
3671 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
3672 pl
(get-text-property 0 'prefix-length x
))
3674 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
3676 (add-text-properties
3677 (or (match-end 1) (match-end 0)) (match-end 0)
3678 (list 'face
(org-get-todo-face (match-string 2 x
)))
3680 (setq x
(concat (substring x
0 (match-end 1))
3681 (format org-agenda-todo-keyword-format
3684 (substring x
(match-end 3)))))
3687 (defsubst org-cmp-priority
(a b
)
3688 "Compare the priorities of string A and B."
3689 (let ((pa (or (get-text-property 1 'priority a
) 0))
3690 (pb (or (get-text-property 1 'priority b
) 0)))
3691 (cond ((> pa pb
) +1)
3695 (defsubst org-cmp-category
(a b
)
3696 "Compare the string values of categories of strings A and B."
3697 (let ((ca (or (get-text-property 1 'org-category a
) ""))
3698 (cb (or (get-text-property 1 'org-category b
) "")))
3699 (cond ((string-lessp ca cb
) -
1)
3700 ((string-lessp cb ca
) +1)
3703 (defsubst org-cmp-tag
(a b
)
3704 "Compare the string values of categories of strings A and B."
3705 (let ((ta (car (last (get-text-property 1 'tags a
))))
3706 (tb (car (last (get-text-property 1 'tags b
)))))
3709 ((string-lessp ta tb
) -
1)
3710 ((string-lessp tb ta
) +1)
3713 (defsubst org-cmp-time
(a b
)
3714 "Compare the time-of-day values of strings A and B."
3715 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
3716 (ta (or (get-text-property 1 'time-of-day a
) def
))
3717 (tb (or (get-text-property 1 'time-of-day b
) def
)))
3718 (cond ((< ta tb
) -
1)
3722 (defun org-entries-lessp (a b
)
3723 "Predicate for sorting agenda entries."
3724 ;; The following variables will be used when the form is evaluated.
3725 ;; So even though the compiler complains, keep them.
3726 (let* ((time-up (org-cmp-time a b
))
3727 (time-down (if time-up
(- time-up
) nil
))
3728 (priority-up (org-cmp-priority a b
))
3729 (priority-down (if priority-up
(- priority-up
) nil
))
3730 (category-up (org-cmp-category a b
))
3731 (category-down (if category-up
(- category-up
) nil
))
3732 (category-keep (if category-up
+1 nil
))
3733 (tag-up (org-cmp-tag a b
))
3734 (tag-down (if tag-up
(- tag-up
) nil
)))
3736 (eval (cons 'or org-agenda-sorting-strategy-selected
))
3737 '((-1 . t
) (1 . nil
) (nil . nil
))))))
3739 ;;; Agenda restriction lock
3741 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
3742 "Overlay to mark the headline to which arenda commands are restricted.")
3743 (org-overlay-put org-agenda-restriction-lock-overlay
3744 'face
'org-agenda-restriction-lock
)
3745 (org-overlay-put org-agenda-restriction-lock-overlay
3746 'help-echo
"Agendas are currently limited to this subtree.")
3747 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3749 (defun org-agenda-set-restriction-lock (&optional type
)
3750 "Set restriction lock for agenda, to current subtree or file.
3751 Restriction will be the file if TYPE is `file', or if type is the
3752 universal prefix '(4), or if the cursor is before the first headline
3753 in the file. Otherwise, restriction will be to the current subtree."
3755 (and (equal type
'(4)) (setq type
'file
))
3758 ((org-at-heading-p) 'subtree
)
3759 ((condition-case nil
(org-back-to-heading t
) (error nil
))
3762 (if (eq type
'subtree
)
3764 (setq org-agenda-restrict t
)
3765 (setq org-agenda-overriding-restriction
'subtree
)
3766 (put 'org-agenda-files
'org-restrict
3767 (list (buffer-file-name (buffer-base-buffer))))
3768 (org-back-to-heading t
)
3769 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
3770 (move-marker org-agenda-restrict-begin
(point))
3771 (move-marker org-agenda-restrict-end
3772 (save-excursion (org-end-of-subtree t
)))
3773 (message "Locking agenda restriction to subtree"))
3774 (put 'org-agenda-files
'org-restrict
3775 (list (buffer-file-name (buffer-base-buffer))))
3776 (setq org-agenda-restrict nil
)
3777 (setq org-agenda-overriding-restriction
'file
)
3778 (move-marker org-agenda-restrict-begin nil
)
3779 (move-marker org-agenda-restrict-end nil
)
3780 (message "Locking agenda restriction to file"))
3781 (setq current-prefix-arg nil
)
3782 (org-agenda-maybe-redo))
3784 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
3785 "Remove the agenda restriction lock."
3787 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3788 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
3789 (setq org-agenda-overriding-restriction nil
)
3790 (setq org-agenda-restrict nil
)
3791 (put 'org-agenda-files
'org-restrict nil
)
3792 (move-marker org-agenda-restrict-begin nil
)
3793 (move-marker org-agenda-restrict-end nil
)
3794 (setq current-prefix-arg nil
)
3795 (message "Agenda restriction lock removed")
3796 (or noupdate
(org-agenda-maybe-redo)))
3798 (defun org-agenda-maybe-redo ()
3799 "If there is any window showing the agenda view, update it."
3800 (let ((w (get-buffer-window org-agenda-buffer-name t
))
3801 (w0 (selected-window)))
3806 (if org-agenda-overriding-restriction
3807 (message "Agenda view shifted to new %s restriction"
3808 org-agenda-overriding-restriction
)
3809 (message "Agenda restriction lock removed")))))
3813 (defun org-agenda-check-type (error &rest types
)
3814 "Check if agenda buffer is of allowed type.
3815 If ERROR is non-nil, throw an error, otherwise just return nil."
3816 (if (memq org-agenda-type types
)
3819 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
3822 (defun org-agenda-quit ()
3823 "Exit agenda by removing the window or the buffer."
3825 (let ((buf (current-buffer)))
3826 (if (not (one-window-p)) (delete-window))
3828 (org-agenda-reset-markers)
3829 (org-columns-remove-overlays))
3830 ;; Maybe restore the pre-agenda window configuration.
3831 (and org-agenda-restore-windows-after-quit
3832 (not (eq org-agenda-window-setup
'other-frame
))
3833 org-pre-agenda-window-conf
3834 (set-window-configuration org-pre-agenda-window-conf
)))
3836 (defun org-agenda-exit ()
3837 "Exit agenda by removing the window or the buffer.
3838 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
3839 Org-mode buffers visited directly by the user will not be touched."
3841 (org-release-buffers org-agenda-new-buffers
)
3842 (setq org-agenda-new-buffers nil
)
3845 (defun org-agenda-execute (arg)
3846 "Execute another agenda command, keeping same window.\\<global-map>
3847 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
3849 (let ((org-agenda-window-setup 'current-window
))
3852 (defun org-save-all-org-buffers ()
3853 "Save all Org-mode buffers without user confirmation."
3855 (message "Saving all Org-mode buffers...")
3856 (save-some-buffers t
'org-mode-p
)
3857 (message "Saving all Org-mode buffers... done"))
3859 (defun org-agenda-redo ()
3861 When this is the global TODO list, a prefix argument will be interpreted."
3863 (let* ((org-agenda-keep-modes t
)
3864 (line (org-current-line))
3865 (window-line (- line
(org-current-line (window-start))))
3866 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
3867 (message "Rebuilding agenda buffer...")
3868 (org-let lprops
'(eval org-agenda-redo-command
))
3869 (setq org-agenda-undo-list nil
3870 org-agenda-pending-undo-list nil
)
3871 (message "Rebuilding agenda buffer...done")
3873 (recenter window-line
)))
3875 (defun org-agenda-manipulate-query-add ()
3876 "Manipulate the query by adding a search term with positive selection.
3877 Positive selection means, the term must be matched for selection of an entry."
3879 (org-agenda-manipulate-query ?\
[))
3880 (defun org-agenda-manipulate-query-subtract ()
3881 "Manipulate the query by adding a search term with negative selection.
3882 Negative selection means, term must not be matched for selection of an entry."
3884 (org-agenda-manipulate-query ?\
]))
3885 (defun org-agenda-manipulate-query-add-re ()
3886 "Manipulate the query by adding a search regexp with positive selection.
3887 Positive selection means, the regexp must match for selection of an entry."
3889 (org-agenda-manipulate-query ?\
{))
3890 (defun org-agenda-manipulate-query-subtract-re ()
3891 "Manipulate the query by adding a search regexp with negative selection.
3892 Negative selection means, regexp must not match for selection of an entry."
3894 (org-agenda-manipulate-query ?\
}))
3895 (defun org-agenda-manipulate-query (char)
3897 ((eq org-agenda-type
'search
)
3899 'org-agenda-query-string
3900 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
3901 (?\
{ .
" +{}") (?\
} .
" -{}")))))
3902 (setq org-agenda-redo-command
3903 (list 'org-search-view
3905 org-agenda-query-string
3906 (+ (length org-agenda-query-string
)
3907 (if (member char
'(?\
{ ?\
})) 0 1))))
3908 (set-register org-agenda-query-register org-agenda-query-string
)
3910 (t (error "Canot manipulate query for %s-type agenda buffers"
3913 (defun org-add-to-string (var string
)
3914 (set var
(concat (symbol-value var
) string
)))
3916 (defun org-agenda-goto-date (date)
3917 "Jump to DATE in agenda."
3918 (interactive (list (org-read-date)))
3919 (org-agenda-list nil date
))
3921 (defun org-agenda-goto-today ()
3924 (org-agenda-check-type t
'timeline
'agenda
)
3925 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
3927 (tdpos (goto-char tdpos
))
3928 ((eq org-agenda-type
'agenda
)
3929 (let* ((sd (time-to-days
3930 (time-subtract (current-time)
3931 (list 0 (* 3600 org-extend-today-until
) 0))))
3932 (comp (org-agenda-compute-time-span sd org-agenda-span
))
3933 (org-agenda-overriding-arguments org-agenda-last-arguments
))
3934 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
3935 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
3937 (org-agenda-find-same-or-today-or-agenda)))
3938 (t (error "Cannot find today")))))
3940 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
3942 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
3943 (text-property-any (point-min) (point-max) 'org-today t
)
3944 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
3947 (defun org-agenda-later (arg)
3948 "Go forward in time by thee current span.
3949 With prefix ARG, go forward that many times the current span."
3951 (org-agenda-check-type t
'agenda
)
3952 (let* ((span org-agenda-span
)
3953 (sd org-starting-day
)
3954 (greg (calendar-gregorian-from-absolute sd
))
3955 (cnt (get-text-property (point) 'org-day-cnt
))
3959 (setq sd
(+ arg sd
) nd
1))
3961 (setq sd
(+ (* 7 arg
) sd
) nd
7))
3963 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
3964 sd
(calendar-absolute-from-gregorian greg2
))
3965 (setcar greg2
(1+ (car greg2
)))
3966 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
3968 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
3969 sd
(calendar-absolute-from-gregorian greg2
))
3970 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
3971 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
3972 (let ((org-agenda-overriding-arguments
3973 (list (car org-agenda-last-arguments
) sd nd t
)))
3975 (org-agenda-find-same-or-today-or-agenda cnt
))))
3977 (defun org-agenda-earlier (arg)
3978 "Go backward in time by the current span.
3979 With prefix ARG, go backward that many times the current span."
3981 (org-agenda-later (- arg
)))
3983 (defun org-agenda-day-view (&optional day-of-year
)
3984 "Switch to daily view for agenda.
3985 With argument DAY-OF-YEAR, switch to that day of the year."
3987 (setq org-agenda-ndays
1)
3988 (org-agenda-change-time-span 'day day-of-year
))
3989 (defun org-agenda-week-view (&optional iso-week
)
3990 "Switch to daily view for agenda.
3991 With argument ISO-WEEK, switch to the corresponding ISO week.
3992 If ISO-WEEK has more then 2 digits, only the last two encode the
3993 week. Any digits before this encode a year. So 200712 means
3994 week 12 of year 2007. Years in the range 1938-2037 can also be
3995 written as 2-digit years."
3997 (setq org-agenda-ndays
7)
3998 (org-agenda-change-time-span 'week iso-week
))
3999 (defun org-agenda-month-view (&optional month
)
4000 "Switch to daily view for agenda.
4001 With argument MONTH, switch to that month."
4003 ;; FIXME: allow month like 812 to mean 2008 december
4004 (org-agenda-change-time-span 'month month
))
4005 (defun org-agenda-year-view (&optional year
)
4006 "Switch to daily view for agenda.
4007 With argument YEAR, switch to that year.
4008 If MONTH has more then 2 digits, only the last two encode the
4009 month. Any digits before this encode a year. So 200712 means
4010 December year 2007. Years in the range 1938-2037 can also be
4011 written as 2-digit years."
4014 (setq year
(org-small-year-to-year year
)))
4015 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4016 (org-agenda-change-time-span 'year year
)
4019 (defun org-agenda-change-time-span (span &optional n
)
4020 "Change the agenda view to SPAN.
4021 SPAN may be `day', `week', `month', `year'."
4022 (org-agenda-check-type t
'agenda
)
4023 (if (and (not n
) (equal org-agenda-span span
))
4024 (error "Viewing span is already \"%s\"" span
))
4025 (let* ((sd (or (get-text-property (point) 'day
)
4027 (computed (org-agenda-compute-time-span sd span n
))
4028 (org-agenda-overriding-arguments
4029 (list (car org-agenda-last-arguments
)
4030 (car computed
) (cdr computed
) t
)))
4032 (org-agenda-find-same-or-today-or-agenda))
4033 (org-agenda-set-mode-name)
4034 (message "Switched to %s view" span
))
4036 (defun org-agenda-compute-time-span (sd span
&optional n
)
4037 "Compute starting date and number of days for agenda.
4038 SPAN may be `day', `week', `month', `year'. The return value
4039 is a cons cell with the starting date and the number of days,
4040 so that the date SD will be in that range."
4041 (let* ((greg (calendar-gregorian-from-absolute sd
))
4045 nd w1 y1 m1 thisweek
)
4049 (setq sd
(+ (calendar-absolute-from-gregorian
4054 (let* ((nt (calendar-day-of-week
4055 (calendar-gregorian-from-absolute sd
)))
4056 (d (if org-agenda-start-on-weekday
4057 (- nt org-agenda-start-on-weekday
)
4059 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
4062 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
4064 (setq y1
(org-small-year-to-year (/ n
100))
4067 (calendar-absolute-from-iso
4069 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
4072 (when (and n
(> n
99))
4073 (setq y1
(org-small-year-to-year (/ n
100))
4075 (setq sd
(calendar-absolute-from-gregorian
4076 (list (or n mg
) 1 (or y1 yg
)))
4077 nd
(- (calendar-absolute-from-gregorian
4078 (list (1+ (or n mg
)) 1 (or y1 yg
)))
4081 (setq sd
(calendar-absolute-from-gregorian
4082 (list 1 1 (or n yg
)))
4083 nd
(- (calendar-absolute-from-gregorian
4084 (list 1 1 (1+ (or n yg
))))
4088 ;; FIXME: does not work if user makes date format that starts with a blank
4089 (defun org-agenda-next-date-line (&optional arg
)
4090 "Jump to the next line indicating a date in agenda buffer."
4092 (org-agenda-check-type t
'agenda
'timeline
)
4093 (beginning-of-line 1)
4094 (if (looking-at "^\\S-") (forward-char 1))
4095 (if (not (re-search-forward "^\\S-" nil t arg
))
4098 (error "No next date after this line in this buffer")))
4099 (goto-char (match-beginning 0)))
4101 (defun org-agenda-previous-date-line (&optional arg
)
4102 "Jump to the previous line indicating a date in agenda buffer."
4104 (org-agenda-check-type t
'agenda
'timeline
)
4105 (beginning-of-line 1)
4106 (if (not (re-search-backward "^\\S-" nil t arg
))
4107 (error "No previous date before this line in this buffer")))
4109 ;; Initialize the highlight
4110 (defvar org-hl
(org-make-overlay 1 1))
4111 (org-overlay-put org-hl
'face
'highlight
)
4113 (defun org-highlight (begin end
&optional buffer
)
4114 "Highlight a region with overlay."
4115 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
4116 org-hl begin end
(or buffer
(current-buffer))))
4118 (defun org-unhighlight ()
4119 "Detach overlay INDEX."
4120 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
4122 ;; FIXME this is currently not used.
4123 (defun org-highlight-until-next-command (beg end
&optional buffer
)
4124 (org-highlight beg end buffer
)
4125 (add-hook 'pre-command-hook
'org-unhighlight-once
))
4126 (defun org-unhighlight-once ()
4127 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
4130 (defun org-agenda-follow-mode ()
4131 "Toggle follow mode in an agenda buffer."
4133 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
4134 (org-agenda-set-mode-name)
4135 (message "Follow mode is %s"
4136 (if org-agenda-follow-mode
"on" "off")))
4138 (defun org-agenda-log-mode ()
4139 "Toggle log mode in an agenda buffer."
4141 (org-agenda-check-type t
'agenda
'timeline
)
4142 (setq org-agenda-show-log
(not org-agenda-show-log
))
4143 (org-agenda-set-mode-name)
4145 (message "Log mode is %s"
4146 (if org-agenda-show-log
"on" "off")))
4148 (defun org-agenda-toggle-diary ()
4149 "Toggle diary inclusion in an agenda buffer."
4151 (org-agenda-check-type t
'agenda
)
4152 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
4154 (org-agenda-set-mode-name)
4155 (message "Diary inclusion turned %s"
4156 (if org-agenda-include-diary
"on" "off")))
4158 (defun org-agenda-toggle-time-grid ()
4159 "Toggle time grid in an agenda buffer."
4161 (org-agenda-check-type t
'agenda
)
4162 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
4164 (org-agenda-set-mode-name)
4165 (message "Time-grid turned %s"
4166 (if org-agenda-use-time-grid
"on" "off")))
4168 (defun org-agenda-set-mode-name ()
4169 "Set the mode name to indicate all the small mode settings."
4171 (concat "Org-Agenda"
4172 (if (equal org-agenda-ndays
1) " Day" "")
4173 (if (equal org-agenda-ndays
7) " Week" "")
4174 (if org-agenda-follow-mode
" Follow" "")
4175 (if org-agenda-include-diary
" Diary" "")
4176 (if org-agenda-use-time-grid
" Grid" "")
4177 (if org-agenda-show-log
" Log" "")))
4178 (force-mode-line-update))
4180 (defun org-agenda-post-command-hook ()
4181 (and (eolp) (not (bolp)) (backward-char 1))
4182 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
4183 (if (and org-agenda-follow-mode
4184 (get-text-property (point) 'org-marker
))
4187 (defun org-agenda-show-priority ()
4188 "Show the priority of the current item.
4189 This priority is composed of the main priority given with the [#A] cookies,
4190 and by additional input from the age of a schedules or deadline entry."
4192 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
4193 (message "Priority is %d" (if pri pri -
1000))))
4195 (defun org-agenda-show-tags ()
4196 "Show the tags applicable to the current item."
4198 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
4200 (message "Tags are :%s:"
4201 (org-no-properties (mapconcat 'identity tags
":")))
4202 (message "No tags associated with this line"))))
4204 (defun org-agenda-goto (&optional highlight
)
4205 "Go to the Org-mode file which contains the item at point."
4207 (let* ((marker (or (get-text-property (point) 'org-marker
)
4208 (org-agenda-error)))
4209 (buffer (marker-buffer marker
))
4210 (pos (marker-position marker
)))
4211 (switch-to-buffer-other-window buffer
)
4215 (org-show-context 'agenda
)
4217 (and (outline-next-heading)
4218 (org-flag-heading nil
)))) ; show the next heading
4219 (recenter (/ (window-height) 2))
4220 (run-hooks 'org-agenda-after-show-hook
)
4221 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
4223 (defvar org-agenda-after-show-hook nil
4224 "Normal hook run after an item has been shown from the agenda.
4225 Point is in the buffer where the item originated.")
4227 (defun org-agenda-kill ()
4228 "Kill the entry or subtree belonging to the current agenda entry."
4230 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4231 (let* ((marker (or (get-text-property (point) 'org-marker
)
4232 (org-agenda-error)))
4233 (buffer (marker-buffer marker
))
4234 (pos (marker-position marker
))
4235 (type (get-text-property (point) 'type
))
4236 dbeg dend
(n 0) conf
)
4237 (org-with-remote-undo buffer
4238 (with-current-buffer buffer
4241 (if (and (org-mode-p) (not (member type
'("sexp"))))
4242 (setq dbeg
(progn (org-back-to-heading t
) (point))
4243 dend
(org-end-of-subtree t t
))
4244 (setq dbeg
(point-at-bol)
4245 dend
(min (point-max) (1+ (point-at-eol)))))
4247 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
4248 (setq conf
(or (eq t org-agenda-confirm-kill
)
4249 (and (numberp org-agenda-confirm-kill
)
4250 (> n org-agenda-confirm-kill
))))
4253 (format "Delete entry with %d lines in buffer \"%s\"? "
4254 n
(buffer-name buffer
))))
4256 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
4257 (with-current-buffer buffer
(delete-region dbeg dend
))
4258 (message "Agenda item and source killed"))))
4260 (defun org-agenda-archive ()
4261 "Kill the entry or subtree belonging to the current agenda entry."
4263 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4264 (let* ((marker (or (get-text-property (point) 'org-marker
)
4265 (org-agenda-error)))
4266 (buffer (marker-buffer marker
))
4267 (pos (marker-position marker
)))
4268 (org-with-remote-undo buffer
4269 (with-current-buffer buffer
4273 (org-remove-subtree-entries-from-agenda)
4274 (org-back-to-heading t
)
4275 (org-archive-subtree))
4276 (error "Archiving works only in Org-mode files"))))))
4278 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
4279 "Remove all lines in the agenda that correspond to a given subtree.
4280 The subtree is the one in buffer BUF, starting at BEG and ending at END.
4281 If this information is not given, the function uses the tree at point."
4282 (let ((buf (or buf
(current-buffer))) m p
)
4284 (unless (and beg end
)
4285 (org-back-to-heading t
)
4287 (org-end-of-subtree t
)
4289 (set-buffer (get-buffer org-agenda-buffer-name
))
4291 (goto-char (point-max))
4292 (beginning-of-line 1)
4294 (when (and (setq m
(get-text-property (point) 'org-marker
))
4295 (equal buf
(marker-buffer m
))
4296 (setq p
(marker-position m
))
4299 (let ((inhibit-read-only t
))
4300 (delete-region (point-at-bol) (1+ (point-at-eol)))))
4301 (beginning-of-line 0))))))
4303 (defun org-agenda-open-link ()
4304 "Follow the link in the current line, if any."
4306 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
4309 (narrow-to-region (point-at-bol) (point-at-eol))
4310 (org-open-at-point))))
4312 (defun org-agenda-copy-local-variable (var)
4313 "Get a variable from a referenced buffer and install it here."
4314 (let ((m (get-text-property (point) 'org-marker
)))
4315 (when (and m
(buffer-live-p (marker-buffer m
)))
4316 (org-set-local var
(with-current-buffer (marker-buffer m
)
4317 (symbol-value var
))))))
4319 (defun org-agenda-switch-to (&optional delete-other-windows
)
4320 "Go to the Org-mode file which contains the item at point."
4322 (let* ((marker (or (get-text-property (point) 'org-marker
)
4323 (org-agenda-error)))
4324 (buffer (marker-buffer marker
))
4325 (pos (marker-position marker
)))
4326 (switch-to-buffer buffer
)
4327 (and delete-other-windows
(delete-other-windows))
4331 (org-show-context 'agenda
)
4333 (and (outline-next-heading)
4334 (org-flag-heading nil
)))))) ; show the next heading
4336 (defun org-agenda-goto-mouse (ev)
4337 "Go to the Org-mode file which contains the item at the mouse click."
4339 (mouse-set-point ev
)
4342 (defun org-agenda-show ()
4343 "Display the Org-mode file which contains the item at point."
4345 (let ((win (selected-window)))
4347 (select-window win
)))
4349 (defun org-agenda-recenter (arg)
4350 "Display the Org-mode file which contains the item at point and recenter."
4352 (let ((win (selected-window)))
4355 (select-window win
)))
4357 (defun org-agenda-show-mouse (ev)
4358 "Display the Org-mode file which contains the item at the mouse click."
4360 (mouse-set-point ev
)
4363 (defun org-agenda-check-no-diary ()
4364 "Check if the entry is a diary link and abort if yes."
4365 (if (get-text-property (point) 'org-agenda-diary-link
)
4366 (org-agenda-error)))
4368 (defun org-agenda-error ()
4369 (error "Command not allowed in this line"))
4371 (defun org-agenda-tree-to-indirect-buffer ()
4372 "Show the subtree corresponding to the current entry in an indirect buffer.
4373 This calls the command `org-tree-to-indirect-buffer' from the original
4375 With numerical prefix arg ARG, go up to this level and then take that tree.
4376 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
4379 (org-agenda-check-no-diary)
4380 (let* ((marker (or (get-text-property (point) 'org-marker
)
4381 (org-agenda-error)))
4382 (buffer (marker-buffer marker
))
4383 (pos (marker-position marker
)))
4384 (with-current-buffer buffer
4387 (call-interactively 'org-tree-to-indirect-buffer
)))))
4389 (defvar org-last-heading-marker
(make-marker)
4390 "Marker pointing to the headline that last changed its TODO state
4391 by a remote command from the agenda.")
4393 (defun org-agenda-todo-nextset ()
4394 "Switch TODO entry to next sequence."
4396 (org-agenda-todo 'nextset
))
4398 (defun org-agenda-todo-previousset ()
4399 "Switch TODO entry to previous sequence."
4401 (org-agenda-todo 'previousset
))
4403 (defun org-agenda-todo (&optional arg
)
4404 "Cycle TODO state of line at point, also in Org-mode file.
4405 This changes the line at point, all other lines in the agenda referring to
4406 the same tree node, and the headline of the tree node in the Org-mode file."
4408 (org-agenda-check-no-diary)
4409 (let* ((col (current-column))
4410 (marker (or (get-text-property (point) 'org-marker
)
4411 (org-agenda-error)))
4412 (buffer (marker-buffer marker
))
4413 (pos (marker-position marker
))
4414 (hdmarker (get-text-property (point) 'org-hd-marker
))
4415 (inhibit-read-only t
)
4417 (org-with-remote-undo buffer
4418 (with-current-buffer buffer
4421 (org-show-context 'agenda
)
4423 (and (outline-next-heading)
4424 (org-flag-heading nil
))) ; show the next heading
4426 (and (bolp) (forward-char 1))
4427 (setq newhead
(org-get-heading))
4429 (org-back-to-heading)
4430 (move-marker org-last-heading-marker
(point))))
4431 (beginning-of-line 1)
4433 (org-agenda-change-all-lines newhead hdmarker
'fixface
))
4434 (move-to-column col
))))
4436 (defun org-agenda-change-all-lines (newhead hdmarker
&optional fixface
)
4437 "Change all lines in the agenda buffer which match HDMARKER.
4438 The new content of the line will be NEWHEAD (as modified by
4439 `org-format-agenda-item'). HDMARKER is checked with
4440 `equal' against all `org-hd-marker' text properties in the file.
4441 If FIXFACE is non-nil, the face of each item is modified acording to
4442 the new TODO state."
4443 (let* ((inhibit-read-only t
)
4444 props m pl undone-face done-face finish new dotime cat tags
)
4446 (goto-char (point-max))
4447 (beginning-of-line 1)
4449 (setq finish
(bobp))
4450 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
4452 (setq props
(text-properties-at (point))
4453 dotime
(get-text-property (point) 'dotime
)
4454 cat
(get-text-property (point) 'org-category
)
4455 tags
(get-text-property (point) 'tags
)
4456 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
4457 pl
(get-text-property (point) 'prefix-length
)
4458 undone-face
(get-text-property (point) 'undone-face
)
4459 done-face
(get-text-property (point) 'done-face
))
4463 (beginning-of-line 1)
4464 (and (looking-at ".*\n?") (replace-match "")))
4466 (replace-match new t t
)
4467 (beginning-of-line 1)
4468 (add-text-properties (point-at-bol) (point-at-eol) props
)
4470 (add-text-properties
4471 (point-at-bol) (point-at-eol)
4473 (if org-last-todo-state-is-todo
4474 undone-face done-face
))))
4475 (org-agenda-highlight-todo 'line
)
4476 (beginning-of-line 1))
4477 (t (error "Line update did not work"))))
4478 (beginning-of-line 0)))
4479 (org-finalize-agenda)))
4481 (defun org-agenda-align-tags (&optional line
)
4482 "Align all tags in agenda items to `org-agenda-tags-column'."
4483 (let ((inhibit-read-only t
) l c
)
4485 (goto-char (if line
(point-at-bol) (point-min)))
4486 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4487 (if line
(point-at-eol) nil
) t
)
4488 (add-text-properties
4489 (match-beginning 2) (match-end 2)
4490 (list 'face
(delq nil
(list 'org-tag
(get-text-property
4491 (match-beginning 2) 'face
)))))
4492 (setq l
(- (match-end 2) (match-beginning 2))
4493 c
(if (< org-agenda-tags-column
0)
4494 (- (abs org-agenda-tags-column
) l
)
4495 org-agenda-tags-column
))
4496 (delete-region (match-beginning 1) (match-end 1))
4497 (goto-char (match-beginning 1))
4498 (insert (org-add-props
4499 (make-string (max 1 (- c
(current-column))) ?\
)
4500 (text-properties-at (point))))))))
4502 (defun org-agenda-priority-up ()
4503 "Increase the priority of line at point, also in Org-mode file."
4505 (org-agenda-priority 'up
))
4507 (defun org-agenda-priority-down ()
4508 "Decrease the priority of line at point, also in Org-mode file."
4510 (org-agenda-priority 'down
))
4512 (defun org-agenda-priority (&optional force-direction
)
4513 "Set the priority of line at point, also in Org-mode file.
4514 This changes the line at point, all other lines in the agenda referring to
4515 the same tree node, and the headline of the tree node in the Org-mode file."
4517 (org-agenda-check-no-diary)
4518 (let* ((marker (or (get-text-property (point) 'org-marker
)
4519 (org-agenda-error)))
4520 (hdmarker (get-text-property (point) 'org-hd-marker
))
4521 (buffer (marker-buffer hdmarker
))
4522 (pos (marker-position hdmarker
))
4523 (inhibit-read-only t
)
4525 (org-with-remote-undo buffer
4526 (with-current-buffer buffer
4529 (org-show-context 'agenda
)
4531 (and (outline-next-heading)
4532 (org-flag-heading nil
))) ; show the next heading
4533 (funcall 'org-priority force-direction
)
4535 (setq newhead
(org-get-heading)))
4536 (org-agenda-change-all-lines newhead hdmarker
)
4537 (beginning-of-line 1))))
4540 ;; FIXME: should fix the tags property of the agenda line.
4541 (defun org-agenda-set-tags ()
4542 "Set tags for the current headline."
4544 (org-agenda-check-no-diary)
4545 (if (and (org-region-active-p) (interactive-p))
4546 (call-interactively 'org-change-tag-in-region
)
4547 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4548 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4549 (org-agenda-error)))
4550 (buffer (marker-buffer hdmarker
))
4551 (pos (marker-position hdmarker
))
4552 (inhibit-read-only t
)
4554 (org-with-remote-undo buffer
4555 (with-current-buffer buffer
4559 (org-show-context 'agenda
))
4561 (and (outline-next-heading)
4562 (org-flag-heading nil
))) ; show the next heading
4564 (call-interactively 'org-set-tags
)
4566 (setq newhead
(org-get-heading)))
4567 (org-agenda-change-all-lines newhead hdmarker
)
4568 (beginning-of-line 1)))))
4570 (defun org-agenda-toggle-archive-tag ()
4571 "Toggle the archive tag for the current entry."
4573 (org-agenda-check-no-diary)
4574 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4575 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4576 (org-agenda-error)))
4577 (buffer (marker-buffer hdmarker
))
4578 (pos (marker-position hdmarker
))
4579 (inhibit-read-only t
)
4581 (org-with-remote-undo buffer
4582 (with-current-buffer buffer
4585 (org-show-context 'agenda
)
4587 (and (outline-next-heading)
4588 (org-flag-heading nil
))) ; show the next heading
4589 (call-interactively 'org-toggle-archive-tag
)
4591 (setq newhead
(org-get-heading)))
4592 (org-agenda-change-all-lines newhead hdmarker
)
4593 (beginning-of-line 1))))
4595 (defun org-agenda-date-later (arg &optional what
)
4596 "Change the date of this item to one day later."
4598 (org-agenda-check-type t
'agenda
'timeline
)
4599 (org-agenda-check-no-diary)
4600 (let* ((marker (or (get-text-property (point) 'org-marker
)
4601 (org-agenda-error)))
4602 (buffer (marker-buffer marker
))
4603 (pos (marker-position marker
)))
4604 (org-with-remote-undo buffer
4605 (with-current-buffer buffer
4608 (if (not (org-at-timestamp-p))
4609 (error "Cannot find time stamp"))
4610 (org-timestamp-change arg
(or what
'day
)))
4611 (org-agenda-show-new-time marker org-last-changed-timestamp
))
4612 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
4614 (defun org-agenda-date-earlier (arg &optional what
)
4615 "Change the date of this item to one day earlier."
4617 (org-agenda-date-later (- arg
) what
))
4619 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
4620 "Show new date stamp via text properties."
4621 ;; We use text properties to make this undoable
4622 (let ((inhibit-read-only t
))
4623 (setq stamp
(concat " " prefix
" => " stamp
))
4625 (goto-char (point-max))
4627 (when (equal marker
(get-text-property (point) 'org-marker
))
4628 (move-to-column (- (window-width) (length stamp
)) t
)
4629 (if (featurep 'xemacs
)
4630 ;; Use `duplicable' property to trigger undo recording
4631 (let ((ex (make-extent nil nil
))
4632 (gl (make-glyph stamp
)))
4633 (set-glyph-face gl
'secondary-selection
)
4634 (set-extent-properties
4635 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
4636 (insert-extent ex
(1- (point)) (point-at-eol)))
4637 (add-text-properties
4638 (1- (point)) (point-at-eol)
4639 (list 'display
(org-add-props stamp nil
4640 'face
'secondary-selection
))))
4641 (beginning-of-line 1))
4642 (beginning-of-line 0)))))
4644 (defun org-agenda-date-prompt (arg)
4645 "Change the date of this item. Date is prompted for, with default today.
4646 The prefix ARG is passed to the `org-time-stamp' command and can therefore
4647 be used to request time specification in the time stamp."
4649 (org-agenda-check-type t
'agenda
'timeline
)
4650 (org-agenda-check-no-diary)
4651 (let* ((marker (or (get-text-property (point) 'org-marker
)
4652 (org-agenda-error)))
4653 (buffer (marker-buffer marker
))
4654 (pos (marker-position marker
)))
4655 (org-with-remote-undo buffer
4656 (with-current-buffer buffer
4659 (if (not (org-at-timestamp-p))
4660 (error "Cannot find time stamp"))
4661 (org-time-stamp arg
)
4662 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
4664 (defun org-agenda-schedule (arg)
4665 "Schedule the item at point."
4667 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4668 (org-agenda-check-no-diary)
4669 (let* ((marker (or (get-text-property (point) 'org-marker
)
4670 (org-agenda-error)))
4671 (type (marker-insertion-type marker
))
4672 (buffer (marker-buffer marker
))
4673 (pos (marker-position marker
))
4674 (org-insert-labeled-timestamps-at-point nil
)
4676 (when type
(message "%s" type
) (sit-for 3))
4677 (set-marker-insertion-type marker t
)
4678 (org-with-remote-undo buffer
4679 (with-current-buffer buffer
4682 (setq ts
(org-schedule arg
)))
4683 (org-agenda-show-new-time marker ts
"S"))
4684 (message "Item scheduled for %s" ts
)))
4686 (defun org-agenda-deadline (arg)
4687 "Schedule the item at point."
4689 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4690 (org-agenda-check-no-diary)
4691 (let* ((marker (or (get-text-property (point) 'org-marker
)
4692 (org-agenda-error)))
4693 (buffer (marker-buffer marker
))
4694 (pos (marker-position marker
))
4695 (org-insert-labeled-timestamps-at-point nil
)
4697 (org-with-remote-undo buffer
4698 (with-current-buffer buffer
4701 (setq ts
(org-deadline arg
)))
4702 (org-agenda-show-new-time marker ts
"S"))
4703 (message "Deadline for this item set to %s" ts
)))
4706 (defun org-agenda-clock-in (&optional arg
)
4707 "Start the clock on the currently selected item."
4709 (org-agenda-check-no-diary)
4710 (let* ((marker (or (get-text-property (point) 'org-marker
)
4711 (org-agenda-error)))
4712 (pos (marker-position marker
)))
4713 (org-with-remote-undo (marker-buffer marker
)
4714 (with-current-buffer (marker-buffer marker
)
4719 (defun org-agenda-clock-out (&optional arg
)
4720 "Stop the currently running clock."
4722 (unless (marker-buffer org-clock-marker
)
4723 (error "No running clock"))
4724 (org-with-remote-undo (marker-buffer org-clock-marker
)
4727 (defun org-agenda-clock-cancel (&optional arg
)
4728 "Cancel the currently running clock."
4730 (unless (marker-buffer org-clock-marker
)
4731 (error "No running clock"))
4732 (org-with-remote-undo (marker-buffer org-clock-marker
)
4733 (org-clock-cancel)))
4735 (defun org-agenda-diary-entry ()
4736 "Make a diary entry, like the `i' command from the calendar.
4737 All the standard commands work: block, weekly etc."
4739 (org-agenda-check-type t
'agenda
'timeline
)
4740 (require 'diary-lib
)
4742 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
4743 (read-char-exclusive)))
4744 (cmd (cdr (assoc char
4745 '((?d . insert-diary-entry
)
4746 (?w . insert-weekly-diary-entry
)
4747 (?m . insert-monthly-diary-entry
)
4748 (?y . insert-yearly-diary-entry
)
4749 (?a . insert-anniversary-diary-entry
)
4750 (?b . insert-block-diary-entry
)
4751 (?c . insert-cyclic-diary-entry
)))))
4752 (oldf (symbol-function 'calendar-cursor-to-date
))
4753 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
4755 (mark (or (mark t
) (point))))
4757 (error "No command associated with <%c>" char
))
4758 (unless (and (get-text-property point
'day
)
4759 (or (not (equal ?b char
))
4760 (get-text-property mark
'day
)))
4761 (error "Don't know which date to use for diary entry"))
4762 ;; We implement this by hacking the `calendar-cursor-to-date' function
4763 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
4764 (let ((calendar-mark-ring
4765 (list (calendar-gregorian-from-absolute
4766 (or (get-text-property mark
'day
)
4767 (get-text-property point
'day
))))))
4770 (fset 'calendar-cursor-to-date
4771 (lambda (&optional error
)
4772 (calendar-gregorian-from-absolute
4773 (get-text-property point
'day
))))
4774 (call-interactively cmd
))
4775 (fset 'calendar-cursor-to-date oldf
)))))
4778 (defun org-agenda-execute-calendar-command (cmd)
4779 "Execute a calendar command from the agenda, with the date associated to
4780 the cursor position."
4781 (org-agenda-check-type t
'agenda
'timeline
)
4782 (require 'diary-lib
)
4783 (unless (get-text-property (point) 'day
)
4784 (error "Don't know which date to use for calendar command"))
4785 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
4787 (date (calendar-gregorian-from-absolute
4788 (get-text-property point
'day
)))
4789 ;; the following 3 vars are needed in the calendar
4790 (displayed-day (extract-calendar-day date
))
4791 (displayed-month (extract-calendar-month date
))
4792 (displayed-year (extract-calendar-year date
)))
4795 (fset 'calendar-cursor-to-date
4796 (lambda (&optional error
)
4797 (calendar-gregorian-from-absolute
4798 (get-text-property point
'day
))))
4799 (call-interactively cmd
))
4800 (fset 'calendar-cursor-to-date oldf
))))
4802 (defun org-agenda-phases-of-moon ()
4803 "Display the phases of the moon for the 3 months around the cursor date."
4805 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
4807 (defun org-agenda-holidays ()
4808 "Display the holidays for the 3 months around the cursor date."
4810 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
4812 (defvar calendar-longitude
)
4813 (defvar calendar-latitude
)
4814 (defvar calendar-location-name
)
4816 (defun org-agenda-sunrise-sunset (arg)
4817 "Display sunrise and sunset for the cursor date.
4818 Latitude and longitude can be specified with the variables
4819 `calendar-latitude' and `calendar-longitude'. When called with prefix
4820 argument, latitude and longitude will be prompted for."
4823 (let ((calendar-longitude (if arg nil calendar-longitude
))
4824 (calendar-latitude (if arg nil calendar-latitude
))
4825 (calendar-location-name
4826 (if arg
"the given coordinates" calendar-location-name
)))
4827 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
4829 (defun org-agenda-goto-calendar ()
4830 "Open the Emacs calendar with the date at the cursor."
4832 (org-agenda-check-type t
'agenda
'timeline
)
4833 (let* ((day (or (get-text-property (point) 'day
)
4834 (error "Don't know which date to open in calendar")))
4835 (date (calendar-gregorian-from-absolute day
))
4836 (calendar-move-hook nil
)
4837 (view-calendar-holidays-initially nil
)
4838 (view-diary-entries-initially nil
))
4840 (calendar-goto-date date
)))
4843 (defun org-calendar-goto-agenda ()
4844 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
4845 This is a command that has to be installed in `calendar-mode-map'."
4847 (org-agenda-list nil
(calendar-absolute-from-gregorian
4848 (calendar-cursor-to-date))
4851 (defun org-agenda-convert-date ()
4853 (org-agenda-check-type t
'agenda
'timeline
)
4854 (let ((day (get-text-property (point) 'day
))
4857 (error "Don't know which date to convert"))
4858 (setq date
(calendar-gregorian-from-absolute day
))
4860 "Gregorian: " (calendar-date-string date
) "\n"
4861 "ISO: " (calendar-iso-date-string date
) "\n"
4862 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
4863 "Julian: " (calendar-julian-date-string date
) "\n"
4864 "Astron. JD: " (calendar-astro-date-string date
)
4865 " (Julian date number at noon UTC)\n"
4866 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
4867 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
4868 "French: " (calendar-french-date-string date
) "\n"
4869 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
4870 "Mayan: " (calendar-mayan-date-string date
) "\n"
4871 "Coptic: " (calendar-coptic-date-string date
) "\n"
4872 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
4873 "Persian: " (calendar-persian-date-string date
) "\n"
4874 "Chinese: " (calendar-chinese-date-string date
) "\n"))
4875 (with-output-to-temp-buffer "*Dates*"
4877 (if (fboundp 'fit-window-to-buffer
)
4878 (fit-window-to-buffer (get-buffer-window "*Dates*")))))
4881 ;;; Appointment reminders
4883 (defvar appt-time-msg-list
)
4886 (defun org-agenda-to-appt (&optional refresh filter
)
4887 "Activate appointments found in `org-agenda-files'.
4888 With a \\[universal-argument] prefix, refresh the list of
4891 If FILTER is t, interactively prompt the user for a regular
4892 expression, and filter out entries that don't match it.
4894 If FILTER is a string, use this string as a regular expression
4895 for filtering entries out.
4897 FILTER can also be an alist with the car of each cell being
4898 either 'headline or 'category. For example:
4900 '((headline \"IMPORTANT\")
4901 (category \"Work\"))
4903 will only add headlines containing IMPORTANT or headlines
4904 belonging to the \"Work\" category."
4907 (if refresh
(setq appt-time-msg-list nil
))
4909 (setq filter
(read-from-minibuffer "Regexp filter: ")))
4910 (let* ((cnt 0) ; count added events
4911 (org-agenda-new-buffers nil
)
4912 (org-deadline-warning-days 0)
4913 (today (org-date-to-gregorian
4914 (time-to-days (current-time))))
4915 (files (org-agenda-files)) entries file
)
4916 ;; Get all entries which may contain an appt
4917 (while (setq file
(pop files
))
4920 (org-agenda-get-day-entries
4921 file today
:timestamp
:scheduled
:deadline
))))
4922 (setq entries
(delq nil entries
))
4923 ;; Map thru entries and find if we should filter them out
4926 (let* ((evt (org-trim (get-text-property 1 'txt x
)))
4927 (cat (get-text-property 1 'org-category x
))
4928 (tod (get-text-property 1 'time-of-day x
))
4929 (ok (or (null filter
)
4930 (and (stringp filter
) (string-match filter evt
))
4933 (cadr (assoc 'category filter
)) cat
)
4935 (cadr (assoc 'headline filter
)) evt
))))))
4936 ;; FIXME: Shall we remove text-properties for the appt text?
4937 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
4939 (setq tod
(number-to-string tod
)
4940 tod
(when (string-match
4941 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)" tod
)
4942 (concat (match-string 1 tod
) ":"
4943 (match-string 2 tod
))))
4945 (setq cnt
(1+ cnt
))))) entries
)
4946 (org-release-buffers org-agenda-new-buffers
)
4948 (message "No event to add")
4949 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
4951 (provide 'org-agenda
)
4953 ;;; org-agenda.el ends here