1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
38 (declare-function diary-add-to-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" (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 (declare-function org-columns-quit
"org-colview" ())
57 (defvar calendar-mode-map
)
59 ;; Defined somewhere in this file, but used before definition.
60 (defvar org-agenda-buffer-name
)
61 (defvar org-agenda-overriding-header
)
64 (defvar org-agenda-undo-list
)
65 (defvar org-agenda-pending-undo-list
)
66 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
68 (defcustom org-agenda-confirm-kill
1
69 "When set, remote killing from the agenda buffer needs confirmation.
70 When t, a confirmation is always needed. When a number N, confirmation is
71 only needed when the text to be killed contains more than N non-white lines."
74 (const :tag
"Never" nil
)
75 (const :tag
"Always" t
)
76 (integer :tag
"When more than N lines")))
78 (defcustom org-agenda-compact-blocks nil
79 "Non-nil means, make the block agenda more compact.
80 This is done by leaving out unnecessary lines."
84 (defcustom org-agenda-block-separator ?
=
85 "The separator between blocks in the agenda.
86 If this is a string, it will be used as the separator, with a newline added.
87 If it is a character, it will be repeated to fill the window width."
93 (defgroup org-agenda-export nil
94 "Options concerning exporting agenda views in Org-mode."
95 :tag
"Org Agenda Export"
98 (defcustom org-agenda-with-colors t
99 "Non-nil means, use colors in agenda views."
100 :group
'org-agenda-export
103 (defcustom org-agenda-exporter-settings nil
104 "Alist of variable/value pairs that should be active during agenda export.
105 This is a good place to set options for ps-print and for htmlize."
106 :group
'org-agenda-export
110 (sexp :tag
"Value"))))
112 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
113 "Hook run in temporary buffer before writing it to an export file.
114 A useful function is `org-agenda-add-entry-text'."
115 :group
'org-agenda-export
117 :options
'(org-agenda-add-entry-text))
119 (defcustom org-agenda-add-entry-text-maxlines
0
120 "Maximum number of entry text lines to be added to agenda.
121 This is only relevant when `org-agenda-add-entry-text' is part of
122 `org-agenda-before-write-hook', which it is by default.
123 When this is 0, nothing will happen. When it is greater than 0, it
124 specifies the maximum number of lines that will be added for each entry
125 that is listed in the agenda view."
129 (defcustom org-agenda-add-entry-text-descriptive-links t
130 "Non-nil means, export org-links as descriptive links in agenda added text.
131 This variable applies to the text added to the agenda when
132 `org-agenda-add-entry-text-maxlines' is larger than 0.
133 When this variable nil, the URL will (also) be shown."
137 (defcustom org-agenda-export-html-style
""
138 "The style specification for exported HTML Agenda files.
139 If this variable contains a string, it will replace the default <style>
140 section as produced by `htmlize'.
141 Since there are different ways of setting style information, this variable
142 needs to contain the full HTML structure to provide a style, including the
143 surrounding HTML tags. The style specifications should include definitions
144 the fonts used by the agenda, here is an example:
146 <style type=\"text/css\">
147 p { font-weight: normal; color: gray; }
148 .org-agenda-structure {
163 .title { text-align: center; }
164 .todo, .deadline { color: red; }
165 .done { color: green; }
168 or, if you want to keep the style in a file,
170 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
172 As the value of this option simply gets inserted into the HTML <head> header,
173 you can \"misuse\" it to also add other text to the header. However,
174 <style>...</style> is required, if not present the variable will be ignored."
175 :group
'org-agenda-export
176 :group
'org-export-html
179 (defgroup org-agenda-custom-commands nil
180 "Options concerning agenda views in Org-mode."
181 :tag
"Org Agenda Custom Commands"
184 (defconst org-sorting-choice
186 (const time-up
) (const time-down
)
187 (const category-keep
) (const category-up
) (const category-down
)
188 (const tag-down
) (const tag-up
)
189 (const priority-up
) (const priority-down
)
190 (const todo-state-up
) (const todo-state-down
)
191 (const effort-up
) (const effort-down
)
192 (const user-defined-up
) (const user-defined-down
))
195 (defconst org-agenda-custom-commands-local-options
196 `(repeat :tag
"Local settings for this command. Remember to quote values"
197 (choice :tag
"Setting"
198 (list :tag
"Heading for this block"
199 (const org-agenda-overriding-header
)
200 (string :tag
"Headline"))
201 (list :tag
"Files to be searched"
202 (const org-agenda-files
)
204 (const :format
"" quote
)
206 (list :tag
"Sorting strategy"
207 (const org-agenda-sorting-strategy
)
209 (const :format
"" quote
)
211 ,org-sorting-choice
)))
212 (list :tag
"Prefix format"
213 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
215 (list :tag
"Number of days in agenda"
216 (const org-agenda-ndays
)
218 (list :tag
"Fixed starting date"
219 (const org-agenda-start-day
)
220 (string :value
"2007-11-01"))
221 (list :tag
"Start on day of week"
222 (const org-agenda-start-on-weekday
)
224 (const :tag
"Today" nil
)
225 (integer :tag
"Weekday No.")))
226 (list :tag
"Include data from diary"
227 (const org-agenda-include-diary
)
229 (list :tag
"Deadline Warning days"
230 (const org-deadline-warning-days
)
232 (list :tag
"Tags filter preset"
233 (const org-agenda-filter-preset
)
235 (const :format
"" quote
)
237 (string :tag
"+tag or -tag"))))
238 (list :tag
"Standard skipping condition"
239 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
240 (const org-agenda-skip-function
)
242 (const :format
"" quote
)
245 :tag
"Skipping range"
246 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
247 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
248 (repeat :inline t
:tag
"Conditions for skipping"
250 :tag
"Condition type"
251 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
252 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
253 (const :tag
"scheduled" 'scheduled
)
254 (const :tag
"not scheduled" 'notscheduled
)
255 (const :tag
"deadline" 'deadline
)
256 (const :tag
"no deadline" 'notdeadline
)
257 (const :tag
"timestamp" 'timestamp
)
258 (const :tag
"no timestamp" 'nottimestamp
))))))
259 (list :tag
"Non-standard skipping condition"
260 :value
(org-agenda-skip-function)
261 (const org-agenda-skip-function
)
262 (sexp :tag
"Function or form (quoted!)"))
263 (list :tag
"Any variable"
264 (variable :tag
"Variable")
265 (sexp :tag
"Value (sexp)"))))
266 "Selection of examples for agenda command settings.
267 This will be spliced into the custom type of
268 `org-agenda-custom-commands'.")
271 (defcustom org-agenda-custom-commands nil
272 "Custom commands for the agenda.
273 These commands will be offered on the splash screen displayed by the
274 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
276 (key desc type match settings files)
278 key The key (one or more characters as a string) to be associated
280 desc A description of the command, when omitted or nil, a default
281 description is built using MATCH.
282 type The command type, any of the following symbols:
283 agenda The daily/weekly agenda.
284 todo Entries with a specific TODO keyword, in all agenda files.
285 search Entries containing search words entry or headline.
286 tags Tags/Property/TODO match in all agenda files.
287 tags-todo Tags/P/T match in all agenda files, TODO entries only.
288 todo-tree Sparse tree of specific TODO keyword in *current* file.
289 tags-tree Sparse tree with all tags matches in *current* file.
290 occur-tree Occur sparse tree for *current* file.
291 ... A user-defined function.
292 match What to search for:
293 - a single keyword for TODO keyword searches
294 - a tags match expression for tags searches
295 - a word search expression for text searches.
296 - a regular expression for occur searches
297 For all other commands, this should be the empty string.
298 settings A list of option settings, similar to that in a let form, so like
299 this: ((opt1 val1) (opt2 val2) ...). The values will be
300 evaluated at the moment of execution, so quote them when needed.
301 files A list of files file to write the produced agenda buffer to
302 with the command `org-store-agenda-views'.
303 If a file name ends in \".html\", an HTML version of the buffer
304 is written out. If it ends in \".ps\", a postscript version is
305 produced. Otherwise, only the plain text is written to the file.
307 You can also define a set of commands, to create a composite agenda buffer.
308 In this case, an entry looks like this:
310 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
314 desc A description string to be displayed in the dispatcher menu.
315 cmd An agenda command, similar to the above. However, tree commands
316 are no allowed, but instead you can get agenda and global todo list.
317 So valid commands for a set are:
318 (agenda \"\" settings)
319 (alltodo \"\" settings)
320 (stuck \"\" settings)
321 (todo \"match\" settings files)
322 (search \"match\" settings files)
323 (tags \"match\" settings files)
324 (tags-todo \"match\" settings files)
326 Each command can carry a list of options, and another set of options can be
327 given for the whole set of commands. Individual command options take
328 precedence over the general options.
330 When using several characters as key to a command, the first characters
331 are prefix commands. For the dispatcher to display useful information, you
332 should provide a description for the prefix, like
334 (setq org-agenda-custom-commands
335 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
336 (\"hl\" tags \"+HOME+Lisa\")
337 (\"hp\" tags \"+HOME+Peter\")
338 (\"hk\" tags \"+HOME+Kim\")))"
339 :group
'org-agenda-custom-commands
341 (choice :value
("x" "Describe command here" tags
"" nil
)
342 (list :tag
"Single command"
343 (string :tag
"Access Key(s) ")
344 (option (string :tag
"Description"))
346 (const :tag
"Agenda" agenda
)
347 (const :tag
"TODO list" alltodo
)
348 (const :tag
"Search words" search
)
349 (const :tag
"Stuck projects" stuck
)
350 (const :tag
"Tags/Property match (all agenda files)" tags
)
351 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
352 (const :tag
"TODO keyword search (all agenda files)" todo
)
353 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
354 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
355 (const :tag
"Occur tree (current buffer)" occur-tree
)
356 (sexp :tag
"Other, user-defined function"))
357 (string :tag
"Match (only for some commands)")
358 ,org-agenda-custom-commands-local-options
359 (option (repeat :tag
"Export" (file :tag
"Export to"))))
360 (list :tag
"Command series, all agenda files"
361 (string :tag
"Access Key(s)")
362 (string :tag
"Description ")
363 (repeat :tag
"Component"
366 (const :format
"" agenda
)
367 (const :tag
"" :format
"" "")
368 ,org-agenda-custom-commands-local-options
)
369 (list :tag
"TODO list (all keywords)"
370 (const :format
"" alltodo
)
371 (const :tag
"" :format
"" "")
372 ,org-agenda-custom-commands-local-options
)
373 (list :tag
"Search words"
374 (const :format
"" search
)
375 (string :tag
"Match")
376 ,org-agenda-custom-commands-local-options
)
377 (list :tag
"Stuck projects"
378 (const :format
"" stuck
)
379 (const :tag
"" :format
"" "")
380 ,org-agenda-custom-commands-local-options
)
381 (list :tag
"Tags search"
382 (const :format
"" tags
)
383 (string :tag
"Match")
384 ,org-agenda-custom-commands-local-options
)
385 (list :tag
"Tags search, TODO entries only"
386 (const :format
"" tags-todo
)
387 (string :tag
"Match")
388 ,org-agenda-custom-commands-local-options
)
389 (list :tag
"TODO keyword search"
390 (const :format
"" todo
)
391 (string :tag
"Match")
392 ,org-agenda-custom-commands-local-options
)
393 (list :tag
"Other, user-defined function"
394 (symbol :tag
"function")
395 (string :tag
"Match")
396 ,org-agenda-custom-commands-local-options
)))
398 (repeat :tag
"Settings for entire command set"
399 (list (variable :tag
"Any variable")
400 (sexp :tag
"Value")))
401 (option (repeat :tag
"Export" (file :tag
"Export to"))))
402 (cons :tag
"Prefix key documentation"
403 (string :tag
"Access Key(s)")
404 (string :tag
"Description ")))))
406 (defcustom org-agenda-query-register ?o
407 "The register holding the current query string.
408 The purpose of this is that if you construct a query string interactively,
409 you can then use it to define a custom command."
410 :group
'org-agenda-custom-commands
413 (defcustom org-stuck-projects
414 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
415 "How to identify stuck projects.
416 This is a list of four items:
417 1. A tags/todo/property matcher string that is used to identify a project.
418 See the manual for a description of tag and property searches.
419 The entire tree below a headline matched by this is considered one project.
420 2. A list of TODO keywords identifying non-stuck projects.
421 If the project subtree contains any headline with one of these todo
422 keywords, the project is considered to be not stuck. If you specify
423 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
424 3. A list of tags identifying non-stuck projects.
425 If the project subtree contains any headline with one of these tags,
426 the project is considered to be not stuck. If you specify \"*\" as
427 a tag, any tag will mark the project unstuck. Note that this is about
428 the explicit presence of a tag somewhere in the subtree, inherited
429 tags to not count here. If inherited tags make a project not stuck,
430 use \"-TAG\" in the tags part of the matcher under (1.) above.
431 4. An arbitrary regular expression matching non-stuck projects.
433 If the project turns out to be not stuck, search continues also in the
434 subtree to see if any of the subtasks have project status.
436 See also the variable `org-tags-match-list-sublevels' which applies
437 to projects matched by this search as well.
439 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
440 or `C-c a #' to produce the list."
441 :group
'org-agenda-custom-commands
443 (string :tag
"Tags/TODO match to identify a project")
444 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
445 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
446 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
448 (defcustom org-agenda-filter-effort-default-operator
"<"
449 "The default operator for effort estimate filtering.
450 If you select an effort estimate limit without first pressing an operator,
451 this one will be used."
452 :group
'org-agenda-custom-commands
453 :type
'(choice (const :tag
"less or equal" "<")
454 (const :tag
"greater or equal"">")
455 (const :tag
"equal" "=")))
457 (defgroup org-agenda-skip nil
458 "Options concerning skipping parts of agenda files."
459 :tag
"Org Agenda Skip"
461 (defgroup org-agenda-daily
/weekly nil
462 "Options concerning the daily/weekly agenda."
463 :tag
"Org Agenda Daily/Weekly"
465 (defgroup org-agenda-todo-list nil
466 "Options concerning the global todo list agenda view."
467 :tag
"Org Agenda Todo List"
469 (defgroup org-agenda-match-view nil
470 "Options concerning the general tags/property/todo match agenda view."
471 :tag
"Org Agenda Match View"
474 (defvar org-agenda-archives-mode nil
475 "Non-nil means, the agenda will include archived items.
476 If this is the symbol `trees', trees in the selected agenda scope
477 that are marked with the ARCHIVE tag will be included anyway. When this is
478 t, also all archive files associated with the current selection of agenda
479 files will be included.")
481 (defcustom org-agenda-skip-comment-trees t
482 "Non-nil means, skip trees that start with the COMMENT keyword.
483 When nil, these trees are also scanned by agenda commands."
484 :group
'org-agenda-skip
487 (defcustom org-agenda-todo-list-sublevels t
488 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
489 When nil, the sublevels of a TODO entry are not checked, resulting in
490 potentially much shorter TODO lists."
491 :group
'org-agenda-skip
492 :group
'org-agenda-todo-list
495 (defcustom org-agenda-todo-ignore-with-date nil
496 "Non-nil means, don't show entries with a date in the global todo list.
497 You can use this if you prefer to mark mere appointments with a TODO keyword,
498 but don't want them to show up in the TODO list.
499 When this is set, it also covers deadlines and scheduled items, the settings
500 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
502 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
503 :group
'org-agenda-skip
504 :group
'org-agenda-todo-list
507 (defcustom org-agenda-todo-ignore-scheduled nil
508 "Non-nil means, don't show scheduled entries in the global todo list.
509 The idea behind this is that by scheduling it, you have already taken care
511 See also `org-agenda-todo-ignore-with-date'.
512 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
513 :group
'org-agenda-skip
514 :group
'org-agenda-todo-list
517 (defcustom org-agenda-todo-ignore-deadlines nil
518 "Non-nil means, don't show near deadline entries in the global todo list.
519 Near means closer than `org-deadline-warning-days' days.
520 The idea behind this is that such items will appear in the agenda anyway.
521 See also `org-agenda-todo-ignore-with-date'.
522 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
523 :group
'org-agenda-skip
524 :group
'org-agenda-todo-list
527 (defcustom org-agenda-tags-todo-honor-ignore-options nil
528 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
530 `org-agenda-todo-ignore-with-date',
531 `org-agenda-todo-ignore-scheduled'
532 `org-agenda-todo-ignore-deadlines'
533 make the global TODO list skip entries that have time stamps of certain
534 kinds. If this option is set, the same options will also apply for the
535 tags-todo search, which is the general tags/property matcher
536 restricted to unfinished TODO entries only."
537 :group
'org-agenda-skip
538 :group
'org-agenda-todo-list
539 :group
'org-agenda-match-view
542 (defcustom org-agenda-skip-scheduled-if-done nil
543 "Non-nil means don't show scheduled items in agenda when they are done.
544 This is relevant for the daily/weekly agenda, not for the TODO list. And
545 it applies only to the actual date of the scheduling. Warnings about
546 an item with a past scheduling dates are always turned off when the item
548 :group
'org-agenda-skip
549 :group
'org-agenda-daily
/weekly
552 (defcustom org-agenda-skip-deadline-if-done nil
553 "Non-nil means don't show deadlines when the corresponding item is done.
554 When nil, the deadline is still shown and should give you a happy feeling.
555 This is relevant for the daily/weekly agenda. And it applied only to the
556 actually date of the deadline. Warnings about approaching and past-due
557 deadlines are always turned off when the item is DONE."
558 :group
'org-agenda-skip
559 :group
'org-agenda-daily
/weekly
562 (defcustom org-agenda-skip-additional-timestamps-same-entry t
563 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
564 When non-nil, after the search for timestamps has matched once in an
565 entry, the rest of the entry will not be searched."
566 :group
'org-agenda-skip
569 (defcustom org-agenda-skip-timestamp-if-done nil
570 "Non-nil means don't select item by timestamp or -range if it is DONE."
571 :group
'org-agenda-skip
572 :group
'org-agenda-daily
/weekly
575 (defcustom org-agenda-dim-blocked-tasks t
576 "Non-nil means, dim blocked tasks in the agenda display.
577 This causes some overhead during agenda construction, but if you
578 have turned on `org-enforce-todo-dependencies',
579 `org-enforce-todo-checkbox-dependencies', or any other blocking
580 mechanism, this will create useful feedback in the agenda.
582 Instead ot t, this variable can also have the value `invisible'.
583 Then blocked tasks will be invisible and only become visible when
584 they become unblocked. An exemption to this behavior is when a task is
585 blocked because of unchecked checkboxes below it. Since checkboxes do
586 not show up in the agenda views, making this task invisible you remove any
587 trace from agenda views that there is something to do. Therefore, a task
588 that is blocked because of checkboxes will never be made invisible, it
589 will only be dimmed."
590 :group
'org-agenda-daily
/weekly
591 :group
'org-agenda-todo-list
593 (const :tag
"Do not dim" nil
)
594 (const :tag
"Dim to a grey face" t
)
595 (const :tag
"Make invisibe" invisible
)))
597 (defcustom org-timeline-show-empty-dates
3
598 "Non-nil means, `org-timeline' also shows dates without an entry.
599 When nil, only the days which actually have entries are shown.
600 When t, all days between the first and the last date are shown.
601 When an integer, show also empty dates, but if there is a gap of more than
602 N days, just insert a special line indicating the size of the gap."
603 :group
'org-agenda-skip
605 (const :tag
"None" nil
)
607 (integer :tag
"at most")))
609 (defgroup org-agenda-startup nil
610 "Options concerning initial settings in the Agenda in Org Mode."
611 :tag
"Org Agenda Startup"
614 (defcustom org-finalize-agenda-hook nil
615 "Hook run just before displaying an agenda buffer."
616 :group
'org-agenda-startup
619 (defcustom org-agenda-mouse-1-follows-link nil
620 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
621 A longer mouse click will still set point. Does not work on XEmacs.
622 Needs to be set before org.el is loaded."
623 :group
'org-agenda-startup
626 (defcustom org-agenda-start-with-follow-mode nil
627 "The initial value of follow-mode in a newly created agenda window."
628 :group
'org-agenda-startup
631 (defvar org-agenda-include-inactive-timestamps nil
632 "Non-nil means, include inactive time stamps in agenda and timeline.")
634 (defgroup org-agenda-windows nil
635 "Options concerning the windows used by the Agenda in Org Mode."
636 :tag
"Org Agenda Windows"
639 (defcustom org-agenda-window-setup
'reorganize-frame
640 "How the agenda buffer should be displayed.
641 Possible values for this option are:
643 current-window Show agenda in the current window, keeping all other windows.
644 other-frame Use `switch-to-buffer-other-frame' to display agenda.
645 other-window Use `switch-to-buffer-other-window' to display agenda.
646 reorganize-frame Show only two windows on the current frame, the current
647 window and the agenda.
648 See also the variable `org-agenda-restore-windows-after-quit'."
649 :group
'org-agenda-windows
651 (const current-window
)
654 (const reorganize-frame
)))
656 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
657 "The min and max height of the agenda window as a fraction of frame height.
658 The value of the variable is a cons cell with two numbers between 0 and 1.
659 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
660 :group
'org-agenda-windows
661 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
663 (defcustom org-agenda-restore-windows-after-quit nil
664 "Non-nil means, restore window configuration open exiting agenda.
665 Before the window configuration is changed for displaying the agenda,
666 the current status is recorded. When the agenda is exited with
667 `q' or `x' and this option is set, the old state is restored. If
668 `org-agenda-window-setup' is `other-frame', the value of this
669 option will be ignored.."
670 :group
'org-agenda-windows
673 (defcustom org-agenda-ndays
7
674 "Number of days to include in overview display.
676 Custom commands can set this variable in the options section."
677 :group
'org-agenda-daily
/weekly
680 (defcustom org-agenda-start-on-weekday
1
681 "Non-nil means, start the overview always on the specified weekday.
682 0 denotes Sunday, 1 denotes Monday etc.
683 When nil, always start on the current day.
684 Custom commands can set this variable in the options section."
685 :group
'org-agenda-daily
/weekly
686 :type
'(choice (const :tag
"Today" nil
)
687 (integer :tag
"Weekday No.")))
689 (defcustom org-agenda-show-all-dates t
690 "Non-nil means, `org-agenda' shows every day in the selected range.
691 When nil, only the days which actually have entries are shown."
692 :group
'org-agenda-daily
/weekly
695 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
696 "Format string for displaying dates in the agenda.
697 Used by the daily/weekly agenda and by the timeline. This should be
698 a format string understood by `format-time-string', or a function returning
699 the formatted date as a string. The function must take a single argument,
700 a calendar-style date list like (month day year)."
701 :group
'org-agenda-daily
/weekly
703 (string :tag
"Format string")
704 (function :tag
"Function")))
706 (defun org-agenda-format-date-aligned (date)
707 "Format a date string for display in the daily/weekly agenda, or timeline.
708 This function makes sure that dates are aligned for easy reading."
710 (let* ((dayname (calendar-day-name date
))
712 (day-of-week (calendar-day-of-week date
))
714 (monthname (calendar-month-name month
))
716 (iso-week (org-days-to-iso-week
717 (calendar-absolute-from-gregorian date
)))
718 (weekyear (cond ((and (= month
1) (>= iso-week
52))
720 ((and (= month
12) (<= iso-week
1))
723 (weekstring (if (= day-of-week
1)
724 (format " W%02d" iso-week
)
726 (format "%-10s %2d %s %4d%s"
727 dayname day monthname year weekstring
)))
729 (defcustom org-agenda-weekend-days
'(6 0)
730 "Which days are weekend?
731 These days get the special face `org-agenda-date-weekend' in the agenda
732 and timeline buffers."
733 :group
'org-agenda-daily
/weekly
734 :type
'(set :greedy t
735 (const :tag
"Monday" 1)
736 (const :tag
"Tuesday" 2)
737 (const :tag
"Wednesday" 3)
738 (const :tag
"Thursday" 4)
739 (const :tag
"Friday" 5)
740 (const :tag
"Saturday" 6)
741 (const :tag
"Sunday" 0)))
743 (defcustom org-agenda-include-diary nil
744 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
745 Custom commands can set this variable in the options section."
746 :group
'org-agenda-daily
/weekly
749 (defcustom org-agenda-include-all-todo nil
750 "Set means weekly/daily agenda will always contain all TODO entries.
751 The TODO entries will be listed at the top of the agenda, before
752 the entries for specific days.
753 This option is deprecated, it is better to define a block agenda instead."
754 :group
'org-agenda-daily
/weekly
757 (defcustom org-agenda-repeating-timestamp-show-all t
758 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
759 When nil, only one occurrence is shown, either today or the
760 nearest into the future."
761 :group
'org-agenda-daily
/weekly
764 (defcustom org-scheduled-past-days
10000
765 "No. of days to continue listing scheduled items that are not marked DONE.
766 When an item is scheduled on a date, it shows up in the agenda on this
767 day and will be listed until it is marked done for the number of days
769 :group
'org-agenda-daily
/weekly
772 (defcustom org-agenda-log-mode-items
'(closed clock
)
773 "List of items that should be shown in agenda log mode.
774 This list may contain the following symbols:
776 closed Show entries that have been closed on that day.
777 clock Show entries that have received clocked time on that day.
778 state Show all logged state changes.
779 Note that instead of changing this variable, you can also press `C-u l' in
780 the agenda to display all available LOG items temporarily."
781 :group
'org-agenda-daily
/weekly
782 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
784 (defcustom org-agenda-log-mode-add-notes t
785 "Non-nil means, add first line of notes to log entries in agenda views.
786 If a log item like a state change or a clock entry is associated with
787 notes, the first line of these notes will be added to the entry in the
789 :group
'org-agenda-daily
/weekly
792 (defcustom org-agenda-start-with-log-mode nil
793 "The initial value of log-mode in a newly created agenda window."
794 :group
'org-agenda-startup
795 :group
'org-agenda-daily
/weekly
798 (defcustom org-agenda-start-with-clockreport-mode nil
799 "The initial value of clockreport-mode in a newly created agenda window."
800 :group
'org-agenda-startup
801 :group
'org-agenda-daily
/weekly
804 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
805 "Property list with parameters for the clocktable in clockreport mode.
806 This is the display mode that shows a clock table in the daily/weekly
807 agenda, the properties for this dynamic block can be set here.
808 The usual clocktable parameters are allowed here, but you cannot set
809 the properties :name, :tstart, :tend, :block, and :scope - these will
810 be overwritten to make sure the content accurately reflects the
811 current display in the agenda."
812 :group
'org-agenda-daily
/weekly
816 (defgroup org-agenda-time-grid nil
817 "Options concerning the time grid in the Org-mode Agenda."
818 :tag
"Org Agenda Time Grid"
821 (defcustom org-agenda-search-headline-for-time t
822 "Non-nil means, search headline for a time-of-day.
823 If the headline contains a time-of-day in one format or another, it will
824 be used to sort the entry into the time sequence of items for a day.
825 Some people have time stamps in the headline that refer to the creation
826 time or so, and then this produces an unwanted side effect. If this is
827 the case for your, use this variable to turn off searching the headline
829 :group
'org-agenda-time-grid
832 (defcustom org-agenda-use-time-grid t
833 "Non-nil means, show a time grid in the agenda schedule.
834 A time grid is a set of lines for specific times (like every two hours between
835 8:00 and 20:00). The items scheduled for a day at specific times are
836 sorted in between these lines.
837 For details about when the grid will be shown, and what it will look like, see
838 the variable `org-agenda-time-grid'."
839 :group
'org-agenda-time-grid
842 (defcustom org-agenda-time-grid
843 '((daily today require-timed
)
845 (800 1000 1200 1400 1600 1800 2000))
847 "The settings for time grid for agenda display.
848 This is a list of three items. The first item is again a list. It contains
849 symbols specifying conditions when the grid should be displayed:
851 daily if the agenda shows a single day
852 weekly if the agenda shows an entire week
853 today show grid on current date, independent of daily/weekly display
854 require-timed show grid only if at least one item has a time specification
856 The second item is a string which will be placed behind the grid time.
858 The third item is a list of integers, indicating the times that should have
860 :group
'org-agenda-time-grid
863 (set :greedy t
:tag
"Grid Display Options"
864 (const :tag
"Show grid in single day agenda display" daily
)
865 (const :tag
"Show grid in weekly agenda display" weekly
)
866 (const :tag
"Always show grid for today" today
)
867 (const :tag
"Show grid only if any timed entries are present"
869 (const :tag
"Skip grid times already present in an entry"
871 (string :tag
"Grid String")
872 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
874 (defgroup org-agenda-sorting nil
875 "Options concerning sorting in the Org-mode Agenda."
876 :tag
"Org Agenda Sorting"
879 (defcustom org-agenda-sorting-strategy
880 '((agenda time-up priority-down category-keep
)
881 (todo priority-down category-keep
)
882 (tags priority-down category-keep
)
883 (search category-keep
))
884 "Sorting structure for the agenda items of a single day.
885 This is a list of symbols which will be used in sequence to determine
886 if an entry should be listed before another entry. The following
887 symbols are recognized:
889 time-up Put entries with time-of-day indications first, early first
890 time-down Put entries with time-of-day indications first, late first
891 category-keep Keep the default order of categories, corresponding to the
892 sequence in `org-agenda-files'.
893 category-up Sort alphabetically by category, A-Z.
894 category-down Sort alphabetically by category, Z-A.
895 tag-up Sort alphabetically by last tag, A-Z.
896 tag-down Sort alphabetically by last tag, Z-A.
897 priority-up Sort numerically by priority, high priority last.
898 priority-down Sort numerically by priority, high priority first.
899 todo-state-up Sort by todo state, tasks that are done last.
900 todo-state-down Sort by todo state, tasks that are done first.
901 effort-up Sort numerically by estimated effort, high effort last.
902 effort-down Sort numerically by estimated effort, high effort first.
903 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
904 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
906 The different possibilities will be tried in sequence, and testing stops
907 if one comparison returns a \"not-equal\". For example, the default
908 '(time-up category-keep priority-down)
909 means: Pull out all entries having a specified time of day and sort them,
910 in order to make a time schedule for the current day the first thing in the
911 agenda listing for the day. Of the entries without a time indication, keep
912 the grouped in categories, don't sort the categories, but keep them in
913 the sequence given in `org-agenda-files'. Within each category sort by
916 Leaving out `category-keep' would mean that items will be sorted across
917 categories by priority.
919 Instead of a single list, this can also be a set of list for specific
920 contents, with a context symbol in the car of the list, any of
921 `agenda', `todo', `tags' for the corresponding agenda views.
923 Custom commands can bind this variable in the options section."
924 :group
'org-agenda-sorting
926 (repeat :tag
"General" ,org-sorting-choice
)
927 (list :tag
"Individually"
928 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
929 (repeat ,org-sorting-choice
))
930 (cons (const :tag
"Strategy for TODO lists" todo
)
931 (repeat ,org-sorting-choice
))
932 (cons (const :tag
"Strategy for Tags matches" tags
)
933 (repeat ,org-sorting-choice
)))))
935 (defcustom org-agenda-cmp-user-defined nil
936 "A function to define the comparison `user-defined'.
937 This function must receive two arguments, agenda entry a and b.
938 If a>b, return +1. If a<b, return -1. If they are equal as seen by
939 the user comparison, return nil.
940 When this is defined, you can make `user-defined-up' and `user-defined-down'
941 part of an agenda sorting strategy."
942 :group
'org-agenda-sorting
945 (defcustom org-sort-agenda-notime-is-late t
946 "Non-nil means, items without time are considered late.
947 This is only relevant for sorting. When t, items which have no explicit
948 time like 15:30 will be considered as 99:01, i.e. later than any items which
949 do have a time. When nil, the default time is before 0:00. You can use this
950 option to decide if the schedule for today should come before or after timeless
952 :group
'org-agenda-sorting
955 (defcustom org-sort-agenda-noeffort-is-high t
956 "Non-nil means, items without effort estimate are sorted as high effort.
957 This also applies when filtering an agenda view with respect to the
958 < or > effort operator. Then, tasks with no effort defined will be treated
959 as tasks with high effort.
960 When nil, such items are sorted as 0 minutes effort."
961 :group
'org-agenda-sorting
964 (defgroup org-agenda-line-format nil
965 "Options concerning the entry prefix in the Org-mode agenda display."
966 :tag
"Org Agenda Line Format"
969 (defcustom org-agenda-prefix-format
970 '((agenda .
" %-12:c%?-12t% s")
974 (search .
" %-12:c"))
975 "Format specifications for the prefix of items in the agenda views.
976 An alist with four entries, for the different agenda types. The keys to the
977 sublists are `agenda', `timeline', `todo', and `tags'. The values
979 This format works similar to a printf format, with the following meaning:
981 %c the category of the item, \"Diary\" for entries from the diary, or
982 as given by the CATEGORY keyword or derived from the file name.
983 %T the *last* tag of the item. Last because inherited tags come
985 %t the time-of-day specification if one applies to the entry, in the
987 %s Scheduling/Deadline information, a short string
989 All specifiers work basically like the standard `%s' of printf, but may
990 contain two additional characters: A question mark just after the `%' and
991 a whitespace/punctuation character just before the final letter.
993 If the first character after `%' is a question mark, the entire field
994 will only be included if the corresponding value applies to the
995 current entry. This is useful for fields which should have fixed
996 width when present, but zero width when absent. For example,
997 \"%?-12t\" will result in a 12 character time field if a time of the
998 day is specified, but will completely disappear in entries which do
1001 If there is punctuation or whitespace character just before the final
1002 format letter, this character will be appended to the field value if
1003 the value is not empty. For example, the format \"%-12:c\" leads to
1004 \"Diary: \" if the category is \"Diary\". If the category were be
1005 empty, no additional colon would be interted.
1007 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1008 - Indent the line with two space characters
1009 - Give the category in a 12 chars wide field, padded with whitespace on
1010 the right (because of `-'). Append a colon if there is a category
1012 - If there is a time-of-day, put it into a 12 chars wide field. If no
1013 time, don't put in an empty field, just skip it (because of '?').
1014 - Finally, put the scheduling information and append a whitespace.
1016 As another example, if you don't want the time-of-day of entries in
1017 the prefix, you could use:
1019 (setq org-agenda-prefix-format \" %-11:c% s\")
1021 See also the variables `org-agenda-remove-times-when-in-prefix' and
1022 `org-agenda-remove-tags'.
1024 Custom commands can set this variable in the options section."
1026 (string :tag
"General format")
1027 (list :greedy t
:tag
"View dependent"
1028 (cons (const agenda
) (string :tag
"Format"))
1029 (cons (const timeline
) (string :tag
"Format"))
1030 (cons (const todo
) (string :tag
"Format"))
1031 (cons (const tags
) (string :tag
"Format"))
1032 (cons (const search
) (string :tag
"Format"))))
1033 :group
'org-agenda-line-format
)
1035 (defvar org-prefix-format-compiled nil
1036 "The compiled version of the most recently used prefix format.
1037 See the variable `org-agenda-prefix-format'.")
1039 (defcustom org-agenda-todo-keyword-format
"%-1s"
1040 "Format for the TODO keyword in agenda lines.
1041 Set this to something like \"%-12s\" if you want all TODO keywords
1042 to occupy a fixed space in the agenda display."
1043 :group
'org-agenda-line-format
1046 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1047 "Text preceding timerange entries in the agenda view.
1048 This is a list with two strings. The first applies when the range
1049 is entirely on one day. The second applies if the range spans several days.
1050 The strings may have two \"%d\" format specifiers which will be filled
1051 with the sequence number of the days, and the total number of days in the
1052 range, respectively."
1053 :group
'org-agenda-line-format
1055 (string :tag
"Deadline today ")
1056 (choice :tag
"Deadline relative"
1057 (string :tag
"Format string")
1060 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1061 "Text preceeding scheduled items in the agenda view.
1062 This is a list with two strings. The first applies when the item is
1063 scheduled on the current day. The second applies when it has been scheduled
1064 previously, it may contain a %d indicating that this is the nth time that
1065 this item is scheduled, due to automatic rescheduling of unfinished items
1066 for the following day. So this number is one larger than the number of days
1067 that passed since this item was scheduled first."
1068 :group
'org-agenda-line-format
1070 (string :tag
"Scheduled today ")
1071 (string :tag
"Scheduled previously")))
1073 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1074 "Text preceeding deadline items in the agenda view.
1075 This is a list with two strings. The first applies when the item has its
1076 deadline on the current day. The second applies when it is in the past or
1077 in the future, it may contain %d to capture how many days away the deadline
1079 :group
'org-agenda-line-format
1081 (string :tag
"Deadline today ")
1082 (choice :tag
"Deadline relative"
1083 (string :tag
"Format string")
1086 (defcustom org-agenda-remove-times-when-in-prefix t
1087 "Non-nil means, remove duplicate time specifications in agenda items.
1088 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1089 time-of-day specification in a headline or diary entry is extracted and
1090 placed into the prefix. If this option is non-nil, the original specification
1091 \(a timestamp or -range, or just a plain time(range) specification like
1092 11:30-4pm) will be removed for agenda display. This makes the agenda less
1094 The option can be t or nil. It may also be the symbol `beg', indicating
1095 that the time should only be removed what it is located at the beginning of
1096 the headline/diary entry."
1097 :group
'org-agenda-line-format
1099 (const :tag
"Always" t
)
1100 (const :tag
"Never" nil
)
1101 (const :tag
"When at beginning of entry" beg
)))
1104 (defcustom org-agenda-default-appointment-duration nil
1105 "Default duration for appointments that only have a starting time.
1106 When nil, no duration is specified in such cases.
1107 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1108 :group
'org-agenda-line-format
1110 (integer :tag
"Minutes")
1111 (const :tag
"No default duration")))
1113 (defcustom org-agenda-show-inherited-tags t
1114 "Non-nil means, show inherited tags in each agenda line."
1115 :group
'org-agenda-line-format
1118 (defcustom org-agenda-remove-tags nil
1119 "Non-nil means, remove the tags from the headline copy in the agenda.
1120 When this is the symbol `prefix', only remove tags when
1121 `org-agenda-prefix-format' contains a `%T' specifier."
1122 :group
'org-agenda-line-format
1124 (const :tag
"Always" t
)
1125 (const :tag
"Never" nil
)
1126 (const :tag
"When prefix format contains %T" prefix
)))
1128 (if (fboundp 'defvaralias
)
1129 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1130 'org-agenda-remove-tags
))
1132 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1133 "Shift tags in agenda items to this column.
1134 If this number is positive, it specifies the column. If it is negative,
1135 it means that the tags should be flushright to that column. For example,
1136 -80 works well for a normal 80 character screen."
1137 :group
'org-agenda-line-format
1140 (if (fboundp 'defvaralias
)
1141 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1143 (defcustom org-agenda-fontify-priorities
'cookies
1144 "Non-nil means, highlight low and high priorities in agenda.
1145 When t, the highest priority entries are bold, lowest priority italic.
1146 However, settings in org-priority-faces will overrule these faces.
1147 When this variable is the symbol `cookies', only fontify the
1148 cookies, not the entire task.
1149 This may also be an association list of priority faces, whose
1150 keys are the character values of `org-highest-priority',
1151 `org-default-priority', and `org-lowest-priority' (the default values
1152 are ?A, ?B, and ?C, respectively). The face may be a named face,
1153 or a list like `(:background \"Red\")'."
1154 :group
'org-agenda-line-format
1156 (const :tag
"Never" nil
)
1157 (const :tag
"Defaults" t
)
1158 (const :tag
"Cookies only" cookies
)
1159 (repeat :tag
"Specify"
1160 (list (character :tag
"Priority" :value ?A
)
1161 (sexp :tag
"face")))))
1163 (defgroup org-agenda-column-view nil
1164 "Options concerning column view in the agenda."
1165 :tag
"Org Agenda Column View"
1168 (defcustom org-agenda-columns-show-summaries t
1169 "Non-nil means, show summaries for columns displayed in the agenda view."
1170 :group
'org-agenda-column-view
1173 (defcustom org-agenda-columns-remove-prefix-from-item t
1174 "Non-nil means, remove the prefix from a headline for agenda column view.
1175 The special ITEM field in the columns format contains the current line, with
1176 all information shown in other columns (like the TODO state or a tag).
1177 When this variable is non-nil, also the agenda prefix will be removed from
1178 the content of the ITEM field, to make sure as much as possible of the
1179 headline can be shown in the limited width of the field."
1183 (defcustom org-agenda-columns-compute-summary-properties t
1184 "Non-nil means, recompute all summary properties before column view.
1185 When column view in the agenda is listing properties that have a summary
1186 operator, it can go to all relevant buffers and recompute the summaries
1187 there. This can mean overhead for the agenda column view, but is necessary
1188 to have thing up to date.
1189 As a special case, a CLOCKSUM property also makes sure that the clock
1190 computations are current."
1191 :group
'org-agenda-column-view
1194 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1195 "Non-nil means, the duration of an appointment will add to day effort.
1196 The property to which appointment durations will be added is the one given
1197 in the option `org-effort-property'. If an appointment does not have
1198 an end time, `org-agenda-default-appointment-duration' will be used. If that
1199 is not set, an appointment without end time will not contribute to the time
1201 :group
'org-agenda-column-view
1208 (defun org-add-agenda-custom-command (entry)
1209 "Replace or add a command in `org-agenda-custom-commands'.
1210 This is mostly for hacking and trying a new command - once the command
1211 works you probably want to add it to `org-agenda-custom-commands' for good."
1212 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1214 (setcdr ass
(cdr entry
))
1215 (push entry org-agenda-custom-commands
))))
1217 ;;; Define the Org-agenda-mode
1219 (defvar org-agenda-mode-map
(make-sparse-keymap)
1220 "Keymap for `org-agenda-mode'.")
1222 (defvar org-agenda-menu
) ; defined later in this file.
1223 (defvar org-agenda-restrict
) ; defined later in this file.
1224 (defvar org-agenda-follow-mode nil
)
1225 (defvar org-agenda-clockreport-mode nil
)
1226 (defvar org-agenda-show-log nil
)
1227 (defvar org-agenda-redo-command nil
)
1228 (defvar org-agenda-query-string nil
)
1229 (defvar org-agenda-mode-hook nil
1230 "Hook for org-agenda-mode, run after the mode is turned on.")
1231 (defvar org-agenda-type nil
)
1232 (defvar org-agenda-force-single-file nil
)
1234 (defun org-agenda-mode ()
1235 "Mode for time-sorted view on action items in Org-mode files.
1237 The following commands are available:
1239 \\{org-agenda-mode-map}"
1241 (kill-all-local-variables)
1242 (setq org-agenda-undo-list nil
1243 org-agenda-pending-undo-list nil
)
1244 (setq major-mode
'org-agenda-mode
)
1245 ;; Keep global-font-lock-mode from turning on font-lock-mode
1246 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1247 (setq mode-name
"Org-Agenda")
1248 (use-local-map org-agenda-mode-map
)
1249 (easy-menu-add org-agenda-menu
)
1250 (if org-startup-truncated
(setq truncate-lines t
))
1251 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1252 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1253 ;; Make sure properties are removed when copying text
1254 (when (boundp 'buffer-substring-filters
)
1255 (org-set-local 'buffer-substring-filters
1257 (set-text-properties 0 (length x
) nil x
) x
)
1258 buffer-substring-filters
)))
1259 (unless org-agenda-keep-modes
1260 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1261 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1262 org-agenda-show-log org-agenda-start-with-log-mode
))
1265 '("Agenda") "Agenda Files"
1269 (if (get 'org-agenda-files
'org-restrict
)
1270 "Restricted to single file"
1272 '(org-edit-agenda-file-list)
1273 (not (get 'org-agenda-files
'org-restrict
)))
1275 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1276 (org-agenda-set-mode-name)
1278 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1279 (list 'org-agenda-mode-hook
)))
1281 (substitute-key-definition 'undo
'org-agenda-undo
1282 org-agenda-mode-map global-map
)
1283 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1284 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1285 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1286 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1287 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1288 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1289 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1290 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1291 (org-defkey org-agenda-mode-map
"A" 'org-agenda-archive-to-archive-sibling
)
1292 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1293 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1294 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1295 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1296 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1297 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1298 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1299 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1300 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1301 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1302 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1303 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1304 (org-defkey org-agenda-mode-map
"\C-c\C-q" 'org-agenda-set-tags
)
1305 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1306 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1307 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1308 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1309 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1310 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1311 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1312 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1313 (org-defkey org-agenda-mode-map
"k" 'org-agenda-action
)
1314 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-k" 'org-agenda-action
)
1315 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-do-date-later
)
1316 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-do-date-earlier
)
1317 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-do-date-later
)
1318 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-do-date-earlier
)
1320 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1321 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1322 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1323 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1324 (while l
(org-defkey org-agenda-mode-map
1325 (int-to-string (pop l
)) 'digit-argument
)))
1327 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1328 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1329 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1330 (org-defkey org-agenda-mode-map
"v" 'org-agenda-archives-mode
)
1331 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1332 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1333 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1334 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1335 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1336 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1337 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1338 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1339 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1340 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1341 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1342 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1343 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1344 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1345 (org-defkey org-agenda-mode-map
"\C-c\C-a" 'org-attach
)
1346 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1347 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1348 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1349 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1350 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1351 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1352 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1353 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1354 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1355 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1356 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1357 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1358 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1359 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1360 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1361 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1362 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1363 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1364 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1365 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1366 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1367 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1368 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1369 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1370 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1371 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1372 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1373 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1374 (org-defkey org-agenda-mode-map
"\C-c\C-x>" 'org-agenda-remove-restriction-lock
)
1376 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1377 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1378 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1379 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1380 (org-defkey org-agenda-mode-map
"/" 'org-agenda-filter-by-tag
)
1381 (org-defkey org-agenda-mode-map
"\\" 'org-agenda-filter-by-tag-refine
)
1383 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1384 "Local keymap for agenda entries from Org-mode.")
1386 (org-defkey org-agenda-keymap
1387 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1388 (org-defkey org-agenda-keymap
1389 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1390 (when org-agenda-mouse-1-follows-link
1391 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1392 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1396 ["Show" org-agenda-show t
]
1397 ["Go To (other window)" org-agenda-goto t
]
1398 ["Go To (this window)" org-agenda-switch-to t
]
1399 ["Follow Mode" org-agenda-follow-mode
1400 :style toggle
:selected org-agenda-follow-mode
:active t
]
1401 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1403 ["Cycle TODO" org-agenda-todo t
]
1405 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t
]
1406 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t
]
1407 ["Archive subtree" org-agenda-archive t
])
1408 ["Delete subtree" org-agenda-kill t
]
1409 ["Add note" org-agenda-add-note t
]
1411 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1412 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1413 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1414 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1416 ("Tags and Properties"
1417 ["Show all Tags" org-agenda-show-tags t
]
1418 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1419 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1421 ["Column View" org-columns t
])
1423 ["Schedule" org-agenda-schedule t
]
1424 ["Set Deadline" org-agenda-deadline t
]
1426 ["Mark item" org-agenda-action
:active t
:keys
"k m"]
1427 ["Show mark item" org-agenda-action
:active t
:keys
"k v"]
1428 ["Schedule marked item" org-agenda-action
:active t
:keys
"k s"]
1429 ["Set Deadline for marked item" org-agenda-action
:active t
:keys
"k d"]
1431 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1432 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1433 ["Change Time +1 hour" org-agenda-do-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-right"]
1434 ["Change Time -1 hour" org-agenda-do-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-left"]
1435 ["Change Time + min" org-agenda-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-right"]
1436 ["Change Time - min" org-agenda-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-left"]
1437 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1439 ["Clock in" org-agenda-clock-in t
]
1440 ["Clock out" org-agenda-clock-out t
]
1441 ["Clock cancel" org-agenda-clock-cancel t
]
1442 ["Goto running clock" org-clock-goto t
])
1444 ["Set Priority" org-agenda-priority t
]
1445 ["Increase Priority" org-agenda-priority-up t
]
1446 ["Decrease Priority" org-agenda-priority-down t
]
1447 ["Show Priority" org-agenda-show-priority t
])
1449 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1450 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1451 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1452 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1453 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1454 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1456 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1459 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1460 :style radio
:selected
(equal org-agenda-ndays
1)]
1461 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1462 :style radio
:selected
(equal org-agenda-ndays
7)]
1463 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1464 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1465 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1466 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1468 ["Include Diary" org-agenda-toggle-diary
1469 :style toggle
:selected org-agenda-include-diary
1470 :active
(org-agenda-check-type nil
'agenda
)]
1471 ["Use Time Grid" org-agenda-toggle-time-grid
1472 :style toggle
:selected org-agenda-use-time-grid
1473 :active
(org-agenda-check-type nil
'agenda
)]
1475 ["Show clock report" org-agenda-clockreport-mode
1476 :style toggle
:selected org-agenda-clockreport-mode
1477 :active
(org-agenda-check-type nil
'agenda
)]
1479 ["Show Logbook entries" org-agenda-log-mode
1480 :style toggle
:selected org-agenda-show-log
1481 :active
(org-agenda-check-type nil
'agenda
'timeline
)]
1482 ["Include archived trees" org-agenda-archives-mode
1483 :style toggle
:selected org-agenda-archives-mode
:active t
]
1484 ["Include archive files" (org-agenda-archives-mode t
)
1485 :style toggle
:selected
(eq org-agenda-archives-mode t
) :active t
1488 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict
])
1489 ["Write view to file" org-write-agenda t
]
1490 ["Rebuild buffer" org-agenda-redo t
]
1491 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1493 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1495 ["Quit" org-agenda-quit t
]
1496 ["Exit and Release Buffers" org-agenda-exit t
]
1501 (defvar org-agenda-allow-remote-undo t
1502 "Non-nil means, allow remote undo from the agenda buffer.")
1503 (defvar org-agenda-undo-list nil
1504 "List of undoable operations in the agenda since last refresh.")
1505 (defvar org-agenda-undo-has-started-in nil
1506 "Buffers that have already seen `undo-start' in the current undo sequence.")
1507 (defvar org-agenda-pending-undo-list nil
1508 "In a series of undo commands, this is the list of remaining undo items.")
1511 (defun org-agenda-undo ()
1512 "Undo a remote editing step in the agenda.
1513 This undoes changes both in the agenda buffer and in the remote buffer
1514 that have been changed along."
1516 (or org-agenda-allow-remote-undo
1517 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1518 (if (not (eq this-command last-command
))
1519 (setq org-agenda-undo-has-started-in nil
1520 org-agenda-pending-undo-list org-agenda-undo-list
))
1521 (if (not org-agenda-pending-undo-list
)
1522 (error "No further undo information"))
1523 (let* ((entry (pop org-agenda-pending-undo-list
))
1524 buf line cmd rembuf
)
1525 (setq cmd
(pop entry
) line
(pop entry
))
1526 (setq rembuf
(nth 2 entry
))
1527 (org-with-remote-undo rembuf
1528 (while (bufferp (setq buf
(pop entry
)))
1530 (with-current-buffer buf
1531 (let ((last-undo-buffer buf
)
1532 (inhibit-read-only t
))
1533 (unless (memq buf org-agenda-undo-has-started-in
)
1534 (push buf org-agenda-undo-has-started-in
)
1535 (make-local-variable 'pending-undo-list
)
1537 (while (and pending-undo-list
1538 (listp pending-undo-list
)
1539 (not (car pending-undo-list
)))
1540 (pop pending-undo-list
))
1543 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1545 (defun org-verify-change-for-undo (l1 l2
)
1546 "Verify that a real change occurred between the undo lists L1 and L2."
1547 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1548 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1553 (defvar org-agenda-restrict nil
)
1554 (defvar org-agenda-restrict-begin
(make-marker))
1555 (defvar org-agenda-restrict-end
(make-marker))
1556 (defvar org-agenda-last-dispatch-buffer nil
)
1557 (defvar org-agenda-overriding-restriction nil
)
1560 (defun org-agenda (&optional arg keys restriction
)
1561 "Dispatch agenda commands to collect entries to the agenda buffer.
1562 Prompts for a command to execute. Any prefix arg will be passed
1563 on to the selected command. The default selections are:
1565 a Call `org-agenda-list' to display the agenda for current day or week.
1566 t Call `org-todo-list' to display the global todo list.
1567 T Call `org-todo-list' to display the global todo list, select only
1568 entries with a specific TODO keyword (the user gets a prompt).
1569 m Call `org-tags-view' to display headlines with tags matching
1570 a condition (the user is prompted for the condition).
1571 M Like `m', but select only TODO entries, no ordinary headlines.
1572 L Create a timeline for the current buffer.
1573 e Export views to associated files.
1574 s Search entries for keywords.
1575 / Multi occur accros all agenda files and also files listed
1576 in `org-agenda-text-search-extra-files'.
1577 < Restrict agenda commands to buffer, subtree, or region.
1578 Press several times to get the desired effect.
1579 > Remove a previous restriction.
1580 # List \"stuck\" projects.
1581 ! Configure what \"stuck\" means.
1582 C Configure custom agenda commands.
1584 More commands can be added by configuring the variable
1585 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1586 searches can be pre-defined in this way.
1588 If the current buffer is in Org-mode and visiting a file, you can also
1589 first press `<' once to indicate that the agenda should be temporarily
1590 \(until the next use of \\[org-agenda]) restricted to the current file.
1591 Pressing `<' twice means to restrict to the current subtree or region
1595 (let* ((prefix-descriptions nil
)
1596 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1597 (org-agenda-custom-commands
1598 ;; normalize different versions
1602 (cond ((stringp (cdr x
))
1603 (push x prefix-descriptions
)
1605 ((stringp (nth 1 x
)) x
)
1606 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1607 (t (cons (car x
) (cons "" (cdr x
))))))
1608 org-agenda-custom-commands
)))
1609 (buf (current-buffer))
1610 (bfn (buffer-file-name (buffer-base-buffer)))
1611 entry key type match lprops ans
)
1612 ;; Turn off restriction unless there is an overriding one
1613 (unless org-agenda-overriding-restriction
1614 (put 'org-agenda-files
'org-restrict nil
)
1615 (setq org-agenda-restrict nil
)
1616 (move-marker org-agenda-restrict-begin nil
)
1617 (move-marker org-agenda-restrict-end nil
))
1618 ;; Delete old local properties
1619 (put 'org-agenda-redo-command
'org-lprops nil
)
1620 ;; Remember where this call originated
1621 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1623 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1625 restriction
(cdr ans
)))
1626 ;; Estabish the restriction, if any
1627 (when (and (not org-agenda-overriding-restriction
) restriction
)
1628 (put 'org-agenda-files
'org-restrict
(list bfn
))
1630 ((eq restriction
'region
)
1631 (setq org-agenda-restrict t
)
1632 (move-marker org-agenda-restrict-begin
(region-beginning))
1633 (move-marker org-agenda-restrict-end
(region-end)))
1634 ((eq restriction
'subtree
)
1636 (setq org-agenda-restrict t
)
1637 (org-back-to-heading t
)
1638 (move-marker org-agenda-restrict-begin
(point))
1639 (move-marker org-agenda-restrict-end
1640 (progn (org-end-of-subtree t
)))))))
1642 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1643 ;; For example the todo list should not need it (but does...)
1645 ((setq entry
(assoc keys org-agenda-custom-commands
))
1646 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1648 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1649 (put 'org-agenda-redo-command
'org-lprops lprops
)
1652 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1654 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1656 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1658 (org-let lprops
'(org-agenda-list-stuck-projects
1659 current-prefix-arg
)))
1661 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1662 ((eq type
'tags-todo
)
1663 (org-let lprops
'(org-tags-view '(4) match
)))
1665 (org-let lprops
'(org-todo-list match
)))
1666 ((eq type
'tags-tree
)
1667 (org-check-for-org-mode)
1668 (org-let lprops
'(org-match-sparse-tree current-prefix-arg match
)))
1669 ((eq type
'todo-tree
)
1670 (org-check-for-org-mode)
1672 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1673 (regexp-quote match
) "\\>"))))
1674 ((eq type
'occur-tree
)
1675 (org-check-for-org-mode)
1676 (org-let lprops
'(org-occur match
)))
1678 (org-let lprops
'(funcall type match
)))
1680 (org-let lprops
'(funcall type match
)))
1681 (t (error "Invalid custom agenda command type %s" type
))))
1682 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1684 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1685 (customize-variable 'org-agenda-custom-commands
))
1686 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1687 ((equal keys
"s") (call-interactively 'org-search-view
))
1688 ((equal keys
"t") (call-interactively 'org-todo-list
))
1689 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1690 ((equal keys
"m") (call-interactively 'org-tags-view
))
1691 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1692 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1694 (unless (org-mode-p)
1695 (error "This is not an Org-mode file"))
1697 (put 'org-agenda-files
'org-restrict
(list bfn
))
1698 (org-call-with-arg 'org-timeline arg
)))
1699 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1700 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1701 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1702 (t (error "Invalid agenda key"))))))
1704 (defun org-agenda-normalize-custom-commands (cmds)
1708 (cond ((stringp (cdr x
)) nil
)
1709 ((stringp (nth 1 x
)) x
)
1710 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1711 (t (cons (car x
) (cons "" (cdr x
))))))
1714 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1715 "The user interface for selecting an agenda command."
1717 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1718 (restrict-ok (and bfn
(org-mode-p)))
1719 (region-p (org-region-active-p))
1720 (custom org-agenda-custom-commands
)
1722 restriction second-time
1723 c entry key type match prefixes rmheader header-end custom1 desc
)
1724 (save-window-excursion
1725 (delete-other-windows)
1726 (org-switch-to-buffer-other-window " *Agenda Commands*")
1728 (insert (eval-when-compile
1731 Press key for an agenda command: < Buffer, subtree/region restriction
1732 -------------------------------- > Remove restriction
1733 a Agenda for current week or day e Export agenda views
1734 t List of all TODO entries T Entries with special TODO kwd
1735 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1736 L Timeline for current buffer # List stuck projects (!=configure)
1737 s Search for keywords C Configure custom agenda commands
1741 (while (string-match
1742 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1744 (setq start
(match-end 0))
1745 (add-text-properties (match-beginning 2) (match-end 2)
1746 '(face bold
) header
))
1748 (setq header-end
(move-marker (make-marker) (point)))
1750 (setq custom1 custom
)
1751 (when (eq rmheader t
)
1753 (re-search-forward ":" nil t
)
1754 (delete-region (match-end 0) (point-at-eol))
1757 (delete-region (match-end 0) (point-at-eol))
1758 (move-marker header-end
(match-end 0)))
1759 (goto-char header-end
)
1760 (delete-region (point) (point-max))
1761 (while (setq entry
(pop custom1
))
1762 (setq key
(car entry
) desc
(nth 1 entry
)
1763 type
(nth 2 entry
) match
(nth 3 entry
))
1764 (if (> (length key
) 1)
1765 (add-to-list 'prefixes
(string-to-char key
))
1769 (org-add-props (copy-sequence key
)
1772 ((string-match "\\S-" desc
) desc
)
1773 ((eq type
'agenda
) "Agenda for current week or day")
1774 ((eq type
'alltodo
) "List of all TODO entries")
1775 ((eq type
'search
) "Word search")
1776 ((eq type
'stuck
) "List of stuck projects")
1777 ((eq type
'todo
) "TODO keyword")
1778 ((eq type
'tags
) "Tags query")
1779 ((eq type
'tags-todo
) "Tags (TODO)")
1780 ((eq type
'tags-tree
) "Tags tree")
1781 ((eq type
'todo-tree
) "TODO kwd tree")
1782 ((eq type
'occur-tree
) "Occur tree")
1783 ((functionp type
) (if (symbolp type
)
1785 "Lambda expression"))
1789 (org-add-props match nil
'face
'org-warning
))
1791 (format "set of %d commands" (length match
)))
1797 (org-add-props (char-to-string x
)
1799 (or (cdr (assoc (concat selstring
(char-to-string x
))
1800 prefix-descriptions
))
1803 (goto-char (point-min))
1805 (if (not (pos-visible-in-window-p (point-max)))
1806 (org-fit-window-to-buffer))
1807 (setq second-time t
)
1808 (org-fit-window-to-buffer))
1809 (message "Press key for agenda command%s:"
1810 (if (or restrict-ok org-agenda-overriding-restriction
)
1811 (if org-agenda-overriding-restriction
1812 " (restriction lock active)"
1814 (format " (restricted to %s)" restriction
)
1817 (setq c
(read-char-exclusive))
1820 ((assoc (char-to-string c
) custom
)
1821 (setq selstring
(concat selstring
(char-to-string c
)))
1822 (throw 'exit
(cons selstring restriction
)))
1824 (setq selstring
(concat selstring
(char-to-string c
))
1826 rmheader
(or rmheader t
)
1827 custom
(delq nil
(mapcar
1829 (if (or (= (length (car x
)) 1)
1830 (/= (string-to-char (car x
)) c
))
1832 (cons (substring (car x
) 1) (cdr x
))))
1834 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1835 (message "Restriction is only possible in Org-mode buffers")
1838 (org-agenda-remove-restriction-lock 'noupdate
)
1839 (setq restriction
'buffer
))
1841 (org-agenda-remove-restriction-lock 'noupdate
)
1842 (setq restriction
(if region-p
'region
'subtree
)))
1844 (org-agenda-remove-restriction-lock 'noupdate
)
1847 ((eq restriction
'buffer
)
1848 (if region-p
'region
'subtree
))
1849 ((memq restriction
'(subtree region
))
1853 (org-agenda-remove-restriction-lock 'noupdate
)
1854 (setq restriction nil
))
1855 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1856 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1857 ((and (> (length selstring
) 0) (eq c ?\d
))
1859 (org-agenda-get-restriction-and-command prefix-descriptions
))
1861 ((equal c ?q
) (error "Abort"))
1862 (t (error "Invalid key %c" c
))))))))
1864 (defun org-run-agenda-series (name series
)
1865 (org-let (nth 1 series
) '(org-prepare-agenda name
))
1866 (let* ((org-agenda-multi t
)
1867 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1869 (gprops (nth 1 series
))
1870 match
;; The byte compiler incorrectly complains about this. Keep it!
1872 (while (setq cmd
(pop cmds
))
1873 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1876 (org-let2 gprops lprops
1877 '(call-interactively 'org-agenda-list
)))
1879 (org-let2 gprops lprops
1880 '(call-interactively 'org-todo-list
)))
1882 (org-let2 gprops lprops
1883 '(org-search-view current-prefix-arg match nil
)))
1885 (org-let2 gprops lprops
1886 '(call-interactively 'org-agenda-list-stuck-projects
)))
1888 (org-let2 gprops lprops
1889 '(org-tags-view current-prefix-arg match
)))
1890 ((eq type
'tags-todo
)
1891 (org-let2 gprops lprops
1892 '(org-tags-view '(4) match
)))
1894 (org-let2 gprops lprops
1895 '(org-todo-list match
)))
1897 (org-let2 gprops lprops
1898 '(funcall type match
)))
1899 (t (error "Invalid type in command series"))))
1901 (setq org-agenda-redo-command redo
)
1902 (goto-char (point-min)))
1903 (org-fit-agenda-window)
1904 (org-let (nth 1 series
) '(org-finalize-agenda)))
1907 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1908 "Run an agenda command in batch mode and send the result to STDOUT.
1909 If CMD-KEY is a string of length 1, it is used as a key in
1910 `org-agenda-custom-commands' and triggers this command. If it is a
1911 longer string it is used as a tags/todo match string.
1912 Paramters are alternating variable names and values that will be bound
1913 before running the agenda command."
1916 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1917 (if (> (length cmd-key
) 2)
1918 (eval (list 'let
(nreverse pars
)
1919 (list 'org-tags-view nil cmd-key
)))
1920 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1921 (set-buffer org-agenda-buffer-name
)
1922 (princ (org-encode-for-stdout (buffer-string)))))
1924 (defun org-encode-for-stdout (string)
1925 (if (fboundp 'encode-coding-string
)
1926 (encode-coding-string string buffer-file-coding-system
)
1929 (defvar org-agenda-info nil
)
1932 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1933 "Run an agenda command in batch mode and send the result to STDOUT.
1934 If CMD-KEY is a string of length 1, it is used as a key in
1935 `org-agenda-custom-commands' and triggers this command. If it is a
1936 longer string it is used as a tags/todo match string.
1937 Paramters are alternating variable names and values that will be bound
1938 before running the agenda command.
1940 The output gives a line for each selected agenda item. Each
1941 item is a list of comma-separated values, like this:
1943 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1945 category The category of the item
1946 head The headline, without TODO kwd, TAGS and PRIORITY
1947 type The type of the agenda entry, can be
1948 todo selected in TODO match
1949 tagsmatch selected in tags match
1950 diary imported from diary
1951 deadline a deadline on given date
1952 scheduled scheduled on given date
1953 timestamp entry has timestamp on given date
1954 closed entry was closed on given date
1955 upcoming-deadline warning about deadline
1956 past-scheduled forwarded scheduled item
1957 block entry has date block including g. date
1958 todo The todo keyword, if any
1959 tags All tags including inherited ones, separated by colons
1960 date The relevant date, like 2007-2-14
1961 time The time, like 15:00-16:50
1962 extra Sting with extra planning info
1963 priority-l The priority letter if any was given
1964 priority-n The computed numerical priority
1965 agenda-day The day in the agenda where this is listed"
1969 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1970 (push (list 'org-agenda-remove-tags t
) pars
)
1971 (if (> (length cmd-key
) 2)
1972 (eval (list 'let
(nreverse pars
)
1973 (list 'org-tags-view nil cmd-key
)))
1974 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1975 (set-buffer org-agenda-buffer-name
)
1976 (let* ((lines (org-split-string (buffer-string) "\n"))
1978 (while (setq line
(pop lines
))
1980 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1981 (setq org-agenda-info
1982 (org-fix-agenda-info (text-properties-at 0 line
)))
1984 (org-encode-for-stdout
1985 (mapconcat 'org-agenda-export-csv-mapper
1986 '(org-category txt type todo tags date time-of-day extra
1987 priority-letter priority agenda-day
)
1991 (defun org-fix-agenda-info (props)
1992 "Make sure all properties on an agenda item have a canonical form,
1993 so the export commands can easily use it."
1995 (when (setq tmp
(plist-get props
'tags
))
1996 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1997 (when (setq tmp
(plist-get props
'date
))
1998 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1999 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
2000 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
2002 (setq tmp
(calendar-date-string tmp
)))
2003 (setq props
(plist-put props
'date tmp
)))
2004 (when (setq tmp
(plist-get props
'day
))
2005 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
2006 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
2007 (setq tmp
(calendar-date-string tmp
)))
2008 (setq props
(plist-put props
'day tmp
))
2009 (setq props
(plist-put props
'agenda-day tmp
)))
2010 (when (setq tmp
(plist-get props
'txt
))
2011 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
2012 (plist-put props
'priority-letter
(match-string 1 tmp
))
2013 (setq tmp
(replace-match "" t t tmp
)))
2014 (when (and (setq re
(plist-get props
'org-todo-regexp
))
2015 (setq re
(concat "\\`\\.*" re
" ?"))
2016 (string-match re tmp
))
2017 (plist-put props
'todo
(match-string 1 tmp
))
2018 (setq tmp
(replace-match "" t t tmp
)))
2019 (plist-put props
'txt tmp
)))
2022 (defun org-agenda-export-csv-mapper (prop)
2023 (let ((res (plist-get org-agenda-info prop
)))
2028 (t (prin1-to-string res
))))
2029 (while (string-match "," res
)
2030 (setq res
(replace-match ";" t t res
)))
2035 (defun org-store-agenda-views (&rest parameters
)
2037 (eval (list 'org-batch-store-agenda-views
)))
2039 ;; FIXME, why is this a macro?????
2041 (defmacro org-batch-store-agenda-views
(&rest parameters
)
2042 "Run all custom agenda commands that have a file argument."
2043 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
2045 (dir default-directory
)
2046 pars cmd thiscmdkey files opts cmd-or-set
)
2048 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
2049 (setq pars
(reverse pars
))
2050 (save-window-excursion
2052 (setq cmd
(pop cmds
)
2053 thiscmdkey
(car cmd
)
2054 cmd-or-set
(nth 2 cmd
)
2055 opts
(nth (if (listp cmd-or-set
) 3 4) cmd
)
2056 files
(nth (if (listp cmd-or-set
) 4 5) cmd
))
2057 (if (stringp files
) (setq files
(list files
)))
2059 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2060 (list 'org-agenda nil thiscmdkey
)))
2061 (set-buffer org-agenda-buffer-name
)
2063 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2064 (list 'org-write-agenda
2065 (expand-file-name (pop files
) dir
) nil t
))))
2066 (and (get-buffer org-agenda-buffer-name
)
2067 (kill-buffer org-agenda-buffer-name
)))))))
2069 (defun org-write-agenda (file &optional open nosettings
)
2070 "Write the current buffer (an agenda view) as a file.
2071 Depending on the extension of the file name, plain text (.txt),
2072 HTML (.html or .htm) or Postscript (.ps) is produced.
2073 If the extension is .ics, run icalendar export over all files used
2074 to construct the agenda and limit the export to entries listed in the
2076 With prefic argument OPEN, open the new file immediately.
2077 If NOSETTINGS is given, do not scope the settings of
2078 `org-agenda-exporter-settings' into the export commands. This is used when
2079 the settings have already been scoped and we do not wish to overrule other,
2080 higher priority settings."
2081 (interactive "FWrite agenda to file: \nP")
2082 (if (not (file-writable-p file
))
2083 (error "Cannot write agenda to file %s" file
))
2085 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
2086 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
2087 (org-let (if nosettings nil org-agenda-exporter-settings
)
2089 (save-window-excursion
2090 (org-agenda-mark-filtered-text)
2091 (let ((bs (copy-sequence (buffer-string))) beg
)
2092 (org-agenda-unmark-filtered-text)
2095 (org-agenda-remove-marked-text 'org-filtered
)
2096 (while (setq beg
(text-property-any (point-min) (point-max)
2099 beg
(or (next-single-property-change beg
'org-filtered
)
2101 (run-hooks 'org-agenda-before-write-hook
)
2103 ((string-match "\\.html?\\'" file
)
2104 (set-buffer (htmlize-buffer (current-buffer)))
2106 (when (and org-agenda-export-html-style
2107 (string-match "<style>" org-agenda-export-html-style
))
2108 ;; replace <style> section with org-agenda-export-html-style
2109 (goto-char (point-min))
2110 (kill-region (- (search-forward "<style") 6)
2111 (search-forward "</style>"))
2112 (insert org-agenda-export-html-style
))
2114 (kill-buffer (current-buffer))
2115 (message "HTML written to %s" file
))
2116 ((string-match "\\.ps\\'" file
)
2118 (flet ((ps-get-buffer-name () "Agenda View"))
2119 (ps-print-buffer-with-faces file
))
2120 (message "Postscript written to %s" file
))
2121 ((string-match "\\.pdf\\'" file
)
2123 (flet ((ps-get-buffer-name () "Agenda View"))
2124 (ps-print-buffer-with-faces
2125 (concat (file-name-sans-extension file
) ".ps")))
2126 (call-process "ps2pdf" nil nil nil
2128 (concat (file-name-sans-extension file
) ".ps"))
2129 (expand-file-name file
))
2130 (message "PDF written to %s" file
))
2131 ((string-match "\\.ics\\'" file
)
2132 (let ((org-agenda-marker-table
2133 (org-create-marker-find-array
2134 (org-agenda-collect-markers)))
2135 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
2136 (org-combined-agenda-icalendar-file file
))
2137 (apply 'org-export-icalendar
'combine
2138 (org-agenda-files nil
'ifmode
))))
2140 (let ((bs (buffer-string)))
2145 (kill-buffer (current-buffer))
2146 (message "Plain text written to %s" file
))))))))
2147 (set-buffer org-agenda-buffer-name
))
2148 (when open
(org-open-file file
)))
2150 (defvar org-agenda-filter-overlays nil
)
2152 (defun org-agenda-mark-filtered-text ()
2153 "Mark all text hidden by filtering with a text property."
2154 (let ((inhibit-read-only t
))
2157 (when (equal (org-overlay-buffer o
) (current-buffer))
2159 (org-overlay-start o
) (org-overlay-end o
)
2161 org-agenda-filter-overlays
)))
2163 (defun org-agenda-unmark-filtered-text ()
2164 "Remove the filtering text property."
2165 (let ((inhibit-read-only t
))
2166 (remove-text-properties (point-min) (point-max) '(org-filtered t
))))
2168 (defun org-agenda-remove-marked-text (property &optional value
)
2169 "Delete all text marked with VALUE of PROPERTY.
2170 VALUE defaults to t."
2172 (setq value
(or value t
))
2173 (while (setq beg
(text-property-any (point-min) (point-max)
2176 beg
(or (next-single-property-change beg
'org-filtered
)
2179 (defun org-agenda-add-entry-text ()
2180 "Add entry text to agenda lines.
2181 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2182 entry text following headings shown in the agenda.
2183 Drawers will be excluded, also the line with scheduling/deadline info."
2184 (when (> org-agenda-add-entry-text-maxlines
0)
2185 (let (m txt drawer-re kwd-time-re ind
)
2186 (goto-char (point-min))
2188 (if (not (setq m
(get-text-property (point) 'org-hd-marker
)))
2189 (beginning-of-line 2)
2191 (with-current-buffer (marker-buffer m
)
2192 (if (not (org-mode-p))
2198 (beginning-of-line 2)
2199 (setq txt
(buffer-substring
2201 (progn (outline-next-heading) (point)))
2202 drawer-re org-drawer-regexp
2203 kwd-time-re
(concat "^[ \t]*" org-keyword-time-regexp
2207 (when org-agenda-add-entry-text-descriptive-links
2208 (goto-char (point-min))
2209 (while (org-activate-bracket-links (point-max))
2210 (add-text-properties (match-beginning 0) (match-end 0)
2212 (goto-char (point-min))
2213 (while (re-search-forward org-bracket-link-regexp
(point-max) t
)
2214 (set-text-properties (match-beginning 0) (match-end 0)
2216 (goto-char (point-min))
2217 (while (re-search-forward drawer-re nil t
)
2220 (progn (re-search-forward
2221 "^[ \t]*:END:.*\n?" nil
'move
)
2223 (goto-char (point-min))
2224 (while (re-search-forward kwd-time-re nil t
)
2226 (if (re-search-forward "[ \t\n]+\\'" nil t
)
2228 (goto-char (point-min))
2229 ;; find min indentation
2230 (goto-char (point-min))
2231 (untabify (point-min) (point-max))
2232 (setq ind
(org-get-indentation))
2234 (unless (looking-at "[ \t]*$")
2235 (setq ind
(min ind
(org-get-indentation))))
2236 (beginning-of-line 2))
2237 (goto-char (point-min))
2239 (unless (looking-at "[ \t]*$")
2240 (move-to-column ind
)
2241 (delete-region (point-at-bol) (point)))
2242 (beginning-of-line 2))
2243 (goto-char (point-min))
2244 (while (and (not (eobp)) (re-search-forward "^" nil t
))
2245 (replace-match " > "))
2246 (goto-char (point-min))
2247 (while (looking-at "[ \t]*\n") (replace-match ""))
2248 (goto-char (point-max))
2249 (when (> (org-current-line)
2250 (1+ org-agenda-add-entry-text-maxlines
))
2251 (goto-line (1+ org-agenda-add-entry-text-maxlines
))
2253 (setq txt
(buffer-substring (point-min) (point)))))))))
2255 (if (string-match "\\S-" txt
) (insert "\n" txt
)))))))
2257 (defun org-agenda-collect-markers ()
2258 "Collect the markers pointing to entries in the agenda buffer."
2261 (goto-char (point-min))
2263 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
2264 (get-text-property (point) 'org-marker
)))
2266 (beginning-of-line 2)))
2267 (nreverse markers
)))
2269 (defun org-create-marker-find-array (marker-list)
2270 "Create a alist of files names with all marker positions in that file."
2272 (while (setq m
(pop marker-list
))
2273 (setq p
(marker-position m
)
2274 f
(buffer-file-name (or (buffer-base-buffer
2276 (marker-buffer m
))))
2277 (if (setq a
(assoc f tbl
))
2278 (push (marker-position m
) (cdr a
))
2279 (push (list f p
) tbl
)))
2280 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
2283 (defvar org-agenda-marker-table nil
) ; dynamically scoped parameter
2284 (defun org-check-agenda-marker-table ()
2285 "Check of the current entry is on the marker list."
2286 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2288 (and (setq a
(assoc file org-agenda-marker-table
))
2291 (org-back-to-heading t
)
2292 (member (point) (cdr a
)))))))
2294 (defun org-check-for-org-mode ()
2295 "Make sure current buffer is in org-mode. Error if not."
2297 (error "Cannot execute org-mode agenda command on buffer in %s."
2300 (defun org-fit-agenda-window ()
2301 "Fit the window to the buffer size."
2302 (and (memq org-agenda-window-setup
'(reorganize-frame))
2303 (fboundp 'fit-window-to-buffer
)
2304 (org-fit-window-to-buffer
2306 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
2307 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
2309 ;;; Agenda prepare and finalize
2311 (defvar org-agenda-multi nil
) ; dynamically scoped
2312 (defvar org-agenda-buffer-name
"*Org Agenda*")
2313 (defvar org-pre-agenda-window-conf nil
)
2314 (defvar org-agenda-columns-active nil
)
2315 (defvar org-agenda-name nil
)
2316 (defvar org-agenda-filter nil
)
2317 (defvar org-agenda-filter-preset nil
2318 "A preset of the tags filter used for secondary agenda filtering.
2319 This must be a list of strings, each string must be a single tag preceeded
2321 This variable should not be set directly, but agenda custom commands can
2322 bind it in the options section.")
2324 (defun org-prepare-agenda (&optional name
)
2325 (setq org-todo-keywords-for-agenda nil
)
2326 (setq org-done-keywords-for-agenda nil
)
2327 (setq org-agenda-filter nil
)
2328 (put 'org-agenda-filter
:preset-filter org-agenda-filter-preset
)
2329 (if org-agenda-multi
2331 (setq buffer-read-only nil
)
2332 (goto-char (point-max))
2333 (unless (or (bobp) org-agenda-compact-blocks
)
2335 (if (stringp org-agenda-block-separator
)
2336 org-agenda-block-separator
2337 (make-string (window-width) org-agenda-block-separator
))
2339 (narrow-to-region (point) (point-max)))
2340 (org-agenda-reset-markers)
2341 (setq org-agenda-contributing-files nil
)
2342 (setq org-agenda-columns-active nil
)
2343 (org-prepare-agenda-buffers (org-agenda-files nil
'ifmode
))
2344 (setq org-todo-keywords-for-agenda
2345 (org-uniquify org-todo-keywords-for-agenda
))
2346 (setq org-done-keywords-for-agenda
2347 (org-uniquify org-done-keywords-for-agenda
))
2348 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
2349 (awin (get-buffer-window abuf
)))
2351 ((equal (current-buffer) abuf
) nil
)
2352 (awin (select-window awin
))
2353 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
2354 ((equal org-agenda-window-setup
'current-window
)
2355 (switch-to-buffer abuf
))
2356 ((equal org-agenda-window-setup
'other-window
)
2357 (org-switch-to-buffer-other-window abuf
))
2358 ((equal org-agenda-window-setup
'other-frame
)
2359 (switch-to-buffer-other-frame abuf
))
2360 ((equal org-agenda-window-setup
'reorganize-frame
)
2361 (delete-other-windows)
2362 (org-switch-to-buffer-other-window abuf
))))
2363 (setq buffer-read-only nil
)
2364 (let ((inhibit-read-only t
)) (erase-buffer))
2366 (and name
(not org-agenda-name
)
2367 (org-set-local 'org-agenda-name name
)))
2368 (setq buffer-read-only nil
))
2370 (defun org-finalize-agenda ()
2371 "Finishing touch for the agenda buffer, called just before displaying it."
2372 (unless org-agenda-multi
2374 (let ((inhibit-read-only t
))
2375 (goto-char (point-min))
2376 (while (org-activate-bracket-links (point-max))
2377 (add-text-properties (match-beginning 0) (match-end 0)
2379 (org-agenda-align-tags)
2380 (unless org-agenda-with-colors
2381 (remove-text-properties (point-min) (point-max) '(face nil
))))
2382 (if (and (boundp 'org-agenda-overriding-columns-format
)
2383 org-agenda-overriding-columns-format
)
2384 (org-set-local 'org-agenda-overriding-columns-format
2385 org-agenda-overriding-columns-format
))
2386 (if (and (boundp 'org-agenda-view-columns-initially
)
2387 org-agenda-view-columns-initially
)
2388 (org-agenda-columns))
2389 (when org-agenda-fontify-priorities
2390 (org-agenda-fontify-priorities))
2391 (when (and org-agenda-dim-blocked-tasks org-blocker-hook
)
2392 (org-agenda-dim-blocked-tasks))
2393 (run-hooks 'org-finalize-agenda-hook
)
2394 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
2395 (when (get 'org-agenda-filter
:preset-filter
)
2396 (org-agenda-filter-apply org-agenda-filter
))
2399 (defun org-agenda-fontify-priorities ()
2400 "Make highest priority lines bold, and lowest italic."
2402 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
2403 (org-delete-overlay o
)))
2404 (org-overlays-in (point-min) (point-max)))
2406 (let ((inhibit-read-only t
)
2408 (goto-char (point-min))
2409 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
2410 (setq h
(or (get-char-property (point) 'org-highest-priority
)
2411 org-highest-priority
)
2412 l
(or (get-char-property (point) 'org-lowest-priority
)
2413 org-lowest-priority
)
2414 p
(string-to-char (match-string 1))
2415 b
(match-beginning 0)
2416 e
(if (eq org-agenda-fontify-priorities
'cookies
)
2419 ov
(org-make-overlay b e
))
2422 (cond ((cdr (assoc p org-priority-faces
)))
2423 ((and (listp org-agenda-fontify-priorities
)
2424 (cdr (assoc p org-agenda-fontify-priorities
))))
2425 ((equal p l
) 'italic
)
2426 ((equal p h
) 'bold
)))
2427 (org-overlay-put ov
'org-type
'org-priority
)))))
2429 (defun org-agenda-dim-blocked-tasks ()
2430 "Dim currently blocked TODO's in the agenda display."
2431 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-blocked-todo
)
2432 (org-delete-overlay o
)))
2433 (org-overlays-in (point-min) (point-max)))
2435 (let ((inhibit-read-only t
)
2436 (org-depend-tag-blocked nil
)
2437 (invis (eq org-agenda-dim-blocked-tasks
'invisible
))
2438 org-blocked-by-checkboxes
2439 invis1 b e p ov h l
)
2440 (goto-char (point-min))
2441 (while (let ((pos (next-single-property-change (point) 'todo-state
)))
2442 (and pos
(goto-char (1+ pos
))))
2443 (setq org-blocked-by-checkboxes nil invis1 invis
)
2444 (let ((marker (get-text-property (point) 'org-hd-marker
)))
2446 (not (with-current-buffer (marker-buffer marker
)
2449 (if (org-entry-get nil
"NOBLOCKING")
2450 t
;; Never block this entry
2451 (run-hook-with-args-until-failure
2453 (list :type
'todo-state-change
2457 (if org-blocked-by-checkboxes
(setq invis1 nil
))
2458 (setq b
(if invis1
(max (point-min) (1- (point))) (point))
2460 ov
(org-make-overlay b e
))
2462 (org-overlay-put ov
'invisible t
)
2463 (org-overlay-put ov
'face
'org-agenda-dimmed-todo-face
))
2464 (org-overlay-put ov
'org-type
'org-blocked-todo
)))))))
2466 (defvar org-agenda-skip-function nil
2467 "Function to be called at each match during agenda construction.
2468 If this function returns nil, the current match should not be skipped.
2469 Otherwise, the function must return a position from where the search
2470 should be continued.
2471 This may also be a Lisp form, it will be evaluated.
2472 Never set this variable using `setq' or so, because then it will apply
2473 to all future agenda commands. Instead, bind it with `let' to scope
2474 it dynamically into the agenda-constructing command. A good way to set
2475 it is through options in org-agenda-custom-commands.")
2477 (defun org-agenda-skip ()
2478 "Throw to `:skip' in places that should be skipped.
2479 Also moves point to the end of the skipped region, so that search can
2480 continue from there."
2481 (let ((p (point-at-bol)) to fp
)
2482 (and org-agenda-skip-archived-trees
(not org-agenda-archives-mode
)
2483 (get-text-property p
:org-archived
)
2484 (org-end-of-subtree t
)
2486 (and org-agenda-skip-comment-trees
2487 (get-text-property p
:org-comment
)
2488 (org-end-of-subtree t
)
2490 (if (equal (char-after p
) ?
#) (throw :skip t
))
2491 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
2492 (consp org-agenda-skip-function
))
2493 (setq to
(save-excursion
2496 (funcall org-agenda-skip-function
)
2497 (eval org-agenda-skip-function
))))))
2501 (defvar org-agenda-markers nil
2502 "List of all currently active markers created by `org-agenda'.")
2503 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
2504 "Creation time of the last agenda marker.")
2506 (defun org-agenda-new-marker (&optional pos
)
2507 "Return a new agenda marker.
2508 Org-mode keeps a list of these markers and resets them when they are
2510 (let ((m (copy-marker (or pos
(point)))))
2511 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
2512 (push m org-agenda-markers
)
2515 (defun org-agenda-reset-markers ()
2516 "Reset markers created by `org-agenda'."
2517 (while org-agenda-markers
2518 (move-marker (pop org-agenda-markers
) nil
)))
2520 (defun org-agenda-save-markers-for-cut-and-paste (beg end
)
2521 "Save relative positions of markers in region."
2522 (mapc (lambda (m) (org-check-and-save-marker m beg end
))
2523 org-agenda-markers
))
2527 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
2529 (defun org-timeline (&optional include-all
)
2530 "Show a time-sorted view of the entries in the current org file.
2531 Only entries with a time stamp of today or later will be listed. With
2532 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2533 under the current date.
2534 If the buffer contains an active region, only check the region for
2538 (org-compile-prefix-format 'timeline
)
2539 (org-set-sorting-strategy 'timeline
)
2541 (dotodo include-all
)
2542 (doclosed org-agenda-show-log
)
2543 (entry buffer-file-name
)
2544 (date (calendar-current-date))
2545 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2546 (end (if (org-region-active-p) (region-end) (point-max)))
2547 (day-numbers (org-get-all-dates beg end
'no-ranges
2548 t doclosed
; always include today
2549 org-timeline-show-empty-dates
))
2550 (org-deadline-warning-days 0)
2551 (org-agenda-only-exact-dates t
)
2552 (today (time-to-days (current-time)))
2555 s e rtn d emptyp wd
)
2556 (setq org-agenda-redo-command
2558 (list 'org-switch-to-buffer-other-window
(current-buffer))
2559 (list 'org-timeline
(list 'quote include-all
))))
2561 ;; Remove past dates from the list of dates.
2562 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2563 (if (>= x today
) x nil
))
2565 (org-prepare-agenda (concat "Timeline "
2566 (file-name-nondirectory buffer-file-name
)))
2567 (if doclosed
(push :closed args
))
2568 (push :timestamp args
)
2569 (push :deadline args
)
2570 (push :scheduled args
)
2572 (if dotodo
(push :todo args
))
2573 (while (setq d
(pop day-numbers
))
2574 (if (and (listp d
) (eq (car d
) :omitted
))
2577 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2578 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2579 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2580 (if (and (>= d today
)
2585 (insert (make-string 79 ?-
) "\n")))
2586 (setq date
(calendar-gregorian-from-absolute d
)
2587 wd
(calendar-day-of-week date
))
2589 (setq rtn
(and (not emptyp
)
2590 (apply 'org-agenda-get-day-entries entry
2592 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2595 (if (stringp org-agenda-format-date
)
2596 (format-time-string org-agenda-format-date
2597 (org-time-from-absolute date
))
2598 (funcall org-agenda-format-date date
))
2600 (put-text-property s
(1- (point)) 'face
2601 (if (member wd org-agenda-weekend-days
)
2602 'org-agenda-date-weekend
2604 (put-text-property s
(1- (point)) 'org-date-line t
)
2606 (put-text-property s
(1- (point)) 'org-today t
))
2607 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2608 (put-text-property s
(1- (point)) 'day d
)))))
2609 (goto-char (point-min))
2610 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2612 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2613 (org-finalize-agenda)
2614 (setq buffer-read-only t
)))
2616 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2617 "Return a list of all relevant day numbers from BEG to END buffer positions.
2618 If NO-RANGES is non-nil, include only the start and end dates of a range,
2619 not every single day in the range. If FORCE-TODAY is non-nil, make
2620 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2621 inactive time stamps (those in square brackets) are included.
2622 When EMPTY is non-nil, also include days without any entries."
2624 (if pre-re pre-re
"")
2625 (if inactive org-ts-regexp-both org-ts-regexp
)))
2626 dates dates1 date day day1 day2 ts1 ts2
)
2628 (setq dates
(list (time-to-days (current-time)))))
2631 (while (re-search-forward re end t
)
2632 (setq day
(time-to-days (org-time-string-to-time
2633 (substring (match-string 1) 0 10))))
2634 (or (memq day dates
) (push day dates
)))
2637 (while (re-search-forward org-tr-regexp end t
)
2638 (setq ts1
(substring (match-string 1) 0 10)
2639 ts2
(substring (match-string 2) 0 10)
2640 day1
(time-to-days (org-time-string-to-time ts1
))
2641 day2
(time-to-days (org-time-string-to-time ts2
)))
2642 (while (< (setq day1
(1+ day1
)) day2
)
2643 (or (memq day1 dates
) (push day1 dates
)))))
2644 (setq dates
(sort dates
'<))
2646 (while (setq day
(pop dates
))
2647 (setq day2
(car dates
))
2649 (when (and day2 empty
)
2650 (if (or (eq empty t
)
2651 (and (numberp empty
) (<= (- day2 day
) empty
)))
2652 (while (< (setq day
(1+ day
)) day2
)
2653 (push (list day
) dates1
))
2654 (push (cons :omitted
(- day2 day
)) dates1
))))
2655 (setq dates
(nreverse dates1
)))
2658 ;;; Agenda Daily/Weekly
2660 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2661 (defvar org-agenda-start-day nil
; dynamically scoped parameter
2662 "Custom commands can set this variable in the options section.")
2663 (defvar org-agenda-last-arguments nil
2664 "The arguments of the previous call to org-agenda")
2665 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2666 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2667 (defvar org-include-all-loc nil
) ; local variable
2668 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2671 (defun org-agenda-list (&optional include-all start-day ndays
)
2672 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2673 The view will be for the current day or week, but from the overview buffer
2674 you will be able to go to other days/weeks.
2676 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2677 all unfinished TODO items will also be shown, before the agenda.
2678 This feature is considered obsolete, please use the TODO list or a block
2681 With a numeric prefix argument in an interactive call, the agenda will
2682 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2683 the number of days. NDAYS defaults to `org-agenda-ndays'.
2685 START-DAY defaults to TODAY, or to the most recent match for the weekday
2686 given in `org-agenda-start-on-weekday'."
2688 (if (and (integerp include-all
) (> include-all
0))
2689 (setq ndays include-all include-all nil
))
2690 (setq ndays
(or ndays org-agenda-ndays
)
2691 start-day
(or start-day org-agenda-start-day
))
2692 (if org-agenda-overriding-arguments
2693 (setq include-all
(car org-agenda-overriding-arguments
)
2694 start-day
(nth 1 org-agenda-overriding-arguments
)
2695 ndays
(nth 2 org-agenda-overriding-arguments
)))
2696 (if (stringp start-day
)
2697 ;; Convert to an absolute day number
2698 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2699 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2700 (org-compile-prefix-format 'agenda
)
2701 (org-set-sorting-strategy 'agenda
)
2703 (let* ((org-agenda-start-on-weekday
2704 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2705 org-agenda-start-on-weekday nil
))
2706 (thefiles (org-agenda-files nil
'ifmode
))
2708 (today (time-to-days
2709 (time-subtract (current-time)
2710 (list 0 (* 3600 org-extend-today-until
) 0))))
2711 (sd (or start-day today
))
2712 (start (if (or (null org-agenda-start-on-weekday
)
2713 (< org-agenda-ndays
7))
2715 (let* ((nt (calendar-day-of-week
2716 (calendar-gregorian-from-absolute sd
)))
2717 (n1 org-agenda-start-on-weekday
)
2719 (- sd
(+ (if (< d
0) 7 0) d
)))))
2720 (day-numbers (list start
))
2722 (inhibit-redisplay (not debug-on-error
))
2723 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2724 clocktable-start clocktable-end
)
2725 (setq org-agenda-redo-command
2726 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2727 ;; Make the list of days
2728 (setq ndays
(or ndays org-agenda-ndays
)
2731 (push (1+ (car day-numbers
)) day-numbers
)
2732 (setq ndays
(1- ndays
)))
2733 (setq day-numbers
(nreverse day-numbers
))
2734 (setq clocktable-start
(car day-numbers
)
2735 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2736 (org-prepare-agenda "Day/Week")
2737 (org-set-local 'org-starting-day
(car day-numbers
))
2738 (org-set-local 'org-include-all-loc include-all
)
2739 (org-set-local 'org-agenda-span
2740 (org-agenda-ndays-to-span nd
))
2741 (when (and (or include-all org-agenda-include-all-todo
)
2742 (member today day-numbers
))
2743 (setq files thefiles
2745 (while (setq file
(pop files
))
2747 (org-check-agenda-file file
)
2748 (setq date
(calendar-gregorian-from-absolute today
)
2749 rtn
(org-agenda-get-day-entries
2751 (setq rtnall
(append rtnall rtn
))))
2753 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2754 (add-text-properties (point-min) (1- (point))
2755 (list 'face
'org-agenda-structure
))
2756 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2757 (unless org-agenda-compact-blocks
2758 (let* ((d1 (car day-numbers
))
2759 (d2 (org-last day-numbers
))
2760 (w1 (org-days-to-iso-week d1
))
2761 (w2 (org-days-to-iso-week d2
)))
2763 (if org-agenda-overriding-header
2764 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2765 nil
'face
'org-agenda-structure
) "\n")
2766 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2768 (if (< (- d2 d1
) 350)
2770 (format " (W%02d)" w1
)
2771 (format " (W%02d-W%02d)" w1 w2
))
2774 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2776 (while (setq d
(pop day-numbers
))
2777 (setq date
(calendar-gregorian-from-absolute d
)
2778 wd
(calendar-day-of-week date
)
2780 (if (or (setq todayp
(= d today
))
2781 (and (not start-pos
) (= d sd
)))
2782 (setq start-pos
(point))
2783 (if (and start-pos
(not end-pos
))
2784 (setq end-pos
(point))))
2785 (setq files thefiles
2787 (while (setq file
(pop files
))
2789 (org-check-agenda-file file
)
2791 ((eq org-agenda-show-log
'only
)
2792 (setq rtn
(org-agenda-get-day-entries
2793 file date
:closed
)))
2794 (org-agenda-show-log
2795 (setq rtn
(org-agenda-get-day-entries
2797 :deadline
:scheduled
:timestamp
:sexp
:closed
)))
2799 (setq rtn
(org-agenda-get-day-entries
2801 :deadline
:scheduled
:sexp
:timestamp
))))
2802 (setq rtnall
(append rtnall rtn
))))
2803 (if org-agenda-include-diary
2804 (let ((org-agenda-search-headline-for-time t
))
2805 (require 'diary-lib
)
2806 (setq rtn
(org-get-entries-from-diary date
))
2807 (setq rtnall
(append rtnall rtn
))))
2808 (if (or rtnall org-agenda-show-all-dates
)
2810 (setq day-cnt
(1+ day-cnt
))
2812 (if (stringp org-agenda-format-date
)
2813 (format-time-string org-agenda-format-date
2814 (org-time-from-absolute date
))
2815 (funcall org-agenda-format-date date
))
2817 (put-text-property s
(1- (point)) 'face
2818 (if (member wd org-agenda-weekend-days
)
2819 'org-agenda-date-weekend
2821 (put-text-property s
(1- (point)) 'org-date-line t
)
2822 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2824 (put-text-property s
(1- (point)) 'org-today t
)
2825 (put-text-property s
(1- (point)) 'face
'org-agenda-date-today
))
2827 (org-finalize-agenda-entries
2828 (org-agenda-add-time-grid-maybe
2831 (put-text-property s
(1- (point)) 'day d
)
2832 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2833 (when (and org-agenda-clockreport-mode clocktable-start
)
2834 (let ((org-agenda-files (org-agenda-files nil
'ifmode
))
2835 ;; the above line is to ensure the restricted range!
2836 (p org-agenda-clockreport-parameter-plist
)
2838 (setq p
(org-plist-delete p
:block
))
2839 (setq p
(plist-put p
:tstart clocktable-start
))
2840 (setq p
(plist-put p
:tend clocktable-end
))
2841 (setq p
(plist-put p
:scope
'agenda
))
2842 (setq tbl
(apply 'org-get-clocktable p
))
2844 (goto-char (point-min))
2845 (or org-agenda-multi
(org-fit-agenda-window))
2846 (unless (and (pos-visible-in-window-p (point-min))
2847 (pos-visible-in-window-p (point-max)))
2848 (goto-char (1- (point-max)))
2850 (if (not (pos-visible-in-window-p (or start-pos
1)))
2852 (goto-char (or start-pos
1))
2854 (goto-char (or start-pos
1))
2855 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2856 (org-finalize-agenda)
2857 (setq buffer-read-only t
)
2860 (defun org-agenda-ndays-to-span (n)
2861 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2863 ;;; Agenda word search
2865 (defvar org-agenda-search-history nil
)
2866 (defvar org-todo-only nil
)
2868 (defvar org-search-syntax-table nil
2869 "Special syntax table for org-mode search.
2870 In this table, we have single quotes not as word constituents, to
2871 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
2873 (defun org-search-syntax-table ()
2874 (unless org-search-syntax-table
2875 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2876 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2877 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2878 org-search-syntax-table
)
2881 (defun org-search-view (&optional todo-only string edit-at
)
2882 "Show all entries that contain words or regular expressions.
2883 If the first character of the search string is an asterisks,
2884 search only the headlines.
2886 With optional prefix argument TODO-ONLY, only consider entries that are
2887 TODO entries. The argument STRING can be used to pass a default search
2888 string into this function. If EDIT-AT is non-nil, it means that the
2889 user should get a chance to edit this string, with cursor at position
2892 The search string is broken into \"words\" by splitting at whitespace.
2893 The individual words are then interpreted as a boolean expression with
2894 logical AND. Words prefixed with a minus must not occur in the entry.
2895 Words without a prefix or prefixed with a plus must occur in the entry.
2896 Matching is case-insensitive and the words are enclosed by word delimiters.
2898 Words enclosed by curly braces are interpreted as regular expressions
2899 that must or must not match in the entry.
2901 If the search string starts with an asterisk, search only in headlines.
2902 If (possibly after the leading star) the search string starts with an
2903 exclamation mark, this also means to look at TODO entries only, an effect
2904 that can also be achieved with a prefix argument.
2906 This command searches the agenda files, and in addition the files listed
2907 in `org-agenda-text-search-extra-files'."
2909 (org-compile-prefix-format 'search
)
2910 (org-set-sorting-strategy 'search
)
2911 (org-prepare-agenda "SEARCH")
2912 (let* ((props (list 'face nil
2913 'done-face
'org-agenda-done
2914 'org-not-done-regexp org-not-done-regexp
2915 'org-todo-regexp org-todo-regexp
2916 'org-complex-heading-regexp org-complex-heading-regexp
2917 'mouse-face
'highlight
2918 'keymap org-agenda-keymap
2919 'help-echo
(format "mouse-2 or RET jump to location")))
2920 regexp rtn rtnall files file pos
2921 marker category tags c neg re
2922 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2923 (unless (and (not edit-at
)
2925 (string-match "\\S-" string
))
2926 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2928 ((integerp edit-at
) (cons string edit-at
))
2930 'org-agenda-search-history
)))
2931 (org-set-local 'org-todo-only todo-only
)
2932 (setq org-agenda-redo-command
2933 (list 'org-search-view
(if todo-only t nil
) string
2934 '(if current-prefix-arg
1 nil
)))
2935 (setq org-agenda-query-string string
)
2937 (if (equal (string-to-char string
) ?
*)
2939 words
(substring string
1))
2940 (setq words string
))
2941 (when (equal (string-to-char words
) ?
!)
2943 words
(substring words
1)))
2944 (setq words
(org-split-string words
))
2946 (setq c
(string-to-char w
))
2948 (setq neg t w
(substring w
1))
2950 (setq neg nil w
(substring w
1))
2952 (if (string-match "\\`{.*}\\'" w
)
2953 (setq re
(substring w
1 -
1))
2954 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2955 (if neg
(push re regexps-
) (push re regexps
+)))
2957 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2959 (setq regexp
(concat "^" org-outline-regexp
))
2960 (setq regexp
(pop regexps
+))
2961 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2963 (setq files
(org-agenda-files nil
'ifmode
))
2964 (when (eq (car org-agenda-text-search-extra-files
) 'agenda-archives
)
2965 (pop org-agenda-text-search-extra-files
)
2966 (setq files
(org-add-archive-files files
)))
2967 (setq files
(append files org-agenda-text-search-extra-files
)
2969 (while (setq file
(pop files
))
2972 (org-check-agenda-file file
)
2973 (setq buffer
(if (file-exists-p file
)
2974 (org-get-agenda-file-buffer file
)
2975 (error "No such file %s" file
)))
2977 ;; If file does not exist, make sure an error message is sent
2978 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2980 (with-current-buffer buffer
2981 (with-syntax-table (org-search-syntax-table)
2982 (unless (org-mode-p)
2983 (error "Agenda file %s is not in `org-mode'" file
))
2984 (let ((case-fold-search t
))
2987 (if org-agenda-restrict
2988 (narrow-to-region org-agenda-restrict-begin
2989 org-agenda-restrict-end
)
2991 (goto-char (point-min))
2992 (unless (or (org-on-heading-p)
2993 (outline-next-heading))
2994 (throw 'nextfile t
))
2995 (goto-char (max (point-min) (1- (point))))
2996 (while (re-search-forward regexp nil t
)
2997 (org-back-to-heading t
)
2998 (skip-chars-forward "* ")
2999 (setq beg
(point-at-bol)
3001 end
(progn (outline-next-heading) (point)))
3005 (setq str
(buffer-substring-no-properties
3007 (if hdl-only
(point-at-eol) end
)))
3008 (mapc (lambda (wr) (when (string-match wr str
)
3009 (goto-char (1- end
))
3012 (mapc (lambda (wr) (unless (string-match wr str
)
3013 (goto-char (1- end
))
3016 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
3020 (setq marker
(org-agenda-new-marker (point))
3021 category
(org-get-category)
3022 tags
(org-get-tags-at (point))
3023 txt
(org-format-agenda-item
3025 (buffer-substring-no-properties
3026 beg1
(point-at-eol))
3028 (org-add-props txt props
3029 'org-marker marker
'org-hd-marker marker
3030 'org-todo-regexp org-todo-regexp
3031 'org-complex-heading-regexp org-complex-heading-regexp
3032 'priority
1000 'org-category category
3035 (goto-char (1- end
))))))))))
3036 (setq rtn
(nreverse ee
))
3037 (setq rtnall
(append rtnall rtn
)))
3038 (if org-agenda-overriding-header
3039 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3040 nil
'face
'org-agenda-structure
) "\n")
3041 (insert "Search words: ")
3042 (add-text-properties (point-min) (1- (point))
3043 (list 'face
'org-agenda-structure
))
3045 (insert string
"\n")
3046 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3048 (unless org-agenda-multi
3049 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3050 (add-text-properties pos
(1- (point))
3051 (list 'face
'org-agenda-structure
))))
3053 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3054 (goto-char (point-min))
3055 (or org-agenda-multi
(org-fit-agenda-window))
3056 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
3057 (org-finalize-agenda)
3058 (setq buffer-read-only t
)))
3060 ;;; Agenda TODO list
3062 (defvar org-select-this-todo-keyword nil
)
3063 (defvar org-last-arg nil
)
3066 (defun org-todo-list (arg)
3067 "Show all TODO entries from all agenda file in a single list.
3068 The prefix arg can be used to select a specific TODO keyword and limit
3069 the list to these. When using \\[universal-argument], you will be prompted
3070 for a keyword. A numeric prefix directly selects the Nth keyword in
3071 `org-todo-keywords-1'."
3074 (org-compile-prefix-format 'todo
)
3075 (org-set-sorting-strategy 'todo
)
3076 (org-prepare-agenda "TODO")
3077 (let* ((today (time-to-days (current-time)))
3078 (date (calendar-gregorian-from-absolute today
))
3079 (kwds org-todo-keywords-for-agenda
)
3080 (completion-ignore-case t
)
3081 (org-select-this-todo-keyword
3082 (if (stringp arg
) arg
3083 (and arg
(integerp arg
) (> arg
0)
3084 (nth (1- arg
) kwds
))))
3085 rtn rtnall files file pos
)
3086 (when (equal arg
'(4))
3087 (setq org-select-this-todo-keyword
3088 (org-ido-completing-read "Keyword (or KWD1|K2D2|...): "
3089 (mapcar 'list kwds
) nil nil
)))
3090 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
3091 (org-set-local 'org-last-arg arg
)
3092 (setq org-agenda-redo-command
3093 '(org-todo-list (or current-prefix-arg org-last-arg
)))
3094 (setq files
(org-agenda-files nil
'ifmode
)
3096 (while (setq file
(pop files
))
3098 (org-check-agenda-file file
)
3099 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
3100 (setq rtnall
(append rtnall rtn
))))
3101 (if org-agenda-overriding-header
3102 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3103 nil
'face
'org-agenda-structure
) "\n")
3104 (insert "Global list of TODO items of type: ")
3105 (add-text-properties (point-min) (1- (point))
3106 (list 'face
'org-agenda-structure
))
3108 (insert (or org-select-this-todo-keyword
"ALL") "\n")
3109 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3111 (unless org-agenda-multi
3112 (insert "Available with `N r': (0)ALL")
3115 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
3116 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
3121 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3123 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3124 (goto-char (point-min))
3125 (or org-agenda-multi
(org-fit-agenda-window))
3126 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
3127 (org-finalize-agenda)
3128 (setq buffer-read-only t
)))
3130 ;;; Agenda tags match
3133 (defun org-tags-view (&optional todo-only match
)
3134 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3135 The prefix arg TODO-ONLY limits the search to TODO entries."
3137 (org-compile-prefix-format 'tags
)
3138 (org-set-sorting-strategy 'tags
)
3139 (let* ((org-tags-match-list-sublevels
3140 (if todo-only t org-tags-match-list-sublevels
))
3141 (completion-ignore-case t
)
3142 rtn rtnall files file pos matcher
3144 (setq matcher
(org-make-tags-matcher match
)
3145 match
(car matcher
) matcher
(cdr matcher
))
3146 (org-prepare-agenda (concat "TAGS " match
))
3147 (setq org-agenda-query-string match
)
3148 (setq org-agenda-redo-command
3149 (list 'org-tags-view
(list 'quote todo-only
)
3150 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
3151 (setq files
(org-agenda-files nil
'ifmode
)
3153 (while (setq file
(pop files
))
3155 (org-check-agenda-file file
)
3156 (setq buffer
(if (file-exists-p file
)
3157 (org-get-agenda-file-buffer file
)
3158 (error "No such file %s" file
)))
3160 ;; If file does not exist, error message to agenda
3162 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3163 rtnall
(append rtnall rtn
))
3164 (with-current-buffer buffer
3165 (unless (org-mode-p)
3166 (error "Agenda file %s is not in `org-mode'" file
))
3169 (if org-agenda-restrict
3170 (narrow-to-region org-agenda-restrict-begin
3171 org-agenda-restrict-end
)
3173 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
3174 (setq rtnall
(append rtnall rtn
))))))))
3175 (if org-agenda-overriding-header
3176 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3177 nil
'face
'org-agenda-structure
) "\n")
3178 (insert "Headlines with TAGS match: ")
3179 (add-text-properties (point-min) (1- (point))
3180 (list 'face
'org-agenda-structure
))
3183 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3185 (unless org-agenda-multi
3186 (insert "Press `C-u r' to search again with new search string\n"))
3187 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3189 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3190 (goto-char (point-min))
3191 (or org-agenda-multi
(org-fit-agenda-window))
3192 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
3193 (org-finalize-agenda)
3194 (setq buffer-read-only t
)))
3196 ;;; Agenda Finding stuck projects
3198 (defvar org-agenda-skip-regexp nil
3199 "Regular expression used in skipping subtrees for the agenda.
3200 This is basically a temporary global variable that can be set and then
3201 used by user-defined selections using `org-agenda-skip-function'.")
3203 (defvar org-agenda-overriding-header nil
3204 "When this is set during todo and tags searches, will replace header.
3205 This variable should not be set directly, but custom commands can bind it
3206 in the options section.")
3208 (defun org-agenda-skip-entry-when-regexp-matches ()
3209 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3210 If yes, it returns the end position of this entry, causing agenda commands
3211 to skip the entry but continuing the search in the subtree. This is a
3212 function that can be put into `org-agenda-skip-function' for the duration
3214 (let ((end (save-excursion (org-end-of-subtree t
)))
3217 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3220 (defun org-agenda-skip-subtree-when-regexp-matches ()
3221 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3222 If yes, it returns the end position of this tree, causing agenda commands
3223 to skip this subtree. This is a function that can be put into
3224 `org-agenda-skip-function' for the duration of a command."
3225 (let ((end (save-excursion (org-end-of-subtree t
)))
3228 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3231 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3232 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3233 If yes, it returns the end position of the current entry (NOT the tree),
3234 causing agenda commands to skip the entry but continuing the search in
3235 the subtree. This is a function that can be put into
3236 `org-agenda-skip-function' for the duration of a command. An important
3237 use of this function is for the stuck project list."
3238 (let ((end (save-excursion (org-end-of-subtree t
)))
3239 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3242 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3243 (and skip entry-end
)))
3245 (defun org-agenda-skip-entry-if (&rest conditions
)
3246 "Skip entry if any of CONDITIONS is true.
3247 See `org-agenda-skip-if' for details."
3248 (org-agenda-skip-if nil conditions
))
3250 (defun org-agenda-skip-subtree-if (&rest conditions
)
3251 "Skip entry if any of CONDITIONS is true.
3252 See `org-agenda-skip-if' for details."
3253 (org-agenda-skip-if t conditions
))
3255 (defun org-agenda-skip-if (subtree conditions
)
3256 "Checks current entity for CONDITIONS.
3257 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3258 the entry, i.e. the text before the next heading is checked.
3260 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3261 from different tests. Valid conditions are:
3263 scheduled Check if there is a scheduled cookie
3264 notscheduled Check if there is no scheduled cookie
3265 deadline Check if there is a deadline
3266 notdeadline Check if there is no deadline
3267 timestamp Check if there is a timestamp (also deadline or scheduled)
3268 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3269 regexp Check if regexp matches
3270 notregexp Check if regexp does not match.
3272 The regexp is taken from the conditions list, it must come right after
3273 the `regexp' or `notregexp' element.
3275 If any of these conditions is met, this function returns the end point of
3276 the entity, causing the search to continue from there. This is a function
3277 that can be put into `org-agenda-skip-function' for the duration of a command."
3279 (org-back-to-heading t
)
3282 (progn (org-end-of-subtree t
) (point))
3283 (progn (outline-next-heading) (1- (point)))))
3287 (and (memq 'scheduled conditions
)
3288 (re-search-forward org-scheduled-time-regexp end t
))
3289 (and (memq 'notscheduled conditions
)
3290 (not (re-search-forward org-scheduled-time-regexp end t
)))
3291 (and (memq 'deadline conditions
)
3292 (re-search-forward org-deadline-time-regexp end t
))
3293 (and (memq 'notdeadline conditions
)
3294 (not (re-search-forward org-deadline-time-regexp end t
)))
3295 (and (memq 'timestamp conditions
)
3296 (re-search-forward org-ts-regexp end t
))
3297 (and (memq 'nottimestamp conditions
)
3298 (not (re-search-forward org-ts-regexp end t
)))
3299 (and (setq m
(memq 'regexp conditions
))
3301 (re-search-forward (nth 1 m
) end t
))
3302 (and (setq m
(memq 'notregexp conditions
))
3304 (not (re-search-forward (nth 1 m
) end t
))))
3308 (defun org-agenda-list-stuck-projects (&rest ignore
)
3309 "Create agenda view for projects that are stuck.
3310 Stuck projects are project that have no next actions. For the definitions
3311 of what a project is and how to check if it stuck, customize the variable
3312 `org-stuck-projects'.
3313 MATCH is being ignored."
3315 (let* ((org-agenda-skip-function
3316 'org-agenda-skip-entry-when-regexp-matches-in-subtree
)
3317 ;; We could have used org-agenda-skip-if here.
3318 (org-agenda-overriding-header "List of stuck projects: ")
3319 (matcher (nth 0 org-stuck-projects
))
3320 (todo (nth 1 org-stuck-projects
))
3321 (todo-wds (if (member "*" todo
)
3323 (org-prepare-agenda-buffers (org-agenda-files
3326 org-done-keywords-for-agenda
3327 (copy-sequence org-todo-keywords-for-agenda
)))
3329 (todo-re (concat "^\\*+[ \t]+\\("
3330 (mapconcat 'identity todo-wds
"\\|")
3332 (tags (nth 2 org-stuck-projects
))
3333 (tags-re (if (member "*" tags
)
3334 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3336 (concat "^\\*+ .*:\\("
3337 (mapconcat 'identity tags
"\\|")
3338 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3339 (gen-re (nth 3 org-stuck-projects
))
3345 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
3347 (setq org-agenda-skip-regexp
3349 (mapconcat 'identity re-list
"\\|")
3350 (error "No information how to identify unstuck projects")))
3351 (org-tags-view nil matcher
)
3352 (with-current-buffer org-agenda-buffer-name
3353 (setq org-agenda-redo-command
3354 '(org-agenda-list-stuck-projects
3355 (or current-prefix-arg org-last-arg
))))))
3357 ;;; Diary integration
3359 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
3360 (defvar list-diary-entries-hook
)
3362 (defun org-get-entries-from-diary (date)
3363 "Get the (Emacs Calendar) diary entries for DATE."
3364 (require 'diary-lib
)
3365 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3366 (fancy-diary-buffer diary-fancy-buffer
)
3367 (diary-display-hook '(fancy-diary-display))
3368 (diary-display-function 'fancy-diary-display
)
3370 (list-diary-entries-hook
3371 (cons 'org-diary-default-entry list-diary-entries-hook
))
3372 (diary-file-name-prefix-function nil
) ; turn this feature off
3373 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
3375 (org-disable-agenda-to-diary t
))
3377 (save-window-excursion
3378 (funcall (if (fboundp 'diary-list-entries
)
3379 'diary-list-entries
'list-diary-entries
)
3381 (if (not (get-buffer diary-fancy-buffer
))
3383 (with-current-buffer diary-fancy-buffer
3384 (setq buffer-read-only nil
)
3385 (if (zerop (buffer-size))
3388 ;; Omit the date and other unnecessary stuff
3389 (org-agenda-cleanup-fancy-diary)
3390 ;; Add prefix to each line and extend the text properties
3391 (if (zerop (buffer-size))
3393 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
3394 (set-buffer-modified-p nil
)
3395 (kill-buffer diary-fancy-buffer
)))
3397 (setq entries
(org-split-string entries
"\n"))
3401 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
3402 ;; Extend the text properties to the beginning of the line
3403 (org-add-props x
(text-properties-at (1- (length x
)) x
)
3404 'type
"diary" 'date date
))
3407 (defvar org-agenda-cleanup-fancy-diary-hook nil
3408 "Hook run when the fancy diary buffer is cleaned up.")
3410 (defun org-agenda-cleanup-fancy-diary ()
3411 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3412 This gets rid of the date, the underline under the date, and
3413 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3414 date. It also removes lines that contain only whitespace."
3415 (goto-char (point-min))
3416 (if (looking-at ".*?:[ \t]*")
3419 (re-search-forward "\n=+$" nil t
)
3421 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
3422 (re-search-forward "\n=+$" nil t
)
3423 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3424 (goto-char (point-min))
3425 (while (re-search-forward "^ +\n" nil t
)
3427 (goto-char (point-min))
3428 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
3430 (run-hooks 'org-agenda-cleanup-fancy-diary-hook
))
3432 ;; Make sure entries from the diary have the right text properties.
3433 (eval-after-load "diary-lib"
3434 '(if (boundp 'diary-modify-entry-list-string-function
)
3435 ;; We can rely on the hook, nothing to do
3437 ;; Hook not available, must use advice to make this work
3438 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
3439 "Make the position visible."
3440 (if (and org-disable-agenda-to-diary
;; called from org-agenda
3443 (setq string
(org-modify-diary-entry-string string
))))))
3445 (defun org-modify-diary-entry-string (string)
3446 "Add text properties to string, allowing org-mode to act on it."
3447 (org-add-props string nil
3448 'mouse-face
'highlight
3449 'keymap org-agenda-keymap
3450 'help-echo
(if buffer-file-name
3451 (format "mouse-2 or RET jump to diary file %s"
3452 (abbreviate-file-name buffer-file-name
))
3454 'org-agenda-diary-link t
3455 'org-marker
(org-agenda-new-marker (point-at-bol))))
3457 (defun org-diary-default-entry ()
3458 "Add a dummy entry to the diary.
3459 Needed to avoid empty dates which mess up holiday display."
3460 ;; Catch the error if dealing with the new add-to-diary-alist
3461 (when org-disable-agenda-to-diary
3463 (org-add-to-diary-list original-date
"Org-mode dummy" "")
3465 (org-add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
3467 (defun org-add-to-diary-list (&rest args
)
3468 (if (fboundp 'diary-add-to-list
)
3469 (apply 'diary-add-to-list args
)
3470 (apply 'add-to-diary-list args
)))
3473 (defun org-diary (&rest args
)
3474 "Return diary information from org-files.
3475 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3476 It accesses org files and extracts information from those files to be
3477 listed in the diary. The function accepts arguments specifying what
3478 items should be listed. The following arguments are allowed:
3480 :timestamp List the headlines of items containing a date stamp or
3481 date range matching the selected date. Deadlines will
3482 also be listed, on the expiration day.
3484 :sexp List entries resulting from diary-like sexps.
3486 :deadline List any deadlines past due, or due within
3487 `org-deadline-warning-days'. The listing occurs only
3488 in the diary for *today*, not at any other date. If
3489 an entry is marked DONE, it is no longer listed.
3491 :scheduled List all items which are scheduled for the given date.
3492 The diary for *today* also contains items which were
3493 scheduled earlier and are not yet marked DONE.
3495 :todo List all TODO items from the org-file. This may be a
3496 long list - so this is not turned on by default.
3497 Like deadlines, these entries only show up in the
3498 diary for *today*, not at any other date.
3500 The call in the diary file should look like this:
3502 &%%(org-diary) ~/path/to/some/orgfile.org
3504 Use a separate line for each org file to check. Or, if you omit the file name,
3505 all files listed in `org-agenda-files' will be checked automatically:
3509 If you don't give any arguments (as in the example above), the default
3510 arguments (:deadline :scheduled :timestamp :sexp) are used.
3511 So the example above may also be written as
3513 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3515 The function expects the lisp variables `entry' and `date' to be provided
3516 by the caller, because this is how the calendar works. Don't use this
3517 function from a program - use `org-agenda-get-day-entries' instead."
3518 (when (> (- (time-to-seconds (current-time))
3519 org-agenda-last-marker-time
)
3521 (org-agenda-reset-markers))
3522 (org-compile-prefix-format 'agenda
)
3523 (org-set-sorting-strategy 'agenda
)
3524 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3525 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
3527 (org-agenda-files t
)))
3529 (org-prepare-agenda-buffers files
)
3530 ;; If this is called during org-agenda, don't return any entries to
3531 ;; the calendar. Org Agenda will list these entries itself.
3532 (if org-disable-agenda-to-diary
(setq files nil
))
3533 (while (setq file
(pop files
))
3534 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
3535 (setq results
(append results rtn
)))
3537 (concat (org-finalize-agenda-entries results
) "\n"))))
3539 ;;; Agenda entry finders
3541 (defun org-agenda-get-day-entries (file date
&rest args
)
3542 "Does the work for `org-diary' and `org-agenda'.
3543 FILE is the path to a file to be checked for entries. DATE is date like
3544 the one returned by `calendar-current-date'. ARGS are symbols indicating
3545 which kind of entries should be extracted. For details about these, see
3546 the documentation of `org-diary'."
3547 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3548 (let* ((org-startup-folded nil
)
3549 (org-startup-align-all-tables nil
)
3550 (buffer (if (file-exists-p file
)
3551 (org-get-agenda-file-buffer file
)
3552 (error "No such file %s" file
)))
3555 ;; If file does not exist, make sure an error message ends up in diary
3556 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3557 (with-current-buffer buffer
3558 (unless (org-mode-p)
3559 (error "Agenda file %s is not in `org-mode'" file
))
3560 (let ((case-fold-search nil
))
3563 (if org-agenda-restrict
3564 (narrow-to-region org-agenda-restrict-begin
3565 org-agenda-restrict-end
)
3567 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3568 (while (setq arg
(pop args
))
3570 ((and (eq arg
:todo
)
3571 (equal date
(calendar-current-date)))
3572 (setq rtn
(org-agenda-get-todos))
3573 (setq results
(append results rtn
)))
3574 ((eq arg
:timestamp
)
3575 (setq rtn
(org-agenda-get-blocks))
3576 (setq results
(append results rtn
))
3577 (setq rtn
(org-agenda-get-timestamps))
3578 (setq results
(append results rtn
)))
3580 (setq rtn
(org-agenda-get-sexps))
3581 (setq results
(append results rtn
)))
3582 ((eq arg
:scheduled
)
3583 (setq rtn
(org-agenda-get-scheduled))
3584 (setq results
(append results rtn
)))
3586 (setq rtn
(org-agenda-get-progress))
3587 (setq results
(append results rtn
)))
3589 (setq rtn
(org-agenda-get-deadlines))
3590 (setq results
(append results rtn
))))))))
3593 (defun org-agenda-get-todos ()
3594 "Return the TODO information for agenda display."
3595 (let* ((props (list 'face nil
3596 'done-face
'org-agenda-done
3597 'org-not-done-regexp org-not-done-regexp
3598 'org-todo-regexp org-todo-regexp
3599 'org-complex-heading-regexp org-complex-heading-regexp
3600 'mouse-face
'highlight
3601 'keymap org-agenda-keymap
3603 (format "mouse-2 or RET jump to org file %s"
3604 (abbreviate-file-name buffer-file-name
))))
3605 (regexp (concat "^\\*+[ \t]+\\("
3606 (if org-select-this-todo-keyword
3607 (if (equal org-select-this-todo-keyword
"*")
3610 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3612 org-not-done-regexp
)
3614 marker priority category tags todo-state
3616 (goto-char (point-min))
3617 (while (re-search-forward regexp nil t
)
3621 (setq beg
(point) end
(save-excursion (outline-next-heading) (point)))
3622 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end
)
3623 (goto-char (1+ beg
))
3624 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3628 (goto-char (match-beginning 1))
3629 (setq marker
(org-agenda-new-marker (match-beginning 0))
3630 category
(org-get-category)
3631 txt
(match-string 1)
3632 tags
(org-get-tags-at (point))
3633 txt
(org-format-agenda-item "" txt category tags
)
3634 priority
(1+ (org-get-priority txt
))
3635 todo-state
(org-get-todo-state))
3636 (org-add-props txt props
3637 'org-marker marker
'org-hd-marker marker
3638 'priority priority
'org-category category
3639 'type
"todo" 'todo-state todo-state
)
3641 (if org-agenda-todo-list-sublevels
3642 (goto-char (match-end 1))
3643 (org-end-of-subtree 'invisible
))))
3647 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end
)
3648 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3649 (when (or org-agenda-todo-ignore-with-date
3650 org-agenda-todo-ignore-scheduled
3651 org-agenda-todo-ignore-deadlines
)
3652 (setq end
(or end
(save-excursion (outline-next-heading) (point))))
3654 (or (and org-agenda-todo-ignore-with-date
3655 (re-search-forward org-ts-regexp end t
))
3656 (and org-agenda-todo-ignore-scheduled
3657 (re-search-forward org-scheduled-time-regexp end t
))
3658 (and org-agenda-todo-ignore-deadlines
3659 (re-search-forward org-deadline-time-regexp end t
)
3660 (org-deadline-close (match-string 1)))))))
3662 (defconst org-agenda-no-heading-message
3663 "No heading for this item in buffer or region.")
3665 (defun org-agenda-get-timestamps ()
3666 "Return the date stamp information for agenda display."
3667 (let* ((props (list 'face nil
3668 'org-not-done-regexp org-not-done-regexp
3669 'org-todo-regexp org-todo-regexp
3670 'org-complex-heading-regexp org-complex-heading-regexp
3671 'mouse-face
'highlight
3672 'keymap org-agenda-keymap
3674 (format "mouse-2 or RET jump to org file %s"
3675 (abbreviate-file-name buffer-file-name
))))
3676 (d1 (calendar-absolute-from-gregorian date
))
3682 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3686 (if org-agenda-include-inactive-timestamps
"[[<]" "<")
3690 (car org-time-stamp-formats
)
3691 (apply 'encode-time
; DATE bound by calendar
3692 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3694 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3695 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3696 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3697 donep tmp priority category ee txt timestr tags b0 b3 e3 head
3698 todo-state end-of-match
)
3699 (goto-char (point-min))
3700 (while (setq end-of-match
(re-search-forward regexp nil t
))
3701 (setq b0
(match-beginning 0)
3702 b3
(match-beginning 3) e3
(match-end 3))
3704 (and (org-at-date-range-p) (throw :skip nil
))
3706 (if (and (match-end 1)
3707 (not (= d1
(org-time-string-to-absolute
3708 (match-string 1) d1 nil
3709 org-agenda-repeating-timestamp-show-all
))))
3712 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3714 (setq tmp
(buffer-substring (max (point-min)
3715 (- b0 org-ds-keyword-length
))
3717 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3718 inactivep
(= (char-after b0
) ?\
[)
3719 deadlinep
(string-match org-deadline-regexp tmp
)
3720 scheduledp
(string-match org-scheduled-regexp tmp
)
3721 closedp
(and org-agenda-include-inactive-timestamps
3722 (string-match org-closed-string tmp
))
3723 clockp
(and org-agenda-include-inactive-timestamps
3724 (or (string-match org-clock-string tmp
)
3725 (string-match "]-+\\'" tmp
)))
3726 todo-state
(org-get-todo-state)
3727 donep
(member todo-state org-done-keywords
))
3728 (if (or scheduledp deadlinep closedp clockp
3729 (and donep org-agenda-skip-timestamp-if-done
))
3731 (if (string-match ">" timestr
)
3732 ;; substring should only run to end of time stamp
3733 (setq timestr
(substring timestr
0 (match-end 0))))
3734 (setq marker
(org-agenda-new-marker b0
)
3735 category
(org-get-category b0
))
3737 (if (not (re-search-backward "^\\*+ " nil t
))
3738 (setq txt org-agenda-no-heading-message
)
3739 (goto-char (match-beginning 0))
3740 (setq hdmarker
(org-agenda-new-marker)
3741 tags
(org-get-tags-at))
3742 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3743 (setq head
(match-string 1))
3744 (setq txt
(org-format-agenda-item
3745 (if inactivep
"[" nil
)
3746 head category tags timestr nil
3748 (setq priority
(org-get-priority txt
))
3749 (org-add-props txt props
3750 'org-marker marker
'org-hd-marker hdmarker
)
3751 (org-add-props txt nil
'priority priority
3752 'org-category category
'date date
3753 'todo-state todo-state
3756 (if org-agenda-skip-additional-timestamps-same-entry
3757 (outline-next-heading)
3758 (goto-char end-of-match
))))
3761 (defun org-agenda-get-sexps ()
3762 "Return the sexp information for agenda display."
3763 (require 'diary-lib
)
3764 (let* ((props (list 'face nil
3765 'mouse-face
'highlight
3766 'keymap org-agenda-keymap
3768 (format "mouse-2 or RET jump to org file %s"
3769 (abbreviate-file-name buffer-file-name
))))
3771 marker category ee txt tags entry result beg b sexp sexp-entry
3773 (goto-char (point-min))
3774 (while (re-search-forward regexp nil t
)
3777 (setq beg
(match-beginning 0))
3778 (goto-char (1- (match-end 0)))
3781 (setq sexp
(buffer-substring b
(point)))
3782 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3783 (org-trim (match-string 1))
3785 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3787 (setq marker
(org-agenda-new-marker beg
)
3788 category
(org-get-category beg
)
3789 todo-state
(org-get-todo-state))
3791 (if (string-match "\\S-" result
)
3793 (setq txt
"SEXP entry returned empty string"))
3795 (setq txt
(org-format-agenda-item
3796 "" txt category tags
'time
))
3797 (org-add-props txt props
'org-marker marker
)
3798 (org-add-props txt nil
3799 'org-category category
'date date
'todo-state todo-state
3804 (defalias 'org-get-closed
'org-agenda-get-progress
)
3805 (defun org-agenda-get-progress ()
3806 "Return the logged TODO entries for agenda display."
3807 (let* ((props (list 'mouse-face
'highlight
3808 'org-not-done-regexp org-not-done-regexp
3809 'org-todo-regexp org-todo-regexp
3810 'org-complex-heading-regexp org-complex-heading-regexp
3811 'keymap org-agenda-keymap
3813 (format "mouse-2 or RET jump to org file %s"
3814 (abbreviate-file-name buffer-file-name
))))
3815 (items (if (consp org-agenda-show-log
)
3817 org-agenda-log-mode-items
))
3821 (if (memq 'closed items
) (concat "\\<" org-closed-string
))
3822 (if (memq 'clock items
) (concat "\\<" org-clock-string
))
3823 (if (memq 'state items
) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
3824 (parts-re (if parts
(mapconcat 'identity parts
"\\|")
3825 (error "`org-agenda-log-mode-items' is empty")))
3827 "\\(" parts-re
"\\)"
3832 (car org-time-stamp-formats
)
3833 (apply 'encode-time
; DATE bound by calendar
3834 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3836 (org-agenda-search-headline-for-time nil
)
3837 marker hdmarker priority category tags closedp statep clockp state
3838 ee txt extra timestr rest clocked
)
3839 (goto-char (point-min))
3840 (while (re-search-forward regexp nil t
)
3843 (setq marker
(org-agenda-new-marker (match-beginning 0))
3844 closedp
(equal (match-string 1) org-closed-string
)
3845 statep
(equal (string-to-char (match-string 1)) ?-
)
3846 clockp
(not (or closedp statep
))
3847 state
(and statep
(match-string 2))
3848 category
(org-get-category (match-beginning 0))
3849 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3851 (when (string-match "\\]" timestr
)
3852 ;; substring should only run to end of time stamp
3853 (setq rest
(substring timestr
(match-end 0))
3854 timestr
(substring timestr
0 (match-end 0)))
3855 (if (and (not closedp
) (not statep
)
3856 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest
))
3857 (progn (setq timestr
(concat (substring timestr
0 -
1)
3858 "-" (match-string 1 rest
) "]"))
3859 (setq clocked
(match-string 2 rest
)))
3860 (setq clocked
"-")))
3863 ((not org-agenda-log-mode-add-notes
) (setq extra nil
))
3865 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
3866 (setq extra
(match-string 1))))
3868 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
3869 (setq extra
(match-string 1))))
3870 (t (setq extra nil
)))
3871 (if (not (re-search-backward "^\\*+ " nil t
))
3872 (setq txt org-agenda-no-heading-message
)
3873 (goto-char (match-beginning 0))
3874 (setq hdmarker
(org-agenda-new-marker)
3875 tags
(org-get-tags-at))
3876 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3877 (setq txt
(match-string 1))
3879 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt
)
3880 (setq txt
(concat (substring txt
0 (match-beginning 1))
3881 " - " extra
" " (match-string 2 txt
)))
3882 (setq txt
(concat txt
" - " extra
))))
3883 (setq txt
(org-format-agenda-item
3885 (closedp "Closed: ")
3886 (statep (concat "State: (" state
")"))
3887 (t (concat "Clocked: (" clocked
")")))
3888 txt category tags timestr
)))
3889 (setq priority
100000)
3890 (org-add-props txt props
3891 'org-marker marker
'org-hd-marker hdmarker
'face
'org-agenda-done
3892 'priority priority
'org-category category
3893 'type
"closed" 'date date
3894 'undone-face
'org-warning
'done-face
'org-agenda-done
)
3896 (goto-char (point-at-eol))))
3899 (defun org-agenda-get-deadlines ()
3900 "Return the deadline information for agenda display."
3901 (let* ((props (list 'mouse-face
'highlight
3902 'org-not-done-regexp org-not-done-regexp
3903 'org-todo-regexp org-todo-regexp
3904 'org-complex-heading-regexp org-complex-heading-regexp
3905 'keymap org-agenda-keymap
3907 (format "mouse-2 or RET jump to org file %s"
3908 (abbreviate-file-name buffer-file-name
))))
3909 (regexp org-deadline-time-regexp
)
3910 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3911 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3912 d2 diff dfrac wdays pos pos1 category tags
3913 ee txt head face s todo-state upcomingp donep timestr
)
3914 (goto-char (point-min))
3915 (while (re-search-forward regexp nil t
)
3918 (setq s
(match-string 1)
3920 pos
(1- (match-beginning 1))
3921 d2
(org-time-string-to-absolute
3922 (match-string 1) d1
'past
3923 org-agenda-repeating-timestamp-show-all
)
3925 wdays
(org-get-wdays s
)
3926 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3927 upcomingp
(and todayp
(> diff
0)))
3928 ;; When to show a deadline in the calendar:
3929 ;; If the expiration is within wdays warning time.
3930 ;; Past-due deadlines are only shown on the current date
3931 (if (or (and (<= diff wdays
)
3932 (and todayp
(not org-agenda-only-exact-dates
)))
3935 (setq todo-state
(org-get-todo-state))
3936 (setq donep
(member todo-state org-done-keywords
))
3938 (or org-agenda-skip-deadline-if-done
3941 (setq category
(org-get-category))
3942 (if (not (re-search-backward "^\\*+[ \t]+" nil t
))
3943 (setq txt org-agenda-no-heading-message
)
3944 (goto-char (match-end 0))
3945 (setq pos1
(match-beginning 0))
3946 (setq tags
(org-get-tags-at pos1
))
3947 (setq head
(buffer-substring-no-properties
3949 (progn (skip-chars-forward "^\r\n")
3951 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3953 (concat (substring s
(match-beginning 1)) " "))
3954 (setq timestr
'time
))
3955 (setq txt
(org-format-agenda-item
3957 (car org-agenda-deadline-leaders
)
3959 (nth 1 org-agenda-deadline-leaders
))
3961 (nth 1 org-agenda-deadline-leaders
)
3963 (format (nth 1 org-agenda-deadline-leaders
)
3966 (if (not (= diff
0)) nil timestr
)))))
3968 (setq face
(org-agenda-deadline-face dfrac wdays
))
3969 (org-add-props txt props
3970 'org-marker
(org-agenda-new-marker pos
)
3971 'org-hd-marker
(org-agenda-new-marker pos1
)
3972 'priority
(+ (- diff
)
3973 (org-get-priority txt
))
3974 'org-category category
3975 'todo-state todo-state
3976 'type
(if upcomingp
"upcoming-deadline" "deadline")
3977 'date
(if upcomingp date d2
)
3978 'face
(if donep
'org-agenda-done face
)
3979 'undone-face face
'done-face
'org-agenda-done
)
3983 (defun org-agenda-deadline-face (fraction &optional wdays
)
3984 "Return the face to displaying a deadline item.
3985 FRACTION is what fraction of the head-warning time has passed."
3986 (if (equal wdays
0) (setq fraction
1.
))
3987 (let ((faces org-agenda-deadline-faces
) f
)
3989 (while (setq f
(pop faces
))
3990 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3992 (defun org-agenda-get-scheduled ()
3993 "Return the scheduled information for agenda display."
3994 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3995 'org-todo-regexp org-todo-regexp
3996 'org-complex-heading-regexp org-complex-heading-regexp
3997 'done-face
'org-agenda-done
3998 'mouse-face
'highlight
3999 'keymap org-agenda-keymap
4001 (format "mouse-2 or RET jump to org file %s"
4002 (abbreviate-file-name buffer-file-name
))))
4003 (regexp org-scheduled-time-regexp
)
4004 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
4005 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
4006 d2 diff pos pos1 category tags donep
4007 ee txt head pastschedp todo-state face timestr s
)
4008 (goto-char (point-min))
4009 (while (re-search-forward regexp nil t
)
4012 (setq s
(match-string 1)
4014 pos
(1- (match-beginning 1))
4015 d2
(org-time-string-to-absolute
4016 (match-string 1) d1
'past
4017 org-agenda-repeating-timestamp-show-all
)
4019 (setq pastschedp
(and todayp
(< diff
0)))
4020 ;; When to show a scheduled item in the calendar:
4021 ;; If it is on or past the date.
4022 (if (or (and (< diff
0)
4023 (< (abs diff
) org-scheduled-past-days
)
4024 (and todayp
(not org-agenda-only-exact-dates
)))
4027 (setq todo-state
(org-get-todo-state))
4028 (setq donep
(member todo-state org-done-keywords
))
4030 (or org-agenda-skip-scheduled-if-done
4033 (setq category
(org-get-category))
4034 (if (not (re-search-backward "^\\*+[ \t]+" nil t
))
4035 (setq txt org-agenda-no-heading-message
)
4036 (goto-char (match-end 0))
4037 (setq pos1
(match-beginning 0))
4038 (setq tags
(org-get-tags-at))
4039 (setq head
(buffer-substring-no-properties
4041 (progn (skip-chars-forward "^\r\n") (point))))
4042 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
4044 (concat (substring s
(match-beginning 1)) " "))
4045 (setq timestr
'time
))
4046 (setq txt
(org-format-agenda-item
4048 (car org-agenda-scheduled-leaders
)
4049 (format (nth 1 org-agenda-scheduled-leaders
)
4052 (if (not (= diff
0)) nil timestr
)))))
4056 (pastschedp 'org-scheduled-previously
)
4057 (todayp 'org-scheduled-today
)
4058 (t 'org-scheduled
)))
4059 (org-add-props txt props
4061 'face
(if donep
'org-agenda-done face
)
4062 'org-marker
(org-agenda-new-marker pos
)
4063 'org-hd-marker
(org-agenda-new-marker pos1
)
4064 'type
(if pastschedp
"past-scheduled" "scheduled")
4065 'date
(if pastschedp d2 date
)
4066 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
4067 'org-category category
4068 'todo-state todo-state
)
4072 (defun org-agenda-get-blocks ()
4073 "Return the date-range information for agenda display."
4074 (let* ((props (list 'face nil
4075 'org-not-done-regexp org-not-done-regexp
4076 'org-todo-regexp org-todo-regexp
4077 'org-complex-heading-regexp org-complex-heading-regexp
4078 'mouse-face
'highlight
4079 'keymap org-agenda-keymap
4081 (format "mouse-2 or RET jump to org file %s"
4082 (abbreviate-file-name buffer-file-name
))))
4083 (regexp org-tr-regexp
)
4084 (d0 (calendar-absolute-from-gregorian date
))
4085 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4087 (goto-char (point-min))
4088 (while (re-search-forward regexp nil t
)
4092 (setq timestr
(match-string 0)
4095 d1
(time-to-days (org-time-string-to-time s1
))
4096 d2
(time-to-days (org-time-string-to-time s2
)))
4097 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
4098 ;; Only allow days between the limits, because the normal
4099 ;; date stamps will catch the limits.
4101 (setq todo-state
(org-get-todo-state))
4102 (setq donep
(member todo-state org-done-keywords
))
4103 (if (and donep org-agenda-skip-timestamp-if-done
)
4105 (setq marker
(org-agenda-new-marker (point)))
4106 (setq category
(org-get-category))
4107 (if (not (re-search-backward "^\\*+ " nil t
))
4108 (setq txt org-agenda-no-heading-message
)
4109 (goto-char (match-beginning 0))
4110 (setq hdmarker
(org-agenda-new-marker (point)))
4111 (setq tags
(org-get-tags-at))
4112 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4113 (setq head
(match-string 1))
4114 (setq txt
(org-format-agenda-item
4116 (nth (if (= d1 d2
) 0 1)
4117 org-agenda-timerange-leaders
)
4118 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
4120 (if (= d0 d1
) timestr
))))
4121 (org-add-props txt props
4122 'org-marker marker
'org-hd-marker hdmarker
4123 'type
"block" 'date date
4124 'todo-state todo-state
4125 'priority
(org-get-priority txt
) 'org-category category
)
4128 ;; Sort the entries by expiration date.
4131 ;;; Agenda presentation and sorting
4133 (defvar org-prefix-has-time nil
4134 "A flag, set by `org-compile-prefix-format'.
4135 The flag is set if the currently compiled format contains a `%t'.")
4136 (defvar org-prefix-has-tag nil
4137 "A flag, set by `org-compile-prefix-format'.
4138 The flag is set if the currently compiled format contains a `%T'.")
4139 (defvar org-prefix-has-effort nil
4140 "A flag, set by `org-compile-prefix-format'.
4141 The flag is set if the currently compiled format contains a `%e'.")
4143 (defun org-format-agenda-item (extra txt
&optional category tags dotime
4145 "Format TXT to be inserted into the agenda buffer.
4146 In particular, it adds the prefix and corresponding text properties. EXTRA
4147 must be a string and replaces the `%s' specifier in the prefix format.
4148 CATEGORY (string, symbol or nil) may be used to overrule the default
4149 category taken from local variable or file name. It will replace the `%c'
4150 specifier in the format. DOTIME, when non-nil, indicates that a
4151 time-of-day should be extracted from TXT for sorting of this entry, and for
4152 the `%t' specifier in the format. When DOTIME is a string, this string is
4153 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4154 only the correctly processes TXT should be returned - this is used by
4155 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4156 Any match of REMOVE-RE will be removed from TXT."
4158 ;; Diary entries sometimes have extra whitespace at the beginning
4159 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
4160 (when org-agenda-show-inherited-tags
4161 ;; Fix the tags part in txt
4162 (setq txt
(org-agenda-add-inherited-tags txt tags
)))
4163 (let* ((category (or category
4165 (if buffer-file-name
4166 (file-name-sans-extension
4167 (file-name-nondirectory buffer-file-name
))
4169 ;; time, tag, effort are needed for the eval of the prefix format
4170 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
4172 (ts (if dotime
(concat
4173 (if (stringp dotime
) dotime
"")
4174 (and org-agenda-search-headline-for-time txt
))))
4175 (time-of-day (and dotime
(org-get-time-of-day ts
)))
4176 stamp plain s0 s1 s2 t1 t2 rtn srp
4178 (and (org-mode-p) buffer-file-name
4179 (add-to-list 'org-agenda-contributing-files buffer-file-name
))
4180 (when (and dotime time-of-day
)
4181 ;; Extract starting and ending time and move them to prefix
4182 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
4183 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
4184 (setq s0
(match-string 0 ts
)
4185 srp
(and stamp
(match-end 3))
4186 s1
(match-string (if plain
1 2) ts
)
4187 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
4189 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4190 ;; them, we might want to remove them there to avoid duplication.
4191 ;; The user can turn this off with a variable.
4192 (if (and org-prefix-has-time
4193 org-agenda-remove-times-when-in-prefix
(or stamp plain
)
4194 (string-match (concat (regexp-quote s0
) " *") txt
)
4195 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
4196 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
4197 (= (match-beginning 0) 0)
4199 (setq txt
(replace-match "" nil nil txt
))))
4200 ;; Normalize the time(s) to 24 hour
4201 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
4202 (if s2
(setq s2
(org-get-time-of-day s2
'string t
)))
4203 ;; Compute the duration
4205 (setq t1
(+ (* 60 (string-to-number (substring s1
0 2)))
4206 (string-to-number (substring s1
3)))
4208 (s2 (+ (* 60 (string-to-number (substring s2
0 2)))
4209 (string-to-number (substring s2
3))))
4210 (org-agenda-default-appointment-duration
4211 (+ t1 org-agenda-default-appointment-duration
))
4213 (setq duration
(if t2
(- t2 t1
)))))
4215 (when (and s1
(not s2
) org-agenda-default-appointment-duration
4216 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
4217 (let ((m (+ (string-to-number (match-string 2 s1
))
4218 (* 60 (string-to-number (match-string 1 s1
)))
4219 org-agenda-default-appointment-duration
))
4221 (setq h
(/ m
60) m
(- m
(* h
60)))
4222 (setq s2
(format "%02d:%02d" h m
))))
4224 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4226 ;; Tags are in the string
4227 (if (or (eq org-agenda-remove-tags t
)
4228 (and org-agenda-remove-tags
4229 org-prefix-has-tag
))
4230 (setq txt
(replace-match "" t t txt
))
4231 (setq txt
(replace-match
4232 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
4233 (match-string 2 txt
))
4239 (or (get-text-property 0 'org-hd-marker txt
)
4240 (get-text-property 0 'org-marker txt
)))
4243 (setq neffort
(org-hh:mm-string-to-minutes effort
)
4244 effort
(setq effort
(concat "[" effort
"]" )))))
4247 (while (string-match remove-re txt
)
4248 (setq txt
(replace-match "" t t txt
))))
4250 ;; Create the final string
4253 ;; Prepare the variables needed in the eval of the compiled format
4254 (setq time
(cond (s2 (concat s1
"-" s2
))
4255 (s1 (concat s1
"......"))
4258 category
(if (symbolp category
) (symbol-name category
) category
))
4259 ;; Evaluate the compiled format
4260 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
4262 ;; And finally add the text properties
4263 (org-add-props rtn nil
4264 'org-category
(downcase category
)
4265 'tags
(mapcar 'org-downcase-keep-props tags
)
4266 'org-highest-priority org-highest-priority
4267 'org-lowest-priority org-lowest-priority
4268 'prefix-length
(- (length rtn
) (length txt
))
4269 'time-of-day time-of-day
4272 'effort-minutes neffort
4278 (defun org-agenda-add-inherited-tags (txt tags
)
4279 "Remove tags string from TXT, and add complete list of tags.
4280 The new list includes inherited tags. If any inherited tags are present,
4281 a double colon separates inherited tags from local tags."
4282 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt
)
4283 (setq txt
(substring txt
0 (match-beginning 0))))
4285 (let ((have-i (get-text-property 0 'inherited
(car tags
)))
4287 (setq txt
(concat txt
" :"
4290 (setq i
(get-text-property 0 'inherited x
))
4291 (if (and have-i
(not i
))
4297 (if have-i
"::" ":")))))
4300 (defun org-downcase-keep-props (s)
4301 (let ((props (text-properties-at 0 s
)))
4302 (setq s
(downcase s
))
4303 (add-text-properties 0 (length s
) props s
)
4306 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
4307 (defvar org-agenda-sorting-strategy-selected nil
)
4309 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
4311 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
4312 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
4313 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
4314 ((member 'weekly
(car org-agenda-time-grid
)))
4315 (t (throw 'exit list
)))
4316 (let* ((have (delq nil
(mapcar
4317 (lambda (x) (get-text-property 1 'time-of-day x
))
4319 (string (nth 1 org-agenda-time-grid
))
4320 (gridtimes (nth 2 org-agenda-time-grid
))
4321 (req (car org-agenda-time-grid
))
4322 (remove (member 'remove-match req
))
4324 (if (and (member 'require-timed req
) (not have
))
4325 ;; don't show empty grid
4327 (while (setq time
(pop gridtimes
))
4328 (unless (and remove
(member time have
))
4329 (setq time
(int-to-string time
))
4330 (push (org-format-agenda-item
4332 (concat (substring time
0 -
2) ":" (substring time -
2)))
4335 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
4336 (if (member 'time-up org-agenda-sorting-strategy-selected
)
4338 (append list new
)))))
4340 (defun org-compile-prefix-format (key)
4341 "Compile the prefix format into a Lisp form that can be evaluated.
4342 The resulting form is returned and stored in the variable
4343 `org-prefix-format-compiled'."
4344 (setq org-prefix-has-time nil org-prefix-has-tag nil
4345 org-prefix-has-effort nil
)
4347 ((stringp org-agenda-prefix-format
)
4348 org-agenda-prefix-format
)
4349 ((assq key org-agenda-prefix-format
)
4350 (cdr (assq key org-agenda-prefix-format
)))
4351 (t " %-12:c%?-12t% s")))
4353 varform vars var e c f opt
)
4354 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4356 (setq var
(cdr (assoc (match-string 4 s
)
4357 '(("c" . category
) ("t" . time
) ("s" . extra
)
4358 ("T" . tag
) ("e" . effort
))))
4359 c
(or (match-string 3 s
) "")
4360 opt
(match-beginning 1)
4361 start
(1+ (match-beginning 0)))
4362 (if (equal var
'time
) (setq org-prefix-has-time t
))
4363 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
4364 (if (equal var
'effort
) (setq org-prefix-has-effort t
))
4365 (setq f
(concat "%" (match-string 2 s
) "s"))
4368 `(if (equal "" ,var
)
4370 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
4371 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
4372 (setq s
(replace-match "%s" t nil s
))
4373 (push varform vars
))
4374 (setq vars
(nreverse vars
))
4375 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
4377 (defun org-set-sorting-strategy (key)
4378 (if (symbolp (car org-agenda-sorting-strategy
))
4380 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
4381 (setq org-agenda-sorting-strategy-selected
4382 (or (cdr (assq key org-agenda-sorting-strategy
))
4383 (cdr (assq 'agenda org-agenda-sorting-strategy
))
4384 '(time-up category-keep priority-down
)))))
4386 (defun org-get-time-of-day (s &optional string mod24
)
4387 "Check string S for a time of day.
4388 If found, return it as a military time number between 0 and 2400.
4389 If not found, return nil.
4390 The optional STRING argument forces conversion into a 5 character wide string
4394 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
4395 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
4396 (let* ((h (string-to-number (match-string 1 s
)))
4397 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
4398 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
4399 (am-p (equal ampm
"am"))
4400 (h1 (cond ((not ampm
) h
)
4401 ((= h
12) (if am-p
0 12))
4402 (t (+ h
(if am-p
0 12)))))
4403 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
4405 (t0 (+ (* 100 h2
) m
))
4406 (t1 (concat (if (>= h1
24) "+" " ")
4407 (if (< t0
100) "0" "")
4408 (if (< t0
10) "0" "")
4409 (int-to-string t0
))))
4410 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
4412 (defun org-finalize-agenda-entries (list &optional nosort
)
4413 "Sort and concatenate the agenda items."
4414 (setq list
(mapcar 'org-agenda-highlight-todo list
))
4417 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
4419 (defun org-agenda-highlight-todo (x)
4420 (let ((org-done-keywords org-done-keywords-for-agenda
)
4424 (beginning-of-line 1)
4425 (setq re
(get-text-property (point) 'org-todo-regexp
))
4426 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
4427 (when (looking-at (concat "[ \t]*\\.*\\(" re
"\\) +"))
4428 (add-text-properties (match-beginning 0) (match-end 0)
4429 (list 'face
(org-get-todo-face 1)))
4430 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4431 (delete-region (match-beginning 1) (1- (match-end 0)))
4432 (goto-char (match-beginning 1))
4433 (insert (format org-agenda-todo-keyword-format s
)))))
4434 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
4435 pl
(get-text-property 0 'prefix-length x
))
4437 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
4439 (add-text-properties
4440 (or (match-end 1) (match-end 0)) (match-end 0)
4441 (list 'face
(org-get-todo-face (match-string 2 x
)))
4443 (setq x
(concat (substring x
0 (match-end 1))
4444 (format org-agenda-todo-keyword-format
4447 (substring x
(match-end 3)))))
4450 (defsubst org-cmp-priority
(a b
)
4451 "Compare the priorities of string A and B."
4452 (let ((pa (or (get-text-property 1 'priority a
) 0))
4453 (pb (or (get-text-property 1 'priority b
) 0)))
4454 (cond ((> pa pb
) +1)
4458 (defsubst org-cmp-effort
(a b
)
4459 "Compare the priorities of string A and B."
4460 (let* ((def (if org-sort-agenda-noeffort-is-high
32767 -
1))
4461 (ea (or (get-text-property 1 'effort-minutes a
) def
))
4462 (eb (or (get-text-property 1 'effort-minutes b
) def
)))
4463 (cond ((> ea eb
) +1)
4467 (defsubst org-cmp-category
(a b
)
4468 "Compare the string values of categories of strings A and B."
4469 (let ((ca (or (get-text-property 1 'org-category a
) ""))
4470 (cb (or (get-text-property 1 'org-category b
) "")))
4471 (cond ((string-lessp ca cb
) -
1)
4472 ((string-lessp cb ca
) +1)
4475 (defsubst org-cmp-todo-state
(a b
)
4476 "Compare the todo states of strings A and B."
4477 (let* ((ma (or (get-text-property 1 'org-marker a
)
4478 (get-text-property 1 'org-hd-marker a
)))
4479 (mb (or (get-text-property 1 'org-marker b
)
4480 (get-text-property 1 'org-hd-marker b
)))
4481 (fa (and ma
(marker-buffer ma
)))
4482 (fb (and mb
(marker-buffer mb
)))
4484 (or (and fa
(with-current-buffer fa org-todo-keywords-1
))
4485 (and fb
(with-current-buffer fb org-todo-keywords-1
))))
4486 (ta (or (get-text-property 1 'todo-state a
) ""))
4487 (tb (or (get-text-property 1 'todo-state b
) ""))
4488 (la (- (length (member ta todo-kwds
))))
4489 (lb (- (length (member tb todo-kwds
))))
4490 (donepa (member ta org-done-keywords-for-agenda
))
4491 (donepb (member tb org-done-keywords-for-agenda
)))
4492 (cond ((and donepa
(not donepb
)) -
1)
4493 ((and (not donepa
) donepb
) +1)
4498 (defsubst org-cmp-tag
(a b
)
4499 "Compare the string values of the first tags of A and B."
4500 (let ((ta (car (last (get-text-property 1 'tags a
))))
4501 (tb (car (last (get-text-property 1 'tags b
)))))
4504 ((string-lessp ta tb
) -
1)
4505 ((string-lessp tb ta
) +1)
4508 (defsubst org-cmp-time
(a b
)
4509 "Compare the time-of-day values of strings A and B."
4510 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
4511 (ta (or (get-text-property 1 'time-of-day a
) def
))
4512 (tb (or (get-text-property 1 'time-of-day b
) def
)))
4513 (cond ((< ta tb
) -
1)
4517 (defun org-entries-lessp (a b
)
4518 "Predicate for sorting agenda entries."
4519 ;; The following variables will be used when the form is evaluated.
4520 ;; So even though the compiler complains, keep them.
4521 (let* ((time-up (org-cmp-time a b
))
4522 (time-down (if time-up
(- time-up
) nil
))
4523 (priority-up (org-cmp-priority a b
))
4524 (priority-down (if priority-up
(- priority-up
) nil
))
4525 (effort-up (org-cmp-effort a b
))
4526 (effort-down (if effort-up
(- effort-up
) nil
))
4527 (category-up (org-cmp-category a b
))
4528 (category-down (if category-up
(- category-up
) nil
))
4529 (category-keep (if category-up
+1 nil
))
4530 (tag-up (org-cmp-tag a b
))
4531 (tag-down (if tag-up
(- tag-up
) nil
))
4532 (todo-state-up (org-cmp-todo-state a b
))
4533 (todo-state-down (if todo-state-up
(- todo-state-up
) nil
))
4534 user-defined-up user-defined-down
)
4535 (if (and org-agenda-cmp-user-defined
4536 (functionp org-agenda-cmp-user-defined
))
4537 (setq user-defined-up
4538 (funcall org-agenda-cmp-user-defined a b
)
4539 user-defined-down
(if user-defined-up
(- user-defined-up
) nil
)))
4541 (eval (cons 'or org-agenda-sorting-strategy-selected
))
4542 '((-1 . t
) (1 . nil
) (nil . nil
))))))
4544 ;;; Agenda restriction lock
4546 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
4547 "Overlay to mark the headline to which arenda commands are restricted.")
4548 (org-overlay-put org-agenda-restriction-lock-overlay
4549 'face
'org-agenda-restriction-lock
)
4550 (org-overlay-put org-agenda-restriction-lock-overlay
4551 'help-echo
"Agendas are currently limited to this subtree.")
4552 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4554 (defun org-agenda-set-restriction-lock (&optional type
)
4555 "Set restriction lock for agenda, to current subtree or file.
4556 Restriction will be the file if TYPE is `file', or if type is the
4557 universal prefix '(4), or if the cursor is before the first headline
4558 in the file. Otherwise, restriction will be to the current subtree."
4560 (and (equal type
'(4)) (setq type
'file
))
4563 ((org-at-heading-p) 'subtree
)
4564 ((condition-case nil
(org-back-to-heading t
) (error nil
))
4567 (if (eq type
'subtree
)
4569 (setq org-agenda-restrict t
)
4570 (setq org-agenda-overriding-restriction
'subtree
)
4571 (put 'org-agenda-files
'org-restrict
4572 (list (buffer-file-name (buffer-base-buffer))))
4573 (org-back-to-heading t
)
4574 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
4575 (move-marker org-agenda-restrict-begin
(point))
4576 (move-marker org-agenda-restrict-end
4577 (save-excursion (org-end-of-subtree t
)))
4578 (message "Locking agenda restriction to subtree"))
4579 (put 'org-agenda-files
'org-restrict
4580 (list (buffer-file-name (buffer-base-buffer))))
4581 (setq org-agenda-restrict nil
)
4582 (setq org-agenda-overriding-restriction
'file
)
4583 (move-marker org-agenda-restrict-begin nil
)
4584 (move-marker org-agenda-restrict-end nil
)
4585 (message "Locking agenda restriction to file"))
4586 (setq current-prefix-arg nil
)
4587 (org-agenda-maybe-redo))
4589 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
4590 "Remove the agenda restriction lock."
4592 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4593 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
4594 (setq org-agenda-overriding-restriction nil
)
4595 (setq org-agenda-restrict nil
)
4596 (put 'org-agenda-files
'org-restrict nil
)
4597 (move-marker org-agenda-restrict-begin nil
)
4598 (move-marker org-agenda-restrict-end nil
)
4599 (setq current-prefix-arg nil
)
4600 (message "Agenda restriction lock removed")
4601 (or noupdate
(org-agenda-maybe-redo)))
4603 (defun org-agenda-maybe-redo ()
4604 "If there is any window showing the agenda view, update it."
4605 (let ((w (get-buffer-window org-agenda-buffer-name t
))
4606 (w0 (selected-window)))
4611 (if org-agenda-overriding-restriction
4612 (message "Agenda view shifted to new %s restriction"
4613 org-agenda-overriding-restriction
)
4614 (message "Agenda restriction lock removed")))))
4618 (defun org-agenda-check-type (error &rest types
)
4619 "Check if agenda buffer is of allowed type.
4620 If ERROR is non-nil, throw an error, otherwise just return nil."
4621 (if (memq org-agenda-type types
)
4624 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
4627 (defun org-agenda-quit ()
4628 "Exit agenda by removing the window or the buffer."
4630 (if org-agenda-columns-active
4632 (let ((buf (current-buffer)))
4633 (and (not (eq org-agenda-window-setup
'current-window
))
4634 (not (one-window-p))
4637 (org-agenda-reset-markers)
4638 (org-columns-remove-overlays)
4639 (setq org-agenda-archives-mode nil
))
4640 ;; Maybe restore the pre-agenda window configuration.
4641 (and org-agenda-restore-windows-after-quit
4642 (not (eq org-agenda-window-setup
'other-frame
))
4643 org-pre-agenda-window-conf
4644 (set-window-configuration org-pre-agenda-window-conf
))))
4646 (defun org-agenda-exit ()
4647 "Exit agenda by removing the window or the buffer.
4648 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
4649 Org-mode buffers visited directly by the user will not be touched."
4651 (org-release-buffers org-agenda-new-buffers
)
4652 (setq org-agenda-new-buffers nil
)
4655 (defun org-agenda-execute (arg)
4656 "Execute another agenda command, keeping same window.\\<global-map>
4657 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
4659 (let ((org-agenda-window-setup 'current-window
))
4662 (defun org-agenda-redo ()
4664 When this is the global TODO list, a prefix argument will be interpreted."
4666 (let* ((org-agenda-keep-modes t
)
4667 (filter org-agenda-filter
)
4668 (preset (get 'org-agenda-filter
:preset-filter
))
4669 (cols org-agenda-columns-active
)
4670 (line (org-current-line))
4671 (window-line (- line
(org-current-line (window-start))))
4672 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
4673 (put 'org-agenda-filter
:preset-filter nil
)
4674 (and cols
(org-columns-quit))
4675 (message "Rebuilding agenda buffer...")
4676 (org-let lprops
'(eval org-agenda-redo-command
))
4677 (setq org-agenda-undo-list nil
4678 org-agenda-pending-undo-list nil
)
4679 (message "Rebuilding agenda buffer...done")
4680 (put 'org-agenda-filter
:preset-filter preset
)
4681 (and (or filter preset
) (org-agenda-filter-apply filter
))
4682 (and cols
(interactive-p) (org-agenda-columns))
4684 (recenter window-line
)))
4687 (defvar org-global-tags-completion-table nil
)
4688 (defvar org-agenda-filter-form nil
)
4689 (defun org-agenda-filter-by-tag (strip &optional char narrow
)
4690 "Keep only those lines in the agenda buffer that have a specific tag.
4691 The tag is selected with its fast selection letter, as configured.
4692 With prefix argument STRIP, remove all lines that do have the tag.
4693 A lisp caller can specify CHAR. NARROW means that the new tag should be
4694 used to narrow the search - the interactive user can also press `-' or `+'
4695 to switch to narrowing."
4697 (let* ((alist org-tag-alist-for-agenda
)
4698 (tag-chars (mapconcat
4699 (lambda (x) (if (cdr x
) (char-to-string (cdr x
)) ""))
4701 (efforts (org-split-string
4702 (or (cdr (assoc (concat org-effort-property
"_ALL")
4703 org-global-properties
))
4704 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
4705 (effort-op org-agenda-filter-effort-default-operator
)
4707 (inhibit-read-only t
)
4708 (current org-agenda-filter
)
4712 "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
4713 (if narrow
"Narrow" "Filter") tag-chars
)
4714 (setq char
(read-char)))
4715 (when (member char
'(?
+ ?-
))
4717 (cond ((equal char ?-
) (setq strip t narrow t
))
4718 ((equal char ?
+) (setq strip nil narrow t
)))
4720 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars
)
4721 (setq char
(read-char)))
4722 (when (member char
'(?
< ?
> ?
= ??
))
4723 ;; An effort operator
4724 (setq effort-op
(char-to-string char
))
4725 (setq alist nil
) ; to make sure it will be interpreted as effort.
4726 (unless (equal char ??
)
4727 (loop for i from
0 to
9 do
4731 (if (= i
9) "0" (int-to-string (1+ i
)))
4732 "]" (nth i efforts
))))
4733 (message "Effort%s: %s " effort-op effort-prompt
)
4734 (setq char
(read-char))
4735 (when (or (< char ?
0) (> char ?
9))
4736 (error "Need 1-9,0 to select effort" ))))
4737 (when (equal char ?
\t)
4738 (unless (local-variable-p 'org-global-tags-completion-table
(current-buffer))
4739 (org-set-local 'org-global-tags-completion-table
4740 (org-global-tags-completion-table)))
4741 (let ((completion-ignore-case t
))
4742 (setq tag
(org-ido-completing-read
4743 "Tag: " org-global-tags-completion-table
))))
4746 (org-agenda-filter-by-tag-show-all)
4747 (when (get 'org-agenda-filter
:preset-filter
)
4748 (org-agenda-filter-apply org-agenda-filter
)))
4749 ((or (equal char ?\
)
4750 (setq a
(rassoc char alist
))
4751 (and (>= char ?
0) (<= char ?
9)
4752 (setq n
(if (= char ?
0) 9 (- char ?
0 1))
4753 tag
(concat effort-op
(nth n efforts
))
4758 (and tag
(setq a
(cons tag nil
))))
4759 (org-agenda-filter-by-tag-show-all)
4761 (setq org-agenda-filter
4762 (cons (concat (if strip
"-" "+") tag
)
4763 (if narrow current nil
)))
4764 (org-agenda-filter-apply org-agenda-filter
))
4765 (t (error "Invalid tag selection character %c" char
)))))
4767 (defun org-agenda-filter-by-tag-refine (strip &optional char
)
4768 "Refine the current filter. See `org-agenda-filter-by-tag."
4770 (org-agenda-filter-by-tag strip char
'refine
))
4772 (defun org-agenda-filter-make-matcher ()
4773 "Create the form that tests a line for the agenda filter."
4775 (dolist (x (append (get 'org-agenda-filter
:preset-filter
)
4777 (if (member x
'("-" "+"))
4778 (setq f1
'(not tags
))
4779 (if (string-match "[<=>?]" x
)
4780 (setq f1
(org-agenda-filter-effort-form x
))
4781 (setq f1
(list 'member
(downcase (substring x
1)) 'tags
)))
4782 (if (equal (string-to-char x
) ?-
)
4783 (setq f1
(list 'not f1
))))
4785 (cons 'and
(nreverse f
))))
4787 (defun org-agenda-filter-effort-form (e)
4788 "Return the form to compare the effort of the current line with what E says.
4789 E looks line \"+<2:25\"."
4791 (setq e
(substring e
1))
4792 (setq op
(string-to-char e
) e
(substring e
1))
4793 (setq op
(cond ((equal op ?
<) '<=)
4797 (list 'org-agenda-compare-effort
(list 'quote op
)
4798 (org-hh:mm-string-to-minutes e
))))
4800 (defun org-agenda-compare-effort (op value
)
4801 "Compare the effort of the current line with VALUE, using OP.
4802 If the line does not have an effort defined, return nil."
4803 (let ((eff (get-text-property (point) 'effort-minutes
)))
4806 (funcall op
(or eff
(if org-sort-agenda-noeffort-is-high
32767 0))
4809 (defun org-agenda-filter-apply (filter)
4810 "Set FILTER as the new agenda filter and apply it."
4812 (setq org-agenda-filter filter
4813 org-agenda-filter-form
(org-agenda-filter-make-matcher))
4814 (org-agenda-set-mode-name)
4816 (goto-char (point-min))
4818 (if (get-text-property (point) 'org-marker
)
4820 (setq tags
(get-text-property (point) 'tags
)) ; used in eval
4821 (if (not (eval org-agenda-filter-form
))
4822 (org-agenda-filter-by-tag-hide-line))
4823 (beginning-of-line 2))
4824 (beginning-of-line 2))))))
4826 (defun org-agenda-filter-by-tag-hide-line ()
4828 (setq ov
(org-make-overlay (max (point-min) (1- (point-at-bol)))
4830 (org-overlay-put ov
'invisible t
)
4831 (org-overlay-put ov
'type
'tags-filter
)
4832 (push ov org-agenda-filter-overlays
)))
4834 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos
)
4835 (setq pos
(or pos
(point)))
4837 (dolist (ov (org-overlays-at pos
))
4838 (when (and (org-overlay-get ov
'invisible
)
4839 (eq (org-overlay-get ov
'type
) 'tags-filter
))
4841 (if (< (org-overlay-start ov
) (point-at-eol))
4842 (org-move-overlay ov
(point-at-eol)
4843 (org-overlay-end ov
)))))))
4845 (defun org-agenda-filter-by-tag-show-all ()
4846 (mapc 'org-delete-overlay org-agenda-filter-overlays
)
4847 (setq org-agenda-filter-overlays nil
)
4848 (setq org-agenda-filter nil
)
4849 (setq org-agenda-filter-form nil
)
4850 (org-agenda-set-mode-name))
4852 (defun org-agenda-manipulate-query-add ()
4853 "Manipulate the query by adding a search term with positive selection.
4854 Positive selection means, the term must be matched for selection of an entry."
4856 (org-agenda-manipulate-query ?\
[))
4857 (defun org-agenda-manipulate-query-subtract ()
4858 "Manipulate the query by adding a search term with negative selection.
4859 Negative selection means, term must not be matched for selection of an entry."
4861 (org-agenda-manipulate-query ?\
]))
4862 (defun org-agenda-manipulate-query-add-re ()
4863 "Manipulate the query by adding a search regexp with positive selection.
4864 Positive selection means, the regexp must match for selection of an entry."
4866 (org-agenda-manipulate-query ?\
{))
4867 (defun org-agenda-manipulate-query-subtract-re ()
4868 "Manipulate the query by adding a search regexp with negative selection.
4869 Negative selection means, regexp must not match for selection of an entry."
4871 (org-agenda-manipulate-query ?\
}))
4872 (defun org-agenda-manipulate-query (char)
4874 ((memq org-agenda-type
'(timeline agenda
))
4875 (if (y-or-n-p "Re-display with inactive time stamps included? ")
4876 (let ((org-agenda-include-inactive-timestamps t
))
4879 ((eq org-agenda-type
'search
)
4881 'org-agenda-query-string
4882 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
4883 (?\
{ .
" +{}") (?\
} .
" -{}")))))
4884 (setq org-agenda-redo-command
4885 (list 'org-search-view
4887 org-agenda-query-string
4888 (+ (length org-agenda-query-string
)
4889 (if (member char
'(?\
{ ?\
})) 0 1))))
4890 (set-register org-agenda-query-register org-agenda-query-string
)
4892 (t (error "Cannot manipulate query for %s-type agenda buffers"
4895 (defun org-add-to-string (var string
)
4896 (set var
(concat (symbol-value var
) string
)))
4898 (defun org-agenda-goto-date (date)
4899 "Jump to DATE in agenda."
4900 (interactive (list (org-read-date)))
4901 (org-agenda-list nil date
))
4903 (defun org-agenda-goto-today ()
4906 (org-agenda-check-type t
'timeline
'agenda
)
4907 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
4909 (tdpos (goto-char tdpos
))
4910 ((eq org-agenda-type
'agenda
)
4911 (let* ((sd (time-to-days
4912 (time-subtract (current-time)
4913 (list 0 (* 3600 org-extend-today-until
) 0))))
4914 (comp (org-agenda-compute-time-span sd org-agenda-span
))
4915 (org-agenda-overriding-arguments org-agenda-last-arguments
))
4916 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
4917 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
4919 (org-agenda-find-same-or-today-or-agenda)))
4920 (t (error "Cannot find today")))))
4922 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
4924 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
4925 (text-property-any (point-min) (point-max) 'org-today t
)
4926 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
4929 (defun org-agenda-later (arg)
4930 "Go forward in time by thee current span.
4931 With prefix ARG, go forward that many times the current span."
4933 (org-agenda-check-type t
'agenda
)
4934 (let* ((span org-agenda-span
)
4935 (sd org-starting-day
)
4936 (greg (calendar-gregorian-from-absolute sd
))
4937 (cnt (get-text-property (point) 'org-day-cnt
))
4941 (setq sd
(+ arg sd
) nd
1))
4943 (setq sd
(+ (* 7 arg
) sd
) nd
7))
4945 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
4946 sd
(calendar-absolute-from-gregorian greg2
))
4947 (setcar greg2
(1+ (car greg2
)))
4948 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
4950 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
4951 sd
(calendar-absolute-from-gregorian greg2
))
4952 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
4953 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
4954 (let ((org-agenda-overriding-arguments
4955 (list (car org-agenda-last-arguments
) sd nd t
)))
4957 (org-agenda-find-same-or-today-or-agenda cnt
))))
4959 (defun org-agenda-earlier (arg)
4960 "Go backward in time by the current span.
4961 With prefix ARG, go backward that many times the current span."
4963 (org-agenda-later (- arg
)))
4965 (defun org-agenda-day-view (&optional day-of-year
)
4966 "Switch to daily view for agenda.
4967 With argument DAY-OF-YEAR, switch to that day of the year."
4969 (setq org-agenda-ndays
1)
4970 (org-agenda-change-time-span 'day day-of-year
))
4971 (defun org-agenda-week-view (&optional iso-week
)
4972 "Switch to daily view for agenda.
4973 With argument ISO-WEEK, switch to the corresponding ISO week.
4974 If ISO-WEEK has more then 2 digits, only the last two encode the
4975 week. Any digits before this encode a year. So 200712 means
4976 week 12 of year 2007. Years in the range 1938-2037 can also be
4977 written as 2-digit years."
4979 (setq org-agenda-ndays
7)
4980 (org-agenda-change-time-span 'week iso-week
))
4981 (defun org-agenda-month-view (&optional month
)
4982 "Switch to monthly view for agenda.
4983 With argument MONTH, switch to that month."
4985 (org-agenda-change-time-span 'month month
))
4986 (defun org-agenda-year-view (&optional year
)
4987 "Switch to yearly view for agenda.
4988 With argument YEAR, switch to that year.
4989 If MONTH has more then 2 digits, only the last two encode the
4990 month. Any digits before this encode a year. So 200712 means
4991 December year 2007. Years in the range 1938-2037 can also be
4992 written as 2-digit years."
4995 (setq year
(org-small-year-to-year year
)))
4996 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4997 (org-agenda-change-time-span 'year year
)
5000 (defun org-agenda-change-time-span (span &optional n
)
5001 "Change the agenda view to SPAN.
5002 SPAN may be `day', `week', `month', `year'."
5003 (org-agenda-check-type t
'agenda
)
5004 (if (and (not n
) (equal org-agenda-span span
))
5005 (error "Viewing span is already \"%s\"" span
))
5006 (let* ((sd (or (get-text-property (point) 'day
)
5008 (computed (org-agenda-compute-time-span sd span n
))
5009 (org-agenda-overriding-arguments
5010 (list (car org-agenda-last-arguments
)
5011 (car computed
) (cdr computed
) t
)))
5013 (org-agenda-find-same-or-today-or-agenda))
5014 (org-agenda-set-mode-name)
5015 (message "Switched to %s view" span
))
5017 (defun org-agenda-compute-time-span (sd span
&optional n
)
5018 "Compute starting date and number of days for agenda.
5019 SPAN may be `day', `week', `month', `year'. The return value
5020 is a cons cell with the starting date and the number of days,
5021 so that the date SD will be in that range."
5022 (let* ((greg (calendar-gregorian-from-absolute sd
))
5026 nd w1 y1 m1 thisweek
)
5030 (setq sd
(+ (calendar-absolute-from-gregorian
5035 (let* ((nt (calendar-day-of-week
5036 (calendar-gregorian-from-absolute sd
)))
5037 (d (if org-agenda-start-on-weekday
5038 (- nt org-agenda-start-on-weekday
)
5040 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
5043 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
5045 (setq y1
(org-small-year-to-year (/ n
100))
5048 (calendar-absolute-from-iso
5050 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
5053 (when (and n
(> n
99))
5054 (setq y1
(org-small-year-to-year (/ n
100))
5056 (setq sd
(calendar-absolute-from-gregorian
5057 (list (or n mg
) 1 (or y1 yg
)))
5058 nd
(- (calendar-absolute-from-gregorian
5059 (list (1+ (or n mg
)) 1 (or y1 yg
)))
5062 (setq sd
(calendar-absolute-from-gregorian
5063 (list 1 1 (or n yg
)))
5064 nd
(- (calendar-absolute-from-gregorian
5065 (list 1 1 (1+ (or n yg
))))
5069 (defun org-agenda-next-date-line (&optional arg
)
5070 "Jump to the next line indicating a date in agenda buffer."
5072 (org-agenda-check-type t
'agenda
'timeline
)
5073 (beginning-of-line 1)
5074 ;; This does not work if user makes date format that starts with a blank
5075 (if (looking-at "^\\S-") (forward-char 1))
5076 (if (not (re-search-forward "^\\S-" nil t arg
))
5079 (error "No next date after this line in this buffer")))
5080 (goto-char (match-beginning 0)))
5082 (defun org-agenda-previous-date-line (&optional arg
)
5083 "Jump to the previous line indicating a date in agenda buffer."
5085 (org-agenda-check-type t
'agenda
'timeline
)
5086 (beginning-of-line 1)
5087 (if (not (re-search-backward "^\\S-" nil t arg
))
5088 (error "No previous date before this line in this buffer")))
5090 ;; Initialize the highlight
5091 (defvar org-hl
(org-make-overlay 1 1))
5092 (org-overlay-put org-hl
'face
'highlight
)
5094 (defun org-highlight (begin end
&optional buffer
)
5095 "Highlight a region with overlay."
5096 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
5097 org-hl begin end
(or buffer
(current-buffer))))
5099 (defun org-unhighlight ()
5100 "Detach overlay INDEX."
5101 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
5103 ;; FIXME this is currently not used.
5104 (defun org-highlight-until-next-command (beg end
&optional buffer
)
5105 "Move the highlight overlay to BEG/END, remove it before the next command."
5106 (org-highlight beg end buffer
)
5107 (add-hook 'pre-command-hook
'org-unhighlight-once
))
5108 (defun org-unhighlight-once ()
5109 "Remove the highlight from its position, and this function from the hook."
5110 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
5113 (defun org-agenda-follow-mode ()
5114 "Toggle follow mode in an agenda buffer."
5116 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
5117 (org-agenda-set-mode-name)
5118 (message "Follow mode is %s"
5119 (if org-agenda-follow-mode
"on" "off")))
5121 (defun org-agenda-clockreport-mode ()
5122 "Toggle clocktable mode in an agenda buffer."
5124 (org-agenda-check-type t
'agenda
)
5125 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
5126 (org-agenda-set-mode-name)
5128 (message "Clocktable mode is %s"
5129 (if org-agenda-clockreport-mode
"on" "off")))
5131 (defun org-agenda-log-mode (&optional special
)
5132 "Toggle log mode in an agenda buffer.
5133 With argument SPECIAL, show all possible log items, not only the ones
5134 configured in `org-agenda-log-mode-items'.
5135 With a double `C-u' prefix arg, show *only* log items, nothing else."
5137 (org-agenda-check-type t
'agenda
'timeline
)
5138 (setq org-agenda-show-log
5139 (if (equal special
'(16))
5141 (if special
'(closed clock state
)
5142 (not org-agenda-show-log
))))
5143 (org-agenda-set-mode-name)
5145 (message "Log mode is %s"
5146 (if org-agenda-show-log
"on" "off")))
5148 (defun org-agenda-archives-mode (&optional with-files
)
5149 "Toggle log mode in an agenda buffer."
5151 (setq org-agenda-archives-mode
5152 (if with-files t
(if org-agenda-archives-mode nil
'trees
)))
5153 (org-agenda-set-mode-name)
5158 ((eq org-agenda-archives-mode nil
)
5159 "No archives are included")
5160 ((eq org-agenda-archives-mode
'trees
)
5161 (format "Trees with :%s: tag are included" org-archive-tag
))
5162 ((eq org-agenda-archives-mode t
)
5163 (format "Trees with :%s: tag and all active archive files are included"
5164 org-archive-tag
)))))
5166 (defun org-agenda-toggle-diary ()
5167 "Toggle diary inclusion in an agenda buffer."
5169 (org-agenda-check-type t
'agenda
)
5170 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
5172 (org-agenda-set-mode-name)
5173 (message "Diary inclusion turned %s"
5174 (if org-agenda-include-diary
"on" "off")))
5176 (defun org-agenda-toggle-time-grid ()
5177 "Toggle time grid in an agenda buffer."
5179 (org-agenda-check-type t
'agenda
)
5180 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
5182 (org-agenda-set-mode-name)
5183 (message "Time-grid turned %s"
5184 (if org-agenda-use-time-grid
"on" "off")))
5186 (defun org-agenda-set-mode-name ()
5187 "Set the mode name to indicate all the small mode settings."
5189 (concat "Org-Agenda"
5190 (if (equal org-agenda-ndays
1) " Day" "")
5191 (if (equal org-agenda-ndays
7) " Week" "")
5192 (if org-agenda-follow-mode
" Follow" "")
5193 (if org-agenda-include-diary
" Diary" "")
5194 (if org-agenda-use-time-grid
" Grid" "")
5195 (if (consp org-agenda-show-log
) " LogAll"
5196 (if org-agenda-show-log
" Log" ""))
5197 (if (or org-agenda-filter
(get 'org-agenda-filter
5199 (concat " {" (mapconcat
5201 (append (get 'org-agenda-filter
5203 org-agenda-filter
) "") "}")
5205 (if org-agenda-archives-mode
5206 (if (eq org-agenda-archives-mode t
)
5208 (format " :%s:" org-archive-tag
))
5210 (if org-agenda-clockreport-mode
" Clock" "")))
5211 (force-mode-line-update))
5213 (defun org-agenda-post-command-hook ()
5214 (and (eolp) (not (bolp)) (backward-char 1))
5215 (setq org-agenda-type
5216 (or (get-text-property (point) 'org-agenda-type
)
5217 (get-text-property (max (point-min) (1- (point)))
5219 (if (and org-agenda-follow-mode
5220 (get-text-property (point) 'org-marker
))
5223 (defun org-agenda-show-priority ()
5224 "Show the priority of the current item.
5225 This priority is composed of the main priority given with the [#A] cookies,
5226 and by additional input from the age of a schedules or deadline entry."
5228 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
5229 (message "Priority is %d" (if pri pri -
1000))))
5231 (defun org-agenda-show-tags ()
5232 "Show the tags applicable to the current item."
5234 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
5236 (message "Tags are :%s:"
5237 (org-no-properties (mapconcat 'identity tags
":")))
5238 (message "No tags associated with this line"))))
5240 (defun org-agenda-goto (&optional highlight
)
5241 "Go to the Org-mode file which contains the item at point."
5243 (let* ((marker (or (get-text-property (point) 'org-marker
)
5244 (org-agenda-error)))
5245 (buffer (marker-buffer marker
))
5246 (pos (marker-position marker
)))
5247 (switch-to-buffer-other-window buffer
)
5251 (org-show-context 'agenda
)
5253 (and (outline-next-heading)
5254 (org-flag-heading nil
)))) ; show the next heading
5255 (recenter (/ (window-height) 2))
5256 (run-hooks 'org-agenda-after-show-hook
)
5257 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
5259 (defvar org-agenda-after-show-hook nil
5260 "Normal hook run after an item has been shown from the agenda.
5261 Point is in the buffer where the item originated.")
5263 (defun org-agenda-kill ()
5264 "Kill the entry or subtree belonging to the current agenda entry."
5266 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5267 (let* ((marker (or (get-text-property (point) 'org-marker
)
5268 (org-agenda-error)))
5269 (buffer (marker-buffer marker
))
5270 (pos (marker-position marker
))
5271 (type (get-text-property (point) 'type
))
5272 dbeg dend
(n 0) conf
)
5273 (org-with-remote-undo buffer
5274 (with-current-buffer buffer
5277 (if (and (org-mode-p) (not (member type
'("sexp"))))
5278 (setq dbeg
(progn (org-back-to-heading t
) (point))
5279 dend
(org-end-of-subtree t t
))
5280 (setq dbeg
(point-at-bol)
5281 dend
(min (point-max) (1+ (point-at-eol)))))
5283 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
5284 (setq conf
(or (eq t org-agenda-confirm-kill
)
5285 (and (numberp org-agenda-confirm-kill
)
5286 (> n org-agenda-confirm-kill
))))
5289 (format "Delete entry with %d lines in buffer \"%s\"? "
5290 n
(buffer-name buffer
))))
5292 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
5293 (with-current-buffer buffer
(delete-region dbeg dend
))
5294 (message "Agenda item and source killed"))))
5296 (defun org-agenda-archive ()
5297 "Archive the entry or subtree belonging to the current agenda entry."
5299 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5300 (let* ((marker (or (get-text-property (point) 'org-marker
)
5301 (org-agenda-error)))
5302 (buffer (marker-buffer marker
))
5303 (pos (marker-position marker
)))
5304 (org-with-remote-undo buffer
5305 (with-current-buffer buffer
5309 (org-remove-subtree-entries-from-agenda)
5310 (org-back-to-heading t
)
5311 (org-archive-subtree))
5312 (error "Archiving works only in Org-mode files"))))))
5314 (defun org-agenda-archive-to-archive-sibling ()
5315 "Move the entry to the archive sibling."
5317 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5318 (let* ((marker (or (get-text-property (point) 'org-marker
)
5319 (org-agenda-error)))
5320 (buffer (marker-buffer marker
))
5321 (pos (marker-position marker
)))
5322 (org-with-remote-undo buffer
5323 (with-current-buffer buffer
5327 (org-remove-subtree-entries-from-agenda)
5328 (org-back-to-heading t
)
5329 (org-archive-to-archive-sibling))
5330 (error "Archiving works only in Org-mode files"))))))
5332 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
5333 "Remove all lines in the agenda that correspond to a given subtree.
5334 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5335 If this information is not given, the function uses the tree at point."
5336 (let ((buf (or buf
(current-buffer))) m p
)
5338 (unless (and beg end
)
5339 (org-back-to-heading t
)
5341 (org-end-of-subtree t
)
5343 (set-buffer (get-buffer org-agenda-buffer-name
))
5345 (goto-char (point-max))
5346 (beginning-of-line 1)
5348 (when (and (setq m
(get-text-property (point) 'org-marker
))
5349 (equal buf
(marker-buffer m
))
5350 (setq p
(marker-position m
))
5353 (let ((inhibit-read-only t
))
5354 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5355 (beginning-of-line 0))))))
5357 (defun org-agenda-open-link ()
5358 "Follow the link in the current line, if any."
5360 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
5363 (narrow-to-region (point-at-bol) (point-at-eol))
5364 (org-open-at-point))))
5366 (defun org-agenda-copy-local-variable (var)
5367 "Get a variable from a referenced buffer and install it here."
5368 (let ((m (get-text-property (point) 'org-marker
)))
5369 (when (and m
(buffer-live-p (marker-buffer m
)))
5370 (org-set-local var
(with-current-buffer (marker-buffer m
)
5371 (symbol-value var
))))))
5373 (defun org-agenda-switch-to (&optional delete-other-windows
)
5374 "Go to the Org-mode file which contains the item at point."
5376 (let* ((marker (or (get-text-property (point) 'org-marker
)
5377 (org-agenda-error)))
5378 (buffer (marker-buffer marker
))
5379 (pos (marker-position marker
)))
5380 (switch-to-buffer buffer
)
5381 (and delete-other-windows
(delete-other-windows))
5385 (org-show-context 'agenda
)
5387 (and (outline-next-heading)
5388 (org-flag-heading nil
)))))) ; show the next heading
5390 (defun org-agenda-goto-mouse (ev)
5391 "Go to the Org-mode file which contains the item at the mouse click."
5393 (mouse-set-point ev
)
5396 (defun org-agenda-show (&optional full-entry
)
5397 "Display the Org-mode file which contains the item at point.
5398 With prefix argument FULL-ENTRY, make the entire entry visible
5399 if it was hidden in the outline."
5401 (let ((win (selected-window)))
5403 (let ((org-show-entry-below t
))
5404 (org-agenda-goto t
))
5405 (org-agenda-goto t
))
5406 (select-window win
)))
5408 (defun org-agenda-show-1 (&optional more
)
5409 "Display the Org-mode file which contains the item at point.
5410 The prefix arg causes further revieling:
5413 1 just show the entry according to defaults.
5414 2 show the text below the heading
5415 3 show the entire subtree
5416 4 show the entire subtree and any LOGBOOK drawers
5417 5 show the entire subtree and any drawers
5418 With prefix argument FULL-ENTRY, make the entire entry visible
5419 if it was hidden in the outline."
5421 (let ((win (selected-window)))
5423 (org-recenter-heading 1)
5427 (message "Remote: hide subtree"))
5428 ((and (interactive-p) (= more
1))
5429 (message "Remote: show with default settings"))
5433 (org-back-to-heading)
5434 (org-cycle-hide-drawers 'children
))
5435 (message "Remote: show entry"))
5439 (org-back-to-heading)
5440 (org-cycle-hide-drawers 'subtree
))
5441 (message "Remote: show subtree"))
5443 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers
)))
5445 (concat "^[ \t]*:\\("
5446 (mapconcat 'regexp-quote org-drawers
"\\|")
5450 (org-back-to-heading)
5451 (org-cycle-hide-drawers 'subtree
)))
5452 (message "Remote: show subtree and LOGBOOK"))
5455 (message "Remote: show subtree and LOGBOOK")))
5456 (select-window win
)))
5458 (defun org-recenter-heading (n)
5460 (org-back-to-heading)
5463 (defvar org-agenda-cycle-counter nil
)
5464 (defun org-agenda-cycle-show (n)
5465 "Show the current entry in another window, with default settings.
5466 Default settings are taken from `org-show-hierarchy-above' and siblings.
5467 When use repeadedly in immediate succession, the remote entry will cycle
5470 entry -> subtree -> subtree with logbook"
5473 (not (eq last-command this-command
)))
5474 (setq org-agenda-cycle-counter
0))
5475 (setq org-agenda-cycle-counter
(1+ org-agenda-cycle-counter
))
5476 (if (> org-agenda-cycle-counter
4)
5477 (setq org-agenda-cycle-counter
0))
5478 (org-agenda-show-1 org-agenda-cycle-counter
))
5480 (defun org-agenda-recenter (arg)
5481 "Display the Org-mode file which contains the item at point and recenter."
5483 (let ((win (selected-window)))
5486 (select-window win
)))
5488 (defun org-agenda-show-mouse (ev)
5489 "Display the Org-mode file which contains the item at the mouse click."
5491 (mouse-set-point ev
)
5494 (defun org-agenda-check-no-diary ()
5495 "Check if the entry is a diary link and abort if yes."
5496 (if (get-text-property (point) 'org-agenda-diary-link
)
5497 (org-agenda-error)))
5499 (defun org-agenda-error ()
5500 (error "Command not allowed in this line"))
5502 (defun org-agenda-tree-to-indirect-buffer ()
5503 "Show the subtree corresponding to the current entry in an indirect buffer.
5504 This calls the command `org-tree-to-indirect-buffer' from the original
5506 With numerical prefix arg ARG, go up to this level and then take that tree.
5507 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
5510 (org-agenda-check-no-diary)
5511 (let* ((marker (or (get-text-property (point) 'org-marker
)
5512 (org-agenda-error)))
5513 (buffer (marker-buffer marker
))
5514 (pos (marker-position marker
)))
5515 (with-current-buffer buffer
5518 (call-interactively 'org-tree-to-indirect-buffer
)))))
5520 (defvar org-last-heading-marker
(make-marker)
5521 "Marker pointing to the headline that last changed its TODO state
5522 by a remote command from the agenda.")
5524 (defun org-agenda-todo-nextset ()
5525 "Switch TODO entry to next sequence."
5527 (org-agenda-todo 'nextset
))
5529 (defun org-agenda-todo-previousset ()
5530 "Switch TODO entry to previous sequence."
5532 (org-agenda-todo 'previousset
))
5534 (defun org-agenda-todo (&optional arg
)
5535 "Cycle TODO state of line at point, also in Org-mode file.
5536 This changes the line at point, all other lines in the agenda referring to
5537 the same tree node, and the headline of the tree node in the Org-mode file."
5539 (org-agenda-check-no-diary)
5540 (let* ((col (current-column))
5541 (marker (or (get-text-property (point) 'org-marker
)
5542 (org-agenda-error)))
5543 (buffer (marker-buffer marker
))
5544 (pos (marker-position marker
))
5545 (hdmarker (get-text-property (point) 'org-hd-marker
))
5546 (todayp (equal (get-text-property (point) 'day
)
5547 (time-to-days (current-time))))
5548 (inhibit-read-only t
)
5549 org-agenda-headline-snapshot-before-repeat newhead just-one
)
5550 (org-with-remote-undo buffer
5551 (with-current-buffer buffer
5554 (org-show-context 'agenda
)
5556 (and (outline-next-heading)
5557 (org-flag-heading nil
))) ; show the next heading
5558 (let ((current-prefix-arg arg
))
5559 (call-interactively 'org-todo
))
5560 (and (bolp) (forward-char 1))
5561 (setq newhead
(org-get-heading))
5562 (when (and (org-bound-and-true-p
5563 org-agenda-headline-snapshot-before-repeat
)
5564 (not (equal org-agenda-headline-snapshot-before-repeat
5567 (setq newhead org-agenda-headline-snapshot-before-repeat
5570 (org-back-to-heading)
5571 (move-marker org-last-heading-marker
(point))))
5572 (beginning-of-line 1)
5574 (org-agenda-change-all-lines newhead hdmarker
'fixface just-one
))
5575 (org-move-to-column col
))))
5577 (defun org-agenda-add-note (&optional arg
)
5578 "Add a time-stamped note to the entry at point."
5580 (org-agenda-check-no-diary)
5581 (let* ((marker (or (get-text-property (point) 'org-marker
)
5582 (org-agenda-error)))
5583 (buffer (marker-buffer marker
))
5584 (pos (marker-position marker
))
5585 (hdmarker (get-text-property (point) 'org-hd-marker
))
5586 (inhibit-read-only t
))
5587 (with-current-buffer buffer
5590 (org-show-context 'agenda
)
5592 (and (outline-next-heading)
5593 (org-flag-heading nil
))) ; show the next heading
5596 (defun org-agenda-change-all-lines (newhead hdmarker
5597 &optional fixface just-this
)
5598 "Change all lines in the agenda buffer which match HDMARKER.
5599 The new content of the line will be NEWHEAD (as modified by
5600 `org-format-agenda-item'). HDMARKER is checked with
5601 `equal' against all `org-hd-marker' text properties in the file.
5602 If FIXFACE is non-nil, the face of each item is modified according to
5604 If JUST-THIS is non-nil, change just the current line, not all.
5605 If FORCE-TAGS is non nil, the car of it returns the new tags."
5606 (let* ((inhibit-read-only t
)
5607 (line (org-current-line))
5608 (thetags (with-current-buffer (marker-buffer hdmarker
)
5609 (save-excursion (save-restriction (widen)
5610 (goto-char hdmarker
)
5611 (org-get-tags-at)))))
5612 props m pl undone-face done-face finish new dotime cat tags
)
5614 (goto-char (point-max))
5615 (beginning-of-line 1)
5617 (setq finish
(bobp))
5618 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
5619 (or (not just-this
) (= (org-current-line) line
))
5621 (setq props
(text-properties-at (point))
5622 dotime
(get-text-property (point) 'dotime
)
5623 cat
(get-text-property (point) 'org-category
)
5625 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
5626 pl
(get-text-property (point) 'prefix-length
)
5627 undone-face
(get-text-property (point) 'undone-face
)
5628 done-face
(get-text-property (point) 'done-face
))
5629 (org-move-to-column pl
)
5632 (beginning-of-line 1)
5633 (and (looking-at ".*\n?") (replace-match "")))
5635 (replace-match new t t
)
5636 (beginning-of-line 1)
5637 (add-text-properties (point-at-bol) (point-at-eol) props
)
5639 (add-text-properties
5640 (point-at-bol) (point-at-eol)
5642 (if org-last-todo-state-is-todo
5643 undone-face done-face
))))
5644 (org-agenda-highlight-todo 'line
)
5645 (beginning-of-line 1))
5646 (t (error "Line update did not work"))))
5647 (beginning-of-line 0)))
5648 (org-finalize-agenda)))
5650 (defun org-agenda-align-tags (&optional line
)
5651 "Align all tags in agenda items to `org-agenda-tags-column'."
5652 (let ((inhibit-read-only t
) l c
)
5654 (goto-char (if line
(point-at-bol) (point-min)))
5655 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
5656 (if line
(point-at-eol) nil
) t
)
5657 (add-text-properties
5658 (match-beginning 2) (match-end 2)
5659 (list 'face
(delq nil
(let ((prop (get-text-property
5660 (match-beginning 2) 'face
)))
5661 (or (listp prop
) (setq prop
(list prop
)))
5662 (if (memq 'org-tag prop
)
5664 (cons 'org-tag prop
))))))
5665 (setq l
(- (match-end 2) (match-beginning 2))
5666 c
(if (< org-agenda-tags-column
0)
5667 (- (abs org-agenda-tags-column
) l
)
5668 org-agenda-tags-column
))
5669 (delete-region (match-beginning 1) (match-end 1))
5670 (goto-char (match-beginning 1))
5671 (insert (org-add-props
5672 (make-string (max 1 (- c
(current-column))) ?\
)
5673 (text-properties-at (point)))))
5674 (goto-char (point-min))
5675 (org-font-lock-add-tag-faces (point-max)))))
5677 (defun org-agenda-priority-up ()
5678 "Increase the priority of line at point, also in Org-mode file."
5680 (org-agenda-priority 'up
))
5682 (defun org-agenda-priority-down ()
5683 "Decrease the priority of line at point, also in Org-mode file."
5685 (org-agenda-priority 'down
))
5687 (defun org-agenda-priority (&optional force-direction
)
5688 "Set the priority of line at point, also in Org-mode file.
5689 This changes the line at point, all other lines in the agenda referring to
5690 the same tree node, and the headline of the tree node in the Org-mode file."
5692 (unless org-enable-priority-commands
5693 (error "Priority commands are disabled"))
5694 (org-agenda-check-no-diary)
5695 (let* ((marker (or (get-text-property (point) 'org-marker
)
5696 (org-agenda-error)))
5697 (hdmarker (get-text-property (point) 'org-hd-marker
))
5698 (buffer (marker-buffer hdmarker
))
5699 (pos (marker-position hdmarker
))
5700 (inhibit-read-only t
)
5702 (org-with-remote-undo buffer
5703 (with-current-buffer buffer
5706 (org-show-context 'agenda
)
5708 (and (outline-next-heading)
5709 (org-flag-heading nil
))) ; show the next heading
5710 (funcall 'org-priority force-direction
)
5712 (setq newhead
(org-get-heading)))
5713 (org-agenda-change-all-lines newhead hdmarker
)
5714 (beginning-of-line 1))))
5716 ;; FIXME: should fix the tags property of the agenda line.
5717 (defun org-agenda-set-tags ()
5718 "Set tags for the current headline."
5720 (org-agenda-check-no-diary)
5721 (if (and (org-region-active-p) (interactive-p))
5722 (call-interactively 'org-change-tag-in-region
)
5723 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5724 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5725 (org-agenda-error)))
5726 (buffer (marker-buffer hdmarker
))
5727 (pos (marker-position hdmarker
))
5728 (inhibit-read-only t
)
5730 (org-with-remote-undo buffer
5731 (with-current-buffer buffer
5735 (org-show-context 'agenda
))
5737 (and (outline-next-heading)
5738 (org-flag-heading nil
))) ; show the next heading
5740 (call-interactively 'org-set-tags
)
5742 (setq newhead
(org-get-heading)))
5743 (org-agenda-change-all-lines newhead hdmarker
)
5744 (beginning-of-line 1)))))
5746 (defun org-agenda-toggle-archive-tag ()
5747 "Toggle the archive tag for the current entry."
5749 (org-agenda-check-no-diary)
5750 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5751 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5752 (org-agenda-error)))
5753 (buffer (marker-buffer hdmarker
))
5754 (pos (marker-position hdmarker
))
5755 (inhibit-read-only t
)
5757 (org-with-remote-undo buffer
5758 (with-current-buffer buffer
5761 (org-show-context 'agenda
)
5763 (and (outline-next-heading)
5764 (org-flag-heading nil
))) ; show the next heading
5765 (call-interactively 'org-toggle-archive-tag
)
5767 (setq newhead
(org-get-heading)))
5768 (org-agenda-change-all-lines newhead hdmarker
)
5769 (beginning-of-line 1))))
5771 (defun org-agenda-do-date-later (arg)
5774 ((or (equal arg
'(16))
5776 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5777 (setq this-command
'org-agenda-date-later-minutes
)
5778 (org-agenda-date-later-minutes 1))
5779 ((or (equal arg
'(4))
5781 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5782 (setq this-command
'org-agenda-date-later-hours
)
5783 (org-agenda-date-later-hours 1))
5785 (org-agenda-date-later (prefix-numeric-value arg
)))))
5787 (defun org-agenda-do-date-earlier (arg)
5790 ((or (equal arg
'(16))
5792 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5793 (setq this-command
'org-agenda-date-earlier-minutes
)
5794 (org-agenda-date-earlier-minutes 1))
5795 ((or (equal arg
'(4))
5797 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5798 (setq this-command
'org-agenda-date-earlier-hours
)
5799 (org-agenda-date-earlier-hours 1))
5801 (org-agenda-date-earlier (prefix-numeric-value arg
)))))
5803 (defun org-agenda-date-later (arg &optional what
)
5804 "Change the date of this item to one day later."
5806 (org-agenda-check-type t
'agenda
'timeline
)
5807 (org-agenda-check-no-diary)
5808 (let* ((marker (or (get-text-property (point) 'org-marker
)
5809 (org-agenda-error)))
5810 (buffer (marker-buffer marker
))
5811 (pos (marker-position marker
)))
5812 (org-with-remote-undo buffer
5813 (with-current-buffer buffer
5816 (if (not (org-at-timestamp-p))
5817 (error "Cannot find time stamp"))
5818 (org-timestamp-change arg
(or what
'day
)))
5819 (org-agenda-show-new-time marker org-last-changed-timestamp
))
5820 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
5822 (defun org-agenda-date-earlier (arg &optional what
)
5823 "Change the date of this item to one day earlier."
5825 (org-agenda-date-later (- arg
) what
))
5827 (defun org-agenda-date-later-minutes (arg)
5828 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5830 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5831 (org-agenda-date-later arg
'minute
))
5833 (defun org-agenda-date-earlier-minutes (arg)
5834 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5836 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5837 (org-agenda-date-earlier arg
'minute
))
5839 (defun org-agenda-date-later-hours (arg)
5840 "Change the time of this item, in hour steps."
5842 (org-agenda-date-later arg
'hour
))
5844 (defun org-agenda-date-earlier-hours (arg)
5845 "Change the time of this item, in hour steps."
5847 (org-agenda-date-earlier arg
'hour
))
5849 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
5850 "Show new date stamp via text properties."
5851 ;; We use text properties to make this undoable
5852 (let ((inhibit-read-only t
)
5853 (buffer-invisibility-spec))
5854 (setq stamp
(concat " " prefix
" => " stamp
))
5856 (goto-char (point-max))
5858 (when (equal marker
(get-text-property (point) 'org-marker
))
5859 (org-move-to-column (- (window-width) (length stamp
)) t
)
5860 (org-agenda-fix-tags-filter-overlays-at (point))
5861 (if (featurep 'xemacs
)
5862 ;; Use `duplicable' property to trigger undo recording
5863 (let ((ex (make-extent nil nil
))
5864 (gl (make-glyph stamp
)))
5865 (set-glyph-face gl
'secondary-selection
)
5866 (set-extent-properties
5867 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
5868 (insert-extent ex
(1- (point)) (point-at-eol)))
5869 (add-text-properties
5870 (1- (point)) (point-at-eol)
5871 (list 'display
(org-add-props stamp nil
5872 'face
'secondary-selection
))))
5873 (beginning-of-line 1))
5874 (beginning-of-line 0)))))
5876 (defun org-agenda-date-prompt (arg)
5877 "Change the date of this item. Date is prompted for, with default today.
5878 The prefix ARG is passed to the `org-time-stamp' command and can therefore
5879 be used to request time specification in the time stamp."
5881 (org-agenda-check-type t
'agenda
'timeline
)
5882 (org-agenda-check-no-diary)
5883 (let* ((marker (or (get-text-property (point) 'org-marker
)
5884 (org-agenda-error)))
5885 (buffer (marker-buffer marker
))
5886 (pos (marker-position marker
)))
5887 (org-with-remote-undo buffer
5888 (with-current-buffer buffer
5891 (if (not (org-at-timestamp-p))
5892 (error "Cannot find time stamp"))
5893 (org-time-stamp arg
)
5894 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
5896 (defun org-agenda-schedule (arg)
5897 "Schedule the item at point."
5899 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
5900 (org-agenda-check-no-diary)
5901 (let* ((marker (or (get-text-property (point) 'org-marker
)
5902 (org-agenda-error)))
5903 (type (marker-insertion-type marker
))
5904 (buffer (marker-buffer marker
))
5905 (pos (marker-position marker
))
5906 (org-insert-labeled-timestamps-at-point nil
)
5908 (set-marker-insertion-type marker t
)
5909 (org-with-remote-undo buffer
5910 (with-current-buffer buffer
5913 (setq ts
(org-schedule arg
)))
5914 (org-agenda-show-new-time marker ts
"S"))
5915 (message "Item scheduled for %s" ts
)))
5917 (defun org-agenda-deadline (arg)
5918 "Schedule the item at point."
5920 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
5921 (org-agenda-check-no-diary)
5922 (let* ((marker (or (get-text-property (point) 'org-marker
)
5923 (org-agenda-error)))
5924 (buffer (marker-buffer marker
))
5925 (pos (marker-position marker
))
5926 (org-insert-labeled-timestamps-at-point nil
)
5928 (org-with-remote-undo buffer
5929 (with-current-buffer buffer
5932 (setq ts
(org-deadline arg
)))
5933 (org-agenda-show-new-time marker ts
"S"))
5934 (message "Deadline for this item set to %s" ts
)))
5936 (defun org-agenda-action ()
5937 "Select entry for agenda action, or execute an agenda action.
5938 This command prompts for another letter. Valid inputs are:
5940 m Mark the entry at point for an agenda action
5941 s Schedule the marked entry to the date at the cursor
5942 d Set the deadline of the marked entry to the date at the cursor
5943 r Call `org-remember' with cursor date as the default date
5944 SPC Show marked entry in other window
5945 TAB Visit marked entry in other window
5947 The cursor may be at a date in the calendar, or in the Org agenda."
5950 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
5951 (setq ans
(read-char-exclusive))
5955 (if (eq major-mode
'org-agenda-mode
)
5956 (let ((m (or (get-text-property (point) 'org-hd-marker
)
5957 (get-text-property (point) 'org-marker
))))
5960 (move-marker org-agenda-action-marker
5961 (marker-position m
) (marker-buffer m
))
5962 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
5963 (error "Don't know which entry to mark")))
5964 (error "This command works only in the agenda")))
5966 (org-agenda-do-action '(org-schedule nil org-overriding-default-time
)))
5968 (org-agenda-do-action '(org-deadline nil org-overriding-default-time
)))
5970 (org-agenda-do-action '(org-remember) t
))
5972 (let ((cw (selected-window)))
5973 (org-switch-to-buffer-other-window
5974 (marker-buffer org-agenda-action-marker
))
5975 (goto-char org-agenda-action-marker
)
5976 (org-show-context 'agenda
)
5977 (select-window cw
)))
5979 (org-switch-to-buffer-other-window
5980 (marker-buffer org-agenda-action-marker
))
5981 (goto-char org-agenda-action-marker
)
5982 (org-show-context 'agenda
))
5983 (t (error "Invalid agenda action %c" ans
)))))
5985 (defun org-agenda-do-action (form &optional current-buffer
)
5986 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
5987 (let ((org-overriding-default-time (org-get-cursor-date)))
5990 (if (not (marker-buffer org-agenda-action-marker
))
5991 (error "No entry has bee selected for agenda action")
5992 (with-current-buffer (marker-buffer org-agenda-action-marker
)
5996 (goto-char org-agenda-action-marker
)
5999 (defun org-agenda-clock-in (&optional arg
)
6000 "Start the clock on the currently selected item."
6002 (org-agenda-check-no-diary)
6003 (if (equal arg
'(4))
6005 (let* ((marker (or (get-text-property (point) 'org-marker
)
6006 (org-agenda-error)))
6007 (hdmarker (or (get-text-property (point) 'org-hd-marker
)
6009 (pos (marker-position marker
))
6011 (org-with-remote-undo (marker-buffer marker
)
6012 (with-current-buffer (marker-buffer marker
)
6015 (org-show-context 'agenda
)
6017 (org-cycle-hide-drawers 'children
)
6019 (setq newhead
(org-get-heading)))
6020 (org-agenda-change-all-lines newhead hdmarker t
)))))
6022 (defun org-agenda-clock-out (&optional arg
)
6023 "Stop the currently running clock."
6025 (unless (marker-buffer org-clock-marker
)
6026 (error "No running clock"))
6027 (org-with-remote-undo (marker-buffer org-clock-marker
)
6030 (defun org-agenda-clock-cancel (&optional arg
)
6031 "Cancel the currently running clock."
6033 (unless (marker-buffer org-clock-marker
)
6034 (error "No running clock"))
6035 (org-with-remote-undo (marker-buffer org-clock-marker
)
6036 (org-clock-cancel)))
6038 (defun org-agenda-diary-entry ()
6039 "Make a diary entry, like the `i' command from the calendar.
6040 All the standard commands work: block, weekly etc."
6042 (org-agenda-check-type t
'agenda
'timeline
)
6043 (require 'diary-lib
)
6045 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6046 (read-char-exclusive)))
6047 (cmd (cdr (assoc char
6048 '((?d . insert-diary-entry
)
6049 (?w . insert-weekly-diary-entry
)
6050 (?m . insert-monthly-diary-entry
)
6051 (?y . insert-yearly-diary-entry
)
6052 (?a . insert-anniversary-diary-entry
)
6053 (?b . insert-block-diary-entry
)
6054 (?c . insert-cyclic-diary-entry
)))))
6055 (oldf (symbol-function 'calendar-cursor-to-date
))
6056 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6058 (mark (or (mark t
) (point))))
6060 (error "No command associated with <%c>" char
))
6061 (unless (and (get-text-property point
'day
)
6062 (or (not (equal ?b char
))
6063 (get-text-property mark
'day
)))
6064 (error "Don't know which date to use for diary entry"))
6065 ;; We implement this by hacking the `calendar-cursor-to-date' function
6066 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6067 (let ((calendar-mark-ring
6068 (list (calendar-gregorian-from-absolute
6069 (or (get-text-property mark
'day
)
6070 (get-text-property point
'day
))))))
6073 (fset 'calendar-cursor-to-date
6074 (lambda (&optional error dummy
)
6075 (calendar-gregorian-from-absolute
6076 (get-text-property point
'day
))))
6077 (call-interactively cmd
))
6078 (fset 'calendar-cursor-to-date oldf
)))))
6080 (defun org-agenda-execute-calendar-command (cmd)
6081 "Execute a calendar command from the agenda, with the date associated to
6082 the cursor position."
6083 (org-agenda-check-type t
'agenda
'timeline
)
6084 (require 'diary-lib
)
6085 (unless (get-text-property (point) 'day
)
6086 (error "Don't know which date to use for calendar command"))
6087 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
6089 (date (calendar-gregorian-from-absolute
6090 (get-text-property point
'day
)))
6091 ;; the following 2 vars are needed in the calendar
6092 (displayed-month (car date
))
6093 (displayed-year (nth 2 date
)))
6096 (fset 'calendar-cursor-to-date
6097 (lambda (&optional error dummy
)
6098 (calendar-gregorian-from-absolute
6099 (get-text-property point
'day
))))
6100 (call-interactively cmd
))
6101 (fset 'calendar-cursor-to-date oldf
))))
6103 (defun org-agenda-phases-of-moon ()
6104 "Display the phases of the moon for the 3 months around the cursor date."
6106 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
6108 (defun org-agenda-holidays ()
6109 "Display the holidays for the 3 months around the cursor date."
6111 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
6113 (defvar calendar-longitude
)
6114 (defvar calendar-latitude
)
6115 (defvar calendar-location-name
)
6117 (defun org-agenda-sunrise-sunset (arg)
6118 "Display sunrise and sunset for the cursor date.
6119 Latitude and longitude can be specified with the variables
6120 `calendar-latitude' and `calendar-longitude'. When called with prefix
6121 argument, latitude and longitude will be prompted for."
6124 (let ((calendar-longitude (if arg nil calendar-longitude
))
6125 (calendar-latitude (if arg nil calendar-latitude
))
6126 (calendar-location-name
6127 (if arg
"the given coordinates" calendar-location-name
)))
6128 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
6130 (defun org-agenda-goto-calendar ()
6131 "Open the Emacs calendar with the date at the cursor."
6133 (org-agenda-check-type t
'agenda
'timeline
)
6134 (let* ((day (or (get-text-property (point) 'day
)
6135 (error "Don't know which date to open in calendar")))
6136 (date (calendar-gregorian-from-absolute day
))
6137 (calendar-move-hook nil
)
6138 (calendar-view-holidays-initially-flag nil
)
6139 (calendar-view-diary-initially-flag nil
)
6140 (view-calendar-holidays-initially nil
)
6141 (view-diary-entries-initially nil
))
6143 (calendar-goto-date date
)))
6146 (defun org-calendar-goto-agenda ()
6147 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6148 This is a command that has to be installed in `calendar-mode-map'."
6150 (org-agenda-list nil
(calendar-absolute-from-gregorian
6151 (calendar-cursor-to-date))
6154 (defun org-agenda-convert-date ()
6156 (org-agenda-check-type t
'agenda
'timeline
)
6157 (let ((day (get-text-property (point) 'day
))
6160 (error "Don't know which date to convert"))
6161 (setq date
(calendar-gregorian-from-absolute day
))
6163 "Gregorian: " (calendar-date-string date
) "\n"
6164 "ISO: " (calendar-iso-date-string date
) "\n"
6165 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
6166 "Julian: " (calendar-julian-date-string date
) "\n"
6167 "Astron. JD: " (calendar-astro-date-string date
)
6168 " (Julian date number at noon UTC)\n"
6169 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
6170 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
6171 "French: " (calendar-french-date-string date
) "\n"
6172 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
6173 "Mayan: " (calendar-mayan-date-string date
) "\n"
6174 "Coptic: " (calendar-coptic-date-string date
) "\n"
6175 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
6176 "Persian: " (calendar-persian-date-string date
) "\n"
6177 "Chinese: " (calendar-chinese-date-string date
) "\n"))
6178 (with-output-to-temp-buffer "*Dates*"
6180 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6182 ;;; Appointment reminders
6184 (defvar appt-time-msg-list
)
6187 (defun org-agenda-to-appt (&optional refresh filter
)
6188 "Activate appointments found in `org-agenda-files'.
6189 With a \\[universal-argument] prefix, refresh the list of
6192 If FILTER is t, interactively prompt the user for a regular
6193 expression, and filter out entries that don't match it.
6195 If FILTER is a string, use this string as a regular expression
6196 for filtering entries out.
6198 FILTER can also be an alist with the car of each cell being
6199 either 'headline or 'category. For example:
6201 '((headline \"IMPORTANT\")
6202 (category \"Work\"))
6204 will only add headlines containing IMPORTANT or headlines
6205 belonging to the \"Work\" category."
6208 (if refresh
(setq appt-time-msg-list nil
))
6210 (setq filter
(read-from-minibuffer "Regexp filter: ")))
6211 (let* ((cnt 0) ; count added events
6212 (org-agenda-new-buffers nil
)
6213 (org-deadline-warning-days 0)
6214 (today (org-date-to-gregorian
6215 (time-to-days (current-time))))
6216 (org-agenda-restrict nil
)
6217 (files (org-agenda-files 'unrestricted
)) entries file
)
6218 ;; Get all entries which may contain an appt
6219 (org-prepare-agenda-buffers files
)
6220 (while (setq file
(pop files
))
6223 (org-agenda-get-day-entries
6224 file today
:timestamp
:scheduled
:deadline
))))
6225 (setq entries
(delq nil entries
))
6226 ;; Map thru entries and find if we should filter them out
6229 (let* ((evt (org-trim (or (get-text-property 1 'txt x
) "")))
6230 (cat (get-text-property 1 'org-category x
))
6231 (tod (get-text-property 1 'time-of-day x
))
6232 (ok (or (null filter
)
6233 (and (stringp filter
) (string-match filter evt
))
6236 (cadr (assoc 'category filter
)) cat
)
6238 (cadr (assoc 'headline filter
)) evt
))))))
6239 ;; FIXME: Shall we remove text-properties for the appt text?
6240 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
6242 (setq tod
(concat "00" (number-to-string tod
))
6243 tod
(when (string-match
6244 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod
)
6245 (concat (match-string 1 tod
) ":"
6246 (match-string 2 tod
))))
6248 (setq cnt
(1+ cnt
))))) entries
)
6249 (org-release-buffers org-agenda-new-buffers
)
6251 (message "No event to add")
6252 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
6254 (defun org-agenda-todayp (date)
6255 "Does DATE mean today, when considering `org-extend-today-until'?"
6257 (if (listp date
) (setq date
(calendar-absolute-from-gregorian date
)))
6258 (setq today
(calendar-absolute-from-gregorian (calendar-current-date)))
6259 (setq h
(nth 2 (decode-time (current-time))))
6260 (or (and (>= h org-extend-today-until
)
6262 (and (< h org-extend-today-until
)
6263 (= date
(1- today
))))))
6265 (provide 'org-agenda
)
6267 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
6269 ;;; org-agenda.el ends here