1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
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 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; This file contains the code for creating and using the Agenda for Org-mode.
36 (declare-function diary-add-to-list
"diary-lib"
37 (date string specifier
&optional marker globcolor literal
))
38 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
39 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
40 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
41 (declare-function calendar-check-holidays
"holidays" (date))
42 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
43 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
44 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
45 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
46 (declare-function calendar-goto-date
"cal-move" (date))
47 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
48 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
49 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
50 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
51 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
52 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
53 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
54 (declare-function org-columns-quit
"org-colview" ())
55 (defvar calendar-mode-map
)
57 ;; Defined somewhere in this file, but used before definition.
58 (defvar org-agenda-buffer-name
)
59 (defvar org-agenda-overriding-header
)
62 (defvar org-agenda-undo-list
)
63 (defvar org-agenda-pending-undo-list
)
64 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
66 (defcustom org-agenda-confirm-kill
1
67 "When set, remote killing from the agenda buffer needs confirmation.
68 When t, a confirmation is always needed. When a number N, confirmation is
69 only needed when the text to be killed contains more than N non-white lines."
72 (const :tag
"Never" nil
)
73 (const :tag
"Always" t
)
74 (number :tag
"When more than N lines")))
76 (defcustom org-agenda-compact-blocks nil
77 "Non-nil means, make the block agenda more compact.
78 This is done by leaving out unnecessary lines."
82 (defgroup org-agenda-export nil
83 "Options concerning exporting agenda views in Org-mode."
84 :tag
"Org Agenda Export"
87 (defcustom org-agenda-with-colors t
88 "Non-nil means, use colors in agenda views."
89 :group
'org-agenda-export
92 (defcustom org-agenda-exporter-settings nil
93 "Alist of variable/value pairs that should be active during agenda export.
94 This is a good place to set uptions for ps-print and for htmlize."
95 :group
'org-agenda-export
99 (sexp :tag
"Value"))))
101 (defcustom org-agenda-export-html-style
""
102 "The style specification for exported HTML Agenda files.
103 If this variable contains a string, it will replace the default <style>
104 section as produced by `htmlize'.
105 Since there are different ways of setting style information, this variable
106 needs to contain the full HTML structure to provide a style, including the
107 surrounding HTML tags. The style specifications should include definitions
108 the fonts used by the agenda, here is an example:
110 <style type=\"text/css\">
111 p { font-weight: normal; color: gray; }
112 .org-agenda-structure {
124 .title { text-align: center; }
125 .todo, .deadline { color: red; }
126 .done { color: green; }
129 or, if you want to keep the style in a file,
131 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
133 As the value of this option simply gets inserted into the HTML <head> header,
134 you can \"misuse\" it to also add other text to the header. However,
135 <style>...</style> is required, if not present the variable will be ignored."
136 :group
'org-agenda-export
137 :group
'org-export-html
140 (defgroup org-agenda-custom-commands nil
141 "Options concerning agenda views in Org-mode."
142 :tag
"Org Agenda Custom Commands"
145 (defconst org-sorting-choice
147 (const time-up
) (const time-down
)
148 (const category-keep
) (const category-up
) (const category-down
)
149 (const tag-down
) (const tag-up
)
150 (const priority-up
) (const priority-down
)
151 (const effort-up
) (const effort-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-skip-comment-trees t
395 "Non-nil means, skip trees that start with teh COMMENT keyword.
396 When nil, these trees are also scand by agenda commands."
397 :group
'org-agenda-skip
400 (defcustom org-agenda-todo-list-sublevels t
401 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
402 When nil, the sublevels of a TODO entry are not checked, resulting in
403 potentially much shorter TODO lists."
404 :group
'org-agenda-skip
408 (defcustom org-agenda-todo-ignore-with-date nil
409 "Non-nil means, don't show entries with a date in the global todo list.
410 You can use this if you prefer to mark mere appointments with a TODO keyword,
411 but don't want them to show up in the TODO list.
412 When this is set, it also covers deadlines and scheduled items, the settings
413 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
415 :group
'org-agenda-skip
419 (defcustom org-agenda-todo-ignore-scheduled nil
420 "Non-nil means, don't show scheduled entries in the global todo list.
421 The idea behind this is that by scheduling it, you have already taken care
423 See also `org-agenda-todo-ignore-with-date'."
424 :group
'org-agenda-skip
428 (defcustom org-agenda-todo-ignore-deadlines nil
429 "Non-nil means, don't show near deadline entries in the global todo list.
430 Near means closer than `org-deadline-warning-days' days.
431 The idea behind this is that such items will appear in the agenda anyway.
432 See also `org-agenda-todo-ignore-with-date'."
433 :group
'org-agenda-skip
437 (defcustom org-agenda-skip-scheduled-if-done nil
438 "Non-nil means don't show scheduled items in agenda when they are done.
439 This is relevant for the daily/weekly agenda, not for the TODO list. And
440 it applies only to the actual date of the scheduling. Warnings about
441 an item with a past scheduling dates are always turned off when the item
443 :group
'org-agenda-skip
446 (defcustom org-agenda-skip-deadline-if-done nil
447 "Non-nil means don't show deadines when the corresponding item is done.
448 When nil, the deadline is still shown and should give you a happy feeling.
449 This is relevant for the daily/weekly agenda. And it applied only to the
450 actualy date of the deadline. Warnings about approching and past-due
451 deadlines are always turned off when the item is DONE."
452 :group
'org-agenda-skip
455 (defcustom org-agenda-skip-timestamp-if-done nil
456 "Non-nil means don't select item by timestamp or -range if it is DONE."
457 :group
'org-agenda-skip
460 (defcustom org-timeline-show-empty-dates
3
461 "Non-nil means, `org-timeline' also shows dates without an entry.
462 When nil, only the days which actually have entries are shown.
463 When t, all days between the first and the last date are shown.
464 When an integer, show also empty dates, but if there is a gap of more than
465 N days, just insert a special line indicating the size of the gap."
466 :group
'org-agenda-skip
468 (const :tag
"None" nil
)
470 (number :tag
"at most")))
472 (defgroup org-agenda-startup nil
473 "Options concerning initial settings in the Agenda in Org Mode."
474 :tag
"Org Agenda Startup"
477 (defcustom org-finalize-agenda-hook nil
478 "Hook run just before displaying an agenda buffer."
479 :group
'org-agenda-startup
482 (defcustom org-agenda-mouse-1-follows-link nil
483 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
484 A longer mouse click will still set point. Does not work on XEmacs.
485 Needs to be set before org.el is loaded."
486 :group
'org-agenda-startup
489 (defcustom org-agenda-start-with-follow-mode nil
490 "The initial value of follow-mode in a newly created agenda window."
491 :group
'org-agenda-startup
494 (defvar org-agenda-include-inactive-timestamps nil
495 "Non-nil means, include inactive time stamps in agenda and timeline.")
497 (defgroup org-agenda-windows nil
498 "Options concerning the windows used by the Agenda in Org Mode."
499 :tag
"Org Agenda Windows"
502 (defcustom org-agenda-window-setup
'reorganize-frame
503 "How the agenda buffer should be displayed.
504 Possible values for this option are:
506 current-window Show agenda in the current window, keeping all other windows.
507 other-frame Use `switch-to-buffer-other-frame' to display agenda.
508 other-window Use `switch-to-buffer-other-window' to display agenda.
509 reorganize-frame Show only two windows on the current frame, the current
510 window and the agenda.
511 See also the variable `org-agenda-restore-windows-after-quit'."
512 :group
'org-agenda-windows
514 (const current-window
)
517 (const reorganize-frame
)))
519 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
520 "The min and max height of the agenda window as a fraction of frame height.
521 The value of the variable is a cons cell with two numbers between 0 and 1.
522 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
523 :group
'org-agenda-windows
524 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
526 (defcustom org-agenda-restore-windows-after-quit nil
527 "Non-nil means, restore window configuration open exiting agenda.
528 Before the window configuration is changed for displaying the agenda,
529 the current status is recorded. When the agenda is exited with
530 `q' or `x' and this option is set, the old state is restored. If
531 `org-agenda-window-setup' is `other-frame', the value of this
532 option will be ignored.."
533 :group
'org-agenda-windows
536 (defgroup org-agenda-daily
/weekly nil
537 "Options concerning the daily/weekly agenda."
538 :tag
"Org Agenda Daily/Weekly"
541 (defcustom org-agenda-ndays
7
542 "Number of days to include in overview display.
544 :group
'org-agenda-daily
/weekly
547 (defcustom org-agenda-start-on-weekday
1
548 "Non-nil means, start the overview always on the specified weekday.
549 0 denotes Sunday, 1 denotes Monday etc.
550 When nil, always start on the current day."
551 :group
'org-agenda-daily
/weekly
552 :type
'(choice (const :tag
"Today" nil
)
553 (number :tag
"Weekday No.")))
555 (defcustom org-agenda-show-all-dates t
556 "Non-nil means, `org-agenda' shows every day in the selected range.
557 When nil, only the days which actually have entries are shown."
558 :group
'org-agenda-daily
/weekly
561 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
562 "Format string for displaying dates in the agenda.
563 Used by the daily/weekly agenda and by the timeline. This should be
564 a format string understood by `format-time-string', or a function returning
565 the formatted date as a string. The function must take a single argument,
566 a calendar-style date list like (month day year)."
567 :group
'org-agenda-daily
/weekly
569 (string :tag
"Format string")
570 (function :tag
"Function")))
572 (defun org-agenda-format-date-aligned (date)
573 "Format a date string for display in the daily/weekly agenda, or timeline.
574 This function makes sure that dates are aligned for easy reading."
576 (let* ((dayname (calendar-day-name date
))
578 (day-of-week (calendar-day-of-week date
))
580 (monthname (calendar-month-name month
))
582 (iso-week (org-days-to-iso-week
583 (calendar-absolute-from-gregorian date
)))
584 (weekyear (cond ((and (= month
1) (>= iso-week
52))
586 ((and (= month
12) (<= iso-week
1))
589 (weekstring (if (= day-of-week
1)
590 (format " W%02d" iso-week
)
592 (format "%-10s %2d %s %4d%s"
593 dayname day monthname year weekstring
)))
595 (defcustom org-agenda-weekend-days
'(6 0)
596 "Which days are weekend?
597 These days get the special face `org-agenda-date-weekend' in the agenda
598 and timeline buffers."
599 :group
'org-agenda-daily
/weekly
600 :type
'(set :greedy t
601 (const :tag
"Monday" 1)
602 (const :tag
"Tuesday" 2)
603 (const :tag
"Wednesday" 3)
604 (const :tag
"Thursday" 4)
605 (const :tag
"Friday" 5)
606 (const :tag
"Saturday" 6)
607 (const :tag
"Sunday" 0)))
609 (defcustom org-agenda-include-diary nil
610 "If non-nil, include in the agenda entries from the Emacs Calendar's diary."
611 :group
'org-agenda-daily
/weekly
614 (defcustom org-agenda-include-all-todo nil
615 "Set means weekly/daily agenda will always contain all TODO entries.
616 The TODO entries will be listed at the top of the agenda, before
617 the entries for specific days."
618 :group
'org-agenda-daily
/weekly
621 (defcustom org-agenda-repeating-timestamp-show-all t
622 "Non-nil means, show all occurences of a repeating stamp in the agenda.
623 When nil, only one occurence is shown, either today or the
624 nearest into the future."
625 :group
'org-agenda-daily
/weekly
628 (defcustom org-scheduled-past-days
10000
629 "No. of days to continue listing scheduled items that are not marked DONE.
630 When an item is scheduled on a date, it shows up in the agenda on this
631 day and will be listed until it is marked done for the number of days
633 :group
'org-agenda-daily
/weekly
636 (defcustom org-agenda-start-with-clockreport-mode nil
637 "The initial value of clockreport-mode in a newly created agenda window."
638 :group
'org-agenda-startup
639 :group
'org-agenda-daily
/weekly
642 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
643 "Property list with parameters for the clocktable in clockreport mode.
644 This is the display mode that shows a clock table in the daily/weekly
645 agenda, the properties for this dynamic block can be set here.
646 The usual clocktable parameters are allowed here, but you cannot set
647 the properties :name, :tstart, :tend, :block, and :scope - these will
648 be overwritten to make sure the content accurately reflects the
649 current display in the agenda."
650 :group
'org-agenda-daily
/weekly
654 (defgroup org-agenda-time-grid nil
655 "Options concerning the time grid in the Org-mode Agenda."
656 :tag
"Org Agenda Time Grid"
659 (defcustom org-agenda-use-time-grid t
660 "Non-nil means, show a time grid in the agenda schedule.
661 A time grid is a set of lines for specific times (like every two hours between
662 8:00 and 20:00). The items scheduled for a day at specific times are
663 sorted in between these lines.
664 For details about when the grid will be shown, and what it will look like, see
665 the variable `org-agenda-time-grid'."
666 :group
'org-agenda-time-grid
669 (defcustom org-agenda-time-grid
670 '((daily today require-timed
)
672 (800 1000 1200 1400 1600 1800 2000))
674 "The settings for time grid for agenda display.
675 This is a list of three items. The first item is again a list. It contains
676 symbols specifying conditions when the grid should be displayed:
678 daily if the agenda shows a single day
679 weekly if the agenda shows an entire week
680 today show grid on current date, independent of daily/weekly display
681 require-timed show grid only if at least one item has a time specification
683 The second item is a string which will be placed behind the grid time.
685 The third item is a list of integers, indicating the times that should have
687 :group
'org-agenda-time-grid
690 (set :greedy t
:tag
"Grid Display Options"
691 (const :tag
"Show grid in single day agenda display" daily
)
692 (const :tag
"Show grid in weekly agenda display" weekly
)
693 (const :tag
"Always show grid for today" today
)
694 (const :tag
"Show grid only if any timed entries are present"
696 (const :tag
"Skip grid times already present in an entry"
698 (string :tag
"Grid String")
699 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
701 (defgroup org-agenda-sorting nil
702 "Options concerning sorting in the Org-mode Agenda."
703 :tag
"Org Agenda Sorting"
706 (defcustom org-agenda-sorting-strategy
707 '((agenda time-up category-keep priority-down
)
708 (todo category-keep priority-down
)
709 (tags category-keep priority-down
)
710 (search category-keep
))
711 "Sorting structure for the agenda items of a single day.
712 This is a list of symbols which will be used in sequence to determine
713 if an entry should be listed before another entry. The following
714 symbols are recognized:
716 time-up Put entries with time-of-day indications first, early first
717 time-down Put entries with time-of-day indications first, late first
718 category-keep Keep the default order of categories, corresponding to the
719 sequence in `org-agenda-files'.
720 category-up Sort alphabetically by category, A-Z.
721 category-down Sort alphabetically by category, Z-A.
722 tag-up Sort alphabetically by last tag, A-Z.
723 tag-down Sort alphabetically by last tag, Z-A.
724 priority-up Sort numerically by priority, high priority last.
725 priority-down Sort numerically by priority, high priority first.
726 effort-up Sort numerically by estimated effort, high effort last.
727 effort-down Sort numerically by estimated effort, high effort first.
729 The different possibilities will be tried in sequence, and testing stops
730 if one comparison returns a \"not-equal\". For example, the default
731 '(time-up category-keep priority-down)
732 means: Pull out all entries having a specified time of day and sort them,
733 in order to make a time schedule for the current day the first thing in the
734 agenda listing for the day. Of the entries without a time indication, keep
735 the grouped in categories, don't sort the categories, but keep them in
736 the sequence given in `org-agenda-files'. Within each category sort by
739 Leaving out `category-keep' would mean that items will be sorted across
740 categories by priority.
742 Instead of a single list, this can also be a set of list for specific
743 contents, with a context symbol in the car of the list, any of
744 `agenda', `todo', `tags' for the corresponding agenda views."
745 :group
'org-agenda-sorting
747 (repeat :tag
"General" ,org-sorting-choice
)
748 (list :tag
"Individually"
749 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
750 (repeat ,org-sorting-choice
))
751 (cons (const :tag
"Strategy for TODO lists" todo
)
752 (repeat ,org-sorting-choice
))
753 (cons (const :tag
"Strategy for Tags matches" tags
)
754 (repeat ,org-sorting-choice
)))))
756 (defcustom org-sort-agenda-notime-is-late t
757 "Non-nil means, items without time are considered late.
758 This is only relevant for sorting. When t, items which have no explicit
759 time like 15:30 will be considered as 99:01, i.e. later than any items which
760 do have a time. When nil, the default time is before 0:00. You can use this
761 option to decide if the schedule for today should come before or after timeless
763 :group
'org-agenda-sorting
766 (defcustom org-sort-agenda-noeffort-is-high t
767 "Non-nil means, items without effort estimate are sorted as high effort.
768 When nil, such items are sorted as 0 minutes effort."
769 :group
'org-agenda-sorting
772 (defgroup org-agenda-line-format nil
773 "Options concerning the entry prefix in the Org-mode agenda display."
774 :tag
"Org Agenda Line Format"
777 (defcustom org-agenda-prefix-format
778 '((agenda .
" %-12:c%?-12t% s")
782 (search .
" %-12:c"))
783 "Format specifications for the prefix of items in the agenda views.
784 An alist with four entries, for the different agenda types. The keys to the
785 sublists are `agenda', `timeline', `todo', and `tags'. The values
787 This format works similar to a printf format, with the following meaning:
789 %c the category of the item, \"Diary\" for entries from the diary, or
790 as given by the CATEGORY keyword or derived from the file name.
791 %T the *last* tag of the item. Last because inherited tags come
793 %t the time-of-day specification if one applies to the entry, in the
795 %s Scheduling/Deadline information, a short string
797 All specifiers work basically like the standard `%s' of printf, but may
798 contain two additional characters: A question mark just after the `%' and
799 a whitespace/punctuation character just before the final letter.
801 If the first character after `%' is a question mark, the entire field
802 will only be included if the corresponding value applies to the
803 current entry. This is useful for fields which should have fixed
804 width when present, but zero width when absent. For example,
805 \"%?-12t\" will result in a 12 character time field if a time of the
806 day is specified, but will completely disappear in entries which do
809 If there is punctuation or whitespace character just before the final
810 format letter, this character will be appended to the field value if
811 the value is not empty. For example, the format \"%-12:c\" leads to
812 \"Diary: \" if the category is \"Diary\". If the category were be
813 empty, no additional colon would be interted.
815 The default value of this option is \" %-12:c%?-12t% s\", meaning:
816 - Indent the line with two space characters
817 - Give the category in a 12 chars wide field, padded with whitespace on
818 the right (because of `-'). Append a colon if there is a category
820 - If there is a time-of-day, put it into a 12 chars wide field. If no
821 time, don't put in an empty field, just skip it (because of '?').
822 - Finally, put the scheduling information and append a whitespace.
824 As another example, if you don't want the time-of-day of entries in
825 the prefix, you could use:
827 (setq org-agenda-prefix-format \" %-11:c% s\")
829 See also the variables `org-agenda-remove-times-when-in-prefix' and
830 `org-agenda-remove-tags'."
832 (string :tag
"General format")
833 (list :greedy t
:tag
"View dependent"
834 (cons (const agenda
) (string :tag
"Format"))
835 (cons (const timeline
) (string :tag
"Format"))
836 (cons (const todo
) (string :tag
"Format"))
837 (cons (const tags
) (string :tag
"Format"))
838 (cons (const search
) (string :tag
"Format"))))
839 :group
'org-agenda-line-format
)
841 (defvar org-prefix-format-compiled nil
842 "The compiled version of the most recently used prefix format.
843 See the variable `org-agenda-prefix-format'.")
845 (defcustom org-agenda-todo-keyword-format
"%-1s"
846 "Format for the TODO keyword in agenda lines.
847 Set this to something like \"%-12s\" if you want all TODO keywords
848 to occupy a fixed space in the agenda display."
849 :group
'org-agenda-line-format
852 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
853 "Text preceeding scheduled items in the agenda view.
854 This is a list with two strings. The first applies when the item is
855 scheduled on the current day. The second applies when it has been scheduled
856 previously, it may contain a %d indicating that this is the nth time that
857 this item is scheduled, due to automatic rescheduling of unfinished items
858 for the following day. So this number is one larger than the number of days
859 that passed since this item was scheduled first."
860 :group
'org-agenda-line-format
862 (string :tag
"Scheduled today ")
863 (string :tag
"Scheduled previously")))
865 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
866 "Text preceeding deadline items in the agenda view.
867 This is a list with two strings. The first applies when the item has its
868 deadline on the current day. The second applies when it is in the past or
869 in the future, it may contain %d to capture how many days away the deadline
871 :group
'org-agenda-line-format
873 (string :tag
"Deadline today ")
874 (choice :tag
"Deadline relative"
875 (string :tag
"Format string")
878 (defcustom org-agenda-remove-times-when-in-prefix t
879 "Non-nil means, remove duplicate time specifications in agenda items.
880 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
881 time-of-day specification in a headline or diary entry is extracted and
882 placed into the prefix. If this option is non-nil, the original specification
883 \(a timestamp or -range, or just a plain time(range) specification like
884 11:30-4pm) will be removed for agenda display. This makes the agenda less
886 The option can be t or nil. It may also be the symbol `beg', indicating
887 that the time should only be removed what it is located at the beginning of
888 the headline/diary entry."
889 :group
'org-agenda-line-format
891 (const :tag
"Always" t
)
892 (const :tag
"Never" nil
)
893 (const :tag
"When at beginning of entry" beg
)))
896 (defcustom org-agenda-default-appointment-duration nil
897 "Default duration for appointments that only have a starting time.
898 When nil, no duration is specified in such cases.
899 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
900 :group
'org-agenda-line-format
902 (integer :tag
"Minutes")
903 (const :tag
"No default duration")))
906 (defcustom org-agenda-remove-tags nil
907 "Non-nil means, remove the tags from the headline copy in the agenda.
908 When this is the symbol `prefix', only remove tags when
909 `org-agenda-prefix-format' contains a `%T' specifier."
910 :group
'org-agenda-line-format
912 (const :tag
"Always" t
)
913 (const :tag
"Never" nil
)
914 (const :tag
"When prefix format contains %T" prefix
)))
916 (if (fboundp 'defvaralias
)
917 (defvaralias 'org-agenda-remove-tags-when-in-prefix
918 'org-agenda-remove-tags
))
920 (defcustom org-agenda-tags-column -
80
921 "Shift tags in agenda items to this column.
922 If this number is positive, it specifies the column. If it is negative,
923 it means that the tags should be flushright to that column. For example,
924 -80 works well for a normal 80 character screen."
925 :group
'org-agenda-line-format
928 (if (fboundp 'defvaralias
)
929 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
931 (defcustom org-agenda-fontify-priorities t
932 "Non-nil means, highlight low and high priorities in agenda.
933 When t, the highest priority entries are bold, lowest priority italic.
934 This may also be an association list of priority faces. The face may be
935 a names face, or a list like `(:background \"Red\")'."
936 :group
'org-agenda-line-format
938 (const :tag
"Never" nil
)
939 (const :tag
"Defaults" t
)
940 (repeat :tag
"Specify"
941 (list (character :tag
"Priority" :value ?A
)
942 (sexp :tag
"face")))))
945 (defgroup org-agenda-column-view nil
946 "Options concerning column view in the agenda."
947 :tag
"Org Agenda Column View"
950 (defcustom org-agenda-columns-show-summaries t
951 "Non-nil means, show summaries for columns displayed in the agenda view."
952 :group
'org-agenda-column-view
955 (defcustom org-agenda-columns-remove-prefix-from-item t
956 "Non-nil means, remove the prefix from a headline for agenda column view.
957 The special ITEM field in the columns format contains the current line, with
958 all information shown in other columns (like the TODO state or a tag).
959 When this variable is non-nil, also the agenda prefix will be removed from
960 the content of the ITEM field, to make sure as much as possible of the
961 headline can be shown in the limited width of the field."
965 (defcustom org-agenda-columns-compute-summary-properties t
966 "Non-nil means, recompute all summary properties before column view.
967 When column view in the agenda is listing properties that have a summary
968 operator, it can go to all relevant buffers and recompute the summaries
969 there. This can mean overhead for the agenda column view, but is necessary
970 to have thing up to date.
971 As a special case, a CLOCKSUM property also makes sure that the clock
972 computations are current."
973 :group
'org-agenda-column-view
976 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
977 "Non-nil means, the duration of an appointment will add to day effort.
978 The property to which appointment durations will be added is the one given
979 in the option `org-effort-property'. If an appointment does not have
980 an end time, `org-agenda-default-appointment-duration' will be used. If that
981 is not set, an appointment without end time will not contribute to the time
983 :group
'org-agenda-column-view
990 (defun org-add-agenda-custom-command (entry)
991 "Replace or add a command in `org-agenda-custom-commands'.
992 This is mostly for hacking and trying a new command - once the command
993 works you probably want to add it to `org-agenda-custom-commands' for good."
994 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
996 (setcdr ass
(cdr entry
))
997 (push entry org-agenda-custom-commands
))))
999 ;;; Define the Org-agenda-mode
1001 (defvar org-agenda-mode-map
(make-sparse-keymap)
1002 "Keymap for `org-agenda-mode'.")
1004 (defvar org-agenda-menu
) ; defined later in this file.
1005 (defvar org-agenda-follow-mode nil
)
1006 (defvar org-agenda-clockreport-mode nil
)
1007 (defvar org-agenda-show-log nil
)
1008 (defvar org-agenda-redo-command nil
)
1009 (defvar org-agenda-query-string nil
)
1010 (defvar org-agenda-mode-hook nil
)
1011 (defvar org-agenda-type nil
)
1012 (defvar org-agenda-force-single-file nil
)
1014 (defun org-agenda-mode ()
1015 "Mode for time-sorted view on action items in Org-mode files.
1017 The following commands are available:
1019 \\{org-agenda-mode-map}"
1021 (kill-all-local-variables)
1022 (setq org-agenda-undo-list nil
1023 org-agenda-pending-undo-list nil
)
1024 (setq major-mode
'org-agenda-mode
)
1025 ;; Keep global-font-lock-mode from turning on font-lock-mode
1026 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1027 (setq mode-name
"Org-Agenda")
1028 (use-local-map org-agenda-mode-map
)
1029 (easy-menu-add org-agenda-menu
)
1030 (if org-startup-truncated
(setq truncate-lines t
))
1031 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1032 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1033 ;; Make sure properties are removed when copying text
1034 (when (boundp 'buffer-substring-filters
)
1035 (org-set-local 'buffer-substring-filters
1037 (set-text-properties 0 (length x
) nil x
) x
)
1038 buffer-substring-filters
)))
1039 (unless org-agenda-keep-modes
1040 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1041 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1042 org-agenda-show-log nil
))
1044 '("Agenda") "Agenda Files"
1048 (if (get 'org-agenda-files
'org-restrict
)
1049 "Restricted to single file"
1051 '(org-edit-agenda-file-list)
1052 (not (get 'org-agenda-files
'org-restrict
)))
1054 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1055 (org-agenda-set-mode-name)
1057 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1058 (list 'org-agenda-mode-hook
)))
1060 (substitute-key-definition 'undo
'org-agenda-undo
1061 org-agenda-mode-map global-map
)
1062 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1063 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1064 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1065 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1066 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1067 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1068 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1069 (org-defkey org-agenda-mode-map
"A" 'org-agenda-archive-to-archive-sibling
)
1070 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1071 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1072 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1073 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1074 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1075 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1076 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1077 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1078 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1079 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1080 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1081 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1082 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1083 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1084 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1085 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1086 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1087 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1088 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1089 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1090 (org-defkey org-agenda-mode-map
"k" 'org-agenda-action
)
1091 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-k" 'org-agenda-action
)
1092 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-date-later
)
1093 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-date-earlier
)
1094 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-date-later
)
1095 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-date-earlier
)
1097 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1098 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1099 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1100 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1101 (while l
(org-defkey org-agenda-mode-map
1102 (int-to-string (pop l
)) 'digit-argument
)))
1104 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1105 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1106 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1107 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1108 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1109 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1110 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1111 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1112 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1113 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1114 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1115 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1116 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1117 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1118 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1119 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1120 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1121 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1122 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1123 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1124 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1125 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1126 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1127 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1128 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1129 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1130 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1131 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1132 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1133 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1134 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1135 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1136 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1137 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1138 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1139 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1140 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1141 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1142 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1143 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1144 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1145 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1146 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1147 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1148 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1150 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1151 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1152 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1153 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1155 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1156 "Local keymap for agenda entries from Org-mode.")
1158 (org-defkey org-agenda-keymap
1159 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1160 (org-defkey org-agenda-keymap
1161 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1162 (when org-agenda-mouse-1-follows-link
1163 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1164 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1168 ["Show" org-agenda-show t
]
1169 ["Go To (other window)" org-agenda-goto t
]
1170 ["Go To (this window)" org-agenda-switch-to t
]
1171 ["Follow Mode" org-agenda-follow-mode
1172 :style toggle
:selected org-agenda-follow-mode
:active t
]
1173 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1175 ["Cycle TODO" org-agenda-todo t
]
1177 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t
]
1178 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t
]
1179 ["Archive subtree" org-agenda-archive t
])
1180 ["Delete subtree" org-agenda-kill t
]
1181 ["Add note" org-agenda-add-note t
]
1183 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1184 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1185 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1186 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1188 ("Tags and Properties"
1189 ["Show all Tags" org-agenda-show-tags t
]
1190 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1191 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1193 ["Column View" org-columns t
])
1195 ["Schedule" org-agenda-schedule t
]
1196 ["Set Deadline" org-agenda-deadline t
]
1198 ["Mark item" org-agenda-action
:active t
:keys
"k m"]
1199 ["Show mark item" org-agenda-action
:active t
:keys
"k v"]
1200 ["Schedule marked item" org-agenda-action
:active t
:keys
"k s"]
1201 ["Set Deadline for marked item" org-agenda-action
:active t
:keys
"k d"]
1203 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1204 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1205 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1207 ["Clock in" org-agenda-clock-in t
]
1208 ["Clock out" org-agenda-clock-out t
]
1209 ["Clock cancel" org-agenda-clock-cancel t
]
1210 ["Goto running clock" org-clock-goto t
])
1212 ["Set Priority" org-agenda-priority t
]
1213 ["Increase Priority" org-agenda-priority-up t
]
1214 ["Decrease Priority" org-agenda-priority-down t
]
1215 ["Show Priority" org-agenda-show-priority t
])
1217 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1218 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1219 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1220 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1221 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1222 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1224 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1227 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1228 :style radio
:selected
(equal org-agenda-ndays
1)]
1229 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1230 :style radio
:selected
(equal org-agenda-ndays
7)]
1231 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1232 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1233 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1234 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1236 ["Show Logbook entries" org-agenda-log-mode
1237 :style toggle
:selected org-agenda-show-log
:active
(org-agenda-check-type nil
'agenda
'timeline
)]
1238 ["Show clock report" org-agenda-clockreport-mode
1239 :style toggle
:selected org-agenda-clockreport-mode
:active
(org-agenda-check-type nil
'agenda
)]
1240 ["Include Diary" org-agenda-toggle-diary
1241 :style toggle
:selected org-agenda-include-diary
:active
(org-agenda-check-type nil
'agenda
)]
1242 ["Use Time Grid" org-agenda-toggle-time-grid
1243 :style toggle
:selected org-agenda-use-time-grid
:active
(org-agenda-check-type nil
'agenda
)])
1244 ["Write view to file" org-write-agenda t
]
1245 ["Rebuild buffer" org-agenda-redo t
]
1246 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1248 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1250 ["Quit" org-agenda-quit t
]
1251 ["Exit and Release Buffers" org-agenda-exit t
]
1256 (defvar org-agenda-allow-remote-undo t
1257 "Non-nil means, allow remote undo from the agenda buffer.")
1258 (defvar org-agenda-undo-list nil
1259 "List of undoable operations in the agenda since last refresh.")
1260 (defvar org-agenda-undo-has-started-in nil
1261 "Buffers that have already seen `undo-start' in the current undo sequence.")
1262 (defvar org-agenda-pending-undo-list nil
1263 "In a series of undo commands, this is the list of remaning undo items.")
1266 (defun org-agenda-undo ()
1267 "Undo a remote editing step in the agenda.
1268 This undoes changes both in the agenda buffer and in the remote buffer
1269 that have been changed along."
1271 (or org-agenda-allow-remote-undo
1272 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1273 (if (not (eq this-command last-command
))
1274 (setq org-agenda-undo-has-started-in nil
1275 org-agenda-pending-undo-list org-agenda-undo-list
))
1276 (if (not org-agenda-pending-undo-list
)
1277 (error "No further undo information"))
1278 (let* ((entry (pop org-agenda-pending-undo-list
))
1279 buf line cmd rembuf
)
1280 (setq cmd
(pop entry
) line
(pop entry
))
1281 (setq rembuf
(nth 2 entry
))
1282 (org-with-remote-undo rembuf
1283 (while (bufferp (setq buf
(pop entry
)))
1285 (with-current-buffer buf
1286 (let ((last-undo-buffer buf
)
1287 (inhibit-read-only t
))
1288 (unless (memq buf org-agenda-undo-has-started-in
)
1289 (push buf org-agenda-undo-has-started-in
)
1290 (make-local-variable 'pending-undo-list
)
1292 (while (and pending-undo-list
1293 (listp pending-undo-list
)
1294 (not (car pending-undo-list
)))
1295 (pop pending-undo-list
))
1298 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1300 (defun org-verify-change-for-undo (l1 l2
)
1301 "Verify that a real change occurred between the undo lists L1 and L2."
1302 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1303 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1308 (defvar org-agenda-restrict nil
)
1309 (defvar org-agenda-restrict-begin
(make-marker))
1310 (defvar org-agenda-restrict-end
(make-marker))
1311 (defvar org-agenda-last-dispatch-buffer nil
)
1312 (defvar org-agenda-overriding-restriction nil
)
1315 (defun org-agenda (arg &optional keys restriction
)
1316 "Dispatch agenda commands to collect entries to the agenda buffer.
1317 Prompts for a command to execute. Any prefix arg will be passed
1318 on to the selected command. The default selections are:
1320 a Call `org-agenda-list' to display the agenda for current day or week.
1321 t Call `org-todo-list' to display the global todo list.
1322 T Call `org-todo-list' to display the global todo list, select only
1323 entries with a specific TODO keyword (the user gets a prompt).
1324 m Call `org-tags-view' to display headlines with tags matching
1325 a condition (the user is prompted for the condition).
1326 M Like `m', but select only TODO entries, no ordinary headlines.
1327 L Create a timeline for the current buffer.
1328 e Export views to associated files.
1330 More commands can be added by configuring the variable
1331 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1332 searches can be pre-defined in this way.
1334 If the current buffer is in Org-mode and visiting a file, you can also
1335 first press `<' once to indicate that the agenda should be temporarily
1336 \(until the next use of \\[org-agenda]) restricted to the current file.
1337 Pressing `<' twice means to restrict to the current subtree or region
1341 (let* ((prefix-descriptions nil
)
1342 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1343 (org-agenda-custom-commands
1344 ;; normalize different versions
1348 (cond ((stringp (cdr x
))
1349 (push x prefix-descriptions
)
1351 ((stringp (nth 1 x
)) x
)
1352 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1353 (t (cons (car x
) (cons "" (cdr x
))))))
1354 org-agenda-custom-commands
)))
1355 (buf (current-buffer))
1356 (bfn (buffer-file-name (buffer-base-buffer)))
1357 entry key type match lprops ans
)
1358 ;; Turn off restriction unless there is an overriding one
1359 (unless org-agenda-overriding-restriction
1360 (put 'org-agenda-files
'org-restrict nil
)
1361 (setq org-agenda-restrict nil
)
1362 (move-marker org-agenda-restrict-begin nil
)
1363 (move-marker org-agenda-restrict-end nil
))
1364 ;; Delete old local properties
1365 (put 'org-agenda-redo-command
'org-lprops nil
)
1366 ;; Remember where this call originated
1367 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1369 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1371 restriction
(cdr ans
)))
1372 ;; Estabish the restriction, if any
1373 (when (and (not org-agenda-overriding-restriction
) restriction
)
1374 (put 'org-agenda-files
'org-restrict
(list bfn
))
1376 ((eq restriction
'region
)
1377 (setq org-agenda-restrict t
)
1378 (move-marker org-agenda-restrict-begin
(region-beginning))
1379 (move-marker org-agenda-restrict-end
(region-end)))
1380 ((eq restriction
'subtree
)
1382 (setq org-agenda-restrict t
)
1383 (org-back-to-heading t
)
1384 (move-marker org-agenda-restrict-begin
(point))
1385 (move-marker org-agenda-restrict-end
1386 (progn (org-end-of-subtree t
)))))))
1388 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1389 ;; For example the todo list should not need it (but does...)
1391 ((setq entry
(assoc keys org-agenda-custom-commands
))
1392 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1394 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1395 (put 'org-agenda-redo-command
'org-lprops lprops
)
1398 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1400 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1402 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1404 (org-let lprops
'(org-agenda-list-stuck-projects
1405 current-prefix-arg
)))
1407 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1408 ((eq type
'tags-todo
)
1409 (org-let lprops
'(org-tags-view '(4) match
)))
1411 (org-let lprops
'(org-todo-list match
)))
1412 ((eq type
'tags-tree
)
1413 (org-check-for-org-mode)
1414 (org-let lprops
'(org-tags-sparse-tree current-prefix-arg match
)))
1415 ((eq type
'todo-tree
)
1416 (org-check-for-org-mode)
1418 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1419 (regexp-quote match
) "\\>"))))
1420 ((eq type
'occur-tree
)
1421 (org-check-for-org-mode)
1422 (org-let lprops
'(org-occur match
)))
1424 (org-let lprops
'(funcall type match
)))
1426 (org-let lprops
'(funcall type match
)))
1427 (t (error "Invalid custom agenda command type %s" type
))))
1428 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1430 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1431 (customize-variable 'org-agenda-custom-commands
))
1432 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1433 ((equal keys
"s") (call-interactively 'org-search-view
))
1434 ((equal keys
"t") (call-interactively 'org-todo-list
))
1435 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1436 ((equal keys
"m") (call-interactively 'org-tags-view
))
1437 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1438 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1440 (unless (org-mode-p)
1441 (error "This is not an Org-mode file"))
1443 (put 'org-agenda-files
'org-restrict
(list bfn
))
1444 (org-call-with-arg 'org-timeline arg
)))
1445 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1446 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1447 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1448 (t (error "Invalid agenda key"))))))
1450 (defun org-agenda-normalize-custom-commands (cmds)
1454 (cond ((stringp (cdr x
)) nil
)
1455 ((stringp (nth 1 x
)) x
)
1456 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1457 (t (cons (car x
) (cons "" (cdr x
))))))
1460 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1461 "The user interface for selecting an agenda command."
1463 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1464 (restrict-ok (and bfn
(org-mode-p)))
1465 (region-p (org-region-active-p))
1466 (custom org-agenda-custom-commands
)
1468 restriction second-time
1469 c entry key type match prefixes rmheader header-end custom1 desc
)
1470 (save-window-excursion
1471 (delete-other-windows)
1472 (org-switch-to-buffer-other-window " *Agenda Commands*")
1474 (insert (eval-when-compile
1477 Press key for an agenda command: < Buffer,subtree/region restriction
1478 -------------------------------- > Remove restriction
1479 a Agenda for current week or day e Export agenda views
1480 t List of all TODO entries T Entries with special TODO kwd
1481 m Match a TAGS query M Like m, but only TODO entries
1482 L Timeline for current buffer # List stuck projects (!=configure)
1483 s Search for keywords C Configure custom agenda commands
1487 (while (string-match
1488 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1490 (setq start
(match-end 0))
1491 (add-text-properties (match-beginning 2) (match-end 2)
1492 '(face bold
) header
))
1494 (setq header-end
(move-marker (make-marker) (point)))
1496 (setq custom1 custom
)
1497 (when (eq rmheader t
)
1499 (re-search-forward ":" nil t
)
1500 (delete-region (match-end 0) (point-at-eol))
1503 (delete-region (match-end 0) (point-at-eol))
1504 (move-marker header-end
(match-end 0)))
1505 (goto-char header-end
)
1506 (delete-region (point) (point-max))
1507 (while (setq entry
(pop custom1
))
1508 (setq key
(car entry
) desc
(nth 1 entry
)
1509 type
(nth 2 entry
) match
(nth 3 entry
))
1510 (if (> (length key
) 1)
1511 (add-to-list 'prefixes
(string-to-char key
))
1515 (org-add-props (copy-sequence key
)
1518 ((string-match "\\S-" desc
) desc
)
1519 ((eq type
'agenda
) "Agenda for current week or day")
1520 ((eq type
'alltodo
) "List of all TODO entries")
1521 ((eq type
'search
) "Word search")
1522 ((eq type
'stuck
) "List of stuck projects")
1523 ((eq type
'todo
) "TODO keyword")
1524 ((eq type
'tags
) "Tags query")
1525 ((eq type
'tags-todo
) "Tags (TODO)")
1526 ((eq type
'tags-tree
) "Tags tree")
1527 ((eq type
'todo-tree
) "TODO kwd tree")
1528 ((eq type
'occur-tree
) "Occur tree")
1529 ((functionp type
) (if (symbolp type
)
1531 "Lambda expression"))
1535 (org-add-props match nil
'face
'org-warning
))
1537 (format "set of %d commands" (length match
)))
1543 (org-add-props (char-to-string x
)
1545 (or (cdr (assoc (concat selstring
(char-to-string x
))
1546 prefix-descriptions
))
1549 (goto-char (point-min))
1550 (when (fboundp 'fit-window-to-buffer
)
1552 (if (not (pos-visible-in-window-p (point-max)))
1553 (fit-window-to-buffer))
1554 (setq second-time t
)
1555 (fit-window-to-buffer)))
1556 (message "Press key for agenda command%s:"
1557 (if (or restrict-ok org-agenda-overriding-restriction
)
1558 (if org-agenda-overriding-restriction
1559 " (restriction lock active)"
1561 (format " (restricted to %s)" restriction
)
1564 (setq c
(read-char-exclusive))
1567 ((assoc (char-to-string c
) custom
)
1568 (setq selstring
(concat selstring
(char-to-string c
)))
1569 (throw 'exit
(cons selstring restriction
)))
1571 (setq selstring
(concat selstring
(char-to-string c
))
1573 rmheader
(or rmheader t
)
1574 custom
(delq nil
(mapcar
1576 (if (or (= (length (car x
)) 1)
1577 (/= (string-to-char (car x
)) c
))
1579 (cons (substring (car x
) 1) (cdr x
))))
1581 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1582 (message "Restriction is only possible in Org-mode buffers")
1585 (org-agenda-remove-restriction-lock 'noupdate
)
1586 (setq restriction
'buffer
))
1588 (org-agenda-remove-restriction-lock 'noupdate
)
1589 (setq restriction
(if region-p
'region
'subtree
)))
1591 (org-agenda-remove-restriction-lock 'noupdate
)
1594 ((eq restriction
'buffer
)
1595 (if region-p
'region
'subtree
))
1596 ((memq restriction
'(subtree region
))
1600 (org-agenda-remove-restriction-lock 'noupdate
)
1601 (setq restriction nil
))
1602 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1603 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1604 ((and (> (length selstring
) 0) (eq c ?\d
))
1606 (org-agenda-get-restriction-and-command prefix-descriptions
))
1608 ((equal c ?q
) (error "Abort"))
1609 (t (error "Invalid key %c" c
))))))))
1611 (defun org-run-agenda-series (name series
)
1612 (org-prepare-agenda name
)
1613 (let* ((org-agenda-multi t
)
1614 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1616 (gprops (nth 1 series
))
1617 match
;; The byte compiler incorrectly complains about this. Keep it!
1619 (while (setq cmd
(pop cmds
))
1620 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1623 (org-let2 gprops lprops
1624 '(call-interactively 'org-agenda-list
)))
1626 (org-let2 gprops lprops
1627 '(call-interactively 'org-todo-list
)))
1629 (org-let2 gprops lprops
1630 '(org-search-view current-prefix-arg match nil
)))
1632 (org-let2 gprops lprops
1633 '(call-interactively 'org-agenda-list-stuck-projects
)))
1635 (org-let2 gprops lprops
1636 '(org-tags-view current-prefix-arg match
)))
1637 ((eq type
'tags-todo
)
1638 (org-let2 gprops lprops
1639 '(org-tags-view '(4) match
)))
1641 (org-let2 gprops lprops
1642 '(org-todo-list match
)))
1644 (org-let2 gprops lprops
1645 '(funcall type match
)))
1646 (t (error "Invalid type in command series"))))
1648 (setq org-agenda-redo-command redo
)
1649 (goto-char (point-min)))
1650 (org-finalize-agenda))
1653 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1654 "Run an agenda command in batch mode and send the result to STDOUT.
1655 If CMD-KEY is a string of length 1, it is used as a key in
1656 `org-agenda-custom-commands' and triggers this command. If it is a
1657 longer string it is used as a tags/todo match string.
1658 Paramters are alternating variable names and values that will be bound
1659 before running the agenda command."
1662 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1663 (if (> (length cmd-key
) 2)
1664 (eval (list 'let
(nreverse pars
)
1665 (list 'org-tags-view nil cmd-key
)))
1666 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1667 (set-buffer org-agenda-buffer-name
)
1668 (princ (org-encode-for-stdout (buffer-string)))))
1670 (defun org-encode-for-stdout (string)
1671 (if (fboundp 'encode-coding-string
)
1672 (encode-coding-string string buffer-file-coding-system
)
1675 (defvar org-agenda-info nil
)
1678 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1679 "Run an agenda command in batch mode and send the result to STDOUT.
1680 If CMD-KEY is a string of length 1, it is used as a key in
1681 `org-agenda-custom-commands' and triggers this command. If it is a
1682 longer string it is used as a tags/todo match string.
1683 Paramters are alternating variable names and values that will be bound
1684 before running the agenda command.
1686 The output gives a line for each selected agenda item. Each
1687 item is a list of comma-separated values, like this:
1689 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1691 category The category of the item
1692 head The headline, without TODO kwd, TAGS and PRIORITY
1693 type The type of the agenda entry, can be
1694 todo selected in TODO match
1695 tagsmatch selected in tags match
1696 diary imported from diary
1697 deadline a deadline on given date
1698 scheduled scheduled on given date
1699 timestamp entry has timestamp on given date
1700 closed entry was closed on given date
1701 upcoming-deadline warning about deadline
1702 past-scheduled forwarded scheduled item
1703 block entry has date block including g. date
1704 todo The todo keyword, if any
1705 tags All tags including inherited ones, separated by colons
1706 date The relevant date, like 2007-2-14
1707 time The time, like 15:00-16:50
1708 extra Sting with extra planning info
1709 priority-l The priority letter if any was given
1710 priority-n The computed numerical priority
1711 agenda-day The day in the agenda where this is listed"
1715 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1716 (push (list 'org-agenda-remove-tags t
) pars
)
1717 (if (> (length cmd-key
) 2)
1718 (eval (list 'let
(nreverse pars
)
1719 (list 'org-tags-view nil cmd-key
)))
1720 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1721 (set-buffer org-agenda-buffer-name
)
1722 (let* ((lines (org-split-string (buffer-string) "\n"))
1724 (while (setq line
(pop lines
))
1726 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1727 (setq org-agenda-info
1728 (org-fix-agenda-info (text-properties-at 0 line
)))
1730 (org-encode-for-stdout
1731 (mapconcat 'org-agenda-export-csv-mapper
1732 '(org-category txt type todo tags date time-of-day extra
1733 priority-letter priority agenda-day
)
1737 (defun org-fix-agenda-info (props)
1738 "Make sure all properties on an agenda item have a canonical form,
1739 so the export commands can easily use it."
1741 (when (setq tmp
(plist-get props
'tags
))
1742 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1743 (when (setq tmp
(plist-get props
'date
))
1744 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1745 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1746 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
1748 (setq tmp
(calendar-date-string tmp
)))
1749 (setq props
(plist-put props
'date tmp
)))
1750 (when (setq tmp
(plist-get props
'day
))
1751 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1752 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1753 (setq tmp
(calendar-date-string tmp
)))
1754 (setq props
(plist-put props
'day tmp
))
1755 (setq props
(plist-put props
'agenda-day tmp
)))
1756 (when (setq tmp
(plist-get props
'txt
))
1757 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
1758 (plist-put props
'priority-letter
(match-string 1 tmp
))
1759 (setq tmp
(replace-match "" t t tmp
)))
1760 (when (and (setq re
(plist-get props
'org-todo-regexp
))
1761 (setq re
(concat "\\`\\.*" re
" ?"))
1762 (string-match re tmp
))
1763 (plist-put props
'todo
(match-string 1 tmp
))
1764 (setq tmp
(replace-match "" t t tmp
)))
1765 (plist-put props
'txt tmp
)))
1768 (defun org-agenda-export-csv-mapper (prop)
1769 (let ((res (plist-get org-agenda-info prop
)))
1774 (t (prin1-to-string res
))))
1775 (while (string-match "," res
)
1776 (setq res
(replace-match ";" t t res
)))
1781 (defun org-store-agenda-views (&rest parameters
)
1783 (eval (list 'org-batch-store-agenda-views
)))
1785 ;; FIXME, why is this a macro?????
1787 (defmacro org-batch-store-agenda-views
(&rest parameters
)
1788 "Run all custom agenda commands that have a file argument."
1789 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
1791 (dir default-directory
)
1792 pars cmd thiscmdkey files opts
)
1794 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1795 (setq pars
(reverse pars
))
1796 (save-window-excursion
1798 (setq cmd
(pop cmds
)
1799 thiscmdkey
(car cmd
)
1802 (if (stringp files
) (setq files
(list files
)))
1804 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1805 (list 'org-agenda nil thiscmdkey
)))
1806 (set-buffer org-agenda-buffer-name
)
1808 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1809 (list 'org-write-agenda
1810 (expand-file-name (pop files
) dir
) t
))))
1811 (and (get-buffer org-agenda-buffer-name
)
1812 (kill-buffer org-agenda-buffer-name
)))))))
1814 (defun org-write-agenda (file &optional nosettings
)
1815 "Write the current buffer (an agenda view) as a file.
1816 Depending on the extension of the file name, plain text (.txt),
1817 HTML (.html or .htm) or Postscript (.ps) is produced.
1818 If the extension is .ics, run icalendar export over all files used
1819 to construct the agenda and limit the export to entries listed in the
1821 If NOSETTINGS is given, do not scope the settings of
1822 `org-agenda-exporter-settings' into the export commands. This is used when
1823 the settings have already been scoped and we do not wish to overrule other,
1824 higher priority settings."
1825 (interactive "FWrite agenda to file: ")
1826 (if (not (file-writable-p file
))
1827 (error "Cannot write agenda to file %s" file
))
1829 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
1830 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
1831 (org-let (if nosettings nil org-agenda-exporter-settings
)
1833 (save-window-excursion
1835 ((string-match "\\.html?\\'" file
)
1836 (set-buffer (htmlize-buffer (current-buffer)))
1838 (when (and org-agenda-export-html-style
1839 (string-match "<style>" org-agenda-export-html-style
))
1840 ;; replace <style> section with org-agenda-export-html-style
1841 (goto-char (point-min))
1842 (kill-region (- (search-forward "<style") 6)
1843 (search-forward "</style>"))
1844 (insert org-agenda-export-html-style
))
1846 (kill-buffer (current-buffer))
1847 (message "HTML written to %s" file
))
1848 ((string-match "\\.ps\\'" file
)
1849 (ps-print-buffer-with-faces file
)
1850 (message "Postscript written to %s" file
))
1851 ((string-match "\\.ics\\'" file
)
1852 (let ((org-agenda-marker-table
1853 (org-create-marker-find-array
1854 (org-agenda-collect-markers)))
1855 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
1856 (org-combined-agenda-icalendar-file file
))
1857 (apply 'org-export-icalendar
'combine
(org-agenda-files))))
1859 (let ((bs (buffer-string)))
1863 (kill-buffer (current-buffer))
1864 (message "Plain text written to %s" file
))))))
1865 (set-buffer org-agenda-buffer-name
)))
1867 (defun org-agenda-collect-markers ()
1868 "Collect the markers pointing to entries in the agenda buffer."
1871 (goto-char (point-min))
1873 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
1874 (get-text-property (point) 'org-marker
)))
1876 (beginning-of-line 2)))
1877 (nreverse markers
)))
1879 (defun org-create-marker-find-array (marker-list)
1880 "Create a alist of files names with all marker positions in that file."
1882 (while (setq m
(pop marker-list
))
1883 (setq p
(marker-position m
)
1884 f
(buffer-file-name (or (buffer-base-buffer
1886 (marker-buffer m
))))
1887 (if (setq a
(assoc f tbl
))
1888 (push (marker-position m
) (cdr a
))
1889 (push (list f p
) tbl
)))
1890 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
1893 (defvar org-agenda-marker-table nil
) ; dyamically scoped parameter
1894 (defun org-check-agenda-marker-table ()
1895 "Check of the current entry is on the marker list."
1896 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
1898 (and (setq a
(assoc file org-agenda-marker-table
))
1901 (org-back-to-heading t
)
1902 (member (point) (cdr a
)))))))
1904 (defun org-check-for-org-mode ()
1905 "Make sure current buffer is in org-mode. Error if not."
1907 (error "Cannot execute org-mode agenda command on buffer in %s."
1910 (defun org-fit-agenda-window ()
1911 "Fit the window to the buffer size."
1912 (and (memq org-agenda-window-setup
'(reorganize-frame))
1913 (fboundp 'fit-window-to-buffer
)
1914 (fit-window-to-buffer
1916 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
1917 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
1919 ;;; Agenda prepare and finalize
1921 (defvar org-agenda-multi nil
) ; dynammically scoped
1922 (defvar org-agenda-buffer-name
"*Org Agenda*")
1923 (defvar org-pre-agenda-window-conf nil
)
1924 (defvar org-agenda-columns-active nil
)
1925 (defvar org-agenda-name nil
)
1926 (defun org-prepare-agenda (&optional name
)
1927 (setq org-todo-keywords-for-agenda nil
)
1928 (setq org-done-keywords-for-agenda nil
)
1929 (if org-agenda-multi
1931 (setq buffer-read-only nil
)
1932 (goto-char (point-max))
1933 (unless (or (bobp) org-agenda-compact-blocks
)
1934 (insert "\n" (make-string (window-width) ?
=) "\n"))
1935 (narrow-to-region (point) (point-max)))
1936 (org-agenda-reset-markers)
1937 (setq org-agenda-contributing-files nil
)
1938 (setq org-agenda-columns-active nil
)
1939 (org-prepare-agenda-buffers (org-agenda-files))
1940 (setq org-todo-keywords-for-agenda
1941 (org-uniquify org-todo-keywords-for-agenda
))
1942 (setq org-done-keywords-for-agenda
1943 (org-uniquify org-done-keywords-for-agenda
))
1944 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
1945 (awin (get-buffer-window abuf
)))
1947 ((equal (current-buffer) abuf
) nil
)
1948 (awin (select-window awin
))
1949 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
1950 ((equal org-agenda-window-setup
'current-window
)
1951 (switch-to-buffer abuf
))
1952 ((equal org-agenda-window-setup
'other-window
)
1953 (org-switch-to-buffer-other-window abuf
))
1954 ((equal org-agenda-window-setup
'other-frame
)
1955 (switch-to-buffer-other-frame abuf
))
1956 ((equal org-agenda-window-setup
'reorganize-frame
)
1957 (delete-other-windows)
1958 (org-switch-to-buffer-other-window abuf
))))
1959 (setq buffer-read-only nil
)
1960 (let ((inhibit-read-only t
)) (erase-buffer))
1962 (and name
(not org-agenda-name
)
1963 (org-set-local 'org-agenda-name name
)))
1964 (setq buffer-read-only nil
))
1966 (defun org-finalize-agenda ()
1967 "Finishing touch for the agenda buffer, called just before displaying it."
1968 (unless org-agenda-multi
1970 (let ((inhibit-read-only t
))
1971 (goto-char (point-min))
1972 (while (org-activate-bracket-links (point-max))
1973 (add-text-properties (match-beginning 0) (match-end 0)
1975 (org-agenda-align-tags)
1976 (unless org-agenda-with-colors
1977 (remove-text-properties (point-min) (point-max) '(face nil
))))
1978 (if (and (boundp 'org-overriding-columns-format
)
1979 org-overriding-columns-format
)
1980 (org-set-local 'org-overriding-columns-format
1981 org-overriding-columns-format
))
1982 (if (and (boundp 'org-agenda-view-columns-initially
)
1983 org-agenda-view-columns-initially
)
1984 (org-agenda-columns))
1985 (when org-agenda-fontify-priorities
1986 (org-fontify-priorities))
1987 (run-hooks 'org-finalize-agenda-hook
)
1988 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
1991 (defun org-fontify-priorities ()
1992 "Make highest priority lines bold, and lowest italic."
1994 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
1995 (org-delete-overlay o
)))
1996 (org-overlays-in (point-min) (point-max)))
1998 (let ((inhibit-read-only t
)
2000 (goto-char (point-min))
2001 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
2002 (setq h
(or (get-char-property (point) 'org-highest-priority
)
2003 org-highest-priority
)
2004 l
(or (get-char-property (point) 'org-lowest-priority
)
2005 org-lowest-priority
)
2006 p
(string-to-char (match-string 1))
2007 b
(match-beginning 0) e
(point-at-eol)
2008 ov
(org-make-overlay b e
))
2011 (cond ((listp org-agenda-fontify-priorities
)
2012 (cdr (assoc p org-agenda-fontify-priorities
)))
2013 ((equal p l
) 'italic
)
2014 ((equal p h
) 'bold
)))
2015 (org-overlay-put ov
'org-type
'org-priority
)))))
2018 (defvar org-agenda-skip-function nil
2019 "Function to be called at each match during agenda construction.
2020 If this function returns nil, the current match should not be skipped.
2021 Otherwise, the function must return a position from where the search
2022 should be continued.
2023 This may also be a Lisp form, it will be evaluated.
2024 Never set this variable using `setq' or so, because then it will apply
2025 to all future agenda commands. Instead, bind it with `let' to scope
2026 it dynamically into the agenda-constructing command. A good way to set
2027 it is through options in org-agenda-custom-commands.")
2029 (defun org-agenda-skip ()
2030 "Throw to `:skip' in places that should be skipped.
2031 Also moves point to the end of the skipped region, so that search can
2032 continue from there."
2033 (let ((p (point-at-bol)) to fp
)
2034 (and org-agenda-skip-archived-trees
2035 (get-text-property p
:org-archived
)
2036 (org-end-of-subtree t
)
2038 (and org-agenda-skip-comment-trees
2039 (get-text-property p
:org-comment
)
2040 (org-end-of-subtree t
)
2042 (if (equal (char-after p
) ?
#) (throw :skip t
))
2043 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
2044 (consp org-agenda-skip-function
))
2045 (setq to
(save-excursion
2048 (funcall org-agenda-skip-function
)
2049 (eval org-agenda-skip-function
))))))
2053 (defvar org-agenda-markers nil
2054 "List of all currently active markers created by `org-agenda'.")
2055 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
2056 "Creation time of the last agenda marker.")
2058 (defun org-agenda-new-marker (&optional pos
)
2059 "Return a new agenda marker.
2060 Org-mode keeps a list of these markers and resets them when they are
2062 (let ((m (copy-marker (or pos
(point)))))
2063 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
2064 (push m org-agenda-markers
)
2067 (defun org-agenda-reset-markers ()
2068 "Reset markers created by `org-agenda'."
2069 (while org-agenda-markers
2070 (move-marker (pop org-agenda-markers
) nil
)))
2072 (defun org-agenda-save-markers-for-cut-and-paste (beg end
)
2073 "Save relative positions of markers in region."
2074 (mapc (lambda (m) (org-check-and-save-marker m beg end
))
2075 org-agenda-markers
))
2079 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
2081 (defun org-timeline (&optional include-all
)
2082 "Show a time-sorted view of the entries in the current org file.
2083 Only entries with a time stamp of today or later will be listed. With
2084 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2085 under the current date.
2086 If the buffer contains an active region, only check the region for
2090 (org-compile-prefix-format 'timeline
)
2091 (org-set-sorting-strategy 'timeline
)
2093 (dotodo include-all
)
2094 (doclosed org-agenda-show-log
)
2095 (entry buffer-file-name
)
2096 (date (calendar-current-date))
2097 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2098 (end (if (org-region-active-p) (region-end) (point-max)))
2099 (day-numbers (org-get-all-dates beg end
'no-ranges
2100 t doclosed
; always include today
2101 org-timeline-show-empty-dates
))
2102 (org-deadline-warning-days 0)
2103 (org-agenda-only-exact-dates t
)
2104 (today (time-to-days (current-time)))
2107 s e rtn d emptyp wd
)
2108 (setq org-agenda-redo-command
2110 (list 'org-switch-to-buffer-other-window
(current-buffer))
2111 (list 'org-timeline
(list 'quote include-all
))))
2113 ;; Remove past dates from the list of dates.
2114 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2115 (if (>= x today
) x nil
))
2117 (org-prepare-agenda (concat "Timeline "
2118 (file-name-nondirectory buffer-file-name
)))
2119 (if doclosed
(push :closed args
))
2120 (push :timestamp args
)
2121 (push :deadline args
)
2122 (push :scheduled args
)
2124 (if dotodo
(push :todo args
))
2125 (while (setq d
(pop day-numbers
))
2126 (if (and (listp d
) (eq (car d
) :omitted
))
2129 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2130 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2131 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2132 (if (and (>= d today
)
2137 (insert (make-string 79 ?-
) "\n")))
2138 (setq date
(calendar-gregorian-from-absolute d
)
2139 wd
(calendar-day-of-week date
))
2141 (setq rtn
(and (not emptyp
)
2142 (apply 'org-agenda-get-day-entries entry
2144 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2147 (if (stringp org-agenda-format-date
)
2148 (format-time-string org-agenda-format-date
2149 (org-time-from-absolute date
))
2150 (funcall org-agenda-format-date date
))
2152 (put-text-property s
(1- (point)) 'face
2153 (if (member wd org-agenda-weekend-days
)
2154 'org-agenda-date-weekend
2156 (put-text-property s
(1- (point)) 'org-date-line t
)
2158 (put-text-property s
(1- (point)) 'org-today t
))
2159 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2160 (put-text-property s
(1- (point)) 'day d
)))))
2161 (goto-char (point-min))
2162 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2164 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2165 (org-finalize-agenda)
2166 (setq buffer-read-only t
)))
2168 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2169 "Return a list of all relevant day numbers from BEG to END buffer positions.
2170 If NO-RANGES is non-nil, include only the start and end dates of a range,
2171 not every single day in the range. If FORCE-TODAY is non-nil, make
2172 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2173 inactive time stamps (those in square brackets) are included.
2174 When EMPTY is non-nil, also include days without any entries."
2176 (if pre-re pre-re
"")
2177 (if inactive org-ts-regexp-both org-ts-regexp
)))
2178 dates dates1 date day day1 day2 ts1 ts2
)
2180 (setq dates
(list (time-to-days (current-time)))))
2183 (while (re-search-forward re end t
)
2184 (setq day
(time-to-days (org-time-string-to-time
2185 (substring (match-string 1) 0 10))))
2186 (or (memq day dates
) (push day dates
)))
2189 (while (re-search-forward org-tr-regexp end t
)
2190 (setq ts1
(substring (match-string 1) 0 10)
2191 ts2
(substring (match-string 2) 0 10)
2192 day1
(time-to-days (org-time-string-to-time ts1
))
2193 day2
(time-to-days (org-time-string-to-time ts2
)))
2194 (while (< (setq day1
(1+ day1
)) day2
)
2195 (or (memq day1 dates
) (push day1 dates
)))))
2196 (setq dates
(sort dates
'<))
2198 (while (setq day
(pop dates
))
2199 (setq day2
(car dates
))
2201 (when (and day2 empty
)
2202 (if (or (eq empty t
)
2203 (and (numberp empty
) (<= (- day2 day
) empty
)))
2204 (while (< (setq day
(1+ day
)) day2
)
2205 (push (list day
) dates1
))
2206 (push (cons :omitted
(- day2 day
)) dates1
))))
2207 (setq dates
(nreverse dates1
)))
2210 ;;; Agenda Daily/Weekly
2212 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2213 (defvar org-agenda-start-day nil
) ; dynamically scoped parameter
2214 (defvar org-agenda-last-arguments nil
2215 "The arguments of the previous call to org-agenda")
2216 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2217 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2218 (defvar org-include-all-loc nil
) ; local variable
2219 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2222 (defun org-agenda-list (&optional include-all start-day ndays
)
2223 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2224 The view will be for the current day or week, but from the overview buffer
2225 you will be able to go to other days/weeks.
2227 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2228 all unfinished TODO items will also be shown, before the agenda.
2229 This feature is considered obsolete, please use the TODO list or a block
2232 With a numeric prefix argument in an interactive call, the agenda will
2233 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2234 the number of days. NDAYS defaults to `org-agenda-ndays'.
2236 START-DAY defaults to TODAY, or to the most recent match for the weekday
2237 given in `org-agenda-start-on-weekday'."
2239 (if (and (integerp include-all
) (> include-all
0))
2240 (setq ndays include-all include-all nil
))
2241 (setq ndays
(or ndays org-agenda-ndays
)
2242 start-day
(or start-day org-agenda-start-day
))
2243 (if org-agenda-overriding-arguments
2244 (setq include-all
(car org-agenda-overriding-arguments
)
2245 start-day
(nth 1 org-agenda-overriding-arguments
)
2246 ndays
(nth 2 org-agenda-overriding-arguments
)))
2247 (if (stringp start-day
)
2248 ;; Convert to an absolute day number
2249 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2250 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2251 (org-compile-prefix-format 'agenda
)
2252 (org-set-sorting-strategy 'agenda
)
2254 (let* ((org-agenda-start-on-weekday
2255 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2256 org-agenda-start-on-weekday nil
))
2257 (thefiles (org-agenda-files))
2259 (today (time-to-days
2260 (time-subtract (current-time)
2261 (list 0 (* 3600 org-extend-today-until
) 0))))
2262 (sd (or start-day today
))
2263 (start (if (or (null org-agenda-start-on-weekday
)
2264 (< org-agenda-ndays
7))
2266 (let* ((nt (calendar-day-of-week
2267 (calendar-gregorian-from-absolute sd
)))
2268 (n1 org-agenda-start-on-weekday
)
2270 (- sd
(+ (if (< d
0) 7 0) d
)))))
2271 (day-numbers (list start
))
2273 (inhibit-redisplay (not debug-on-error
))
2274 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2275 clocktable-start clocktable-end
)
2276 (setq org-agenda-redo-command
2277 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2278 ;; Make the list of days
2279 (setq ndays
(or ndays org-agenda-ndays
)
2282 (push (1+ (car day-numbers
)) day-numbers
)
2283 (setq ndays
(1- ndays
)))
2284 (setq day-numbers
(nreverse day-numbers
))
2285 (setq clocktable-start
(car day-numbers
)
2286 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2287 (org-prepare-agenda "Day/Week")
2288 (org-set-local 'org-starting-day
(car day-numbers
))
2289 (org-set-local 'org-include-all-loc include-all
)
2290 (org-set-local 'org-agenda-span
2291 (org-agenda-ndays-to-span nd
))
2292 (when (and (or include-all org-agenda-include-all-todo
)
2293 (member today day-numbers
))
2294 (setq files thefiles
2296 (while (setq file
(pop files
))
2298 (org-check-agenda-file file
)
2299 (setq date
(calendar-gregorian-from-absolute today
)
2300 rtn
(org-agenda-get-day-entries
2302 (setq rtnall
(append rtnall rtn
))))
2304 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2305 (add-text-properties (point-min) (1- (point))
2306 (list 'face
'org-agenda-structure
))
2307 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2308 (unless org-agenda-compact-blocks
2309 (let* ((d1 (car day-numbers
))
2310 (d2 (org-last day-numbers
))
2311 (w1 (org-days-to-iso-week d1
))
2312 (w2 (org-days-to-iso-week d2
)))
2314 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2316 (if (< (- d2 d1
) 350)
2318 (format " (W%02d)" w1
)
2319 (format " (W%02d-W%02d)" w1 w2
))
2322 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2324 (while (setq d
(pop day-numbers
))
2325 (setq date
(calendar-gregorian-from-absolute d
)
2326 wd
(calendar-day-of-week date
)
2328 (if (or (setq todayp
(= d today
))
2329 (and (not start-pos
) (= d sd
)))
2330 (setq start-pos
(point))
2331 (if (and start-pos
(not end-pos
))
2332 (setq end-pos
(point))))
2333 (setq files thefiles
2335 (while (setq file
(pop files
))
2337 (org-check-agenda-file file
)
2338 (if org-agenda-show-log
2339 (setq rtn
(org-agenda-get-day-entries
2341 :deadline
:scheduled
:timestamp
:sexp
:closed
))
2342 (setq rtn
(org-agenda-get-day-entries
2344 :deadline
:scheduled
:sexp
:timestamp
)))
2345 (setq rtnall
(append rtnall rtn
))))
2346 (if org-agenda-include-diary
2348 (require 'diary-lib
)
2349 (setq rtn
(org-get-entries-from-diary date
))
2350 (setq rtnall
(append rtnall rtn
))))
2351 (if (or rtnall org-agenda-show-all-dates
)
2353 (setq day-cnt
(1+ day-cnt
))
2355 (if (stringp org-agenda-format-date
)
2356 (format-time-string org-agenda-format-date
2357 (org-time-from-absolute date
))
2358 (funcall org-agenda-format-date date
))
2360 (put-text-property s
(1- (point)) 'face
2361 (if (member wd org-agenda-weekend-days
)
2362 'org-agenda-date-weekend
2364 (put-text-property s
(1- (point)) 'org-date-line t
)
2365 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2366 (if todayp
(put-text-property s
(1- (point)) 'org-today t
))
2368 (org-finalize-agenda-entries
2369 (org-agenda-add-time-grid-maybe
2372 (put-text-property s
(1- (point)) 'day d
)
2373 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2374 (when (and org-agenda-clockreport-mode clocktable-start
)
2375 (let ((org-agenda-files (org-agenda-files))
2376 ;; the above line is to ensure the restricted range!
2377 (p org-agenda-clockreport-parameter-plist
)
2379 (setq p
(org-plist-delete p
:block
))
2380 (setq p
(plist-put p
:tstart clocktable-start
))
2381 (setq p
(plist-put p
:tend clocktable-end
))
2382 (setq p
(plist-put p
:scope
'agenda
))
2383 (setq tbl
(apply 'org-get-clocktable p
))
2385 (goto-char (point-min))
2386 (org-fit-agenda-window)
2387 (unless (and (pos-visible-in-window-p (point-min))
2388 (pos-visible-in-window-p (point-max)))
2389 (goto-char (1- (point-max)))
2391 (if (not (pos-visible-in-window-p (or start-pos
1)))
2393 (goto-char (or start-pos
1))
2395 (goto-char (or start-pos
1))
2396 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2397 (org-finalize-agenda)
2398 (setq buffer-read-only t
)
2401 (defun org-agenda-ndays-to-span (n)
2402 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2404 ;;; Agenda word search
2406 (defvar org-agenda-search-history nil
)
2407 (defvar org-todo-only nil
)
2409 (defvar org-search-syntax-table nil
2410 "Special syntax table for org-mode search.
2411 In this table, we have single quotes not as word constituents, to
2412 that when \"+Ameli\" is searchd as a work, it will also match \"Ameli's\"")
2414 (defun org-search-syntax-table ()
2415 (unless org-search-syntax-table
2416 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2417 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2418 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2419 org-search-syntax-table
)
2422 (defun org-search-view (&optional todo-only string edit-at
)
2423 "Show all entries that contain words or regular expressions.
2424 If the first character of the search string is an asterisks,
2425 search only the headlines.
2427 With optional prefix argument TODO-ONLY, only consider entries that are
2428 TODO entries. The argument STRING can be used to pass a default search
2429 string into this function. If EDIT-AT is non-nil, it means that the
2430 user should get a chance to edit this string, with cursor at position
2433 The search string is broken into \"words\" by splitting at whitespace.
2434 The individual words are then interpreted as a boolean expression with
2435 logical AND. Words prefixed with a minus must not occur in the entry.
2436 Words without a prefix or prefixed with a plus must occur in the entry.
2437 Matching is case-insensitive and the words are enclosed by word delimiters.
2439 Words enclosed by curly braces are interpreted as regular expressions
2440 that must or must not match in the entry.
2442 If the search string starts with an asterisk, search only in headlines.
2443 If (possibly after the leading star) the search string starts with an
2444 exclamation mark, this also means to look at TODO entries only, an effect
2445 that can also be achieved with a prefix argument.
2447 This command searches the agenda files, and in addition the files listed
2448 in `org-agenda-text-search-extra-files'."
2450 (org-compile-prefix-format 'search
)
2451 (org-set-sorting-strategy 'search
)
2452 (org-prepare-agenda "SEARCH")
2453 (let* ((props (list 'face nil
2454 'done-face
'org-done
2455 'org-not-done-regexp org-not-done-regexp
2456 'org-todo-regexp org-todo-regexp
2457 'org-complex-heading-regexp org-complex-heading-regexp
2458 'mouse-face
'highlight
2459 'keymap org-agenda-keymap
2460 'help-echo
(format "mouse-2 or RET jump to location")))
2461 regexp rtn rtnall files file pos
2462 marker priority category tags c neg re
2463 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2464 (unless (and (not edit-at
)
2466 (string-match "\\S-" string
))
2467 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2469 ((integerp edit-at
) (cons string edit-at
))
2471 'org-agenda-search-history
)))
2472 (org-set-local 'org-todo-only todo-only
)
2473 (setq org-agenda-redo-command
2474 (list 'org-search-view
(if todo-only t nil
) string
2475 '(if current-prefix-arg
1 nil
)))
2476 (setq org-agenda-query-string string
)
2478 (if (equal (string-to-char string
) ?
*)
2480 words
(substring string
1))
2481 (setq words string
))
2482 (when (equal (string-to-char words
) ?
!)
2484 words
(substring words
1)))
2485 (setq words
(org-split-string words
))
2487 (setq c
(string-to-char w
))
2489 (setq neg t w
(substring w
1))
2491 (setq neg nil w
(substring w
1))
2493 (if (string-match "\\`{.*}\\'" w
)
2494 (setq re
(substring w
1 -
1))
2495 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2496 (if neg
(push re regexps-
) (push re regexps
+)))
2498 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2500 (setq regexp
(concat "^" org-outline-regexp
))
2501 (setq regexp
(pop regexps
+))
2502 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2504 (setq files
(org-agenda-files))
2505 (when (eq (car org-agenda-text-search-extra-files
) 'agenda-archives
)
2506 (pop org-agenda-text-search-extra-files
)
2507 (setq files
(org-add-archive-files files
)))
2508 (setq files
(append files org-agenda-text-search-extra-files
)
2510 (while (setq file
(pop files
))
2513 (org-check-agenda-file file
)
2514 (setq buffer
(if (file-exists-p file
)
2515 (org-get-agenda-file-buffer file
)
2516 (error "No such file %s" file
)))
2518 ;; If file does not exist, make sure an error message is sent
2519 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2521 (with-current-buffer buffer
2522 (with-syntax-table (org-search-syntax-table)
2523 (unless (org-mode-p)
2524 (error "Agenda file %s is not in `org-mode'" file
))
2525 (let ((case-fold-search t
))
2528 (if org-agenda-restrict
2529 (narrow-to-region org-agenda-restrict-begin
2530 org-agenda-restrict-end
)
2532 (goto-char (point-min))
2533 (unless (or (org-on-heading-p)
2534 (outline-next-heading))
2535 (throw 'nextfile t
))
2536 (goto-char (max (point-min) (1- (point))))
2537 (while (re-search-forward regexp nil t
)
2538 (org-back-to-heading t
)
2539 (skip-chars-forward "* ")
2540 (setq beg
(point-at-bol)
2542 end
(progn (outline-next-heading) (point)))
2546 (setq str
(buffer-substring-no-properties
2548 (if hdl-only
(point-at-eol) end
)))
2549 (mapc (lambda (wr) (when (string-match wr str
)
2550 (goto-char (1- end
))
2553 (mapc (lambda (wr) (unless (string-match wr str
)
2554 (goto-char (1- end
))
2557 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
2561 (setq marker
(org-agenda-new-marker (point))
2562 category
(org-get-category)
2563 tags
(org-get-tags-at (point))
2564 txt
(org-format-agenda-item
2566 (buffer-substring-no-properties
2567 beg1
(point-at-eol))
2569 (org-add-props txt props
2570 'org-marker marker
'org-hd-marker marker
2571 'org-todo-regexp org-todo-regexp
2572 'org-complex-heading-regexp org-complex-heading-regexp
2573 'priority
1000 'org-category category
2576 (goto-char (1- end
))))))))))
2577 (setq rtn
(nreverse ee
))
2578 (setq rtnall
(append rtnall rtn
)))
2579 (if org-agenda-overriding-header
2580 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2581 nil
'face
'org-agenda-structure
) "\n")
2582 (insert "Search words: ")
2583 (add-text-properties (point-min) (1- (point))
2584 (list 'face
'org-agenda-structure
))
2586 (insert string
"\n")
2587 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2589 (unless org-agenda-multi
2590 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
2591 (add-text-properties pos
(1- (point))
2592 (list 'face
'org-agenda-structure
))))
2594 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2595 (goto-char (point-min))
2596 (org-fit-agenda-window)
2597 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
2598 (org-finalize-agenda)
2599 (setq buffer-read-only t
)))
2601 ;;; Agenda TODO list
2603 (defvar org-select-this-todo-keyword nil
)
2604 (defvar org-last-arg nil
)
2607 (defun org-todo-list (arg)
2608 "Show all TODO entries from all agenda file in a single list.
2609 The prefix arg can be used to select a specific TODO keyword and limit
2610 the list to these. When using \\[universal-argument], you will be prompted
2611 for a keyword. A numeric prefix directly selects the Nth keyword in
2612 `org-todo-keywords-1'."
2615 (org-compile-prefix-format 'todo
)
2616 (org-set-sorting-strategy 'todo
)
2617 (org-prepare-agenda "TODO")
2618 (let* ((today (time-to-days (current-time)))
2619 (date (calendar-gregorian-from-absolute today
))
2620 (kwds org-todo-keywords-for-agenda
)
2621 (completion-ignore-case t
)
2622 (org-select-this-todo-keyword
2623 (if (stringp arg
) arg
2624 (and arg
(integerp arg
) (> arg
0)
2625 (nth (1- arg
) kwds
))))
2626 rtn rtnall files file pos
)
2627 (when (equal arg
'(4))
2628 (setq org-select-this-todo-keyword
2629 (completing-read "Keyword (or KWD1|K2D2|...): "
2630 (mapcar 'list kwds
) nil nil
)))
2631 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
2632 (org-set-local 'org-last-arg arg
)
2633 (setq org-agenda-redo-command
2634 '(org-todo-list (or current-prefix-arg org-last-arg
)))
2635 (setq files
(org-agenda-files)
2637 (while (setq file
(pop files
))
2639 (org-check-agenda-file file
)
2640 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
2641 (setq rtnall
(append rtnall rtn
))))
2642 (if org-agenda-overriding-header
2643 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2644 nil
'face
'org-agenda-structure
) "\n")
2645 (insert "Global list of TODO items of type: ")
2646 (add-text-properties (point-min) (1- (point))
2647 (list 'face
'org-agenda-structure
))
2649 (insert (or org-select-this-todo-keyword
"ALL") "\n")
2650 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2652 (unless org-agenda-multi
2653 (insert "Available with `N r': (0)ALL")
2656 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
2657 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
2662 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2664 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2665 (goto-char (point-min))
2666 (org-fit-agenda-window)
2667 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
2668 (org-finalize-agenda)
2669 (setq buffer-read-only t
)))
2671 ;;; Agenda tags match
2674 (defun org-tags-view (&optional todo-only match
)
2675 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
2676 The prefix arg TODO-ONLY limits the search to TODO entries."
2678 (org-compile-prefix-format 'tags
)
2679 (org-set-sorting-strategy 'tags
)
2680 (let* ((org-tags-match-list-sublevels
2681 (if todo-only t org-tags-match-list-sublevels
))
2682 (completion-ignore-case t
)
2683 rtn rtnall files file pos matcher
2685 (setq matcher
(org-make-tags-matcher match
)
2686 match
(car matcher
) matcher
(cdr matcher
))
2687 (org-prepare-agenda (concat "TAGS " match
))
2688 (setq org-agenda-query-string match
)
2689 (setq org-agenda-redo-command
2690 (list 'org-tags-view
(list 'quote todo-only
)
2691 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
2692 (setq files
(org-agenda-files)
2694 (while (setq file
(pop files
))
2696 (org-check-agenda-file file
)
2697 (setq buffer
(if (file-exists-p file
)
2698 (org-get-agenda-file-buffer file
)
2699 (error "No such file %s" file
)))
2701 ;; If file does not exist, merror message to agenda
2703 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
2704 rtnall
(append rtnall rtn
))
2705 (with-current-buffer buffer
2706 (unless (org-mode-p)
2707 (error "Agenda file %s is not in `org-mode'" file
))
2710 (if org-agenda-restrict
2711 (narrow-to-region org-agenda-restrict-begin
2712 org-agenda-restrict-end
)
2714 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
2715 (setq rtnall
(append rtnall rtn
))))))))
2716 (if org-agenda-overriding-header
2717 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2718 nil
'face
'org-agenda-structure
) "\n")
2719 (insert "Headlines with TAGS match: ")
2720 (add-text-properties (point-min) (1- (point))
2721 (list 'face
'org-agenda-structure
))
2724 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2726 (unless org-agenda-multi
2727 (insert "Press `C-u r' to search again with new search string\n"))
2728 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2730 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2731 (goto-char (point-min))
2732 (org-fit-agenda-window)
2733 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
2734 (org-finalize-agenda)
2735 (setq buffer-read-only t
)))
2737 ;;; Agenda Finding stuck projects
2739 (defvar org-agenda-skip-regexp nil
2740 "Regular expression used in skipping subtrees for the agenda.
2741 This is basically a temporary global variable that can be set and then
2742 used by user-defined selections using `org-agenda-skip-function'.")
2744 (defvar org-agenda-overriding-header nil
2745 "When this is set during todo and tags searches, will replace header.")
2747 (defun org-agenda-skip-subtree-when-regexp-matches ()
2748 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
2749 If yes, it returns the end position of this tree, causing agenda commands
2750 to skip this subtree. This is a function that can be put into
2751 `org-agenda-skip-function' for the duration of a command."
2752 (let ((end (save-excursion (org-end-of-subtree t
)))
2755 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
2758 (defun org-agenda-skip-entry-if (&rest conditions
)
2759 "Skip entry if any of CONDITIONS is true.
2760 See `org-agenda-skip-if' for details."
2761 (org-agenda-skip-if nil conditions
))
2763 (defun org-agenda-skip-subtree-if (&rest conditions
)
2764 "Skip entry if any of CONDITIONS is true.
2765 See `org-agenda-skip-if' for details."
2766 (org-agenda-skip-if t conditions
))
2768 (defun org-agenda-skip-if (subtree conditions
)
2769 "Checks current entity for CONDITIONS.
2770 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
2771 the entry, i.e. the text before the next heading is checked.
2773 CONDITIONS is a list of symbols, boolean OR is used to combine the results
2774 from different tests. Valid conditions are:
2776 scheduled Check if there is a scheduled cookie
2777 notscheduled Check if there is no scheduled cookie
2778 deadline Check if there is a deadline
2779 notdeadline Check if there is no deadline
2780 regexp Check if regexp matches
2781 notregexp Check if regexp does not match.
2783 The regexp is taken from the conditions list, it must come right after
2784 the `regexp' or `notregexp' element.
2786 If any of these conditions is met, this function returns the end point of
2787 the entity, causing the search to continue from there. This is a function
2788 that can be put into `org-agenda-skip-function' for the duration of a command."
2790 (org-back-to-heading t
)
2793 (progn (org-end-of-subtree t
) (point))
2794 (progn (outline-next-heading) (1- (point)))))
2798 (and (memq 'scheduled conditions
)
2799 (re-search-forward org-scheduled-time-regexp end t
))
2800 (and (memq 'notscheduled conditions
)
2801 (not (re-search-forward org-scheduled-time-regexp end t
)))
2802 (and (memq 'deadline conditions
)
2803 (re-search-forward org-deadline-time-regexp end t
))
2804 (and (memq 'notdeadline conditions
)
2805 (not (re-search-forward org-deadline-time-regexp end t
)))
2806 (and (setq m
(memq 'regexp conditions
))
2808 (re-search-forward (nth 1 m
) end t
))
2809 (and (setq m
(memq 'notregexp conditions
))
2811 (not (re-search-forward (nth 1 m
) end t
))))
2815 (defun org-agenda-list-stuck-projects (&rest ignore
)
2816 "Create agenda view for projects that are stuck.
2817 Stuck projects are project that have no next actions. For the definitions
2818 of what a project is and how to check if it stuck, customize the variable
2819 `org-stuck-projects'.
2820 MATCH is being ignored."
2822 (let* ((org-agenda-skip-function 'org-agenda-skip-subtree-when-regexp-matches
)
2823 ;; We could have used org-agenda-skip-if here.
2824 (org-agenda-overriding-header "List of stuck projects: ")
2825 (matcher (nth 0 org-stuck-projects
))
2826 (todo (nth 1 org-stuck-projects
))
2827 (todo-wds (if (member "*" todo
)
2829 (org-prepare-agenda-buffers (org-agenda-files))
2831 org-done-keywords-for-agenda
2832 (copy-sequence org-todo-keywords-for-agenda
)))
2834 (todo-re (concat "^\\*+[ \t]+\\("
2835 (mapconcat 'identity todo-wds
"\\|")
2837 (tags (nth 2 org-stuck-projects
))
2838 (tags-re (if (member "*" tags
)
2839 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
2840 (concat "^\\*+ .*:\\("
2841 (mapconcat 'identity tags
"\\|")
2842 (org-re "\\):[[:alnum:]_@:]*[ \t]*$"))))
2843 (gen-re (nth 3 org-stuck-projects
))
2849 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
2851 (setq org-agenda-skip-regexp
2853 (mapconcat 'identity re-list
"\\|")
2854 (error "No information how to identify unstuck projects")))
2855 (org-tags-view nil matcher
)
2856 (with-current-buffer org-agenda-buffer-name
2857 (setq org-agenda-redo-command
2858 '(org-agenda-list-stuck-projects
2859 (or current-prefix-arg org-last-arg
))))))
2861 ;;; Diary integration
2863 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
2864 (defvar list-diary-entries-hook
)
2866 (defun org-get-entries-from-diary (date)
2867 "Get the (Emacs Calendar) diary entries for DATE."
2868 (require 'diary-lib
)
2869 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
2870 (fancy-diary-buffer diary-fancy-buffer
)
2871 (diary-display-hook '(fancy-diary-display))
2873 (list-diary-entries-hook
2874 (cons 'org-diary-default-entry list-diary-entries-hook
))
2875 (diary-file-name-prefix-function nil
) ; turn this feature off
2876 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
2878 (org-disable-agenda-to-diary t
))
2880 (save-window-excursion
2881 (funcall (if (fboundp 'diary-list-entries
)
2882 'diary-list-entries
'list-diary-entries
)
2884 (if (not (get-buffer diary-fancy-buffer
))
2886 (with-current-buffer diary-fancy-buffer
2887 (setq buffer-read-only nil
)
2888 (if (zerop (buffer-size))
2891 ;; Omit the date and other unnecessary stuff
2892 (org-agenda-cleanup-fancy-diary)
2893 ;; Add prefix to each line and extend the text properties
2894 (if (zerop (buffer-size))
2896 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
2897 (set-buffer-modified-p nil
)
2898 (kill-buffer diary-fancy-buffer
)))
2900 (setq entries
(org-split-string entries
"\n"))
2904 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
2905 ;; Extend the text properties to the beginning of the line
2906 (org-add-props x
(text-properties-at (1- (length x
)) x
)
2907 'type
"diary" 'date date
))
2910 (defun org-agenda-cleanup-fancy-diary ()
2911 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
2912 This gets rid of the date, the underline under the date, and
2913 the dummy entry installed by `org-mode' to ensure non-empty diary for each
2914 date. It also removes lines that contain only whitespace."
2915 (goto-char (point-min))
2916 (if (looking-at ".*?:[ \t]*")
2919 (re-search-forward "\n=+$" nil t
)
2921 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
2922 (re-search-forward "\n=+$" nil t
)
2923 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
2924 (goto-char (point-min))
2925 (while (re-search-forward "^ +\n" nil t
)
2927 (goto-char (point-min))
2928 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
2929 (replace-match "")))
2931 ;; Make sure entries from the diary have the right text properties.
2932 (eval-after-load "diary-lib"
2933 '(if (boundp 'diary-modify-entry-list-string-function
)
2934 ;; We can rely on the hook, nothing to do
2936 ;; Hook not avaiable, must use advice to make this work
2937 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
2938 "Make the position visible."
2939 (if (and org-disable-agenda-to-diary
;; called from org-agenda
2942 (setq string
(org-modify-diary-entry-string string
))))))
2944 (defun org-modify-diary-entry-string (string)
2945 "Add text properties to string, allowing org-mode to act on it."
2946 (org-add-props string nil
2947 'mouse-face
'highlight
2948 'keymap org-agenda-keymap
2949 'help-echo
(if buffer-file-name
2950 (format "mouse-2 or RET jump to diary file %s"
2951 (abbreviate-file-name buffer-file-name
))
2953 'org-agenda-diary-link t
2954 'org-marker
(org-agenda-new-marker (point-at-bol))))
2956 (defun org-diary-default-entry ()
2957 "Add a dummy entry to the diary.
2958 Needed to avoid empty dates which mess up holiday display."
2959 ;; Catch the error if dealing with the new add-to-diary-alist
2960 (when org-disable-agenda-to-diary
2962 (org-add-to-diary-list original-date
"Org-mode dummy" "")
2964 (org-add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
2966 (defun org-add-to-diary-list (&rest args
)
2967 (if (fboundp 'diary-add-to-list
)
2968 (apply 'diary-add-to-list args
)
2969 (apply 'add-to-diary-list args
)))
2972 (defun org-diary (&rest args
)
2973 "Return diary information from org-files.
2974 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
2975 It accesses org files and extracts information from those files to be
2976 listed in the diary. The function accepts arguments specifying what
2977 items should be listed. The following arguments are allowed:
2979 :timestamp List the headlines of items containing a date stamp or
2980 date range matching the selected date. Deadlines will
2981 also be listed, on the expiration day.
2983 :sexp List entries resulting from diary-like sexps.
2985 :deadline List any deadlines past due, or due within
2986 `org-deadline-warning-days'. The listing occurs only
2987 in the diary for *today*, not at any other date. If
2988 an entry is marked DONE, it is no longer listed.
2990 :scheduled List all items which are scheduled for the given date.
2991 The diary for *today* also contains items which were
2992 scheduled earlier and are not yet marked DONE.
2994 :todo List all TODO items from the org-file. This may be a
2995 long list - so this is not turned on by default.
2996 Like deadlines, these entries only show up in the
2997 diary for *today*, not at any other date.
2999 The call in the diary file should look like this:
3001 &%%(org-diary) ~/path/to/some/orgfile.org
3003 Use a separate line for each org file to check. Or, if you omit the file name,
3004 all files listed in `org-agenda-files' will be checked automatically:
3008 If you don't give any arguments (as in the example above), the default
3009 arguments (:deadline :scheduled :timestamp :sexp) are used.
3010 So the example above may also be written as
3012 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3014 The function expects the lisp variables `entry' and `date' to be provided
3015 by the caller, because this is how the calendar works. Don't use this
3016 function from a program - use `org-agenda-get-day-entries' instead."
3017 (when (> (- (time-to-seconds (current-time))
3018 org-agenda-last-marker-time
)
3020 (org-agenda-reset-markers))
3021 (org-compile-prefix-format 'agenda
)
3022 (org-set-sorting-strategy 'agenda
)
3023 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3024 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
3026 (org-agenda-files t
)))
3028 (org-prepare-agenda-buffers files
)
3029 ;; If this is called during org-agenda, don't return any entries to
3030 ;; the calendar. Org Agenda will list these entries itself.
3031 (if org-disable-agenda-to-diary
(setq files nil
))
3032 (while (setq file
(pop files
))
3033 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
3034 (setq results
(append results rtn
)))
3036 (concat (org-finalize-agenda-entries results
) "\n"))))
3038 ;;; Agenda entry finders
3040 (defun org-agenda-get-day-entries (file date
&rest args
)
3041 "Does the work for `org-diary' and `org-agenda'.
3042 FILE is the path to a file to be checked for entries. DATE is date like
3043 the one returned by `calendar-current-date'. ARGS are symbols indicating
3044 which kind of entries should be extracted. For details about these, see
3045 the documentation of `org-diary'."
3046 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3047 (let* ((org-startup-folded nil
)
3048 (org-startup-align-all-tables nil
)
3049 (buffer (if (file-exists-p file
)
3050 (org-get-agenda-file-buffer file
)
3051 (error "No such file %s" file
)))
3054 ;; If file does not exist, make sure an error message ends up in diary
3055 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3056 (with-current-buffer buffer
3057 (unless (org-mode-p)
3058 (error "Agenda file %s is not in `org-mode'" file
))
3059 (let ((case-fold-search nil
))
3062 (if org-agenda-restrict
3063 (narrow-to-region org-agenda-restrict-begin
3064 org-agenda-restrict-end
)
3066 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3067 (while (setq arg
(pop args
))
3069 ((and (eq arg
:todo
)
3070 (equal date
(calendar-current-date)))
3071 (setq rtn
(org-agenda-get-todos))
3072 (setq results
(append results rtn
)))
3073 ((eq arg
:timestamp
)
3074 (setq rtn
(org-agenda-get-blocks))
3075 (setq results
(append results rtn
))
3076 (setq rtn
(org-agenda-get-timestamps))
3077 (setq results
(append results rtn
)))
3079 (setq rtn
(org-agenda-get-sexps))
3080 (setq results
(append results rtn
)))
3081 ((eq arg
:scheduled
)
3082 (setq rtn
(org-agenda-get-scheduled))
3083 (setq results
(append results rtn
)))
3085 (setq rtn
(org-agenda-get-closed))
3086 (setq results
(append results rtn
)))
3088 (setq rtn
(org-agenda-get-deadlines))
3089 (setq results
(append results rtn
))))))))
3092 (defun org-agenda-get-todos ()
3093 "Return the TODO information for agenda display."
3094 (let* ((props (list 'face nil
3095 'done-face
'org-done
3096 'org-not-done-regexp org-not-done-regexp
3097 'org-todo-regexp org-todo-regexp
3098 'org-complex-heading-regexp org-complex-heading-regexp
3099 'mouse-face
'highlight
3100 'keymap org-agenda-keymap
3102 (format "mouse-2 or RET jump to org file %s"
3103 (abbreviate-file-name buffer-file-name
))))
3104 (regexp (concat "^\\*+[ \t]+\\("
3105 (if org-select-this-todo-keyword
3106 (if (equal org-select-this-todo-keyword
"*")
3109 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3111 org-not-done-regexp
)
3113 marker priority category tags
3115 (goto-char (point-min))
3116 (while (re-search-forward regexp nil t
)
3120 (setq beg
(point) end
(progn (outline-next-heading) (point)))
3121 (when (or (and org-agenda-todo-ignore-with-date
(goto-char beg
)
3122 (re-search-forward org-ts-regexp end t
))
3123 (and org-agenda-todo-ignore-scheduled
(goto-char beg
)
3124 (re-search-forward org-scheduled-time-regexp end t
))
3125 (and org-agenda-todo-ignore-deadlines
(goto-char beg
)
3126 (re-search-forward org-deadline-time-regexp end t
)
3127 (org-deadline-close (match-string 1))))
3128 (goto-char (1+ beg
))
3129 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3133 (goto-char (match-beginning 1))
3134 (setq marker
(org-agenda-new-marker (match-beginning 0))
3135 category
(org-get-category)
3136 tags
(org-get-tags-at (point))
3137 txt
(org-format-agenda-item "" (match-string 1) category tags
)
3138 priority
(1+ (org-get-priority txt
)))
3139 (org-add-props txt props
3140 'org-marker marker
'org-hd-marker marker
3141 'priority priority
'org-category category
3144 (if org-agenda-todo-list-sublevels
3145 (goto-char (match-end 1))
3146 (org-end-of-subtree 'invisible
))))
3149 (defconst org-agenda-no-heading-message
3150 "No heading for this item in buffer or region.")
3152 (defun org-agenda-get-timestamps ()
3153 "Return the date stamp information for agenda display."
3154 (let* ((props (list 'face nil
3155 'org-not-done-regexp org-not-done-regexp
3156 'org-todo-regexp org-todo-regexp
3157 'org-complex-heading-regexp org-complex-heading-regexp
3158 'mouse-face
'highlight
3159 'keymap org-agenda-keymap
3161 (format "mouse-2 or RET jump to org file %s"
3162 (abbreviate-file-name buffer-file-name
))))
3163 (d1 (calendar-absolute-from-gregorian date
))
3169 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3173 (if org-agenda-include-inactive-timestamps
"[[<]" "<")
3177 (car org-time-stamp-formats
)
3178 (apply 'encode-time
; DATE bound by calendar
3179 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3181 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3182 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3183 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3184 donep tmp priority category ee txt timestr tags b0 b3 e3 head
)
3185 (goto-char (point-min))
3186 (while (re-search-forward regexp nil t
)
3187 (setq b0
(match-beginning 0)
3188 b3
(match-beginning 3) e3
(match-end 3))
3190 (and (org-at-date-range-p) (throw :skip nil
))
3192 (if (and (match-end 1)
3193 (not (= d1
(org-time-string-to-absolute
3194 (match-string 1) d1 nil
3195 org-agenda-repeating-timestamp-show-all
))))
3198 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3200 (setq marker
(org-agenda-new-marker b0
)
3201 category
(org-get-category b0
)
3202 tmp
(buffer-substring (max (point-min)
3203 (- b0 org-ds-keyword-length
))
3205 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3206 inactivep
(= (char-after b0
) ?\
[)
3207 deadlinep
(string-match org-deadline-regexp tmp
)
3208 scheduledp
(string-match org-scheduled-regexp tmp
)
3209 closedp
(and org-agenda-include-inactive-timestamps
3210 (string-match org-closed-string tmp
))
3211 clockp
(and org-agenda-include-inactive-timestamps
3212 (or (string-match org-clock-string tmp
)
3213 (string-match "]-+\\'" tmp
)))
3214 donep
(org-entry-is-done-p))
3215 (if (or scheduledp deadlinep closedp clockp
)
3217 (if (string-match ">" timestr
)
3218 ;; substring should only run to end of time stamp
3219 (setq timestr
(substring timestr
0 (match-end 0))))
3221 (if (re-search-backward "^\\*+ " nil t
)
3223 (goto-char (match-beginning 0))
3224 (setq hdmarker
(org-agenda-new-marker)
3225 tags
(org-get-tags-at))
3226 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3227 (setq head
(match-string 1))
3228 (and org-agenda-skip-timestamp-if-done donep
(throw :skip t
))
3229 (setq txt
(org-format-agenda-item
3230 (if inactivep
"[" nil
)
3231 head category tags timestr nil
3233 (setq txt org-agenda-no-heading-message
))
3234 (setq priority
(org-get-priority txt
))
3235 (org-add-props txt props
3236 'org-marker marker
'org-hd-marker hdmarker
)
3237 (org-add-props txt nil
'priority priority
3238 'org-category category
'date date
3241 (outline-next-heading)))
3244 (defun org-agenda-get-sexps ()
3245 "Return the sexp information for agenda display."
3246 (require 'diary-lib
)
3247 (let* ((props (list 'face nil
3248 'mouse-face
'highlight
3249 'keymap org-agenda-keymap
3251 (format "mouse-2 or RET jump to org file %s"
3252 (abbreviate-file-name buffer-file-name
))))
3254 marker category ee txt tags entry result beg b sexp sexp-entry
)
3255 (goto-char (point-min))
3256 (while (re-search-forward regexp nil t
)
3259 (setq beg
(match-beginning 0))
3260 (goto-char (1- (match-end 0)))
3263 (setq sexp
(buffer-substring b
(point)))
3264 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3265 (org-trim (match-string 1))
3267 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3269 (setq marker
(org-agenda-new-marker beg
)
3270 category
(org-get-category beg
))
3272 (if (string-match "\\S-" result
)
3274 (setq txt
"SEXP entry returned empty string"))
3276 (setq txt
(org-format-agenda-item
3277 "" txt category tags
'time
))
3278 (org-add-props txt props
'org-marker marker
)
3279 (org-add-props txt nil
3280 'org-category category
'date date
3285 (defun org-agenda-get-closed ()
3286 "Return the logged TODO entries for agenda display."
3287 (let* ((props (list 'mouse-face
'highlight
3288 'org-not-done-regexp org-not-done-regexp
3289 'org-todo-regexp org-todo-regexp
3290 'org-complex-heading-regexp org-complex-heading-regexp
3291 'keymap org-agenda-keymap
3293 (format "mouse-2 or RET jump to org file %s"
3294 (abbreviate-file-name buffer-file-name
))))
3296 "\\<\\(" org-closed-string
"\\|" org-clock-string
"\\) *\\["
3300 (car org-time-stamp-formats
)
3301 (apply 'encode-time
; DATE bound by calendar
3302 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3304 marker hdmarker priority category tags closedp
3306 (goto-char (point-min))
3307 (while (re-search-forward regexp nil t
)
3310 (setq marker
(org-agenda-new-marker (match-beginning 0))
3311 closedp
(equal (match-string 1) org-closed-string
)
3312 category
(org-get-category (match-beginning 0))
3313 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3314 ;; donep (org-entry-is-done-p)
3316 (if (string-match "\\]" timestr
)
3317 ;; substring should only run to end of time stamp
3318 (setq timestr
(substring timestr
0 (match-end 0))))
3320 (if (re-search-backward "^\\*+ " nil t
)
3322 (goto-char (match-beginning 0))
3323 (setq hdmarker
(org-agenda-new-marker)
3324 tags
(org-get-tags-at))
3325 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3326 (setq txt
(org-format-agenda-item
3327 (if closedp
"Closed: " "Clocked: ")
3328 (match-string 1) category tags timestr
)))
3329 (setq txt org-agenda-no-heading-message
))
3330 (setq priority
100000)
3331 (org-add-props txt props
3332 'org-marker marker
'org-hd-marker hdmarker
'face
'org-done
3333 'priority priority
'org-category category
3334 'type
"closed" 'date date
3335 'undone-face
'org-warning
'done-face
'org-done
)
3337 (goto-char (point-at-eol))))
3340 (defun org-agenda-get-deadlines ()
3341 "Return the deadline information for agenda display."
3342 (let* ((props (list 'mouse-face
'highlight
3343 'org-not-done-regexp org-not-done-regexp
3344 'org-todo-regexp org-todo-regexp
3345 'org-complex-heading-regexp org-complex-heading-regexp
3346 'keymap org-agenda-keymap
3348 (format "mouse-2 or RET jump to org file %s"
3349 (abbreviate-file-name buffer-file-name
))))
3350 (regexp org-deadline-time-regexp
)
3351 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
3352 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3353 d2 diff dfrac wdays pos pos1 category tags
3354 ee txt head face s upcomingp donep timestr
)
3355 (goto-char (point-min))
3356 (while (re-search-forward regexp nil t
)
3359 (setq s
(match-string 1)
3360 pos
(1- (match-beginning 1))
3361 d2
(org-time-string-to-absolute
3362 (match-string 1) d1
'past
3363 org-agenda-repeating-timestamp-show-all
)
3365 wdays
(org-get-wdays s
)
3366 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3367 upcomingp
(and todayp
(> diff
0)))
3368 ;; When to show a deadline in the calendar:
3369 ;; If the expiration is within wdays warning time.
3370 ;; Past-due deadlines are only shown on the current date
3371 (if (or (and (<= diff wdays
)
3372 (and todayp
(not org-agenda-only-exact-dates
)))
3375 (setq category
(org-get-category))
3376 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3378 (goto-char (match-end 0))
3379 (setq pos1
(match-beginning 0))
3380 (setq tags
(org-get-tags-at pos1
))
3381 (setq head
(buffer-substring-no-properties
3383 (progn (skip-chars-forward "^\r\n")
3385 (setq donep
(string-match org-looking-at-done-regexp head
))
3386 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3388 (concat (substring s
(match-beginning 1)) " "))
3389 (setq timestr
'time
))
3391 (or org-agenda-skip-deadline-if-done
3394 (setq txt
(org-format-agenda-item
3396 (car org-agenda-deadline-leaders
)
3397 (if (functionp (nth 1 org-agenda-deadline-leaders
))
3398 (funcall (nth 1 org-agenda-deadline-leaders
) diff date
)
3399 (format (nth 1 org-agenda-deadline-leaders
)
3401 head category tags timestr
))))
3402 (setq txt org-agenda-no-heading-message
))
3404 (setq face
(org-agenda-deadline-face dfrac wdays
))
3405 (org-add-props txt props
3406 'org-marker
(org-agenda-new-marker pos
)
3407 'org-hd-marker
(org-agenda-new-marker pos1
)
3408 'priority
(+ (- diff
)
3409 (org-get-priority txt
))
3410 'org-category category
3411 'type
(if upcomingp
"upcoming-deadline" "deadline")
3412 'date
(if upcomingp date d2
)
3413 'face
(if donep
'org-done face
)
3414 'undone-face face
'done-face
'org-done
)
3418 (defun org-agenda-deadline-face (fraction &optional wdays
)
3419 "Return the face to displaying a deadline item.
3420 FRACTION is what fraction of the head-warning time has passed."
3421 (if (equal wdays
0) (setq fraction
1.
))
3422 (let ((faces org-agenda-deadline-faces
) f
)
3424 (while (setq f
(pop faces
))
3425 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3427 (defun org-agenda-get-scheduled ()
3428 "Return the scheduled information for agenda display."
3429 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3430 'org-todo-regexp org-todo-regexp
3431 'org-complex-heading-regexp org-complex-heading-regexp
3432 'done-face
'org-done
3433 'mouse-face
'highlight
3434 'keymap org-agenda-keymap
3436 (format "mouse-2 or RET jump to org file %s"
3437 (abbreviate-file-name buffer-file-name
))))
3438 (regexp org-scheduled-time-regexp
)
3439 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
3440 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3441 d2 diff pos pos1 category tags
3442 ee txt head pastschedp donep face timestr s
)
3443 (goto-char (point-min))
3444 (while (re-search-forward regexp nil t
)
3447 (setq s
(match-string 1)
3448 pos
(1- (match-beginning 1))
3449 d2
(org-time-string-to-absolute
3450 (match-string 1) d1
'past
3451 org-agenda-repeating-timestamp-show-all
)
3453 (setq pastschedp
(and todayp
(< diff
0)))
3454 ;; When to show a scheduled item in the calendar:
3455 ;; If it is on or past the date.
3456 (if (or (and (< diff
0)
3457 (< (abs diff
) org-scheduled-past-days
)
3458 (and todayp
(not org-agenda-only-exact-dates
)))
3461 (setq category
(org-get-category))
3462 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3464 (goto-char (match-end 0))
3465 (setq pos1
(match-beginning 0))
3466 (setq tags
(org-get-tags-at))
3467 (setq head
(buffer-substring-no-properties
3469 (progn (skip-chars-forward "^\r\n") (point))))
3470 (setq donep
(string-match org-looking-at-done-regexp head
))
3471 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3473 (concat (substring s
(match-beginning 1)) " "))
3474 (setq timestr
'time
))
3476 (or org-agenda-skip-scheduled-if-done
3479 (setq txt
(org-format-agenda-item
3481 (car org-agenda-scheduled-leaders
)
3482 (format (nth 1 org-agenda-scheduled-leaders
)
3484 head category tags timestr
))))
3485 (setq txt org-agenda-no-heading-message
))
3487 (setq face
(if pastschedp
3488 'org-scheduled-previously
3489 'org-scheduled-today
))
3490 (org-add-props txt props
3492 'face
(if donep
'org-done face
)
3493 'org-marker
(org-agenda-new-marker pos
)
3494 'org-hd-marker
(org-agenda-new-marker pos1
)
3495 'type
(if pastschedp
"past-scheduled" "scheduled")
3496 'date
(if pastschedp d2 date
)
3497 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
3498 'org-category category
)
3502 (defun org-agenda-get-blocks ()
3503 "Return the date-range information for agenda display."
3504 (let* ((props (list 'face nil
3505 'org-not-done-regexp org-not-done-regexp
3506 'org-todo-regexp org-todo-regexp
3507 'org-complex-heading-regexp org-complex-heading-regexp
3508 'mouse-face
'highlight
3509 'keymap org-agenda-keymap
3511 (format "mouse-2 or RET jump to org file %s"
3512 (abbreviate-file-name buffer-file-name
))))
3513 (regexp org-tr-regexp
)
3514 (d0 (calendar-absolute-from-gregorian date
))
3515 marker hdmarker ee txt d1 d2 s1 s2 timestr category tags pos
3517 (goto-char (point-min))
3518 (while (re-search-forward regexp nil t
)
3522 (setq timestr
(match-string 0)
3525 d1
(time-to-days (org-time-string-to-time s1
))
3526 d2
(time-to-days (org-time-string-to-time s2
)))
3527 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
3528 ;; Only allow days between the limits, because the normal
3529 ;; date stamps will catch the limits.
3531 (setq marker
(org-agenda-new-marker (point)))
3532 (setq category
(org-get-category))
3533 (if (re-search-backward "^\\*+ " nil t
)
3535 (goto-char (match-beginning 0))
3536 (setq hdmarker
(org-agenda-new-marker (point)))
3537 (setq tags
(org-get-tags-at))
3538 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3539 (setq head
(match-string 1))
3540 (and org-agenda-skip-timestamp-if-done
3541 (org-entry-is-done-p)
3543 (setq txt
(org-format-agenda-item
3544 (format (if (= d1 d2
) "" "(%d/%d): ")
3545 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
3547 (if (= d0 d1
) timestr
))))
3548 (setq txt org-agenda-no-heading-message
))
3549 (org-add-props txt props
3550 'org-marker marker
'org-hd-marker hdmarker
3551 'type
"block" 'date date
3552 'priority
(org-get-priority txt
) 'org-category category
)
3555 ;; Sort the entries by expiration date.
3558 ;;; Agenda presentation and sorting
3560 (defvar org-prefix-has-time nil
3561 "A flag, set by `org-compile-prefix-format'.
3562 The flag is set if the currently compiled format contains a `%t'.")
3563 (defvar org-prefix-has-tag nil
3564 "A flag, set by `org-compile-prefix-format'.
3565 The flag is set if the currently compiled format contains a `%T'.")
3566 (defvar org-prefix-has-effort nil
3567 "A flag, set by `org-compile-prefix-format'.
3568 The flag is set if the currently compiled format contains a `%e'.")
3570 (defun org-format-agenda-item (extra txt
&optional category tags dotime
3572 "Format TXT to be inserted into the agenda buffer.
3573 In particular, it adds the prefix and corresponding text properties. EXTRA
3574 must be a string and replaces the `%s' specifier in the prefix format.
3575 CATEGORY (string, symbol or nil) may be used to overrule the default
3576 category taken from local variable or file name. It will replace the `%c'
3577 specifier in the format. DOTIME, when non-nil, indicates that a
3578 time-of-day should be extracted from TXT for sorting of this entry, and for
3579 the `%t' specifier in the format. When DOTIME is a string, this string is
3580 searched for a time before TXT is. NOPREFIX is a flag and indicates that
3581 only the correctly processes TXT should be returned - this is used by
3582 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
3583 Any match of REMOVE-RE will be removed from TXT."
3585 ;; Diary entries sometimes have extra whitespace at the beginning
3586 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
3587 (let* ((category (or category
3589 (if buffer-file-name
3590 (file-name-sans-extension
3591 (file-name-nondirectory buffer-file-name
))
3593 ;; time, tag, effort are needed for the eval of the prefix format
3594 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
3596 (ts (if dotime
(concat (if (stringp dotime
) dotime
"") txt
)))
3597 (time-of-day (and dotime
(org-get-time-of-day ts
)))
3598 stamp plain s0 s1 s2 t1 t2 rtn srp
3600 (and (org-mode-p) buffer-file-name
3601 (add-to-list 'org-agenda-contributing-files buffer-file-name
))
3602 (when (and dotime time-of-day
)
3603 ;; Extract starting and ending time and move them to prefix
3604 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
3605 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
3606 (setq s0
(match-string 0 ts
)
3607 srp
(and stamp
(match-end 3))
3608 s1
(match-string (if plain
1 2) ts
)
3609 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
3611 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
3612 ;; them, we might want to remove them there to avoid duplication.
3613 ;; The user can turn this off with a variable.
3614 (if (and org-prefix-has-time
3615 org-agenda-remove-times-when-in-prefix
(or stamp plain
)
3616 (string-match (concat (regexp-quote s0
) " *") txt
)
3617 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
3618 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
3619 (= (match-beginning 0) 0)
3621 (setq txt
(replace-match "" nil nil txt
))))
3622 ;; Normalize the time(s) to 24 hour
3623 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
3624 (if s2
(setq s2
(org-get-time-of-day s2
'string t
)))
3625 ;; Compute the duration
3627 (setq t1
(+ (* 60 (string-to-number (substring s1
0 2)))
3628 (string-to-number (substring s1
3)))
3630 (s2 (+ (* 60 (string-to-number (substring s2
0 2)))
3631 (string-to-number (substring s2
3))))
3632 (org-agenda-default-appointment-duration
3633 (+ t1 org-agenda-default-appointment-duration
))
3635 (setq duration
(if t2
(- t2 t1
)))))
3637 (when (and s1
(not s2
) org-agenda-default-appointment-duration
3638 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
3639 (let ((m (+ (string-to-number (match-string 2 s1
))
3640 (* 60 (string-to-number (match-string 1 s1
)))
3641 org-agenda-default-appointment-duration
))
3643 (setq h
(/ m
60) m
(- m
(* h
60)))
3644 (setq s2
(format "%02d:%02d" h m
))))
3646 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
3648 ;; Tags are in the string
3649 (if (or (eq org-agenda-remove-tags t
)
3650 (and org-agenda-remove-tags
3651 org-prefix-has-tag
))
3652 (setq txt
(replace-match "" t t txt
))
3653 (setq txt
(replace-match
3654 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
3655 (match-string 2 txt
))
3661 (or (get-text-property 0 'org-hd-marker txt
)
3662 (get-text-property 0 'org-marker txt
)))
3665 (setq neffort
(org-hh:mm-string-to-minutes effort
)
3666 effort
(setq effort
(concat "[" effort
"]" )))))
3669 (while (string-match remove-re txt
)
3670 (setq txt
(replace-match "" t t txt
))))
3672 ;; Create the final string
3675 ;; Prepare the variables needed in the eval of the compiled format
3676 (setq time
(cond (s2 (concat s1
"-" s2
))
3677 (s1 (concat s1
"......"))
3680 category
(if (symbolp category
) (symbol-name category
) category
))
3681 ;; Evaluate the compiled format
3682 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
3684 ;; And finally add the text properties
3685 (org-add-props rtn nil
3686 'org-category
(downcase category
) 'tags tags
3687 'org-highest-priority org-highest-priority
3688 'org-lowest-priority org-lowest-priority
3689 'prefix-length
(- (length rtn
) (length txt
))
3690 'time-of-day time-of-day
3693 'effort-minutes neffort
3699 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
3700 (defvar org-agenda-sorting-strategy-selected nil
)
3702 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
3704 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
3705 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
3706 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
3707 ((member 'weekly
(car org-agenda-time-grid
)))
3708 (t (throw 'exit list
)))
3709 (let* ((have (delq nil
(mapcar
3710 (lambda (x) (get-text-property 1 'time-of-day x
))
3712 (string (nth 1 org-agenda-time-grid
))
3713 (gridtimes (nth 2 org-agenda-time-grid
))
3714 (req (car org-agenda-time-grid
))
3715 (remove (member 'remove-match req
))
3717 (if (and (member 'require-timed req
) (not have
))
3718 ;; don't show empty grid
3720 (while (setq time
(pop gridtimes
))
3721 (unless (and remove
(member time have
))
3722 (setq time
(int-to-string time
))
3723 (push (org-format-agenda-item
3725 (concat (substring time
0 -
2) ":" (substring time -
2)))
3728 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
3729 (if (member 'time-up org-agenda-sorting-strategy-selected
)
3731 (append list new
)))))
3733 (defun org-compile-prefix-format (key)
3734 "Compile the prefix format into a Lisp form that can be evaluated.
3735 The resulting form is returned and stored in the variable
3736 `org-prefix-format-compiled'."
3737 (setq org-prefix-has-time nil org-prefix-has-tag nil
3738 org-prefix-has-effort nil
)
3740 ((stringp org-agenda-prefix-format
)
3741 org-agenda-prefix-format
)
3742 ((assq key org-agenda-prefix-format
)
3743 (cdr (assq key org-agenda-prefix-format
)))
3744 (t " %-12:c%?-12t% s")))
3746 varform vars var e c f opt
)
3747 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
3749 (setq var
(cdr (assoc (match-string 4 s
)
3750 '(("c" . category
) ("t" . time
) ("s" . extra
)
3751 ("T" . tag
) ("e" . effort
))))
3752 c
(or (match-string 3 s
) "")
3753 opt
(match-beginning 1)
3754 start
(1+ (match-beginning 0)))
3755 (if (equal var
'time
) (setq org-prefix-has-time t
))
3756 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
3757 (if (equal var
'effort
) (setq org-prefix-has-effort t
))
3758 (setq f
(concat "%" (match-string 2 s
) "s"))
3761 `(if (equal "" ,var
)
3763 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
3764 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
3765 (setq s
(replace-match "%s" t nil s
))
3766 (push varform vars
))
3767 (setq vars
(nreverse vars
))
3768 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
3770 (defun org-set-sorting-strategy (key)
3771 (if (symbolp (car org-agenda-sorting-strategy
))
3773 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
3774 (setq org-agenda-sorting-strategy-selected
3775 (or (cdr (assq key org-agenda-sorting-strategy
))
3776 (cdr (assq 'agenda org-agenda-sorting-strategy
))
3777 '(time-up category-keep priority-down
)))))
3779 (defun org-get-time-of-day (s &optional string mod24
)
3780 "Check string S for a time of day.
3781 If found, return it as a military time number between 0 and 2400.
3782 If not found, return nil.
3783 The optional STRING argument forces conversion into a 5 character wide string
3787 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
3788 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
3789 (let* ((h (string-to-number (match-string 1 s
)))
3790 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
3791 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
3792 (am-p (equal ampm
"am"))
3793 (h1 (cond ((not ampm
) h
)
3794 ((= h
12) (if am-p
0 12))
3795 (t (+ h
(if am-p
0 12)))))
3796 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
3798 (t0 (+ (* 100 h2
) m
))
3799 (t1 (concat (if (>= h1
24) "+" " ")
3800 (if (< t0
100) "0" "")
3801 (if (< t0
10) "0" "")
3802 (int-to-string t0
))))
3803 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
3805 (defun org-finalize-agenda-entries (list &optional nosort
)
3806 "Sort and concatenate the agenda items."
3807 (setq list
(mapcar 'org-agenda-highlight-todo list
))
3810 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
3812 (defun org-agenda-highlight-todo (x)
3816 (beginning-of-line 1)
3817 (setq re
(get-text-property (point) 'org-todo-regexp
))
3818 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
3819 (when (looking-at (concat "[ \t]*\\.*" re
" +"))
3820 (add-text-properties (match-beginning 0) (match-end 0)
3821 (list 'face
(org-get-todo-face 0)))
3822 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
3823 (delete-region (match-beginning 1) (1- (match-end 0)))
3824 (goto-char (match-beginning 1))
3825 (insert (format org-agenda-todo-keyword-format s
)))))
3826 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
3827 pl
(get-text-property 0 'prefix-length x
))
3829 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
3831 (add-text-properties
3832 (or (match-end 1) (match-end 0)) (match-end 0)
3833 (list 'face
(org-get-todo-face (match-string 2 x
)))
3835 (setq x
(concat (substring x
0 (match-end 1))
3836 (format org-agenda-todo-keyword-format
3839 (substring x
(match-end 3)))))
3842 (defsubst org-cmp-priority
(a b
)
3843 "Compare the priorities of string A and B."
3844 (let ((pa (or (get-text-property 1 'priority a
) 0))
3845 (pb (or (get-text-property 1 'priority b
) 0)))
3846 (cond ((> pa pb
) +1)
3850 (defsubst org-cmp-effort
(a b
)
3851 "Compare the priorities of string A and B."
3852 (let* ((def (if org-sort-agenda-noeffort-is-high
32767 -
1))
3853 (ea (or (get-text-property 1 'effort-minutes a
) def
))
3854 (eb (or (get-text-property 1 'effort-minutes b
) def
)))
3855 (cond ((> ea eb
) +1)
3859 (defsubst org-cmp-category
(a b
)
3860 "Compare the string values of categories of strings A and B."
3861 (let ((ca (or (get-text-property 1 'org-category a
) ""))
3862 (cb (or (get-text-property 1 'org-category b
) "")))
3863 (cond ((string-lessp ca cb
) -
1)
3864 ((string-lessp cb ca
) +1)
3867 (defsubst org-cmp-tag
(a b
)
3868 "Compare the string values of categories of strings A and B."
3869 (let ((ta (car (last (get-text-property 1 'tags a
))))
3870 (tb (car (last (get-text-property 1 'tags b
)))))
3873 ((string-lessp ta tb
) -
1)
3874 ((string-lessp tb ta
) +1)
3877 (defsubst org-cmp-time
(a b
)
3878 "Compare the time-of-day values of strings A and B."
3879 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
3880 (ta (or (get-text-property 1 'time-of-day a
) def
))
3881 (tb (or (get-text-property 1 'time-of-day b
) def
)))
3882 (cond ((< ta tb
) -
1)
3886 (defun org-entries-lessp (a b
)
3887 "Predicate for sorting agenda entries."
3888 ;; The following variables will be used when the form is evaluated.
3889 ;; So even though the compiler complains, keep them.
3890 (let* ((time-up (org-cmp-time a b
))
3891 (time-down (if time-up
(- time-up
) nil
))
3892 (priority-up (org-cmp-priority a b
))
3893 (priority-down (if priority-up
(- priority-up
) nil
))
3894 (effort-up (org-cmp-effort a b
))
3895 (effort-down (if effort-up
(- effort-up
) nil
))
3896 (category-up (org-cmp-category a b
))
3897 (category-down (if category-up
(- category-up
) nil
))
3898 (category-keep (if category-up
+1 nil
))
3899 (tag-up (org-cmp-tag a b
))
3900 (tag-down (if tag-up
(- tag-up
) nil
)))
3902 (eval (cons 'or org-agenda-sorting-strategy-selected
))
3903 '((-1 . t
) (1 . nil
) (nil . nil
))))))
3905 ;;; Agenda restriction lock
3907 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
3908 "Overlay to mark the headline to which arenda commands are restricted.")
3909 (org-overlay-put org-agenda-restriction-lock-overlay
3910 'face
'org-agenda-restriction-lock
)
3911 (org-overlay-put org-agenda-restriction-lock-overlay
3912 'help-echo
"Agendas are currently limited to this subtree.")
3913 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3915 (defun org-agenda-set-restriction-lock (&optional type
)
3916 "Set restriction lock for agenda, to current subtree or file.
3917 Restriction will be the file if TYPE is `file', or if type is the
3918 universal prefix '(4), or if the cursor is before the first headline
3919 in the file. Otherwise, restriction will be to the current subtree."
3921 (and (equal type
'(4)) (setq type
'file
))
3924 ((org-at-heading-p) 'subtree
)
3925 ((condition-case nil
(org-back-to-heading t
) (error nil
))
3928 (if (eq type
'subtree
)
3930 (setq org-agenda-restrict t
)
3931 (setq org-agenda-overriding-restriction
'subtree
)
3932 (put 'org-agenda-files
'org-restrict
3933 (list (buffer-file-name (buffer-base-buffer))))
3934 (org-back-to-heading t
)
3935 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
3936 (move-marker org-agenda-restrict-begin
(point))
3937 (move-marker org-agenda-restrict-end
3938 (save-excursion (org-end-of-subtree t
)))
3939 (message "Locking agenda restriction to subtree"))
3940 (put 'org-agenda-files
'org-restrict
3941 (list (buffer-file-name (buffer-base-buffer))))
3942 (setq org-agenda-restrict nil
)
3943 (setq org-agenda-overriding-restriction
'file
)
3944 (move-marker org-agenda-restrict-begin nil
)
3945 (move-marker org-agenda-restrict-end nil
)
3946 (message "Locking agenda restriction to file"))
3947 (setq current-prefix-arg nil
)
3948 (org-agenda-maybe-redo))
3950 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
3951 "Remove the agenda restriction lock."
3953 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3954 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
3955 (setq org-agenda-overriding-restriction nil
)
3956 (setq org-agenda-restrict nil
)
3957 (put 'org-agenda-files
'org-restrict nil
)
3958 (move-marker org-agenda-restrict-begin nil
)
3959 (move-marker org-agenda-restrict-end nil
)
3960 (setq current-prefix-arg nil
)
3961 (message "Agenda restriction lock removed")
3962 (or noupdate
(org-agenda-maybe-redo)))
3964 (defun org-agenda-maybe-redo ()
3965 "If there is any window showing the agenda view, update it."
3966 (let ((w (get-buffer-window org-agenda-buffer-name t
))
3967 (w0 (selected-window)))
3972 (if org-agenda-overriding-restriction
3973 (message "Agenda view shifted to new %s restriction"
3974 org-agenda-overriding-restriction
)
3975 (message "Agenda restriction lock removed")))))
3979 (defun org-agenda-check-type (error &rest types
)
3980 "Check if agenda buffer is of allowed type.
3981 If ERROR is non-nil, throw an error, otherwise just return nil."
3982 (if (memq org-agenda-type types
)
3985 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
3988 (defun org-agenda-quit ()
3989 "Exit agenda by removing the window or the buffer."
3991 (if org-agenda-columns-active
3993 (let ((buf (current-buffer)))
3994 (if (not (one-window-p)) (delete-window))
3996 (org-agenda-reset-markers)
3997 (org-columns-remove-overlays))
3998 ;; Maybe restore the pre-agenda window configuration.
3999 (and org-agenda-restore-windows-after-quit
4000 (not (eq org-agenda-window-setup
'other-frame
))
4001 org-pre-agenda-window-conf
4002 (set-window-configuration org-pre-agenda-window-conf
))))
4004 (defun org-agenda-exit ()
4005 "Exit agenda by removing the window or the buffer.
4006 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
4007 Org-mode buffers visited directly by the user will not be touched."
4009 (org-release-buffers org-agenda-new-buffers
)
4010 (setq org-agenda-new-buffers nil
)
4013 (defun org-agenda-execute (arg)
4014 "Execute another agenda command, keeping same window.\\<global-map>
4015 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
4017 (let ((org-agenda-window-setup 'current-window
))
4020 (defun org-save-all-org-buffers ()
4021 "Save all Org-mode buffers without user confirmation."
4023 (message "Saving all Org-mode buffers...")
4024 (save-some-buffers t
'org-mode-p
)
4025 (message "Saving all Org-mode buffers... done"))
4027 (defun org-agenda-redo ()
4029 When this is the global TODO list, a prefix argument will be interpreted."
4031 (let* ((org-agenda-keep-modes t
)
4032 (cols org-agenda-columns-active
)
4033 (line (org-current-line))
4034 (window-line (- line
(org-current-line (window-start))))
4035 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
4036 (and cols
(org-columns-quit))
4037 (message "Rebuilding agenda buffer...")
4038 (org-let lprops
'(eval org-agenda-redo-command
))
4039 (setq org-agenda-undo-list nil
4040 org-agenda-pending-undo-list nil
)
4041 (message "Rebuilding agenda buffer...done")
4042 (and cols
(interactive-p) (org-agenda-columns))
4044 (recenter window-line
)))
4046 (defun org-agenda-manipulate-query-add ()
4047 "Manipulate the query by adding a search term with positive selection.
4048 Positive selection means, the term must be matched for selection of an entry."
4050 (org-agenda-manipulate-query ?\
[))
4051 (defun org-agenda-manipulate-query-subtract ()
4052 "Manipulate the query by adding a search term with negative selection.
4053 Negative selection means, term must not be matched for selection of an entry."
4055 (org-agenda-manipulate-query ?\
]))
4056 (defun org-agenda-manipulate-query-add-re ()
4057 "Manipulate the query by adding a search regexp with positive selection.
4058 Positive selection means, the regexp must match for selection of an entry."
4060 (org-agenda-manipulate-query ?\
{))
4061 (defun org-agenda-manipulate-query-subtract-re ()
4062 "Manipulate the query by adding a search regexp with negative selection.
4063 Negative selection means, regexp must not match for selection of an entry."
4065 (org-agenda-manipulate-query ?\
}))
4066 (defun org-agenda-manipulate-query (char)
4068 ((memq org-agenda-type
'(timeline agenda
))
4069 (if (y-or-n-p "Re-display with inactive time stamps included? ")
4070 (let ((org-agenda-include-inactive-timestamps t
))
4073 ((eq org-agenda-type
'search
)
4075 'org-agenda-query-string
4076 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
4077 (?\
{ .
" +{}") (?\
} .
" -{}")))))
4078 (setq org-agenda-redo-command
4079 (list 'org-search-view
4081 org-agenda-query-string
4082 (+ (length org-agenda-query-string
)
4083 (if (member char
'(?\
{ ?\
})) 0 1))))
4084 (set-register org-agenda-query-register org-agenda-query-string
)
4086 (t (error "Cannot manipulate query for %s-type agenda buffers"
4089 (defun org-add-to-string (var string
)
4090 (set var
(concat (symbol-value var
) string
)))
4092 (defun org-agenda-goto-date (date)
4093 "Jump to DATE in agenda."
4094 (interactive (list (org-read-date)))
4095 (org-agenda-list nil date
))
4097 (defun org-agenda-goto-today ()
4100 (org-agenda-check-type t
'timeline
'agenda
)
4101 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
4103 (tdpos (goto-char tdpos
))
4104 ((eq org-agenda-type
'agenda
)
4105 (let* ((sd (time-to-days
4106 (time-subtract (current-time)
4107 (list 0 (* 3600 org-extend-today-until
) 0))))
4108 (comp (org-agenda-compute-time-span sd org-agenda-span
))
4109 (org-agenda-overriding-arguments org-agenda-last-arguments
))
4110 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
4111 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
4113 (org-agenda-find-same-or-today-or-agenda)))
4114 (t (error "Cannot find today")))))
4116 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
4118 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
4119 (text-property-any (point-min) (point-max) 'org-today t
)
4120 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
4123 (defun org-agenda-later (arg)
4124 "Go forward in time by thee current span.
4125 With prefix ARG, go forward that many times the current span."
4127 (org-agenda-check-type t
'agenda
)
4128 (let* ((span org-agenda-span
)
4129 (sd org-starting-day
)
4130 (greg (calendar-gregorian-from-absolute sd
))
4131 (cnt (get-text-property (point) 'org-day-cnt
))
4135 (setq sd
(+ arg sd
) nd
1))
4137 (setq sd
(+ (* 7 arg
) sd
) nd
7))
4139 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
4140 sd
(calendar-absolute-from-gregorian greg2
))
4141 (setcar greg2
(1+ (car greg2
)))
4142 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
4144 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
4145 sd
(calendar-absolute-from-gregorian greg2
))
4146 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
4147 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
4148 (let ((org-agenda-overriding-arguments
4149 (list (car org-agenda-last-arguments
) sd nd t
)))
4151 (org-agenda-find-same-or-today-or-agenda cnt
))))
4153 (defun org-agenda-earlier (arg)
4154 "Go backward in time by the current span.
4155 With prefix ARG, go backward that many times the current span."
4157 (org-agenda-later (- arg
)))
4159 (defun org-agenda-day-view (&optional day-of-year
)
4160 "Switch to daily view for agenda.
4161 With argument DAY-OF-YEAR, switch to that day of the year."
4163 (setq org-agenda-ndays
1)
4164 (org-agenda-change-time-span 'day day-of-year
))
4165 (defun org-agenda-week-view (&optional iso-week
)
4166 "Switch to daily view for agenda.
4167 With argument ISO-WEEK, switch to the corresponding ISO week.
4168 If ISO-WEEK has more then 2 digits, only the last two encode the
4169 week. Any digits before this encode a year. So 200712 means
4170 week 12 of year 2007. Years in the range 1938-2037 can also be
4171 written as 2-digit years."
4173 (setq org-agenda-ndays
7)
4174 (org-agenda-change-time-span 'week iso-week
))
4175 (defun org-agenda-month-view (&optional month
)
4176 "Switch to monthly view for agenda.
4177 With argument MONTH, switch to that month."
4179 (org-agenda-change-time-span 'month month
))
4180 (defun org-agenda-year-view (&optional year
)
4181 "Switch to yearly view for agenda.
4182 With argument YEAR, switch to that year.
4183 If MONTH has more then 2 digits, only the last two encode the
4184 month. Any digits before this encode a year. So 200712 means
4185 December year 2007. Years in the range 1938-2037 can also be
4186 written as 2-digit years."
4189 (setq year
(org-small-year-to-year year
)))
4190 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4191 (org-agenda-change-time-span 'year year
)
4194 (defun org-agenda-change-time-span (span &optional n
)
4195 "Change the agenda view to SPAN.
4196 SPAN may be `day', `week', `month', `year'."
4197 (org-agenda-check-type t
'agenda
)
4198 (if (and (not n
) (equal org-agenda-span span
))
4199 (error "Viewing span is already \"%s\"" span
))
4200 (let* ((sd (or (get-text-property (point) 'day
)
4202 (computed (org-agenda-compute-time-span sd span n
))
4203 (org-agenda-overriding-arguments
4204 (list (car org-agenda-last-arguments
)
4205 (car computed
) (cdr computed
) t
)))
4207 (org-agenda-find-same-or-today-or-agenda))
4208 (org-agenda-set-mode-name)
4209 (message "Switched to %s view" span
))
4211 (defun org-agenda-compute-time-span (sd span
&optional n
)
4212 "Compute starting date and number of days for agenda.
4213 SPAN may be `day', `week', `month', `year'. The return value
4214 is a cons cell with the starting date and the number of days,
4215 so that the date SD will be in that range."
4216 (let* ((greg (calendar-gregorian-from-absolute sd
))
4220 nd w1 y1 m1 thisweek
)
4224 (setq sd
(+ (calendar-absolute-from-gregorian
4229 (let* ((nt (calendar-day-of-week
4230 (calendar-gregorian-from-absolute sd
)))
4231 (d (if org-agenda-start-on-weekday
4232 (- nt org-agenda-start-on-weekday
)
4234 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
4237 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
4239 (setq y1
(org-small-year-to-year (/ n
100))
4242 (calendar-absolute-from-iso
4244 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
4247 (when (and n
(> n
99))
4248 (setq y1
(org-small-year-to-year (/ n
100))
4250 (setq sd
(calendar-absolute-from-gregorian
4251 (list (or n mg
) 1 (or y1 yg
)))
4252 nd
(- (calendar-absolute-from-gregorian
4253 (list (1+ (or n mg
)) 1 (or y1 yg
)))
4256 (setq sd
(calendar-absolute-from-gregorian
4257 (list 1 1 (or n yg
)))
4258 nd
(- (calendar-absolute-from-gregorian
4259 (list 1 1 (1+ (or n yg
))))
4263 (defun org-agenda-next-date-line (&optional arg
)
4264 "Jump to the next line indicating a date in agenda buffer."
4266 (org-agenda-check-type t
'agenda
'timeline
)
4267 (beginning-of-line 1)
4268 ;; This does not work if user makes date format that starts with a blank
4269 (if (looking-at "^\\S-") (forward-char 1))
4270 (if (not (re-search-forward "^\\S-" nil t arg
))
4273 (error "No next date after this line in this buffer")))
4274 (goto-char (match-beginning 0)))
4276 (defun org-agenda-previous-date-line (&optional arg
)
4277 "Jump to the previous line indicating a date in agenda buffer."
4279 (org-agenda-check-type t
'agenda
'timeline
)
4280 (beginning-of-line 1)
4281 (if (not (re-search-backward "^\\S-" nil t arg
))
4282 (error "No previous date before this line in this buffer")))
4284 ;; Initialize the highlight
4285 (defvar org-hl
(org-make-overlay 1 1))
4286 (org-overlay-put org-hl
'face
'highlight
)
4288 (defun org-highlight (begin end
&optional buffer
)
4289 "Highlight a region with overlay."
4290 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
4291 org-hl begin end
(or buffer
(current-buffer))))
4293 (defun org-unhighlight ()
4294 "Detach overlay INDEX."
4295 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
4297 ;; FIXME this is currently not used.
4298 (defun org-highlight-until-next-command (beg end
&optional buffer
)
4299 "Move the highlight overlay to BEG/END, remove it before the next command."
4300 (org-highlight beg end buffer
)
4301 (add-hook 'pre-command-hook
'org-unhighlight-once
))
4302 (defun org-unhighlight-once ()
4303 "Remove the highlight from its position, and this function from the hook."
4304 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
4307 (defun org-agenda-follow-mode ()
4308 "Toggle follow mode in an agenda buffer."
4310 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
4311 (org-agenda-set-mode-name)
4312 (message "Follow mode is %s"
4313 (if org-agenda-follow-mode
"on" "off")))
4315 (defun org-agenda-clockreport-mode ()
4316 "Toggle clocktable mode in an agenda buffer."
4318 (org-agenda-check-type t
'agenda
)
4319 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
4320 (org-agenda-set-mode-name)
4322 (message "Clocktable mode is %s"
4323 (if org-agenda-clockreport-mode
"on" "off")))
4325 (defun org-agenda-log-mode ()
4326 "Toggle log mode in an agenda buffer."
4328 (org-agenda-check-type t
'agenda
'timeline
)
4329 (setq org-agenda-show-log
(not org-agenda-show-log
))
4330 (org-agenda-set-mode-name)
4332 (message "Log mode is %s"
4333 (if org-agenda-show-log
"on" "off")))
4335 (defun org-agenda-toggle-diary ()
4336 "Toggle diary inclusion in an agenda buffer."
4338 (org-agenda-check-type t
'agenda
)
4339 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
4341 (org-agenda-set-mode-name)
4342 (message "Diary inclusion turned %s"
4343 (if org-agenda-include-diary
"on" "off")))
4345 (defun org-agenda-toggle-time-grid ()
4346 "Toggle time grid in an agenda buffer."
4348 (org-agenda-check-type t
'agenda
)
4349 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
4351 (org-agenda-set-mode-name)
4352 (message "Time-grid turned %s"
4353 (if org-agenda-use-time-grid
"on" "off")))
4355 (defun org-agenda-set-mode-name ()
4356 "Set the mode name to indicate all the small mode settings."
4358 (concat "Org-Agenda"
4359 (if (equal org-agenda-ndays
1) " Day" "")
4360 (if (equal org-agenda-ndays
7) " Week" "")
4361 (if org-agenda-follow-mode
" Follow" "")
4362 (if org-agenda-include-diary
" Diary" "")
4363 (if org-agenda-use-time-grid
" Grid" "")
4364 (if org-agenda-show-log
" Log" "")
4365 (if org-agenda-clockreport-mode
" Clock" "")))
4366 (force-mode-line-update))
4368 (defun org-agenda-post-command-hook ()
4369 (and (eolp) (not (bolp)) (backward-char 1))
4370 (setq org-agenda-type
4371 (or (get-text-property (point) 'org-agenda-type
)
4372 (get-text-property (max (point-min) (1- (point)))
4374 (if (and org-agenda-follow-mode
4375 (get-text-property (point) 'org-marker
))
4378 (defun org-agenda-show-priority ()
4379 "Show the priority of the current item.
4380 This priority is composed of the main priority given with the [#A] cookies,
4381 and by additional input from the age of a schedules or deadline entry."
4383 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
4384 (message "Priority is %d" (if pri pri -
1000))))
4386 (defun org-agenda-show-tags ()
4387 "Show the tags applicable to the current item."
4389 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
4391 (message "Tags are :%s:"
4392 (org-no-properties (mapconcat 'identity tags
":")))
4393 (message "No tags associated with this line"))))
4395 (defun org-agenda-goto (&optional highlight
)
4396 "Go to the Org-mode file which contains the item at point."
4398 (let* ((marker (or (get-text-property (point) 'org-marker
)
4399 (org-agenda-error)))
4400 (buffer (marker-buffer marker
))
4401 (pos (marker-position marker
)))
4402 (switch-to-buffer-other-window buffer
)
4406 (org-show-context 'agenda
)
4408 (and (outline-next-heading)
4409 (org-flag-heading nil
)))) ; show the next heading
4410 (recenter (/ (window-height) 2))
4411 (run-hooks 'org-agenda-after-show-hook
)
4412 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
4414 (defvar org-agenda-after-show-hook nil
4415 "Normal hook run after an item has been shown from the agenda.
4416 Point is in the buffer where the item originated.")
4418 (defun org-agenda-kill ()
4419 "Kill the entry or subtree belonging to the current agenda entry."
4421 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4422 (let* ((marker (or (get-text-property (point) 'org-marker
)
4423 (org-agenda-error)))
4424 (buffer (marker-buffer marker
))
4425 (pos (marker-position marker
))
4426 (type (get-text-property (point) 'type
))
4427 dbeg dend
(n 0) conf
)
4428 (org-with-remote-undo buffer
4429 (with-current-buffer buffer
4432 (if (and (org-mode-p) (not (member type
'("sexp"))))
4433 (setq dbeg
(progn (org-back-to-heading t
) (point))
4434 dend
(org-end-of-subtree t t
))
4435 (setq dbeg
(point-at-bol)
4436 dend
(min (point-max) (1+ (point-at-eol)))))
4438 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
4439 (setq conf
(or (eq t org-agenda-confirm-kill
)
4440 (and (numberp org-agenda-confirm-kill
)
4441 (> n org-agenda-confirm-kill
))))
4444 (format "Delete entry with %d lines in buffer \"%s\"? "
4445 n
(buffer-name buffer
))))
4447 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
4448 (with-current-buffer buffer
(delete-region dbeg dend
))
4449 (message "Agenda item and source killed"))))
4451 (defun org-agenda-archive ()
4452 "Archive the entry or subtree belonging to the current agenda entry."
4454 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4455 (let* ((marker (or (get-text-property (point) 'org-marker
)
4456 (org-agenda-error)))
4457 (buffer (marker-buffer marker
))
4458 (pos (marker-position marker
)))
4459 (org-with-remote-undo buffer
4460 (with-current-buffer buffer
4464 (org-remove-subtree-entries-from-agenda)
4465 (org-back-to-heading t
)
4466 (org-archive-subtree))
4467 (error "Archiving works only in Org-mode files"))))))
4469 (defun org-agenda-archive-to-archive-sibling ()
4470 "Move the entry to the archive sibling."
4472 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4473 (let* ((marker (or (get-text-property (point) 'org-marker
)
4474 (org-agenda-error)))
4475 (buffer (marker-buffer marker
))
4476 (pos (marker-position marker
)))
4477 (org-with-remote-undo buffer
4478 (with-current-buffer buffer
4482 (org-remove-subtree-entries-from-agenda)
4483 (org-back-to-heading t
)
4484 (org-archive-to-archive-sibling))
4485 (error "Archiving works only in Org-mode files"))))))
4487 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
4488 "Remove all lines in the agenda that correspond to a given subtree.
4489 The subtree is the one in buffer BUF, starting at BEG and ending at END.
4490 If this information is not given, the function uses the tree at point."
4491 (let ((buf (or buf
(current-buffer))) m p
)
4493 (unless (and beg end
)
4494 (org-back-to-heading t
)
4496 (org-end-of-subtree t
)
4498 (set-buffer (get-buffer org-agenda-buffer-name
))
4500 (goto-char (point-max))
4501 (beginning-of-line 1)
4503 (when (and (setq m
(get-text-property (point) 'org-marker
))
4504 (equal buf
(marker-buffer m
))
4505 (setq p
(marker-position m
))
4508 (let ((inhibit-read-only t
))
4509 (delete-region (point-at-bol) (1+ (point-at-eol)))))
4510 (beginning-of-line 0))))))
4512 (defun org-agenda-open-link ()
4513 "Follow the link in the current line, if any."
4515 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
4518 (narrow-to-region (point-at-bol) (point-at-eol))
4519 (org-open-at-point))))
4521 (defun org-agenda-copy-local-variable (var)
4522 "Get a variable from a referenced buffer and install it here."
4523 (let ((m (get-text-property (point) 'org-marker
)))
4524 (when (and m
(buffer-live-p (marker-buffer m
)))
4525 (org-set-local var
(with-current-buffer (marker-buffer m
)
4526 (symbol-value var
))))))
4528 (defun org-agenda-switch-to (&optional delete-other-windows
)
4529 "Go to the Org-mode file which contains the item at point."
4531 (let* ((marker (or (get-text-property (point) 'org-marker
)
4532 (org-agenda-error)))
4533 (buffer (marker-buffer marker
))
4534 (pos (marker-position marker
)))
4535 (switch-to-buffer buffer
)
4536 (and delete-other-windows
(delete-other-windows))
4540 (org-show-context 'agenda
)
4542 (and (outline-next-heading)
4543 (org-flag-heading nil
)))))) ; show the next heading
4545 (defun org-agenda-goto-mouse (ev)
4546 "Go to the Org-mode file which contains the item at the mouse click."
4548 (mouse-set-point ev
)
4551 (defun org-agenda-show ()
4552 "Display the Org-mode file which contains the item at point."
4554 (let ((win (selected-window)))
4556 (select-window win
)))
4558 (defun org-agenda-recenter (arg)
4559 "Display the Org-mode file which contains the item at point and recenter."
4561 (let ((win (selected-window)))
4564 (select-window win
)))
4566 (defun org-agenda-show-mouse (ev)
4567 "Display the Org-mode file which contains the item at the mouse click."
4569 (mouse-set-point ev
)
4572 (defun org-agenda-check-no-diary ()
4573 "Check if the entry is a diary link and abort if yes."
4574 (if (get-text-property (point) 'org-agenda-diary-link
)
4575 (org-agenda-error)))
4577 (defun org-agenda-error ()
4578 (error "Command not allowed in this line"))
4580 (defun org-agenda-tree-to-indirect-buffer ()
4581 "Show the subtree corresponding to the current entry in an indirect buffer.
4582 This calls the command `org-tree-to-indirect-buffer' from the original
4584 With numerical prefix arg ARG, go up to this level and then take that tree.
4585 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
4588 (org-agenda-check-no-diary)
4589 (let* ((marker (or (get-text-property (point) 'org-marker
)
4590 (org-agenda-error)))
4591 (buffer (marker-buffer marker
))
4592 (pos (marker-position marker
)))
4593 (with-current-buffer buffer
4596 (call-interactively 'org-tree-to-indirect-buffer
)))))
4598 (defvar org-last-heading-marker
(make-marker)
4599 "Marker pointing to the headline that last changed its TODO state
4600 by a remote command from the agenda.")
4602 (defun org-agenda-todo-nextset ()
4603 "Switch TODO entry to next sequence."
4605 (org-agenda-todo 'nextset
))
4607 (defun org-agenda-todo-previousset ()
4608 "Switch TODO entry to previous sequence."
4610 (org-agenda-todo 'previousset
))
4612 (defun org-agenda-todo (&optional arg
)
4613 "Cycle TODO state of line at point, also in Org-mode file.
4614 This changes the line at point, all other lines in the agenda referring to
4615 the same tree node, and the headline of the tree node in the Org-mode file."
4617 (org-agenda-check-no-diary)
4618 (let* ((col (current-column))
4619 (marker (or (get-text-property (point) 'org-marker
)
4620 (org-agenda-error)))
4621 (buffer (marker-buffer marker
))
4622 (pos (marker-position marker
))
4623 (hdmarker (get-text-property (point) 'org-hd-marker
))
4624 (inhibit-read-only t
)
4626 (org-with-remote-undo buffer
4627 (with-current-buffer buffer
4630 (org-show-context 'agenda
)
4632 (and (outline-next-heading)
4633 (org-flag-heading nil
))) ; show the next heading
4635 (and (bolp) (forward-char 1))
4636 (setq newhead
(org-get-heading))
4638 (org-back-to-heading)
4639 (move-marker org-last-heading-marker
(point))))
4640 (beginning-of-line 1)
4642 (org-agenda-change-all-lines newhead hdmarker
'fixface
))
4643 (org-move-to-column col
))))
4645 (defun org-agenda-add-note (&optional arg
)
4646 "Add a time-stamped note to the entry at point."
4648 (org-agenda-check-no-diary)
4649 (let* ((marker (or (get-text-property (point) 'org-marker
)
4650 (org-agenda-error)))
4651 (buffer (marker-buffer marker
))
4652 (pos (marker-position marker
))
4653 (hdmarker (get-text-property (point) 'org-hd-marker
))
4654 (inhibit-read-only t
))
4655 (with-current-buffer buffer
4658 (org-show-context 'agenda
)
4660 (and (outline-next-heading)
4661 (org-flag-heading nil
))) ; show the next heading
4664 (defun org-agenda-change-all-lines (newhead hdmarker
&optional fixface
)
4665 "Change all lines in the agenda buffer which match HDMARKER.
4666 The new content of the line will be NEWHEAD (as modified by
4667 `org-format-agenda-item'). HDMARKER is checked with
4668 `equal' against all `org-hd-marker' text properties in the file.
4669 If FIXFACE is non-nil, the face of each item is modified acording to
4670 the new TODO state."
4671 (let* ((inhibit-read-only t
)
4672 props m pl undone-face done-face finish new dotime cat tags
)
4674 (goto-char (point-max))
4675 (beginning-of-line 1)
4677 (setq finish
(bobp))
4678 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
4680 (setq props
(text-properties-at (point))
4681 dotime
(get-text-property (point) 'dotime
)
4682 cat
(get-text-property (point) 'org-category
)
4683 tags
(get-text-property (point) 'tags
)
4684 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
4685 pl
(get-text-property (point) 'prefix-length
)
4686 undone-face
(get-text-property (point) 'undone-face
)
4687 done-face
(get-text-property (point) 'done-face
))
4688 (org-move-to-column pl
)
4691 (beginning-of-line 1)
4692 (and (looking-at ".*\n?") (replace-match "")))
4694 (replace-match new t t
)
4695 (beginning-of-line 1)
4696 (add-text-properties (point-at-bol) (point-at-eol) props
)
4698 (add-text-properties
4699 (point-at-bol) (point-at-eol)
4701 (if org-last-todo-state-is-todo
4702 undone-face done-face
))))
4703 (org-agenda-highlight-todo 'line
)
4704 (beginning-of-line 1))
4705 (t (error "Line update did not work"))))
4706 (beginning-of-line 0)))
4707 (org-finalize-agenda)))
4709 (defun org-agenda-align-tags (&optional line
)
4710 "Align all tags in agenda items to `org-agenda-tags-column'."
4711 (let ((inhibit-read-only t
) l c
)
4713 (goto-char (if line
(point-at-bol) (point-min)))
4714 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4715 (if line
(point-at-eol) nil
) t
)
4716 (add-text-properties
4717 (match-beginning 2) (match-end 2)
4718 (list 'face
(delq nil
(list 'org-tag
(get-text-property
4719 (match-beginning 2) 'face
)))))
4720 (setq l
(- (match-end 2) (match-beginning 2))
4721 c
(if (< org-agenda-tags-column
0)
4722 (- (abs org-agenda-tags-column
) l
)
4723 org-agenda-tags-column
))
4724 (delete-region (match-beginning 1) (match-end 1))
4725 (goto-char (match-beginning 1))
4726 (insert (org-add-props
4727 (make-string (max 1 (- c
(current-column))) ?\
)
4728 (text-properties-at (point))))))))
4730 (defun org-agenda-priority-up ()
4731 "Increase the priority of line at point, also in Org-mode file."
4733 (org-agenda-priority 'up
))
4735 (defun org-agenda-priority-down ()
4736 "Decrease the priority of line at point, also in Org-mode file."
4738 (org-agenda-priority 'down
))
4740 (defun org-agenda-priority (&optional force-direction
)
4741 "Set the priority of line at point, also in Org-mode file.
4742 This changes the line at point, all other lines in the agenda referring to
4743 the same tree node, and the headline of the tree node in the Org-mode file."
4745 (org-agenda-check-no-diary)
4746 (let* ((marker (or (get-text-property (point) 'org-marker
)
4747 (org-agenda-error)))
4748 (hdmarker (get-text-property (point) 'org-hd-marker
))
4749 (buffer (marker-buffer hdmarker
))
4750 (pos (marker-position hdmarker
))
4751 (inhibit-read-only t
)
4753 (org-with-remote-undo buffer
4754 (with-current-buffer buffer
4757 (org-show-context 'agenda
)
4759 (and (outline-next-heading)
4760 (org-flag-heading nil
))) ; show the next heading
4761 (funcall 'org-priority force-direction
)
4763 (setq newhead
(org-get-heading)))
4764 (org-agenda-change-all-lines newhead hdmarker
)
4765 (beginning-of-line 1))))
4767 ;; FIXME: should fix the tags property of the agenda line.
4768 (defun org-agenda-set-tags ()
4769 "Set tags for the current headline."
4771 (org-agenda-check-no-diary)
4772 (if (and (org-region-active-p) (interactive-p))
4773 (call-interactively 'org-change-tag-in-region
)
4774 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4775 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4776 (org-agenda-error)))
4777 (buffer (marker-buffer hdmarker
))
4778 (pos (marker-position hdmarker
))
4779 (inhibit-read-only t
)
4781 (org-with-remote-undo buffer
4782 (with-current-buffer buffer
4786 (org-show-context 'agenda
))
4788 (and (outline-next-heading)
4789 (org-flag-heading nil
))) ; show the next heading
4791 (call-interactively 'org-set-tags
)
4793 (setq newhead
(org-get-heading)))
4794 (org-agenda-change-all-lines newhead hdmarker
)
4795 (beginning-of-line 1)))))
4797 (defun org-agenda-toggle-archive-tag ()
4798 "Toggle the archive tag for the current entry."
4800 (org-agenda-check-no-diary)
4801 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4802 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4803 (org-agenda-error)))
4804 (buffer (marker-buffer hdmarker
))
4805 (pos (marker-position hdmarker
))
4806 (inhibit-read-only t
)
4808 (org-with-remote-undo buffer
4809 (with-current-buffer buffer
4812 (org-show-context 'agenda
)
4814 (and (outline-next-heading)
4815 (org-flag-heading nil
))) ; show the next heading
4816 (call-interactively 'org-toggle-archive-tag
)
4818 (setq newhead
(org-get-heading)))
4819 (org-agenda-change-all-lines newhead hdmarker
)
4820 (beginning-of-line 1))))
4822 (defun org-agenda-date-later (arg &optional what
)
4823 "Change the date of this item to one day later."
4825 (org-agenda-check-type t
'agenda
'timeline
)
4826 (org-agenda-check-no-diary)
4827 (let* ((marker (or (get-text-property (point) 'org-marker
)
4828 (org-agenda-error)))
4829 (buffer (marker-buffer marker
))
4830 (pos (marker-position marker
)))
4831 (org-with-remote-undo buffer
4832 (with-current-buffer buffer
4835 (if (not (org-at-timestamp-p))
4836 (error "Cannot find time stamp"))
4837 (org-timestamp-change arg
(or what
'day
)))
4838 (org-agenda-show-new-time marker org-last-changed-timestamp
))
4839 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
4841 (defun org-agenda-date-earlier (arg &optional what
)
4842 "Change the date of this item to one day earlier."
4844 (org-agenda-date-later (- arg
) what
))
4846 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
4847 "Show new date stamp via text properties."
4848 ;; We use text properties to make this undoable
4849 (let ((inhibit-read-only t
))
4850 (setq stamp
(concat " " prefix
" => " stamp
))
4852 (goto-char (point-max))
4854 (when (equal marker
(get-text-property (point) 'org-marker
))
4855 (org-move-to-column (- (window-width) (length stamp
)) t
)
4856 (if (featurep 'xemacs
)
4857 ;; Use `duplicable' property to trigger undo recording
4858 (let ((ex (make-extent nil nil
))
4859 (gl (make-glyph stamp
)))
4860 (set-glyph-face gl
'secondary-selection
)
4861 (set-extent-properties
4862 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
4863 (insert-extent ex
(1- (point)) (point-at-eol)))
4864 (add-text-properties
4865 (1- (point)) (point-at-eol)
4866 (list 'display
(org-add-props stamp nil
4867 'face
'secondary-selection
))))
4868 (beginning-of-line 1))
4869 (beginning-of-line 0)))))
4871 (defun org-agenda-date-prompt (arg)
4872 "Change the date of this item. Date is prompted for, with default today.
4873 The prefix ARG is passed to the `org-time-stamp' command and can therefore
4874 be used to request time specification in the time stamp."
4876 (org-agenda-check-type t
'agenda
'timeline
)
4877 (org-agenda-check-no-diary)
4878 (let* ((marker (or (get-text-property (point) 'org-marker
)
4879 (org-agenda-error)))
4880 (buffer (marker-buffer marker
))
4881 (pos (marker-position marker
)))
4882 (org-with-remote-undo buffer
4883 (with-current-buffer buffer
4886 (if (not (org-at-timestamp-p))
4887 (error "Cannot find time stamp"))
4888 (org-time-stamp arg
)
4889 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
4891 (defun org-agenda-schedule (arg)
4892 "Schedule the item at point."
4894 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4895 (org-agenda-check-no-diary)
4896 (let* ((marker (or (get-text-property (point) 'org-marker
)
4897 (org-agenda-error)))
4898 (type (marker-insertion-type marker
))
4899 (buffer (marker-buffer marker
))
4900 (pos (marker-position marker
))
4901 (org-insert-labeled-timestamps-at-point nil
)
4903 (when type
(message "%s" type
) (sit-for 3))
4904 (set-marker-insertion-type marker t
)
4905 (org-with-remote-undo buffer
4906 (with-current-buffer buffer
4909 (setq ts
(org-schedule arg
)))
4910 (org-agenda-show-new-time marker ts
"S"))
4911 (message "Item scheduled for %s" ts
)))
4913 (defun org-agenda-deadline (arg)
4914 "Schedule the item at point."
4916 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4917 (org-agenda-check-no-diary)
4918 (let* ((marker (or (get-text-property (point) 'org-marker
)
4919 (org-agenda-error)))
4920 (buffer (marker-buffer marker
))
4921 (pos (marker-position marker
))
4922 (org-insert-labeled-timestamps-at-point nil
)
4924 (org-with-remote-undo buffer
4925 (with-current-buffer buffer
4928 (setq ts
(org-deadline arg
)))
4929 (org-agenda-show-new-time marker ts
"S"))
4930 (message "Deadline for this item set to %s" ts
)))
4932 (defun org-agenda-action ()
4933 "Select entry for agenda action, or execute an agenda action.
4934 This command prompts for another letter. Valid inputs are:
4936 m Mark the entry at point for an agenda action
4937 s Schedule the marked entry to the date at the cursor
4938 d Set the deadline of the marked entry to the date at the cursor
4939 r Call `org-remember' with cursor date as the default date
4940 SPC Show marked entry in other window
4941 TAB Visit marked entry in other window
4943 The cursor may be at a date in the calendar, or in the Org agenda."
4946 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
4947 (setq ans
(read-char-exclusive))
4951 (if (eq major-mode
'org-agenda-mode
)
4952 (let ((m (or (get-text-property (point) 'org-hd-marker
)
4953 (get-text-property (point) 'org-marker
))))
4956 (move-marker org-agenda-action-marker
4957 (marker-position m
) (marker-buffer m
))
4958 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
4959 (error "Don't know which entry to mark")))
4960 (error "This command works only in the agenda")))
4962 (org-agenda-do-action '(org-schedule nil org-overriding-default-time
)))
4964 (org-agenda-do-action '(org-deadline nil org-overriding-default-time
)))
4966 (org-agenda-do-action '(org-remember) t
))
4968 (let ((cw (selected-window)))
4969 (org-switch-to-buffer-other-window
4970 (marker-buffer org-agenda-action-marker
))
4971 (goto-char org-agenda-action-marker
)
4972 (org-show-context 'agenda
)
4973 (select-window cw
)))
4975 (org-switch-to-buffer-other-window
4976 (marker-buffer org-agenda-action-marker
))
4977 (goto-char org-agenda-action-marker
)
4978 (org-show-context 'agenda
))
4979 (t (error "Invalid agenda action %c" ans
)))))
4981 (defun org-agenda-do-action (form &optional current-buffer
)
4982 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
4983 (let ((org-overriding-default-time (org-get-cursor-date)))
4986 (if (not (marker-buffer org-agenda-action-marker
))
4987 (error "No entry has bee selected for agenda action")
4988 (with-current-buffer (marker-buffer org-agenda-action-marker
)
4992 (goto-char org-agenda-action-marker
)
4995 (defun org-agenda-clock-in (&optional arg
)
4996 "Start the clock on the currently selected item."
4998 (org-agenda-check-no-diary)
4999 (if (equal arg
'(4))
5001 (let* ((marker (or (get-text-property (point) 'org-marker
)
5002 (org-agenda-error)))
5003 (hdmarker (or (get-text-property (point) 'org-hd-marker
)
5005 (pos (marker-position marker
))
5007 (org-with-remote-undo (marker-buffer marker
)
5008 (with-current-buffer (marker-buffer marker
)
5011 (org-show-context 'agenda
)
5013 (org-cycle-hide-drawers 'children
)
5015 (setq newhead
(org-get-heading)))
5016 (org-agenda-change-all-lines newhead hdmarker t
)))))
5018 (defun org-agenda-clock-out (&optional arg
)
5019 "Stop the currently running clock."
5021 (unless (marker-buffer org-clock-marker
)
5022 (error "No running clock"))
5023 (org-with-remote-undo (marker-buffer org-clock-marker
)
5026 (defun org-agenda-clock-cancel (&optional arg
)
5027 "Cancel the currently running clock."
5029 (unless (marker-buffer org-clock-marker
)
5030 (error "No running clock"))
5031 (org-with-remote-undo (marker-buffer org-clock-marker
)
5032 (org-clock-cancel)))
5034 (defun org-agenda-diary-entry ()
5035 "Make a diary entry, like the `i' command from the calendar.
5036 All the standard commands work: block, weekly etc."
5038 (org-agenda-check-type t
'agenda
'timeline
)
5039 (require 'diary-lib
)
5041 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
5042 (read-char-exclusive)))
5043 (cmd (cdr (assoc char
5044 '((?d . insert-diary-entry
)
5045 (?w . insert-weekly-diary-entry
)
5046 (?m . insert-monthly-diary-entry
)
5047 (?y . insert-yearly-diary-entry
)
5048 (?a . insert-anniversary-diary-entry
)
5049 (?b . insert-block-diary-entry
)
5050 (?c . insert-cyclic-diary-entry
)))))
5051 (oldf (symbol-function 'calendar-cursor-to-date
))
5052 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
5054 (mark (or (mark t
) (point))))
5056 (error "No command associated with <%c>" char
))
5057 (unless (and (get-text-property point
'day
)
5058 (or (not (equal ?b char
))
5059 (get-text-property mark
'day
)))
5060 (error "Don't know which date to use for diary entry"))
5061 ;; We implement this by hacking the `calendar-cursor-to-date' function
5062 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
5063 (let ((calendar-mark-ring
5064 (list (calendar-gregorian-from-absolute
5065 (or (get-text-property mark
'day
)
5066 (get-text-property point
'day
))))))
5069 (fset 'calendar-cursor-to-date
5070 (lambda (&optional error
)
5071 (calendar-gregorian-from-absolute
5072 (get-text-property point
'day
))))
5073 (call-interactively cmd
))
5074 (fset 'calendar-cursor-to-date oldf
)))))
5077 (defun org-agenda-execute-calendar-command (cmd)
5078 "Execute a calendar command from the agenda, with the date associated to
5079 the cursor position."
5080 (org-agenda-check-type t
'agenda
'timeline
)
5081 (require 'diary-lib
)
5082 (unless (get-text-property (point) 'day
)
5083 (error "Don't know which date to use for calendar command"))
5084 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
5086 (date (calendar-gregorian-from-absolute
5087 (get-text-property point
'day
)))
5088 ;; the following 2 vars are needed in the calendar
5089 (displayed-month (car date
))
5090 (displayed-year (nth 2 date
)))
5093 (fset 'calendar-cursor-to-date
5094 (lambda (&optional error
)
5095 (calendar-gregorian-from-absolute
5096 (get-text-property point
'day
))))
5097 (call-interactively cmd
))
5098 (fset 'calendar-cursor-to-date oldf
))))
5100 (defun org-agenda-phases-of-moon ()
5101 "Display the phases of the moon for the 3 months around the cursor date."
5103 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
5105 (defun org-agenda-holidays ()
5106 "Display the holidays for the 3 months around the cursor date."
5108 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
5110 (defvar calendar-longitude
)
5111 (defvar calendar-latitude
)
5112 (defvar calendar-location-name
)
5114 (defun org-agenda-sunrise-sunset (arg)
5115 "Display sunrise and sunset for the cursor date.
5116 Latitude and longitude can be specified with the variables
5117 `calendar-latitude' and `calendar-longitude'. When called with prefix
5118 argument, latitude and longitude will be prompted for."
5121 (let ((calendar-longitude (if arg nil calendar-longitude
))
5122 (calendar-latitude (if arg nil calendar-latitude
))
5123 (calendar-location-name
5124 (if arg
"the given coordinates" calendar-location-name
)))
5125 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
5127 (defun org-agenda-goto-calendar ()
5128 "Open the Emacs calendar with the date at the cursor."
5130 (org-agenda-check-type t
'agenda
'timeline
)
5131 (let* ((day (or (get-text-property (point) 'day
)
5132 (error "Don't know which date to open in calendar")))
5133 (date (calendar-gregorian-from-absolute day
))
5134 (calendar-move-hook nil
)
5135 (calendar-view-holidays-initially-flag nil
)
5136 (calendar-view-diary-initially-flag nil
)
5137 (view-calendar-holidays-initially nil
)
5138 (calendar-view-diary-initially-flag nil
)
5139 (calendar-view-holidays-initially-flag nil
)
5140 (view-diary-entries-initially nil
))
5142 (calendar-goto-date date
)))
5145 (defun org-calendar-goto-agenda ()
5146 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
5147 This is a command that has to be installed in `calendar-mode-map'."
5149 (org-agenda-list nil
(calendar-absolute-from-gregorian
5150 (calendar-cursor-to-date))
5153 (defun org-agenda-convert-date ()
5155 (org-agenda-check-type t
'agenda
'timeline
)
5156 (let ((day (get-text-property (point) 'day
))
5159 (error "Don't know which date to convert"))
5160 (setq date
(calendar-gregorian-from-absolute day
))
5162 "Gregorian: " (calendar-date-string date
) "\n"
5163 "ISO: " (calendar-iso-date-string date
) "\n"
5164 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
5165 "Julian: " (calendar-julian-date-string date
) "\n"
5166 "Astron. JD: " (calendar-astro-date-string date
)
5167 " (Julian date number at noon UTC)\n"
5168 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
5169 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
5170 "French: " (calendar-french-date-string date
) "\n"
5171 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
5172 "Mayan: " (calendar-mayan-date-string date
) "\n"
5173 "Coptic: " (calendar-coptic-date-string date
) "\n"
5174 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
5175 "Persian: " (calendar-persian-date-string date
) "\n"
5176 "Chinese: " (calendar-chinese-date-string date
) "\n"))
5177 (with-output-to-temp-buffer "*Dates*"
5179 (if (fboundp 'fit-window-to-buffer
)
5180 (fit-window-to-buffer (get-buffer-window "*Dates*")))))
5182 ;;; Appointment reminders
5184 (defvar appt-time-msg-list
)
5187 (defun org-agenda-to-appt (&optional refresh filter
)
5188 "Activate appointments found in `org-agenda-files'.
5189 With a \\[universal-argument] prefix, refresh the list of
5192 If FILTER is t, interactively prompt the user for a regular
5193 expression, and filter out entries that don't match it.
5195 If FILTER is a string, use this string as a regular expression
5196 for filtering entries out.
5198 FILTER can also be an alist with the car of each cell being
5199 either 'headline or 'category. For example:
5201 '((headline \"IMPORTANT\")
5202 (category \"Work\"))
5204 will only add headlines containing IMPORTANT or headlines
5205 belonging to the \"Work\" category."
5208 (if refresh
(setq appt-time-msg-list nil
))
5210 (setq filter
(read-from-minibuffer "Regexp filter: ")))
5211 (let* ((cnt 0) ; count added events
5212 (org-agenda-new-buffers nil
)
5213 (org-deadline-warning-days 0)
5214 (today (org-date-to-gregorian
5215 (time-to-days (current-time))))
5216 (files (org-agenda-files)) entries file
)
5217 ;; Get all entries which may contain an appt
5218 (while (setq file
(pop files
))
5221 (org-agenda-get-day-entries
5222 file today
:timestamp
:scheduled
:deadline
))))
5223 (setq entries
(delq nil entries
))
5224 ;; Map thru entries and find if we should filter them out
5227 (let* ((evt (org-trim (get-text-property 1 'txt x
)))
5228 (cat (get-text-property 1 'org-category x
))
5229 (tod (get-text-property 1 'time-of-day x
))
5230 (ok (or (null filter
)
5231 (and (stringp filter
) (string-match filter evt
))
5234 (cadr (assoc 'category filter
)) cat
)
5236 (cadr (assoc 'headline filter
)) evt
))))))
5237 ;; FIXME: Shall we remove text-properties for the appt text?
5238 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
5240 (setq tod
(number-to-string tod
)
5241 tod
(when (string-match
5242 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)" tod
)
5243 (concat (match-string 1 tod
) ":"
5244 (match-string 2 tod
))))
5246 (setq cnt
(1+ cnt
))))) entries
)
5247 (org-release-buffers org-agenda-new-buffers
)
5249 (message "No event to add")
5250 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
5252 (provide 'org-agenda
)
5254 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
5256 ;;; org-agenda.el ends here