1 ;;; org-agenda.el --- The table editor for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; This file contains the code for creating and using the Agenda for Org-mode.
38 (declare-function add-to-diary-list
"diary-lib"
39 (date string specifier
&optional marker globcolor literal
))
40 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
41 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
42 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
43 (declare-function calendar-check-holidays
"holidays" (date))
44 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
45 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
46 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
47 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
48 (declare-function calendar-goto-date
"cal-move" (date))
49 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
50 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
51 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
52 (declare-function calendar-iso-from-absolute
"cal-iso" (&optional date
))
53 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
54 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
55 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
56 (defvar calendar-mode-map
)
58 ;; Defined somewhere in this file, but used before definition.
59 (defvar org-agenda-buffer-name
)
60 (defvar org-agenda-overriding-header
)
63 (defvar org-agenda-undo-list
)
64 (defvar org-agenda-pending-undo-list
)
65 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
67 (defcustom org-agenda-confirm-kill
1
68 "When set, remote killing from the agenda buffer needs confirmation.
69 When t, a confirmation is always needed. When a number N, confirmation is
70 only needed when the text to be killed contains more than N non-white lines."
73 (const :tag
"Never" nil
)
74 (const :tag
"Always" t
)
75 (number :tag
"When more than N lines")))
77 (defcustom org-agenda-compact-blocks nil
78 "Non-nil means, make the block agenda more compact.
79 This is done by leaving out unnecessary lines."
83 (defgroup org-agenda-export nil
84 "Options concerning exporting agenda views in Org-mode."
85 :tag
"Org Agenda Export"
88 (defcustom org-agenda-with-colors t
89 "Non-nil means, use colors in agenda views."
90 :group
'org-agenda-export
93 (defcustom org-agenda-exporter-settings nil
94 "Alist of variable/value pairs that should be active during agenda export.
95 This is a good place to set uptions for ps-print and for htmlize."
96 :group
'org-agenda-export
100 (sexp :tag
"Value"))))
102 (defcustom org-agenda-export-html-style
""
103 "The style specification for exported HTML Agenda files.
104 If this variable contains a string, it will replace the default <style>
105 section as produced by `htmlize'.
106 Since there are different ways of setting style information, this variable
107 needs to contain the full HTML structure to provide a style, including the
108 surrounding HTML tags. The style specifications should include definitions
109 the fonts used by the agenda, here is an example:
111 <style type=\"text/css\">
112 p { font-weight: normal; color: gray; }
113 .org-agenda-structure {
125 .title { text-align: center; }
126 .todo, .deadline { color: red; }
127 .done { color: green; }
130 or, if you want to keep the style in a file,
132 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
134 As the value of this option simply gets inserted into the HTML <head> header,
135 you can \"misuse\" it to also add other text to the header. However,
136 <style>...</style> is required, if not present the variable will be ignored."
137 :group
'org-agenda-export
138 :group
'org-export-html
141 (defgroup org-agenda-custom-commands nil
142 "Options concerning agenda views in Org-mode."
143 :tag
"Org Agenda Custom Commands"
146 (defconst org-sorting-choice
148 (const time-up
) (const time-down
)
149 (const category-keep
) (const category-up
) (const category-down
)
150 (const tag-down
) (const tag-up
)
151 (const priority-up
) (const priority-down
))
154 (defconst org-agenda-custom-commands-local-options
155 `(repeat :tag
"Local settings for this command. Remember to quote values"
156 (choice :tag
"Setting"
157 (list :tag
"Any variable"
158 (variable :tag
"Variable")
160 (list :tag
"Files to be searched"
161 (const org-agenda-files
)
163 (const :format
"" quote
)
166 (list :tag
"Sorting strategy"
167 (const org-agenda-sorting-strategy
)
169 (const :format
"" quote
)
171 ,org-sorting-choice
)))
172 (list :tag
"Prefix format"
173 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
175 (list :tag
"Number of days in agenda"
176 (const org-agenda-ndays
)
178 (list :tag
"Fixed starting date"
179 (const org-agenda-start-day
)
180 (string :value
"2007-11-01"))
181 (list :tag
"Start on day of week"
182 (const org-agenda-start-on-weekday
)
184 (const :tag
"Today" nil
)
185 (number :tag
"Weekday No.")))
186 (list :tag
"Include data from diary"
187 (const org-agenda-include-diary
)
189 (list :tag
"Deadline Warning days"
190 (const org-deadline-warning-days
)
192 (list :tag
"Standard skipping condition"
193 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
194 (const org-agenda-skip-function
)
196 (const :format
"" quote
)
200 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
201 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
202 (repeat :inline t
:tag
"Conditions for skipping"
204 :tag
"Condition type"
205 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
206 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
207 (const :tag
"scheduled" 'scheduled
)
208 (const :tag
"not scheduled" 'notscheduled
)
209 (const :tag
"deadline" 'deadline
)
210 (const :tag
"no deadline" 'notdeadline
))))))
211 (list :tag
"Non-standard skipping condition"
212 :value
(org-agenda-skip-function)
214 (const org-agenda-skip-function
)
215 (sexp :tag
"Function or form (quoted!)")))))
216 "Selection of examples for agenda command settings.
217 This will be spliced into the custom type of
218 `org-agenda-custom-commands'.")
221 (defcustom org-agenda-custom-commands nil
222 "Custom commands for the agenda.
223 These commands will be offered on the splash screen displayed by the
224 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
226 (key desc type match settings files)
228 key The key (one or more characters as a string) to be associated
230 desc A description of the command, when omitted or nil, a default
231 description is built using MATCH.
232 type The command type, any of the following symbols:
233 agenda The daily/weekly agenda.
234 todo Entries with a specific TODO keyword, in all agenda files.
235 search Entries containing search words entry or headline.
236 tags Tags/Property/TODO match in all agenda files.
237 tags-todo Tags/P/T match in all agenda files, TODO entries only.
238 todo-tree Sparse tree of specific TODO keyword in *current* file.
239 tags-tree Sparse tree with all tags matches in *current* file.
240 occur-tree Occur sparse tree for *current* file.
241 ... A user-defined function.
242 match What to search for:
243 - a single keyword for TODO keyword searches
244 - a tags match expression for tags searches
245 - a word search expression for text searches.
246 - a regular expression for occur searches
247 For all other commands, this should be the empty string.
248 settings A list of option settings, similar to that in a let form, so like
249 this: ((opt1 val1) (opt2 val2) ...). The values will be
250 evaluated at the moment of execution, so quote them when needed.
251 files A list of files file to write the produced agenda buffer to
252 with the command `org-store-agenda-views'.
253 If a file name ends in \".html\", an HTML version of the buffer
254 is written out. If it ends in \".ps\", a postscript version is
255 produced. Otherwide, only the plain text is written to the file.
257 You can also define a set of commands, to create a composite agenda buffer.
258 In this case, an entry looks like this:
260 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
264 desc A description string to be displayed in the dispatcher menu.
265 cmd An agenda command, similar to the above. However, tree commands
266 are no allowed, but instead you can get agenda and global todo list.
267 So valid commands for a set are:
268 (agenda \"\" settings)
269 (alltodo \"\" settings)
270 (stuck \"\" settings)
271 (todo \"match\" settings files)
272 (search \"match\" settings files)
273 (tags \"match\" settings files)
274 (tags-todo \"match\" settings files)
276 Each command can carry a list of options, and another set of options can be
277 given for the whole set of commands. Individual command options take
278 precedence over the general options.
280 When using several characters as key to a command, the first characters
281 are prefix commands. For the dispatcher to display useful information, you
282 should provide a description for the prefix, like
284 (setq org-agenda-custom-commands
285 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
286 (\"hl\" tags \"+HOME+Lisa\")
287 (\"hp\" tags \"+HOME+Peter\")
288 (\"hk\" tags \"+HOME+Kim\")))"
289 :group
'org-agenda-custom-commands
291 (choice :value
("x" "Describe command here" tags
"" nil
)
292 (list :tag
"Single command"
293 (string :tag
"Access Key(s) ")
294 (option (string :tag
"Description"))
296 (const :tag
"Agenda" agenda
)
297 (const :tag
"TODO list" alltodo
)
298 (const :tag
"Search words" search
)
299 (const :tag
"Stuck projects" stuck
)
300 (const :tag
"Tags search (all agenda files)" tags
)
301 (const :tag
"Tags search of TODO entries (all agenda files)" tags-todo
)
302 (const :tag
"TODO keyword search (all agenda files)" todo
)
303 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
304 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
305 (const :tag
"Occur tree (current buffer)" occur-tree
)
306 (sexp :tag
"Other, user-defined function"))
307 (string :tag
"Match (only for some commands)")
308 ,org-agenda-custom-commands-local-options
309 (option (repeat :tag
"Export" (file :tag
"Export to"))))
310 (list :tag
"Command series, all agenda files"
311 (string :tag
"Access Key(s)")
312 (string :tag
"Description ")
313 (repeat :tag
"Component"
316 (const :format
"" agenda
)
317 (const :tag
"" :format
"" "")
318 ,org-agenda-custom-commands-local-options
)
319 (list :tag
"TODO list (all keywords)"
320 (const :format
"" alltodo
)
321 (const :tag
"" :format
"" "")
322 ,org-agenda-custom-commands-local-options
)
323 (list :tag
"Search words"
324 (const :format
"" search
)
325 (string :tag
"Match")
326 ,org-agenda-custom-commands-local-options
)
327 (list :tag
"Stuck projects"
328 (const :format
"" stuck
)
329 (const :tag
"" :format
"" "")
330 ,org-agenda-custom-commands-local-options
)
331 (list :tag
"Tags search"
332 (const :format
"" tags
)
333 (string :tag
"Match")
334 ,org-agenda-custom-commands-local-options
)
335 (list :tag
"Tags search, TODO entries only"
336 (const :format
"" tags-todo
)
337 (string :tag
"Match")
338 ,org-agenda-custom-commands-local-options
)
339 (list :tag
"TODO keyword search"
340 (const :format
"" todo
)
341 (string :tag
"Match")
342 ,org-agenda-custom-commands-local-options
)
343 (list :tag
"Other, user-defined function"
344 (symbol :tag
"function")
345 (string :tag
"Match")
346 ,org-agenda-custom-commands-local-options
)))
348 (repeat :tag
"Settings for entire command set"
349 (list (variable :tag
"Any variable")
350 (sexp :tag
"Value")))
351 (option (repeat :tag
"Export" (file :tag
"Export to"))))
352 (cons :tag
"Prefix key documentation"
353 (string :tag
"Access Key(s)")
354 (string :tag
"Description ")))))
356 (defcustom org-agenda-query-register ?o
357 "The register holding the current query string.
358 The prupose of this is that if you construct a query string interactively,
359 you can then use it to define a custom command."
360 :group
'org-agenda-custom-commands
363 (defcustom org-stuck-projects
364 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
365 "How to identify stuck projects.
366 This is a list of four items:
367 1. A tags/todo matcher string that is used to identify a project.
368 The entire tree below a headline matched by this is considered one project.
369 2. A list of TODO keywords identifying non-stuck projects.
370 If the project subtree contains any headline with one of these todo
371 keywords, the project is considered to be not stuck. If you specify
372 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
373 3. A list of tags identifying non-stuck projects.
374 If the project subtree contains any headline with one of these tags,
375 the project is considered to be not stuck. If you specify \"*\" as
376 a tag, any tag will mark the project unstuck.
377 4. An arbitrary regular expression matching non-stuck projects.
379 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
380 or `C-c a #' to produce the list."
381 :group
'org-agenda-custom-commands
383 (string :tag
"Tags/TODO match to identify a project")
384 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
385 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
386 (regexp :tag
"Projects are *not* stuck if this regexp matches\ninside the subtree")))
389 (defgroup org-agenda-skip nil
390 "Options concerning skipping parts of agenda files."
391 :tag
"Org Agenda Skip"
394 (defcustom org-agenda-todo-list-sublevels t
395 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
396 When nil, the sublevels of a TODO entry are not checked, resulting in
397 potentially much shorter TODO lists."
398 :group
'org-agenda-skip
402 (defcustom org-agenda-todo-ignore-with-date nil
403 "Non-nil means, don't show entries with a date in the global todo list.
404 You can use this if you prefer to mark mere appointments with a TODO keyword,
405 but don't want them to show up in the TODO list.
406 When this is set, it also covers deadlines and scheduled items, the settings
407 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
409 :group
'org-agenda-skip
413 (defcustom org-agenda-todo-ignore-scheduled nil
414 "Non-nil means, don't show scheduled entries in the global todo list.
415 The idea behind this is that by scheduling it, you have already taken care
417 See also `org-agenda-todo-ignore-with-date'."
418 :group
'org-agenda-skip
422 (defcustom org-agenda-todo-ignore-deadlines nil
423 "Non-nil means, don't show near deadline entries in the global todo list.
424 Near means closer than `org-deadline-warning-days' days.
425 The idea behind this is that such items will appear in the agenda anyway.
426 See also `org-agenda-todo-ignore-with-date'."
427 :group
'org-agenda-skip
431 (defcustom org-agenda-skip-scheduled-if-done nil
432 "Non-nil means don't show scheduled items in agenda when they are done.
433 This is relevant for the daily/weekly agenda, not for the TODO list. And
434 it applies only to the actual date of the scheduling. Warnings about
435 an item with a past scheduling dates are always turned off when the item
437 :group
'org-agenda-skip
440 (defcustom org-agenda-skip-deadline-if-done nil
441 "Non-nil means don't show deadines when the corresponding item is done.
442 When nil, the deadline is still shown and should give you a happy feeling.
443 This is relevant for the daily/weekly agenda. And it applied only to the
444 actualy date of the deadline. Warnings about approching and past-due
445 deadlines are always turned off when the item is DONE."
446 :group
'org-agenda-skip
449 (defcustom org-agenda-skip-timestamp-if-done nil
450 "Non-nil means don't select item by timestamp or -range if it is DONE."
451 :group
'org-agenda-skip
454 (defcustom org-timeline-show-empty-dates
3
455 "Non-nil means, `org-timeline' also shows dates without an entry.
456 When nil, only the days which actually have entries are shown.
457 When t, all days between the first and the last date are shown.
458 When an integer, show also empty dates, but if there is a gap of more than
459 N days, just insert a special line indicating the size of the gap."
460 :group
'org-agenda-skip
462 (const :tag
"None" nil
)
464 (number :tag
"at most")))
467 (defgroup org-agenda-startup nil
468 "Options concerning initial settings in the Agenda in Org Mode."
469 :tag
"Org Agenda Startup"
472 (defcustom org-finalize-agenda-hook nil
473 "Hook run just before displaying an agenda buffer."
474 :group
'org-agenda-startup
477 (defcustom org-agenda-mouse-1-follows-link nil
478 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
479 A longer mouse click will still set point. Does not work on XEmacs.
480 Needs to be set before org.el is loaded."
481 :group
'org-agenda-startup
484 (defcustom org-agenda-start-with-follow-mode nil
485 "The initial value of follow-mode in a newly created agenda window."
486 :group
'org-agenda-startup
489 (defvar org-agenda-include-inactive-timestamps nil
490 "Non-nil means, include inactive time stamps in agenda and timeline.")
492 (defgroup org-agenda-windows nil
493 "Options concerning the windows used by the Agenda in Org Mode."
494 :tag
"Org Agenda Windows"
497 (defcustom org-agenda-window-setup
'reorganize-frame
498 "How the agenda buffer should be displayed.
499 Possible values for this option are:
501 current-window Show agenda in the current window, keeping all other windows.
502 other-frame Use `switch-to-buffer-other-frame' to display agenda.
503 other-window Use `switch-to-buffer-other-window' to display agenda.
504 reorganize-frame Show only two windows on the current frame, the current
505 window and the agenda.
506 See also the variable `org-agenda-restore-windows-after-quit'."
507 :group
'org-agenda-windows
509 (const current-window
)
512 (const reorganize-frame
)))
514 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
515 "The min and max height of the agenda window as a fraction of frame height.
516 The value of the variable is a cons cell with two numbers between 0 and 1.
517 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
518 :group
'org-agenda-windows
519 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
521 (defcustom org-agenda-restore-windows-after-quit nil
522 "Non-nil means, restore window configuration open exiting agenda.
523 Before the window configuration is changed for displaying the agenda,
524 the current status is recorded. When the agenda is exited with
525 `q' or `x' and this option is set, the old state is restored. If
526 `org-agenda-window-setup' is `other-frame', the value of this
527 option will be ignored.."
528 :group
'org-agenda-windows
531 (defgroup org-agenda-daily
/weekly nil
532 "Options concerning the daily/weekly agenda."
533 :tag
"Org Agenda Daily/Weekly"
536 (defcustom org-agenda-ndays
7
537 "Number of days to include in overview display.
539 :group
'org-agenda-daily
/weekly
542 (defcustom org-agenda-start-on-weekday
1
543 "Non-nil means, start the overview always on the specified weekday.
544 0 denotes Sunday, 1 denotes Monday etc.
545 When nil, always start on the current day."
546 :group
'org-agenda-daily
/weekly
547 :type
'(choice (const :tag
"Today" nil
)
548 (number :tag
"Weekday No.")))
550 (defcustom org-agenda-show-all-dates t
551 "Non-nil means, `org-agenda' shows every day in the selected range.
552 When nil, only the days which actually have entries are shown."
553 :group
'org-agenda-daily
/weekly
556 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
557 "Format string for displaying dates in the agenda.
558 Used by the daily/weekly agenda and by the timeline. This should be
559 a format string understood by `format-time-string', or a function returning
560 the formatted date as a string. The function must take a single argument,
561 a calendar-style date list like (month day year)."
562 :group
'org-agenda-daily
/weekly
564 (string :tag
"Format string")
565 (function :tag
"Function")))
567 (defun org-agenda-format-date-aligned (date)
568 "Format a date string for display in the daily/weekly agenda, or timeline.
569 This function makes sure that dates are aligned for easy reading."
571 (let* ((dayname (calendar-day-name date
))
573 (day-of-week (calendar-day-of-week date
))
575 (monthname (calendar-month-name month
))
577 (iso-week (org-days-to-iso-week
578 (calendar-absolute-from-gregorian date
)))
579 (weekyear (cond ((and (= month
1) (>= iso-week
52))
581 ((and (= month
12) (<= iso-week
1))
584 (weekstring (if (= day-of-week
1)
585 (format " W%02d" iso-week
)
587 (format "%-10s %2d %s %4d%s"
588 dayname day monthname year weekstring
)))
590 (defcustom org-agenda-weekend-days
'(6 0)
591 "Which days are weekend?
592 These days get the special face `org-agenda-date-weekend' in the agenda
593 and timeline buffers."
594 :group
'org-agenda-daily
/weekly
595 :type
'(set :greedy t
596 (const :tag
"Monday" 1)
597 (const :tag
"Tuesday" 2)
598 (const :tag
"Wednesday" 3)
599 (const :tag
"Thursday" 4)
600 (const :tag
"Friday" 5)
601 (const :tag
"Saturday" 6)
602 (const :tag
"Sunday" 0)))
604 (defcustom org-agenda-include-diary nil
605 "If non-nil, include in the agenda entries from the Emacs Calendar's diary."
606 :group
'org-agenda-daily
/weekly
609 (defcustom org-agenda-include-all-todo nil
610 "Set means weekly/daily agenda will always contain all TODO entries.
611 The TODO entries will be listed at the top of the agenda, before
612 the entries for specific days."
613 :group
'org-agenda-daily
/weekly
616 (defcustom org-agenda-repeating-timestamp-show-all t
617 "Non-nil means, show all occurences of a repeating stamp in the agenda.
618 When nil, only one occurence is shown, either today or the
619 nearest into the future."
620 :group
'org-agenda-daily
/weekly
623 (defcustom org-scheduled-past-days
10000
624 "No. of days to continue listing scheduled items that are not marked DONE.
625 When an item is scheduled on a date, it shows up in the agenda on this
626 day and will be listed until it is marked done for the number of days
628 :group
'org-agenda-daily
/weekly
631 (defcustom org-agenda-start-with-clockreport-mode nil
632 "The initial value of clockreport-mode in a newly created agenda window."
633 :group
'org-agenda-startup
634 :group
'org-agenda-daily
/weekly
637 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
638 "Property list with parameters for the clocktable in clockreport mode.
639 This is the display mode that shows a clock table in the daily/weekly
640 agenda, the properties for this dynamic block can be set here.
641 The usual clocktable parameters are allowed here, but you cannot set
642 the properties :name, :tstart, :tend, :block, and :scope - these will
643 be overwritten to make sure the content accurately reflects the
644 current display in the agenda."
645 :group
'org-agenda-daily
/weekly
649 (defgroup org-agenda-time-grid nil
650 "Options concerning the time grid in the Org-mode Agenda."
651 :tag
"Org Agenda Time Grid"
654 (defcustom org-agenda-use-time-grid t
655 "Non-nil means, show a time grid in the agenda schedule.
656 A time grid is a set of lines for specific times (like every two hours between
657 8:00 and 20:00). The items scheduled for a day at specific times are
658 sorted in between these lines.
659 For details about when the grid will be shown, and what it will look like, see
660 the variable `org-agenda-time-grid'."
661 :group
'org-agenda-time-grid
664 (defcustom org-agenda-time-grid
665 '((daily today require-timed
)
667 (800 1000 1200 1400 1600 1800 2000))
669 "The settings for time grid for agenda display.
670 This is a list of three items. The first item is again a list. It contains
671 symbols specifying conditions when the grid should be displayed:
673 daily if the agenda shows a single day
674 weekly if the agenda shows an entire week
675 today show grid on current date, independent of daily/weekly display
676 require-timed show grid only if at least one item has a time specification
678 The second item is a string which will be places behing the grid time.
680 The third item is a list of integers, indicating the times that should have
682 :group
'org-agenda-time-grid
685 (set :greedy t
:tag
"Grid Display Options"
686 (const :tag
"Show grid in single day agenda display" daily
)
687 (const :tag
"Show grid in weekly agenda display" weekly
)
688 (const :tag
"Always show grid for today" today
)
689 (const :tag
"Show grid only if any timed entries are present"
691 (const :tag
"Skip grid times already present in an entry"
693 (string :tag
"Grid String")
694 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
696 (defgroup org-agenda-sorting nil
697 "Options concerning sorting in the Org-mode Agenda."
698 :tag
"Org Agenda Sorting"
701 (defcustom org-agenda-sorting-strategy
702 '((agenda time-up category-keep priority-down
)
703 (todo category-keep priority-down
)
704 (tags category-keep priority-down
)
705 (search category-keep
))
706 "Sorting structure for the agenda items of a single day.
707 This is a list of symbols which will be used in sequence to determine
708 if an entry should be listed before another entry. The following
709 symbols are recognized:
711 time-up Put entries with time-of-day indications first, early first
712 time-down Put entries with time-of-day indications first, late first
713 category-keep Keep the default order of categories, corresponding to the
714 sequence in `org-agenda-files'.
715 category-up Sort alphabetically by category, A-Z.
716 category-down Sort alphabetically by category, Z-A.
717 tag-up Sort alphabetically by last tag, A-Z.
718 tag-down Sort alphabetically by last tag, Z-A.
719 priority-up Sort numerically by priority, high priority last.
720 priority-down Sort numerically by priority, high priority first.
722 The different possibilities will be tried in sequence, and testing stops
723 if one comparison returns a \"not-equal\". For example, the default
724 '(time-up category-keep priority-down)
725 means: Pull out all entries having a specified time of day and sort them,
726 in order to make a time schedule for the current day the first thing in the
727 agenda listing for the day. Of the entries without a time indication, keep
728 the grouped in categories, don't sort the categories, but keep them in
729 the sequence given in `org-agenda-files'. Within each category sort by
732 Leaving out `category-keep' would mean that items will be sorted across
733 categories by priority.
735 Instead of a single list, this can also be a set of list for specific
736 contents, with a context symbol in the car of the list, any of
737 `agenda', `todo', `tags' for the corresponding agenda views."
738 :group
'org-agenda-sorting
740 (repeat :tag
"General" ,org-sorting-choice
)
741 (list :tag
"Individually"
742 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
743 (repeat ,org-sorting-choice
))
744 (cons (const :tag
"Strategy for TODO lists" todo
)
745 (repeat ,org-sorting-choice
))
746 (cons (const :tag
"Strategy for Tags matches" tags
)
747 (repeat ,org-sorting-choice
)))))
749 (defcustom org-sort-agenda-notime-is-late t
750 "Non-nil means, items without time are considered late.
751 This is only relevant for sorting. When t, items which have no explicit
752 time like 15:30 will be considered as 99:01, i.e. later than any items which
753 do have a time. When nil, the default time is before 0:00. You can use this
754 option to decide if the schedule for today should come before or after timeless
756 :group
'org-agenda-sorting
759 (defgroup org-agenda-line-format nil
760 "Options concerning the entry prefix in the Org-mode agenda display."
761 :tag
"Org Agenda Line Format"
764 (defcustom org-agenda-prefix-format
765 '((agenda .
" %-12:c%?-12t% s")
769 (search .
" %-12:c"))
770 "Format specifications for the prefix of items in the agenda views.
771 An alist with four entries, for the different agenda types. The keys to the
772 sublists are `agenda', `timeline', `todo', and `tags'. The values
774 This format works similar to a printf format, with the following meaning:
776 %c the category of the item, \"Diary\" for entries from the diary, or
777 as given by the CATEGORY keyword or derived from the file name.
778 %T the *last* tag of the item. Last because inherited tags come
780 %t the time-of-day specification if one applies to the entry, in the
782 %s Scheduling/Deadline information, a short string
784 All specifiers work basically like the standard `%s' of printf, but may
785 contain two additional characters: A question mark just after the `%' and
786 a whitespace/punctuation character just before the final letter.
788 If the first character after `%' is a question mark, the entire field
789 will only be included if the corresponding value applies to the
790 current entry. This is useful for fields which should have fixed
791 width when present, but zero width when absent. For example,
792 \"%?-12t\" will result in a 12 character time field if a time of the
793 day is specified, but will completely disappear in entries which do
796 If there is punctuation or whitespace character just before the final
797 format letter, this character will be appended to the field value if
798 the value is not empty. For example, the format \"%-12:c\" leads to
799 \"Diary: \" if the category is \"Diary\". If the category were be
800 empty, no additional colon would be interted.
802 The default value of this option is \" %-12:c%?-12t% s\", meaning:
803 - Indent the line with two space characters
804 - Give the category in a 12 chars wide field, padded with whitespace on
805 the right (because of `-'). Append a colon if there is a category
807 - If there is a time-of-day, put it into a 12 chars wide field. If no
808 time, don't put in an empty field, just skip it (because of '?').
809 - Finally, put the scheduling information and append a whitespace.
811 As another example, if you don't want the time-of-day of entries in
812 the prefix, you could use:
814 (setq org-agenda-prefix-format \" %-11:c% s\")
816 See also the variables `org-agenda-remove-times-when-in-prefix' and
817 `org-agenda-remove-tags'."
819 (string :tag
"General format")
820 (list :greedy t
:tag
"View dependent"
821 (cons (const agenda
) (string :tag
"Format"))
822 (cons (const timeline
) (string :tag
"Format"))
823 (cons (const todo
) (string :tag
"Format"))
824 (cons (const tags
) (string :tag
"Format"))
825 (cons (const search
) (string :tag
"Format"))))
826 :group
'org-agenda-line-format
)
828 (defvar org-prefix-format-compiled nil
829 "The compiled version of the most recently used prefix format.
830 See the variable `org-agenda-prefix-format'.")
832 (defcustom org-agenda-todo-keyword-format
"%-1s"
833 "Format for the TODO keyword in agenda lines.
834 Set this to something like \"%-12s\" if you want all TODO keywords
835 to occupy a fixed space in the agenda display."
836 :group
'org-agenda-line-format
839 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
840 "Text preceeding scheduled items in the agenda view.
841 This is a list with two strings. The first applies when the item is
842 scheduled on the current day. The second applies when it has been scheduled
843 previously, it may contain a %d to capture how many days ago the item was
845 :group
'org-agenda-line-format
847 (string :tag
"Scheduled today ")
848 (string :tag
"Scheduled previously")))
850 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
851 "Text preceeding deadline items in the agenda view.
852 This is a list with two strings. The first applies when the item has its
853 deadline on the current day. The second applies when it is in the past or
854 in the future, it may contain %d to capture how many days away the deadline
856 :group
'org-agenda-line-format
858 (string :tag
"Deadline today ")
859 (choice :tag
"Deadline relative"
860 (string :tag
"Format string")
863 (defcustom org-agenda-remove-times-when-in-prefix t
864 "Non-nil means, remove duplicate time specifications in agenda items.
865 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
866 time-of-day specification in a headline or diary entry is extracted and
867 placed into the prefix. If this option is non-nil, the original specification
868 \(a timestamp or -range, or just a plain time(range) specification like
869 11:30-4pm) will be removed for agenda display. This makes the agenda less
871 The option can be t or nil. It may also be the symbol `beg', indicating
872 that the time should only be removed what it is located at the beginning of
873 the headline/diary entry."
874 :group
'org-agenda-line-format
876 (const :tag
"Always" t
)
877 (const :tag
"Never" nil
)
878 (const :tag
"When at beginning of entry" beg
)))
881 (defcustom org-agenda-default-appointment-duration nil
882 "Default duration for appointments that only have a starting time.
883 When nil, no duration is specified in such cases.
884 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
885 :group
'org-agenda-line-format
887 (integer :tag
"Minutes")
888 (const :tag
"No default duration")))
891 (defcustom org-agenda-remove-tags nil
892 "Non-nil means, remove the tags from the headline copy in the agenda.
893 When this is the symbol `prefix', only remove tags when
894 `org-agenda-prefix-format' contains a `%T' specifier."
895 :group
'org-agenda-line-format
897 (const :tag
"Always" t
)
898 (const :tag
"Never" nil
)
899 (const :tag
"When prefix format contains %T" prefix
)))
901 (if (fboundp 'defvaralias
)
902 (defvaralias 'org-agenda-remove-tags-when-in-prefix
903 'org-agenda-remove-tags
))
905 (defcustom org-agenda-tags-column -
80
906 "Shift tags in agenda items to this column.
907 If this number is positive, it specifies the column. If it is negative,
908 it means that the tags should be flushright to that column. For example,
909 -80 works well for a normal 80 character screen."
910 :group
'org-agenda-line-format
913 (if (fboundp 'defvaralias
)
914 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
916 (defcustom org-agenda-fontify-priorities t
917 "Non-nil means, highlight low and high priorities in agenda.
918 When t, the highest priority entries are bold, lowest priority italic.
919 This may also be an association list of priority faces. The face may be
920 a names face, or a list like `(:background \"Red\")'."
921 :group
'org-agenda-line-format
923 (const :tag
"Never" nil
)
924 (const :tag
"Defaults" t
)
925 (repeat :tag
"Specify"
926 (list (character :tag
"Priority" :value ?A
)
927 (sexp :tag
"face")))))
934 (defun org-add-agenda-custom-command (entry)
935 "Replace or add a command in `org-agenda-custom-commands'.
936 This is mostly for hacking and trying a new command - once the command
937 works you probably want to add it to `org-agenda-custom-commands' for good."
938 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
940 (setcdr ass
(cdr entry
))
941 (push entry org-agenda-custom-commands
))))
943 ;;; Define the Org-agenda-mode
945 (defvar org-agenda-mode-map
(make-sparse-keymap)
946 "Keymap for `org-agenda-mode'.")
948 (defvar org-agenda-menu
) ; defined later in this file.
949 (defvar org-agenda-follow-mode nil
)
950 (defvar org-agenda-clockreport-mode nil
)
951 (defvar org-agenda-show-log nil
)
952 (defvar org-agenda-redo-command nil
)
953 (defvar org-agenda-query-string nil
)
954 (defvar org-agenda-mode-hook nil
)
955 (defvar org-agenda-type nil
)
956 (defvar org-agenda-force-single-file nil
)
958 (defun org-agenda-mode ()
959 "Mode for time-sorted view on action items in Org-mode files.
961 The following commands are available:
963 \\{org-agenda-mode-map}"
965 (kill-all-local-variables)
966 (setq org-agenda-undo-list nil
967 org-agenda-pending-undo-list nil
)
968 (setq major-mode
'org-agenda-mode
)
969 ;; Keep global-font-lock-mode from turning on font-lock-mode
970 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
971 (setq mode-name
"Org-Agenda")
972 (use-local-map org-agenda-mode-map
)
973 (easy-menu-add org-agenda-menu
)
974 (if org-startup-truncated
(setq truncate-lines t
))
975 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
976 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
977 ;; Make sure properties are removed when copying text
978 (when (boundp 'buffer-substring-filters
)
979 (org-set-local 'buffer-substring-filters
981 (set-text-properties 0 (length x
) nil x
) x
)
982 buffer-substring-filters
)))
983 (unless org-agenda-keep-modes
984 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
985 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
986 org-agenda-show-log nil
))
988 '("Agenda") "Agenda Files"
992 (if (get 'org-agenda-files
'org-restrict
)
993 "Restricted to single file"
995 '(org-edit-agenda-file-list)
996 (not (get 'org-agenda-files
'org-restrict
)))
998 (mapcar 'org-file-menu-entry
(org-agenda-files))))
999 (org-agenda-set-mode-name)
1001 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1002 (list 'org-agenda-mode-hook
)))
1004 (substitute-key-definition 'undo
'org-agenda-undo
1005 org-agenda-mode-map global-map
)
1006 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1007 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1008 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1009 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1010 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1011 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1012 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1013 (org-defkey org-agenda-mode-map
"A" 'org-agenda-archive-to-archive-sibling
)
1014 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1015 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1016 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1017 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1018 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1019 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1020 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1021 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1022 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1023 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1024 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1025 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1026 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1027 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1028 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1029 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1030 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1031 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1032 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1033 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1034 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-date-later
)
1035 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-date-earlier
)
1036 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-date-later
)
1037 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-date-earlier
)
1039 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1040 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1041 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1042 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1043 (while l
(org-defkey org-agenda-mode-map
1044 (int-to-string (pop l
)) 'digit-argument
)))
1046 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1047 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1048 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1049 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1050 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1051 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1052 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1053 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1054 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1055 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1056 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1057 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1058 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1059 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1060 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1061 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1062 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1063 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1064 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1065 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1066 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1067 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1068 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1069 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1070 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1071 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1072 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1073 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1074 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1075 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1076 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1077 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1078 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1079 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1080 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1081 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1082 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1083 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1084 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1085 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1086 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1087 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1088 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1089 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1090 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1092 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1093 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1094 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1095 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1097 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1098 "Local keymap for agenda entries from Org-mode.")
1100 (org-defkey org-agenda-keymap
1101 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1102 (org-defkey org-agenda-keymap
1103 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1104 (when org-agenda-mouse-1-follows-link
1105 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1106 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1110 ["Show" org-agenda-show t
]
1111 ["Go To (other window)" org-agenda-goto t
]
1112 ["Go To (this window)" org-agenda-switch-to t
]
1113 ["Follow Mode" org-agenda-follow-mode
1114 :style toggle
:selected org-agenda-follow-mode
:active t
]
1115 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1117 ["Cycle TODO" org-agenda-todo t
]
1119 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t
]
1120 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t
]
1121 ["Archive subtree" org-agenda-archive t
])
1122 ["Delete subtree" org-agenda-kill t
]
1123 ["Add note" org-agenda-add-note t
]
1125 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1126 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1127 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1128 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1130 ("Tags and Properties"
1131 ["Show all Tags" org-agenda-show-tags t
]
1132 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1133 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1135 ["Column View" org-columns t
])
1137 ["Schedule" org-agenda-schedule t
]
1138 ["Set Deadline" org-agenda-deadline t
]
1140 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1141 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1142 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1144 ["Clock in" org-agenda-clock-in t
]
1145 ["Clock out" org-agenda-clock-out t
]
1146 ["Clock cancel" org-agenda-clock-cancel t
]
1147 ["Goto running clock" org-clock-goto t
])
1149 ["Set Priority" org-agenda-priority t
]
1150 ["Increase Priority" org-agenda-priority-up t
]
1151 ["Decrease Priority" org-agenda-priority-down t
]
1152 ["Show Priority" org-agenda-show-priority t
])
1154 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1155 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1156 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1157 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1158 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1159 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1161 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1164 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1165 :style radio
:selected
(equal org-agenda-ndays
1)]
1166 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1167 :style radio
:selected
(equal org-agenda-ndays
7)]
1168 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1169 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1170 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1171 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1173 ["Show Logbook entries" org-agenda-log-mode
1174 :style toggle
:selected org-agenda-show-log
:active
(org-agenda-check-type nil
'agenda
'timeline
)]
1175 ["Show clock report" org-agenda-clockreport-mode
1176 :style toggle
:selected org-agenda-clockreport-mode
:active
(org-agenda-check-type nil
'agenda
)]
1177 ["Include Diary" org-agenda-toggle-diary
1178 :style toggle
:selected org-agenda-include-diary
:active
(org-agenda-check-type nil
'agenda
)]
1179 ["Use Time Grid" org-agenda-toggle-time-grid
1180 :style toggle
:selected org-agenda-use-time-grid
:active
(org-agenda-check-type nil
'agenda
)])
1181 ["Write view to file" org-write-agenda t
]
1182 ["Rebuild buffer" org-agenda-redo t
]
1183 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1185 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1187 ["Quit" org-agenda-quit t
]
1188 ["Exit and Release Buffers" org-agenda-exit t
]
1193 (defvar org-agenda-allow-remote-undo t
1194 "Non-nil means, allow remote undo from the agenda buffer.")
1195 (defvar org-agenda-undo-list nil
1196 "List of undoable operations in the agenda since last refresh.")
1197 (defvar org-agenda-undo-has-started-in nil
1198 "Buffers that have already seen `undo-start' in the current undo sequence.")
1199 (defvar org-agenda-pending-undo-list nil
1200 "In a series of undo commands, this is the list of remaning undo items.")
1203 (defun org-agenda-undo ()
1204 "Undo a remote editing step in the agenda.
1205 This undoes changes both in the agenda buffer and in the remote buffer
1206 that have been changed along."
1208 (or org-agenda-allow-remote-undo
1209 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1210 (if (not (eq this-command last-command
))
1211 (setq org-agenda-undo-has-started-in nil
1212 org-agenda-pending-undo-list org-agenda-undo-list
))
1213 (if (not org-agenda-pending-undo-list
)
1214 (error "No further undo information"))
1215 (let* ((entry (pop org-agenda-pending-undo-list
))
1216 buf line cmd rembuf
)
1217 (setq cmd
(pop entry
) line
(pop entry
))
1218 (setq rembuf
(nth 2 entry
))
1219 (org-with-remote-undo rembuf
1220 (while (bufferp (setq buf
(pop entry
)))
1222 (with-current-buffer buf
1223 (let ((last-undo-buffer buf
)
1224 (inhibit-read-only t
))
1225 (unless (memq buf org-agenda-undo-has-started-in
)
1226 (push buf org-agenda-undo-has-started-in
)
1227 (make-local-variable 'pending-undo-list
)
1229 (while (and pending-undo-list
1230 (listp pending-undo-list
)
1231 (not (car pending-undo-list
)))
1232 (pop pending-undo-list
))
1235 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1237 (defun org-verify-change-for-undo (l1 l2
)
1238 "Verify that a real change occurred between the undo lists L1 and L2."
1239 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1240 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1245 (defvar org-agenda-restrict nil
)
1246 (defvar org-agenda-restrict-begin
(make-marker))
1247 (defvar org-agenda-restrict-end
(make-marker))
1248 (defvar org-agenda-last-dispatch-buffer nil
)
1249 (defvar org-agenda-overriding-restriction nil
)
1252 (defun org-agenda (arg &optional keys restriction
)
1253 "Dispatch agenda commands to collect entries to the agenda buffer.
1254 Prompts for a command to execute. Any prefix arg will be passed
1255 on to the selected command. The default selections are:
1257 a Call `org-agenda-list' to display the agenda for current day or week.
1258 t Call `org-todo-list' to display the global todo list.
1259 T Call `org-todo-list' to display the global todo list, select only
1260 entries with a specific TODO keyword (the user gets a prompt).
1261 m Call `org-tags-view' to display headlines with tags matching
1262 a condition (the user is prompted for the condition).
1263 M Like `m', but select only TODO entries, no ordinary headlines.
1264 L Create a timeline for the current buffer.
1265 e Export views to associated files.
1267 More commands can be added by configuring the variable
1268 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1269 searches can be pre-defined in this way.
1271 If the current buffer is in Org-mode and visiting a file, you can also
1272 first press `<' once to indicate that the agenda should be temporarily
1273 \(until the next use of \\[org-agenda]) restricted to the current file.
1274 Pressing `<' twice means to restrict to the current subtree or region
1278 (let* ((prefix-descriptions nil
)
1279 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1280 (org-agenda-custom-commands
1281 ;; normalize different versions
1285 (cond ((stringp (cdr x
))
1286 (push x prefix-descriptions
)
1288 ((stringp (nth 1 x
)) x
)
1289 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1290 (t (cons (car x
) (cons "" (cdr x
))))))
1291 org-agenda-custom-commands
)))
1292 (buf (current-buffer))
1293 (bfn (buffer-file-name (buffer-base-buffer)))
1294 entry key type match lprops ans
)
1295 ;; Turn off restriction unless there is an overriding one
1296 (unless org-agenda-overriding-restriction
1297 (put 'org-agenda-files
'org-restrict nil
)
1298 (setq org-agenda-restrict nil
)
1299 (move-marker org-agenda-restrict-begin nil
)
1300 (move-marker org-agenda-restrict-end nil
))
1301 ;; Delete old local properties
1302 (put 'org-agenda-redo-command
'org-lprops nil
)
1303 ;; Remember where this call originated
1304 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1306 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1308 restriction
(cdr ans
)))
1309 ;; Estabish the restriction, if any
1310 (when (and (not org-agenda-overriding-restriction
) restriction
)
1311 (put 'org-agenda-files
'org-restrict
(list bfn
))
1313 ((eq restriction
'region
)
1314 (setq org-agenda-restrict t
)
1315 (move-marker org-agenda-restrict-begin
(region-beginning))
1316 (move-marker org-agenda-restrict-end
(region-end)))
1317 ((eq restriction
'subtree
)
1319 (setq org-agenda-restrict t
)
1320 (org-back-to-heading t
)
1321 (move-marker org-agenda-restrict-begin
(point))
1322 (move-marker org-agenda-restrict-end
1323 (progn (org-end-of-subtree t
)))))))
1325 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1326 ;; For example the todo list should not need it (but does...)
1328 ((setq entry
(assoc keys org-agenda-custom-commands
))
1329 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1331 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1332 (put 'org-agenda-redo-command
'org-lprops lprops
)
1335 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1337 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1339 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1341 (org-let lprops
'(org-agenda-list-stuck-projects
1342 current-prefix-arg
)))
1344 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1345 ((eq type
'tags-todo
)
1346 (org-let lprops
'(org-tags-view '(4) match
)))
1348 (org-let lprops
'(org-todo-list match
)))
1349 ((eq type
'tags-tree
)
1350 (org-check-for-org-mode)
1351 (org-let lprops
'(org-tags-sparse-tree current-prefix-arg match
)))
1352 ((eq type
'todo-tree
)
1353 (org-check-for-org-mode)
1355 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1356 (regexp-quote match
) "\\>"))))
1357 ((eq type
'occur-tree
)
1358 (org-check-for-org-mode)
1359 (org-let lprops
'(org-occur match
)))
1361 (org-let lprops
'(funcall type match
)))
1363 (org-let lprops
'(funcall type match
)))
1364 (t (error "Invalid custom agenda command type %s" type
))))
1365 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1367 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1368 (customize-variable 'org-agenda-custom-commands
))
1369 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1370 ((equal keys
"s") (call-interactively 'org-search-view
))
1371 ((equal keys
"t") (call-interactively 'org-todo-list
))
1372 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1373 ((equal keys
"m") (call-interactively 'org-tags-view
))
1374 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1375 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1377 (unless (org-mode-p)
1378 (error "This is not an Org-mode file"))
1380 (put 'org-agenda-files
'org-restrict
(list bfn
))
1381 (org-call-with-arg 'org-timeline arg
)))
1382 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1383 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1384 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1385 (t (error "Invalid agenda key"))))))
1387 (defun org-agenda-normalize-custom-commands (cmds)
1391 (cond ((stringp (cdr x
)) nil
)
1392 ((stringp (nth 1 x
)) x
)
1393 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1394 (t (cons (car x
) (cons "" (cdr x
))))))
1397 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1398 "The user interface for selecting an agenda command."
1400 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1401 (restrict-ok (and bfn
(org-mode-p)))
1402 (region-p (org-region-active-p))
1403 (custom org-agenda-custom-commands
)
1405 restriction second-time
1406 c entry key type match prefixes rmheader header-end custom1 desc
)
1407 (save-window-excursion
1408 (delete-other-windows)
1409 (org-switch-to-buffer-other-window " *Agenda Commands*")
1411 (insert (eval-when-compile
1414 Press key for an agenda command: < Buffer,subtree/region restriction
1415 -------------------------------- > Remove restriction
1416 a Agenda for current week or day e Export agenda views
1417 t List of all TODO entries T Entries with special TODO kwd
1418 m Match a TAGS query M Like m, but only TODO entries
1419 L Timeline for current buffer # List stuck projects (!=configure)
1420 s Search for keywords C Configure custom agenda commands
1424 (while (string-match
1425 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1427 (setq start
(match-end 0))
1428 (add-text-properties (match-beginning 2) (match-end 2)
1429 '(face bold
) header
))
1431 (setq header-end
(move-marker (make-marker) (point)))
1433 (setq custom1 custom
)
1434 (when (eq rmheader t
)
1436 (re-search-forward ":" nil t
)
1437 (delete-region (match-end 0) (point-at-eol))
1440 (delete-region (match-end 0) (point-at-eol))
1441 (move-marker header-end
(match-end 0)))
1442 (goto-char header-end
)
1443 (delete-region (point) (point-max))
1444 (while (setq entry
(pop custom1
))
1445 (setq key
(car entry
) desc
(nth 1 entry
)
1446 type
(nth 2 entry
) match
(nth 3 entry
))
1447 (if (> (length key
) 1)
1448 (add-to-list 'prefixes
(string-to-char key
))
1452 (org-add-props (copy-sequence key
)
1455 ((string-match "\\S-" desc
) desc
)
1456 ((eq type
'agenda
) "Agenda for current week or day")
1457 ((eq type
'alltodo
) "List of all TODO entries")
1458 ((eq type
'search
) "Word search")
1459 ((eq type
'stuck
) "List of stuck projects")
1460 ((eq type
'todo
) "TODO keyword")
1461 ((eq type
'tags
) "Tags query")
1462 ((eq type
'tags-todo
) "Tags (TODO)")
1463 ((eq type
'tags-tree
) "Tags tree")
1464 ((eq type
'todo-tree
) "TODO kwd tree")
1465 ((eq type
'occur-tree
) "Occur tree")
1466 ((functionp type
) (if (symbolp type
)
1468 "Lambda expression"))
1472 (org-add-props match nil
'face
'org-warning
))
1474 (format "set of %d commands" (length match
)))
1480 (org-add-props (char-to-string x
)
1482 (or (cdr (assoc (concat selstring
(char-to-string x
))
1483 prefix-descriptions
))
1486 (goto-char (point-min))
1487 (when (fboundp 'fit-window-to-buffer
)
1489 (if (not (pos-visible-in-window-p (point-max)))
1490 (fit-window-to-buffer))
1491 (setq second-time t
)
1492 (fit-window-to-buffer)))
1493 (message "Press key for agenda command%s:"
1494 (if (or restrict-ok org-agenda-overriding-restriction
)
1495 (if org-agenda-overriding-restriction
1496 " (restriction lock active)"
1498 (format " (restricted to %s)" restriction
)
1501 (setq c
(read-char-exclusive))
1504 ((assoc (char-to-string c
) custom
)
1505 (setq selstring
(concat selstring
(char-to-string c
)))
1506 (throw 'exit
(cons selstring restriction
)))
1508 (setq selstring
(concat selstring
(char-to-string c
))
1510 rmheader
(or rmheader t
)
1511 custom
(delq nil
(mapcar
1513 (if (or (= (length (car x
)) 1)
1514 (/= (string-to-char (car x
)) c
))
1516 (cons (substring (car x
) 1) (cdr x
))))
1518 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1519 (message "Restriction is only possible in Org-mode buffers")
1522 (org-agenda-remove-restriction-lock 'noupdate
)
1523 (setq restriction
'buffer
))
1525 (org-agenda-remove-restriction-lock 'noupdate
)
1526 (setq restriction
(if region-p
'region
'subtree
)))
1528 (org-agenda-remove-restriction-lock 'noupdate
)
1531 ((eq restriction
'buffer
)
1532 (if region-p
'region
'subtree
))
1533 ((memq restriction
'(subtree region
))
1537 (org-agenda-remove-restriction-lock 'noupdate
)
1538 (setq restriction nil
))
1539 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1540 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1541 ((and (> (length selstring
) 0) (eq c ?\d
))
1543 (org-agenda-get-restriction-and-command prefix-descriptions
))
1545 ((equal c ?q
) (error "Abort"))
1546 (t (error "Invalid key %c" c
))))))))
1548 (defun org-run-agenda-series (name series
)
1549 (org-prepare-agenda name
)
1550 (let* ((org-agenda-multi t
)
1551 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1553 (gprops (nth 1 series
))
1554 match
;; The byte compiler incorrectly complains about this. Keep it!
1556 (while (setq cmd
(pop cmds
))
1557 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1560 (org-let2 gprops lprops
1561 '(call-interactively 'org-agenda-list
)))
1563 (org-let2 gprops lprops
1564 '(call-interactively 'org-todo-list
)))
1566 (org-let2 gprops lprops
1567 '(org-search-view current-prefix-arg match nil
)))
1569 (org-let2 gprops lprops
1570 '(call-interactively 'org-agenda-list-stuck-projects
)))
1572 (org-let2 gprops lprops
1573 '(org-tags-view current-prefix-arg match
)))
1574 ((eq type
'tags-todo
)
1575 (org-let2 gprops lprops
1576 '(org-tags-view '(4) match
)))
1578 (org-let2 gprops lprops
1579 '(org-todo-list match
)))
1581 (org-let2 gprops lprops
1582 '(funcall type match
)))
1583 (t (error "Invalid type in command series"))))
1585 (setq org-agenda-redo-command redo
)
1586 (goto-char (point-min)))
1587 (org-finalize-agenda))
1590 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1591 "Run an agenda command in batch mode and send the result to STDOUT.
1592 If CMD-KEY is a string of length 1, it is used as a key in
1593 `org-agenda-custom-commands' and triggers this command. If it is a
1594 longer string it is used as a tags/todo match string.
1595 Paramters are alternating variable names and values that will be bound
1596 before running the agenda command."
1599 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1600 (if (> (length cmd-key
) 2)
1601 (eval (list 'let
(nreverse pars
)
1602 (list 'org-tags-view nil cmd-key
)))
1603 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1604 (set-buffer org-agenda-buffer-name
)
1605 (princ (org-encode-for-stdout (buffer-string)))))
1607 (defun org-encode-for-stdout (string)
1608 (if (fboundp 'encode-coding-string
)
1609 (encode-coding-string string buffer-file-coding-system
)
1612 (defvar org-agenda-info nil
)
1615 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1616 "Run an agenda command in batch mode and send the result to STDOUT.
1617 If CMD-KEY is a string of length 1, it is used as a key in
1618 `org-agenda-custom-commands' and triggers this command. If it is a
1619 longer string it is used as a tags/todo match string.
1620 Paramters are alternating variable names and values that will be bound
1621 before running the agenda command.
1623 The output gives a line for each selected agenda item. Each
1624 item is a list of comma-separated values, like this:
1626 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1628 category The category of the item
1629 head The headline, without TODO kwd, TAGS and PRIORITY
1630 type The type of the agenda entry, can be
1631 todo selected in TODO match
1632 tagsmatch selected in tags match
1633 diary imported from diary
1634 deadline a deadline on given date
1635 scheduled scheduled on given date
1636 timestamp entry has timestamp on given date
1637 closed entry was closed on given date
1638 upcoming-deadline warning about deadline
1639 past-scheduled forwarded scheduled item
1640 block entry has date block including g. date
1641 todo The todo keyword, if any
1642 tags All tags including inherited ones, separated by colons
1643 date The relevant date, like 2007-2-14
1644 time The time, like 15:00-16:50
1645 extra Sting with extra planning info
1646 priority-l The priority letter if any was given
1647 priority-n The computed numerical priority
1648 agenda-day The day in the agenda where this is listed"
1652 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1653 (push (list 'org-agenda-remove-tags t
) pars
)
1654 (if (> (length cmd-key
) 2)
1655 (eval (list 'let
(nreverse pars
)
1656 (list 'org-tags-view nil cmd-key
)))
1657 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1658 (set-buffer org-agenda-buffer-name
)
1659 (let* ((lines (org-split-string (buffer-string) "\n"))
1661 (while (setq line
(pop lines
))
1663 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1664 (setq org-agenda-info
1665 (org-fix-agenda-info (text-properties-at 0 line
)))
1667 (org-encode-for-stdout
1668 (mapconcat 'org-agenda-export-csv-mapper
1669 '(org-category txt type todo tags date time-of-day extra
1670 priority-letter priority agenda-day
)
1674 (defun org-fix-agenda-info (props)
1675 "Make sure all properties on an agenda item have a canonical form,
1676 so the export commands can easily use it."
1678 (when (setq tmp
(plist-get props
'tags
))
1679 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1680 (when (setq tmp
(plist-get props
'date
))
1681 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1682 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1683 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
1685 (setq tmp
(calendar-date-string tmp
)))
1686 (setq props
(plist-put props
'date tmp
)))
1687 (when (setq tmp
(plist-get props
'day
))
1688 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1689 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1690 (setq tmp
(calendar-date-string tmp
)))
1691 (setq props
(plist-put props
'day tmp
))
1692 (setq props
(plist-put props
'agenda-day tmp
)))
1693 (when (setq tmp
(plist-get props
'txt
))
1694 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
1695 (plist-put props
'priority-letter
(match-string 1 tmp
))
1696 (setq tmp
(replace-match "" t t tmp
)))
1697 (when (and (setq re
(plist-get props
'org-todo-regexp
))
1698 (setq re
(concat "\\`\\.*" re
" ?"))
1699 (string-match re tmp
))
1700 (plist-put props
'todo
(match-string 1 tmp
))
1701 (setq tmp
(replace-match "" t t tmp
)))
1702 (plist-put props
'txt tmp
)))
1705 (defun org-agenda-export-csv-mapper (prop)
1706 (let ((res (plist-get org-agenda-info prop
)))
1711 (t (prin1-to-string res
))))
1712 (while (string-match "," res
)
1713 (setq res
(replace-match ";" t t res
)))
1718 (defun org-store-agenda-views (&rest parameters
)
1720 (eval (list 'org-batch-store-agenda-views
)))
1722 ;; FIXME, why is this a macro?????
1724 (defmacro org-batch-store-agenda-views
(&rest parameters
)
1725 "Run all custom agenda commands that have a file argument."
1726 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
1728 (dir default-directory
)
1729 pars cmd thiscmdkey files opts
)
1731 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1732 (setq pars
(reverse pars
))
1733 (save-window-excursion
1735 (setq cmd
(pop cmds
)
1736 thiscmdkey
(car cmd
)
1739 (if (stringp files
) (setq files
(list files
)))
1741 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1742 (list 'org-agenda nil thiscmdkey
)))
1743 (set-buffer org-agenda-buffer-name
)
1745 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1746 (list 'org-write-agenda
1747 (expand-file-name (pop files
) dir
) t
))))
1748 (and (get-buffer org-agenda-buffer-name
)
1749 (kill-buffer org-agenda-buffer-name
)))))))
1751 (defun org-write-agenda (file &optional nosettings
)
1752 "Write the current buffer (an agenda view) as a file.
1753 Depending on the extension of the file name, plain text (.txt),
1754 HTML (.html or .htm) or Postscript (.ps) is produced.
1755 If the extension is .ics, run icalendar export over all files used
1756 to construct the agenda and limit the export to entries listed in the
1758 If NOSETTINGS is given, do not scope the settings of
1759 `org-agenda-exporter-settings' into the export commands. This is used when
1760 the settings have already been scoped and we do not wish to overrule other,
1761 higher priority settings."
1762 (interactive "FWrite agenda to file: ")
1763 (if (not (file-writable-p file
))
1764 (error "Cannot write agenda to file %s" file
))
1766 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
1767 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
1768 (org-let (if nosettings nil org-agenda-exporter-settings
)
1770 (save-window-excursion
1772 ((string-match "\\.html?\\'" file
)
1773 (set-buffer (htmlize-buffer (current-buffer)))
1775 (when (and org-agenda-export-html-style
1776 (string-match "<style>" org-agenda-export-html-style
))
1777 ;; replace <style> section with org-agenda-export-html-style
1778 (goto-char (point-min))
1779 (kill-region (- (search-forward "<style") 6)
1780 (search-forward "</style>"))
1781 (insert org-agenda-export-html-style
))
1783 (kill-buffer (current-buffer))
1784 (message "HTML written to %s" file
))
1785 ((string-match "\\.ps\\'" file
)
1786 (ps-print-buffer-with-faces file
)
1787 (message "Postscript written to %s" file
))
1788 ((string-match "\\.ics\\'" file
)
1789 (let ((org-agenda-marker-table
1790 (org-create-marker-find-array
1791 (org-agenda-collect-markers)))
1792 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
1793 (org-combined-agenda-icalendar-file file
))
1794 (apply 'org-export-icalendar
'combine
(org-agenda-files))))
1796 (let ((bs (buffer-string)))
1800 (kill-buffer (current-buffer))
1801 (message "Plain text written to %s" file
))))))
1802 (set-buffer org-agenda-buffer-name
)))
1804 (defun org-agenda-collect-markers ()
1805 "Collect the markers pointing to entries in the agenda buffer."
1808 (goto-char (point-min))
1810 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
1811 (get-text-property (point) 'org-marker
)))
1813 (beginning-of-line 2)))
1814 (nreverse markers
)))
1816 (defun org-create-marker-find-array (marker-list)
1817 "Create a alist of files names with all marker positions in that file."
1819 (while (setq m
(pop marker-list
))
1820 (setq p
(marker-position m
)
1821 f
(buffer-file-name (or (buffer-base-buffer
1823 (marker-buffer m
))))
1824 (if (setq a
(assoc f tbl
))
1825 (push (marker-position m
) (cdr a
))
1826 (push (list f p
) tbl
)))
1827 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
1830 (defvar org-agenda-marker-table nil
) ; dyamically scoped parameter
1831 (defun org-check-agenda-marker-table ()
1832 "Check of the current entry is on the marker list."
1833 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
1835 (and (setq a
(assoc file org-agenda-marker-table
))
1838 (org-back-to-heading t
)
1839 (member (point) (cdr a
)))))))
1841 (defun org-check-for-org-mode ()
1842 "Make sure current buffer is in org-mode. Error if not."
1844 (error "Cannot execute org-mode agenda command on buffer in %s."
1847 (defun org-fit-agenda-window ()
1848 "Fit the window to the buffer size."
1849 (and (memq org-agenda-window-setup
'(reorganize-frame))
1850 (fboundp 'fit-window-to-buffer
)
1851 (fit-window-to-buffer
1853 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
1854 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
1856 ;;; Agenda prepare and finalize
1858 (defvar org-agenda-multi nil
) ; dynammically scoped
1859 (defvar org-agenda-buffer-name
"*Org Agenda*")
1860 (defvar org-pre-agenda-window-conf nil
)
1861 (defvar org-agenda-name nil
)
1862 (defun org-prepare-agenda (&optional name
)
1863 (setq org-todo-keywords-for-agenda nil
)
1864 (setq org-done-keywords-for-agenda nil
)
1865 (if org-agenda-multi
1867 (setq buffer-read-only nil
)
1868 (goto-char (point-max))
1869 (unless (or (bobp) org-agenda-compact-blocks
)
1870 (insert "\n" (make-string (window-width) ?
=) "\n"))
1871 (narrow-to-region (point) (point-max)))
1872 (org-agenda-reset-markers)
1873 (org-prepare-agenda-buffers (org-agenda-files))
1874 (setq org-todo-keywords-for-agenda
1875 (org-uniquify org-todo-keywords-for-agenda
))
1876 (setq org-done-keywords-for-agenda
1877 (org-uniquify org-done-keywords-for-agenda
))
1878 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
1879 (awin (get-buffer-window abuf
)))
1881 ((equal (current-buffer) abuf
) nil
)
1882 (awin (select-window awin
))
1883 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
1884 ((equal org-agenda-window-setup
'current-window
)
1885 (switch-to-buffer abuf
))
1886 ((equal org-agenda-window-setup
'other-window
)
1887 (org-switch-to-buffer-other-window abuf
))
1888 ((equal org-agenda-window-setup
'other-frame
)
1889 (switch-to-buffer-other-frame abuf
))
1890 ((equal org-agenda-window-setup
'reorganize-frame
)
1891 (delete-other-windows)
1892 (org-switch-to-buffer-other-window abuf
))))
1893 (setq buffer-read-only nil
)
1896 (and name
(not org-agenda-name
)
1897 (org-set-local 'org-agenda-name name
)))
1898 (setq buffer-read-only nil
))
1900 (defun org-finalize-agenda ()
1901 "Finishing touch for the agenda buffer, called just before displaying it."
1902 (unless org-agenda-multi
1904 (let ((inhibit-read-only t
))
1905 (goto-char (point-min))
1906 (while (org-activate-bracket-links (point-max))
1907 (add-text-properties (match-beginning 0) (match-end 0)
1909 (org-agenda-align-tags)
1910 (unless org-agenda-with-colors
1911 (remove-text-properties (point-min) (point-max) '(face nil
))))
1912 (if (and (boundp 'org-overriding-columns-format
)
1913 org-overriding-columns-format
)
1914 (org-set-local 'org-overriding-columns-format
1915 org-overriding-columns-format
))
1916 (if (and (boundp 'org-agenda-view-columns-initially
)
1917 org-agenda-view-columns-initially
)
1918 (org-agenda-columns))
1919 (when org-agenda-fontify-priorities
1920 (org-fontify-priorities))
1921 (run-hooks 'org-finalize-agenda-hook
)
1922 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
1925 (defun org-fontify-priorities ()
1926 "Make highest priority lines bold, and lowest italic."
1928 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
1929 (org-delete-overlay o
)))
1930 (org-overlays-in (point-min) (point-max)))
1932 (let ((inhibit-read-only t
)
1934 (goto-char (point-min))
1935 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
1936 (setq h
(or (get-char-property (point) 'org-highest-priority
)
1937 org-highest-priority
)
1938 l
(or (get-char-property (point) 'org-lowest-priority
)
1939 org-lowest-priority
)
1940 p
(string-to-char (match-string 1))
1941 b
(match-beginning 0) e
(point-at-eol)
1942 ov
(org-make-overlay b e
))
1945 (cond ((listp org-agenda-fontify-priorities
)
1946 (cdr (assoc p org-agenda-fontify-priorities
)))
1947 ((equal p l
) 'italic
)
1948 ((equal p h
) 'bold
)))
1949 (org-overlay-put ov
'org-type
'org-priority
)))))
1952 (defvar org-agenda-skip-function nil
1953 "Function to be called at each match during agenda construction.
1954 If this function returns nil, the current match should not be skipped.
1955 Otherwise, the function must return a position from where the search
1956 should be continued.
1957 This may also be a Lisp form, it will be evaluated.
1958 Never set this variable using `setq' or so, because then it will apply
1959 to all future agenda commands. Instead, bind it with `let' to scope
1960 it dynamically into the agenda-constructing command. A good way to set
1961 it is through options in org-agenda-custom-commands.")
1963 (defun org-agenda-skip ()
1964 "Throw to `:skip' in places that should be skipped.
1965 Also moves point to the end of the skipped region, so that search can
1966 continue from there."
1967 (let ((p (point-at-bol)) to fp
)
1968 (and org-agenda-skip-archived-trees
1969 (get-text-property p
:org-archived
)
1970 (org-end-of-subtree t
)
1972 (and (get-text-property p
:org-comment
)
1973 (org-end-of-subtree t
)
1975 (if (equal (char-after p
) ?
#) (throw :skip t
))
1976 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
1977 (consp org-agenda-skip-function
))
1978 (setq to
(save-excursion
1981 (funcall org-agenda-skip-function
)
1982 (eval org-agenda-skip-function
))))))
1986 (defvar org-agenda-markers nil
1987 "List of all currently active markers created by `org-agenda'.")
1988 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
1989 "Creation time of the last agenda marker.")
1991 (defun org-agenda-new-marker (&optional pos
)
1992 "Return a new agenda marker.
1993 Org-mode keeps a list of these markers and resets them when they are
1995 (let ((m (copy-marker (or pos
(point)))))
1996 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
1997 (push m org-agenda-markers
)
2000 (defun org-agenda-reset-markers ()
2001 "Reset markers created by `org-agenda'."
2002 (while org-agenda-markers
2003 (move-marker (pop org-agenda-markers
) nil
)))
2007 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
2009 (defun org-timeline (&optional include-all
)
2010 "Show a time-sorted view of the entries in the current org file.
2011 Only entries with a time stamp of today or later will be listed. With
2012 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2013 under the current date.
2014 If the buffer contains an active region, only check the region for
2018 (org-compile-prefix-format 'timeline
)
2019 (org-set-sorting-strategy 'timeline
)
2021 (dotodo include-all
)
2022 (doclosed org-agenda-show-log
)
2023 (entry buffer-file-name
)
2024 (date (calendar-current-date))
2025 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2026 (end (if (org-region-active-p) (region-end) (point-max)))
2027 (day-numbers (org-get-all-dates beg end
'no-ranges
2028 t doclosed
; always include today
2029 org-timeline-show-empty-dates
))
2030 (org-deadline-warning-days 0)
2031 (org-agenda-only-exact-dates t
)
2032 (today (time-to-days (current-time)))
2035 s e rtn d emptyp wd
)
2036 (setq org-agenda-redo-command
2038 (list 'org-switch-to-buffer-other-window
(current-buffer))
2039 (list 'org-timeline
(list 'quote include-all
))))
2041 ;; Remove past dates from the list of dates.
2042 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2043 (if (>= x today
) x nil
))
2045 (org-prepare-agenda (concat "Timeline "
2046 (file-name-nondirectory buffer-file-name
)))
2047 (if doclosed
(push :closed args
))
2048 (push :timestamp args
)
2049 (push :deadline args
)
2050 (push :scheduled args
)
2052 (if dotodo
(push :todo args
))
2053 (while (setq d
(pop day-numbers
))
2054 (if (and (listp d
) (eq (car d
) :omitted
))
2057 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2058 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2059 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2060 (if (and (>= d today
)
2065 (insert (make-string 79 ?-
) "\n")))
2066 (setq date
(calendar-gregorian-from-absolute d
)
2067 wd
(calendar-day-of-week date
))
2069 (setq rtn
(and (not emptyp
)
2070 (apply 'org-agenda-get-day-entries entry
2072 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2075 (if (stringp org-agenda-format-date
)
2076 (format-time-string org-agenda-format-date
2077 (org-time-from-absolute date
))
2078 (funcall org-agenda-format-date date
))
2080 (put-text-property s
(1- (point)) 'face
2081 (if (member wd org-agenda-weekend-days
)
2082 'org-agenda-date-weekend
2084 (put-text-property s
(1- (point)) 'org-date-line t
)
2086 (put-text-property s
(1- (point)) 'org-today t
))
2087 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2088 (put-text-property s
(1- (point)) 'day d
)))))
2089 (goto-char (point-min))
2090 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2092 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2093 (org-finalize-agenda)
2094 (setq buffer-read-only t
)))
2096 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2097 "Return a list of all relevant day numbers from BEG to END buffer positions.
2098 If NO-RANGES is non-nil, include only the start and end dates of a range,
2099 not every single day in the range. If FORCE-TODAY is non-nil, make
2100 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2101 inactive time stamps (those in square brackets) are included.
2102 When EMPTY is non-nil, also include days without any entries."
2104 (if pre-re pre-re
"")
2105 (if inactive org-ts-regexp-both org-ts-regexp
)))
2106 dates dates1 date day day1 day2 ts1 ts2
)
2108 (setq dates
(list (time-to-days (current-time)))))
2111 (while (re-search-forward re end t
)
2112 (setq day
(time-to-days (org-time-string-to-time
2113 (substring (match-string 1) 0 10))))
2114 (or (memq day dates
) (push day dates
)))
2117 (while (re-search-forward org-tr-regexp end t
)
2118 (setq ts1
(substring (match-string 1) 0 10)
2119 ts2
(substring (match-string 2) 0 10)
2120 day1
(time-to-days (org-time-string-to-time ts1
))
2121 day2
(time-to-days (org-time-string-to-time ts2
)))
2122 (while (< (setq day1
(1+ day1
)) day2
)
2123 (or (memq day1 dates
) (push day1 dates
)))))
2124 (setq dates
(sort dates
'<))
2126 (while (setq day
(pop dates
))
2127 (setq day2
(car dates
))
2129 (when (and day2 empty
)
2130 (if (or (eq empty t
)
2131 (and (numberp empty
) (<= (- day2 day
) empty
)))
2132 (while (< (setq day
(1+ day
)) day2
)
2133 (push (list day
) dates1
))
2134 (push (cons :omitted
(- day2 day
)) dates1
))))
2135 (setq dates
(nreverse dates1
)))
2138 ;;; Agenda Daily/Weekly
2140 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2141 (defvar org-agenda-start-day nil
) ; dynamically scoped parameter
2142 (defvar org-agenda-last-arguments nil
2143 "The arguments of the previous call to org-agenda")
2144 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2145 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2146 (defvar org-include-all-loc nil
) ; local variable
2147 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2150 (defun org-agenda-list (&optional include-all start-day ndays
)
2151 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2152 The view will be for the current day or week, but from the overview buffer
2153 you will be able to go to other days/weeks.
2155 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2156 all unfinished TODO items will also be shown, before the agenda.
2157 This feature is considered obsolete, please use the TODO list or a block
2160 With a numeric prefix argument in an interactive call, the agenda will
2161 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2162 the number of days. NDAYS defaults to `org-agenda-ndays'.
2164 START-DAY defaults to TODAY, or to the most recent match for the weekday
2165 given in `org-agenda-start-on-weekday'."
2167 (if (and (integerp include-all
) (> include-all
0))
2168 (setq ndays include-all include-all nil
))
2169 (setq ndays
(or ndays org-agenda-ndays
)
2170 start-day
(or start-day org-agenda-start-day
))
2171 (if org-agenda-overriding-arguments
2172 (setq include-all
(car org-agenda-overriding-arguments
)
2173 start-day
(nth 1 org-agenda-overriding-arguments
)
2174 ndays
(nth 2 org-agenda-overriding-arguments
)))
2175 (if (stringp start-day
)
2176 ;; Convert to an absolute day number
2177 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2178 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2179 (org-compile-prefix-format 'agenda
)
2180 (org-set-sorting-strategy 'agenda
)
2182 (let* ((org-agenda-start-on-weekday
2183 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2184 org-agenda-start-on-weekday nil
))
2185 (thefiles (org-agenda-files))
2187 (today (time-to-days
2188 (time-subtract (current-time)
2189 (list 0 (* 3600 org-extend-today-until
) 0))))
2190 (sd (or start-day today
))
2191 (start (if (or (null org-agenda-start-on-weekday
)
2192 (< org-agenda-ndays
7))
2194 (let* ((nt (calendar-day-of-week
2195 (calendar-gregorian-from-absolute sd
)))
2196 (n1 org-agenda-start-on-weekday
)
2198 (- sd
(+ (if (< d
0) 7 0) d
)))))
2199 (day-numbers (list start
))
2201 (inhibit-redisplay (not debug-on-error
))
2202 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2203 clocktable-start clocktable-end
)
2204 (setq org-agenda-redo-command
2205 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2206 ;; Make the list of days
2207 (setq ndays
(or ndays org-agenda-ndays
)
2210 (push (1+ (car day-numbers
)) day-numbers
)
2211 (setq ndays
(1- ndays
)))
2212 (setq day-numbers
(nreverse day-numbers
))
2213 (setq clocktable-start
(car day-numbers
)
2214 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2215 (org-prepare-agenda "Day/Week")
2216 (org-set-local 'org-starting-day
(car day-numbers
))
2217 (org-set-local 'org-include-all-loc include-all
)
2218 (org-set-local 'org-agenda-span
2219 (org-agenda-ndays-to-span nd
))
2220 (when (and (or include-all org-agenda-include-all-todo
)
2221 (member today day-numbers
))
2222 (setq files thefiles
2224 (while (setq file
(pop files
))
2226 (org-check-agenda-file file
)
2227 (setq date
(calendar-gregorian-from-absolute today
)
2228 rtn
(org-agenda-get-day-entries
2230 (setq rtnall
(append rtnall rtn
))))
2232 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2233 (add-text-properties (point-min) (1- (point))
2234 (list 'face
'org-agenda-structure
))
2235 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2236 (unless org-agenda-compact-blocks
2237 (let* ((d1 (car day-numbers
))
2238 (d2 (org-last day-numbers
))
2239 (w1 (org-days-to-iso-week d1
))
2240 (w2 (org-days-to-iso-week d2
)))
2242 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2244 (if (< (- d2 d1
) 350)
2246 (format " (W%02d)" w1
)
2247 (format " (W%02d-W%02d)" w1 w2
))
2250 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2252 (while (setq d
(pop day-numbers
))
2253 (setq date
(calendar-gregorian-from-absolute d
)
2254 wd
(calendar-day-of-week date
)
2256 (if (or (setq todayp
(= d today
))
2257 (and (not start-pos
) (= d sd
)))
2258 (setq start-pos
(point))
2259 (if (and start-pos
(not end-pos
))
2260 (setq end-pos
(point))))
2261 (setq files thefiles
2263 (while (setq file
(pop files
))
2265 (org-check-agenda-file file
)
2266 (if org-agenda-show-log
2267 (setq rtn
(org-agenda-get-day-entries
2269 :deadline
:scheduled
:timestamp
:sexp
:closed
))
2270 (setq rtn
(org-agenda-get-day-entries
2272 :deadline
:scheduled
:sexp
:timestamp
)))
2273 (setq rtnall
(append rtnall rtn
))))
2274 (if org-agenda-include-diary
2276 (require 'diary-lib
)
2277 (setq rtn
(org-get-entries-from-diary date
))
2278 (setq rtnall
(append rtnall rtn
))))
2279 (if (or rtnall org-agenda-show-all-dates
)
2281 (setq day-cnt
(1+ day-cnt
))
2283 (if (stringp org-agenda-format-date
)
2284 (format-time-string org-agenda-format-date
2285 (org-time-from-absolute date
))
2286 (funcall org-agenda-format-date date
))
2288 (put-text-property s
(1- (point)) 'face
2289 (if (member wd org-agenda-weekend-days
)
2290 'org-agenda-date-weekend
2292 (put-text-property s
(1- (point)) 'org-date-line t
)
2293 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2294 (if todayp
(put-text-property s
(1- (point)) 'org-today t
))
2296 (org-finalize-agenda-entries
2297 (org-agenda-add-time-grid-maybe
2300 (put-text-property s
(1- (point)) 'day d
)
2301 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2302 (when (and org-agenda-clockreport-mode clocktable-start
)
2303 (let ((org-agenda-files (org-agenda-files))
2304 ;; the above line is to ensure the restricted range!
2305 (p org-agenda-clockreport-parameter-plist
)
2307 (setq p
(org-plist-delete p
:block
))
2308 (setq p
(plist-put p
:tstart clocktable-start
))
2309 (setq p
(plist-put p
:tend clocktable-end
))
2310 (setq p
(plist-put p
:scope
'agenda
))
2311 (setq tbl
(apply 'org-get-clocktable p
))
2313 (goto-char (point-min))
2314 (org-fit-agenda-window)
2315 (unless (and (pos-visible-in-window-p (point-min))
2316 (pos-visible-in-window-p (point-max)))
2317 (goto-char (1- (point-max)))
2319 (if (not (pos-visible-in-window-p (or start-pos
1)))
2321 (goto-char (or start-pos
1))
2323 (goto-char (or start-pos
1))
2324 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2325 (org-finalize-agenda)
2326 (setq buffer-read-only t
)
2329 (defun org-agenda-ndays-to-span (n)
2330 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2332 ;;; Agenda word search
2334 (defvar org-agenda-search-history nil
)
2335 (defvar org-todo-only nil
)
2337 (defvar org-search-syntax-table nil
2338 "Special syntax table for org-mode search.
2339 In this table, we have single quotes not as word constituents, to
2340 that when \"+Ameli\" is searchd as a work, it will also match \"Ameli's\"")
2342 (defun org-search-syntax-table ()
2343 (unless org-search-syntax-table
2344 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2345 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2346 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2347 org-search-syntax-table
)
2350 (defun org-search-view (&optional todo-only string edit-at
)
2351 "Show all entries that contain words or regular expressions.
2352 If the first character of the search string is an asterisks,
2353 search only the headlines.
2355 With optional prefix argument TODO-ONLY, only consider entries that are
2356 TODO entries. The argument STRING can be used to pass a default search
2357 string into this function. If EDIT-AT is non-nil, it means that the
2358 user should get a chance to edit this string, with cursor at position
2361 The search string is broken into \"words\" by splitting at whitespace.
2362 The individual words are then interpreted as a boolean expression with
2363 logical AND. Words prefixed with a minus must not occur in the entry.
2364 Words without a prefix or prefixed with a plus must occur in the entry.
2365 Matching is case-insensitive and the words are enclosed by word delimiters.
2367 Words enclosed by curly braces are interpreted as regular expressions
2368 that must or must not match in the entry.
2370 If the search string starts with an asterisk, search only in headlines.
2371 If (possibly after the leading star) the search string starts with an
2372 exclamation mark, this also means to look at TODO entries only, an effect
2373 that can also be achieved with a prefix argument.
2375 This command searches the agenda files, and in addition the files listed
2376 in `org-agenda-text-search-extra-files'."
2378 (org-compile-prefix-format 'search
)
2379 (org-set-sorting-strategy 'search
)
2380 (org-prepare-agenda "SEARCH")
2381 (let* ((props (list 'face nil
2382 'done-face
'org-done
2383 'org-not-done-regexp org-not-done-regexp
2384 'org-todo-regexp org-todo-regexp
2385 'mouse-face
'highlight
2386 'keymap org-agenda-keymap
2387 'help-echo
(format "mouse-2 or RET jump to location")))
2388 regexp rtn rtnall files file pos
2389 marker priority category tags c neg re
2390 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2391 (unless (and (not edit-at
)
2393 (string-match "\\S-" string
))
2394 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2396 ((integerp edit-at
) (cons string edit-at
))
2398 'org-agenda-search-history
)))
2399 (org-set-local 'org-todo-only todo-only
)
2400 (setq org-agenda-redo-command
2401 (list 'org-search-view
(if todo-only t nil
) string
2402 '(if current-prefix-arg
1 nil
)))
2403 (setq org-agenda-query-string string
)
2405 (if (equal (string-to-char string
) ?
*)
2407 words
(substring string
1))
2408 (setq words string
))
2409 (when (equal (string-to-char words
) ?
!)
2411 words
(substring words
1)))
2412 (setq words
(org-split-string words
))
2414 (setq c
(string-to-char w
))
2416 (setq neg t w
(substring w
1))
2418 (setq neg nil w
(substring w
1))
2420 (if (string-match "\\`{.*}\\'" w
)
2421 (setq re
(substring w
1 -
1))
2422 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2423 (if neg
(push re regexps-
) (push re regexps
+)))
2425 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2427 (setq regexp
(concat "^" org-outline-regexp
))
2428 (setq regexp
(pop regexps
+))
2429 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2431 (setq files
(append (org-agenda-files) org-agenda-text-search-extra-files
)
2433 (while (setq file
(pop files
))
2436 (org-check-agenda-file file
)
2437 (setq buffer
(if (file-exists-p file
)
2438 (org-get-agenda-file-buffer file
)
2439 (error "No such file %s" file
)))
2441 ;; If file does not exist, make sure an error message is sent
2442 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2444 (with-current-buffer buffer
2445 (with-syntax-table (org-search-syntax-table)
2446 (unless (org-mode-p)
2447 (error "Agenda file %s is not in `org-mode'" file
))
2448 (let ((case-fold-search t
))
2451 (if org-agenda-restrict
2452 (narrow-to-region org-agenda-restrict-begin
2453 org-agenda-restrict-end
)
2455 (goto-char (point-min))
2456 (unless (or (org-on-heading-p)
2457 (outline-next-heading))
2458 (throw 'nextfile t
))
2459 (goto-char (max (point-min) (1- (point))))
2460 (while (re-search-forward regexp nil t
)
2461 (org-back-to-heading t
)
2462 (skip-chars-forward "* ")
2463 (setq beg
(point-at-bol)
2465 end
(progn (outline-next-heading) (point)))
2469 (setq str
(buffer-substring-no-properties
2471 (if hdl-only
(point-at-eol) end
)))
2472 (mapc (lambda (wr) (when (string-match wr str
)
2473 (goto-char (1- end
))
2476 (mapc (lambda (wr) (unless (string-match wr str
)
2477 (goto-char (1- end
))
2480 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
2484 (setq marker
(org-agenda-new-marker (point))
2485 category
(org-get-category)
2486 tags
(org-get-tags-at (point))
2487 txt
(org-format-agenda-item
2489 (buffer-substring-no-properties
2490 beg1
(point-at-eol))
2492 (org-add-props txt props
2493 'org-marker marker
'org-hd-marker marker
2494 'org-todo-regexp org-todo-regexp
2495 'priority
1000 'org-category category
2498 (goto-char (1- end
))))))))))
2499 (setq rtn
(nreverse ee
))
2500 (setq rtnall
(append rtnall rtn
)))
2501 (if org-agenda-overriding-header
2502 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2503 nil
'face
'org-agenda-structure
) "\n")
2504 (insert "Search words: ")
2505 (add-text-properties (point-min) (1- (point))
2506 (list 'face
'org-agenda-structure
))
2508 (insert string
"\n")
2509 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2511 (unless org-agenda-multi
2512 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
2513 (add-text-properties pos
(1- (point))
2514 (list 'face
'org-agenda-structure
))))
2516 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2517 (goto-char (point-min))
2518 (org-fit-agenda-window)
2519 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
2520 (org-finalize-agenda)
2521 (setq buffer-read-only t
)))
2523 ;;; Agenda TODO list
2525 (defvar org-select-this-todo-keyword nil
)
2526 (defvar org-last-arg nil
)
2529 (defun org-todo-list (arg)
2530 "Show all TODO entries from all agenda file in a single list.
2531 The prefix arg can be used to select a specific TODO keyword and limit
2532 the list to these. When using \\[universal-argument], you will be prompted
2533 for a keyword. A numeric prefix directly selects the Nth keyword in
2534 `org-todo-keywords-1'."
2537 (org-compile-prefix-format 'todo
)
2538 (org-set-sorting-strategy 'todo
)
2539 (org-prepare-agenda "TODO")
2540 (let* ((today (time-to-days (current-time)))
2541 (date (calendar-gregorian-from-absolute today
))
2542 (kwds org-todo-keywords-for-agenda
)
2543 (completion-ignore-case t
)
2544 (org-select-this-todo-keyword
2545 (if (stringp arg
) arg
2546 (and arg
(integerp arg
) (> arg
0)
2547 (nth (1- arg
) kwds
))))
2548 rtn rtnall files file pos
)
2549 (when (equal arg
'(4))
2550 (setq org-select-this-todo-keyword
2551 (completing-read "Keyword (or KWD1|K2D2|...): "
2552 (mapcar 'list kwds
) nil nil
)))
2553 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
2554 (org-set-local 'org-last-arg arg
)
2555 (setq org-agenda-redo-command
2556 '(org-todo-list (or current-prefix-arg org-last-arg
)))
2557 (setq files
(org-agenda-files)
2559 (while (setq file
(pop files
))
2561 (org-check-agenda-file file
)
2562 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
2563 (setq rtnall
(append rtnall rtn
))))
2564 (if org-agenda-overriding-header
2565 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2566 nil
'face
'org-agenda-structure
) "\n")
2567 (insert "Global list of TODO items of type: ")
2568 (add-text-properties (point-min) (1- (point))
2569 (list 'face
'org-agenda-structure
))
2571 (insert (or org-select-this-todo-keyword
"ALL") "\n")
2572 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2574 (unless org-agenda-multi
2575 (insert "Available with `N r': (0)ALL")
2578 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
2579 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
2584 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2586 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2587 (goto-char (point-min))
2588 (org-fit-agenda-window)
2589 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
2590 (org-finalize-agenda)
2591 (setq buffer-read-only t
)))
2593 ;;; Agenda tags match
2596 (defun org-tags-view (&optional todo-only match
)
2597 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
2598 The prefix arg TODO-ONLY limits the search to TODO entries."
2600 (org-compile-prefix-format 'tags
)
2601 (org-set-sorting-strategy 'tags
)
2602 (let* ((org-tags-match-list-sublevels
2603 (if todo-only t org-tags-match-list-sublevels
))
2604 (completion-ignore-case t
)
2605 rtn rtnall files file pos matcher
2607 (setq matcher
(org-make-tags-matcher match
)
2608 match
(car matcher
) matcher
(cdr matcher
))
2609 (org-prepare-agenda (concat "TAGS " match
))
2610 (setq org-agenda-query-string match
)
2611 (setq org-agenda-redo-command
2612 (list 'org-tags-view
(list 'quote todo-only
)
2613 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
2614 (setq files
(org-agenda-files)
2616 (while (setq file
(pop files
))
2618 (org-check-agenda-file file
)
2619 (setq buffer
(if (file-exists-p file
)
2620 (org-get-agenda-file-buffer file
)
2621 (error "No such file %s" file
)))
2623 ;; If file does not exist, merror message to agenda
2625 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
2626 rtnall
(append rtnall rtn
))
2627 (with-current-buffer buffer
2628 (unless (org-mode-p)
2629 (error "Agenda file %s is not in `org-mode'" file
))
2632 (if org-agenda-restrict
2633 (narrow-to-region org-agenda-restrict-begin
2634 org-agenda-restrict-end
)
2636 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
2637 (setq rtnall
(append rtnall rtn
))))))))
2638 (if org-agenda-overriding-header
2639 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2640 nil
'face
'org-agenda-structure
) "\n")
2641 (insert "Headlines with TAGS match: ")
2642 (add-text-properties (point-min) (1- (point))
2643 (list 'face
'org-agenda-structure
))
2646 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2648 (unless org-agenda-multi
2649 (insert "Press `C-u r' to search again with new search string\n"))
2650 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2652 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2653 (goto-char (point-min))
2654 (org-fit-agenda-window)
2655 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
2656 (org-finalize-agenda)
2657 (setq buffer-read-only t
)))
2659 ;;; Agenda Finding stuck projects
2661 (defvar org-agenda-skip-regexp nil
2662 "Regular expression used in skipping subtrees for the agenda.
2663 This is basically a temporary global variable that can be set and then
2664 used by user-defined selections using `org-agenda-skip-function'.")
2666 (defvar org-agenda-overriding-header nil
2667 "When this is set during todo and tags searches, will replace header.")
2669 (defun org-agenda-skip-subtree-when-regexp-matches ()
2670 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
2671 If yes, it returns the end position of this tree, causing agenda commands
2672 to skip this subtree. This is a function that can be put into
2673 `org-agenda-skip-function' for the duration of a command."
2674 (let ((end (save-excursion (org-end-of-subtree t
)))
2677 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
2680 (defun org-agenda-skip-entry-if (&rest conditions
)
2681 "Skip entry if any of CONDITIONS is true.
2682 See `org-agenda-skip-if' for details."
2683 (org-agenda-skip-if nil conditions
))
2685 (defun org-agenda-skip-subtree-if (&rest conditions
)
2686 "Skip entry if any of CONDITIONS is true.
2687 See `org-agenda-skip-if' for details."
2688 (org-agenda-skip-if t conditions
))
2690 (defun org-agenda-skip-if (subtree conditions
)
2691 "Checks current entity for CONDITIONS.
2692 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
2693 the entry, i.e. the text before the next heading is checked.
2695 CONDITIONS is a list of symbols, boolean OR is used to combine the results
2696 from different tests. Valid conditions are:
2698 scheduled Check if there is a scheduled cookie
2699 notscheduled Check if there is no scheduled cookie
2700 deadline Check if there is a deadline
2701 notdeadline Check if there is no deadline
2702 regexp Check if regexp matches
2703 notregexp Check if regexp does not match.
2705 The regexp is taken from the conditions list, it must come right after
2706 the `regexp' or `notregexp' element.
2708 If any of these conditions is met, this function returns the end point of
2709 the entity, causing the search to continue from there. This is a function
2710 that can be put into `org-agenda-skip-function' for the duration of a command."
2712 (org-back-to-heading t
)
2715 (progn (org-end-of-subtree t
) (point))
2716 (progn (outline-next-heading) (1- (point)))))
2720 (and (memq 'scheduled conditions
)
2721 (re-search-forward org-scheduled-time-regexp end t
))
2722 (and (memq 'notscheduled conditions
)
2723 (not (re-search-forward org-scheduled-time-regexp end t
)))
2724 (and (memq 'deadline conditions
)
2725 (re-search-forward org-deadline-time-regexp end t
))
2726 (and (memq 'notdeadline conditions
)
2727 (not (re-search-forward org-deadline-time-regexp end t
)))
2728 (and (setq m
(memq 'regexp conditions
))
2730 (re-search-forward (nth 1 m
) end t
))
2731 (and (setq m
(memq 'notregexp conditions
))
2733 (not (re-search-forward (nth 1 m
) end t
))))
2737 (defun org-agenda-list-stuck-projects (&rest ignore
)
2738 "Create agenda view for projects that are stuck.
2739 Stuck projects are project that have no next actions. For the definitions
2740 of what a project is and how to check if it stuck, customize the variable
2741 `org-stuck-projects'.
2742 MATCH is being ignored."
2744 (let* ((org-agenda-skip-function 'org-agenda-skip-subtree-when-regexp-matches
)
2745 ;; We could have used org-agenda-skip-if here.
2746 (org-agenda-overriding-header "List of stuck projects: ")
2747 (matcher (nth 0 org-stuck-projects
))
2748 (todo (nth 1 org-stuck-projects
))
2749 (todo-wds (if (member "*" todo
)
2751 (org-prepare-agenda-buffers (org-agenda-files))
2753 org-done-keywords-for-agenda
2754 (copy-sequence org-todo-keywords-for-agenda
)))
2756 (todo-re (concat "^\\*+[ \t]+\\("
2757 (mapconcat 'identity todo-wds
"\\|")
2759 (tags (nth 2 org-stuck-projects
))
2760 (tags-re (if (member "*" tags
)
2761 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
2762 (concat "^\\*+ .*:\\("
2763 (mapconcat 'identity tags
"\\|")
2764 (org-re "\\):[[:alnum:]_@:]*[ \t]*$"))))
2765 (gen-re (nth 3 org-stuck-projects
))
2771 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
2773 (setq org-agenda-skip-regexp
2775 (mapconcat 'identity re-list
"\\|")
2776 (error "No information how to identify unstuck projects")))
2777 (org-tags-view nil matcher
)
2778 (with-current-buffer org-agenda-buffer-name
2779 (setq org-agenda-redo-command
2780 '(org-agenda-list-stuck-projects
2781 (or current-prefix-arg org-last-arg
))))))
2783 ;;; Diary integration
2785 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
2786 (defvar list-diary-entries-hook
)
2788 (defun org-get-entries-from-diary (date)
2789 "Get the (Emacs Calendar) diary entries for DATE."
2790 (require 'diary-lib
)
2791 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
2792 (fancy-diary-buffer diary-fancy-buffer
)
2793 (diary-display-hook '(fancy-diary-display))
2795 (list-diary-entries-hook
2796 (cons 'org-diary-default-entry list-diary-entries-hook
))
2797 (diary-file-name-prefix-function nil
) ; turn this feature off
2798 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
2800 (org-disable-agenda-to-diary t
))
2802 (save-window-excursion
2803 (funcall (if (fboundp 'diary-list-entries
)
2804 'diary-list-entries
'list-diary-entries
)
2806 (if (not (get-buffer diary-fancy-buffer
))
2808 (with-current-buffer diary-fancy-buffer
2809 (setq buffer-read-only nil
)
2810 (if (zerop (buffer-size))
2813 ;; Omit the date and other unnecessary stuff
2814 (org-agenda-cleanup-fancy-diary)
2815 ;; Add prefix to each line and extend the text properties
2816 (if (zerop (buffer-size))
2818 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
2819 (set-buffer-modified-p nil
)
2820 (kill-buffer diary-fancy-buffer
)))
2822 (setq entries
(org-split-string entries
"\n"))
2826 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
2827 ;; Extend the text properties to the beginning of the line
2828 (org-add-props x
(text-properties-at (1- (length x
)) x
)
2829 'type
"diary" 'date date
))
2832 (defun org-agenda-cleanup-fancy-diary ()
2833 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
2834 This gets rid of the date, the underline under the date, and
2835 the dummy entry installed by `org-mode' to ensure non-empty diary for each
2836 date. It also removes lines that contain only whitespace."
2837 (goto-char (point-min))
2838 (if (looking-at ".*?:[ \t]*")
2841 (re-search-forward "\n=+$" nil t
)
2843 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
2844 (re-search-forward "\n=+$" nil t
)
2845 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
2846 (goto-char (point-min))
2847 (while (re-search-forward "^ +\n" nil t
)
2849 (goto-char (point-min))
2850 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
2851 (replace-match "")))
2853 ;; Make sure entries from the diary have the right text properties.
2854 (eval-after-load "diary-lib"
2855 '(if (boundp 'diary-modify-entry-list-string-function
)
2856 ;; We can rely on the hook, nothing to do
2858 ;; Hook not avaiable, must use advice to make this work
2859 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
2860 "Make the position visible."
2861 (if (and org-disable-agenda-to-diary
;; called from org-agenda
2864 (setq string
(org-modify-diary-entry-string string
))))))
2866 (defun org-modify-diary-entry-string (string)
2867 "Add text properties to string, allowing org-mode to act on it."
2868 (org-add-props string nil
2869 'mouse-face
'highlight
2870 'keymap org-agenda-keymap
2871 'help-echo
(if buffer-file-name
2872 (format "mouse-2 or RET jump to diary file %s"
2873 (abbreviate-file-name buffer-file-name
))
2875 'org-agenda-diary-link t
2876 'org-marker
(org-agenda-new-marker (point-at-bol))))
2878 (defun org-diary-default-entry ()
2879 "Add a dummy entry to the diary.
2880 Needed to avoid empty dates which mess up holiday display."
2881 ;; Catch the error if dealing with the new add-to-diary-alist
2882 (when org-disable-agenda-to-diary
2884 (add-to-diary-list original-date
"Org-mode dummy" "")
2886 (add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
2889 (defun org-diary (&rest args
)
2890 "Return diary information from org-files.
2891 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
2892 It accesses org files and extracts information from those files to be
2893 listed in the diary. The function accepts arguments specifying what
2894 items should be listed. The following arguments are allowed:
2896 :timestamp List the headlines of items containing a date stamp or
2897 date range matching the selected date. Deadlines will
2898 also be listed, on the expiration day.
2900 :sexp List entries resulting from diary-like sexps.
2902 :deadline List any deadlines past due, or due within
2903 `org-deadline-warning-days'. The listing occurs only
2904 in the diary for *today*, not at any other date. If
2905 an entry is marked DONE, it is no longer listed.
2907 :scheduled List all items which are scheduled for the given date.
2908 The diary for *today* also contains items which were
2909 scheduled earlier and are not yet marked DONE.
2911 :todo List all TODO items from the org-file. This may be a
2912 long list - so this is not turned on by default.
2913 Like deadlines, these entries only show up in the
2914 diary for *today*, not at any other date.
2916 The call in the diary file should look like this:
2918 &%%(org-diary) ~/path/to/some/orgfile.org
2920 Use a separate line for each org file to check. Or, if you omit the file name,
2921 all files listed in `org-agenda-files' will be checked automatically:
2925 If you don't give any arguments (as in the example above), the default
2926 arguments (:deadline :scheduled :timestamp :sexp) are used.
2927 So the example above may also be written as
2929 &%%(org-diary :deadline :timestamp :sexp :scheduled)
2931 The function expects the lisp variables `entry' and `date' to be provided
2932 by the caller, because this is how the calendar works. Don't use this
2933 function from a program - use `org-agenda-get-day-entries' instead."
2934 (when (> (- (time-to-seconds (current-time))
2935 org-agenda-last-marker-time
)
2937 (org-agenda-reset-markers))
2938 (org-compile-prefix-format 'agenda
)
2939 (org-set-sorting-strategy 'agenda
)
2940 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
2941 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
2943 (org-agenda-files t
)))
2945 (org-prepare-agenda-buffers files
)
2946 ;; If this is called during org-agenda, don't return any entries to
2947 ;; the calendar. Org Agenda will list these entries itself.
2948 (if org-disable-agenda-to-diary
(setq files nil
))
2949 (while (setq file
(pop files
))
2950 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
2951 (setq results
(append results rtn
)))
2953 (concat (org-finalize-agenda-entries results
) "\n"))))
2955 ;;; Agenda entry finders
2957 (defun org-agenda-get-day-entries (file date
&rest args
)
2958 "Does the work for `org-diary' and `org-agenda'.
2959 FILE is the path to a file to be checked for entries. DATE is date like
2960 the one returned by `calendar-current-date'. ARGS are symbols indicating
2961 which kind of entries should be extracted. For details about these, see
2962 the documentation of `org-diary'."
2963 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
2964 (let* ((org-startup-folded nil
)
2965 (org-startup-align-all-tables nil
)
2966 (buffer (if (file-exists-p file
)
2967 (org-get-agenda-file-buffer file
)
2968 (error "No such file %s" file
)))
2971 ;; If file does not exist, make sure an error message ends up in diary
2972 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
2973 (with-current-buffer buffer
2974 (unless (org-mode-p)
2975 (error "Agenda file %s is not in `org-mode'" file
))
2976 (let ((case-fold-search nil
))
2979 (if org-agenda-restrict
2980 (narrow-to-region org-agenda-restrict-begin
2981 org-agenda-restrict-end
)
2983 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
2984 (while (setq arg
(pop args
))
2986 ((and (eq arg
:todo
)
2987 (equal date
(calendar-current-date)))
2988 (setq rtn
(org-agenda-get-todos))
2989 (setq results
(append results rtn
)))
2990 ((eq arg
:timestamp
)
2991 (setq rtn
(org-agenda-get-blocks))
2992 (setq results
(append results rtn
))
2993 (setq rtn
(org-agenda-get-timestamps))
2994 (setq results
(append results rtn
)))
2996 (setq rtn
(org-agenda-get-sexps))
2997 (setq results
(append results rtn
)))
2998 ((eq arg
:scheduled
)
2999 (setq rtn
(org-agenda-get-scheduled))
3000 (setq results
(append results rtn
)))
3002 (setq rtn
(org-agenda-get-closed))
3003 (setq results
(append results rtn
)))
3005 (setq rtn
(org-agenda-get-deadlines))
3006 (setq results
(append results rtn
))))))))
3009 (defun org-agenda-get-todos ()
3010 "Return the TODO information for agenda display."
3011 (let* ((props (list 'face nil
3012 'done-face
'org-done
3013 'org-not-done-regexp org-not-done-regexp
3014 'org-todo-regexp org-todo-regexp
3015 'mouse-face
'highlight
3016 'keymap org-agenda-keymap
3018 (format "mouse-2 or RET jump to org file %s"
3019 (abbreviate-file-name buffer-file-name
))))
3020 (regexp (concat "^\\*+[ \t]+\\("
3021 (if org-select-this-todo-keyword
3022 (if (equal org-select-this-todo-keyword
"*")
3025 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3027 org-not-done-regexp
)
3029 marker priority category tags
3031 (goto-char (point-min))
3032 (while (re-search-forward regexp nil t
)
3036 (setq beg
(point) end
(progn (outline-next-heading) (point)))
3037 (when (or (and org-agenda-todo-ignore-with-date
(goto-char beg
)
3038 (re-search-forward org-ts-regexp end t
))
3039 (and org-agenda-todo-ignore-scheduled
(goto-char beg
)
3040 (re-search-forward org-scheduled-time-regexp end t
))
3041 (and org-agenda-todo-ignore-deadlines
(goto-char beg
)
3042 (re-search-forward org-deadline-time-regexp end t
)
3043 (org-deadline-close (match-string 1))))
3044 (goto-char (1+ beg
))
3045 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3049 (goto-char (match-beginning 1))
3050 (setq marker
(org-agenda-new-marker (match-beginning 0))
3051 category
(org-get-category)
3052 tags
(org-get-tags-at (point))
3053 txt
(org-format-agenda-item "" (match-string 1) category tags
)
3054 priority
(1+ (org-get-priority txt
)))
3055 (org-add-props txt props
3056 'org-marker marker
'org-hd-marker marker
3057 'priority priority
'org-category category
3060 (if org-agenda-todo-list-sublevels
3061 (goto-char (match-end 1))
3062 (org-end-of-subtree 'invisible
))))
3065 (defconst org-agenda-no-heading-message
3066 "No heading for this item in buffer or region.")
3068 (defun org-agenda-get-timestamps ()
3069 "Return the date stamp information for agenda display."
3070 (let* ((props (list 'face nil
3071 'org-not-done-regexp org-not-done-regexp
3072 'org-todo-regexp org-todo-regexp
3073 'mouse-face
'highlight
3074 'keymap org-agenda-keymap
3076 (format "mouse-2 or RET jump to org file %s"
3077 (abbreviate-file-name buffer-file-name
))))
3078 (d1 (calendar-absolute-from-gregorian date
))
3084 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3088 (if org-agenda-include-inactive-timestamps
"[[<]" "<")
3092 (car org-time-stamp-formats
)
3093 (apply 'encode-time
; DATE bound by calendar
3094 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3096 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3097 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3098 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3099 donep tmp priority category ee txt timestr tags b0 b3 e3 head
)
3100 (goto-char (point-min))
3101 (while (re-search-forward regexp nil t
)
3102 (setq b0
(match-beginning 0)
3103 b3
(match-beginning 3) e3
(match-end 3))
3105 (and (org-at-date-range-p) (throw :skip nil
))
3107 (if (and (match-end 1)
3108 (not (= d1
(org-time-string-to-absolute
3109 (match-string 1) d1 nil
3110 org-agenda-repeating-timestamp-show-all
))))
3113 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3115 (setq marker
(org-agenda-new-marker b0
)
3116 category
(org-get-category b0
)
3117 tmp
(buffer-substring (max (point-min)
3118 (- b0 org-ds-keyword-length
))
3120 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3121 inactivep
(= (char-after b0
) ?\
[)
3122 deadlinep
(string-match org-deadline-regexp tmp
)
3123 scheduledp
(string-match org-scheduled-regexp tmp
)
3124 closedp
(and org-agenda-include-inactive-timestamps
3125 (string-match org-closed-string tmp
))
3126 clockp
(and org-agenda-include-inactive-timestamps
3127 (or (string-match org-clock-string tmp
)
3128 (string-match "]-+\\'" tmp
)))
3129 donep
(org-entry-is-done-p))
3130 (if (or scheduledp deadlinep closedp clockp
)
3132 (if (string-match ">" timestr
)
3133 ;; substring should only run to end of time stamp
3134 (setq timestr
(substring timestr
0 (match-end 0))))
3136 (if (re-search-backward "^\\*+ " nil t
)
3138 (goto-char (match-beginning 0))
3139 (setq hdmarker
(org-agenda-new-marker)
3140 tags
(org-get-tags-at))
3141 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3142 (setq head
(match-string 1))
3143 (and org-agenda-skip-timestamp-if-done donep
(throw :skip t
))
3144 (setq txt
(org-format-agenda-item
3145 (if inactivep
"[" nil
)
3146 head category tags timestr nil
3148 (setq txt org-agenda-no-heading-message
))
3149 (setq priority
(org-get-priority txt
))
3150 (org-add-props txt props
3151 'org-marker marker
'org-hd-marker hdmarker
)
3152 (org-add-props txt nil
'priority priority
3153 'org-category category
'date date
3156 (outline-next-heading)))
3159 (defun org-agenda-get-sexps ()
3160 "Return the sexp information for agenda display."
3161 (require 'diary-lib
)
3162 (let* ((props (list 'face nil
3163 'mouse-face
'highlight
3164 'keymap org-agenda-keymap
3166 (format "mouse-2 or RET jump to org file %s"
3167 (abbreviate-file-name buffer-file-name
))))
3169 marker category ee txt tags entry result beg b sexp sexp-entry
)
3170 (goto-char (point-min))
3171 (while (re-search-forward regexp nil t
)
3174 (setq beg
(match-beginning 0))
3175 (goto-char (1- (match-end 0)))
3178 (setq sexp
(buffer-substring b
(point)))
3179 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3180 (org-trim (match-string 1))
3182 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3184 (setq marker
(org-agenda-new-marker beg
)
3185 category
(org-get-category beg
))
3187 (if (string-match "\\S-" result
)
3189 (setq txt
"SEXP entry returned empty string"))
3191 (setq txt
(org-format-agenda-item
3192 "" txt category tags
'time
))
3193 (org-add-props txt props
'org-marker marker
)
3194 (org-add-props txt nil
3195 'org-category category
'date date
3200 (defun org-agenda-get-closed ()
3201 "Return the logged TODO entries for agenda display."
3202 (let* ((props (list 'mouse-face
'highlight
3203 'org-not-done-regexp org-not-done-regexp
3204 'org-todo-regexp org-todo-regexp
3205 'keymap org-agenda-keymap
3207 (format "mouse-2 or RET jump to org file %s"
3208 (abbreviate-file-name buffer-file-name
))))
3210 "\\<\\(" org-closed-string
"\\|" org-clock-string
"\\) *\\["
3214 (car org-time-stamp-formats
)
3215 (apply 'encode-time
; DATE bound by calendar
3216 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3218 marker hdmarker priority category tags closedp
3220 (goto-char (point-min))
3221 (while (re-search-forward regexp nil t
)
3224 (setq marker
(org-agenda-new-marker (match-beginning 0))
3225 closedp
(equal (match-string 1) org-closed-string
)
3226 category
(org-get-category (match-beginning 0))
3227 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3228 ;; donep (org-entry-is-done-p)
3230 (if (string-match "\\]" timestr
)
3231 ;; substring should only run to end of time stamp
3232 (setq timestr
(substring timestr
0 (match-end 0))))
3234 (if (re-search-backward "^\\*+ " nil t
)
3236 (goto-char (match-beginning 0))
3237 (setq hdmarker
(org-agenda-new-marker)
3238 tags
(org-get-tags-at))
3239 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3240 (setq txt
(org-format-agenda-item
3241 (if closedp
"Closed: " "Clocked: ")
3242 (match-string 1) category tags timestr
)))
3243 (setq txt org-agenda-no-heading-message
))
3244 (setq priority
100000)
3245 (org-add-props txt props
3246 'org-marker marker
'org-hd-marker hdmarker
'face
'org-done
3247 'priority priority
'org-category category
3248 'type
"closed" 'date date
3249 'undone-face
'org-warning
'done-face
'org-done
)
3251 (goto-char (point-at-eol))))
3254 (defun org-agenda-get-deadlines ()
3255 "Return the deadline information for agenda display."
3256 (let* ((props (list 'mouse-face
'highlight
3257 'org-not-done-regexp org-not-done-regexp
3258 'org-todo-regexp org-todo-regexp
3259 'keymap org-agenda-keymap
3261 (format "mouse-2 or RET jump to org file %s"
3262 (abbreviate-file-name buffer-file-name
))))
3263 (regexp org-deadline-time-regexp
)
3264 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
3265 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3266 d2 diff dfrac wdays pos pos1 category tags
3267 ee txt head face s upcomingp donep timestr
)
3268 (goto-char (point-min))
3269 (while (re-search-forward regexp nil t
)
3272 (setq s
(match-string 1)
3273 pos
(1- (match-beginning 1))
3274 d2
(org-time-string-to-absolute
3275 (match-string 1) d1
'past
3276 org-agenda-repeating-timestamp-show-all
)
3278 wdays
(org-get-wdays s
)
3279 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3280 upcomingp
(and todayp
(> diff
0)))
3281 ;; When to show a deadline in the calendar:
3282 ;; If the expiration is within wdays warning time.
3283 ;; Past-due deadlines are only shown on the current date
3284 (if (or (and (<= diff wdays
)
3285 (and todayp
(not org-agenda-only-exact-dates
)))
3288 (setq category
(org-get-category))
3289 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3291 (goto-char (match-end 0))
3292 (setq pos1
(match-beginning 0))
3293 (setq tags
(org-get-tags-at pos1
))
3294 (setq head
(buffer-substring-no-properties
3296 (progn (skip-chars-forward "^\r\n")
3298 (setq donep
(string-match org-looking-at-done-regexp head
))
3299 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3301 (concat (substring s
(match-beginning 1)) " "))
3302 (setq timestr
'time
))
3304 (or org-agenda-skip-deadline-if-done
3307 (setq txt
(org-format-agenda-item
3309 (car org-agenda-deadline-leaders
)
3310 (if (functionp (nth 1 org-agenda-deadline-leaders
))
3311 (funcall (nth 1 org-agenda-deadline-leaders
) diff date
)
3312 (format (nth 1 org-agenda-deadline-leaders
)
3314 head category tags timestr
))))
3315 (setq txt org-agenda-no-heading-message
))
3317 (setq face
(org-agenda-deadline-face dfrac wdays
))
3318 (org-add-props txt props
3319 'org-marker
(org-agenda-new-marker pos
)
3320 'org-hd-marker
(org-agenda-new-marker pos1
)
3321 'priority
(+ (- diff
)
3322 (org-get-priority txt
))
3323 'org-category category
3324 'type
(if upcomingp
"upcoming-deadline" "deadline")
3325 'date
(if upcomingp date d2
)
3326 'face
(if donep
'org-done face
)
3327 'undone-face face
'done-face
'org-done
)
3331 (defun org-agenda-deadline-face (fraction &optional wdays
)
3332 "Return the face to displaying a deadline item.
3333 FRACTION is what fraction of the head-warning time has passed."
3334 (if (equal wdays
0) (setq fraction
1.
))
3335 (let ((faces org-agenda-deadline-faces
) f
)
3337 (while (setq f
(pop faces
))
3338 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3340 (defun org-agenda-get-scheduled ()
3341 "Return the scheduled information for agenda display."
3342 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3343 'org-todo-regexp org-todo-regexp
3344 'done-face
'org-done
3345 'mouse-face
'highlight
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-scheduled-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 pos pos1 category tags
3354 ee txt head pastschedp donep face timestr s
)
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 (setq pastschedp
(and todayp
(< diff
0)))
3366 ;; When to show a scheduled item in the calendar:
3367 ;; If it is on or past the date.
3368 (if (or (and (< diff
0)
3369 (< (abs diff
) org-scheduled-past-days
)
3370 (and todayp
(not org-agenda-only-exact-dates
)))
3373 (setq category
(org-get-category))
3374 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3376 (goto-char (match-end 0))
3377 (setq pos1
(match-beginning 0))
3378 (setq tags
(org-get-tags-at))
3379 (setq head
(buffer-substring-no-properties
3381 (progn (skip-chars-forward "^\r\n") (point))))
3382 (setq donep
(string-match org-looking-at-done-regexp head
))
3383 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3385 (concat (substring s
(match-beginning 1)) " "))
3386 (setq timestr
'time
))
3388 (or org-agenda-skip-scheduled-if-done
3391 (setq txt
(org-format-agenda-item
3393 (car org-agenda-scheduled-leaders
)
3394 (format (nth 1 org-agenda-scheduled-leaders
)
3396 head category tags timestr
))))
3397 (setq txt org-agenda-no-heading-message
))
3399 (setq face
(if pastschedp
3400 'org-scheduled-previously
3401 'org-scheduled-today
))
3402 (org-add-props txt props
3404 'face
(if donep
'org-done face
)
3405 'org-marker
(org-agenda-new-marker pos
)
3406 'org-hd-marker
(org-agenda-new-marker pos1
)
3407 'type
(if pastschedp
"past-scheduled" "scheduled")
3408 'date
(if pastschedp d2 date
)
3409 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
3410 'org-category category
)
3414 (defun org-agenda-get-blocks ()
3415 "Return the date-range information for agenda display."
3416 (let* ((props (list 'face nil
3417 'org-not-done-regexp org-not-done-regexp
3418 'org-todo-regexp org-todo-regexp
3419 'mouse-face
'highlight
3420 'keymap org-agenda-keymap
3422 (format "mouse-2 or RET jump to org file %s"
3423 (abbreviate-file-name buffer-file-name
))))
3424 (regexp org-tr-regexp
)
3425 (d0 (calendar-absolute-from-gregorian date
))
3426 marker hdmarker ee txt d1 d2 s1 s2 timestr category tags pos
3428 (goto-char (point-min))
3429 (while (re-search-forward regexp nil t
)
3433 (setq timestr
(match-string 0)
3436 d1
(time-to-days (org-time-string-to-time s1
))
3437 d2
(time-to-days (org-time-string-to-time s2
)))
3438 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
3439 ;; Only allow days between the limits, because the normal
3440 ;; date stamps will catch the limits.
3442 (setq marker
(org-agenda-new-marker (point)))
3443 (setq category
(org-get-category))
3444 (if (re-search-backward "^\\*+ " nil t
)
3446 (goto-char (match-beginning 0))
3447 (setq hdmarker
(org-agenda-new-marker (point)))
3448 (setq tags
(org-get-tags-at))
3449 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3450 (setq head
(match-string 1))
3451 (and org-agenda-skip-timestamp-if-done
3452 (org-entry-is-done-p)
3454 (setq txt
(org-format-agenda-item
3455 (format (if (= d1 d2
) "" "(%d/%d): ")
3456 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
3458 (if (= d0 d1
) timestr
))))
3459 (setq txt org-agenda-no-heading-message
))
3460 (org-add-props txt props
3461 'org-marker marker
'org-hd-marker hdmarker
3462 'type
"block" 'date date
3463 'priority
(org-get-priority txt
) 'org-category category
)
3466 ;; Sort the entries by expiration date.
3469 ;;; Agenda presentation and sorting
3471 (defvar org-prefix-has-time nil
3472 "A flag, set by `org-compile-prefix-format'.
3473 The flag is set if the currently compiled format contains a `%t'.")
3474 (defvar org-prefix-has-tag nil
3475 "A flag, set by `org-compile-prefix-format'.
3476 The flag is set if the currently compiled format contains a `%T'.")
3478 (defun org-format-agenda-item (extra txt
&optional category tags dotime
3480 "Format TXT to be inserted into the agenda buffer.
3481 In particular, it adds the prefix and corresponding text properties. EXTRA
3482 must be a string and replaces the `%s' specifier in the prefix format.
3483 CATEGORY (string, symbol or nil) may be used to overrule the default
3484 category taken from local variable or file name. It will replace the `%c'
3485 specifier in the format. DOTIME, when non-nil, indicates that a
3486 time-of-day should be extracted from TXT for sorting of this entry, and for
3487 the `%t' specifier in the format. When DOTIME is a string, this string is
3488 searched for a time before TXT is. NOPREFIX is a flag and indicates that
3489 only the correctly processes TXT should be returned - this is used by
3490 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
3491 Any match of REMOVE-RE will be removed from TXT."
3493 ;; Diary entries sometimes have extra whitespace at the beginning
3494 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
3495 (let* ((category (or category
3497 (if buffer-file-name
3498 (file-name-sans-extension
3499 (file-name-nondirectory buffer-file-name
))
3501 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
3502 time
; time and tag are needed for the eval of the prefix format
3503 (ts (if dotime
(concat (if (stringp dotime
) dotime
"") txt
)))
3504 (time-of-day (and dotime
(org-get-time-of-day ts
)))
3505 stamp plain s0 s1 s2 rtn srp
)
3506 (when (and dotime time-of-day org-prefix-has-time
)
3507 ;; Extract starting and ending time and move them to prefix
3508 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
3509 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
3510 (setq s0
(match-string 0 ts
)
3511 srp
(and stamp
(match-end 3))
3512 s1
(match-string (if plain
1 2) ts
)
3513 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
3515 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
3516 ;; them, we might want to remove them there to avoid duplication.
3517 ;; The user can turn this off with a variable.
3518 (if (and org-agenda-remove-times-when-in-prefix
(or stamp plain
)
3519 (string-match (concat (regexp-quote s0
) " *") txt
)
3520 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
3521 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
3522 (= (match-beginning 0) 0)
3524 (setq txt
(replace-match "" nil nil txt
))))
3525 ;; Normalize the time(s) to 24 hour
3526 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
3527 (if s2
(setq s2
(org-get-time-of-day s2
'string t
))))
3529 (when (and s1
(not s2
) org-agenda-default-appointment-duration
3530 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
3531 (let ((m (+ (string-to-number (match-string 2 s1
))
3532 (* 60 (string-to-number (match-string 1 s1
)))
3533 org-agenda-default-appointment-duration
))
3535 (setq h
(/ m
60) m
(- m
(* h
60)))
3536 (setq s2
(format "%02d:%02d" h m
))))
3538 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
3540 ;; Tags are in the string
3541 (if (or (eq org-agenda-remove-tags t
)
3542 (and org-agenda-remove-tags
3543 org-prefix-has-tag
))
3544 (setq txt
(replace-match "" t t txt
))
3545 (setq txt
(replace-match
3546 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
3547 (match-string 2 txt
))
3551 (while (string-match remove-re txt
)
3552 (setq txt
(replace-match "" t t txt
))))
3554 ;; Create the final string
3557 ;; Prepare the variables needed in the eval of the compiled format
3558 (setq time
(cond (s2 (concat s1
"-" s2
))
3559 (s1 (concat s1
"......"))
3562 category
(if (symbolp category
) (symbol-name category
) category
))
3563 ;; Evaluate the compiled format
3564 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
3566 ;; And finally add the text properties
3567 (org-add-props rtn nil
3568 'org-category
(downcase category
) 'tags tags
3569 'org-highest-priority org-highest-priority
3570 'org-lowest-priority org-lowest-priority
3571 'prefix-length
(- (length rtn
) (length txt
))
3572 'time-of-day time-of-day
3578 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
3579 (defvar org-agenda-sorting-strategy-selected nil
)
3581 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
3583 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
3584 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
3585 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
3586 ((member 'weekly
(car org-agenda-time-grid
)))
3587 (t (throw 'exit list
)))
3588 (let* ((have (delq nil
(mapcar
3589 (lambda (x) (get-text-property 1 'time-of-day x
))
3591 (string (nth 1 org-agenda-time-grid
))
3592 (gridtimes (nth 2 org-agenda-time-grid
))
3593 (req (car org-agenda-time-grid
))
3594 (remove (member 'remove-match req
))
3596 (if (and (member 'require-timed req
) (not have
))
3597 ;; don't show empty grid
3599 (while (setq time
(pop gridtimes
))
3600 (unless (and remove
(member time have
))
3601 (setq time
(int-to-string time
))
3602 (push (org-format-agenda-item
3604 (concat (substring time
0 -
2) ":" (substring time -
2)))
3607 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
3608 (if (member 'time-up org-agenda-sorting-strategy-selected
)
3610 (append list new
)))))
3612 (defun org-compile-prefix-format (key)
3613 "Compile the prefix format into a Lisp form that can be evaluated.
3614 The resulting form is returned and stored in the variable
3615 `org-prefix-format-compiled'."
3616 (setq org-prefix-has-time nil org-prefix-has-tag nil
)
3618 ((stringp org-agenda-prefix-format
)
3619 org-agenda-prefix-format
)
3620 ((assq key org-agenda-prefix-format
)
3621 (cdr (assq key org-agenda-prefix-format
)))
3622 (t " %-12:c%?-12t% s")))
3624 varform vars var e c f opt
)
3625 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cts]\\)"
3627 (setq var
(cdr (assoc (match-string 4 s
)
3628 '(("c" . category
) ("t" . time
) ("s" . extra
)
3630 c
(or (match-string 3 s
) "")
3631 opt
(match-beginning 1)
3632 start
(1+ (match-beginning 0)))
3633 (if (equal var
'time
) (setq org-prefix-has-time t
))
3634 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
3635 (setq f
(concat "%" (match-string 2 s
) "s"))
3638 `(if (equal "" ,var
)
3640 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
3641 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
3642 (setq s
(replace-match "%s" t nil s
))
3643 (push varform vars
))
3644 (setq vars
(nreverse vars
))
3645 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
3647 (defun org-set-sorting-strategy (key)
3648 (if (symbolp (car org-agenda-sorting-strategy
))
3650 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
3651 (setq org-agenda-sorting-strategy-selected
3652 (or (cdr (assq key org-agenda-sorting-strategy
))
3653 (cdr (assq 'agenda org-agenda-sorting-strategy
))
3654 '(time-up category-keep priority-down
)))))
3656 (defun org-get-time-of-day (s &optional string mod24
)
3657 "Check string S for a time of day.
3658 If found, return it as a military time number between 0 and 2400.
3659 If not found, return nil.
3660 The optional STRING argument forces conversion into a 5 character wide string
3664 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
3665 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
3666 (let* ((h (string-to-number (match-string 1 s
)))
3667 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
3668 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
3669 (am-p (equal ampm
"am"))
3670 (h1 (cond ((not ampm
) h
)
3671 ((= h
12) (if am-p
0 12))
3672 (t (+ h
(if am-p
0 12)))))
3673 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
3675 (t0 (+ (* 100 h2
) m
))
3676 (t1 (concat (if (>= h1
24) "+" " ")
3677 (if (< t0
100) "0" "")
3678 (if (< t0
10) "0" "")
3679 (int-to-string t0
))))
3680 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
3682 (defun org-finalize-agenda-entries (list &optional nosort
)
3683 "Sort and concatenate the agenda items."
3684 (setq list
(mapcar 'org-agenda-highlight-todo list
))
3687 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
3689 (defun org-agenda-highlight-todo (x)
3693 (beginning-of-line 1)
3694 (setq re
(get-text-property (point) 'org-todo-regexp
))
3695 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
3696 (when (looking-at (concat "[ \t]*\\.*" re
" +"))
3697 (add-text-properties (match-beginning 0) (match-end 0)
3698 (list 'face
(org-get-todo-face 0)))
3699 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
3700 (delete-region (match-beginning 1) (1- (match-end 0)))
3701 (goto-char (match-beginning 1))
3702 (insert (format org-agenda-todo-keyword-format s
)))))
3703 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
3704 pl
(get-text-property 0 'prefix-length x
))
3706 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
3708 (add-text-properties
3709 (or (match-end 1) (match-end 0)) (match-end 0)
3710 (list 'face
(org-get-todo-face (match-string 2 x
)))
3712 (setq x
(concat (substring x
0 (match-end 1))
3713 (format org-agenda-todo-keyword-format
3716 (substring x
(match-end 3)))))
3719 (defsubst org-cmp-priority
(a b
)
3720 "Compare the priorities of string A and B."
3721 (let ((pa (or (get-text-property 1 'priority a
) 0))
3722 (pb (or (get-text-property 1 'priority b
) 0)))
3723 (cond ((> pa pb
) +1)
3727 (defsubst org-cmp-category
(a b
)
3728 "Compare the string values of categories of strings A and B."
3729 (let ((ca (or (get-text-property 1 'org-category a
) ""))
3730 (cb (or (get-text-property 1 'org-category b
) "")))
3731 (cond ((string-lessp ca cb
) -
1)
3732 ((string-lessp cb ca
) +1)
3735 (defsubst org-cmp-tag
(a b
)
3736 "Compare the string values of categories of strings A and B."
3737 (let ((ta (car (last (get-text-property 1 'tags a
))))
3738 (tb (car (last (get-text-property 1 'tags b
)))))
3741 ((string-lessp ta tb
) -
1)
3742 ((string-lessp tb ta
) +1)
3745 (defsubst org-cmp-time
(a b
)
3746 "Compare the time-of-day values of strings A and B."
3747 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
3748 (ta (or (get-text-property 1 'time-of-day a
) def
))
3749 (tb (or (get-text-property 1 'time-of-day b
) def
)))
3750 (cond ((< ta tb
) -
1)
3754 (defun org-entries-lessp (a b
)
3755 "Predicate for sorting agenda entries."
3756 ;; The following variables will be used when the form is evaluated.
3757 ;; So even though the compiler complains, keep them.
3758 (let* ((time-up (org-cmp-time a b
))
3759 (time-down (if time-up
(- time-up
) nil
))
3760 (priority-up (org-cmp-priority a b
))
3761 (priority-down (if priority-up
(- priority-up
) nil
))
3762 (category-up (org-cmp-category a b
))
3763 (category-down (if category-up
(- category-up
) nil
))
3764 (category-keep (if category-up
+1 nil
))
3765 (tag-up (org-cmp-tag a b
))
3766 (tag-down (if tag-up
(- tag-up
) nil
)))
3768 (eval (cons 'or org-agenda-sorting-strategy-selected
))
3769 '((-1 . t
) (1 . nil
) (nil . nil
))))))
3771 ;;; Agenda restriction lock
3773 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
3774 "Overlay to mark the headline to which arenda commands are restricted.")
3775 (org-overlay-put org-agenda-restriction-lock-overlay
3776 'face
'org-agenda-restriction-lock
)
3777 (org-overlay-put org-agenda-restriction-lock-overlay
3778 'help-echo
"Agendas are currently limited to this subtree.")
3779 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3781 (defun org-agenda-set-restriction-lock (&optional type
)
3782 "Set restriction lock for agenda, to current subtree or file.
3783 Restriction will be the file if TYPE is `file', or if type is the
3784 universal prefix '(4), or if the cursor is before the first headline
3785 in the file. Otherwise, restriction will be to the current subtree."
3787 (and (equal type
'(4)) (setq type
'file
))
3790 ((org-at-heading-p) 'subtree
)
3791 ((condition-case nil
(org-back-to-heading t
) (error nil
))
3794 (if (eq type
'subtree
)
3796 (setq org-agenda-restrict t
)
3797 (setq org-agenda-overriding-restriction
'subtree
)
3798 (put 'org-agenda-files
'org-restrict
3799 (list (buffer-file-name (buffer-base-buffer))))
3800 (org-back-to-heading t
)
3801 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
3802 (move-marker org-agenda-restrict-begin
(point))
3803 (move-marker org-agenda-restrict-end
3804 (save-excursion (org-end-of-subtree t
)))
3805 (message "Locking agenda restriction to subtree"))
3806 (put 'org-agenda-files
'org-restrict
3807 (list (buffer-file-name (buffer-base-buffer))))
3808 (setq org-agenda-restrict nil
)
3809 (setq org-agenda-overriding-restriction
'file
)
3810 (move-marker org-agenda-restrict-begin nil
)
3811 (move-marker org-agenda-restrict-end nil
)
3812 (message "Locking agenda restriction to file"))
3813 (setq current-prefix-arg nil
)
3814 (org-agenda-maybe-redo))
3816 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
3817 "Remove the agenda restriction lock."
3819 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3820 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
3821 (setq org-agenda-overriding-restriction nil
)
3822 (setq org-agenda-restrict nil
)
3823 (put 'org-agenda-files
'org-restrict nil
)
3824 (move-marker org-agenda-restrict-begin nil
)
3825 (move-marker org-agenda-restrict-end nil
)
3826 (setq current-prefix-arg nil
)
3827 (message "Agenda restriction lock removed")
3828 (or noupdate
(org-agenda-maybe-redo)))
3830 (defun org-agenda-maybe-redo ()
3831 "If there is any window showing the agenda view, update it."
3832 (let ((w (get-buffer-window org-agenda-buffer-name t
))
3833 (w0 (selected-window)))
3838 (if org-agenda-overriding-restriction
3839 (message "Agenda view shifted to new %s restriction"
3840 org-agenda-overriding-restriction
)
3841 (message "Agenda restriction lock removed")))))
3845 (defun org-agenda-check-type (error &rest types
)
3846 "Check if agenda buffer is of allowed type.
3847 If ERROR is non-nil, throw an error, otherwise just return nil."
3848 (if (memq org-agenda-type types
)
3851 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
3854 (defun org-agenda-quit ()
3855 "Exit agenda by removing the window or the buffer."
3857 (let ((buf (current-buffer)))
3858 (if (not (one-window-p)) (delete-window))
3860 (org-agenda-reset-markers)
3861 (org-columns-remove-overlays))
3862 ;; Maybe restore the pre-agenda window configuration.
3863 (and org-agenda-restore-windows-after-quit
3864 (not (eq org-agenda-window-setup
'other-frame
))
3865 org-pre-agenda-window-conf
3866 (set-window-configuration org-pre-agenda-window-conf
)))
3868 (defun org-agenda-exit ()
3869 "Exit agenda by removing the window or the buffer.
3870 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
3871 Org-mode buffers visited directly by the user will not be touched."
3873 (org-release-buffers org-agenda-new-buffers
)
3874 (setq org-agenda-new-buffers nil
)
3877 (defun org-agenda-execute (arg)
3878 "Execute another agenda command, keeping same window.\\<global-map>
3879 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
3881 (let ((org-agenda-window-setup 'current-window
))
3884 (defun org-save-all-org-buffers ()
3885 "Save all Org-mode buffers without user confirmation."
3887 (message "Saving all Org-mode buffers...")
3888 (save-some-buffers t
'org-mode-p
)
3889 (message "Saving all Org-mode buffers... done"))
3891 (defun org-agenda-redo ()
3893 When this is the global TODO list, a prefix argument will be interpreted."
3895 (let* ((org-agenda-keep-modes t
)
3896 (line (org-current-line))
3897 (window-line (- line
(org-current-line (window-start))))
3898 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
3899 (message "Rebuilding agenda buffer...")
3900 (org-let lprops
'(eval org-agenda-redo-command
))
3901 (setq org-agenda-undo-list nil
3902 org-agenda-pending-undo-list nil
)
3903 (message "Rebuilding agenda buffer...done")
3905 (recenter window-line
)))
3907 (defun org-agenda-manipulate-query-add ()
3908 "Manipulate the query by adding a search term with positive selection.
3909 Positive selection means, the term must be matched for selection of an entry."
3911 (org-agenda-manipulate-query ?\
[))
3912 (defun org-agenda-manipulate-query-subtract ()
3913 "Manipulate the query by adding a search term with negative selection.
3914 Negative selection means, term must not be matched for selection of an entry."
3916 (org-agenda-manipulate-query ?\
]))
3917 (defun org-agenda-manipulate-query-add-re ()
3918 "Manipulate the query by adding a search regexp with positive selection.
3919 Positive selection means, the regexp must match for selection of an entry."
3921 (org-agenda-manipulate-query ?\
{))
3922 (defun org-agenda-manipulate-query-subtract-re ()
3923 "Manipulate the query by adding a search regexp with negative selection.
3924 Negative selection means, regexp must not match for selection of an entry."
3926 (org-agenda-manipulate-query ?\
}))
3927 (defun org-agenda-manipulate-query (char)
3929 ((memq org-agenda-type
'(timeline agenda
))
3930 (if (y-or-n-p "Re-display with inactive time stamps included? ")
3931 (let ((org-agenda-include-inactive-timestamps t
))
3934 ((eq org-agenda-type
'search
)
3936 'org-agenda-query-string
3937 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
3938 (?\
{ .
" +{}") (?\
} .
" -{}")))))
3939 (setq org-agenda-redo-command
3940 (list 'org-search-view
3942 org-agenda-query-string
3943 (+ (length org-agenda-query-string
)
3944 (if (member char
'(?\
{ ?\
})) 0 1))))
3945 (set-register org-agenda-query-register org-agenda-query-string
)
3947 (t (error "Cannot manipulate query for %s-type agenda buffers"
3950 (defun org-add-to-string (var string
)
3951 (set var
(concat (symbol-value var
) string
)))
3953 (defun org-agenda-goto-date (date)
3954 "Jump to DATE in agenda."
3955 (interactive (list (org-read-date)))
3956 (org-agenda-list nil date
))
3958 (defun org-agenda-goto-today ()
3961 (org-agenda-check-type t
'timeline
'agenda
)
3962 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
3964 (tdpos (goto-char tdpos
))
3965 ((eq org-agenda-type
'agenda
)
3966 (let* ((sd (time-to-days
3967 (time-subtract (current-time)
3968 (list 0 (* 3600 org-extend-today-until
) 0))))
3969 (comp (org-agenda-compute-time-span sd org-agenda-span
))
3970 (org-agenda-overriding-arguments org-agenda-last-arguments
))
3971 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
3972 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
3974 (org-agenda-find-same-or-today-or-agenda)))
3975 (t (error "Cannot find today")))))
3977 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
3979 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
3980 (text-property-any (point-min) (point-max) 'org-today t
)
3981 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
3984 (defun org-agenda-later (arg)
3985 "Go forward in time by thee current span.
3986 With prefix ARG, go forward that many times the current span."
3988 (org-agenda-check-type t
'agenda
)
3989 (let* ((span org-agenda-span
)
3990 (sd org-starting-day
)
3991 (greg (calendar-gregorian-from-absolute sd
))
3992 (cnt (get-text-property (point) 'org-day-cnt
))
3996 (setq sd
(+ arg sd
) nd
1))
3998 (setq sd
(+ (* 7 arg
) sd
) nd
7))
4000 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
4001 sd
(calendar-absolute-from-gregorian greg2
))
4002 (setcar greg2
(1+ (car greg2
)))
4003 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
4005 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
4006 sd
(calendar-absolute-from-gregorian greg2
))
4007 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
4008 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
4009 (let ((org-agenda-overriding-arguments
4010 (list (car org-agenda-last-arguments
) sd nd t
)))
4012 (org-agenda-find-same-or-today-or-agenda cnt
))))
4014 (defun org-agenda-earlier (arg)
4015 "Go backward in time by the current span.
4016 With prefix ARG, go backward that many times the current span."
4018 (org-agenda-later (- arg
)))
4020 (defun org-agenda-day-view (&optional day-of-year
)
4021 "Switch to daily view for agenda.
4022 With argument DAY-OF-YEAR, switch to that day of the year."
4024 (setq org-agenda-ndays
1)
4025 (org-agenda-change-time-span 'day day-of-year
))
4026 (defun org-agenda-week-view (&optional iso-week
)
4027 "Switch to daily view for agenda.
4028 With argument ISO-WEEK, switch to the corresponding ISO week.
4029 If ISO-WEEK has more then 2 digits, only the last two encode the
4030 week. Any digits before this encode a year. So 200712 means
4031 week 12 of year 2007. Years in the range 1938-2037 can also be
4032 written as 2-digit years."
4034 (setq org-agenda-ndays
7)
4035 (org-agenda-change-time-span 'week iso-week
))
4036 (defun org-agenda-month-view (&optional month
)
4037 "Switch to daily view for agenda.
4038 With argument MONTH, switch to that month."
4040 (org-agenda-change-time-span 'month month
))
4041 (defun org-agenda-year-view (&optional year
)
4042 "Switch to daily view for agenda.
4043 With argument YEAR, switch to that year.
4044 If MONTH has more then 2 digits, only the last two encode the
4045 month. Any digits before this encode a year. So 200712 means
4046 December year 2007. Years in the range 1938-2037 can also be
4047 written as 2-digit years."
4050 (setq year
(org-small-year-to-year year
)))
4051 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4052 (org-agenda-change-time-span 'year year
)
4055 (defun org-agenda-change-time-span (span &optional n
)
4056 "Change the agenda view to SPAN.
4057 SPAN may be `day', `week', `month', `year'."
4058 (org-agenda-check-type t
'agenda
)
4059 (if (and (not n
) (equal org-agenda-span span
))
4060 (error "Viewing span is already \"%s\"" span
))
4061 (let* ((sd (or (get-text-property (point) 'day
)
4063 (computed (org-agenda-compute-time-span sd span n
))
4064 (org-agenda-overriding-arguments
4065 (list (car org-agenda-last-arguments
)
4066 (car computed
) (cdr computed
) t
)))
4068 (org-agenda-find-same-or-today-or-agenda))
4069 (org-agenda-set-mode-name)
4070 (message "Switched to %s view" span
))
4072 (defun org-agenda-compute-time-span (sd span
&optional n
)
4073 "Compute starting date and number of days for agenda.
4074 SPAN may be `day', `week', `month', `year'. The return value
4075 is a cons cell with the starting date and the number of days,
4076 so that the date SD will be in that range."
4077 (let* ((greg (calendar-gregorian-from-absolute sd
))
4081 nd w1 y1 m1 thisweek
)
4085 (setq sd
(+ (calendar-absolute-from-gregorian
4090 (let* ((nt (calendar-day-of-week
4091 (calendar-gregorian-from-absolute sd
)))
4092 (d (if org-agenda-start-on-weekday
4093 (- nt org-agenda-start-on-weekday
)
4095 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
4098 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
4100 (setq y1
(org-small-year-to-year (/ n
100))
4103 (calendar-absolute-from-iso
4105 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
4108 (when (and n
(> n
99))
4109 (setq y1
(org-small-year-to-year (/ n
100))
4111 (setq sd
(calendar-absolute-from-gregorian
4112 (list (or n mg
) 1 (or y1 yg
)))
4113 nd
(- (calendar-absolute-from-gregorian
4114 (list (1+ (or n mg
)) 1 (or y1 yg
)))
4117 (setq sd
(calendar-absolute-from-gregorian
4118 (list 1 1 (or n yg
)))
4119 nd
(- (calendar-absolute-from-gregorian
4120 (list 1 1 (1+ (or n yg
))))
4124 (defun org-agenda-next-date-line (&optional arg
)
4125 "Jump to the next line indicating a date in agenda buffer."
4127 (org-agenda-check-type t
'agenda
'timeline
)
4128 (beginning-of-line 1)
4129 ;; This does not work if user makes date format that starts with a blank
4130 (if (looking-at "^\\S-") (forward-char 1))
4131 (if (not (re-search-forward "^\\S-" nil t arg
))
4134 (error "No next date after this line in this buffer")))
4135 (goto-char (match-beginning 0)))
4137 (defun org-agenda-previous-date-line (&optional arg
)
4138 "Jump to the previous line indicating a date in agenda buffer."
4140 (org-agenda-check-type t
'agenda
'timeline
)
4141 (beginning-of-line 1)
4142 (if (not (re-search-backward "^\\S-" nil t arg
))
4143 (error "No previous date before this line in this buffer")))
4145 ;; Initialize the highlight
4146 (defvar org-hl
(org-make-overlay 1 1))
4147 (org-overlay-put org-hl
'face
'highlight
)
4149 (defun org-highlight (begin end
&optional buffer
)
4150 "Highlight a region with overlay."
4151 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
4152 org-hl begin end
(or buffer
(current-buffer))))
4154 (defun org-unhighlight ()
4155 "Detach overlay INDEX."
4156 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
4158 ;; FIXME this is currently not used.
4159 (defun org-highlight-until-next-command (beg end
&optional buffer
)
4160 "Move the highlight overlay to BEG/END, remove it before the next command."
4161 (org-highlight beg end buffer
)
4162 (add-hook 'pre-command-hook
'org-unhighlight-once
))
4163 (defun org-unhighlight-once ()
4164 "Remove the highlight from its position, and this function from the hook."
4165 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
4168 (defun org-agenda-follow-mode ()
4169 "Toggle follow mode in an agenda buffer."
4171 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
4172 (org-agenda-set-mode-name)
4173 (message "Follow mode is %s"
4174 (if org-agenda-follow-mode
"on" "off")))
4176 (defun org-agenda-clockreport-mode ()
4177 "Toggle clocktable mode in an agenda buffer."
4179 (org-agenda-check-type t
'agenda
)
4180 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
4181 (org-agenda-set-mode-name)
4183 (message "Clocktable mode is %s"
4184 (if org-agenda-clockreport-mode
"on" "off")))
4186 (defun org-agenda-log-mode ()
4187 "Toggle log mode in an agenda buffer."
4189 (org-agenda-check-type t
'agenda
'timeline
)
4190 (setq org-agenda-show-log
(not org-agenda-show-log
))
4191 (org-agenda-set-mode-name)
4193 (message "Log mode is %s"
4194 (if org-agenda-show-log
"on" "off")))
4196 (defun org-agenda-toggle-diary ()
4197 "Toggle diary inclusion in an agenda buffer."
4199 (org-agenda-check-type t
'agenda
)
4200 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
4202 (org-agenda-set-mode-name)
4203 (message "Diary inclusion turned %s"
4204 (if org-agenda-include-diary
"on" "off")))
4206 (defun org-agenda-toggle-time-grid ()
4207 "Toggle time grid in an agenda buffer."
4209 (org-agenda-check-type t
'agenda
)
4210 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
4212 (org-agenda-set-mode-name)
4213 (message "Time-grid turned %s"
4214 (if org-agenda-use-time-grid
"on" "off")))
4216 (defun org-agenda-set-mode-name ()
4217 "Set the mode name to indicate all the small mode settings."
4219 (concat "Org-Agenda"
4220 (if (equal org-agenda-ndays
1) " Day" "")
4221 (if (equal org-agenda-ndays
7) " Week" "")
4222 (if org-agenda-follow-mode
" Follow" "")
4223 (if org-agenda-include-diary
" Diary" "")
4224 (if org-agenda-use-time-grid
" Grid" "")
4225 (if org-agenda-show-log
" Log" "")
4226 (if org-agenda-clockreport-mode
" Clock" "")))
4227 (force-mode-line-update))
4229 (defun org-agenda-post-command-hook ()
4230 (and (eolp) (not (bolp)) (backward-char 1))
4231 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
4232 (if (and org-agenda-follow-mode
4233 (get-text-property (point) 'org-marker
))
4236 (defun org-agenda-show-priority ()
4237 "Show the priority of the current item.
4238 This priority is composed of the main priority given with the [#A] cookies,
4239 and by additional input from the age of a schedules or deadline entry."
4241 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
4242 (message "Priority is %d" (if pri pri -
1000))))
4244 (defun org-agenda-show-tags ()
4245 "Show the tags applicable to the current item."
4247 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
4249 (message "Tags are :%s:"
4250 (org-no-properties (mapconcat 'identity tags
":")))
4251 (message "No tags associated with this line"))))
4253 (defun org-agenda-goto (&optional highlight
)
4254 "Go to the Org-mode file which contains the item at point."
4256 (let* ((marker (or (get-text-property (point) 'org-marker
)
4257 (org-agenda-error)))
4258 (buffer (marker-buffer marker
))
4259 (pos (marker-position marker
)))
4260 (switch-to-buffer-other-window buffer
)
4264 (org-show-context 'agenda
)
4266 (and (outline-next-heading)
4267 (org-flag-heading nil
)))) ; show the next heading
4268 (recenter (/ (window-height) 2))
4269 (run-hooks 'org-agenda-after-show-hook
)
4270 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
4272 (defvar org-agenda-after-show-hook nil
4273 "Normal hook run after an item has been shown from the agenda.
4274 Point is in the buffer where the item originated.")
4276 (defun org-agenda-kill ()
4277 "Kill the entry or subtree belonging to the current agenda entry."
4279 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4280 (let* ((marker (or (get-text-property (point) 'org-marker
)
4281 (org-agenda-error)))
4282 (buffer (marker-buffer marker
))
4283 (pos (marker-position marker
))
4284 (type (get-text-property (point) 'type
))
4285 dbeg dend
(n 0) conf
)
4286 (org-with-remote-undo buffer
4287 (with-current-buffer buffer
4290 (if (and (org-mode-p) (not (member type
'("sexp"))))
4291 (setq dbeg
(progn (org-back-to-heading t
) (point))
4292 dend
(org-end-of-subtree t t
))
4293 (setq dbeg
(point-at-bol)
4294 dend
(min (point-max) (1+ (point-at-eol)))))
4296 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
4297 (setq conf
(or (eq t org-agenda-confirm-kill
)
4298 (and (numberp org-agenda-confirm-kill
)
4299 (> n org-agenda-confirm-kill
))))
4302 (format "Delete entry with %d lines in buffer \"%s\"? "
4303 n
(buffer-name buffer
))))
4305 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
4306 (with-current-buffer buffer
(delete-region dbeg dend
))
4307 (message "Agenda item and source killed"))))
4309 (defun org-agenda-archive ()
4310 "Archive the entry or subtree belonging to the current agenda entry."
4312 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4313 (let* ((marker (or (get-text-property (point) 'org-marker
)
4314 (org-agenda-error)))
4315 (buffer (marker-buffer marker
))
4316 (pos (marker-position marker
)))
4317 (org-with-remote-undo buffer
4318 (with-current-buffer buffer
4322 (org-remove-subtree-entries-from-agenda)
4323 (org-back-to-heading t
)
4324 (org-archive-subtree))
4325 (error "Archiving works only in Org-mode files"))))))
4327 (defun org-agenda-archive-to-archive-sibling ()
4328 "Move the entry to the archive sibling."
4330 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4331 (let* ((marker (or (get-text-property (point) 'org-marker
)
4332 (org-agenda-error)))
4333 (buffer (marker-buffer marker
))
4334 (pos (marker-position marker
)))
4335 (org-with-remote-undo buffer
4336 (with-current-buffer buffer
4340 (org-remove-subtree-entries-from-agenda)
4341 (org-back-to-heading t
)
4342 (org-archive-to-archive-sibling))
4343 (error "Archiving works only in Org-mode files"))))))
4345 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
4346 "Remove all lines in the agenda that correspond to a given subtree.
4347 The subtree is the one in buffer BUF, starting at BEG and ending at END.
4348 If this information is not given, the function uses the tree at point."
4349 (let ((buf (or buf
(current-buffer))) m p
)
4351 (unless (and beg end
)
4352 (org-back-to-heading t
)
4354 (org-end-of-subtree t
)
4356 (set-buffer (get-buffer org-agenda-buffer-name
))
4358 (goto-char (point-max))
4359 (beginning-of-line 1)
4361 (when (and (setq m
(get-text-property (point) 'org-marker
))
4362 (equal buf
(marker-buffer m
))
4363 (setq p
(marker-position m
))
4366 (let ((inhibit-read-only t
))
4367 (delete-region (point-at-bol) (1+ (point-at-eol)))))
4368 (beginning-of-line 0))))))
4370 (defun org-agenda-open-link ()
4371 "Follow the link in the current line, if any."
4373 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
4376 (narrow-to-region (point-at-bol) (point-at-eol))
4377 (org-open-at-point))))
4379 (defun org-agenda-copy-local-variable (var)
4380 "Get a variable from a referenced buffer and install it here."
4381 (let ((m (get-text-property (point) 'org-marker
)))
4382 (when (and m
(buffer-live-p (marker-buffer m
)))
4383 (org-set-local var
(with-current-buffer (marker-buffer m
)
4384 (symbol-value var
))))))
4386 (defun org-agenda-switch-to (&optional delete-other-windows
)
4387 "Go to the Org-mode file which contains the item at point."
4389 (let* ((marker (or (get-text-property (point) 'org-marker
)
4390 (org-agenda-error)))
4391 (buffer (marker-buffer marker
))
4392 (pos (marker-position marker
)))
4393 (switch-to-buffer buffer
)
4394 (and delete-other-windows
(delete-other-windows))
4398 (org-show-context 'agenda
)
4400 (and (outline-next-heading)
4401 (org-flag-heading nil
)))))) ; show the next heading
4403 (defun org-agenda-goto-mouse (ev)
4404 "Go to the Org-mode file which contains the item at the mouse click."
4406 (mouse-set-point ev
)
4409 (defun org-agenda-show ()
4410 "Display the Org-mode file which contains the item at point."
4412 (let ((win (selected-window)))
4414 (select-window win
)))
4416 (defun org-agenda-recenter (arg)
4417 "Display the Org-mode file which contains the item at point and recenter."
4419 (let ((win (selected-window)))
4422 (select-window win
)))
4424 (defun org-agenda-show-mouse (ev)
4425 "Display the Org-mode file which contains the item at the mouse click."
4427 (mouse-set-point ev
)
4430 (defun org-agenda-check-no-diary ()
4431 "Check if the entry is a diary link and abort if yes."
4432 (if (get-text-property (point) 'org-agenda-diary-link
)
4433 (org-agenda-error)))
4435 (defun org-agenda-error ()
4436 (error "Command not allowed in this line"))
4438 (defun org-agenda-tree-to-indirect-buffer ()
4439 "Show the subtree corresponding to the current entry in an indirect buffer.
4440 This calls the command `org-tree-to-indirect-buffer' from the original
4442 With numerical prefix arg ARG, go up to this level and then take that tree.
4443 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
4446 (org-agenda-check-no-diary)
4447 (let* ((marker (or (get-text-property (point) 'org-marker
)
4448 (org-agenda-error)))
4449 (buffer (marker-buffer marker
))
4450 (pos (marker-position marker
)))
4451 (with-current-buffer buffer
4454 (call-interactively 'org-tree-to-indirect-buffer
)))))
4456 (defvar org-last-heading-marker
(make-marker)
4457 "Marker pointing to the headline that last changed its TODO state
4458 by a remote command from the agenda.")
4460 (defun org-agenda-todo-nextset ()
4461 "Switch TODO entry to next sequence."
4463 (org-agenda-todo 'nextset
))
4465 (defun org-agenda-todo-previousset ()
4466 "Switch TODO entry to previous sequence."
4468 (org-agenda-todo 'previousset
))
4470 (defun org-agenda-todo (&optional arg
)
4471 "Cycle TODO state of line at point, also in Org-mode file.
4472 This changes the line at point, all other lines in the agenda referring to
4473 the same tree node, and the headline of the tree node in the Org-mode file."
4475 (org-agenda-check-no-diary)
4476 (let* ((col (current-column))
4477 (marker (or (get-text-property (point) 'org-marker
)
4478 (org-agenda-error)))
4479 (buffer (marker-buffer marker
))
4480 (pos (marker-position marker
))
4481 (hdmarker (get-text-property (point) 'org-hd-marker
))
4482 (inhibit-read-only t
)
4484 (org-with-remote-undo buffer
4485 (with-current-buffer buffer
4488 (org-show-context 'agenda
)
4490 (and (outline-next-heading)
4491 (org-flag-heading nil
))) ; show the next heading
4493 (and (bolp) (forward-char 1))
4494 (setq newhead
(org-get-heading))
4496 (org-back-to-heading)
4497 (move-marker org-last-heading-marker
(point))))
4498 (beginning-of-line 1)
4500 (org-agenda-change-all-lines newhead hdmarker
'fixface
))
4501 (move-to-column col
))))
4503 (defun org-agenda-add-note (&optional arg
)
4504 "Add a time-stamped note to the entry at point."
4506 (org-agenda-check-no-diary)
4507 (let* ((marker (or (get-text-property (point) 'org-marker
)
4508 (org-agenda-error)))
4509 (buffer (marker-buffer marker
))
4510 (pos (marker-position marker
))
4511 (hdmarker (get-text-property (point) 'org-hd-marker
))
4512 (inhibit-read-only t
))
4513 (with-current-buffer buffer
4516 (org-show-context 'agenda
)
4518 (and (outline-next-heading)
4519 (org-flag-heading nil
))) ; show the next heading
4522 (defun org-agenda-change-all-lines (newhead hdmarker
&optional fixface
)
4523 "Change all lines in the agenda buffer which match HDMARKER.
4524 The new content of the line will be NEWHEAD (as modified by
4525 `org-format-agenda-item'). HDMARKER is checked with
4526 `equal' against all `org-hd-marker' text properties in the file.
4527 If FIXFACE is non-nil, the face of each item is modified acording to
4528 the new TODO state."
4529 (let* ((inhibit-read-only t
)
4530 props m pl undone-face done-face finish new dotime cat tags
)
4532 (goto-char (point-max))
4533 (beginning-of-line 1)
4535 (setq finish
(bobp))
4536 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
4538 (setq props
(text-properties-at (point))
4539 dotime
(get-text-property (point) 'dotime
)
4540 cat
(get-text-property (point) 'org-category
)
4541 tags
(get-text-property (point) 'tags
)
4542 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
4543 pl
(get-text-property (point) 'prefix-length
)
4544 undone-face
(get-text-property (point) 'undone-face
)
4545 done-face
(get-text-property (point) 'done-face
))
4549 (beginning-of-line 1)
4550 (and (looking-at ".*\n?") (replace-match "")))
4552 (replace-match new t t
)
4553 (beginning-of-line 1)
4554 (add-text-properties (point-at-bol) (point-at-eol) props
)
4556 (add-text-properties
4557 (point-at-bol) (point-at-eol)
4559 (if org-last-todo-state-is-todo
4560 undone-face done-face
))))
4561 (org-agenda-highlight-todo 'line
)
4562 (beginning-of-line 1))
4563 (t (error "Line update did not work"))))
4564 (beginning-of-line 0)))
4565 (org-finalize-agenda)))
4567 (defun org-agenda-align-tags (&optional line
)
4568 "Align all tags in agenda items to `org-agenda-tags-column'."
4569 (let ((inhibit-read-only t
) l c
)
4571 (goto-char (if line
(point-at-bol) (point-min)))
4572 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4573 (if line
(point-at-eol) nil
) t
)
4574 (add-text-properties
4575 (match-beginning 2) (match-end 2)
4576 (list 'face
(delq nil
(list 'org-tag
(get-text-property
4577 (match-beginning 2) 'face
)))))
4578 (setq l
(- (match-end 2) (match-beginning 2))
4579 c
(if (< org-agenda-tags-column
0)
4580 (- (abs org-agenda-tags-column
) l
)
4581 org-agenda-tags-column
))
4582 (delete-region (match-beginning 1) (match-end 1))
4583 (goto-char (match-beginning 1))
4584 (insert (org-add-props
4585 (make-string (max 1 (- c
(current-column))) ?\
)
4586 (text-properties-at (point))))))))
4588 (defun org-agenda-priority-up ()
4589 "Increase the priority of line at point, also in Org-mode file."
4591 (org-agenda-priority 'up
))
4593 (defun org-agenda-priority-down ()
4594 "Decrease the priority of line at point, also in Org-mode file."
4596 (org-agenda-priority 'down
))
4598 (defun org-agenda-priority (&optional force-direction
)
4599 "Set the priority of line at point, also in Org-mode file.
4600 This changes the line at point, all other lines in the agenda referring to
4601 the same tree node, and the headline of the tree node in the Org-mode file."
4603 (org-agenda-check-no-diary)
4604 (let* ((marker (or (get-text-property (point) 'org-marker
)
4605 (org-agenda-error)))
4606 (hdmarker (get-text-property (point) 'org-hd-marker
))
4607 (buffer (marker-buffer hdmarker
))
4608 (pos (marker-position hdmarker
))
4609 (inhibit-read-only t
)
4611 (org-with-remote-undo buffer
4612 (with-current-buffer buffer
4615 (org-show-context 'agenda
)
4617 (and (outline-next-heading)
4618 (org-flag-heading nil
))) ; show the next heading
4619 (funcall 'org-priority force-direction
)
4621 (setq newhead
(org-get-heading)))
4622 (org-agenda-change-all-lines newhead hdmarker
)
4623 (beginning-of-line 1))))
4625 ;; FIXME: should fix the tags property of the agenda line.
4626 (defun org-agenda-set-tags ()
4627 "Set tags for the current headline."
4629 (org-agenda-check-no-diary)
4630 (if (and (org-region-active-p) (interactive-p))
4631 (call-interactively 'org-change-tag-in-region
)
4632 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4633 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4634 (org-agenda-error)))
4635 (buffer (marker-buffer hdmarker
))
4636 (pos (marker-position hdmarker
))
4637 (inhibit-read-only t
)
4639 (org-with-remote-undo buffer
4640 (with-current-buffer buffer
4644 (org-show-context 'agenda
))
4646 (and (outline-next-heading)
4647 (org-flag-heading nil
))) ; show the next heading
4649 (call-interactively 'org-set-tags
)
4651 (setq newhead
(org-get-heading)))
4652 (org-agenda-change-all-lines newhead hdmarker
)
4653 (beginning-of-line 1)))))
4655 (defun org-agenda-toggle-archive-tag ()
4656 "Toggle the archive tag for the current entry."
4658 (org-agenda-check-no-diary)
4659 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4660 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4661 (org-agenda-error)))
4662 (buffer (marker-buffer hdmarker
))
4663 (pos (marker-position hdmarker
))
4664 (inhibit-read-only t
)
4666 (org-with-remote-undo buffer
4667 (with-current-buffer buffer
4670 (org-show-context 'agenda
)
4672 (and (outline-next-heading)
4673 (org-flag-heading nil
))) ; show the next heading
4674 (call-interactively 'org-toggle-archive-tag
)
4676 (setq newhead
(org-get-heading)))
4677 (org-agenda-change-all-lines newhead hdmarker
)
4678 (beginning-of-line 1))))
4680 (defun org-agenda-date-later (arg &optional what
)
4681 "Change the date of this item to one day later."
4683 (org-agenda-check-type t
'agenda
'timeline
)
4684 (org-agenda-check-no-diary)
4685 (let* ((marker (or (get-text-property (point) 'org-marker
)
4686 (org-agenda-error)))
4687 (buffer (marker-buffer marker
))
4688 (pos (marker-position marker
)))
4689 (org-with-remote-undo buffer
4690 (with-current-buffer buffer
4693 (if (not (org-at-timestamp-p))
4694 (error "Cannot find time stamp"))
4695 (org-timestamp-change arg
(or what
'day
)))
4696 (org-agenda-show-new-time marker org-last-changed-timestamp
))
4697 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
4699 (defun org-agenda-date-earlier (arg &optional what
)
4700 "Change the date of this item to one day earlier."
4702 (org-agenda-date-later (- arg
) what
))
4704 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
4705 "Show new date stamp via text properties."
4706 ;; We use text properties to make this undoable
4707 (let ((inhibit-read-only t
))
4708 (setq stamp
(concat " " prefix
" => " stamp
))
4710 (goto-char (point-max))
4712 (when (equal marker
(get-text-property (point) 'org-marker
))
4713 (move-to-column (- (window-width) (length stamp
)) t
)
4714 (if (featurep 'xemacs
)
4715 ;; Use `duplicable' property to trigger undo recording
4716 (let ((ex (make-extent nil nil
))
4717 (gl (make-glyph stamp
)))
4718 (set-glyph-face gl
'secondary-selection
)
4719 (set-extent-properties
4720 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
4721 (insert-extent ex
(1- (point)) (point-at-eol)))
4722 (add-text-properties
4723 (1- (point)) (point-at-eol)
4724 (list 'display
(org-add-props stamp nil
4725 'face
'secondary-selection
))))
4726 (beginning-of-line 1))
4727 (beginning-of-line 0)))))
4729 (defun org-agenda-date-prompt (arg)
4730 "Change the date of this item. Date is prompted for, with default today.
4731 The prefix ARG is passed to the `org-time-stamp' command and can therefore
4732 be used to request time specification in the time stamp."
4734 (org-agenda-check-type t
'agenda
'timeline
)
4735 (org-agenda-check-no-diary)
4736 (let* ((marker (or (get-text-property (point) 'org-marker
)
4737 (org-agenda-error)))
4738 (buffer (marker-buffer marker
))
4739 (pos (marker-position marker
)))
4740 (org-with-remote-undo buffer
4741 (with-current-buffer buffer
4744 (if (not (org-at-timestamp-p))
4745 (error "Cannot find time stamp"))
4746 (org-time-stamp arg
)
4747 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
4749 (defun org-agenda-schedule (arg)
4750 "Schedule the item at point."
4752 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4753 (org-agenda-check-no-diary)
4754 (let* ((marker (or (get-text-property (point) 'org-marker
)
4755 (org-agenda-error)))
4756 (type (marker-insertion-type marker
))
4757 (buffer (marker-buffer marker
))
4758 (pos (marker-position marker
))
4759 (org-insert-labeled-timestamps-at-point nil
)
4761 (when type
(message "%s" type
) (sit-for 3))
4762 (set-marker-insertion-type marker t
)
4763 (org-with-remote-undo buffer
4764 (with-current-buffer buffer
4767 (setq ts
(org-schedule arg
)))
4768 (org-agenda-show-new-time marker ts
"S"))
4769 (message "Item scheduled for %s" ts
)))
4771 (defun org-agenda-deadline (arg)
4772 "Schedule the item at point."
4774 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4775 (org-agenda-check-no-diary)
4776 (let* ((marker (or (get-text-property (point) 'org-marker
)
4777 (org-agenda-error)))
4778 (buffer (marker-buffer marker
))
4779 (pos (marker-position marker
))
4780 (org-insert-labeled-timestamps-at-point nil
)
4782 (org-with-remote-undo buffer
4783 (with-current-buffer buffer
4786 (setq ts
(org-deadline arg
)))
4787 (org-agenda-show-new-time marker ts
"S"))
4788 (message "Deadline for this item set to %s" ts
)))
4791 (defun org-agenda-clock-in (&optional arg
)
4792 "Start the clock on the currently selected item."
4794 (org-agenda-check-no-diary)
4795 (let* ((marker (or (get-text-property (point) 'org-marker
)
4796 (org-agenda-error)))
4797 (pos (marker-position marker
)))
4798 (org-with-remote-undo (marker-buffer marker
)
4799 (with-current-buffer (marker-buffer marker
)
4804 (defun org-agenda-clock-out (&optional arg
)
4805 "Stop the currently running clock."
4807 (unless (marker-buffer org-clock-marker
)
4808 (error "No running clock"))
4809 (org-with-remote-undo (marker-buffer org-clock-marker
)
4812 (defun org-agenda-clock-cancel (&optional arg
)
4813 "Cancel the currently running clock."
4815 (unless (marker-buffer org-clock-marker
)
4816 (error "No running clock"))
4817 (org-with-remote-undo (marker-buffer org-clock-marker
)
4818 (org-clock-cancel)))
4820 (defun org-agenda-diary-entry ()
4821 "Make a diary entry, like the `i' command from the calendar.
4822 All the standard commands work: block, weekly etc."
4824 (org-agenda-check-type t
'agenda
'timeline
)
4825 (require 'diary-lib
)
4827 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
4828 (read-char-exclusive)))
4829 (cmd (cdr (assoc char
4830 '((?d . insert-diary-entry
)
4831 (?w . insert-weekly-diary-entry
)
4832 (?m . insert-monthly-diary-entry
)
4833 (?y . insert-yearly-diary-entry
)
4834 (?a . insert-anniversary-diary-entry
)
4835 (?b . insert-block-diary-entry
)
4836 (?c . insert-cyclic-diary-entry
)))))
4837 (oldf (symbol-function 'calendar-cursor-to-date
))
4838 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
4840 (mark (or (mark t
) (point))))
4842 (error "No command associated with <%c>" char
))
4843 (unless (and (get-text-property point
'day
)
4844 (or (not (equal ?b char
))
4845 (get-text-property mark
'day
)))
4846 (error "Don't know which date to use for diary entry"))
4847 ;; We implement this by hacking the `calendar-cursor-to-date' function
4848 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
4849 (let ((calendar-mark-ring
4850 (list (calendar-gregorian-from-absolute
4851 (or (get-text-property mark
'day
)
4852 (get-text-property point
'day
))))))
4855 (fset 'calendar-cursor-to-date
4856 (lambda (&optional error
)
4857 (calendar-gregorian-from-absolute
4858 (get-text-property point
'day
))))
4859 (call-interactively cmd
))
4860 (fset 'calendar-cursor-to-date oldf
)))))
4863 (defun org-agenda-execute-calendar-command (cmd)
4864 "Execute a calendar command from the agenda, with the date associated to
4865 the cursor position."
4866 (org-agenda-check-type t
'agenda
'timeline
)
4867 (require 'diary-lib
)
4868 (unless (get-text-property (point) 'day
)
4869 (error "Don't know which date to use for calendar command"))
4870 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
4872 (date (calendar-gregorian-from-absolute
4873 (get-text-property point
'day
)))
4874 ;; the following 2 vars are needed in the calendar
4875 (displayed-month (car date
))
4876 (displayed-year (nth 2 date
)))
4879 (fset 'calendar-cursor-to-date
4880 (lambda (&optional error
)
4881 (calendar-gregorian-from-absolute
4882 (get-text-property point
'day
))))
4883 (call-interactively cmd
))
4884 (fset 'calendar-cursor-to-date oldf
))))
4886 (defun org-agenda-phases-of-moon ()
4887 "Display the phases of the moon for the 3 months around the cursor date."
4889 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
4891 (defun org-agenda-holidays ()
4892 "Display the holidays for the 3 months around the cursor date."
4894 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
4896 (defvar calendar-longitude
)
4897 (defvar calendar-latitude
)
4898 (defvar calendar-location-name
)
4900 (defun org-agenda-sunrise-sunset (arg)
4901 "Display sunrise and sunset for the cursor date.
4902 Latitude and longitude can be specified with the variables
4903 `calendar-latitude' and `calendar-longitude'. When called with prefix
4904 argument, latitude and longitude will be prompted for."
4907 (let ((calendar-longitude (if arg nil calendar-longitude
))
4908 (calendar-latitude (if arg nil calendar-latitude
))
4909 (calendar-location-name
4910 (if arg
"the given coordinates" calendar-location-name
)))
4911 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
4913 (defun org-agenda-goto-calendar ()
4914 "Open the Emacs calendar with the date at the cursor."
4916 (org-agenda-check-type t
'agenda
'timeline
)
4917 (let* ((day (or (get-text-property (point) 'day
)
4918 (error "Don't know which date to open in calendar")))
4919 (date (calendar-gregorian-from-absolute day
))
4920 (calendar-move-hook nil
)
4921 (calendar-view-holidays-initially-flag nil
)
4922 (calendar-view-diary-initially-flag nil
)
4923 (view-calendar-holidays-initially nil
)
4924 (calendar-view-diary-initially-flag nil
)
4925 (calendar-view-holidays-initially-flag nil
)
4926 (view-diary-entries-initially nil
))
4928 (calendar-goto-date date
)))
4931 (defun org-calendar-goto-agenda ()
4932 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
4933 This is a command that has to be installed in `calendar-mode-map'."
4935 (org-agenda-list nil
(calendar-absolute-from-gregorian
4936 (calendar-cursor-to-date))
4939 (defun org-agenda-convert-date ()
4941 (org-agenda-check-type t
'agenda
'timeline
)
4942 (let ((day (get-text-property (point) 'day
))
4945 (error "Don't know which date to convert"))
4946 (setq date
(calendar-gregorian-from-absolute day
))
4948 "Gregorian: " (calendar-date-string date
) "\n"
4949 "ISO: " (calendar-iso-date-string date
) "\n"
4950 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
4951 "Julian: " (calendar-julian-date-string date
) "\n"
4952 "Astron. JD: " (calendar-astro-date-string date
)
4953 " (Julian date number at noon UTC)\n"
4954 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
4955 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
4956 "French: " (calendar-french-date-string date
) "\n"
4957 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
4958 "Mayan: " (calendar-mayan-date-string date
) "\n"
4959 "Coptic: " (calendar-coptic-date-string date
) "\n"
4960 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
4961 "Persian: " (calendar-persian-date-string date
) "\n"
4962 "Chinese: " (calendar-chinese-date-string date
) "\n"))
4963 (with-output-to-temp-buffer "*Dates*"
4965 (if (fboundp 'fit-window-to-buffer
)
4966 (fit-window-to-buffer (get-buffer-window "*Dates*")))))
4969 ;;; Appointment reminders
4971 (defvar appt-time-msg-list
)
4974 (defun org-agenda-to-appt (&optional refresh filter
)
4975 "Activate appointments found in `org-agenda-files'.
4976 With a \\[universal-argument] prefix, refresh the list of
4979 If FILTER is t, interactively prompt the user for a regular
4980 expression, and filter out entries that don't match it.
4982 If FILTER is a string, use this string as a regular expression
4983 for filtering entries out.
4985 FILTER can also be an alist with the car of each cell being
4986 either 'headline or 'category. For example:
4988 '((headline \"IMPORTANT\")
4989 (category \"Work\"))
4991 will only add headlines containing IMPORTANT or headlines
4992 belonging to the \"Work\" category."
4995 (if refresh
(setq appt-time-msg-list nil
))
4997 (setq filter
(read-from-minibuffer "Regexp filter: ")))
4998 (let* ((cnt 0) ; count added events
4999 (org-agenda-new-buffers nil
)
5000 (org-deadline-warning-days 0)
5001 (today (org-date-to-gregorian
5002 (time-to-days (current-time))))
5003 (files (org-agenda-files)) entries file
)
5004 ;; Get all entries which may contain an appt
5005 (while (setq file
(pop files
))
5008 (org-agenda-get-day-entries
5009 file today
:timestamp
:scheduled
:deadline
))))
5010 (setq entries
(delq nil entries
))
5011 ;; Map thru entries and find if we should filter them out
5014 (let* ((evt (org-trim (get-text-property 1 'txt x
)))
5015 (cat (get-text-property 1 'org-category x
))
5016 (tod (get-text-property 1 'time-of-day x
))
5017 (ok (or (null filter
)
5018 (and (stringp filter
) (string-match filter evt
))
5021 (cadr (assoc 'category filter
)) cat
)
5023 (cadr (assoc 'headline filter
)) evt
))))))
5024 ;; FIXME: Shall we remove text-properties for the appt text?
5025 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
5027 (setq tod
(number-to-string tod
)
5028 tod
(when (string-match
5029 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)" tod
)
5030 (concat (match-string 1 tod
) ":"
5031 (match-string 2 tod
))))
5033 (setq cnt
(1+ cnt
))))) entries
)
5034 (org-release-buffers org-agenda-new-buffers
)
5036 (message "No event to add")
5037 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
5039 (provide 'org-agenda
)
5041 ;;; org-agenda.el ends here