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 (defgroup org-agenda-windows nil
490 "Options concerning the windows used by the Agenda in Org Mode."
491 :tag
"Org Agenda Windows"
494 (defcustom org-agenda-window-setup
'reorganize-frame
495 "How the agenda buffer should be displayed.
496 Possible values for this option are:
498 current-window Show agenda in the current window, keeping all other windows.
499 other-frame Use `switch-to-buffer-other-frame' to display agenda.
500 other-window Use `switch-to-buffer-other-window' to display agenda.
501 reorganize-frame Show only two windows on the current frame, the current
502 window and the agenda.
503 See also the variable `org-agenda-restore-windows-after-quit'."
504 :group
'org-agenda-windows
506 (const current-window
)
509 (const reorganize-frame
)))
511 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
512 "The min and max height of the agenda window as a fraction of frame height.
513 The value of the variable is a cons cell with two numbers between 0 and 1.
514 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
515 :group
'org-agenda-windows
516 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
518 (defcustom org-agenda-restore-windows-after-quit nil
519 "Non-nil means, restore window configuration open exiting agenda.
520 Before the window configuration is changed for displaying the agenda,
521 the current status is recorded. When the agenda is exited with
522 `q' or `x' and this option is set, the old state is restored. If
523 `org-agenda-window-setup' is `other-frame', the value of this
524 option will be ignored.."
525 :group
'org-agenda-windows
528 (defgroup org-agenda-daily
/weekly nil
529 "Options concerning the daily/weekly agenda."
530 :tag
"Org Agenda Daily/Weekly"
533 (defcustom org-agenda-ndays
7
534 "Number of days to include in overview display.
536 :group
'org-agenda-daily
/weekly
539 (defcustom org-agenda-start-on-weekday
1
540 "Non-nil means, start the overview always on the specified weekday.
541 0 denotes Sunday, 1 denotes Monday etc.
542 When nil, always start on the current day."
543 :group
'org-agenda-daily
/weekly
544 :type
'(choice (const :tag
"Today" nil
)
545 (number :tag
"Weekday No.")))
547 (defcustom org-agenda-show-all-dates t
548 "Non-nil means, `org-agenda' shows every day in the selected range.
549 When nil, only the days which actually have entries are shown."
550 :group
'org-agenda-daily
/weekly
553 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
554 "Format string for displaying dates in the agenda.
555 Used by the daily/weekly agenda and by the timeline. This should be
556 a format string understood by `format-time-string', or a function returning
557 the formatted date as a string. The function must take a single argument,
558 a calendar-style date list like (month day year)."
559 :group
'org-agenda-daily
/weekly
561 (string :tag
"Format string")
562 (function :tag
"Function")))
564 (defun org-agenda-format-date-aligned (date)
565 "Format a date string for display in the daily/weekly agenda, or timeline.
566 This function makes sure that dates are aligned for easy reading."
568 (let* ((dayname (calendar-day-name date
))
570 (day-of-week (calendar-day-of-week date
))
572 (monthname (calendar-month-name month
))
574 (iso-week (org-days-to-iso-week
575 (calendar-absolute-from-gregorian date
)))
576 (weekyear (cond ((and (= month
1) (>= iso-week
52))
578 ((and (= month
12) (<= iso-week
1))
581 (weekstring (if (= day-of-week
1)
582 (format " W%02d" iso-week
)
584 (format "%-10s %2d %s %4d%s"
585 dayname day monthname year weekstring
)))
587 (defcustom org-agenda-include-diary nil
588 "If non-nil, include in the agenda entries from the Emacs Calendar's diary."
589 :group
'org-agenda-daily
/weekly
592 (defcustom org-agenda-include-all-todo nil
593 "Set means weekly/daily agenda will always contain all TODO entries.
594 The TODO entries will be listed at the top of the agenda, before
595 the entries for specific days."
596 :group
'org-agenda-daily
/weekly
599 (defcustom org-agenda-repeating-timestamp-show-all t
600 "Non-nil means, show all occurences of a repeating stamp in the agenda.
601 When nil, only one occurence is shown, either today or the
602 nearest into the future."
603 :group
'org-agenda-daily
/weekly
606 (defcustom org-scheduled-past-days
10000
607 "No. of days to continue listing scheduled items that are not marked DONE.
608 When an item is scheduled on a date, it shows up in the agenda on this
609 day and will be listed until it is marked done for the number of days
611 :group
'org-agenda-daily
/weekly
614 (defcustom org-agenda-start-with-clockreport-mode nil
615 "The initial value of clockreport-mode in a newly created agenda window."
616 :group
'org-agenda-startup
617 :group
'org-agenda-daily
/weekly
620 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
621 "Property list with parameters for the clocktable in clockreport mode.
622 This is the display mode that shows a clock table in the daily/weekly
623 agenda, the properties for this dynamic block can be set here.
624 The usual clocktable parameters are allowed here, but you cannot set
625 the properties :name, :tstart, :tend, :block, and :scope - these will
626 be overwritten to make sure the content accurately reflects the
627 current display in the agenda."
628 :group
'org-agenda-daily
/weekly
632 (defgroup org-agenda-time-grid nil
633 "Options concerning the time grid in the Org-mode Agenda."
634 :tag
"Org Agenda Time Grid"
637 (defcustom org-agenda-use-time-grid t
638 "Non-nil means, show a time grid in the agenda schedule.
639 A time grid is a set of lines for specific times (like every two hours between
640 8:00 and 20:00). The items scheduled for a day at specific times are
641 sorted in between these lines.
642 For details about when the grid will be shown, and what it will look like, see
643 the variable `org-agenda-time-grid'."
644 :group
'org-agenda-time-grid
647 (defcustom org-agenda-time-grid
648 '((daily today require-timed
)
650 (800 1000 1200 1400 1600 1800 2000))
652 "The settings for time grid for agenda display.
653 This is a list of three items. The first item is again a list. It contains
654 symbols specifying conditions when the grid should be displayed:
656 daily if the agenda shows a single day
657 weekly if the agenda shows an entire week
658 today show grid on current date, independent of daily/weekly display
659 require-timed show grid only if at least one item has a time specification
661 The second item is a string which will be places behing the grid time.
663 The third item is a list of integers, indicating the times that should have
665 :group
'org-agenda-time-grid
668 (set :greedy t
:tag
"Grid Display Options"
669 (const :tag
"Show grid in single day agenda display" daily
)
670 (const :tag
"Show grid in weekly agenda display" weekly
)
671 (const :tag
"Always show grid for today" today
)
672 (const :tag
"Show grid only if any timed entries are present"
674 (const :tag
"Skip grid times already present in an entry"
676 (string :tag
"Grid String")
677 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
679 (defgroup org-agenda-sorting nil
680 "Options concerning sorting in the Org-mode Agenda."
681 :tag
"Org Agenda Sorting"
684 (defcustom org-agenda-sorting-strategy
685 '((agenda time-up category-keep priority-down
)
686 (todo category-keep priority-down
)
687 (tags category-keep priority-down
)
688 (search category-keep
))
689 "Sorting structure for the agenda items of a single day.
690 This is a list of symbols which will be used in sequence to determine
691 if an entry should be listed before another entry. The following
692 symbols are recognized:
694 time-up Put entries with time-of-day indications first, early first
695 time-down Put entries with time-of-day indications first, late first
696 category-keep Keep the default order of categories, corresponding to the
697 sequence in `org-agenda-files'.
698 category-up Sort alphabetically by category, A-Z.
699 category-down Sort alphabetically by category, Z-A.
700 tag-up Sort alphabetically by last tag, A-Z.
701 tag-down Sort alphabetically by last tag, Z-A.
702 priority-up Sort numerically by priority, high priority last.
703 priority-down Sort numerically by priority, high priority first.
705 The different possibilities will be tried in sequence, and testing stops
706 if one comparison returns a \"not-equal\". For example, the default
707 '(time-up category-keep priority-down)
708 means: Pull out all entries having a specified time of day and sort them,
709 in order to make a time schedule for the current day the first thing in the
710 agenda listing for the day. Of the entries without a time indication, keep
711 the grouped in categories, don't sort the categories, but keep them in
712 the sequence given in `org-agenda-files'. Within each category sort by
715 Leaving out `category-keep' would mean that items will be sorted across
716 categories by priority.
718 Instead of a single list, this can also be a set of list for specific
719 contents, with a context symbol in the car of the list, any of
720 `agenda', `todo', `tags' for the corresponding agenda views."
721 :group
'org-agenda-sorting
723 (repeat :tag
"General" ,org-sorting-choice
)
724 (list :tag
"Individually"
725 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
726 (repeat ,org-sorting-choice
))
727 (cons (const :tag
"Strategy for TODO lists" todo
)
728 (repeat ,org-sorting-choice
))
729 (cons (const :tag
"Strategy for Tags matches" tags
)
730 (repeat ,org-sorting-choice
)))))
732 (defcustom org-sort-agenda-notime-is-late t
733 "Non-nil means, items without time are considered late.
734 This is only relevant for sorting. When t, items which have no explicit
735 time like 15:30 will be considered as 99:01, i.e. later than any items which
736 do have a time. When nil, the default time is before 0:00. You can use this
737 option to decide if the schedule for today should come before or after timeless
739 :group
'org-agenda-sorting
742 (defgroup org-agenda-line-format nil
743 "Options concerning the entry prefix in the Org-mode agenda display."
744 :tag
"Org Agenda Line Format"
747 (defcustom org-agenda-prefix-format
748 '((agenda .
" %-12:c%?-12t% s")
752 (search .
" %-12:c"))
753 "Format specifications for the prefix of items in the agenda views.
754 An alist with four entries, for the different agenda types. The keys to the
755 sublists are `agenda', `timeline', `todo', and `tags'. The values
757 This format works similar to a printf format, with the following meaning:
759 %c the category of the item, \"Diary\" for entries from the diary, or
760 as given by the CATEGORY keyword or derived from the file name.
761 %T the *last* tag of the item. Last because inherited tags come
763 %t the time-of-day specification if one applies to the entry, in the
765 %s Scheduling/Deadline information, a short string
767 All specifiers work basically like the standard `%s' of printf, but may
768 contain two additional characters: A question mark just after the `%' and
769 a whitespace/punctuation character just before the final letter.
771 If the first character after `%' is a question mark, the entire field
772 will only be included if the corresponding value applies to the
773 current entry. This is useful for fields which should have fixed
774 width when present, but zero width when absent. For example,
775 \"%?-12t\" will result in a 12 character time field if a time of the
776 day is specified, but will completely disappear in entries which do
779 If there is punctuation or whitespace character just before the final
780 format letter, this character will be appended to the field value if
781 the value is not empty. For example, the format \"%-12:c\" leads to
782 \"Diary: \" if the category is \"Diary\". If the category were be
783 empty, no additional colon would be interted.
785 The default value of this option is \" %-12:c%?-12t% s\", meaning:
786 - Indent the line with two space characters
787 - Give the category in a 12 chars wide field, padded with whitespace on
788 the right (because of `-'). Append a colon if there is a category
790 - If there is a time-of-day, put it into a 12 chars wide field. If no
791 time, don't put in an empty field, just skip it (because of '?').
792 - Finally, put the scheduling information and append a whitespace.
794 As another example, if you don't want the time-of-day of entries in
795 the prefix, you could use:
797 (setq org-agenda-prefix-format \" %-11:c% s\")
799 See also the variables `org-agenda-remove-times-when-in-prefix' and
800 `org-agenda-remove-tags'."
802 (string :tag
"General format")
803 (list :greedy t
:tag
"View dependent"
804 (cons (const agenda
) (string :tag
"Format"))
805 (cons (const timeline
) (string :tag
"Format"))
806 (cons (const todo
) (string :tag
"Format"))
807 (cons (const tags
) (string :tag
"Format"))
808 (cons (const search
) (string :tag
"Format"))))
809 :group
'org-agenda-line-format
)
811 (defvar org-prefix-format-compiled nil
812 "The compiled version of the most recently used prefix format.
813 See the variable `org-agenda-prefix-format'.")
815 (defcustom org-agenda-todo-keyword-format
"%-1s"
816 "Format for the TODO keyword in agenda lines.
817 Set this to something like \"%-12s\" if you want all TODO keywords
818 to occupy a fixed space in the agenda display."
819 :group
'org-agenda-line-format
822 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
823 "Text preceeding scheduled items in the agenda view.
824 This is a list with two strings. The first applies when the item is
825 scheduled on the current day. The second applies when it has been scheduled
826 previously, it may contain a %d to capture how many days ago the item was
828 :group
'org-agenda-line-format
830 (string :tag
"Scheduled today ")
831 (string :tag
"Scheduled previously")))
833 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
834 "Text preceeding deadline items in the agenda view.
835 This is a list with two strings. The first applies when the item has its
836 deadline on the current day. The second applies when it is in the past or
837 in the future, it may contain %d to capture how many days away the deadline
839 :group
'org-agenda-line-format
841 (string :tag
"Deadline today ")
842 (choice :tag
"Deadline relative"
843 (string :tag
"Format string")
846 (defcustom org-agenda-remove-times-when-in-prefix t
847 "Non-nil means, remove duplicate time specifications in agenda items.
848 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
849 time-of-day specification in a headline or diary entry is extracted and
850 placed into the prefix. If this option is non-nil, the original specification
851 \(a timestamp or -range, or just a plain time(range) specification like
852 11:30-4pm) will be removed for agenda display. This makes the agenda less
854 The option can be t or nil. It may also be the symbol `beg', indicating
855 that the time should only be removed what it is located at the beginning of
856 the headline/diary entry."
857 :group
'org-agenda-line-format
859 (const :tag
"Always" t
)
860 (const :tag
"Never" nil
)
861 (const :tag
"When at beginning of entry" beg
)))
864 (defcustom org-agenda-default-appointment-duration nil
865 "Default duration for appointments that only have a starting time.
866 When nil, no duration is specified in such cases.
867 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
868 :group
'org-agenda-line-format
870 (integer :tag
"Minutes")
871 (const :tag
"No default duration")))
874 (defcustom org-agenda-remove-tags nil
875 "Non-nil means, remove the tags from the headline copy in the agenda.
876 When this is the symbol `prefix', only remove tags when
877 `org-agenda-prefix-format' contains a `%T' specifier."
878 :group
'org-agenda-line-format
880 (const :tag
"Always" t
)
881 (const :tag
"Never" nil
)
882 (const :tag
"When prefix format contains %T" prefix
)))
884 (if (fboundp 'defvaralias
)
885 (defvaralias 'org-agenda-remove-tags-when-in-prefix
886 'org-agenda-remove-tags
))
888 (defcustom org-agenda-tags-column -
80
889 "Shift tags in agenda items to this column.
890 If this number is positive, it specifies the column. If it is negative,
891 it means that the tags should be flushright to that column. For example,
892 -80 works well for a normal 80 character screen."
893 :group
'org-agenda-line-format
896 (if (fboundp 'defvaralias
)
897 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
899 (defcustom org-agenda-fontify-priorities t
900 "Non-nil means, highlight low and high priorities in agenda.
901 When t, the highest priority entries are bold, lowest priority italic.
902 This may also be an association list of priority faces. The face may be
903 a names face, or a list like `(:background \"Red\")'."
904 :group
'org-agenda-line-format
906 (const :tag
"Never" nil
)
907 (const :tag
"Defaults" t
)
908 (repeat :tag
"Specify"
909 (list (character :tag
"Priority" :value ?A
)
910 (sexp :tag
"face")))))
927 (defun org-add-agenda-custom-command (entry)
928 "Replace or add a command in `org-agenda-custom-commands'.
929 This is mostly for hacking and trying a new command - once the command
930 works you probably want to add it to `org-agenda-custom-commands' for good."
931 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
933 (setcdr ass
(cdr entry
))
934 (push entry org-agenda-custom-commands
))))
936 ;;; Define the Org-agenda-mode
938 (defvar org-agenda-mode-map
(make-sparse-keymap)
939 "Keymap for `org-agenda-mode'.")
941 (defvar org-agenda-menu
) ; defined later in this file.
942 (defvar org-agenda-follow-mode nil
)
943 (defvar org-agenda-clockreport-mode nil
)
944 (defvar org-agenda-show-log nil
)
945 (defvar org-agenda-redo-command nil
)
946 (defvar org-agenda-query-string nil
)
947 (defvar org-agenda-mode-hook nil
)
948 (defvar org-agenda-type nil
)
949 (defvar org-agenda-force-single-file nil
)
951 (defun org-agenda-mode ()
952 "Mode for time-sorted view on action items in Org-mode files.
954 The following commands are available:
956 \\{org-agenda-mode-map}"
958 (kill-all-local-variables)
959 (setq org-agenda-undo-list nil
960 org-agenda-pending-undo-list nil
)
961 (setq major-mode
'org-agenda-mode
)
962 ;; Keep global-font-lock-mode from turning on font-lock-mode
963 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
964 (setq mode-name
"Org-Agenda")
965 (use-local-map org-agenda-mode-map
)
966 (easy-menu-add org-agenda-menu
)
967 (if org-startup-truncated
(setq truncate-lines t
))
968 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
969 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
970 ;; Make sure properties are removed when copying text
971 (when (boundp 'buffer-substring-filters
)
972 (org-set-local 'buffer-substring-filters
974 (set-text-properties 0 (length x
) nil x
) x
)
975 buffer-substring-filters
)))
976 (unless org-agenda-keep-modes
977 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
978 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
979 org-agenda-show-log nil
))
981 '("Agenda") "Agenda Files"
985 (if (get 'org-agenda-files
'org-restrict
)
986 "Restricted to single file"
988 '(org-edit-agenda-file-list)
989 (not (get 'org-agenda-files
'org-restrict
)))
991 (mapcar 'org-file-menu-entry
(org-agenda-files))))
992 (org-agenda-set-mode-name)
994 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
995 (list 'org-agenda-mode-hook
)))
997 (substitute-key-definition 'undo
'org-agenda-undo
998 org-agenda-mode-map global-map
)
999 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1000 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1001 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1002 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1003 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1004 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1005 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1006 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1007 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1008 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1009 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1010 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1011 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1012 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1013 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1014 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1015 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1016 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1017 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1018 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1019 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1020 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1021 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1022 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1023 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1024 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1025 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1026 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-date-later
)
1027 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-date-earlier
)
1028 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-date-later
)
1029 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-date-earlier
)
1031 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1032 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1033 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1034 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1035 (while l
(org-defkey org-agenda-mode-map
1036 (int-to-string (pop l
)) 'digit-argument
)))
1038 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1039 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1040 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1041 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1042 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1043 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1044 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1045 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1046 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1047 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1048 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1049 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1050 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1051 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1052 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1053 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1054 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1055 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1056 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1057 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1058 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1059 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1060 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1061 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1062 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1063 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1064 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1065 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1066 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1067 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1068 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1069 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1070 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1071 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1072 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1073 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1074 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1075 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1076 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1077 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1078 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1079 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1080 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1081 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1082 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1084 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1085 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1086 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1087 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1089 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1090 "Local keymap for agenda entries from Org-mode.")
1092 (org-defkey org-agenda-keymap
1093 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1094 (org-defkey org-agenda-keymap
1095 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1096 (when org-agenda-mouse-1-follows-link
1097 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1098 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1102 ["Show" org-agenda-show t
]
1103 ["Go To (other window)" org-agenda-goto t
]
1104 ["Go To (this window)" org-agenda-switch-to t
]
1105 ["Follow Mode" org-agenda-follow-mode
1106 :style toggle
:selected org-agenda-follow-mode
:active t
]
1107 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1109 ["Cycle TODO" org-agenda-todo t
]
1110 ["Archive subtree" org-agenda-archive t
]
1111 ["Delete subtree" org-agenda-kill t
]
1112 ["Add note" org-agenda-add-note t
]
1114 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1115 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1116 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1117 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1119 ("Tags and Properties"
1120 ["Show all Tags" org-agenda-show-tags t
]
1121 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1122 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1124 ["Column View" org-columns t
])
1126 ["Schedule" org-agenda-schedule t
]
1127 ["Set Deadline" org-agenda-deadline t
]
1129 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1130 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1131 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1133 ["Clock in" org-agenda-clock-in t
]
1134 ["Clock out" org-agenda-clock-out t
]
1135 ["Clock cancel" org-agenda-clock-cancel t
]
1136 ["Goto running clock" org-clock-goto t
])
1138 ["Set Priority" org-agenda-priority t
]
1139 ["Increase Priority" org-agenda-priority-up t
]
1140 ["Decrease Priority" org-agenda-priority-down t
]
1141 ["Show Priority" org-agenda-show-priority t
])
1143 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1144 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1145 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1146 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1147 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1148 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1150 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1153 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1154 :style radio
:selected
(equal org-agenda-ndays
1)]
1155 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1156 :style radio
:selected
(equal org-agenda-ndays
7)]
1157 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1158 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1159 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1160 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1162 ["Show Logbook entries" org-agenda-log-mode
1163 :style toggle
:selected org-agenda-show-log
:active
(org-agenda-check-type nil
'agenda
'timeline
)]
1164 ["Show clock report" org-agenda-clockreport-mode
1165 :style toggle
:selected org-agenda-clockreport-mode
:active
(org-agenda-check-type nil
'agenda
)]
1166 ["Include Diary" org-agenda-toggle-diary
1167 :style toggle
:selected org-agenda-include-diary
:active
(org-agenda-check-type nil
'agenda
)]
1168 ["Use Time Grid" org-agenda-toggle-time-grid
1169 :style toggle
:selected org-agenda-use-time-grid
:active
(org-agenda-check-type nil
'agenda
)])
1170 ["Write view to file" org-write-agenda t
]
1171 ["Rebuild buffer" org-agenda-redo t
]
1172 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1174 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1176 ["Quit" org-agenda-quit t
]
1177 ["Exit and Release Buffers" org-agenda-exit t
]
1182 (defvar org-agenda-allow-remote-undo t
1183 "Non-nil means, allow remote undo from the agenda buffer.")
1184 (defvar org-agenda-undo-list nil
1185 "List of undoable operations in the agenda since last refresh.")
1186 (defvar org-agenda-undo-has-started-in nil
1187 "Buffers that have already seen `undo-start' in the current undo sequence.")
1188 (defvar org-agenda-pending-undo-list nil
1189 "In a series of undo commands, this is the list of remaning undo items.")
1192 (defun org-agenda-undo ()
1193 "Undo a remote editing step in the agenda.
1194 This undoes changes both in the agenda buffer and in the remote buffer
1195 that have been changed along."
1197 (or org-agenda-allow-remote-undo
1198 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1199 (if (not (eq this-command last-command
))
1200 (setq org-agenda-undo-has-started-in nil
1201 org-agenda-pending-undo-list org-agenda-undo-list
))
1202 (if (not org-agenda-pending-undo-list
)
1203 (error "No further undo information"))
1204 (let* ((entry (pop org-agenda-pending-undo-list
))
1205 buf line cmd rembuf
)
1206 (setq cmd
(pop entry
) line
(pop entry
))
1207 (setq rembuf
(nth 2 entry
))
1208 (org-with-remote-undo rembuf
1209 (while (bufferp (setq buf
(pop entry
)))
1211 (with-current-buffer buf
1212 (let ((last-undo-buffer buf
)
1213 (inhibit-read-only t
))
1214 (unless (memq buf org-agenda-undo-has-started-in
)
1215 (push buf org-agenda-undo-has-started-in
)
1216 (make-local-variable 'pending-undo-list
)
1218 (while (and pending-undo-list
1219 (listp pending-undo-list
)
1220 (not (car pending-undo-list
)))
1221 (pop pending-undo-list
))
1224 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1226 (defun org-verify-change-for-undo (l1 l2
)
1227 "Verify that a real change occurred between the undo lists L1 and L2."
1228 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1229 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1234 (defvar org-agenda-restrict nil
)
1235 (defvar org-agenda-restrict-begin
(make-marker))
1236 (defvar org-agenda-restrict-end
(make-marker))
1237 (defvar org-agenda-last-dispatch-buffer nil
)
1238 (defvar org-agenda-overriding-restriction nil
)
1241 (defun org-agenda (arg &optional keys restriction
)
1242 "Dispatch agenda commands to collect entries to the agenda buffer.
1243 Prompts for a command to execute. Any prefix arg will be passed
1244 on to the selected command. The default selections are:
1246 a Call `org-agenda-list' to display the agenda for current day or week.
1247 t Call `org-todo-list' to display the global todo list.
1248 T Call `org-todo-list' to display the global todo list, select only
1249 entries with a specific TODO keyword (the user gets a prompt).
1250 m Call `org-tags-view' to display headlines with tags matching
1251 a condition (the user is prompted for the condition).
1252 M Like `m', but select only TODO entries, no ordinary headlines.
1253 L Create a timeline for the current buffer.
1254 e Export views to associated files.
1256 More commands can be added by configuring the variable
1257 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1258 searches can be pre-defined in this way.
1260 If the current buffer is in Org-mode and visiting a file, you can also
1261 first press `<' once to indicate that the agenda should be temporarily
1262 \(until the next use of \\[org-agenda]) restricted to the current file.
1263 Pressing `<' twice means to restrict to the current subtree or region
1267 (let* ((prefix-descriptions nil
)
1268 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1269 (org-agenda-custom-commands
1270 ;; normalize different versions
1274 (cond ((stringp (cdr x
))
1275 (push x prefix-descriptions
)
1277 ((stringp (nth 1 x
)) x
)
1278 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1279 (t (cons (car x
) (cons "" (cdr x
))))))
1280 org-agenda-custom-commands
)))
1281 (buf (current-buffer))
1282 (bfn (buffer-file-name (buffer-base-buffer)))
1283 entry key type match lprops ans
)
1284 ;; Turn off restriction unless there is an overriding one
1285 (unless org-agenda-overriding-restriction
1286 (put 'org-agenda-files
'org-restrict nil
)
1287 (setq org-agenda-restrict nil
)
1288 (move-marker org-agenda-restrict-begin nil
)
1289 (move-marker org-agenda-restrict-end nil
))
1290 ;; Delete old local properties
1291 (put 'org-agenda-redo-command
'org-lprops nil
)
1292 ;; Remember where this call originated
1293 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1295 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1297 restriction
(cdr ans
)))
1298 ;; Estabish the restriction, if any
1299 (when (and (not org-agenda-overriding-restriction
) restriction
)
1300 (put 'org-agenda-files
'org-restrict
(list bfn
))
1302 ((eq restriction
'region
)
1303 (setq org-agenda-restrict t
)
1304 (move-marker org-agenda-restrict-begin
(region-beginning))
1305 (move-marker org-agenda-restrict-end
(region-end)))
1306 ((eq restriction
'subtree
)
1308 (setq org-agenda-restrict t
)
1309 (org-back-to-heading t
)
1310 (move-marker org-agenda-restrict-begin
(point))
1311 (move-marker org-agenda-restrict-end
1312 (progn (org-end-of-subtree t
)))))))
1314 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1315 ;; For example the todo list should not need it (but does...)
1317 ((setq entry
(assoc keys org-agenda-custom-commands
))
1318 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1320 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1321 (put 'org-agenda-redo-command
'org-lprops lprops
)
1324 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1326 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1328 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1330 (org-let lprops
'(org-agenda-list-stuck-projects
1331 current-prefix-arg
)))
1333 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1334 ((eq type
'tags-todo
)
1335 (org-let lprops
'(org-tags-view '(4) match
)))
1337 (org-let lprops
'(org-todo-list match
)))
1338 ((eq type
'tags-tree
)
1339 (org-check-for-org-mode)
1340 (org-let lprops
'(org-tags-sparse-tree current-prefix-arg match
)))
1341 ((eq type
'todo-tree
)
1342 (org-check-for-org-mode)
1344 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1345 (regexp-quote match
) "\\>"))))
1346 ((eq type
'occur-tree
)
1347 (org-check-for-org-mode)
1348 (org-let lprops
'(org-occur match
)))
1350 (org-let lprops
'(funcall type match
)))
1352 (org-let lprops
'(funcall type match
)))
1353 (t (error "Invalid custom agenda command type %s" type
))))
1354 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1356 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1357 (customize-variable 'org-agenda-custom-commands
))
1358 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1359 ((equal keys
"s") (call-interactively 'org-search-view
))
1360 ((equal keys
"t") (call-interactively 'org-todo-list
))
1361 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1362 ((equal keys
"m") (call-interactively 'org-tags-view
))
1363 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1364 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1366 (unless (org-mode-p)
1367 (error "This is not an Org-mode file"))
1369 (put 'org-agenda-files
'org-restrict
(list bfn
))
1370 (org-call-with-arg 'org-timeline arg
)))
1371 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1372 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1373 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1374 (t (error "Invalid agenda key"))))))
1376 (defun org-agenda-normalize-custom-commands (cmds)
1380 (cond ((stringp (cdr x
)) nil
)
1381 ((stringp (nth 1 x
)) x
)
1382 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1383 (t (cons (car x
) (cons "" (cdr x
))))))
1386 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1387 "The user interface for selecting an agenda command."
1389 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1390 (restrict-ok (and bfn
(org-mode-p)))
1391 (region-p (org-region-active-p))
1392 (custom org-agenda-custom-commands
)
1394 restriction second-time
1395 c entry key type match prefixes rmheader header-end custom1 desc
)
1396 (save-window-excursion
1397 (delete-other-windows)
1398 (org-switch-to-buffer-other-window " *Agenda Commands*")
1400 (insert (eval-when-compile
1403 Press key for an agenda command: < Buffer,subtree/region restriction
1404 -------------------------------- > Remove restriction
1405 a Agenda for current week or day e Export agenda views
1406 t List of all TODO entries T Entries with special TODO kwd
1407 m Match a TAGS query M Like m, but only TODO entries
1408 L Timeline for current buffer # List stuck projects (!=configure)
1409 s Search for keywords C Configure custom agenda commands
1413 (while (string-match
1414 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1416 (setq start
(match-end 0))
1417 (add-text-properties (match-beginning 2) (match-end 2)
1418 '(face bold
) header
))
1420 (setq header-end
(move-marker (make-marker) (point)))
1422 (setq custom1 custom
)
1423 (when (eq rmheader t
)
1425 (re-search-forward ":" nil t
)
1426 (delete-region (match-end 0) (point-at-eol))
1429 (delete-region (match-end 0) (point-at-eol))
1430 (move-marker header-end
(match-end 0)))
1431 (goto-char header-end
)
1432 (delete-region (point) (point-max))
1433 (while (setq entry
(pop custom1
))
1434 (setq key
(car entry
) desc
(nth 1 entry
)
1435 type
(nth 2 entry
) match
(nth 3 entry
))
1436 (if (> (length key
) 1)
1437 (add-to-list 'prefixes
(string-to-char key
))
1441 (org-add-props (copy-sequence key
)
1444 ((string-match "\\S-" desc
) desc
)
1445 ((eq type
'agenda
) "Agenda for current week or day")
1446 ((eq type
'alltodo
) "List of all TODO entries")
1447 ((eq type
'search
) "Word search")
1448 ((eq type
'stuck
) "List of stuck projects")
1449 ((eq type
'todo
) "TODO keyword")
1450 ((eq type
'tags
) "Tags query")
1451 ((eq type
'tags-todo
) "Tags (TODO)")
1452 ((eq type
'tags-tree
) "Tags tree")
1453 ((eq type
'todo-tree
) "TODO kwd tree")
1454 ((eq type
'occur-tree
) "Occur tree")
1455 ((functionp type
) (if (symbolp type
)
1457 "Lambda expression"))
1461 (org-add-props match nil
'face
'org-warning
))
1463 (format "set of %d commands" (length match
)))
1469 (org-add-props (char-to-string x
)
1471 (or (cdr (assoc (concat selstring
(char-to-string x
))
1472 prefix-descriptions
))
1475 (goto-char (point-min))
1476 (when (fboundp 'fit-window-to-buffer
)
1478 (if (not (pos-visible-in-window-p (point-max)))
1479 (fit-window-to-buffer))
1480 (setq second-time t
)
1481 (fit-window-to-buffer)))
1482 (message "Press key for agenda command%s:"
1483 (if (or restrict-ok org-agenda-overriding-restriction
)
1484 (if org-agenda-overriding-restriction
1485 " (restriction lock active)"
1487 (format " (restricted to %s)" restriction
)
1490 (setq c
(read-char-exclusive))
1493 ((assoc (char-to-string c
) custom
)
1494 (setq selstring
(concat selstring
(char-to-string c
)))
1495 (throw 'exit
(cons selstring restriction
)))
1497 (setq selstring
(concat selstring
(char-to-string c
))
1499 rmheader
(or rmheader t
)
1500 custom
(delq nil
(mapcar
1502 (if (or (= (length (car x
)) 1)
1503 (/= (string-to-char (car x
)) c
))
1505 (cons (substring (car x
) 1) (cdr x
))))
1507 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1508 (message "Restriction is only possible in Org-mode buffers")
1511 (org-agenda-remove-restriction-lock 'noupdate
)
1512 (setq restriction
'buffer
))
1514 (org-agenda-remove-restriction-lock 'noupdate
)
1515 (setq restriction
(if region-p
'region
'subtree
)))
1517 (org-agenda-remove-restriction-lock 'noupdate
)
1520 ((eq restriction
'buffer
)
1521 (if region-p
'region
'subtree
))
1522 ((memq restriction
'(subtree region
))
1526 (org-agenda-remove-restriction-lock 'noupdate
)
1527 (setq restriction nil
))
1528 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1529 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1530 ((and (> (length selstring
) 0) (eq c ?\d
))
1532 (org-agenda-get-restriction-and-command prefix-descriptions
))
1534 ((equal c ?q
) (error "Abort"))
1535 (t (error "Invalid key %c" c
))))))))
1537 (defun org-run-agenda-series (name series
)
1538 (org-prepare-agenda name
)
1539 (let* ((org-agenda-multi t
)
1540 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1542 (gprops (nth 1 series
))
1543 match
;; The byte compiler incorrectly complains about this. Keep it!
1545 (while (setq cmd
(pop cmds
))
1546 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1549 (org-let2 gprops lprops
1550 '(call-interactively 'org-agenda-list
)))
1552 (org-let2 gprops lprops
1553 '(call-interactively 'org-todo-list
)))
1555 (org-let2 gprops lprops
1556 '(org-search-view current-prefix-arg match nil
)))
1558 (org-let2 gprops lprops
1559 '(call-interactively 'org-agenda-list-stuck-projects
)))
1561 (org-let2 gprops lprops
1562 '(org-tags-view current-prefix-arg match
)))
1563 ((eq type
'tags-todo
)
1564 (org-let2 gprops lprops
1565 '(org-tags-view '(4) match
)))
1567 (org-let2 gprops lprops
1568 '(org-todo-list match
)))
1570 (org-let2 gprops lprops
1571 '(funcall type match
)))
1572 (t (error "Invalid type in command series"))))
1574 (setq org-agenda-redo-command redo
)
1575 (goto-char (point-min)))
1576 (org-finalize-agenda))
1579 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1580 "Run an agenda command in batch mode and send the result to STDOUT.
1581 If CMD-KEY is a string of length 1, it is used as a key in
1582 `org-agenda-custom-commands' and triggers this command. If it is a
1583 longer string it is used as a tags/todo match string.
1584 Paramters are alternating variable names and values that will be bound
1585 before running the agenda command."
1588 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1589 (if (> (length cmd-key
) 2)
1590 (eval (list 'let
(nreverse pars
)
1591 (list 'org-tags-view nil cmd-key
)))
1592 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1593 (set-buffer org-agenda-buffer-name
)
1594 (princ (org-encode-for-stdout (buffer-string)))))
1596 (defun org-encode-for-stdout (string)
1597 (if (fboundp 'encode-coding-string
)
1598 (encode-coding-string string buffer-file-coding-system
)
1601 (defvar org-agenda-info nil
)
1604 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1605 "Run an agenda command in batch mode and send the result to STDOUT.
1606 If CMD-KEY is a string of length 1, it is used as a key in
1607 `org-agenda-custom-commands' and triggers this command. If it is a
1608 longer string it is used as a tags/todo match string.
1609 Paramters are alternating variable names and values that will be bound
1610 before running the agenda command.
1612 The output gives a line for each selected agenda item. Each
1613 item is a list of comma-separated values, like this:
1615 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1617 category The category of the item
1618 head The headline, without TODO kwd, TAGS and PRIORITY
1619 type The type of the agenda entry, can be
1620 todo selected in TODO match
1621 tagsmatch selected in tags match
1622 diary imported from diary
1623 deadline a deadline on given date
1624 scheduled scheduled on given date
1625 timestamp entry has timestamp on given date
1626 closed entry was closed on given date
1627 upcoming-deadline warning about deadline
1628 past-scheduled forwarded scheduled item
1629 block entry has date block including g. date
1630 todo The todo keyword, if any
1631 tags All tags including inherited ones, separated by colons
1632 date The relevant date, like 2007-2-14
1633 time The time, like 15:00-16:50
1634 extra Sting with extra planning info
1635 priority-l The priority letter if any was given
1636 priority-n The computed numerical priority
1637 agenda-day The day in the agenda where this is listed"
1641 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1642 (push (list 'org-agenda-remove-tags t
) pars
)
1643 (if (> (length cmd-key
) 2)
1644 (eval (list 'let
(nreverse pars
)
1645 (list 'org-tags-view nil cmd-key
)))
1646 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1647 (set-buffer org-agenda-buffer-name
)
1648 (let* ((lines (org-split-string (buffer-string) "\n"))
1650 (while (setq line
(pop lines
))
1652 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1653 (setq org-agenda-info
1654 (org-fix-agenda-info (text-properties-at 0 line
)))
1656 (org-encode-for-stdout
1657 (mapconcat 'org-agenda-export-csv-mapper
1658 '(org-category txt type todo tags date time-of-day extra
1659 priority-letter priority agenda-day
)
1663 (defun org-fix-agenda-info (props)
1664 "Make sure all properties on an agenda item have a canonical form,
1665 so the export commands can easily use it."
1667 (when (setq tmp
(plist-get props
'tags
))
1668 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1669 (when (setq tmp
(plist-get props
'date
))
1670 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1671 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1672 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
1674 (setq tmp
(calendar-date-string tmp
)))
1675 (setq props
(plist-put props
'date tmp
)))
1676 (when (setq tmp
(plist-get props
'day
))
1677 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1678 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1679 (setq tmp
(calendar-date-string tmp
)))
1680 (setq props
(plist-put props
'day tmp
))
1681 (setq props
(plist-put props
'agenda-day tmp
)))
1682 (when (setq tmp
(plist-get props
'txt
))
1683 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
1684 (plist-put props
'priority-letter
(match-string 1 tmp
))
1685 (setq tmp
(replace-match "" t t tmp
)))
1686 (when (and (setq re
(plist-get props
'org-todo-regexp
))
1687 (setq re
(concat "\\`\\.*" re
" ?"))
1688 (string-match re tmp
))
1689 (plist-put props
'todo
(match-string 1 tmp
))
1690 (setq tmp
(replace-match "" t t tmp
)))
1691 (plist-put props
'txt tmp
)))
1694 (defun org-agenda-export-csv-mapper (prop)
1695 (let ((res (plist-get org-agenda-info prop
)))
1700 (t (prin1-to-string res
))))
1701 (while (string-match "," res
)
1702 (setq res
(replace-match ";" t t res
)))
1707 (defun org-store-agenda-views (&rest parameters
)
1709 (eval (list 'org-batch-store-agenda-views
)))
1711 ;; FIXME, why is this a macro?????
1713 (defmacro org-batch-store-agenda-views
(&rest parameters
)
1714 "Run all custom agenda commands that have a file argument."
1715 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
1717 (dir default-directory
)
1718 pars cmd thiscmdkey files opts
)
1720 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1721 (setq pars
(reverse pars
))
1722 (save-window-excursion
1724 (setq cmd
(pop cmds
)
1725 thiscmdkey
(car cmd
)
1728 (if (stringp files
) (setq files
(list files
)))
1730 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1731 (list 'org-agenda nil thiscmdkey
)))
1732 (set-buffer org-agenda-buffer-name
)
1734 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
1735 (list 'org-write-agenda
1736 (expand-file-name (pop files
) dir
) t
))))
1737 (and (get-buffer org-agenda-buffer-name
)
1738 (kill-buffer org-agenda-buffer-name
)))))))
1740 (defun org-write-agenda (file &optional nosettings
)
1741 "Write the current buffer (an agenda view) as a file.
1742 Depending on the extension of the file name, plain text (.txt),
1743 HTML (.html or .htm) or Postscript (.ps) is produced.
1744 If the extension is .ics, run icalendar export over all files used
1745 to construct the agenda and limit the export to entries listed in the
1747 If NOSETTINGS is given, do not scope the settings of
1748 `org-agenda-exporter-settings' into the export commands. This is used when
1749 the settings have already been scoped and we do not wish to overrule other,
1750 higher priority settings."
1751 (interactive "FWrite agenda to file: ")
1752 (if (not (file-writable-p file
))
1753 (error "Cannot write agenda to file %s" file
))
1755 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
1756 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
1757 (org-let (if nosettings nil org-agenda-exporter-settings
)
1759 (save-window-excursion
1761 ((string-match "\\.html?\\'" file
)
1762 (set-buffer (htmlize-buffer (current-buffer)))
1764 (when (and org-agenda-export-html-style
1765 (string-match "<style>" org-agenda-export-html-style
))
1766 ;; replace <style> section with org-agenda-export-html-style
1767 (goto-char (point-min))
1768 (kill-region (- (search-forward "<style") 6)
1769 (search-forward "</style>"))
1770 (insert org-agenda-export-html-style
))
1772 (kill-buffer (current-buffer))
1773 (message "HTML written to %s" file
))
1774 ((string-match "\\.ps\\'" file
)
1775 (ps-print-buffer-with-faces file
)
1776 (message "Postscript written to %s" file
))
1777 ((string-match "\\.ics\\'" file
)
1778 (let ((org-agenda-marker-table
1779 (org-create-marker-find-array
1780 (org-agenda-collect-markers)))
1781 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
1782 (org-combined-agenda-icalendar-file file
))
1783 (apply 'org-export-icalendar
'combine
(org-agenda-files))))
1785 (let ((bs (buffer-string)))
1789 (kill-buffer (current-buffer))
1790 (message "Plain text written to %s" file
))))))
1791 (set-buffer org-agenda-buffer-name
)))
1793 (defun org-agenda-collect-markers ()
1794 "Collect the markers pointing to entries in the agenda buffer."
1797 (goto-char (point-min))
1799 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
1800 (get-text-property (point) 'org-marker
)))
1802 (beginning-of-line 2)))
1803 (nreverse markers
)))
1805 (defun org-create-marker-find-array (marker-list)
1806 "Create a alist of files names with all marker positions in that file."
1808 (while (setq m
(pop marker-list
))
1809 (setq p
(marker-position m
)
1810 f
(buffer-file-name (or (buffer-base-buffer
1812 (marker-buffer m
))))
1813 (if (setq a
(assoc f tbl
))
1814 (push (marker-position m
) (cdr a
))
1815 (push (list f p
) tbl
)))
1816 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
1819 (defvar org-agenda-marker-table nil
) ; dyamically scoped parameter
1820 (defun org-check-agenda-marker-table ()
1821 "Check of the current entry is on the marker list."
1822 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
1824 (and (setq a
(assoc file org-agenda-marker-table
))
1827 (org-back-to-heading t
)
1828 (member (point) (cdr a
)))))))
1830 (defun org-check-for-org-mode ()
1831 "Make sure current buffer is in org-mode. Error if not."
1833 (error "Cannot execute org-mode agenda command on buffer in %s."
1836 (defun org-fit-agenda-window ()
1837 "Fit the window to the buffer size."
1838 (and (memq org-agenda-window-setup
'(reorganize-frame))
1839 (fboundp 'fit-window-to-buffer
)
1840 (fit-window-to-buffer
1842 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
1843 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
1845 ;;; Agenda prepare and finalize
1847 (defvar org-agenda-multi nil
) ; dynammically scoped
1848 (defvar org-agenda-buffer-name
"*Org Agenda*")
1849 (defvar org-pre-agenda-window-conf nil
)
1850 (defvar org-agenda-name nil
)
1851 (defun org-prepare-agenda (&optional name
)
1852 (setq org-todo-keywords-for-agenda nil
)
1853 (setq org-done-keywords-for-agenda nil
)
1854 (if org-agenda-multi
1856 (setq buffer-read-only nil
)
1857 (goto-char (point-max))
1858 (unless (or (bobp) org-agenda-compact-blocks
)
1859 (insert "\n" (make-string (window-width) ?
=) "\n"))
1860 (narrow-to-region (point) (point-max)))
1861 (org-agenda-reset-markers)
1862 (org-prepare-agenda-buffers (org-agenda-files))
1863 (setq org-todo-keywords-for-agenda
1864 (org-uniquify org-todo-keywords-for-agenda
))
1865 (setq org-done-keywords-for-agenda
1866 (org-uniquify org-done-keywords-for-agenda
))
1867 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
1868 (awin (get-buffer-window abuf
)))
1870 ((equal (current-buffer) abuf
) nil
)
1871 (awin (select-window awin
))
1872 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
1873 ((equal org-agenda-window-setup
'current-window
)
1874 (switch-to-buffer abuf
))
1875 ((equal org-agenda-window-setup
'other-window
)
1876 (org-switch-to-buffer-other-window abuf
))
1877 ((equal org-agenda-window-setup
'other-frame
)
1878 (switch-to-buffer-other-frame abuf
))
1879 ((equal org-agenda-window-setup
'reorganize-frame
)
1880 (delete-other-windows)
1881 (org-switch-to-buffer-other-window abuf
))))
1882 (setq buffer-read-only nil
)
1885 (and name
(not org-agenda-name
)
1886 (org-set-local 'org-agenda-name name
)))
1887 (setq buffer-read-only nil
))
1889 (defun org-finalize-agenda ()
1890 "Finishing touch for the agenda buffer, called just before displaying it."
1891 (unless org-agenda-multi
1893 (let ((inhibit-read-only t
))
1894 (goto-char (point-min))
1895 (while (org-activate-bracket-links (point-max))
1896 (add-text-properties (match-beginning 0) (match-end 0)
1898 (org-agenda-align-tags)
1899 (unless org-agenda-with-colors
1900 (remove-text-properties (point-min) (point-max) '(face nil
))))
1901 (if (and (boundp 'org-overriding-columns-format
)
1902 org-overriding-columns-format
)
1903 (org-set-local 'org-overriding-columns-format
1904 org-overriding-columns-format
))
1905 (if (and (boundp 'org-agenda-view-columns-initially
)
1906 org-agenda-view-columns-initially
)
1907 (org-agenda-columns))
1908 (when org-agenda-fontify-priorities
1909 (org-fontify-priorities))
1910 (run-hooks 'org-finalize-agenda-hook
)
1911 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
1914 (defun org-fontify-priorities ()
1915 "Make highest priority lines bold, and lowest italic."
1917 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
1918 (org-delete-overlay o
)))
1919 (org-overlays-in (point-min) (point-max)))
1921 (let ((inhibit-read-only t
)
1923 (goto-char (point-min))
1924 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
1925 (setq h
(or (get-char-property (point) 'org-highest-priority
)
1926 org-highest-priority
)
1927 l
(or (get-char-property (point) 'org-lowest-priority
)
1928 org-lowest-priority
)
1929 p
(string-to-char (match-string 1))
1930 b
(match-beginning 0) e
(point-at-eol)
1931 ov
(org-make-overlay b e
))
1934 (cond ((listp org-agenda-fontify-priorities
)
1935 (cdr (assoc p org-agenda-fontify-priorities
)))
1936 ((equal p l
) 'italic
)
1937 ((equal p h
) 'bold
)))
1938 (org-overlay-put ov
'org-type
'org-priority
)))))
1941 (defvar org-agenda-skip-function nil
1942 "Function to be called at each match during agenda construction.
1943 If this function returns nil, the current match should not be skipped.
1944 Otherwise, the function must return a position from where the search
1945 should be continued.
1946 This may also be a Lisp form, it will be evaluated.
1947 Never set this variable using `setq' or so, because then it will apply
1948 to all future agenda commands. Instead, bind it with `let' to scope
1949 it dynamically into the agenda-constructing command. A good way to set
1950 it is through options in org-agenda-custom-commands.")
1952 (defun org-agenda-skip ()
1953 "Throw to `:skip' in places that should be skipped.
1954 Also moves point to the end of the skipped region, so that search can
1955 continue from there."
1956 (let ((p (point-at-bol)) to fp
)
1957 (and org-agenda-skip-archived-trees
1958 (get-text-property p
:org-archived
)
1959 (org-end-of-subtree t
)
1961 (and (get-text-property p
:org-comment
)
1962 (org-end-of-subtree t
)
1964 (if (equal (char-after p
) ?
#) (throw :skip t
))
1965 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
1966 (consp org-agenda-skip-function
))
1967 (setq to
(save-excursion
1970 (funcall org-agenda-skip-function
)
1971 (eval org-agenda-skip-function
))))))
1975 (defvar org-agenda-markers nil
1976 "List of all currently active markers created by `org-agenda'.")
1977 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
1978 "Creation time of the last agenda marker.")
1980 (defun org-agenda-new-marker (&optional pos
)
1981 "Return a new agenda marker.
1982 Org-mode keeps a list of these markers and resets them when they are
1984 (let ((m (copy-marker (or pos
(point)))))
1985 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
1986 (push m org-agenda-markers
)
1989 (defun org-agenda-reset-markers ()
1990 "Reset markers created by `org-agenda'."
1991 (while org-agenda-markers
1992 (move-marker (pop org-agenda-markers
) nil
)))
1996 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
1998 (defun org-timeline (&optional include-all
)
1999 "Show a time-sorted view of the entries in the current org file.
2000 Only entries with a time stamp of today or later will be listed. With
2001 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2002 under the current date.
2003 If the buffer contains an active region, only check the region for
2007 (org-compile-prefix-format 'timeline
)
2008 (org-set-sorting-strategy 'timeline
)
2010 (dotodo include-all
)
2011 (doclosed org-agenda-show-log
)
2012 (entry buffer-file-name
)
2013 (date (calendar-current-date))
2014 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2015 (end (if (org-region-active-p) (region-end) (point-max)))
2016 (day-numbers (org-get-all-dates beg end
'no-ranges
2017 t doclosed
; always include today
2018 org-timeline-show-empty-dates
))
2019 (org-deadline-warning-days 0)
2020 (org-agenda-only-exact-dates t
)
2021 (today (time-to-days (current-time)))
2025 (setq org-agenda-redo-command
2027 (list 'org-switch-to-buffer-other-window
(current-buffer))
2028 (list 'org-timeline
(list 'quote include-all
))))
2030 ;; Remove past dates from the list of dates.
2031 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2032 (if (>= x today
) x nil
))
2034 (org-prepare-agenda (concat "Timeline "
2035 (file-name-nondirectory buffer-file-name
)))
2036 (if doclosed
(push :closed args
))
2037 (push :timestamp args
)
2038 (push :deadline args
)
2039 (push :scheduled args
)
2041 (if dotodo
(push :todo args
))
2042 (while (setq d
(pop day-numbers
))
2043 (if (and (listp d
) (eq (car d
) :omitted
))
2046 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2047 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2048 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2049 (if (and (>= d today
)
2054 (insert (make-string 79 ?-
) "\n")))
2055 (setq date
(calendar-gregorian-from-absolute d
))
2057 (setq rtn
(and (not emptyp
)
2058 (apply 'org-agenda-get-day-entries entry
2060 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2063 (if (stringp org-agenda-format-date
)
2064 (format-time-string org-agenda-format-date
2065 (org-time-from-absolute date
))
2066 (funcall org-agenda-format-date date
))
2068 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
)
2069 (put-text-property s
(1- (point)) 'org-date-line t
)
2071 (put-text-property s
(1- (point)) 'org-today t
))
2072 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2073 (put-text-property s
(1- (point)) 'day d
)))))
2074 (goto-char (point-min))
2075 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2077 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2078 (org-finalize-agenda)
2079 (setq buffer-read-only t
)))
2081 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2082 "Return a list of all relevant day numbers from BEG to END buffer positions.
2083 If NO-RANGES is non-nil, include only the start and end dates of a range,
2084 not every single day in the range. If FORCE-TODAY is non-nil, make
2085 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2086 inactive time stamps (those in square brackets) are included.
2087 When EMPTY is non-nil, also include days without any entries."
2089 (if pre-re pre-re
"")
2090 (if inactive org-ts-regexp-both org-ts-regexp
)))
2091 dates dates1 date day day1 day2 ts1 ts2
)
2093 (setq dates
(list (time-to-days (current-time)))))
2096 (while (re-search-forward re end t
)
2097 (setq day
(time-to-days (org-time-string-to-time
2098 (substring (match-string 1) 0 10))))
2099 (or (memq day dates
) (push day dates
)))
2102 (while (re-search-forward org-tr-regexp end t
)
2103 (setq ts1
(substring (match-string 1) 0 10)
2104 ts2
(substring (match-string 2) 0 10)
2105 day1
(time-to-days (org-time-string-to-time ts1
))
2106 day2
(time-to-days (org-time-string-to-time ts2
)))
2107 (while (< (setq day1
(1+ day1
)) day2
)
2108 (or (memq day1 dates
) (push day1 dates
)))))
2109 (setq dates
(sort dates
'<))
2111 (while (setq day
(pop dates
))
2112 (setq day2
(car dates
))
2114 (when (and day2 empty
)
2115 (if (or (eq empty t
)
2116 (and (numberp empty
) (<= (- day2 day
) empty
)))
2117 (while (< (setq day
(1+ day
)) day2
)
2118 (push (list day
) dates1
))
2119 (push (cons :omitted
(- day2 day
)) dates1
))))
2120 (setq dates
(nreverse dates1
)))
2123 ;;; Agenda Daily/Weekly
2125 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2126 (defvar org-agenda-start-day nil
) ; dynamically scoped parameter
2127 (defvar org-agenda-last-arguments nil
2128 "The arguments of the previous call to org-agenda")
2129 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2130 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2131 (defvar org-include-all-loc nil
) ; local variable
2132 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2135 (defun org-agenda-list (&optional include-all start-day ndays
)
2136 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2137 The view will be for the current day or week, but from the overview buffer
2138 you will be able to go to other days/weeks.
2140 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2141 all unfinished TODO items will also be shown, before the agenda.
2142 This feature is considered obsolete, please use the TODO list or a block
2145 With a numeric prefix argument in an interactive call, the agenda will
2146 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2147 the number of days. NDAYS defaults to `org-agenda-ndays'.
2149 START-DAY defaults to TODAY, or to the most recent match for the weekday
2150 given in `org-agenda-start-on-weekday'."
2152 (if (and (integerp include-all
) (> include-all
0))
2153 (setq ndays include-all include-all nil
))
2154 (setq ndays
(or ndays org-agenda-ndays
)
2155 start-day
(or start-day org-agenda-start-day
))
2156 (if org-agenda-overriding-arguments
2157 (setq include-all
(car org-agenda-overriding-arguments
)
2158 start-day
(nth 1 org-agenda-overriding-arguments
)
2159 ndays
(nth 2 org-agenda-overriding-arguments
)))
2160 (if (stringp start-day
)
2161 ;; Convert to an absolute day number
2162 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2163 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2164 (org-compile-prefix-format 'agenda
)
2165 (org-set-sorting-strategy 'agenda
)
2167 (let* ((org-agenda-start-on-weekday
2168 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2169 org-agenda-start-on-weekday nil
))
2170 (thefiles (org-agenda-files))
2172 (today (time-to-days
2173 (time-subtract (current-time)
2174 (list 0 (* 3600 org-extend-today-until
) 0))))
2175 (sd (or start-day today
))
2176 (start (if (or (null org-agenda-start-on-weekday
)
2177 (< org-agenda-ndays
7))
2179 (let* ((nt (calendar-day-of-week
2180 (calendar-gregorian-from-absolute sd
)))
2181 (n1 org-agenda-start-on-weekday
)
2183 (- sd
(+ (if (< d
0) 7 0) d
)))))
2184 (day-numbers (list start
))
2186 (inhibit-redisplay (not debug-on-error
))
2187 s e rtn rtnall file date d start-pos end-pos todayp nd
2188 clocktable-start clocktable-end
)
2189 (setq org-agenda-redo-command
2190 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2191 ;; Make the list of days
2192 (setq ndays
(or ndays org-agenda-ndays
)
2195 (push (1+ (car day-numbers
)) day-numbers
)
2196 (setq ndays
(1- ndays
)))
2197 (setq day-numbers
(nreverse day-numbers
))
2198 (setq clocktable-start
(car day-numbers
)
2199 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2200 (org-prepare-agenda "Day/Week")
2201 (org-set-local 'org-starting-day
(car day-numbers
))
2202 (org-set-local 'org-include-all-loc include-all
)
2203 (org-set-local 'org-agenda-span
2204 (org-agenda-ndays-to-span nd
))
2205 (when (and (or include-all org-agenda-include-all-todo
)
2206 (member today day-numbers
))
2207 (setq files thefiles
2209 (while (setq file
(pop files
))
2211 (org-check-agenda-file file
)
2212 (setq date
(calendar-gregorian-from-absolute today
)
2213 rtn
(org-agenda-get-day-entries
2215 (setq rtnall
(append rtnall rtn
))))
2217 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2218 (add-text-properties (point-min) (1- (point))
2219 (list 'face
'org-agenda-structure
))
2220 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2221 (unless org-agenda-compact-blocks
2222 (let* ((d1 (car day-numbers
))
2223 (d2 (org-last day-numbers
))
2224 (w1 (org-days-to-iso-week d1
))
2225 (w2 (org-days-to-iso-week d2
)))
2227 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2229 (if (< (- d2 d1
) 350)
2231 (format " (W%02d)" w1
)
2232 (format " (W%02d-W%02d)" w1 w2
))
2235 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2237 (while (setq d
(pop day-numbers
))
2238 (setq date
(calendar-gregorian-from-absolute d
)
2240 (if (or (setq todayp
(= d today
))
2241 (and (not start-pos
) (= d sd
)))
2242 (setq start-pos
(point))
2243 (if (and start-pos
(not end-pos
))
2244 (setq end-pos
(point))))
2245 (setq files thefiles
2247 (while (setq file
(pop files
))
2249 (org-check-agenda-file file
)
2250 (if org-agenda-show-log
2251 (setq rtn
(org-agenda-get-day-entries
2253 :deadline
:scheduled
:timestamp
:sexp
:closed
))
2254 (setq rtn
(org-agenda-get-day-entries
2256 :deadline
:scheduled
:sexp
:timestamp
)))
2257 (setq rtnall
(append rtnall rtn
))))
2258 (if org-agenda-include-diary
2260 (require 'diary-lib
)
2261 (setq rtn
(org-get-entries-from-diary date
))
2262 (setq rtnall
(append rtnall rtn
))))
2263 (if (or rtnall org-agenda-show-all-dates
)
2265 (setq day-cnt
(1+ day-cnt
))
2267 (if (stringp org-agenda-format-date
)
2268 (format-time-string org-agenda-format-date
2269 (org-time-from-absolute date
))
2270 (funcall org-agenda-format-date date
))
2272 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
)
2273 (put-text-property s
(1- (point)) 'org-date-line t
)
2274 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2275 (if todayp
(put-text-property s
(1- (point)) 'org-today t
))
2277 (org-finalize-agenda-entries
2278 (org-agenda-add-time-grid-maybe
2281 (put-text-property s
(1- (point)) 'day d
)
2282 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2283 (when (and org-agenda-clockreport-mode clocktable-start
)
2284 (let ((org-agenda-files (org-agenda-files))
2285 ;; the above line is to ensure the restricted range!
2286 (p org-agenda-clockreport-parameter-plist
)
2288 (setq p
(org-plist-delete p
:block
))
2289 (setq p
(plist-put p
:tstart clocktable-start
))
2290 (setq p
(plist-put p
:tend clocktable-end
))
2291 (setq p
(plist-put p
:scope
'agenda
))
2292 (setq tbl
(apply 'org-get-clocktable p
))
2294 (goto-char (point-min))
2295 (org-fit-agenda-window)
2296 (unless (and (pos-visible-in-window-p (point-min))
2297 (pos-visible-in-window-p (point-max)))
2298 (goto-char (1- (point-max)))
2300 (if (not (pos-visible-in-window-p (or start-pos
1)))
2302 (goto-char (or start-pos
1))
2304 (goto-char (or start-pos
1))
2305 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2306 (org-finalize-agenda)
2307 (setq buffer-read-only t
)
2310 (defun org-agenda-ndays-to-span (n)
2311 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2313 ;;; Agenda word search
2315 (defvar org-agenda-search-history nil
)
2316 (defvar org-todo-only nil
)
2318 (defvar org-search-syntax-table nil
2319 "Special syntax table for org-mode search.
2320 In this table, we have single quotes not as word constituents, to
2321 that when \"+Ameli\" is searchd as a work, it will also match \"Ameli's\"")
2323 (defun org-search-syntax-table ()
2324 (unless org-search-syntax-table
2325 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2326 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2327 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2328 org-search-syntax-table
)
2331 (defun org-search-view (&optional todo-only string edit-at
)
2332 "Show all entries that contain words or regular expressions.
2333 If the first character of the search string is an asterisks,
2334 search only the headlines.
2336 With optional prefix argument TODO-ONLY, only consider entries that are
2337 TODO entries. The argument STRING can be used to pass a default search
2338 string into this function. If EDIT-AT is non-nil, it means that the
2339 user should get a chance to edit this string, with cursor at position
2342 The search string is broken into \"words\" by splitting at whitespace.
2343 The individual words are then interpreted as a boolean expression with
2344 logical AND. Words prefixed with a minus must not occur in the entry.
2345 Words without a prefix or prefixed with a plus must occur in the entry.
2346 Matching is case-insensitive and the words are enclosed by word delimiters.
2348 Words enclosed by curly braces are interpreted as regular expressions
2349 that must or must not match in the entry.
2351 If the search string starts with an asterisk, search only in headlines.
2352 If (possibly after the leading star) the search string starts with an
2353 exclamation mark, this also means to look at TODO entries only, an effect
2354 that can also be achieved with a prefix argument.
2356 This command searches the agenda files, and in addition the files listed
2357 in `org-agenda-text-search-extra-files'."
2359 (org-compile-prefix-format 'search
)
2360 (org-set-sorting-strategy 'search
)
2361 (org-prepare-agenda "SEARCH")
2362 (let* ((props (list 'face nil
2363 'done-face
'org-done
2364 'org-not-done-regexp org-not-done-regexp
2365 'org-todo-regexp org-todo-regexp
2366 'mouse-face
'highlight
2367 'keymap org-agenda-keymap
2368 'help-echo
(format "mouse-2 or RET jump to location")))
2369 regexp rtn rtnall files file pos
2370 marker priority category tags c neg re
2371 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2372 (unless (and (not edit-at
)
2374 (string-match "\\S-" string
))
2375 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2377 ((integerp edit-at
) (cons string edit-at
))
2379 'org-agenda-search-history
)))
2380 (org-set-local 'org-todo-only todo-only
)
2381 (setq org-agenda-redo-command
2382 (list 'org-search-view
(if todo-only t nil
) string
2383 '(if current-prefix-arg
1 nil
)))
2384 (setq org-agenda-query-string string
)
2386 (if (equal (string-to-char string
) ?
*)
2388 words
(substring string
1))
2389 (setq words string
))
2390 (when (equal (string-to-char words
) ?
!)
2392 words
(substring words
1)))
2393 (setq words
(org-split-string words
))
2395 (setq c
(string-to-char w
))
2397 (setq neg t w
(substring w
1))
2399 (setq neg nil w
(substring w
1))
2401 (if (string-match "\\`{.*}\\'" w
)
2402 (setq re
(substring w
1 -
1))
2403 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2404 (if neg
(push re regexps-
) (push re regexps
+)))
2406 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2408 (setq regexp
(concat "^" org-outline-regexp
))
2409 (setq regexp
(pop regexps
+))
2410 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2412 (setq files
(append (org-agenda-files) org-agenda-text-search-extra-files
)
2414 (while (setq file
(pop files
))
2417 (org-check-agenda-file file
)
2418 (setq buffer
(if (file-exists-p file
)
2419 (org-get-agenda-file-buffer file
)
2420 (error "No such file %s" file
)))
2422 ;; If file does not exist, make sure an error message is sent
2423 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2425 (with-current-buffer buffer
2426 (with-syntax-table (org-search-syntax-table)
2427 (unless (org-mode-p)
2428 (error "Agenda file %s is not in `org-mode'" file
))
2429 (let ((case-fold-search t
))
2432 (if org-agenda-restrict
2433 (narrow-to-region org-agenda-restrict-begin
2434 org-agenda-restrict-end
)
2436 (goto-char (point-min))
2437 (unless (or (org-on-heading-p)
2438 (outline-next-heading))
2439 (throw 'nextfile t
))
2440 (goto-char (max (point-min) (1- (point))))
2441 (while (re-search-forward regexp nil t
)
2442 (org-back-to-heading t
)
2443 (skip-chars-forward "* ")
2444 (setq beg
(point-at-bol)
2446 end
(progn (outline-next-heading) (point)))
2450 (setq str
(buffer-substring-no-properties
2452 (if hdl-only
(point-at-eol) end
)))
2453 (mapc (lambda (wr) (when (string-match wr str
)
2454 (goto-char (1- end
))
2457 (mapc (lambda (wr) (unless (string-match wr str
)
2458 (goto-char (1- end
))
2461 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
2465 (setq marker
(org-agenda-new-marker (point))
2466 category
(org-get-category)
2467 tags
(org-get-tags-at (point))
2468 txt
(org-format-agenda-item
2470 (buffer-substring-no-properties
2471 beg1
(point-at-eol))
2473 (org-add-props txt props
2474 'org-marker marker
'org-hd-marker marker
2475 'org-todo-regexp org-todo-regexp
2476 'priority
1000 'org-category category
2479 (goto-char (1- end
))))))))))
2480 (setq rtn
(nreverse ee
))
2481 (setq rtnall
(append rtnall rtn
)))
2482 (if org-agenda-overriding-header
2483 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2484 nil
'face
'org-agenda-structure
) "\n")
2485 (insert "Search words: ")
2486 (add-text-properties (point-min) (1- (point))
2487 (list 'face
'org-agenda-structure
))
2489 (insert string
"\n")
2490 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2492 (unless org-agenda-multi
2493 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
2494 (add-text-properties pos
(1- (point))
2495 (list 'face
'org-agenda-structure
))))
2497 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2498 (goto-char (point-min))
2499 (org-fit-agenda-window)
2500 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
2501 (org-finalize-agenda)
2502 (setq buffer-read-only t
)))
2504 ;;; Agenda TODO list
2506 (defvar org-select-this-todo-keyword nil
)
2507 (defvar org-last-arg nil
)
2510 (defun org-todo-list (arg)
2511 "Show all TODO entries from all agenda file in a single list.
2512 The prefix arg can be used to select a specific TODO keyword and limit
2513 the list to these. When using \\[universal-argument], you will be prompted
2514 for a keyword. A numeric prefix directly selects the Nth keyword in
2515 `org-todo-keywords-1'."
2518 (org-compile-prefix-format 'todo
)
2519 (org-set-sorting-strategy 'todo
)
2520 (org-prepare-agenda "TODO")
2521 (let* ((today (time-to-days (current-time)))
2522 (date (calendar-gregorian-from-absolute today
))
2523 (kwds org-todo-keywords-for-agenda
)
2524 (completion-ignore-case t
)
2525 (org-select-this-todo-keyword
2526 (if (stringp arg
) arg
2527 (and arg
(integerp arg
) (> arg
0)
2528 (nth (1- arg
) kwds
))))
2529 rtn rtnall files file pos
)
2530 (when (equal arg
'(4))
2531 (setq org-select-this-todo-keyword
2532 (completing-read "Keyword (or KWD1|K2D2|...): "
2533 (mapcar 'list kwds
) nil nil
)))
2534 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
2535 (org-set-local 'org-last-arg arg
)
2536 (setq org-agenda-redo-command
2537 '(org-todo-list (or current-prefix-arg org-last-arg
)))
2538 (setq files
(org-agenda-files)
2540 (while (setq file
(pop files
))
2542 (org-check-agenda-file file
)
2543 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
2544 (setq rtnall
(append rtnall rtn
))))
2545 (if org-agenda-overriding-header
2546 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2547 nil
'face
'org-agenda-structure
) "\n")
2548 (insert "Global list of TODO items of type: ")
2549 (add-text-properties (point-min) (1- (point))
2550 (list 'face
'org-agenda-structure
))
2552 (insert (or org-select-this-todo-keyword
"ALL") "\n")
2553 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2555 (unless org-agenda-multi
2556 (insert "Available with `N r': (0)ALL")
2559 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
2560 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
2565 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2567 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2568 (goto-char (point-min))
2569 (org-fit-agenda-window)
2570 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
2571 (org-finalize-agenda)
2572 (setq buffer-read-only t
)))
2574 ;;; Agenda tags match
2577 (defun org-tags-view (&optional todo-only match
)
2578 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
2579 The prefix arg TODO-ONLY limits the search to TODO entries."
2581 (org-compile-prefix-format 'tags
)
2582 (org-set-sorting-strategy 'tags
)
2583 (let* ((org-tags-match-list-sublevels
2584 (if todo-only t org-tags-match-list-sublevels
))
2585 (completion-ignore-case t
)
2586 rtn rtnall files file pos matcher
2588 (setq matcher
(org-make-tags-matcher match
)
2589 match
(car matcher
) matcher
(cdr matcher
))
2590 (org-prepare-agenda (concat "TAGS " match
))
2591 (setq org-agenda-query-string match
)
2592 (setq org-agenda-redo-command
2593 (list 'org-tags-view
(list 'quote todo-only
)
2594 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
2595 (setq files
(org-agenda-files)
2597 (while (setq file
(pop files
))
2599 (org-check-agenda-file file
)
2600 (setq buffer
(if (file-exists-p file
)
2601 (org-get-agenda-file-buffer file
)
2602 (error "No such file %s" file
)))
2604 ;; If file does not exist, merror message to agenda
2606 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
2607 rtnall
(append rtnall rtn
))
2608 (with-current-buffer buffer
2609 (unless (org-mode-p)
2610 (error "Agenda file %s is not in `org-mode'" file
))
2613 (if org-agenda-restrict
2614 (narrow-to-region org-agenda-restrict-begin
2615 org-agenda-restrict-end
)
2617 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
2618 (setq rtnall
(append rtnall rtn
))))))))
2619 (if org-agenda-overriding-header
2620 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2621 nil
'face
'org-agenda-structure
) "\n")
2622 (insert "Headlines with TAGS match: ")
2623 (add-text-properties (point-min) (1- (point))
2624 (list 'face
'org-agenda-structure
))
2627 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
2629 (unless org-agenda-multi
2630 (insert "Press `C-u r' to search again with new search string\n"))
2631 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
2633 (insert (org-finalize-agenda-entries rtnall
) "\n"))
2634 (goto-char (point-min))
2635 (org-fit-agenda-window)
2636 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
2637 (org-finalize-agenda)
2638 (setq buffer-read-only t
)))
2640 ;;; Agenda Finding stuck projects
2642 (defvar org-agenda-skip-regexp nil
2643 "Regular expression used in skipping subtrees for the agenda.
2644 This is basically a temporary global variable that can be set and then
2645 used by user-defined selections using `org-agenda-skip-function'.")
2647 (defvar org-agenda-overriding-header nil
2648 "When this is set during todo and tags searches, will replace header.")
2650 (defun org-agenda-skip-subtree-when-regexp-matches ()
2651 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
2652 If yes, it returns the end position of this tree, causing agenda commands
2653 to skip this subtree. This is a function that can be put into
2654 `org-agenda-skip-function' for the duration of a command."
2655 (let ((end (save-excursion (org-end-of-subtree t
)))
2658 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
2661 (defun org-agenda-skip-entry-if (&rest conditions
)
2662 "Skip entry if any of CONDITIONS is true.
2663 See `org-agenda-skip-if' for details."
2664 (org-agenda-skip-if nil conditions
))
2666 (defun org-agenda-skip-subtree-if (&rest conditions
)
2667 "Skip entry if any of CONDITIONS is true.
2668 See `org-agenda-skip-if' for details."
2669 (org-agenda-skip-if t conditions
))
2671 (defun org-agenda-skip-if (subtree conditions
)
2672 "Checks current entity for CONDITIONS.
2673 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
2674 the entry, i.e. the text before the next heading is checked.
2676 CONDITIONS is a list of symbols, boolean OR is used to combine the results
2677 from different tests. Valid conditions are:
2679 scheduled Check if there is a scheduled cookie
2680 notscheduled Check if there is no scheduled cookie
2681 deadline Check if there is a deadline
2682 notdeadline Check if there is no deadline
2683 regexp Check if regexp matches
2684 notregexp Check if regexp does not match.
2686 The regexp is taken from the conditions list, it must come right after
2687 the `regexp' or `notregexp' element.
2689 If any of these conditions is met, this function returns the end point of
2690 the entity, causing the search to continue from there. This is a function
2691 that can be put into `org-agenda-skip-function' for the duration of a command."
2693 (org-back-to-heading t
)
2696 (progn (org-end-of-subtree t
) (point))
2697 (progn (outline-next-heading) (1- (point)))))
2701 (and (memq 'scheduled conditions
)
2702 (re-search-forward org-scheduled-time-regexp end t
))
2703 (and (memq 'notscheduled conditions
)
2704 (not (re-search-forward org-scheduled-time-regexp end t
)))
2705 (and (memq 'deadline conditions
)
2706 (re-search-forward org-deadline-time-regexp end t
))
2707 (and (memq 'notdeadline conditions
)
2708 (not (re-search-forward org-deadline-time-regexp end t
)))
2709 (and (setq m
(memq 'regexp conditions
))
2711 (re-search-forward (nth 1 m
) end t
))
2712 (and (setq m
(memq 'notregexp conditions
))
2714 (not (re-search-forward (nth 1 m
) end t
))))
2718 (defun org-agenda-list-stuck-projects (&rest ignore
)
2719 "Create agenda view for projects that are stuck.
2720 Stuck projects are project that have no next actions. For the definitions
2721 of what a project is and how to check if it stuck, customize the variable
2722 `org-stuck-projects'.
2723 MATCH is being ignored."
2725 (let* ((org-agenda-skip-function 'org-agenda-skip-subtree-when-regexp-matches
)
2726 ;; We could have used org-agenda-skip-if here.
2727 (org-agenda-overriding-header "List of stuck projects: ")
2728 (matcher (nth 0 org-stuck-projects
))
2729 (todo (nth 1 org-stuck-projects
))
2730 (todo-wds (if (member "*" todo
)
2732 (org-prepare-agenda-buffers (org-agenda-files))
2734 org-done-keywords-for-agenda
2735 (copy-sequence org-todo-keywords-for-agenda
)))
2737 (todo-re (concat "^\\*+[ \t]+\\("
2738 (mapconcat 'identity todo-wds
"\\|")
2740 (tags (nth 2 org-stuck-projects
))
2741 (tags-re (if (member "*" tags
)
2742 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
2743 (concat "^\\*+ .*:\\("
2744 (mapconcat 'identity tags
"\\|")
2745 (org-re "\\):[[:alnum:]_@:]*[ \t]*$"))))
2746 (gen-re (nth 3 org-stuck-projects
))
2752 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
2754 (setq org-agenda-skip-regexp
2756 (mapconcat 'identity re-list
"\\|")
2757 (error "No information how to identify unstuck projects")))
2758 (org-tags-view nil matcher
)
2759 (with-current-buffer org-agenda-buffer-name
2760 (setq org-agenda-redo-command
2761 '(org-agenda-list-stuck-projects
2762 (or current-prefix-arg org-last-arg
))))))
2764 ;;; Diary integration
2766 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
2767 (defvar list-diary-entries-hook
)
2769 (defun org-get-entries-from-diary (date)
2770 "Get the (Emacs Calendar) diary entries for DATE."
2771 (require 'diary-lib
)
2772 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
2773 (fancy-diary-buffer diary-fancy-buffer
)
2774 (diary-display-hook '(fancy-diary-display))
2776 (list-diary-entries-hook
2777 (cons 'org-diary-default-entry list-diary-entries-hook
))
2778 (diary-file-name-prefix-function nil
) ; turn this feature off
2779 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
2781 (org-disable-agenda-to-diary t
))
2783 (save-window-excursion
2784 (funcall (if (fboundp 'diary-list-entries
)
2785 'diary-list-entries
'list-diary-entries
)
2787 (if (not (get-buffer diary-fancy-buffer
))
2789 (with-current-buffer diary-fancy-buffer
2790 (setq buffer-read-only nil
)
2791 (if (zerop (buffer-size))
2794 ;; Omit the date and other unnecessary stuff
2795 (org-agenda-cleanup-fancy-diary)
2796 ;; Add prefix to each line and extend the text properties
2797 (if (zerop (buffer-size))
2799 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
2800 (set-buffer-modified-p nil
)
2801 (kill-buffer diary-fancy-buffer
)))
2803 (setq entries
(org-split-string entries
"\n"))
2807 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
2808 ;; Extend the text properties to the beginning of the line
2809 (org-add-props x
(text-properties-at (1- (length x
)) x
)
2810 'type
"diary" 'date date
))
2813 (defun org-agenda-cleanup-fancy-diary ()
2814 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
2815 This gets rid of the date, the underline under the date, and
2816 the dummy entry installed by `org-mode' to ensure non-empty diary for each
2817 date. It also removes lines that contain only whitespace."
2818 (goto-char (point-min))
2819 (if (looking-at ".*?:[ \t]*")
2822 (re-search-forward "\n=+$" nil t
)
2824 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
2825 (re-search-forward "\n=+$" nil t
)
2826 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
2827 (goto-char (point-min))
2828 (while (re-search-forward "^ +\n" nil t
)
2830 (goto-char (point-min))
2831 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
2832 (replace-match "")))
2834 ;; Make sure entries from the diary have the right text properties.
2835 (eval-after-load "diary-lib"
2836 '(if (boundp 'diary-modify-entry-list-string-function
)
2837 ;; We can rely on the hook, nothing to do
2839 ;; Hook not avaiable, must use advice to make this work
2840 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
2841 "Make the position visible."
2842 (if (and org-disable-agenda-to-diary
;; called from org-agenda
2845 (setq string
(org-modify-diary-entry-string string
))))))
2847 (defun org-modify-diary-entry-string (string)
2848 "Add text properties to string, allowing org-mode to act on it."
2849 (org-add-props string nil
2850 'mouse-face
'highlight
2851 'keymap org-agenda-keymap
2852 'help-echo
(if buffer-file-name
2853 (format "mouse-2 or RET jump to diary file %s"
2854 (abbreviate-file-name buffer-file-name
))
2856 'org-agenda-diary-link t
2857 'org-marker
(org-agenda-new-marker (point-at-bol))))
2859 (defun org-diary-default-entry ()
2860 "Add a dummy entry to the diary.
2861 Needed to avoid empty dates which mess up holiday display."
2862 ;; Catch the error if dealing with the new add-to-diary-alist
2863 (when org-disable-agenda-to-diary
2865 (add-to-diary-list original-date
"Org-mode dummy" "")
2867 (add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
2870 (defun org-diary (&rest args
)
2871 "Return diary information from org-files.
2872 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
2873 It accesses org files and extracts information from those files to be
2874 listed in the diary. The function accepts arguments specifying what
2875 items should be listed. The following arguments are allowed:
2877 :timestamp List the headlines of items containing a date stamp or
2878 date range matching the selected date. Deadlines will
2879 also be listed, on the expiration day.
2881 :sexp List entries resulting from diary-like sexps.
2883 :deadline List any deadlines past due, or due within
2884 `org-deadline-warning-days'. The listing occurs only
2885 in the diary for *today*, not at any other date. If
2886 an entry is marked DONE, it is no longer listed.
2888 :scheduled List all items which are scheduled for the given date.
2889 The diary for *today* also contains items which were
2890 scheduled earlier and are not yet marked DONE.
2892 :todo List all TODO items from the org-file. This may be a
2893 long list - so this is not turned on by default.
2894 Like deadlines, these entries only show up in the
2895 diary for *today*, not at any other date.
2897 The call in the diary file should look like this:
2899 &%%(org-diary) ~/path/to/some/orgfile.org
2901 Use a separate line for each org file to check. Or, if you omit the file name,
2902 all files listed in `org-agenda-files' will be checked automatically:
2906 If you don't give any arguments (as in the example above), the default
2907 arguments (:deadline :scheduled :timestamp :sexp) are used.
2908 So the example above may also be written as
2910 &%%(org-diary :deadline :timestamp :sexp :scheduled)
2912 The function expects the lisp variables `entry' and `date' to be provided
2913 by the caller, because this is how the calendar works. Don't use this
2914 function from a program - use `org-agenda-get-day-entries' instead."
2915 (when (> (- (time-to-seconds (current-time))
2916 org-agenda-last-marker-time
)
2918 (org-agenda-reset-markers))
2919 (org-compile-prefix-format 'agenda
)
2920 (org-set-sorting-strategy 'agenda
)
2921 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
2922 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
2924 (org-agenda-files t
)))
2926 (org-prepare-agenda-buffers files
)
2927 ;; If this is called during org-agenda, don't return any entries to
2928 ;; the calendar. Org Agenda will list these entries itself.
2929 (if org-disable-agenda-to-diary
(setq files nil
))
2930 (while (setq file
(pop files
))
2931 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
2932 (setq results
(append results rtn
)))
2934 (concat (org-finalize-agenda-entries results
) "\n"))))
2936 ;;; Agenda entry finders
2938 (defun org-agenda-get-day-entries (file date
&rest args
)
2939 "Does the work for `org-diary' and `org-agenda'.
2940 FILE is the path to a file to be checked for entries. DATE is date like
2941 the one returned by `calendar-current-date'. ARGS are symbols indicating
2942 which kind of entries should be extracted. For details about these, see
2943 the documentation of `org-diary'."
2944 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
2945 (let* ((org-startup-folded nil
)
2946 (org-startup-align-all-tables nil
)
2947 (buffer (if (file-exists-p file
)
2948 (org-get-agenda-file-buffer file
)
2949 (error "No such file %s" file
)))
2952 ;; If file does not exist, make sure an error message ends up in diary
2953 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
2954 (with-current-buffer buffer
2955 (unless (org-mode-p)
2956 (error "Agenda file %s is not in `org-mode'" file
))
2957 (let ((case-fold-search nil
))
2960 (if org-agenda-restrict
2961 (narrow-to-region org-agenda-restrict-begin
2962 org-agenda-restrict-end
)
2964 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
2965 (while (setq arg
(pop args
))
2967 ((and (eq arg
:todo
)
2968 (equal date
(calendar-current-date)))
2969 (setq rtn
(org-agenda-get-todos))
2970 (setq results
(append results rtn
)))
2971 ((eq arg
:timestamp
)
2972 (setq rtn
(org-agenda-get-blocks))
2973 (setq results
(append results rtn
))
2974 (setq rtn
(org-agenda-get-timestamps))
2975 (setq results
(append results rtn
)))
2977 (setq rtn
(org-agenda-get-sexps))
2978 (setq results
(append results rtn
)))
2979 ((eq arg
:scheduled
)
2980 (setq rtn
(org-agenda-get-scheduled))
2981 (setq results
(append results rtn
)))
2983 (setq rtn
(org-agenda-get-closed))
2984 (setq results
(append results rtn
)))
2986 (setq rtn
(org-agenda-get-deadlines))
2987 (setq results
(append results rtn
))))))))
2990 (defun org-agenda-get-todos ()
2991 "Return the TODO information for agenda display."
2992 (let* ((props (list 'face nil
2993 'done-face
'org-done
2994 'org-not-done-regexp org-not-done-regexp
2995 'org-todo-regexp org-todo-regexp
2996 'mouse-face
'highlight
2997 'keymap org-agenda-keymap
2999 (format "mouse-2 or RET jump to org file %s"
3000 (abbreviate-file-name buffer-file-name
))))
3001 (regexp (concat "^\\*+[ \t]+\\("
3002 (if org-select-this-todo-keyword
3003 (if (equal org-select-this-todo-keyword
"*")
3006 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3008 org-not-done-regexp
)
3010 marker priority category tags
3012 (goto-char (point-min))
3013 (while (re-search-forward regexp nil t
)
3017 (setq beg
(point) end
(progn (outline-next-heading) (point)))
3018 (when (or (and org-agenda-todo-ignore-with-date
(goto-char beg
)
3019 (re-search-forward org-ts-regexp end t
))
3020 (and org-agenda-todo-ignore-scheduled
(goto-char beg
)
3021 (re-search-forward org-scheduled-time-regexp end t
))
3022 (and org-agenda-todo-ignore-deadlines
(goto-char beg
)
3023 (re-search-forward org-deadline-time-regexp end t
)
3024 (org-deadline-close (match-string 1))))
3025 (goto-char (1+ beg
))
3026 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3030 (goto-char (match-beginning 1))
3031 (setq marker
(org-agenda-new-marker (match-beginning 0))
3032 category
(org-get-category)
3033 tags
(org-get-tags-at (point))
3034 txt
(org-format-agenda-item "" (match-string 1) category tags
)
3035 priority
(1+ (org-get-priority txt
)))
3036 (org-add-props txt props
3037 'org-marker marker
'org-hd-marker marker
3038 'priority priority
'org-category category
3041 (if org-agenda-todo-list-sublevels
3042 (goto-char (match-end 1))
3043 (org-end-of-subtree 'invisible
))))
3046 (defconst org-agenda-no-heading-message
3047 "No heading for this item in buffer or region.")
3049 (defun org-agenda-get-timestamps ()
3050 "Return the date stamp information for agenda display."
3051 (let* ((props (list 'face nil
3052 'org-not-done-regexp org-not-done-regexp
3053 'org-todo-regexp org-todo-regexp
3054 'mouse-face
'highlight
3055 'keymap org-agenda-keymap
3057 (format "mouse-2 or RET jump to org file %s"
3058 (abbreviate-file-name buffer-file-name
))))
3059 (d1 (calendar-absolute-from-gregorian date
))
3065 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3072 (car org-time-stamp-formats
)
3073 (apply 'encode-time
; DATE bound by calendar
3074 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3076 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3077 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3078 marker hdmarker deadlinep scheduledp donep tmp priority category
3079 ee txt timestr tags b0 b3 e3 head
)
3080 (goto-char (point-min))
3081 (while (re-search-forward regexp nil t
)
3082 (setq b0
(match-beginning 0)
3083 b3
(match-beginning 3) e3
(match-end 3))
3085 (and (org-at-date-range-p) (throw :skip nil
))
3087 (if (and (match-end 1)
3088 (not (= d1
(org-time-string-to-absolute
3089 (match-string 1) d1 nil
3090 org-agenda-repeating-timestamp-show-all
))))
3093 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3095 (setq marker
(org-agenda-new-marker b0
)
3096 category
(org-get-category b0
)
3097 tmp
(buffer-substring (max (point-min)
3098 (- b0 org-ds-keyword-length
))
3100 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3101 deadlinep
(string-match org-deadline-regexp tmp
)
3102 scheduledp
(string-match org-scheduled-regexp tmp
)
3103 donep
(org-entry-is-done-p))
3104 (if (or scheduledp deadlinep
) (throw :skip t
))
3105 (if (string-match ">" timestr
)
3106 ;; substring should only run to end of time stamp
3107 (setq timestr
(substring timestr
0 (match-end 0))))
3109 (if (re-search-backward "^\\*+ " nil t
)
3111 (goto-char (match-beginning 0))
3112 (setq hdmarker
(org-agenda-new-marker)
3113 tags
(org-get-tags-at))
3114 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3115 (setq head
(match-string 1))
3116 (and org-agenda-skip-timestamp-if-done donep
(throw :skip t
))
3117 (setq txt
(org-format-agenda-item
3118 nil head category tags timestr nil
3120 (setq txt org-agenda-no-heading-message
))
3121 (setq priority
(org-get-priority txt
))
3122 (org-add-props txt props
3123 'org-marker marker
'org-hd-marker hdmarker
)
3124 (org-add-props txt nil
'priority priority
3125 'org-category category
'date date
3128 (outline-next-heading)))
3131 (defun org-agenda-get-sexps ()
3132 "Return the sexp information for agenda display."
3133 (require 'diary-lib
)
3134 (let* ((props (list 'face nil
3135 'mouse-face
'highlight
3136 'keymap org-agenda-keymap
3138 (format "mouse-2 or RET jump to org file %s"
3139 (abbreviate-file-name buffer-file-name
))))
3141 marker category ee txt tags entry result beg b sexp sexp-entry
)
3142 (goto-char (point-min))
3143 (while (re-search-forward regexp nil t
)
3146 (setq beg
(match-beginning 0))
3147 (goto-char (1- (match-end 0)))
3150 (setq sexp
(buffer-substring b
(point)))
3151 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3152 (org-trim (match-string 1))
3154 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3156 (setq marker
(org-agenda-new-marker beg
)
3157 category
(org-get-category beg
))
3159 (if (string-match "\\S-" result
)
3161 (setq txt
"SEXP entry returned empty string"))
3163 (setq txt
(org-format-agenda-item
3164 "" txt category tags
'time
))
3165 (org-add-props txt props
'org-marker marker
)
3166 (org-add-props txt nil
3167 'org-category category
'date date
3172 (defun org-agenda-get-closed ()
3173 "Return the logged TODO entries for agenda display."
3174 (let* ((props (list 'mouse-face
'highlight
3175 'org-not-done-regexp org-not-done-regexp
3176 'org-todo-regexp org-todo-regexp
3177 'keymap org-agenda-keymap
3179 (format "mouse-2 or RET jump to org file %s"
3180 (abbreviate-file-name buffer-file-name
))))
3182 "\\<\\(" org-closed-string
"\\|" org-clock-string
"\\) *\\["
3186 (car org-time-stamp-formats
)
3187 (apply 'encode-time
; DATE bound by calendar
3188 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3190 marker hdmarker priority category tags closedp
3192 (goto-char (point-min))
3193 (while (re-search-forward regexp nil t
)
3196 (setq marker
(org-agenda-new-marker (match-beginning 0))
3197 closedp
(equal (match-string 1) org-closed-string
)
3198 category
(org-get-category (match-beginning 0))
3199 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3200 ;; donep (org-entry-is-done-p)
3202 (if (string-match "\\]" timestr
)
3203 ;; substring should only run to end of time stamp
3204 (setq timestr
(substring timestr
0 (match-end 0))))
3206 (if (re-search-backward "^\\*+ " nil t
)
3208 (goto-char (match-beginning 0))
3209 (setq hdmarker
(org-agenda-new-marker)
3210 tags
(org-get-tags-at))
3211 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3212 (setq txt
(org-format-agenda-item
3213 (if closedp
"Closed: " "Clocked: ")
3214 (match-string 1) category tags timestr
)))
3215 (setq txt org-agenda-no-heading-message
))
3216 (setq priority
100000)
3217 (org-add-props txt props
3218 'org-marker marker
'org-hd-marker hdmarker
'face
'org-done
3219 'priority priority
'org-category category
3220 'type
"closed" 'date date
3221 'undone-face
'org-warning
'done-face
'org-done
)
3223 (goto-char (point-at-eol))))
3226 (defun org-agenda-get-deadlines ()
3227 "Return the deadline information for agenda display."
3228 (let* ((props (list 'mouse-face
'highlight
3229 'org-not-done-regexp org-not-done-regexp
3230 'org-todo-regexp org-todo-regexp
3231 'keymap org-agenda-keymap
3233 (format "mouse-2 or RET jump to org file %s"
3234 (abbreviate-file-name buffer-file-name
))))
3235 (regexp org-deadline-time-regexp
)
3236 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
3237 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3238 d2 diff dfrac wdays pos pos1 category tags
3239 ee txt head face s upcomingp donep timestr
)
3240 (goto-char (point-min))
3241 (while (re-search-forward regexp nil t
)
3244 (setq s
(match-string 1)
3245 pos
(1- (match-beginning 1))
3246 d2
(org-time-string-to-absolute
3247 (match-string 1) d1
'past
3248 org-agenda-repeating-timestamp-show-all
)
3250 wdays
(org-get-wdays s
)
3251 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3252 upcomingp
(and todayp
(> diff
0)))
3253 ;; When to show a deadline in the calendar:
3254 ;; If the expiration is within wdays warning time.
3255 ;; Past-due deadlines are only shown on the current date
3256 (if (or (and (<= diff wdays
)
3257 (and todayp
(not org-agenda-only-exact-dates
)))
3260 (setq category
(org-get-category))
3261 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3263 (goto-char (match-end 0))
3264 (setq pos1
(match-beginning 0))
3265 (setq tags
(org-get-tags-at pos1
))
3266 (setq head
(buffer-substring-no-properties
3268 (progn (skip-chars-forward "^\r\n")
3270 (setq donep
(string-match org-looking-at-done-regexp head
))
3271 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3273 (concat (substring s
(match-beginning 1)) " "))
3274 (setq timestr
'time
))
3276 (or org-agenda-skip-deadline-if-done
3279 (setq txt
(org-format-agenda-item
3281 (car org-agenda-deadline-leaders
)
3282 (if (functionp (nth 1 org-agenda-deadline-leaders
))
3283 (funcall (nth 1 org-agenda-deadline-leaders
) diff date
)
3284 (format (nth 1 org-agenda-deadline-leaders
)
3286 head category tags timestr
))))
3287 (setq txt org-agenda-no-heading-message
))
3289 (setq face
(org-agenda-deadline-face dfrac wdays
))
3290 (org-add-props txt props
3291 'org-marker
(org-agenda-new-marker pos
)
3292 'org-hd-marker
(org-agenda-new-marker pos1
)
3293 'priority
(+ (- diff
)
3294 (org-get-priority txt
))
3295 'org-category category
3296 'type
(if upcomingp
"upcoming-deadline" "deadline")
3297 'date
(if upcomingp date d2
)
3298 'face
(if donep
'org-done face
)
3299 'undone-face face
'done-face
'org-done
)
3303 (defun org-agenda-deadline-face (fraction &optional wdays
)
3304 "Return the face to displaying a deadline item.
3305 FRACTION is what fraction of the head-warning time has passed."
3306 (if (equal wdays
0) (setq fraction
1.
))
3307 (let ((faces org-agenda-deadline-faces
) f
)
3309 (while (setq f
(pop faces
))
3310 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3312 (defun org-agenda-get-scheduled ()
3313 "Return the scheduled information for agenda display."
3314 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3315 'org-todo-regexp org-todo-regexp
3316 'done-face
'org-done
3317 'mouse-face
'highlight
3318 'keymap org-agenda-keymap
3320 (format "mouse-2 or RET jump to org file %s"
3321 (abbreviate-file-name buffer-file-name
))))
3322 (regexp org-scheduled-time-regexp
)
3323 (todayp (equal date
(calendar-current-date))) ; DATE bound by calendar
3324 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3325 d2 diff pos pos1 category tags
3326 ee txt head pastschedp donep face timestr s
)
3327 (goto-char (point-min))
3328 (while (re-search-forward regexp nil t
)
3331 (setq s
(match-string 1)
3332 pos
(1- (match-beginning 1))
3333 d2
(org-time-string-to-absolute
3334 (match-string 1) d1
'past
3335 org-agenda-repeating-timestamp-show-all
)
3337 (setq pastschedp
(and todayp
(< diff
0)))
3338 ;; When to show a scheduled item in the calendar:
3339 ;; If it is on or past the date.
3340 (if (or (and (< diff
0)
3341 (< (abs diff
) org-scheduled-past-days
)
3342 (and todayp
(not org-agenda-only-exact-dates
)))
3345 (setq category
(org-get-category))
3346 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3348 (goto-char (match-end 0))
3349 (setq pos1
(match-beginning 0))
3350 (setq tags
(org-get-tags-at))
3351 (setq head
(buffer-substring-no-properties
3353 (progn (skip-chars-forward "^\r\n") (point))))
3354 (setq donep
(string-match org-looking-at-done-regexp head
))
3355 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3357 (concat (substring s
(match-beginning 1)) " "))
3358 (setq timestr
'time
))
3360 (or org-agenda-skip-scheduled-if-done
3363 (setq txt
(org-format-agenda-item
3365 (car org-agenda-scheduled-leaders
)
3366 (format (nth 1 org-agenda-scheduled-leaders
)
3368 head category tags timestr
))))
3369 (setq txt org-agenda-no-heading-message
))
3371 (setq face
(if pastschedp
3372 'org-scheduled-previously
3373 'org-scheduled-today
))
3374 (org-add-props txt props
3376 'face
(if donep
'org-done face
)
3377 'org-marker
(org-agenda-new-marker pos
)
3378 'org-hd-marker
(org-agenda-new-marker pos1
)
3379 'type
(if pastschedp
"past-scheduled" "scheduled")
3380 'date
(if pastschedp d2 date
)
3381 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
3382 'org-category category
)
3386 (defun org-agenda-get-blocks ()
3387 "Return the date-range information for agenda display."
3388 (let* ((props (list 'face nil
3389 'org-not-done-regexp org-not-done-regexp
3390 'org-todo-regexp org-todo-regexp
3391 'mouse-face
'highlight
3392 'keymap org-agenda-keymap
3394 (format "mouse-2 or RET jump to org file %s"
3395 (abbreviate-file-name buffer-file-name
))))
3396 (regexp org-tr-regexp
)
3397 (d0 (calendar-absolute-from-gregorian date
))
3398 marker hdmarker ee txt d1 d2 s1 s2 timestr category tags pos
3400 (goto-char (point-min))
3401 (while (re-search-forward regexp nil t
)
3405 (setq timestr
(match-string 0)
3408 d1
(time-to-days (org-time-string-to-time s1
))
3409 d2
(time-to-days (org-time-string-to-time s2
)))
3410 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
3411 ;; Only allow days between the limits, because the normal
3412 ;; date stamps will catch the limits.
3414 (setq marker
(org-agenda-new-marker (point)))
3415 (setq category
(org-get-category))
3416 (if (re-search-backward "^\\*+ " nil t
)
3418 (goto-char (match-beginning 0))
3419 (setq hdmarker
(org-agenda-new-marker (point)))
3420 (setq tags
(org-get-tags-at))
3421 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3422 (setq head
(match-string 1))
3423 (and org-agenda-skip-timestamp-if-done
3424 (org-entry-is-done-p)
3426 (setq txt
(org-format-agenda-item
3427 (format (if (= d1 d2
) "" "(%d/%d): ")
3428 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
3430 (if (= d0 d1
) timestr
))))
3431 (setq txt org-agenda-no-heading-message
))
3432 (org-add-props txt props
3433 'org-marker marker
'org-hd-marker hdmarker
3434 'type
"block" 'date date
3435 'priority
(org-get-priority txt
) 'org-category category
)
3438 ;; Sort the entries by expiration date.
3441 ;;; Agenda presentation and sorting
3443 (defvar org-prefix-has-time nil
3444 "A flag, set by `org-compile-prefix-format'.
3445 The flag is set if the currently compiled format contains a `%t'.")
3446 (defvar org-prefix-has-tag nil
3447 "A flag, set by `org-compile-prefix-format'.
3448 The flag is set if the currently compiled format contains a `%T'.")
3450 (defun org-format-agenda-item (extra txt
&optional category tags dotime
3452 "Format TXT to be inserted into the agenda buffer.
3453 In particular, it adds the prefix and corresponding text properties. EXTRA
3454 must be a string and replaces the `%s' specifier in the prefix format.
3455 CATEGORY (string, symbol or nil) may be used to overrule the default
3456 category taken from local variable or file name. It will replace the `%c'
3457 specifier in the format. DOTIME, when non-nil, indicates that a
3458 time-of-day should be extracted from TXT for sorting of this entry, and for
3459 the `%t' specifier in the format. When DOTIME is a string, this string is
3460 searched for a time before TXT is. NOPREFIX is a flag and indicates that
3461 only the correctly processes TXT should be returned - this is used by
3462 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
3463 Any match of REMOVE-RE will be removed from TXT."
3465 ;; Diary entries sometimes have extra whitespace at the beginning
3466 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
3467 (let* ((category (or category
3469 (if buffer-file-name
3470 (file-name-sans-extension
3471 (file-name-nondirectory buffer-file-name
))
3473 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
3474 time
; time and tag are needed for the eval of the prefix format
3475 (ts (if dotime
(concat (if (stringp dotime
) dotime
"") txt
)))
3476 (time-of-day (and dotime
(org-get-time-of-day ts
)))
3477 stamp plain s0 s1 s2 rtn srp
)
3478 (when (and dotime time-of-day org-prefix-has-time
)
3479 ;; Extract starting and ending time and move them to prefix
3480 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
3481 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
3482 (setq s0
(match-string 0 ts
)
3483 srp
(and stamp
(match-end 3))
3484 s1
(match-string (if plain
1 2) ts
)
3485 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
3487 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
3488 ;; them, we might want to remove them there to avoid duplication.
3489 ;; The user can turn this off with a variable.
3490 (if (and org-agenda-remove-times-when-in-prefix
(or stamp plain
)
3491 (string-match (concat (regexp-quote s0
) " *") txt
)
3492 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
3493 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
3494 (= (match-beginning 0) 0)
3496 (setq txt
(replace-match "" nil nil txt
))))
3497 ;; Normalize the time(s) to 24 hour
3498 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
3499 (if s2
(setq s2
(org-get-time-of-day s2
'string t
))))
3501 (when (and s1
(not s2
) org-agenda-default-appointment-duration
3502 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
3503 (let ((m (+ (string-to-number (match-string 2 s1
))
3504 (* 60 (string-to-number (match-string 1 s1
)))
3505 org-agenda-default-appointment-duration
))
3507 (setq h
(/ m
60) m
(- m
(* h
60)))
3508 (setq s2
(format "%02d:%02d" h m
))))
3510 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
3512 ;; Tags are in the string
3513 (if (or (eq org-agenda-remove-tags t
)
3514 (and org-agenda-remove-tags
3515 org-prefix-has-tag
))
3516 (setq txt
(replace-match "" t t txt
))
3517 (setq txt
(replace-match
3518 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
3519 (match-string 2 txt
))
3523 (while (string-match remove-re txt
)
3524 (setq txt
(replace-match "" t t txt
))))
3526 ;; Create the final string
3529 ;; Prepare the variables needed in the eval of the compiled format
3530 (setq time
(cond (s2 (concat s1
"-" s2
))
3531 (s1 (concat s1
"......"))
3534 category
(if (symbolp category
) (symbol-name category
) category
))
3535 ;; Evaluate the compiled format
3536 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
3538 ;; And finally add the text properties
3539 (org-add-props rtn nil
3540 'org-category
(downcase category
) 'tags tags
3541 'org-highest-priority org-highest-priority
3542 'org-lowest-priority org-lowest-priority
3543 'prefix-length
(- (length rtn
) (length txt
))
3544 'time-of-day time-of-day
3550 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
3551 (defvar org-agenda-sorting-strategy-selected nil
)
3553 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
3555 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
3556 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
3557 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
3558 ((member 'weekly
(car org-agenda-time-grid
)))
3559 (t (throw 'exit list
)))
3560 (let* ((have (delq nil
(mapcar
3561 (lambda (x) (get-text-property 1 'time-of-day x
))
3563 (string (nth 1 org-agenda-time-grid
))
3564 (gridtimes (nth 2 org-agenda-time-grid
))
3565 (req (car org-agenda-time-grid
))
3566 (remove (member 'remove-match req
))
3568 (if (and (member 'require-timed req
) (not have
))
3569 ;; don't show empty grid
3571 (while (setq time
(pop gridtimes
))
3572 (unless (and remove
(member time have
))
3573 (setq time
(int-to-string time
))
3574 (push (org-format-agenda-item
3576 (concat (substring time
0 -
2) ":" (substring time -
2)))
3579 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
3580 (if (member 'time-up org-agenda-sorting-strategy-selected
)
3582 (append list new
)))))
3584 (defun org-compile-prefix-format (key)
3585 "Compile the prefix format into a Lisp form that can be evaluated.
3586 The resulting form is returned and stored in the variable
3587 `org-prefix-format-compiled'."
3588 (setq org-prefix-has-time nil org-prefix-has-tag nil
)
3590 ((stringp org-agenda-prefix-format
)
3591 org-agenda-prefix-format
)
3592 ((assq key org-agenda-prefix-format
)
3593 (cdr (assq key org-agenda-prefix-format
)))
3594 (t " %-12:c%?-12t% s")))
3596 varform vars var e c f opt
)
3597 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cts]\\)"
3599 (setq var
(cdr (assoc (match-string 4 s
)
3600 '(("c" . category
) ("t" . time
) ("s" . extra
)
3602 c
(or (match-string 3 s
) "")
3603 opt
(match-beginning 1)
3604 start
(1+ (match-beginning 0)))
3605 (if (equal var
'time
) (setq org-prefix-has-time t
))
3606 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
3607 (setq f
(concat "%" (match-string 2 s
) "s"))
3610 `(if (equal "" ,var
)
3612 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
3613 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
3614 (setq s
(replace-match "%s" t nil s
))
3615 (push varform vars
))
3616 (setq vars
(nreverse vars
))
3617 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
3619 (defun org-set-sorting-strategy (key)
3620 (if (symbolp (car org-agenda-sorting-strategy
))
3622 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
3623 (setq org-agenda-sorting-strategy-selected
3624 (or (cdr (assq key org-agenda-sorting-strategy
))
3625 (cdr (assq 'agenda org-agenda-sorting-strategy
))
3626 '(time-up category-keep priority-down
)))))
3628 (defun org-get-time-of-day (s &optional string mod24
)
3629 "Check string S for a time of day.
3630 If found, return it as a military time number between 0 and 2400.
3631 If not found, return nil.
3632 The optional STRING argument forces conversion into a 5 character wide string
3636 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
3637 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
3638 (let* ((h (string-to-number (match-string 1 s
)))
3639 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
3640 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
3641 (am-p (equal ampm
"am"))
3642 (h1 (cond ((not ampm
) h
)
3643 ((= h
12) (if am-p
0 12))
3644 (t (+ h
(if am-p
0 12)))))
3645 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
3647 (t0 (+ (* 100 h2
) m
))
3648 (t1 (concat (if (>= h1
24) "+" " ")
3649 (if (< t0
100) "0" "")
3650 (if (< t0
10) "0" "")
3651 (int-to-string t0
))))
3652 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
3654 (defun org-finalize-agenda-entries (list &optional nosort
)
3655 "Sort and concatenate the agenda items."
3656 (setq list
(mapcar 'org-agenda-highlight-todo list
))
3659 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
3661 (defun org-agenda-highlight-todo (x)
3665 (beginning-of-line 1)
3666 (setq re
(get-text-property (point) 'org-todo-regexp
))
3667 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
3668 (when (looking-at (concat "[ \t]*\\.*" re
" +"))
3669 (add-text-properties (match-beginning 0) (match-end 0)
3670 (list 'face
(org-get-todo-face 0)))
3671 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
3672 (delete-region (match-beginning 1) (1- (match-end 0)))
3673 (goto-char (match-beginning 1))
3674 (insert (format org-agenda-todo-keyword-format s
)))))
3675 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
3676 pl
(get-text-property 0 'prefix-length x
))
3678 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
3680 (add-text-properties
3681 (or (match-end 1) (match-end 0)) (match-end 0)
3682 (list 'face
(org-get-todo-face (match-string 2 x
)))
3684 (setq x
(concat (substring x
0 (match-end 1))
3685 (format org-agenda-todo-keyword-format
3688 (substring x
(match-end 3)))))
3691 (defsubst org-cmp-priority
(a b
)
3692 "Compare the priorities of string A and B."
3693 (let ((pa (or (get-text-property 1 'priority a
) 0))
3694 (pb (or (get-text-property 1 'priority b
) 0)))
3695 (cond ((> pa pb
) +1)
3699 (defsubst org-cmp-category
(a b
)
3700 "Compare the string values of categories of strings A and B."
3701 (let ((ca (or (get-text-property 1 'org-category a
) ""))
3702 (cb (or (get-text-property 1 'org-category b
) "")))
3703 (cond ((string-lessp ca cb
) -
1)
3704 ((string-lessp cb ca
) +1)
3707 (defsubst org-cmp-tag
(a b
)
3708 "Compare the string values of categories of strings A and B."
3709 (let ((ta (car (last (get-text-property 1 'tags a
))))
3710 (tb (car (last (get-text-property 1 'tags b
)))))
3713 ((string-lessp ta tb
) -
1)
3714 ((string-lessp tb ta
) +1)
3717 (defsubst org-cmp-time
(a b
)
3718 "Compare the time-of-day values of strings A and B."
3719 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
3720 (ta (or (get-text-property 1 'time-of-day a
) def
))
3721 (tb (or (get-text-property 1 'time-of-day b
) def
)))
3722 (cond ((< ta tb
) -
1)
3726 (defun org-entries-lessp (a b
)
3727 "Predicate for sorting agenda entries."
3728 ;; The following variables will be used when the form is evaluated.
3729 ;; So even though the compiler complains, keep them.
3730 (let* ((time-up (org-cmp-time a b
))
3731 (time-down (if time-up
(- time-up
) nil
))
3732 (priority-up (org-cmp-priority a b
))
3733 (priority-down (if priority-up
(- priority-up
) nil
))
3734 (category-up (org-cmp-category a b
))
3735 (category-down (if category-up
(- category-up
) nil
))
3736 (category-keep (if category-up
+1 nil
))
3737 (tag-up (org-cmp-tag a b
))
3738 (tag-down (if tag-up
(- tag-up
) nil
)))
3740 (eval (cons 'or org-agenda-sorting-strategy-selected
))
3741 '((-1 . t
) (1 . nil
) (nil . nil
))))))
3743 ;;; Agenda restriction lock
3745 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
3746 "Overlay to mark the headline to which arenda commands are restricted.")
3747 (org-overlay-put org-agenda-restriction-lock-overlay
3748 'face
'org-agenda-restriction-lock
)
3749 (org-overlay-put org-agenda-restriction-lock-overlay
3750 'help-echo
"Agendas are currently limited to this subtree.")
3751 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3753 (defun org-agenda-set-restriction-lock (&optional type
)
3754 "Set restriction lock for agenda, to current subtree or file.
3755 Restriction will be the file if TYPE is `file', or if type is the
3756 universal prefix '(4), or if the cursor is before the first headline
3757 in the file. Otherwise, restriction will be to the current subtree."
3759 (and (equal type
'(4)) (setq type
'file
))
3762 ((org-at-heading-p) 'subtree
)
3763 ((condition-case nil
(org-back-to-heading t
) (error nil
))
3766 (if (eq type
'subtree
)
3768 (setq org-agenda-restrict t
)
3769 (setq org-agenda-overriding-restriction
'subtree
)
3770 (put 'org-agenda-files
'org-restrict
3771 (list (buffer-file-name (buffer-base-buffer))))
3772 (org-back-to-heading t
)
3773 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
3774 (move-marker org-agenda-restrict-begin
(point))
3775 (move-marker org-agenda-restrict-end
3776 (save-excursion (org-end-of-subtree t
)))
3777 (message "Locking agenda restriction to subtree"))
3778 (put 'org-agenda-files
'org-restrict
3779 (list (buffer-file-name (buffer-base-buffer))))
3780 (setq org-agenda-restrict nil
)
3781 (setq org-agenda-overriding-restriction
'file
)
3782 (move-marker org-agenda-restrict-begin nil
)
3783 (move-marker org-agenda-restrict-end nil
)
3784 (message "Locking agenda restriction to file"))
3785 (setq current-prefix-arg nil
)
3786 (org-agenda-maybe-redo))
3788 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
3789 "Remove the agenda restriction lock."
3791 (org-detach-overlay org-agenda-restriction-lock-overlay
)
3792 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
3793 (setq org-agenda-overriding-restriction nil
)
3794 (setq org-agenda-restrict nil
)
3795 (put 'org-agenda-files
'org-restrict nil
)
3796 (move-marker org-agenda-restrict-begin nil
)
3797 (move-marker org-agenda-restrict-end nil
)
3798 (setq current-prefix-arg nil
)
3799 (message "Agenda restriction lock removed")
3800 (or noupdate
(org-agenda-maybe-redo)))
3802 (defun org-agenda-maybe-redo ()
3803 "If there is any window showing the agenda view, update it."
3804 (let ((w (get-buffer-window org-agenda-buffer-name t
))
3805 (w0 (selected-window)))
3810 (if org-agenda-overriding-restriction
3811 (message "Agenda view shifted to new %s restriction"
3812 org-agenda-overriding-restriction
)
3813 (message "Agenda restriction lock removed")))))
3817 (defun org-agenda-check-type (error &rest types
)
3818 "Check if agenda buffer is of allowed type.
3819 If ERROR is non-nil, throw an error, otherwise just return nil."
3820 (if (memq org-agenda-type types
)
3823 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
3826 (defun org-agenda-quit ()
3827 "Exit agenda by removing the window or the buffer."
3829 (let ((buf (current-buffer)))
3830 (if (not (one-window-p)) (delete-window))
3832 (org-agenda-reset-markers)
3833 (org-columns-remove-overlays))
3834 ;; Maybe restore the pre-agenda window configuration.
3835 (and org-agenda-restore-windows-after-quit
3836 (not (eq org-agenda-window-setup
'other-frame
))
3837 org-pre-agenda-window-conf
3838 (set-window-configuration org-pre-agenda-window-conf
)))
3840 (defun org-agenda-exit ()
3841 "Exit agenda by removing the window or the buffer.
3842 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
3843 Org-mode buffers visited directly by the user will not be touched."
3845 (org-release-buffers org-agenda-new-buffers
)
3846 (setq org-agenda-new-buffers nil
)
3849 (defun org-agenda-execute (arg)
3850 "Execute another agenda command, keeping same window.\\<global-map>
3851 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
3853 (let ((org-agenda-window-setup 'current-window
))
3856 (defun org-save-all-org-buffers ()
3857 "Save all Org-mode buffers without user confirmation."
3859 (message "Saving all Org-mode buffers...")
3860 (save-some-buffers t
'org-mode-p
)
3861 (message "Saving all Org-mode buffers... done"))
3863 (defun org-agenda-redo ()
3865 When this is the global TODO list, a prefix argument will be interpreted."
3867 (let* ((org-agenda-keep-modes t
)
3868 (line (org-current-line))
3869 (window-line (- line
(org-current-line (window-start))))
3870 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
3871 (message "Rebuilding agenda buffer...")
3872 (org-let lprops
'(eval org-agenda-redo-command
))
3873 (setq org-agenda-undo-list nil
3874 org-agenda-pending-undo-list nil
)
3875 (message "Rebuilding agenda buffer...done")
3877 (recenter window-line
)))
3879 (defun org-agenda-manipulate-query-add ()
3880 "Manipulate the query by adding a search term with positive selection.
3881 Positive selection means, the term must be matched for selection of an entry."
3883 (org-agenda-manipulate-query ?\
[))
3884 (defun org-agenda-manipulate-query-subtract ()
3885 "Manipulate the query by adding a search term with negative selection.
3886 Negative selection means, term must not be matched for selection of an entry."
3888 (org-agenda-manipulate-query ?\
]))
3889 (defun org-agenda-manipulate-query-add-re ()
3890 "Manipulate the query by adding a search regexp with positive selection.
3891 Positive selection means, the regexp must match for selection of an entry."
3893 (org-agenda-manipulate-query ?\
{))
3894 (defun org-agenda-manipulate-query-subtract-re ()
3895 "Manipulate the query by adding a search regexp with negative selection.
3896 Negative selection means, regexp must not match for selection of an entry."
3898 (org-agenda-manipulate-query ?\
}))
3899 (defun org-agenda-manipulate-query (char)
3901 ((eq org-agenda-type
'search
)
3903 'org-agenda-query-string
3904 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
3905 (?\
{ .
" +{}") (?\
} .
" -{}")))))
3906 (setq org-agenda-redo-command
3907 (list 'org-search-view
3909 org-agenda-query-string
3910 (+ (length org-agenda-query-string
)
3911 (if (member char
'(?\
{ ?\
})) 0 1))))
3912 (set-register org-agenda-query-register org-agenda-query-string
)
3914 (t (error "Canot manipulate query for %s-type agenda buffers"
3917 (defun org-add-to-string (var string
)
3918 (set var
(concat (symbol-value var
) string
)))
3920 (defun org-agenda-goto-date (date)
3921 "Jump to DATE in agenda."
3922 (interactive (list (org-read-date)))
3923 (org-agenda-list nil date
))
3925 (defun org-agenda-goto-today ()
3928 (org-agenda-check-type t
'timeline
'agenda
)
3929 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
3931 (tdpos (goto-char tdpos
))
3932 ((eq org-agenda-type
'agenda
)
3933 (let* ((sd (time-to-days
3934 (time-subtract (current-time)
3935 (list 0 (* 3600 org-extend-today-until
) 0))))
3936 (comp (org-agenda-compute-time-span sd org-agenda-span
))
3937 (org-agenda-overriding-arguments org-agenda-last-arguments
))
3938 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
3939 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
3941 (org-agenda-find-same-or-today-or-agenda)))
3942 (t (error "Cannot find today")))))
3944 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
3946 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
3947 (text-property-any (point-min) (point-max) 'org-today t
)
3948 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
3951 (defun org-agenda-later (arg)
3952 "Go forward in time by thee current span.
3953 With prefix ARG, go forward that many times the current span."
3955 (org-agenda-check-type t
'agenda
)
3956 (let* ((span org-agenda-span
)
3957 (sd org-starting-day
)
3958 (greg (calendar-gregorian-from-absolute sd
))
3959 (cnt (get-text-property (point) 'org-day-cnt
))
3963 (setq sd
(+ arg sd
) nd
1))
3965 (setq sd
(+ (* 7 arg
) sd
) nd
7))
3967 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
3968 sd
(calendar-absolute-from-gregorian greg2
))
3969 (setcar greg2
(1+ (car greg2
)))
3970 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
3972 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
3973 sd
(calendar-absolute-from-gregorian greg2
))
3974 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
3975 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
3976 (let ((org-agenda-overriding-arguments
3977 (list (car org-agenda-last-arguments
) sd nd t
)))
3979 (org-agenda-find-same-or-today-or-agenda cnt
))))
3981 (defun org-agenda-earlier (arg)
3982 "Go backward in time by the current span.
3983 With prefix ARG, go backward that many times the current span."
3985 (org-agenda-later (- arg
)))
3987 (defun org-agenda-day-view (&optional day-of-year
)
3988 "Switch to daily view for agenda.
3989 With argument DAY-OF-YEAR, switch to that day of the year."
3991 (setq org-agenda-ndays
1)
3992 (org-agenda-change-time-span 'day day-of-year
))
3993 (defun org-agenda-week-view (&optional iso-week
)
3994 "Switch to daily view for agenda.
3995 With argument ISO-WEEK, switch to the corresponding ISO week.
3996 If ISO-WEEK has more then 2 digits, only the last two encode the
3997 week. Any digits before this encode a year. So 200712 means
3998 week 12 of year 2007. Years in the range 1938-2037 can also be
3999 written as 2-digit years."
4001 (setq org-agenda-ndays
7)
4002 (org-agenda-change-time-span 'week iso-week
))
4003 (defun org-agenda-month-view (&optional month
)
4004 "Switch to daily view for agenda.
4005 With argument MONTH, switch to that month."
4007 (org-agenda-change-time-span 'month month
))
4008 (defun org-agenda-year-view (&optional year
)
4009 "Switch to daily view for agenda.
4010 With argument YEAR, switch to that year.
4011 If MONTH has more then 2 digits, only the last two encode the
4012 month. Any digits before this encode a year. So 200712 means
4013 December year 2007. Years in the range 1938-2037 can also be
4014 written as 2-digit years."
4017 (setq year
(org-small-year-to-year year
)))
4018 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4019 (org-agenda-change-time-span 'year year
)
4022 (defun org-agenda-change-time-span (span &optional n
)
4023 "Change the agenda view to SPAN.
4024 SPAN may be `day', `week', `month', `year'."
4025 (org-agenda-check-type t
'agenda
)
4026 (if (and (not n
) (equal org-agenda-span span
))
4027 (error "Viewing span is already \"%s\"" span
))
4028 (let* ((sd (or (get-text-property (point) 'day
)
4030 (computed (org-agenda-compute-time-span sd span n
))
4031 (org-agenda-overriding-arguments
4032 (list (car org-agenda-last-arguments
)
4033 (car computed
) (cdr computed
) t
)))
4035 (org-agenda-find-same-or-today-or-agenda))
4036 (org-agenda-set-mode-name)
4037 (message "Switched to %s view" span
))
4039 (defun org-agenda-compute-time-span (sd span
&optional n
)
4040 "Compute starting date and number of days for agenda.
4041 SPAN may be `day', `week', `month', `year'. The return value
4042 is a cons cell with the starting date and the number of days,
4043 so that the date SD will be in that range."
4044 (let* ((greg (calendar-gregorian-from-absolute sd
))
4048 nd w1 y1 m1 thisweek
)
4052 (setq sd
(+ (calendar-absolute-from-gregorian
4057 (let* ((nt (calendar-day-of-week
4058 (calendar-gregorian-from-absolute sd
)))
4059 (d (if org-agenda-start-on-weekday
4060 (- nt org-agenda-start-on-weekday
)
4062 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
4065 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
4067 (setq y1
(org-small-year-to-year (/ n
100))
4070 (calendar-absolute-from-iso
4072 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
4075 (when (and n
(> n
99))
4076 (setq y1
(org-small-year-to-year (/ n
100))
4078 (setq sd
(calendar-absolute-from-gregorian
4079 (list (or n mg
) 1 (or y1 yg
)))
4080 nd
(- (calendar-absolute-from-gregorian
4081 (list (1+ (or n mg
)) 1 (or y1 yg
)))
4084 (setq sd
(calendar-absolute-from-gregorian
4085 (list 1 1 (or n yg
)))
4086 nd
(- (calendar-absolute-from-gregorian
4087 (list 1 1 (1+ (or n yg
))))
4091 (defun org-agenda-next-date-line (&optional arg
)
4092 "Jump to the next line indicating a date in agenda buffer."
4094 (org-agenda-check-type t
'agenda
'timeline
)
4095 (beginning-of-line 1)
4096 ;; This does not work if user makes date format that starts with a blank
4097 (if (looking-at "^\\S-") (forward-char 1))
4098 (if (not (re-search-forward "^\\S-" nil t arg
))
4101 (error "No next date after this line in this buffer")))
4102 (goto-char (match-beginning 0)))
4104 (defun org-agenda-previous-date-line (&optional arg
)
4105 "Jump to the previous line indicating a date in agenda buffer."
4107 (org-agenda-check-type t
'agenda
'timeline
)
4108 (beginning-of-line 1)
4109 (if (not (re-search-backward "^\\S-" nil t arg
))
4110 (error "No previous date before this line in this buffer")))
4112 ;; Initialize the highlight
4113 (defvar org-hl
(org-make-overlay 1 1))
4114 (org-overlay-put org-hl
'face
'highlight
)
4116 (defun org-highlight (begin end
&optional buffer
)
4117 "Highlight a region with overlay."
4118 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
4119 org-hl begin end
(or buffer
(current-buffer))))
4121 (defun org-unhighlight ()
4122 "Detach overlay INDEX."
4123 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
4125 ;; FIXME this is currently not used.
4126 (defun org-highlight-until-next-command (beg end
&optional buffer
)
4127 "Move the highlight overlay to BEG/END, remove it before the next command."
4128 (org-highlight beg end buffer
)
4129 (add-hook 'pre-command-hook
'org-unhighlight-once
))
4130 (defun org-unhighlight-once ()
4131 "Remove the highlight from its position, and this function from the hook."
4132 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
4135 (defun org-agenda-follow-mode ()
4136 "Toggle follow mode in an agenda buffer."
4138 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
4139 (org-agenda-set-mode-name)
4140 (message "Follow mode is %s"
4141 (if org-agenda-follow-mode
"on" "off")))
4143 (defun org-agenda-clockreport-mode ()
4144 "Toggle clocktable mode in an agenda buffer."
4146 (org-agenda-check-type t
'agenda
)
4147 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
4148 (org-agenda-set-mode-name)
4150 (message "Clocktable mode is %s"
4151 (if org-agenda-clockreport-mode
"on" "off")))
4153 (defun org-agenda-log-mode ()
4154 "Toggle log mode in an agenda buffer."
4156 (org-agenda-check-type t
'agenda
'timeline
)
4157 (setq org-agenda-show-log
(not org-agenda-show-log
))
4158 (org-agenda-set-mode-name)
4160 (message "Log mode is %s"
4161 (if org-agenda-show-log
"on" "off")))
4163 (defun org-agenda-toggle-diary ()
4164 "Toggle diary inclusion in an agenda buffer."
4166 (org-agenda-check-type t
'agenda
)
4167 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
4169 (org-agenda-set-mode-name)
4170 (message "Diary inclusion turned %s"
4171 (if org-agenda-include-diary
"on" "off")))
4173 (defun org-agenda-toggle-time-grid ()
4174 "Toggle time grid in an agenda buffer."
4176 (org-agenda-check-type t
'agenda
)
4177 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
4179 (org-agenda-set-mode-name)
4180 (message "Time-grid turned %s"
4181 (if org-agenda-use-time-grid
"on" "off")))
4183 (defun org-agenda-set-mode-name ()
4184 "Set the mode name to indicate all the small mode settings."
4186 (concat "Org-Agenda"
4187 (if (equal org-agenda-ndays
1) " Day" "")
4188 (if (equal org-agenda-ndays
7) " Week" "")
4189 (if org-agenda-follow-mode
" Follow" "")
4190 (if org-agenda-include-diary
" Diary" "")
4191 (if org-agenda-use-time-grid
" Grid" "")
4192 (if org-agenda-show-log
" Log" "")
4193 (if org-agenda-clockreport-mode
" Clock" "")))
4194 (force-mode-line-update))
4196 (defun org-agenda-post-command-hook ()
4197 (and (eolp) (not (bolp)) (backward-char 1))
4198 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
4199 (if (and org-agenda-follow-mode
4200 (get-text-property (point) 'org-marker
))
4203 (defun org-agenda-show-priority ()
4204 "Show the priority of the current item.
4205 This priority is composed of the main priority given with the [#A] cookies,
4206 and by additional input from the age of a schedules or deadline entry."
4208 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
4209 (message "Priority is %d" (if pri pri -
1000))))
4211 (defun org-agenda-show-tags ()
4212 "Show the tags applicable to the current item."
4214 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
4216 (message "Tags are :%s:"
4217 (org-no-properties (mapconcat 'identity tags
":")))
4218 (message "No tags associated with this line"))))
4220 (defun org-agenda-goto (&optional highlight
)
4221 "Go to the Org-mode file which contains the item at point."
4223 (let* ((marker (or (get-text-property (point) 'org-marker
)
4224 (org-agenda-error)))
4225 (buffer (marker-buffer marker
))
4226 (pos (marker-position marker
)))
4227 (switch-to-buffer-other-window buffer
)
4231 (org-show-context 'agenda
)
4233 (and (outline-next-heading)
4234 (org-flag-heading nil
)))) ; show the next heading
4235 (recenter (/ (window-height) 2))
4236 (run-hooks 'org-agenda-after-show-hook
)
4237 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
4239 (defvar org-agenda-after-show-hook nil
4240 "Normal hook run after an item has been shown from the agenda.
4241 Point is in the buffer where the item originated.")
4243 (defun org-agenda-kill ()
4244 "Kill the entry or subtree belonging to the current agenda entry."
4246 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
4247 (let* ((marker (or (get-text-property (point) 'org-marker
)
4248 (org-agenda-error)))
4249 (buffer (marker-buffer marker
))
4250 (pos (marker-position marker
))
4251 (type (get-text-property (point) 'type
))
4252 dbeg dend
(n 0) conf
)
4253 (org-with-remote-undo buffer
4254 (with-current-buffer buffer
4257 (if (and (org-mode-p) (not (member type
'("sexp"))))
4258 (setq dbeg
(progn (org-back-to-heading t
) (point))
4259 dend
(org-end-of-subtree t t
))
4260 (setq dbeg
(point-at-bol)
4261 dend
(min (point-max) (1+ (point-at-eol)))))
4263 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
4264 (setq conf
(or (eq t org-agenda-confirm-kill
)
4265 (and (numberp org-agenda-confirm-kill
)
4266 (> n org-agenda-confirm-kill
))))
4269 (format "Delete entry with %d lines in buffer \"%s\"? "
4270 n
(buffer-name buffer
))))
4272 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
4273 (with-current-buffer buffer
(delete-region dbeg dend
))
4274 (message "Agenda item and source killed"))))
4276 (defun org-agenda-archive ()
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 (org-with-remote-undo buffer
4285 (with-current-buffer buffer
4289 (org-remove-subtree-entries-from-agenda)
4290 (org-back-to-heading t
)
4291 (org-archive-subtree))
4292 (error "Archiving works only in Org-mode files"))))))
4294 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
4295 "Remove all lines in the agenda that correspond to a given subtree.
4296 The subtree is the one in buffer BUF, starting at BEG and ending at END.
4297 If this information is not given, the function uses the tree at point."
4298 (let ((buf (or buf
(current-buffer))) m p
)
4300 (unless (and beg end
)
4301 (org-back-to-heading t
)
4303 (org-end-of-subtree t
)
4305 (set-buffer (get-buffer org-agenda-buffer-name
))
4307 (goto-char (point-max))
4308 (beginning-of-line 1)
4310 (when (and (setq m
(get-text-property (point) 'org-marker
))
4311 (equal buf
(marker-buffer m
))
4312 (setq p
(marker-position m
))
4315 (let ((inhibit-read-only t
))
4316 (delete-region (point-at-bol) (1+ (point-at-eol)))))
4317 (beginning-of-line 0))))))
4319 (defun org-agenda-open-link ()
4320 "Follow the link in the current line, if any."
4322 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
4325 (narrow-to-region (point-at-bol) (point-at-eol))
4326 (org-open-at-point))))
4328 (defun org-agenda-copy-local-variable (var)
4329 "Get a variable from a referenced buffer and install it here."
4330 (let ((m (get-text-property (point) 'org-marker
)))
4331 (when (and m
(buffer-live-p (marker-buffer m
)))
4332 (org-set-local var
(with-current-buffer (marker-buffer m
)
4333 (symbol-value var
))))))
4335 (defun org-agenda-switch-to (&optional delete-other-windows
)
4336 "Go to the Org-mode file which contains the item at point."
4338 (let* ((marker (or (get-text-property (point) 'org-marker
)
4339 (org-agenda-error)))
4340 (buffer (marker-buffer marker
))
4341 (pos (marker-position marker
)))
4342 (switch-to-buffer buffer
)
4343 (and delete-other-windows
(delete-other-windows))
4347 (org-show-context 'agenda
)
4349 (and (outline-next-heading)
4350 (org-flag-heading nil
)))))) ; show the next heading
4352 (defun org-agenda-goto-mouse (ev)
4353 "Go to the Org-mode file which contains the item at the mouse click."
4355 (mouse-set-point ev
)
4358 (defun org-agenda-show ()
4359 "Display the Org-mode file which contains the item at point."
4361 (let ((win (selected-window)))
4363 (select-window win
)))
4365 (defun org-agenda-recenter (arg)
4366 "Display the Org-mode file which contains the item at point and recenter."
4368 (let ((win (selected-window)))
4371 (select-window win
)))
4373 (defun org-agenda-show-mouse (ev)
4374 "Display the Org-mode file which contains the item at the mouse click."
4376 (mouse-set-point ev
)
4379 (defun org-agenda-check-no-diary ()
4380 "Check if the entry is a diary link and abort if yes."
4381 (if (get-text-property (point) 'org-agenda-diary-link
)
4382 (org-agenda-error)))
4384 (defun org-agenda-error ()
4385 (error "Command not allowed in this line"))
4387 (defun org-agenda-tree-to-indirect-buffer ()
4388 "Show the subtree corresponding to the current entry in an indirect buffer.
4389 This calls the command `org-tree-to-indirect-buffer' from the original
4391 With numerical prefix arg ARG, go up to this level and then take that tree.
4392 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
4395 (org-agenda-check-no-diary)
4396 (let* ((marker (or (get-text-property (point) 'org-marker
)
4397 (org-agenda-error)))
4398 (buffer (marker-buffer marker
))
4399 (pos (marker-position marker
)))
4400 (with-current-buffer buffer
4403 (call-interactively 'org-tree-to-indirect-buffer
)))))
4405 (defvar org-last-heading-marker
(make-marker)
4406 "Marker pointing to the headline that last changed its TODO state
4407 by a remote command from the agenda.")
4409 (defun org-agenda-todo-nextset ()
4410 "Switch TODO entry to next sequence."
4412 (org-agenda-todo 'nextset
))
4414 (defun org-agenda-todo-previousset ()
4415 "Switch TODO entry to previous sequence."
4417 (org-agenda-todo 'previousset
))
4419 (defun org-agenda-todo (&optional arg
)
4420 "Cycle TODO state of line at point, also in Org-mode file.
4421 This changes the line at point, all other lines in the agenda referring to
4422 the same tree node, and the headline of the tree node in the Org-mode file."
4424 (org-agenda-check-no-diary)
4425 (let* ((col (current-column))
4426 (marker (or (get-text-property (point) 'org-marker
)
4427 (org-agenda-error)))
4428 (buffer (marker-buffer marker
))
4429 (pos (marker-position marker
))
4430 (hdmarker (get-text-property (point) 'org-hd-marker
))
4431 (inhibit-read-only t
)
4433 (org-with-remote-undo buffer
4434 (with-current-buffer buffer
4437 (org-show-context 'agenda
)
4439 (and (outline-next-heading)
4440 (org-flag-heading nil
))) ; show the next heading
4442 (and (bolp) (forward-char 1))
4443 (setq newhead
(org-get-heading))
4445 (org-back-to-heading)
4446 (move-marker org-last-heading-marker
(point))))
4447 (beginning-of-line 1)
4449 (org-agenda-change-all-lines newhead hdmarker
'fixface
))
4450 (move-to-column col
))))
4452 (defun org-agenda-add-note (&optional arg
)
4453 "Add a time-stamped note to the entry at point."
4455 (org-agenda-check-no-diary)
4456 (let* ((marker (or (get-text-property (point) 'org-marker
)
4457 (org-agenda-error)))
4458 (buffer (marker-buffer marker
))
4459 (pos (marker-position marker
))
4460 (hdmarker (get-text-property (point) 'org-hd-marker
))
4461 (inhibit-read-only t
))
4462 (with-current-buffer buffer
4465 (org-show-context 'agenda
)
4467 (and (outline-next-heading)
4468 (org-flag-heading nil
))) ; show the next heading
4471 (defun org-agenda-change-all-lines (newhead hdmarker
&optional fixface
)
4472 "Change all lines in the agenda buffer which match HDMARKER.
4473 The new content of the line will be NEWHEAD (as modified by
4474 `org-format-agenda-item'). HDMARKER is checked with
4475 `equal' against all `org-hd-marker' text properties in the file.
4476 If FIXFACE is non-nil, the face of each item is modified acording to
4477 the new TODO state."
4478 (let* ((inhibit-read-only t
)
4479 props m pl undone-face done-face finish new dotime cat tags
)
4481 (goto-char (point-max))
4482 (beginning-of-line 1)
4484 (setq finish
(bobp))
4485 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
4487 (setq props
(text-properties-at (point))
4488 dotime
(get-text-property (point) 'dotime
)
4489 cat
(get-text-property (point) 'org-category
)
4490 tags
(get-text-property (point) 'tags
)
4491 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
4492 pl
(get-text-property (point) 'prefix-length
)
4493 undone-face
(get-text-property (point) 'undone-face
)
4494 done-face
(get-text-property (point) 'done-face
))
4498 (beginning-of-line 1)
4499 (and (looking-at ".*\n?") (replace-match "")))
4501 (replace-match new t t
)
4502 (beginning-of-line 1)
4503 (add-text-properties (point-at-bol) (point-at-eol) props
)
4505 (add-text-properties
4506 (point-at-bol) (point-at-eol)
4508 (if org-last-todo-state-is-todo
4509 undone-face done-face
))))
4510 (org-agenda-highlight-todo 'line
)
4511 (beginning-of-line 1))
4512 (t (error "Line update did not work"))))
4513 (beginning-of-line 0)))
4514 (org-finalize-agenda)))
4516 (defun org-agenda-align-tags (&optional line
)
4517 "Align all tags in agenda items to `org-agenda-tags-column'."
4518 (let ((inhibit-read-only t
) l c
)
4520 (goto-char (if line
(point-at-bol) (point-min)))
4521 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4522 (if line
(point-at-eol) nil
) t
)
4523 (add-text-properties
4524 (match-beginning 2) (match-end 2)
4525 (list 'face
(delq nil
(list 'org-tag
(get-text-property
4526 (match-beginning 2) 'face
)))))
4527 (setq l
(- (match-end 2) (match-beginning 2))
4528 c
(if (< org-agenda-tags-column
0)
4529 (- (abs org-agenda-tags-column
) l
)
4530 org-agenda-tags-column
))
4531 (delete-region (match-beginning 1) (match-end 1))
4532 (goto-char (match-beginning 1))
4533 (insert (org-add-props
4534 (make-string (max 1 (- c
(current-column))) ?\
)
4535 (text-properties-at (point))))))))
4537 (defun org-agenda-priority-up ()
4538 "Increase the priority of line at point, also in Org-mode file."
4540 (org-agenda-priority 'up
))
4542 (defun org-agenda-priority-down ()
4543 "Decrease the priority of line at point, also in Org-mode file."
4545 (org-agenda-priority 'down
))
4547 (defun org-agenda-priority (&optional force-direction
)
4548 "Set the priority of line at point, also in Org-mode file.
4549 This changes the line at point, all other lines in the agenda referring to
4550 the same tree node, and the headline of the tree node in the Org-mode file."
4552 (org-agenda-check-no-diary)
4553 (let* ((marker (or (get-text-property (point) 'org-marker
)
4554 (org-agenda-error)))
4555 (hdmarker (get-text-property (point) 'org-hd-marker
))
4556 (buffer (marker-buffer hdmarker
))
4557 (pos (marker-position hdmarker
))
4558 (inhibit-read-only t
)
4560 (org-with-remote-undo buffer
4561 (with-current-buffer buffer
4564 (org-show-context 'agenda
)
4566 (and (outline-next-heading)
4567 (org-flag-heading nil
))) ; show the next heading
4568 (funcall 'org-priority force-direction
)
4570 (setq newhead
(org-get-heading)))
4571 (org-agenda-change-all-lines newhead hdmarker
)
4572 (beginning-of-line 1))))
4574 ;; FIXME: should fix the tags property of the agenda line.
4575 (defun org-agenda-set-tags ()
4576 "Set tags for the current headline."
4578 (org-agenda-check-no-diary)
4579 (if (and (org-region-active-p) (interactive-p))
4580 (call-interactively 'org-change-tag-in-region
)
4581 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4582 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4583 (org-agenda-error)))
4584 (buffer (marker-buffer hdmarker
))
4585 (pos (marker-position hdmarker
))
4586 (inhibit-read-only t
)
4588 (org-with-remote-undo buffer
4589 (with-current-buffer buffer
4593 (org-show-context 'agenda
))
4595 (and (outline-next-heading)
4596 (org-flag-heading nil
))) ; show the next heading
4598 (call-interactively 'org-set-tags
)
4600 (setq newhead
(org-get-heading)))
4601 (org-agenda-change-all-lines newhead hdmarker
)
4602 (beginning-of-line 1)))))
4604 (defun org-agenda-toggle-archive-tag ()
4605 "Toggle the archive tag for the current entry."
4607 (org-agenda-check-no-diary)
4608 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
4609 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
4610 (org-agenda-error)))
4611 (buffer (marker-buffer hdmarker
))
4612 (pos (marker-position hdmarker
))
4613 (inhibit-read-only t
)
4615 (org-with-remote-undo buffer
4616 (with-current-buffer buffer
4619 (org-show-context 'agenda
)
4621 (and (outline-next-heading)
4622 (org-flag-heading nil
))) ; show the next heading
4623 (call-interactively 'org-toggle-archive-tag
)
4625 (setq newhead
(org-get-heading)))
4626 (org-agenda-change-all-lines newhead hdmarker
)
4627 (beginning-of-line 1))))
4629 (defun org-agenda-date-later (arg &optional what
)
4630 "Change the date of this item to one day later."
4632 (org-agenda-check-type t
'agenda
'timeline
)
4633 (org-agenda-check-no-diary)
4634 (let* ((marker (or (get-text-property (point) 'org-marker
)
4635 (org-agenda-error)))
4636 (buffer (marker-buffer marker
))
4637 (pos (marker-position marker
)))
4638 (org-with-remote-undo buffer
4639 (with-current-buffer buffer
4642 (if (not (org-at-timestamp-p))
4643 (error "Cannot find time stamp"))
4644 (org-timestamp-change arg
(or what
'day
)))
4645 (org-agenda-show-new-time marker org-last-changed-timestamp
))
4646 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
4648 (defun org-agenda-date-earlier (arg &optional what
)
4649 "Change the date of this item to one day earlier."
4651 (org-agenda-date-later (- arg
) what
))
4653 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
4654 "Show new date stamp via text properties."
4655 ;; We use text properties to make this undoable
4656 (let ((inhibit-read-only t
))
4657 (setq stamp
(concat " " prefix
" => " stamp
))
4659 (goto-char (point-max))
4661 (when (equal marker
(get-text-property (point) 'org-marker
))
4662 (move-to-column (- (window-width) (length stamp
)) t
)
4663 (if (featurep 'xemacs
)
4664 ;; Use `duplicable' property to trigger undo recording
4665 (let ((ex (make-extent nil nil
))
4666 (gl (make-glyph stamp
)))
4667 (set-glyph-face gl
'secondary-selection
)
4668 (set-extent-properties
4669 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
4670 (insert-extent ex
(1- (point)) (point-at-eol)))
4671 (add-text-properties
4672 (1- (point)) (point-at-eol)
4673 (list 'display
(org-add-props stamp nil
4674 'face
'secondary-selection
))))
4675 (beginning-of-line 1))
4676 (beginning-of-line 0)))))
4678 (defun org-agenda-date-prompt (arg)
4679 "Change the date of this item. Date is prompted for, with default today.
4680 The prefix ARG is passed to the `org-time-stamp' command and can therefore
4681 be used to request time specification in the time stamp."
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-time-stamp arg
)
4696 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
4698 (defun org-agenda-schedule (arg)
4699 "Schedule the item at point."
4701 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4702 (org-agenda-check-no-diary)
4703 (let* ((marker (or (get-text-property (point) 'org-marker
)
4704 (org-agenda-error)))
4705 (type (marker-insertion-type marker
))
4706 (buffer (marker-buffer marker
))
4707 (pos (marker-position marker
))
4708 (org-insert-labeled-timestamps-at-point nil
)
4710 (when type
(message "%s" type
) (sit-for 3))
4711 (set-marker-insertion-type marker t
)
4712 (org-with-remote-undo buffer
4713 (with-current-buffer buffer
4716 (setq ts
(org-schedule arg
)))
4717 (org-agenda-show-new-time marker ts
"S"))
4718 (message "Item scheduled for %s" ts
)))
4720 (defun org-agenda-deadline (arg)
4721 "Schedule the item at point."
4723 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
4724 (org-agenda-check-no-diary)
4725 (let* ((marker (or (get-text-property (point) 'org-marker
)
4726 (org-agenda-error)))
4727 (buffer (marker-buffer marker
))
4728 (pos (marker-position marker
))
4729 (org-insert-labeled-timestamps-at-point nil
)
4731 (org-with-remote-undo buffer
4732 (with-current-buffer buffer
4735 (setq ts
(org-deadline arg
)))
4736 (org-agenda-show-new-time marker ts
"S"))
4737 (message "Deadline for this item set to %s" ts
)))
4740 (defun org-agenda-clock-in (&optional arg
)
4741 "Start the clock on the currently selected item."
4743 (org-agenda-check-no-diary)
4744 (let* ((marker (or (get-text-property (point) 'org-marker
)
4745 (org-agenda-error)))
4746 (pos (marker-position marker
)))
4747 (org-with-remote-undo (marker-buffer marker
)
4748 (with-current-buffer (marker-buffer marker
)
4753 (defun org-agenda-clock-out (&optional arg
)
4754 "Stop the currently running clock."
4756 (unless (marker-buffer org-clock-marker
)
4757 (error "No running clock"))
4758 (org-with-remote-undo (marker-buffer org-clock-marker
)
4761 (defun org-agenda-clock-cancel (&optional arg
)
4762 "Cancel the currently running clock."
4764 (unless (marker-buffer org-clock-marker
)
4765 (error "No running clock"))
4766 (org-with-remote-undo (marker-buffer org-clock-marker
)
4767 (org-clock-cancel)))
4769 (defun org-agenda-diary-entry ()
4770 "Make a diary entry, like the `i' command from the calendar.
4771 All the standard commands work: block, weekly etc."
4773 (org-agenda-check-type t
'agenda
'timeline
)
4774 (require 'diary-lib
)
4776 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
4777 (read-char-exclusive)))
4778 (cmd (cdr (assoc char
4779 '((?d . insert-diary-entry
)
4780 (?w . insert-weekly-diary-entry
)
4781 (?m . insert-monthly-diary-entry
)
4782 (?y . insert-yearly-diary-entry
)
4783 (?a . insert-anniversary-diary-entry
)
4784 (?b . insert-block-diary-entry
)
4785 (?c . insert-cyclic-diary-entry
)))))
4786 (oldf (symbol-function 'calendar-cursor-to-date
))
4787 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
4789 (mark (or (mark t
) (point))))
4791 (error "No command associated with <%c>" char
))
4792 (unless (and (get-text-property point
'day
)
4793 (or (not (equal ?b char
))
4794 (get-text-property mark
'day
)))
4795 (error "Don't know which date to use for diary entry"))
4796 ;; We implement this by hacking the `calendar-cursor-to-date' function
4797 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
4798 (let ((calendar-mark-ring
4799 (list (calendar-gregorian-from-absolute
4800 (or (get-text-property mark
'day
)
4801 (get-text-property point
'day
))))))
4804 (fset 'calendar-cursor-to-date
4805 (lambda (&optional error
)
4806 (calendar-gregorian-from-absolute
4807 (get-text-property point
'day
))))
4808 (call-interactively cmd
))
4809 (fset 'calendar-cursor-to-date oldf
)))))
4812 (defun org-agenda-execute-calendar-command (cmd)
4813 "Execute a calendar command from the agenda, with the date associated to
4814 the cursor position."
4815 (org-agenda-check-type t
'agenda
'timeline
)
4816 (require 'diary-lib
)
4817 (unless (get-text-property (point) 'day
)
4818 (error "Don't know which date to use for calendar command"))
4819 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
4821 (date (calendar-gregorian-from-absolute
4822 (get-text-property point
'day
)))
4823 ;; the following 2 vars are needed in the calendar
4824 (displayed-month (car date
))
4825 (displayed-year (nth 2 date
)))
4828 (fset 'calendar-cursor-to-date
4829 (lambda (&optional error
)
4830 (calendar-gregorian-from-absolute
4831 (get-text-property point
'day
))))
4832 (call-interactively cmd
))
4833 (fset 'calendar-cursor-to-date oldf
))))
4835 (defun org-agenda-phases-of-moon ()
4836 "Display the phases of the moon for the 3 months around the cursor date."
4838 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
4840 (defun org-agenda-holidays ()
4841 "Display the holidays for the 3 months around the cursor date."
4843 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
4845 (defvar calendar-longitude
)
4846 (defvar calendar-latitude
)
4847 (defvar calendar-location-name
)
4849 (defun org-agenda-sunrise-sunset (arg)
4850 "Display sunrise and sunset for the cursor date.
4851 Latitude and longitude can be specified with the variables
4852 `calendar-latitude' and `calendar-longitude'. When called with prefix
4853 argument, latitude and longitude will be prompted for."
4856 (let ((calendar-longitude (if arg nil calendar-longitude
))
4857 (calendar-latitude (if arg nil calendar-latitude
))
4858 (calendar-location-name
4859 (if arg
"the given coordinates" calendar-location-name
)))
4860 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
4862 (defun org-agenda-goto-calendar ()
4863 "Open the Emacs calendar with the date at the cursor."
4865 (org-agenda-check-type t
'agenda
'timeline
)
4866 (let* ((day (or (get-text-property (point) 'day
)
4867 (error "Don't know which date to open in calendar")))
4868 (date (calendar-gregorian-from-absolute day
))
4869 (calendar-move-hook nil
)
4870 (calendar-view-holidays-initially-flag nil
)
4871 (calendar-view-diary-initially-flag nil
)
4872 (view-calendar-holidays-initially nil
)
4873 (calendar-view-diary-initially-flag nil
)
4874 (calendar-view-holidays-initially-flag nil
)
4875 (view-diary-entries-initially nil
))
4877 (calendar-goto-date date
)))
4880 (defun org-calendar-goto-agenda ()
4881 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
4882 This is a command that has to be installed in `calendar-mode-map'."
4884 (org-agenda-list nil
(calendar-absolute-from-gregorian
4885 (calendar-cursor-to-date))
4888 (defun org-agenda-convert-date ()
4890 (org-agenda-check-type t
'agenda
'timeline
)
4891 (let ((day (get-text-property (point) 'day
))
4894 (error "Don't know which date to convert"))
4895 (setq date
(calendar-gregorian-from-absolute day
))
4897 "Gregorian: " (calendar-date-string date
) "\n"
4898 "ISO: " (calendar-iso-date-string date
) "\n"
4899 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
4900 "Julian: " (calendar-julian-date-string date
) "\n"
4901 "Astron. JD: " (calendar-astro-date-string date
)
4902 " (Julian date number at noon UTC)\n"
4903 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
4904 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
4905 "French: " (calendar-french-date-string date
) "\n"
4906 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
4907 "Mayan: " (calendar-mayan-date-string date
) "\n"
4908 "Coptic: " (calendar-coptic-date-string date
) "\n"
4909 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
4910 "Persian: " (calendar-persian-date-string date
) "\n"
4911 "Chinese: " (calendar-chinese-date-string date
) "\n"))
4912 (with-output-to-temp-buffer "*Dates*"
4914 (if (fboundp 'fit-window-to-buffer
)
4915 (fit-window-to-buffer (get-buffer-window "*Dates*")))))
4918 ;;; Appointment reminders
4920 (defvar appt-time-msg-list
)
4923 (defun org-agenda-to-appt (&optional refresh filter
)
4924 "Activate appointments found in `org-agenda-files'.
4925 With a \\[universal-argument] prefix, refresh the list of
4928 If FILTER is t, interactively prompt the user for a regular
4929 expression, and filter out entries that don't match it.
4931 If FILTER is a string, use this string as a regular expression
4932 for filtering entries out.
4934 FILTER can also be an alist with the car of each cell being
4935 either 'headline or 'category. For example:
4937 '((headline \"IMPORTANT\")
4938 (category \"Work\"))
4940 will only add headlines containing IMPORTANT or headlines
4941 belonging to the \"Work\" category."
4944 (if refresh
(setq appt-time-msg-list nil
))
4946 (setq filter
(read-from-minibuffer "Regexp filter: ")))
4947 (let* ((cnt 0) ; count added events
4948 (org-agenda-new-buffers nil
)
4949 (org-deadline-warning-days 0)
4950 (today (org-date-to-gregorian
4951 (time-to-days (current-time))))
4952 (files (org-agenda-files)) entries file
)
4953 ;; Get all entries which may contain an appt
4954 (while (setq file
(pop files
))
4957 (org-agenda-get-day-entries
4958 file today
:timestamp
:scheduled
:deadline
))))
4959 (setq entries
(delq nil entries
))
4960 ;; Map thru entries and find if we should filter them out
4963 (let* ((evt (org-trim (get-text-property 1 'txt x
)))
4964 (cat (get-text-property 1 'org-category x
))
4965 (tod (get-text-property 1 'time-of-day x
))
4966 (ok (or (null filter
)
4967 (and (stringp filter
) (string-match filter evt
))
4970 (cadr (assoc 'category filter
)) cat
)
4972 (cadr (assoc 'headline filter
)) evt
))))))
4973 ;; FIXME: Shall we remove text-properties for the appt text?
4974 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
4976 (setq tod
(number-to-string tod
)
4977 tod
(when (string-match
4978 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)" tod
)
4979 (concat (match-string 1 tod
) ":"
4980 (match-string 2 tod
))))
4982 (setq cnt
(1+ cnt
))))) entries
)
4983 (org-release-buffers org-agenda-new-buffers
)
4985 (message "No event to add")
4986 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
4988 (provide 'org-agenda
)
4990 ;;; org-agenda.el ends here