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 Note that the way this is implemented, the values will be evaluated
107 before assigned to the variables. So make sure to quote values you do
108 *not* want evaluated, for example
110 (setq org-agenda-exporter-settings
111 '((ps-print-color-p 'black-white)))"
112 :group
'org-agenda-export
116 (sexp :tag
"Value"))))
118 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
119 "Hook run in temporary buffer before writing it to an export file.
120 A useful function is `org-agenda-add-entry-text'."
121 :group
'org-agenda-export
123 :options
'(org-agenda-add-entry-text))
125 (defcustom org-agenda-add-entry-text-maxlines
0
126 "Maximum number of entry text lines to be added to agenda.
127 This is only relevant when `org-agenda-add-entry-text' is part of
128 `org-agenda-before-write-hook', which it is by default.
129 When this is 0, nothing will happen. When it is greater than 0, it
130 specifies the maximum number of lines that will be added for each entry
131 that is listed in the agenda view."
135 (defcustom org-agenda-add-entry-text-descriptive-links t
136 "Non-nil means, export org-links as descriptive links in agenda added text.
137 This variable applies to the text added to the agenda when
138 `org-agenda-add-entry-text-maxlines' is larger than 0.
139 When this variable nil, the URL will (also) be shown."
143 (defcustom org-agenda-export-html-style
""
144 "The style specification for exported HTML Agenda files.
145 If this variable contains a string, it will replace the default <style>
146 section as produced by `htmlize'.
147 Since there are different ways of setting style information, this variable
148 needs to contain the full HTML structure to provide a style, including the
149 surrounding HTML tags. The style specifications should include definitions
150 the fonts used by the agenda, here is an example:
152 <style type=\"text/css\">
153 p { font-weight: normal; color: gray; }
154 .org-agenda-structure {
169 .title { text-align: center; }
170 .todo, .deadline { color: red; }
171 .done { color: green; }
174 or, if you want to keep the style in a file,
176 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
178 As the value of this option simply gets inserted into the HTML <head> header,
179 you can \"misuse\" it to also add other text to the header. However,
180 <style>...</style> is required, if not present the variable will be ignored."
181 :group
'org-agenda-export
182 :group
'org-export-html
185 (defgroup org-agenda-custom-commands nil
186 "Options concerning agenda views in Org-mode."
187 :tag
"Org Agenda Custom Commands"
190 (defconst org-sorting-choice
192 (const time-up
) (const time-down
)
193 (const category-keep
) (const category-up
) (const category-down
)
194 (const tag-down
) (const tag-up
)
195 (const priority-up
) (const priority-down
)
196 (const todo-state-up
) (const todo-state-down
)
197 (const effort-up
) (const effort-down
)
198 (const user-defined-up
) (const user-defined-down
))
201 (defconst org-agenda-custom-commands-local-options
202 `(repeat :tag
"Local settings for this command. Remember to quote values"
203 (choice :tag
"Setting"
204 (list :tag
"Heading for this block"
205 (const org-agenda-overriding-header
)
206 (string :tag
"Headline"))
207 (list :tag
"Files to be searched"
208 (const org-agenda-files
)
210 (const :format
"" quote
)
212 (list :tag
"Sorting strategy"
213 (const org-agenda-sorting-strategy
)
215 (const :format
"" quote
)
217 ,org-sorting-choice
)))
218 (list :tag
"Prefix format"
219 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
221 (list :tag
"Number of days in agenda"
222 (const org-agenda-ndays
)
224 (list :tag
"Fixed starting date"
225 (const org-agenda-start-day
)
226 (string :value
"2007-11-01"))
227 (list :tag
"Start on day of week"
228 (const org-agenda-start-on-weekday
)
230 (const :tag
"Today" nil
)
231 (integer :tag
"Weekday No.")))
232 (list :tag
"Include data from diary"
233 (const org-agenda-include-diary
)
235 (list :tag
"Deadline Warning days"
236 (const org-deadline-warning-days
)
238 (list :tag
"Tags filter preset"
239 (const org-agenda-filter-preset
)
241 (const :format
"" quote
)
243 (string :tag
"+tag or -tag"))))
244 (list :tag
"Standard skipping condition"
245 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
246 (const org-agenda-skip-function
)
248 (const :format
"" quote
)
251 :tag
"Skipping range"
252 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
253 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
254 (repeat :inline t
:tag
"Conditions for skipping"
256 :tag
"Condition type"
257 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
258 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
259 (const :tag
"scheduled" 'scheduled
)
260 (const :tag
"not scheduled" 'notscheduled
)
261 (const :tag
"deadline" 'deadline
)
262 (const :tag
"no deadline" 'notdeadline
)
263 (const :tag
"timestamp" 'timestamp
)
264 (const :tag
"no timestamp" 'nottimestamp
))))))
265 (list :tag
"Non-standard skipping condition"
266 :value
(org-agenda-skip-function)
267 (const org-agenda-skip-function
)
268 (sexp :tag
"Function or form (quoted!)"))
269 (list :tag
"Any variable"
270 (variable :tag
"Variable")
271 (sexp :tag
"Value (sexp)"))))
272 "Selection of examples for agenda command settings.
273 This will be spliced into the custom type of
274 `org-agenda-custom-commands'.")
277 (defcustom org-agenda-custom-commands nil
278 "Custom commands for the agenda.
279 These commands will be offered on the splash screen displayed by the
280 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
282 (key desc type match settings files)
284 key The key (one or more characters as a string) to be associated
286 desc A description of the command, when omitted or nil, a default
287 description is built using MATCH.
288 type The command type, any of the following symbols:
289 agenda The daily/weekly agenda.
290 todo Entries with a specific TODO keyword, in all agenda files.
291 search Entries containing search words entry or headline.
292 tags Tags/Property/TODO match in all agenda files.
293 tags-todo Tags/P/T match in all agenda files, TODO entries only.
294 todo-tree Sparse tree of specific TODO keyword in *current* file.
295 tags-tree Sparse tree with all tags matches in *current* file.
296 occur-tree Occur sparse tree for *current* file.
297 ... A user-defined function.
298 match What to search for:
299 - a single keyword for TODO keyword searches
300 - a tags match expression for tags searches
301 - a word search expression for text searches.
302 - a regular expression for occur searches
303 For all other commands, this should be the empty string.
304 settings A list of option settings, similar to that in a let form, so like
305 this: ((opt1 val1) (opt2 val2) ...). The values will be
306 evaluated at the moment of execution, so quote them when needed.
307 files A list of files file to write the produced agenda buffer to
308 with the command `org-store-agenda-views'.
309 If a file name ends in \".html\", an HTML version of the buffer
310 is written out. If it ends in \".ps\", a postscript version is
311 produced. Otherwise, only the plain text is written to the file.
313 You can also define a set of commands, to create a composite agenda buffer.
314 In this case, an entry looks like this:
316 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
320 desc A description string to be displayed in the dispatcher menu.
321 cmd An agenda command, similar to the above. However, tree commands
322 are no allowed, but instead you can get agenda and global todo list.
323 So valid commands for a set are:
324 (agenda \"\" settings)
325 (alltodo \"\" settings)
326 (stuck \"\" settings)
327 (todo \"match\" settings files)
328 (search \"match\" settings files)
329 (tags \"match\" settings files)
330 (tags-todo \"match\" settings files)
332 Each command can carry a list of options, and another set of options can be
333 given for the whole set of commands. Individual command options take
334 precedence over the general options.
336 When using several characters as key to a command, the first characters
337 are prefix commands. For the dispatcher to display useful information, you
338 should provide a description for the prefix, like
340 (setq org-agenda-custom-commands
341 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
342 (\"hl\" tags \"+HOME+Lisa\")
343 (\"hp\" tags \"+HOME+Peter\")
344 (\"hk\" tags \"+HOME+Kim\")))"
345 :group
'org-agenda-custom-commands
347 (choice :value
("x" "Describe command here" tags
"" nil
)
348 (list :tag
"Single command"
349 (string :tag
"Access Key(s) ")
350 (option (string :tag
"Description"))
352 (const :tag
"Agenda" agenda
)
353 (const :tag
"TODO list" alltodo
)
354 (const :tag
"Search words" search
)
355 (const :tag
"Stuck projects" stuck
)
356 (const :tag
"Tags/Property match (all agenda files)" tags
)
357 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
358 (const :tag
"TODO keyword search (all agenda files)" todo
)
359 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
360 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
361 (const :tag
"Occur tree (current buffer)" occur-tree
)
362 (sexp :tag
"Other, user-defined function"))
363 (string :tag
"Match (only for some commands)")
364 ,org-agenda-custom-commands-local-options
365 (option (repeat :tag
"Export" (file :tag
"Export to"))))
366 (list :tag
"Command series, all agenda files"
367 (string :tag
"Access Key(s)")
368 (string :tag
"Description ")
369 (repeat :tag
"Component"
372 (const :format
"" agenda
)
373 (const :tag
"" :format
"" "")
374 ,org-agenda-custom-commands-local-options
)
375 (list :tag
"TODO list (all keywords)"
376 (const :format
"" alltodo
)
377 (const :tag
"" :format
"" "")
378 ,org-agenda-custom-commands-local-options
)
379 (list :tag
"Search words"
380 (const :format
"" search
)
381 (string :tag
"Match")
382 ,org-agenda-custom-commands-local-options
)
383 (list :tag
"Stuck projects"
384 (const :format
"" stuck
)
385 (const :tag
"" :format
"" "")
386 ,org-agenda-custom-commands-local-options
)
387 (list :tag
"Tags search"
388 (const :format
"" tags
)
389 (string :tag
"Match")
390 ,org-agenda-custom-commands-local-options
)
391 (list :tag
"Tags search, TODO entries only"
392 (const :format
"" tags-todo
)
393 (string :tag
"Match")
394 ,org-agenda-custom-commands-local-options
)
395 (list :tag
"TODO keyword search"
396 (const :format
"" todo
)
397 (string :tag
"Match")
398 ,org-agenda-custom-commands-local-options
)
399 (list :tag
"Other, user-defined function"
400 (symbol :tag
"function")
401 (string :tag
"Match")
402 ,org-agenda-custom-commands-local-options
)))
404 (repeat :tag
"Settings for entire command set"
405 (list (variable :tag
"Any variable")
406 (sexp :tag
"Value")))
407 (option (repeat :tag
"Export" (file :tag
"Export to"))))
408 (cons :tag
"Prefix key documentation"
409 (string :tag
"Access Key(s)")
410 (string :tag
"Description ")))))
412 (defcustom org-agenda-query-register ?o
413 "The register holding the current query string.
414 The purpose of this is that if you construct a query string interactively,
415 you can then use it to define a custom command."
416 :group
'org-agenda-custom-commands
419 (defcustom org-stuck-projects
420 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
421 "How to identify stuck projects.
422 This is a list of four items:
423 1. A tags/todo/property matcher string that is used to identify a project.
424 See the manual for a description of tag and property searches.
425 The entire tree below a headline matched by this is considered one project.
426 2. A list of TODO keywords identifying non-stuck projects.
427 If the project subtree contains any headline with one of these todo
428 keywords, the project is considered to be not stuck. If you specify
429 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
430 3. A list of tags identifying non-stuck projects.
431 If the project subtree contains any headline with one of these tags,
432 the project is considered to be not stuck. If you specify \"*\" as
433 a tag, any tag will mark the project unstuck. Note that this is about
434 the explicit presence of a tag somewhere in the subtree, inherited
435 tags to not count here. If inherited tags make a project not stuck,
436 use \"-TAG\" in the tags part of the matcher under (1.) above.
437 4. An arbitrary regular expression matching non-stuck projects.
439 If the project turns out to be not stuck, search continues also in the
440 subtree to see if any of the subtasks have project status.
442 See also the variable `org-tags-match-list-sublevels' which applies
443 to projects matched by this search as well.
445 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
446 or `C-c a #' to produce the list."
447 :group
'org-agenda-custom-commands
449 (string :tag
"Tags/TODO match to identify a project")
450 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
451 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
452 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
454 (defcustom org-agenda-filter-effort-default-operator
"<"
455 "The default operator for effort estimate filtering.
456 If you select an effort estimate limit without first pressing an operator,
457 this one will be used."
458 :group
'org-agenda-custom-commands
459 :type
'(choice (const :tag
"less or equal" "<")
460 (const :tag
"greater or equal"">")
461 (const :tag
"equal" "=")))
463 (defgroup org-agenda-skip nil
464 "Options concerning skipping parts of agenda files."
465 :tag
"Org Agenda Skip"
467 (defgroup org-agenda-daily
/weekly nil
468 "Options concerning the daily/weekly agenda."
469 :tag
"Org Agenda Daily/Weekly"
471 (defgroup org-agenda-todo-list nil
472 "Options concerning the global todo list agenda view."
473 :tag
"Org Agenda Todo List"
475 (defgroup org-agenda-match-view nil
476 "Options concerning the general tags/property/todo match agenda view."
477 :tag
"Org Agenda Match View"
480 (defvar org-agenda-archives-mode nil
481 "Non-nil means, the agenda will include archived items.
482 If this is the symbol `trees', trees in the selected agenda scope
483 that are marked with the ARCHIVE tag will be included anyway. When this is
484 t, also all archive files associated with the current selection of agenda
485 files will be included.")
487 (defcustom org-agenda-skip-comment-trees t
488 "Non-nil means, skip trees that start with the COMMENT keyword.
489 When nil, these trees are also scanned by agenda commands."
490 :group
'org-agenda-skip
493 (defcustom org-agenda-todo-list-sublevels t
494 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
495 When nil, the sublevels of a TODO entry are not checked, resulting in
496 potentially much shorter TODO lists."
497 :group
'org-agenda-skip
498 :group
'org-agenda-todo-list
501 (defcustom org-agenda-todo-ignore-with-date nil
502 "Non-nil means, don't show entries with a date in the global todo list.
503 You can use this if you prefer to mark mere appointments with a TODO keyword,
504 but don't want them to show up in the TODO list.
505 When this is set, it also covers deadlines and scheduled items, the settings
506 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
508 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
509 :group
'org-agenda-skip
510 :group
'org-agenda-todo-list
513 (defcustom org-agenda-todo-ignore-scheduled nil
514 "Non-nil means, don't show scheduled entries in the global todo list.
515 The idea behind this is that by scheduling it, you have already taken care
517 See also `org-agenda-todo-ignore-with-date'.
518 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
519 :group
'org-agenda-skip
520 :group
'org-agenda-todo-list
523 (defcustom org-agenda-todo-ignore-deadlines nil
524 "Non-nil means, don't show near deadline entries in the global todo list.
525 Near means closer than `org-deadline-warning-days' days.
526 The idea behind this is that such items will appear in the agenda anyway.
527 See also `org-agenda-todo-ignore-with-date'.
528 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
529 :group
'org-agenda-skip
530 :group
'org-agenda-todo-list
533 (defcustom org-agenda-tags-todo-honor-ignore-options nil
534 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
536 `org-agenda-todo-ignore-with-date',
537 `org-agenda-todo-ignore-scheduled'
538 `org-agenda-todo-ignore-deadlines'
539 make the global TODO list skip entries that have time stamps of certain
540 kinds. If this option is set, the same options will also apply for the
541 tags-todo search, which is the general tags/property matcher
542 restricted to unfinished TODO entries only."
543 :group
'org-agenda-skip
544 :group
'org-agenda-todo-list
545 :group
'org-agenda-match-view
548 (defcustom org-agenda-skip-scheduled-if-done nil
549 "Non-nil means don't show scheduled items in agenda when they are done.
550 This is relevant for the daily/weekly agenda, not for the TODO list. And
551 it applies only to the actual date of the scheduling. Warnings about
552 an item with a past scheduling dates are always turned off when the item
554 :group
'org-agenda-skip
555 :group
'org-agenda-daily
/weekly
558 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
559 "Non-nil means skip scheduling line if same entry shows because of deadline.
560 In the agenda of today, an entry can show up multiple times because
561 it is both scheduled and has a nearby deadline, and maybe a plain time
563 When this variable is t, then only the deadline is shown and the fact that
564 the entry is scheduled today or was scheduled previously is not shown.
565 When this variable is nil, the entry will be shown several times. When
566 the variable is the symbol `not-today', then skip scheduled previously,
567 but not scheduled today."
568 :group
'org-agenda-skip
569 :group
'org-agenda-daily
/weekly
571 (const :tag
"Never" nil
)
572 (const :tag
"Always" t
)
573 (const :tag
"Not when scheduled today" not-today
)))
575 (defcustom org-agenda-skip-deadline-if-done nil
576 "Non-nil means don't show deadlines when the corresponding item is done.
577 When nil, the deadline is still shown and should give you a happy feeling.
578 This is relevant for the daily/weekly agenda. And it applied only to the
579 actually date of the deadline. Warnings about approaching and past-due
580 deadlines are always turned off when the item is DONE."
581 :group
'org-agenda-skip
582 :group
'org-agenda-daily
/weekly
585 (defcustom org-agenda-skip-additional-timestamps-same-entry t
586 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
587 When non-nil, after the search for timestamps has matched once in an
588 entry, the rest of the entry will not be searched."
589 :group
'org-agenda-skip
592 (defcustom org-agenda-skip-timestamp-if-done nil
593 "Non-nil means don't select item by timestamp or -range if it is DONE."
594 :group
'org-agenda-skip
595 :group
'org-agenda-daily
/weekly
598 (defcustom org-agenda-dim-blocked-tasks t
599 "Non-nil means, dim blocked tasks in the agenda display.
600 This causes some overhead during agenda construction, but if you
601 have turned on `org-enforce-todo-dependencies',
602 `org-enforce-todo-checkbox-dependencies', or any other blocking
603 mechanism, this will create useful feedback in the agenda.
605 Instead ot t, this variable can also have the value `invisible'.
606 Then blocked tasks will be invisible and only become visible when
607 they become unblocked. An exemption to this behavior is when a task is
608 blocked because of unchecked checkboxes below it. Since checkboxes do
609 not show up in the agenda views, making this task invisible you remove any
610 trace from agenda views that there is something to do. Therefore, a task
611 that is blocked because of checkboxes will never be made invisible, it
612 will only be dimmed."
613 :group
'org-agenda-daily
/weekly
614 :group
'org-agenda-todo-list
616 (const :tag
"Do not dim" nil
)
617 (const :tag
"Dim to a grey face" t
)
618 (const :tag
"Make invisibe" invisible
)))
620 (defcustom org-timeline-show-empty-dates
3
621 "Non-nil means, `org-timeline' also shows dates without an entry.
622 When nil, only the days which actually have entries are shown.
623 When t, all days between the first and the last date are shown.
624 When an integer, show also empty dates, but if there is a gap of more than
625 N days, just insert a special line indicating the size of the gap."
626 :group
'org-agenda-skip
628 (const :tag
"None" nil
)
630 (integer :tag
"at most")))
632 (defgroup org-agenda-startup nil
633 "Options concerning initial settings in the Agenda in Org Mode."
634 :tag
"Org Agenda Startup"
637 (defcustom org-finalize-agenda-hook nil
638 "Hook run just before displaying an agenda buffer."
639 :group
'org-agenda-startup
642 (defcustom org-agenda-mouse-1-follows-link nil
643 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
644 A longer mouse click will still set point. Does not work on XEmacs.
645 Needs to be set before org.el is loaded."
646 :group
'org-agenda-startup
649 (defcustom org-agenda-start-with-follow-mode nil
650 "The initial value of follow-mode in a newly created agenda window."
651 :group
'org-agenda-startup
654 (defvar org-agenda-include-inactive-timestamps nil
655 "Non-nil means, include inactive time stamps in agenda and timeline.")
657 (defgroup org-agenda-windows nil
658 "Options concerning the windows used by the Agenda in Org Mode."
659 :tag
"Org Agenda Windows"
662 (defcustom org-agenda-window-setup
'reorganize-frame
663 "How the agenda buffer should be displayed.
664 Possible values for this option are:
666 current-window Show agenda in the current window, keeping all other windows.
667 other-frame Use `switch-to-buffer-other-frame' to display agenda.
668 other-window Use `switch-to-buffer-other-window' to display agenda.
669 reorganize-frame Show only two windows on the current frame, the current
670 window and the agenda.
671 See also the variable `org-agenda-restore-windows-after-quit'."
672 :group
'org-agenda-windows
674 (const current-window
)
677 (const reorganize-frame
)))
679 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
680 "The min and max height of the agenda window as a fraction of frame height.
681 The value of the variable is a cons cell with two numbers between 0 and 1.
682 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
683 :group
'org-agenda-windows
684 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
686 (defcustom org-agenda-restore-windows-after-quit nil
687 "Non-nil means, restore window configuration open exiting agenda.
688 Before the window configuration is changed for displaying the agenda,
689 the current status is recorded. When the agenda is exited with
690 `q' or `x' and this option is set, the old state is restored. If
691 `org-agenda-window-setup' is `other-frame', the value of this
692 option will be ignored.."
693 :group
'org-agenda-windows
696 (defcustom org-agenda-ndays
7
697 "Number of days to include in overview display.
699 Custom commands can set this variable in the options section."
700 :group
'org-agenda-daily
/weekly
703 (defcustom org-agenda-start-on-weekday
1
704 "Non-nil means, start the overview always on the specified weekday.
705 0 denotes Sunday, 1 denotes Monday etc.
706 When nil, always start on the current day.
707 Custom commands can set this variable in the options section."
708 :group
'org-agenda-daily
/weekly
709 :type
'(choice (const :tag
"Today" nil
)
710 (integer :tag
"Weekday No.")))
712 (defcustom org-agenda-show-all-dates t
713 "Non-nil means, `org-agenda' shows every day in the selected range.
714 When nil, only the days which actually have entries are shown."
715 :group
'org-agenda-daily
/weekly
718 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
719 "Format string for displaying dates in the agenda.
720 Used by the daily/weekly agenda and by the timeline. This should be
721 a format string understood by `format-time-string', or a function returning
722 the formatted date as a string. The function must take a single argument,
723 a calendar-style date list like (month day year)."
724 :group
'org-agenda-daily
/weekly
726 (string :tag
"Format string")
727 (function :tag
"Function")))
729 (defun org-agenda-format-date-aligned (date)
730 "Format a date string for display in the daily/weekly agenda, or timeline.
731 This function makes sure that dates are aligned for easy reading."
733 (let* ((dayname (calendar-day-name date
))
735 (day-of-week (calendar-day-of-week date
))
737 (monthname (calendar-month-name month
))
739 (iso-week (org-days-to-iso-week
740 (calendar-absolute-from-gregorian date
)))
741 (weekyear (cond ((and (= month
1) (>= iso-week
52))
743 ((and (= month
12) (<= iso-week
1))
746 (weekstring (if (= day-of-week
1)
747 (format " W%02d" iso-week
)
749 (format "%-10s %2d %s %4d%s"
750 dayname day monthname year weekstring
)))
752 (defcustom org-agenda-weekend-days
'(6 0)
753 "Which days are weekend?
754 These days get the special face `org-agenda-date-weekend' in the agenda
755 and timeline buffers."
756 :group
'org-agenda-daily
/weekly
757 :type
'(set :greedy t
758 (const :tag
"Monday" 1)
759 (const :tag
"Tuesday" 2)
760 (const :tag
"Wednesday" 3)
761 (const :tag
"Thursday" 4)
762 (const :tag
"Friday" 5)
763 (const :tag
"Saturday" 6)
764 (const :tag
"Sunday" 0)))
766 (defcustom org-agenda-include-diary nil
767 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
768 Custom commands can set this variable in the options section."
769 :group
'org-agenda-daily
/weekly
772 (defcustom org-agenda-include-all-todo nil
773 "Set means weekly/daily agenda will always contain all TODO entries.
774 The TODO entries will be listed at the top of the agenda, before
775 the entries for specific days.
776 This option is deprecated, it is better to define a block agenda instead."
777 :group
'org-agenda-daily
/weekly
780 (defcustom org-agenda-repeating-timestamp-show-all t
781 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
782 When nil, only one occurrence is shown, either today or the
783 nearest into the future."
784 :group
'org-agenda-daily
/weekly
787 (defcustom org-scheduled-past-days
10000
788 "No. of days to continue listing scheduled items that are not marked DONE.
789 When an item is scheduled on a date, it shows up in the agenda on this
790 day and will be listed until it is marked done for the number of days
792 :group
'org-agenda-daily
/weekly
795 (defcustom org-agenda-log-mode-items
'(closed clock
)
796 "List of items that should be shown in agenda log mode.
797 This list may contain the following symbols:
799 closed Show entries that have been closed on that day.
800 clock Show entries that have received clocked time on that day.
801 state Show all logged state changes.
802 Note that instead of changing this variable, you can also press `C-u l' in
803 the agenda to display all available LOG items temporarily."
804 :group
'org-agenda-daily
/weekly
805 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
807 (defcustom org-agenda-log-mode-add-notes t
808 "Non-nil means, add first line of notes to log entries in agenda views.
809 If a log item like a state change or a clock entry is associated with
810 notes, the first line of these notes will be added to the entry in the
812 :group
'org-agenda-daily
/weekly
815 (defcustom org-agenda-start-with-log-mode nil
816 "The initial value of log-mode in a newly created agenda window."
817 :group
'org-agenda-startup
818 :group
'org-agenda-daily
/weekly
821 (defcustom org-agenda-start-with-clockreport-mode nil
822 "The initial value of clockreport-mode in a newly created agenda window."
823 :group
'org-agenda-startup
824 :group
'org-agenda-daily
/weekly
827 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
828 "Property list with parameters for the clocktable in clockreport mode.
829 This is the display mode that shows a clock table in the daily/weekly
830 agenda, the properties for this dynamic block can be set here.
831 The usual clocktable parameters are allowed here, but you cannot set
832 the properties :name, :tstart, :tend, :block, and :scope - these will
833 be overwritten to make sure the content accurately reflects the
834 current display in the agenda."
835 :group
'org-agenda-daily
/weekly
839 (defgroup org-agenda-time-grid nil
840 "Options concerning the time grid in the Org-mode Agenda."
841 :tag
"Org Agenda Time Grid"
844 (defcustom org-agenda-search-headline-for-time t
845 "Non-nil means, search headline for a time-of-day.
846 If the headline contains a time-of-day in one format or another, it will
847 be used to sort the entry into the time sequence of items for a day.
848 Some people have time stamps in the headline that refer to the creation
849 time or so, and then this produces an unwanted side effect. If this is
850 the case for your, use this variable to turn off searching the headline
852 :group
'org-agenda-time-grid
855 (defcustom org-agenda-use-time-grid t
856 "Non-nil means, show a time grid in the agenda schedule.
857 A time grid is a set of lines for specific times (like every two hours between
858 8:00 and 20:00). The items scheduled for a day at specific times are
859 sorted in between these lines.
860 For details about when the grid will be shown, and what it will look like, see
861 the variable `org-agenda-time-grid'."
862 :group
'org-agenda-time-grid
865 (defcustom org-agenda-time-grid
866 '((daily today require-timed
)
868 (800 1000 1200 1400 1600 1800 2000))
870 "The settings for time grid for agenda display.
871 This is a list of three items. The first item is again a list. It contains
872 symbols specifying conditions when the grid should be displayed:
874 daily if the agenda shows a single day
875 weekly if the agenda shows an entire week
876 today show grid on current date, independent of daily/weekly display
877 require-timed show grid only if at least one item has a time specification
879 The second item is a string which will be placed behind the grid time.
881 The third item is a list of integers, indicating the times that should have
883 :group
'org-agenda-time-grid
886 (set :greedy t
:tag
"Grid Display Options"
887 (const :tag
"Show grid in single day agenda display" daily
)
888 (const :tag
"Show grid in weekly agenda display" weekly
)
889 (const :tag
"Always show grid for today" today
)
890 (const :tag
"Show grid only if any timed entries are present"
892 (const :tag
"Skip grid times already present in an entry"
894 (string :tag
"Grid String")
895 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
897 (defgroup org-agenda-sorting nil
898 "Options concerning sorting in the Org-mode Agenda."
899 :tag
"Org Agenda Sorting"
902 (defcustom org-agenda-sorting-strategy
903 '((agenda time-up priority-down category-keep
)
904 (todo priority-down category-keep
)
905 (tags priority-down category-keep
)
906 (search category-keep
))
907 "Sorting structure for the agenda items of a single day.
908 This is a list of symbols which will be used in sequence to determine
909 if an entry should be listed before another entry. The following
910 symbols are recognized:
912 time-up Put entries with time-of-day indications first, early first
913 time-down Put entries with time-of-day indications first, late first
914 category-keep Keep the default order of categories, corresponding to the
915 sequence in `org-agenda-files'.
916 category-up Sort alphabetically by category, A-Z.
917 category-down Sort alphabetically by category, Z-A.
918 tag-up Sort alphabetically by last tag, A-Z.
919 tag-down Sort alphabetically by last tag, Z-A.
920 priority-up Sort numerically by priority, high priority last.
921 priority-down Sort numerically by priority, high priority first.
922 todo-state-up Sort by todo state, tasks that are done last.
923 todo-state-down Sort by todo state, tasks that are done first.
924 effort-up Sort numerically by estimated effort, high effort last.
925 effort-down Sort numerically by estimated effort, high effort first.
926 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
927 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
929 The different possibilities will be tried in sequence, and testing stops
930 if one comparison returns a \"not-equal\". For example, the default
931 '(time-up category-keep priority-down)
932 means: Pull out all entries having a specified time of day and sort them,
933 in order to make a time schedule for the current day the first thing in the
934 agenda listing for the day. Of the entries without a time indication, keep
935 the grouped in categories, don't sort the categories, but keep them in
936 the sequence given in `org-agenda-files'. Within each category sort by
939 Leaving out `category-keep' would mean that items will be sorted across
940 categories by priority.
942 Instead of a single list, this can also be a set of list for specific
943 contents, with a context symbol in the car of the list, any of
944 `agenda', `todo', `tags' for the corresponding agenda views.
946 Custom commands can bind this variable in the options section."
947 :group
'org-agenda-sorting
949 (repeat :tag
"General" ,org-sorting-choice
)
950 (list :tag
"Individually"
951 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
952 (repeat ,org-sorting-choice
))
953 (cons (const :tag
"Strategy for TODO lists" todo
)
954 (repeat ,org-sorting-choice
))
955 (cons (const :tag
"Strategy for Tags matches" tags
)
956 (repeat ,org-sorting-choice
)))))
958 (defcustom org-agenda-cmp-user-defined nil
959 "A function to define the comparison `user-defined'.
960 This function must receive two arguments, agenda entry a and b.
961 If a>b, return +1. If a<b, return -1. If they are equal as seen by
962 the user comparison, return nil.
963 When this is defined, you can make `user-defined-up' and `user-defined-down'
964 part of an agenda sorting strategy."
965 :group
'org-agenda-sorting
968 (defcustom org-sort-agenda-notime-is-late t
969 "Non-nil means, items without time are considered late.
970 This is only relevant for sorting. When t, items which have no explicit
971 time like 15:30 will be considered as 99:01, i.e. later than any items which
972 do have a time. When nil, the default time is before 0:00. You can use this
973 option to decide if the schedule for today should come before or after timeless
975 :group
'org-agenda-sorting
978 (defcustom org-sort-agenda-noeffort-is-high t
979 "Non-nil means, items without effort estimate are sorted as high effort.
980 This also applies when filtering an agenda view with respect to the
981 < or > effort operator. Then, tasks with no effort defined will be treated
982 as tasks with high effort.
983 When nil, such items are sorted as 0 minutes effort."
984 :group
'org-agenda-sorting
987 (defgroup org-agenda-line-format nil
988 "Options concerning the entry prefix in the Org-mode agenda display."
989 :tag
"Org Agenda Line Format"
992 (defcustom org-agenda-prefix-format
993 '((agenda .
" %-12:c%?-12t% s")
997 (search .
" %-12:c"))
998 "Format specifications for the prefix of items in the agenda views.
999 An alist with four entries, for the different agenda types. The keys to the
1000 sublists are `agenda', `timeline', `todo', and `tags'. The values
1002 This format works similar to a printf format, with the following meaning:
1004 %c the category of the item, \"Diary\" for entries from the diary, or
1005 as given by the CATEGORY keyword or derived from the file name.
1006 %T the *last* tag of the item. Last because inherited tags come
1008 %t the time-of-day specification if one applies to the entry, in the
1010 %s Scheduling/Deadline information, a short string
1012 All specifiers work basically like the standard `%s' of printf, but may
1013 contain two additional characters: A question mark just after the `%' and
1014 a whitespace/punctuation character just before the final letter.
1016 If the first character after `%' is a question mark, the entire field
1017 will only be included if the corresponding value applies to the
1018 current entry. This is useful for fields which should have fixed
1019 width when present, but zero width when absent. For example,
1020 \"%?-12t\" will result in a 12 character time field if a time of the
1021 day is specified, but will completely disappear in entries which do
1024 If there is punctuation or whitespace character just before the final
1025 format letter, this character will be appended to the field value if
1026 the value is not empty. For example, the format \"%-12:c\" leads to
1027 \"Diary: \" if the category is \"Diary\". If the category were be
1028 empty, no additional colon would be interted.
1030 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1031 - Indent the line with two space characters
1032 - Give the category in a 12 chars wide field, padded with whitespace on
1033 the right (because of `-'). Append a colon if there is a category
1035 - If there is a time-of-day, put it into a 12 chars wide field. If no
1036 time, don't put in an empty field, just skip it (because of '?').
1037 - Finally, put the scheduling information and append a whitespace.
1039 As another example, if you don't want the time-of-day of entries in
1040 the prefix, you could use:
1042 (setq org-agenda-prefix-format \" %-11:c% s\")
1044 See also the variables `org-agenda-remove-times-when-in-prefix' and
1045 `org-agenda-remove-tags'.
1047 Custom commands can set this variable in the options section."
1049 (string :tag
"General format")
1050 (list :greedy t
:tag
"View dependent"
1051 (cons (const agenda
) (string :tag
"Format"))
1052 (cons (const timeline
) (string :tag
"Format"))
1053 (cons (const todo
) (string :tag
"Format"))
1054 (cons (const tags
) (string :tag
"Format"))
1055 (cons (const search
) (string :tag
"Format"))))
1056 :group
'org-agenda-line-format
)
1058 (defvar org-prefix-format-compiled nil
1059 "The compiled version of the most recently used prefix format.
1060 See the variable `org-agenda-prefix-format'.")
1062 (defcustom org-agenda-todo-keyword-format
"%-1s"
1063 "Format for the TODO keyword in agenda lines.
1064 Set this to something like \"%-12s\" if you want all TODO keywords
1065 to occupy a fixed space in the agenda display."
1066 :group
'org-agenda-line-format
1069 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1070 "Text preceding timerange entries in the agenda view.
1071 This is a list with two strings. The first applies when the range
1072 is entirely on one day. The second applies if the range spans several days.
1073 The strings may have two \"%d\" format specifiers which will be filled
1074 with the sequence number of the days, and the total number of days in the
1075 range, respectively."
1076 :group
'org-agenda-line-format
1078 (string :tag
"Deadline today ")
1079 (choice :tag
"Deadline relative"
1080 (string :tag
"Format string")
1083 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1084 "Text preceeding scheduled items in the agenda view.
1085 This is a list with two strings. The first applies when the item is
1086 scheduled on the current day. The second applies when it has been scheduled
1087 previously, it may contain a %d indicating that this is the nth time that
1088 this item is scheduled, due to automatic rescheduling of unfinished items
1089 for the following day. So this number is one larger than the number of days
1090 that passed since this item was scheduled first."
1091 :group
'org-agenda-line-format
1093 (string :tag
"Scheduled today ")
1094 (string :tag
"Scheduled previously")))
1096 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1097 "Text preceeding deadline items in the agenda view.
1098 This is a list with two strings. The first applies when the item has its
1099 deadline on the current day. The second applies when it is in the past or
1100 in the future, it may contain %d to capture how many days away the deadline
1102 :group
'org-agenda-line-format
1104 (string :tag
"Deadline today ")
1105 (choice :tag
"Deadline relative"
1106 (string :tag
"Format string")
1109 (defcustom org-agenda-remove-times-when-in-prefix t
1110 "Non-nil means, remove duplicate time specifications in agenda items.
1111 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1112 time-of-day specification in a headline or diary entry is extracted and
1113 placed into the prefix. If this option is non-nil, the original specification
1114 \(a timestamp or -range, or just a plain time(range) specification like
1115 11:30-4pm) will be removed for agenda display. This makes the agenda less
1117 The option can be t or nil. It may also be the symbol `beg', indicating
1118 that the time should only be removed what it is located at the beginning of
1119 the headline/diary entry."
1120 :group
'org-agenda-line-format
1122 (const :tag
"Always" t
)
1123 (const :tag
"Never" nil
)
1124 (const :tag
"When at beginning of entry" beg
)))
1127 (defcustom org-agenda-default-appointment-duration nil
1128 "Default duration for appointments that only have a starting time.
1129 When nil, no duration is specified in such cases.
1130 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1131 :group
'org-agenda-line-format
1133 (integer :tag
"Minutes")
1134 (const :tag
"No default duration")))
1136 (defcustom org-agenda-show-inherited-tags t
1137 "Non-nil means, show inherited tags in each agenda line."
1138 :group
'org-agenda-line-format
1141 (defcustom org-agenda-remove-tags nil
1142 "Non-nil means, remove the tags from the headline copy in the agenda.
1143 When this is the symbol `prefix', only remove tags when
1144 `org-agenda-prefix-format' contains a `%T' specifier."
1145 :group
'org-agenda-line-format
1147 (const :tag
"Always" t
)
1148 (const :tag
"Never" nil
)
1149 (const :tag
"When prefix format contains %T" prefix
)))
1151 (if (fboundp 'defvaralias
)
1152 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1153 'org-agenda-remove-tags
))
1155 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1156 "Shift tags in agenda items to this column.
1157 If this number is positive, it specifies the column. If it is negative,
1158 it means that the tags should be flushright to that column. For example,
1159 -80 works well for a normal 80 character screen."
1160 :group
'org-agenda-line-format
1163 (if (fboundp 'defvaralias
)
1164 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1166 (defcustom org-agenda-fontify-priorities
'cookies
1167 "Non-nil means, highlight low and high priorities in agenda.
1168 When t, the highest priority entries are bold, lowest priority italic.
1169 However, settings in org-priority-faces will overrule these faces.
1170 When this variable is the symbol `cookies', only fontify the
1171 cookies, not the entire task.
1172 This may also be an association list of priority faces, whose
1173 keys are the character values of `org-highest-priority',
1174 `org-default-priority', and `org-lowest-priority' (the default values
1175 are ?A, ?B, and ?C, respectively). The face may be a named face,
1176 or a list like `(:background \"Red\")'."
1177 :group
'org-agenda-line-format
1179 (const :tag
"Never" nil
)
1180 (const :tag
"Defaults" t
)
1181 (const :tag
"Cookies only" cookies
)
1182 (repeat :tag
"Specify"
1183 (list (character :tag
"Priority" :value ?A
)
1184 (sexp :tag
"face")))))
1186 (defgroup org-agenda-column-view nil
1187 "Options concerning column view in the agenda."
1188 :tag
"Org Agenda Column View"
1191 (defcustom org-agenda-columns-show-summaries t
1192 "Non-nil means, show summaries for columns displayed in the agenda view."
1193 :group
'org-agenda-column-view
1196 (defcustom org-agenda-columns-remove-prefix-from-item t
1197 "Non-nil means, remove the prefix from a headline for agenda column view.
1198 The special ITEM field in the columns format contains the current line, with
1199 all information shown in other columns (like the TODO state or a tag).
1200 When this variable is non-nil, also the agenda prefix will be removed from
1201 the content of the ITEM field, to make sure as much as possible of the
1202 headline can be shown in the limited width of the field."
1206 (defcustom org-agenda-columns-compute-summary-properties t
1207 "Non-nil means, recompute all summary properties before column view.
1208 When column view in the agenda is listing properties that have a summary
1209 operator, it can go to all relevant buffers and recompute the summaries
1210 there. This can mean overhead for the agenda column view, but is necessary
1211 to have thing up to date.
1212 As a special case, a CLOCKSUM property also makes sure that the clock
1213 computations are current."
1214 :group
'org-agenda-column-view
1217 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1218 "Non-nil means, the duration of an appointment will add to day effort.
1219 The property to which appointment durations will be added is the one given
1220 in the option `org-effort-property'. If an appointment does not have
1221 an end time, `org-agenda-default-appointment-duration' will be used. If that
1222 is not set, an appointment without end time will not contribute to the time
1224 :group
'org-agenda-column-view
1231 (defun org-add-agenda-custom-command (entry)
1232 "Replace or add a command in `org-agenda-custom-commands'.
1233 This is mostly for hacking and trying a new command - once the command
1234 works you probably want to add it to `org-agenda-custom-commands' for good."
1235 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1237 (setcdr ass
(cdr entry
))
1238 (push entry org-agenda-custom-commands
))))
1240 ;;; Define the Org-agenda-mode
1242 (defvar org-agenda-mode-map
(make-sparse-keymap)
1243 "Keymap for `org-agenda-mode'.")
1245 (defvar org-agenda-menu
) ; defined later in this file.
1246 (defvar org-agenda-restrict
) ; defined later in this file.
1247 (defvar org-agenda-follow-mode nil
)
1248 (defvar org-agenda-clockreport-mode nil
)
1249 (defvar org-agenda-show-log nil
)
1250 (defvar org-agenda-redo-command nil
)
1251 (defvar org-agenda-query-string nil
)
1252 (defvar org-agenda-mode-hook nil
1253 "Hook for org-agenda-mode, run after the mode is turned on.")
1254 (defvar org-agenda-type nil
)
1255 (defvar org-agenda-force-single-file nil
)
1256 (defvar org-agenda-bulk-marked-entries
) ;; Defined further down in this file
1258 (defun org-agenda-mode ()
1259 "Mode for time-sorted view on action items in Org-mode files.
1261 The following commands are available:
1263 \\{org-agenda-mode-map}"
1265 (kill-all-local-variables)
1266 (setq org-agenda-undo-list nil
1267 org-agenda-pending-undo-list nil
1268 org-agenda-bulk-marked-entries nil
)
1269 (setq major-mode
'org-agenda-mode
)
1270 ;; Keep global-font-lock-mode from turning on font-lock-mode
1271 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1272 (setq mode-name
"Org-Agenda")
1273 (use-local-map org-agenda-mode-map
)
1274 (easy-menu-add org-agenda-menu
)
1275 (if org-startup-truncated
(setq truncate-lines t
))
1276 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1277 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1278 ;; Make sure properties are removed when copying text
1279 (when (boundp 'buffer-substring-filters
)
1280 (org-set-local 'buffer-substring-filters
1282 (set-text-properties 0 (length x
) nil x
) x
)
1283 buffer-substring-filters
)))
1284 (unless org-agenda-keep-modes
1285 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1286 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1287 org-agenda-show-log org-agenda-start-with-log-mode
))
1290 '("Agenda") "Agenda Files"
1294 (if (get 'org-agenda-files
'org-restrict
)
1295 "Restricted to single file"
1297 '(org-edit-agenda-file-list)
1298 (not (get 'org-agenda-files
'org-restrict
)))
1300 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1301 (org-agenda-set-mode-name)
1303 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1304 (list 'org-agenda-mode-hook
)))
1306 (substitute-key-definition 'undo
'org-agenda-undo
1307 org-agenda-mode-map global-map
)
1308 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1309 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1310 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1311 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1312 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1313 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1314 (org-defkey org-agenda-mode-map
"\C-c\C-w" 'org-agenda-refile
)
1315 (org-defkey org-agenda-mode-map
"m" 'org-agenda-bulk-mark
)
1316 (org-defkey org-agenda-mode-map
"u" 'org-agenda-bulk-unmark
)
1317 (org-defkey org-agenda-mode-map
"U" 'org-agenda-bulk-remove-all-marks
)
1318 (org-defkey org-agenda-mode-map
"B" 'org-agenda-bulk-action
)
1319 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1320 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1321 (org-defkey org-agenda-mode-map
"A" 'org-agenda-archive-to-archive-sibling
)
1322 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1323 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1324 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1325 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1326 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1327 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1328 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1329 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1330 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1331 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1332 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1333 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1334 (org-defkey org-agenda-mode-map
"\C-c\C-q" 'org-agenda-set-tags
)
1335 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1336 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1337 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1338 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1339 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1340 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1341 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1342 (org-defkey org-agenda-mode-map
"k" 'org-agenda-action
)
1343 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-k" 'org-agenda-action
)
1344 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-do-date-later
)
1345 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-do-date-earlier
)
1346 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-do-date-later
)
1347 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-do-date-earlier
)
1349 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1350 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1351 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1352 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1353 (while l
(org-defkey org-agenda-mode-map
1354 (int-to-string (pop l
)) 'digit-argument
)))
1356 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1357 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1358 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1359 (org-defkey org-agenda-mode-map
"v" 'org-agenda-view-mode-dispatch
)
1360 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1361 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1362 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1363 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1364 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1365 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1366 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1367 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1368 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1369 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1370 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1371 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1372 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1373 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1374 (org-defkey org-agenda-mode-map
"\C-c\C-a" 'org-attach
)
1375 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1376 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1377 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1378 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1379 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1380 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1381 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1382 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1383 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1384 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1385 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1386 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1387 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1388 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1389 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1390 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1391 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1392 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1393 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1394 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1395 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1396 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1397 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1398 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1399 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1400 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1401 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1402 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1403 (org-defkey org-agenda-mode-map
"\C-c\C-x>" 'org-agenda-remove-restriction-lock
)
1405 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1406 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1407 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1408 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1409 (org-defkey org-agenda-mode-map
"/" 'org-agenda-filter-by-tag
)
1410 (org-defkey org-agenda-mode-map
"\\" 'org-agenda-filter-by-tag-refine
)
1411 (org-defkey org-agenda-mode-map
";" 'org-timer-set-timer
)
1413 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1414 "Local keymap for agenda entries from Org-mode.")
1416 (org-defkey org-agenda-keymap
1417 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1418 (org-defkey org-agenda-keymap
1419 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1420 (when org-agenda-mouse-1-follows-link
1421 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1422 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1426 ["Show" org-agenda-show t
]
1427 ["Go To (other window)" org-agenda-goto t
]
1428 ["Go To (this window)" org-agenda-switch-to t
]
1429 ["Follow Mode" org-agenda-follow-mode
1430 :style toggle
:selected org-agenda-follow-mode
:active t
]
1431 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1433 ["Cycle TODO" org-agenda-todo t
]
1434 ("Archive and Refile"
1435 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t
]
1436 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t
]
1437 ["Archive subtree" org-agenda-archive t
]
1438 ["Refile" org-agenda-refile t
])
1439 ["Delete subtree" org-agenda-kill t
]
1441 ["Toggle mark entry" org-agenda-bulk-mark t
]
1442 ["Act on all marked" org-agenda-bulk-action t
]
1443 ["Unmark all entries" org-agenda-bulk-remove-all-marks
:active t
:keys
"C-u s"])
1445 ["Add note" org-agenda-add-note t
]
1447 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1448 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1449 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1450 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1452 ("Tags and Properties"
1453 ["Show all Tags" org-agenda-show-tags t
]
1454 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1455 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1457 ["Column View" org-columns t
])
1459 ["Schedule" org-agenda-schedule t
]
1460 ["Set Deadline" org-agenda-deadline t
]
1462 ["Mark item" org-agenda-action
:active t
:keys
"k m"]
1463 ["Show mark item" org-agenda-action
:active t
:keys
"k v"]
1464 ["Schedule marked item" org-agenda-action
:active t
:keys
"k s"]
1465 ["Set Deadline for marked item" org-agenda-action
:active t
:keys
"k d"]
1467 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1468 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1469 ["Change Time +1 hour" org-agenda-do-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-right"]
1470 ["Change Time -1 hour" org-agenda-do-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-left"]
1471 ["Change Time + min" org-agenda-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-right"]
1472 ["Change Time - min" org-agenda-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-left"]
1473 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1475 ["Clock in" org-agenda-clock-in t
]
1476 ["Clock out" org-agenda-clock-out t
]
1477 ["Clock cancel" org-agenda-clock-cancel t
]
1478 ["Goto running clock" org-clock-goto t
])
1480 ["Set Priority" org-agenda-priority t
]
1481 ["Increase Priority" org-agenda-priority-up t
]
1482 ["Decrease Priority" org-agenda-priority-down t
]
1483 ["Show Priority" org-agenda-show-priority t
])
1485 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1486 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1487 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1488 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1489 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1490 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1492 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1495 ["Day View" org-agenda-day-view
1496 :active
(org-agenda-check-type nil
'agenda
)
1497 :style radio
:selected
(equal org-agenda-ndays
1)
1498 :keys
"v d (or just d)"]
1499 ["Week View" org-agenda-week-view
1500 :active
(org-agenda-check-type nil
'agenda
)
1501 :style radio
:selected
(equal org-agenda-ndays
7)
1502 :keys
"v w (or just w)"]
1503 ["Month View" org-agenda-month-view
1504 :active
(org-agenda-check-type nil
'agenda
)
1505 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))
1507 ["Year View" org-agenda-year-view
1508 :active
(org-agenda-check-type nil
'agenda
)
1509 :style radio
:selected
(member org-agenda-ndays
'(365 366))
1512 ["Include Diary" org-agenda-toggle-diary
1513 :style toggle
:selected org-agenda-include-diary
1514 :active
(org-agenda-check-type nil
'agenda
)]
1515 ["Use Time Grid" org-agenda-toggle-time-grid
1516 :style toggle
:selected org-agenda-use-time-grid
1517 :active
(org-agenda-check-type nil
'agenda
)]
1519 ["Show clock report" org-agenda-clockreport-mode
1520 :style toggle
:selected org-agenda-clockreport-mode
1521 :active
(org-agenda-check-type nil
'agenda
)]
1523 ["Show Logbook entries" org-agenda-log-mode
1524 :style toggle
:selected org-agenda-show-log
1525 :active
(org-agenda-check-type nil
'agenda
'timeline
)
1526 :keys
"v l (or just l)"]
1527 ["Include archived trees" org-agenda-archives-mode
1528 :style toggle
:selected org-agenda-archives-mode
:active t
1530 ["Include archive files" (org-agenda-archives-mode t
)
1531 :style toggle
:selected
(eq org-agenda-archives-mode t
) :active t
1534 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict
])
1535 ["Write view to file" org-write-agenda t
]
1536 ["Rebuild buffer" org-agenda-redo t
]
1537 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1539 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1541 ["Quit" org-agenda-quit t
]
1542 ["Exit and Release Buffers" org-agenda-exit t
]
1547 (defvar org-agenda-allow-remote-undo t
1548 "Non-nil means, allow remote undo from the agenda buffer.")
1549 (defvar org-agenda-undo-list nil
1550 "List of undoable operations in the agenda since last refresh.")
1551 (defvar org-agenda-undo-has-started-in nil
1552 "Buffers that have already seen `undo-start' in the current undo sequence.")
1553 (defvar org-agenda-pending-undo-list nil
1554 "In a series of undo commands, this is the list of remaining undo items.")
1557 (defun org-agenda-undo ()
1558 "Undo a remote editing step in the agenda.
1559 This undoes changes both in the agenda buffer and in the remote buffer
1560 that have been changed along."
1562 (or org-agenda-allow-remote-undo
1563 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1564 (if (not (eq this-command last-command
))
1565 (setq org-agenda-undo-has-started-in nil
1566 org-agenda-pending-undo-list org-agenda-undo-list
))
1567 (if (not org-agenda-pending-undo-list
)
1568 (error "No further undo information"))
1569 (let* ((entry (pop org-agenda-pending-undo-list
))
1570 buf line cmd rembuf
)
1571 (setq cmd
(pop entry
) line
(pop entry
))
1572 (setq rembuf
(nth 2 entry
))
1573 (org-with-remote-undo rembuf
1574 (while (bufferp (setq buf
(pop entry
)))
1576 (with-current-buffer buf
1577 (let ((last-undo-buffer buf
)
1578 (inhibit-read-only t
))
1579 (unless (memq buf org-agenda-undo-has-started-in
)
1580 (push buf org-agenda-undo-has-started-in
)
1581 (make-local-variable 'pending-undo-list
)
1583 (while (and pending-undo-list
1584 (listp pending-undo-list
)
1585 (not (car pending-undo-list
)))
1586 (pop pending-undo-list
))
1589 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1591 (defun org-verify-change-for-undo (l1 l2
)
1592 "Verify that a real change occurred between the undo lists L1 and L2."
1593 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1594 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1599 (defvar org-agenda-restrict nil
)
1600 (defvar org-agenda-restrict-begin
(make-marker))
1601 (defvar org-agenda-restrict-end
(make-marker))
1602 (defvar org-agenda-last-dispatch-buffer nil
)
1603 (defvar org-agenda-overriding-restriction nil
)
1606 (defun org-agenda (&optional arg keys restriction
)
1607 "Dispatch agenda commands to collect entries to the agenda buffer.
1608 Prompts for a command to execute. Any prefix arg will be passed
1609 on to the selected command. The default selections are:
1611 a Call `org-agenda-list' to display the agenda for current day or week.
1612 t Call `org-todo-list' to display the global todo list.
1613 T Call `org-todo-list' to display the global todo list, select only
1614 entries with a specific TODO keyword (the user gets a prompt).
1615 m Call `org-tags-view' to display headlines with tags matching
1616 a condition (the user is prompted for the condition).
1617 M Like `m', but select only TODO entries, no ordinary headlines.
1618 L Create a timeline for the current buffer.
1619 e Export views to associated files.
1620 s Search entries for keywords.
1621 / Multi occur accros all agenda files and also files listed
1622 in `org-agenda-text-search-extra-files'.
1623 < Restrict agenda commands to buffer, subtree, or region.
1624 Press several times to get the desired effect.
1625 > Remove a previous restriction.
1626 # List \"stuck\" projects.
1627 ! Configure what \"stuck\" means.
1628 C Configure custom agenda commands.
1630 More commands can be added by configuring the variable
1631 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1632 searches can be pre-defined in this way.
1634 If the current buffer is in Org-mode and visiting a file, you can also
1635 first press `<' once to indicate that the agenda should be temporarily
1636 \(until the next use of \\[org-agenda]) restricted to the current file.
1637 Pressing `<' twice means to restrict to the current subtree or region
1641 (let* ((prefix-descriptions nil
)
1642 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1643 (org-agenda-custom-commands
1644 ;; normalize different versions
1648 (cond ((stringp (cdr x
))
1649 (push x prefix-descriptions
)
1651 ((stringp (nth 1 x
)) x
)
1652 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1653 (t (cons (car x
) (cons "" (cdr x
))))))
1654 org-agenda-custom-commands
)))
1655 (buf (current-buffer))
1656 (bfn (buffer-file-name (buffer-base-buffer)))
1657 entry key type match lprops ans
)
1658 ;; Turn off restriction unless there is an overriding one
1659 (unless org-agenda-overriding-restriction
1660 (put 'org-agenda-files
'org-restrict nil
)
1661 (setq org-agenda-restrict nil
)
1662 (move-marker org-agenda-restrict-begin nil
)
1663 (move-marker org-agenda-restrict-end nil
))
1664 ;; Delete old local properties
1665 (put 'org-agenda-redo-command
'org-lprops nil
)
1666 ;; Remember where this call originated
1667 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1669 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1671 restriction
(cdr ans
)))
1672 ;; Estabish the restriction, if any
1673 (when (and (not org-agenda-overriding-restriction
) restriction
)
1674 (put 'org-agenda-files
'org-restrict
(list bfn
))
1676 ((eq restriction
'region
)
1677 (setq org-agenda-restrict t
)
1678 (move-marker org-agenda-restrict-begin
(region-beginning))
1679 (move-marker org-agenda-restrict-end
(region-end)))
1680 ((eq restriction
'subtree
)
1682 (setq org-agenda-restrict t
)
1683 (org-back-to-heading t
)
1684 (move-marker org-agenda-restrict-begin
(point))
1685 (move-marker org-agenda-restrict-end
1686 (progn (org-end-of-subtree t
)))))))
1688 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1689 ;; For example the todo list should not need it (but does...)
1691 ((setq entry
(assoc keys org-agenda-custom-commands
))
1692 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1694 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1695 (put 'org-agenda-redo-command
'org-lprops lprops
)
1698 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1700 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1702 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1704 (org-let lprops
'(org-agenda-list-stuck-projects
1705 current-prefix-arg
)))
1707 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1708 ((eq type
'tags-todo
)
1709 (org-let lprops
'(org-tags-view '(4) match
)))
1711 (org-let lprops
'(org-todo-list match
)))
1712 ((eq type
'tags-tree
)
1713 (org-check-for-org-mode)
1714 (org-let lprops
'(org-match-sparse-tree current-prefix-arg match
)))
1715 ((eq type
'todo-tree
)
1716 (org-check-for-org-mode)
1718 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1719 (regexp-quote match
) "\\>"))))
1720 ((eq type
'occur-tree
)
1721 (org-check-for-org-mode)
1722 (org-let lprops
'(org-occur match
)))
1724 (org-let lprops
'(funcall type match
)))
1726 (org-let lprops
'(funcall type match
)))
1727 (t (error "Invalid custom agenda command type %s" type
))))
1728 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1730 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1731 (customize-variable 'org-agenda-custom-commands
))
1732 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1733 ((equal keys
"s") (call-interactively 'org-search-view
))
1734 ((equal keys
"t") (call-interactively 'org-todo-list
))
1735 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1736 ((equal keys
"m") (call-interactively 'org-tags-view
))
1737 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1738 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1740 (unless (org-mode-p)
1741 (error "This is not an Org-mode file"))
1743 (put 'org-agenda-files
'org-restrict
(list bfn
))
1744 (org-call-with-arg 'org-timeline arg
)))
1745 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1746 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1747 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1748 (t (error "Invalid agenda key"))))))
1750 (defun org-agenda-normalize-custom-commands (cmds)
1754 (cond ((stringp (cdr x
)) nil
)
1755 ((stringp (nth 1 x
)) x
)
1756 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1757 (t (cons (car x
) (cons "" (cdr x
))))))
1760 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1761 "The user interface for selecting an agenda command."
1763 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1764 (restrict-ok (and bfn
(org-mode-p)))
1765 (region-p (org-region-active-p))
1766 (custom org-agenda-custom-commands
)
1768 restriction second-time
1769 c entry key type match prefixes rmheader header-end custom1 desc
)
1770 (save-window-excursion
1771 (delete-other-windows)
1772 (org-switch-to-buffer-other-window " *Agenda Commands*")
1774 (insert (eval-when-compile
1777 Press key for an agenda command: < Buffer, subtree/region restriction
1778 -------------------------------- > Remove restriction
1779 a Agenda for current week or day e Export agenda views
1780 t List of all TODO entries T Entries with special TODO kwd
1781 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1782 L Timeline for current buffer # List stuck projects (!=configure)
1783 s Search for keywords C Configure custom agenda commands
1787 (while (string-match
1788 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1790 (setq start
(match-end 0))
1791 (add-text-properties (match-beginning 2) (match-end 2)
1792 '(face bold
) header
))
1794 (setq header-end
(move-marker (make-marker) (point)))
1796 (setq custom1 custom
)
1797 (when (eq rmheader t
)
1799 (re-search-forward ":" nil t
)
1800 (delete-region (match-end 0) (point-at-eol))
1803 (delete-region (match-end 0) (point-at-eol))
1804 (move-marker header-end
(match-end 0)))
1805 (goto-char header-end
)
1806 (delete-region (point) (point-max))
1807 (while (setq entry
(pop custom1
))
1808 (setq key
(car entry
) desc
(nth 1 entry
)
1809 type
(nth 2 entry
) match
(nth 3 entry
))
1810 (if (> (length key
) 1)
1811 (add-to-list 'prefixes
(string-to-char key
))
1815 (org-add-props (copy-sequence key
)
1818 ((string-match "\\S-" desc
) desc
)
1819 ((eq type
'agenda
) "Agenda for current week or day")
1820 ((eq type
'alltodo
) "List of all TODO entries")
1821 ((eq type
'search
) "Word search")
1822 ((eq type
'stuck
) "List of stuck projects")
1823 ((eq type
'todo
) "TODO keyword")
1824 ((eq type
'tags
) "Tags query")
1825 ((eq type
'tags-todo
) "Tags (TODO)")
1826 ((eq type
'tags-tree
) "Tags tree")
1827 ((eq type
'todo-tree
) "TODO kwd tree")
1828 ((eq type
'occur-tree
) "Occur tree")
1829 ((functionp type
) (if (symbolp type
)
1831 "Lambda expression"))
1835 (org-add-props match nil
'face
'org-warning
))
1837 (format "set of %d commands" (length match
)))
1843 (org-add-props (char-to-string x
)
1845 (or (cdr (assoc (concat selstring
(char-to-string x
))
1846 prefix-descriptions
))
1849 (goto-char (point-min))
1851 (if (not (pos-visible-in-window-p (point-max)))
1852 (org-fit-window-to-buffer))
1853 (setq second-time t
)
1854 (org-fit-window-to-buffer))
1855 (message "Press key for agenda command%s:"
1856 (if (or restrict-ok org-agenda-overriding-restriction
)
1857 (if org-agenda-overriding-restriction
1858 " (restriction lock active)"
1860 (format " (restricted to %s)" restriction
)
1863 (setq c
(read-char-exclusive))
1866 ((assoc (char-to-string c
) custom
)
1867 (setq selstring
(concat selstring
(char-to-string c
)))
1868 (throw 'exit
(cons selstring restriction
)))
1870 (setq selstring
(concat selstring
(char-to-string c
))
1872 rmheader
(or rmheader t
)
1873 custom
(delq nil
(mapcar
1875 (if (or (= (length (car x
)) 1)
1876 (/= (string-to-char (car x
)) c
))
1878 (cons (substring (car x
) 1) (cdr x
))))
1880 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1881 (message "Restriction is only possible in Org-mode buffers")
1884 (org-agenda-remove-restriction-lock 'noupdate
)
1885 (setq restriction
'buffer
))
1887 (org-agenda-remove-restriction-lock 'noupdate
)
1888 (setq restriction
(if region-p
'region
'subtree
)))
1890 (org-agenda-remove-restriction-lock 'noupdate
)
1893 ((eq restriction
'buffer
)
1894 (if region-p
'region
'subtree
))
1895 ((memq restriction
'(subtree region
))
1899 (org-agenda-remove-restriction-lock 'noupdate
)
1900 (setq restriction nil
))
1901 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1902 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1903 ((and (> (length selstring
) 0) (eq c ?\d
))
1905 (org-agenda-get-restriction-and-command prefix-descriptions
))
1907 ((equal c ?q
) (error "Abort"))
1908 (t (error "Invalid key %c" c
))))))))
1910 (defun org-run-agenda-series (name series
)
1911 (org-let (nth 1 series
) '(org-prepare-agenda name
))
1912 (let* ((org-agenda-multi t
)
1913 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1915 (gprops (nth 1 series
))
1916 match
;; The byte compiler incorrectly complains about this. Keep it!
1918 (while (setq cmd
(pop cmds
))
1919 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1922 (org-let2 gprops lprops
1923 '(call-interactively 'org-agenda-list
)))
1925 (org-let2 gprops lprops
1926 '(call-interactively 'org-todo-list
)))
1928 (org-let2 gprops lprops
1929 '(org-search-view current-prefix-arg match nil
)))
1931 (org-let2 gprops lprops
1932 '(call-interactively 'org-agenda-list-stuck-projects
)))
1934 (org-let2 gprops lprops
1935 '(org-tags-view current-prefix-arg match
)))
1936 ((eq type
'tags-todo
)
1937 (org-let2 gprops lprops
1938 '(org-tags-view '(4) match
)))
1940 (org-let2 gprops lprops
1941 '(org-todo-list match
)))
1943 (org-let2 gprops lprops
1944 '(funcall type match
)))
1945 (t (error "Invalid type in command series"))))
1947 (setq org-agenda-redo-command redo
)
1948 (goto-char (point-min)))
1949 (org-fit-agenda-window)
1950 (org-let (nth 1 series
) '(org-finalize-agenda)))
1953 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1954 "Run an agenda command in batch mode and send the result to STDOUT.
1955 If CMD-KEY is a string of length 1, it is used as a key in
1956 `org-agenda-custom-commands' and triggers this command. If it is a
1957 longer string it is used as a tags/todo match string.
1958 Paramters are alternating variable names and values that will be bound
1959 before running the agenda command."
1962 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1963 (if (> (length cmd-key
) 2)
1964 (eval (list 'let
(nreverse pars
)
1965 (list 'org-tags-view nil cmd-key
)))
1966 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1967 (set-buffer org-agenda-buffer-name
)
1968 (princ (org-encode-for-stdout (buffer-string)))))
1970 (defun org-encode-for-stdout (string)
1971 (if (fboundp 'encode-coding-string
)
1972 (encode-coding-string string buffer-file-coding-system
)
1975 (defvar org-agenda-info nil
)
1978 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1979 "Run an agenda command in batch mode and send the result to STDOUT.
1980 If CMD-KEY is a string of length 1, it is used as a key in
1981 `org-agenda-custom-commands' and triggers this command. If it is a
1982 longer string it is used as a tags/todo match string.
1983 Paramters are alternating variable names and values that will be bound
1984 before running the agenda command.
1986 The output gives a line for each selected agenda item. Each
1987 item is a list of comma-separated values, like this:
1989 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1991 category The category of the item
1992 head The headline, without TODO kwd, TAGS and PRIORITY
1993 type The type of the agenda entry, can be
1994 todo selected in TODO match
1995 tagsmatch selected in tags match
1996 diary imported from diary
1997 deadline a deadline on given date
1998 scheduled scheduled on given date
1999 timestamp entry has timestamp on given date
2000 closed entry was closed on given date
2001 upcoming-deadline warning about deadline
2002 past-scheduled forwarded scheduled item
2003 block entry has date block including g. date
2004 todo The todo keyword, if any
2005 tags All tags including inherited ones, separated by colons
2006 date The relevant date, like 2007-2-14
2007 time The time, like 15:00-16:50
2008 extra Sting with extra planning info
2009 priority-l The priority letter if any was given
2010 priority-n The computed numerical priority
2011 agenda-day The day in the agenda where this is listed"
2015 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
2016 (push (list 'org-agenda-remove-tags t
) pars
)
2017 (if (> (length cmd-key
) 2)
2018 (eval (list 'let
(nreverse pars
)
2019 (list 'org-tags-view nil cmd-key
)))
2020 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
2021 (set-buffer org-agenda-buffer-name
)
2022 (let* ((lines (org-split-string (buffer-string) "\n"))
2024 (while (setq line
(pop lines
))
2026 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
2027 (setq org-agenda-info
2028 (org-fix-agenda-info (text-properties-at 0 line
)))
2030 (org-encode-for-stdout
2031 (mapconcat 'org-agenda-export-csv-mapper
2032 '(org-category txt type todo tags date time-of-day extra
2033 priority-letter priority agenda-day
)
2037 (defun org-fix-agenda-info (props)
2038 "Make sure all properties on an agenda item have a canonical form,
2039 so the export commands can easily use it."
2041 (when (setq tmp
(plist-get props
'tags
))
2042 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
2043 (when (setq tmp
(plist-get props
'date
))
2044 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
2045 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
2046 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
2048 (setq tmp
(calendar-date-string tmp
)))
2049 (setq props
(plist-put props
'date tmp
)))
2050 (when (setq tmp
(plist-get props
'day
))
2051 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
2052 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
2053 (setq tmp
(calendar-date-string tmp
)))
2054 (setq props
(plist-put props
'day tmp
))
2055 (setq props
(plist-put props
'agenda-day tmp
)))
2056 (when (setq tmp
(plist-get props
'txt
))
2057 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
2058 (plist-put props
'priority-letter
(match-string 1 tmp
))
2059 (setq tmp
(replace-match "" t t tmp
)))
2060 (when (and (setq re
(plist-get props
'org-todo-regexp
))
2061 (setq re
(concat "\\`\\.*" re
" ?"))
2062 (string-match re tmp
))
2063 (plist-put props
'todo
(match-string 1 tmp
))
2064 (setq tmp
(replace-match "" t t tmp
)))
2065 (plist-put props
'txt tmp
)))
2068 (defun org-agenda-export-csv-mapper (prop)
2069 (let ((res (plist-get org-agenda-info prop
)))
2074 (t (prin1-to-string res
))))
2075 (while (string-match "," res
)
2076 (setq res
(replace-match ";" t t res
)))
2081 (defun org-store-agenda-views (&rest parameters
)
2083 (eval (list 'org-batch-store-agenda-views
)))
2085 ;; FIXME, why is this a macro?????
2087 (defmacro org-batch-store-agenda-views
(&rest parameters
)
2088 "Run all custom agenda commands that have a file argument."
2089 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
2091 (dir default-directory
)
2092 pars cmd thiscmdkey files opts cmd-or-set
)
2094 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
2095 (setq pars
(reverse pars
))
2096 (save-window-excursion
2098 (setq cmd
(pop cmds
)
2099 thiscmdkey
(car cmd
)
2100 cmd-or-set
(nth 2 cmd
)
2101 opts
(nth (if (listp cmd-or-set
) 3 4) cmd
)
2102 files
(nth (if (listp cmd-or-set
) 4 5) cmd
))
2103 (if (stringp files
) (setq files
(list files
)))
2105 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2106 (list 'org-agenda nil thiscmdkey
)))
2107 (set-buffer org-agenda-buffer-name
)
2109 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2110 (list 'org-write-agenda
2111 (expand-file-name (pop files
) dir
) nil t
))))
2112 (and (get-buffer org-agenda-buffer-name
)
2113 (kill-buffer org-agenda-buffer-name
)))))))
2115 (defun org-write-agenda (file &optional open nosettings
)
2116 "Write the current buffer (an agenda view) as a file.
2117 Depending on the extension of the file name, plain text (.txt),
2118 HTML (.html or .htm) or Postscript (.ps) is produced.
2119 If the extension is .ics, run icalendar export over all files used
2120 to construct the agenda and limit the export to entries listed in the
2122 With prefic argument OPEN, open the new file immediately.
2123 If NOSETTINGS is given, do not scope the settings of
2124 `org-agenda-exporter-settings' into the export commands. This is used when
2125 the settings have already been scoped and we do not wish to overrule other,
2126 higher priority settings."
2127 (interactive "FWrite agenda to file: \nP")
2128 (if (not (file-writable-p file
))
2129 (error "Cannot write agenda to file %s" file
))
2131 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
2132 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
2133 (org-let (if nosettings nil org-agenda-exporter-settings
)
2135 (save-window-excursion
2136 (org-agenda-mark-filtered-text)
2137 (let ((bs (copy-sequence (buffer-string))) beg
)
2138 (org-agenda-unmark-filtered-text)
2141 (org-agenda-remove-marked-text 'org-filtered
)
2142 (while (setq beg
(text-property-any (point-min) (point-max)
2145 beg
(or (next-single-property-change beg
'org-filtered
)
2147 (run-hooks 'org-agenda-before-write-hook
)
2149 ((string-match "\\.html?\\'" file
)
2150 (set-buffer (htmlize-buffer (current-buffer)))
2152 (when (and org-agenda-export-html-style
2153 (string-match "<style>" org-agenda-export-html-style
))
2154 ;; replace <style> section with org-agenda-export-html-style
2155 (goto-char (point-min))
2156 (kill-region (- (search-forward "<style") 6)
2157 (search-forward "</style>"))
2158 (insert org-agenda-export-html-style
))
2160 (kill-buffer (current-buffer))
2161 (message "HTML written to %s" file
))
2162 ((string-match "\\.ps\\'" file
)
2164 (flet ((ps-get-buffer-name () "Agenda View"))
2165 (ps-print-buffer-with-faces file
))
2166 (message "Postscript written to %s" file
))
2167 ((string-match "\\.pdf\\'" file
)
2169 (flet ((ps-get-buffer-name () "Agenda View"))
2170 (ps-print-buffer-with-faces
2171 (concat (file-name-sans-extension file
) ".ps")))
2172 (call-process "ps2pdf" nil nil nil
2174 (concat (file-name-sans-extension file
) ".ps"))
2175 (expand-file-name file
))
2176 (message "PDF written to %s" file
))
2177 ((string-match "\\.ics\\'" file
)
2178 (require 'org-icalendar
)
2179 (let ((org-agenda-marker-table
2180 (org-create-marker-find-array
2181 (org-agenda-collect-markers)))
2182 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
2183 (org-combined-agenda-icalendar-file file
))
2184 (apply 'org-export-icalendar
'combine
2185 (org-agenda-files nil
'ifmode
))))
2187 (let ((bs (buffer-string)))
2192 (kill-buffer (current-buffer))
2193 (message "Plain text written to %s" file
))))))))
2194 (set-buffer org-agenda-buffer-name
))
2195 (when open
(org-open-file file
)))
2197 (defvar org-agenda-filter-overlays nil
)
2199 (defun org-agenda-mark-filtered-text ()
2200 "Mark all text hidden by filtering with a text property."
2201 (let ((inhibit-read-only t
))
2204 (when (equal (org-overlay-buffer o
) (current-buffer))
2206 (org-overlay-start o
) (org-overlay-end o
)
2208 org-agenda-filter-overlays
)))
2210 (defun org-agenda-unmark-filtered-text ()
2211 "Remove the filtering text property."
2212 (let ((inhibit-read-only t
))
2213 (remove-text-properties (point-min) (point-max) '(org-filtered t
))))
2215 (defun org-agenda-remove-marked-text (property &optional value
)
2216 "Delete all text marked with VALUE of PROPERTY.
2217 VALUE defaults to t."
2219 (setq value
(or value t
))
2220 (while (setq beg
(text-property-any (point-min) (point-max)
2223 beg
(or (next-single-property-change beg
'org-filtered
)
2226 (defun org-agenda-add-entry-text ()
2227 "Add entry text to agenda lines.
2228 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2229 entry text following headings shown in the agenda.
2230 Drawers will be excluded, also the line with scheduling/deadline info."
2231 (when (> org-agenda-add-entry-text-maxlines
0)
2232 (let (m txt drawer-re kwd-time-re ind
)
2233 (goto-char (point-min))
2235 (if (not (setq m
(get-text-property (point) 'org-hd-marker
)))
2236 (beginning-of-line 2)
2238 (with-current-buffer (marker-buffer m
)
2239 (if (not (org-mode-p))
2245 (beginning-of-line 2)
2246 (setq txt
(buffer-substring
2248 (progn (outline-next-heading) (point)))
2249 drawer-re org-drawer-regexp
2250 kwd-time-re
(concat "^[ \t]*" org-keyword-time-regexp
2254 (when org-agenda-add-entry-text-descriptive-links
2255 (goto-char (point-min))
2256 (while (org-activate-bracket-links (point-max))
2257 (add-text-properties (match-beginning 0) (match-end 0)
2259 (goto-char (point-min))
2260 (while (re-search-forward org-bracket-link-regexp
(point-max) t
)
2261 (set-text-properties (match-beginning 0) (match-end 0)
2263 (goto-char (point-min))
2264 (while (re-search-forward drawer-re nil t
)
2267 (progn (re-search-forward
2268 "^[ \t]*:END:.*\n?" nil
'move
)
2270 (goto-char (point-min))
2271 (while (re-search-forward kwd-time-re nil t
)
2273 (if (re-search-forward "[ \t\n]+\\'" nil t
)
2275 (goto-char (point-min))
2276 ;; find min indentation
2277 (goto-char (point-min))
2278 (untabify (point-min) (point-max))
2279 (setq ind
(org-get-indentation))
2281 (unless (looking-at "[ \t]*$")
2282 (setq ind
(min ind
(org-get-indentation))))
2283 (beginning-of-line 2))
2284 (goto-char (point-min))
2286 (unless (looking-at "[ \t]*$")
2287 (move-to-column ind
)
2288 (delete-region (point-at-bol) (point)))
2289 (beginning-of-line 2))
2290 (goto-char (point-min))
2291 (while (and (not (eobp)) (re-search-forward "^" nil t
))
2292 (replace-match " > "))
2293 (goto-char (point-min))
2294 (while (looking-at "[ \t]*\n") (replace-match ""))
2295 (goto-char (point-max))
2296 (when (> (org-current-line)
2297 (1+ org-agenda-add-entry-text-maxlines
))
2298 (goto-line (1+ org-agenda-add-entry-text-maxlines
))
2300 (setq txt
(buffer-substring (point-min) (point)))))))))
2302 (if (string-match "\\S-" txt
) (insert "\n" txt
)))))))
2304 (defun org-agenda-collect-markers ()
2305 "Collect the markers pointing to entries in the agenda buffer."
2308 (goto-char (point-min))
2310 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
2311 (get-text-property (point) 'org-marker
)))
2313 (beginning-of-line 2)))
2314 (nreverse markers
)))
2316 (defun org-create-marker-find-array (marker-list)
2317 "Create a alist of files names with all marker positions in that file."
2319 (while (setq m
(pop marker-list
))
2320 (setq p
(marker-position m
)
2321 f
(buffer-file-name (or (buffer-base-buffer
2323 (marker-buffer m
))))
2324 (if (setq a
(assoc f tbl
))
2325 (push (marker-position m
) (cdr a
))
2326 (push (list f p
) tbl
)))
2327 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
2330 (defvar org-agenda-marker-table nil
) ; dynamically scoped parameter
2331 (defun org-check-agenda-marker-table ()
2332 "Check of the current entry is on the marker list."
2333 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2335 (and (setq a
(assoc file org-agenda-marker-table
))
2338 (org-back-to-heading t
)
2339 (member (point) (cdr a
)))))))
2341 (defun org-check-for-org-mode ()
2342 "Make sure current buffer is in org-mode. Error if not."
2344 (error "Cannot execute org-mode agenda command on buffer in %s."
2347 (defun org-fit-agenda-window ()
2348 "Fit the window to the buffer size."
2349 (and (memq org-agenda-window-setup
'(reorganize-frame))
2350 (fboundp 'fit-window-to-buffer
)
2351 (org-fit-window-to-buffer
2353 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
2354 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
2356 ;;; Agenda prepare and finalize
2358 (defvar org-agenda-multi nil
) ; dynamically scoped
2359 (defvar org-agenda-buffer-name
"*Org Agenda*")
2360 (defvar org-pre-agenda-window-conf nil
)
2361 (defvar org-agenda-columns-active nil
)
2362 (defvar org-agenda-name nil
)
2363 (defvar org-agenda-filter nil
)
2364 (defvar org-agenda-filter-preset nil
2365 "A preset of the tags filter used for secondary agenda filtering.
2366 This must be a list of strings, each string must be a single tag preceeded
2368 This variable should not be set directly, but agenda custom commands can
2369 bind it in the options section.")
2371 (defun org-prepare-agenda (&optional name
)
2372 (setq org-todo-keywords-for-agenda nil
)
2373 (setq org-done-keywords-for-agenda nil
)
2374 (setq org-agenda-filter nil
)
2375 (put 'org-agenda-filter
:preset-filter org-agenda-filter-preset
)
2376 (if org-agenda-multi
2378 (setq buffer-read-only nil
)
2379 (goto-char (point-max))
2380 (unless (or (bobp) org-agenda-compact-blocks
)
2382 (if (stringp org-agenda-block-separator
)
2383 org-agenda-block-separator
2384 (make-string (window-width) org-agenda-block-separator
))
2386 (narrow-to-region (point) (point-max)))
2387 (org-agenda-reset-markers)
2388 (setq org-agenda-contributing-files nil
)
2389 (setq org-agenda-columns-active nil
)
2390 (org-prepare-agenda-buffers (org-agenda-files nil
'ifmode
))
2391 (setq org-todo-keywords-for-agenda
2392 (org-uniquify org-todo-keywords-for-agenda
))
2393 (setq org-done-keywords-for-agenda
2394 (org-uniquify org-done-keywords-for-agenda
))
2395 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
2396 (awin (get-buffer-window abuf
)))
2398 ((equal (current-buffer) abuf
) nil
)
2399 (awin (select-window awin
))
2400 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
2401 ((equal org-agenda-window-setup
'current-window
)
2402 (switch-to-buffer abuf
))
2403 ((equal org-agenda-window-setup
'other-window
)
2404 (org-switch-to-buffer-other-window abuf
))
2405 ((equal org-agenda-window-setup
'other-frame
)
2406 (switch-to-buffer-other-frame abuf
))
2407 ((equal org-agenda-window-setup
'reorganize-frame
)
2408 (delete-other-windows)
2409 (org-switch-to-buffer-other-window abuf
))))
2410 (setq buffer-read-only nil
)
2411 (let ((inhibit-read-only t
)) (erase-buffer))
2413 (and name
(not org-agenda-name
)
2414 (org-set-local 'org-agenda-name name
)))
2415 (setq buffer-read-only nil
))
2417 (defun org-finalize-agenda ()
2418 "Finishing touch for the agenda buffer, called just before displaying it."
2419 (unless org-agenda-multi
2421 (let ((inhibit-read-only t
))
2422 (goto-char (point-min))
2423 (while (org-activate-bracket-links (point-max))
2424 (add-text-properties (match-beginning 0) (match-end 0)
2426 (org-agenda-align-tags)
2427 (unless org-agenda-with-colors
2428 (remove-text-properties (point-min) (point-max) '(face nil
))))
2429 (if (and (boundp 'org-agenda-overriding-columns-format
)
2430 org-agenda-overriding-columns-format
)
2431 (org-set-local 'org-agenda-overriding-columns-format
2432 org-agenda-overriding-columns-format
))
2433 (if (and (boundp 'org-agenda-view-columns-initially
)
2434 org-agenda-view-columns-initially
)
2435 (org-agenda-columns))
2436 (when org-agenda-fontify-priorities
2437 (org-agenda-fontify-priorities))
2438 (when (and org-agenda-dim-blocked-tasks org-blocker-hook
)
2439 (org-agenda-dim-blocked-tasks))
2440 (org-agenda-mark-clocking-task)
2441 (run-hooks 'org-finalize-agenda-hook
)
2442 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
2443 (when (get 'org-agenda-filter
:preset-filter
)
2444 (org-agenda-filter-apply org-agenda-filter
))
2447 (defun org-agenda-mark-clocking-task ()
2448 "Mark the current clock entry in the agenda if it is present."
2450 (if (eq (org-overlay-get o
'type
) 'org-agenda-clocking
)
2451 (org-delete-overlay o
)))
2452 (org-overlays-in (point-min) (point-max)))
2453 (when (marker-buffer org-clock-hd-marker
)
2455 (goto-char (point-min))
2457 (while (setq s
(next-single-property-change (point) 'org-hd-marker
))
2459 (when (equal (get-text-property (point) 'org-hd-marker
)
2460 org-clock-hd-marker
)
2461 (setq ov
(org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2462 (org-overlay-put ov
'type
'org-agenda-clocking
)
2463 (org-overlay-put ov
'face
'org-agenda-clocking
)
2464 (org-overlay-put ov
'help-echo
2465 "The clock is running in this item")))))))
2467 (defun org-agenda-fontify-priorities ()
2468 "Make highest priority lines bold, and lowest italic."
2470 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
2471 (org-delete-overlay o
)))
2472 (org-overlays-in (point-min) (point-max)))
2474 (let ((inhibit-read-only t
)
2476 (goto-char (point-min))
2477 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
2478 (setq h
(or (get-char-property (point) 'org-highest-priority
)
2479 org-highest-priority
)
2480 l
(or (get-char-property (point) 'org-lowest-priority
)
2481 org-lowest-priority
)
2482 p
(string-to-char (match-string 1))
2483 b
(match-beginning 0)
2484 e
(if (eq org-agenda-fontify-priorities
'cookies
)
2487 ov
(org-make-overlay b e
))
2490 (cond ((cdr (assoc p org-priority-faces
)))
2491 ((and (listp org-agenda-fontify-priorities
)
2492 (cdr (assoc p org-agenda-fontify-priorities
))))
2493 ((equal p l
) 'italic
)
2494 ((equal p h
) 'bold
)))
2495 (org-overlay-put ov
'org-type
'org-priority
)))))
2497 (defun org-agenda-dim-blocked-tasks ()
2498 "Dim currently blocked TODO's in the agenda display."
2499 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-blocked-todo
)
2500 (org-delete-overlay o
)))
2501 (org-overlays-in (point-min) (point-max)))
2503 (let ((inhibit-read-only t
)
2504 (org-depend-tag-blocked nil
)
2505 (invis (eq org-agenda-dim-blocked-tasks
'invisible
))
2506 org-blocked-by-checkboxes
2507 invis1 b e p ov h l
)
2508 (goto-char (point-min))
2509 (while (let ((pos (next-single-property-change (point) 'todo-state
)))
2510 (and pos
(goto-char (1+ pos
))))
2511 (setq org-blocked-by-checkboxes nil invis1 invis
)
2512 (let ((marker (get-text-property (point) 'org-hd-marker
)))
2514 (not (with-current-buffer (marker-buffer marker
)
2517 (if (org-entry-get nil
"NOBLOCKING")
2518 t
;; Never block this entry
2519 (run-hook-with-args-until-failure
2521 (list :type
'todo-state-change
2525 (if org-blocked-by-checkboxes
(setq invis1 nil
))
2526 (setq b
(if invis1
(max (point-min) (1- (point))) (point))
2528 ov
(org-make-overlay b e
))
2530 (org-overlay-put ov
'invisible t
)
2531 (org-overlay-put ov
'face
'org-agenda-dimmed-todo-face
))
2532 (org-overlay-put ov
'org-type
'org-blocked-todo
)))))))
2534 (defvar org-agenda-skip-function nil
2535 "Function to be called at each match during agenda construction.
2536 If this function returns nil, the current match should not be skipped.
2537 Otherwise, the function must return a position from where the search
2538 should be continued.
2539 This may also be a Lisp form, it will be evaluated.
2540 Never set this variable using `setq' or so, because then it will apply
2541 to all future agenda commands. Instead, bind it with `let' to scope
2542 it dynamically into the agenda-constructing command. A good way to set
2543 it is through options in org-agenda-custom-commands.")
2545 (defun org-agenda-skip ()
2546 "Throw to `:skip' in places that should be skipped.
2547 Also moves point to the end of the skipped region, so that search can
2548 continue from there."
2549 (let ((p (point-at-bol)) to fp
)
2550 (and org-agenda-skip-archived-trees
(not org-agenda-archives-mode
)
2551 (get-text-property p
:org-archived
)
2552 (org-end-of-subtree t
)
2554 (and org-agenda-skip-comment-trees
2555 (get-text-property p
:org-comment
)
2556 (org-end-of-subtree t
)
2558 (if (equal (char-after p
) ?
#) (throw :skip t
))
2559 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
2560 (consp org-agenda-skip-function
))
2561 (setq to
(save-excursion
2564 (funcall org-agenda-skip-function
)
2565 (eval org-agenda-skip-function
))))))
2569 (defvar org-agenda-markers nil
2570 "List of all currently active markers created by `org-agenda'.")
2571 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
2572 "Creation time of the last agenda marker.")
2574 (defun org-agenda-new-marker (&optional pos
)
2575 "Return a new agenda marker.
2576 Org-mode keeps a list of these markers and resets them when they are
2578 (let ((m (copy-marker (or pos
(point)))))
2579 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
2580 (push m org-agenda-markers
)
2583 (defun org-agenda-reset-markers ()
2584 "Reset markers created by `org-agenda'."
2585 (while org-agenda-markers
2586 (move-marker (pop org-agenda-markers
) nil
)))
2588 (defun org-agenda-save-markers-for-cut-and-paste (beg end
)
2589 "Save relative positions of markers in region."
2590 (mapc (lambda (m) (org-check-and-save-marker m beg end
))
2591 org-agenda-markers
))
2595 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
2597 (defun org-timeline (&optional include-all
)
2598 "Show a time-sorted view of the entries in the current org file.
2599 Only entries with a time stamp of today or later will be listed. With
2600 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2601 under the current date.
2602 If the buffer contains an active region, only check the region for
2606 (org-compile-prefix-format 'timeline
)
2607 (org-set-sorting-strategy 'timeline
)
2609 (dotodo include-all
)
2610 (doclosed org-agenda-show-log
)
2611 (entry buffer-file-name
)
2612 (date (calendar-current-date))
2613 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2614 (end (if (org-region-active-p) (region-end) (point-max)))
2615 (day-numbers (org-get-all-dates beg end
'no-ranges
2616 t doclosed
; always include today
2617 org-timeline-show-empty-dates
))
2618 (org-deadline-warning-days 0)
2619 (org-agenda-only-exact-dates t
)
2620 (today (time-to-days (current-time)))
2623 s e rtn d emptyp wd
)
2624 (setq org-agenda-redo-command
2626 (list 'org-switch-to-buffer-other-window
(current-buffer))
2627 (list 'org-timeline
(list 'quote include-all
))))
2629 ;; Remove past dates from the list of dates.
2630 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2631 (if (>= x today
) x nil
))
2633 (org-prepare-agenda (concat "Timeline "
2634 (file-name-nondirectory buffer-file-name
)))
2635 (if doclosed
(push :closed args
))
2636 (push :timestamp args
)
2637 (push :deadline args
)
2638 (push :scheduled args
)
2640 (if dotodo
(push :todo args
))
2641 (while (setq d
(pop day-numbers
))
2642 (if (and (listp d
) (eq (car d
) :omitted
))
2645 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2646 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2647 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2648 (if (and (>= d today
)
2653 (insert (make-string 79 ?-
) "\n")))
2654 (setq date
(calendar-gregorian-from-absolute d
)
2655 wd
(calendar-day-of-week date
))
2657 (setq rtn
(and (not emptyp
)
2658 (apply 'org-agenda-get-day-entries entry
2660 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2663 (if (stringp org-agenda-format-date
)
2664 (format-time-string org-agenda-format-date
2665 (org-time-from-absolute date
))
2666 (funcall org-agenda-format-date date
))
2668 (put-text-property s
(1- (point)) 'face
2669 (if (member wd org-agenda-weekend-days
)
2670 'org-agenda-date-weekend
2672 (put-text-property s
(1- (point)) 'org-date-line t
)
2674 (put-text-property s
(1- (point)) 'org-today t
))
2675 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2676 (put-text-property s
(1- (point)) 'day d
)))))
2677 (goto-char (point-min))
2678 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2680 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2681 (org-finalize-agenda)
2682 (setq buffer-read-only t
)))
2684 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2685 "Return a list of all relevant day numbers from BEG to END buffer positions.
2686 If NO-RANGES is non-nil, include only the start and end dates of a range,
2687 not every single day in the range. If FORCE-TODAY is non-nil, make
2688 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2689 inactive time stamps (those in square brackets) are included.
2690 When EMPTY is non-nil, also include days without any entries."
2692 (if pre-re pre-re
"")
2693 (if inactive org-ts-regexp-both org-ts-regexp
)))
2694 dates dates1 date day day1 day2 ts1 ts2
)
2696 (setq dates
(list (time-to-days (current-time)))))
2699 (while (re-search-forward re end t
)
2700 (setq day
(time-to-days (org-time-string-to-time
2701 (substring (match-string 1) 0 10))))
2702 (or (memq day dates
) (push day dates
)))
2705 (while (re-search-forward org-tr-regexp end t
)
2706 (setq ts1
(substring (match-string 1) 0 10)
2707 ts2
(substring (match-string 2) 0 10)
2708 day1
(time-to-days (org-time-string-to-time ts1
))
2709 day2
(time-to-days (org-time-string-to-time ts2
)))
2710 (while (< (setq day1
(1+ day1
)) day2
)
2711 (or (memq day1 dates
) (push day1 dates
)))))
2712 (setq dates
(sort dates
'<))
2714 (while (setq day
(pop dates
))
2715 (setq day2
(car dates
))
2717 (when (and day2 empty
)
2718 (if (or (eq empty t
)
2719 (and (numberp empty
) (<= (- day2 day
) empty
)))
2720 (while (< (setq day
(1+ day
)) day2
)
2721 (push (list day
) dates1
))
2722 (push (cons :omitted
(- day2 day
)) dates1
))))
2723 (setq dates
(nreverse dates1
)))
2726 ;;; Agenda Daily/Weekly
2728 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2729 (defvar org-agenda-start-day nil
; dynamically scoped parameter
2730 "Custom commands can set this variable in the options section.")
2731 (defvar org-agenda-last-arguments nil
2732 "The arguments of the previous call to org-agenda")
2733 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2734 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2735 (defvar org-include-all-loc nil
) ; local variable
2736 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2739 (defun org-agenda-list (&optional include-all start-day ndays
)
2740 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2741 The view will be for the current day or week, but from the overview buffer
2742 you will be able to go to other days/weeks.
2744 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2745 all unfinished TODO items will also be shown, before the agenda.
2746 This feature is considered obsolete, please use the TODO list or a block
2749 With a numeric prefix argument in an interactive call, the agenda will
2750 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2751 the number of days. NDAYS defaults to `org-agenda-ndays'.
2753 START-DAY defaults to TODAY, or to the most recent match for the weekday
2754 given in `org-agenda-start-on-weekday'."
2756 (if (and (integerp include-all
) (> include-all
0))
2757 (setq ndays include-all include-all nil
))
2758 (setq ndays
(or ndays org-agenda-ndays
)
2759 start-day
(or start-day org-agenda-start-day
))
2760 (if org-agenda-overriding-arguments
2761 (setq include-all
(car org-agenda-overriding-arguments
)
2762 start-day
(nth 1 org-agenda-overriding-arguments
)
2763 ndays
(nth 2 org-agenda-overriding-arguments
)))
2764 (if (stringp start-day
)
2765 ;; Convert to an absolute day number
2766 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2767 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2768 (org-compile-prefix-format 'agenda
)
2769 (org-set-sorting-strategy 'agenda
)
2771 (let* ((org-agenda-start-on-weekday
2772 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2773 org-agenda-start-on-weekday nil
))
2774 (thefiles (org-agenda-files nil
'ifmode
))
2776 (today (time-to-days
2777 (time-subtract (current-time)
2778 (list 0 (* 3600 org-extend-today-until
) 0))))
2779 (sd (or start-day today
))
2780 (start (if (or (null org-agenda-start-on-weekday
)
2781 (< org-agenda-ndays
7))
2783 (let* ((nt (calendar-day-of-week
2784 (calendar-gregorian-from-absolute sd
)))
2785 (n1 org-agenda-start-on-weekday
)
2787 (- sd
(+ (if (< d
0) 7 0) d
)))))
2788 (day-numbers (list start
))
2790 (inhibit-redisplay (not debug-on-error
))
2791 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2792 clocktable-start clocktable-end
)
2793 (setq org-agenda-redo-command
2794 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2795 ;; Make the list of days
2796 (setq ndays
(or ndays org-agenda-ndays
)
2799 (push (1+ (car day-numbers
)) day-numbers
)
2800 (setq ndays
(1- ndays
)))
2801 (setq day-numbers
(nreverse day-numbers
))
2802 (setq clocktable-start
(car day-numbers
)
2803 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2804 (org-prepare-agenda "Day/Week")
2805 (org-set-local 'org-starting-day
(car day-numbers
))
2806 (org-set-local 'org-include-all-loc include-all
)
2807 (org-set-local 'org-agenda-span
2808 (org-agenda-ndays-to-span nd
))
2809 (when (and (or include-all org-agenda-include-all-todo
)
2810 (member today day-numbers
))
2811 (setq files thefiles
2813 (while (setq file
(pop files
))
2815 (org-check-agenda-file file
)
2816 (setq date
(calendar-gregorian-from-absolute today
)
2817 rtn
(org-agenda-get-day-entries
2819 (setq rtnall
(append rtnall rtn
))))
2821 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2822 (add-text-properties (point-min) (1- (point))
2823 (list 'face
'org-agenda-structure
))
2824 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2825 (unless org-agenda-compact-blocks
2826 (let* ((d1 (car day-numbers
))
2827 (d2 (org-last day-numbers
))
2828 (w1 (org-days-to-iso-week d1
))
2829 (w2 (org-days-to-iso-week d2
)))
2831 (if org-agenda-overriding-header
2832 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2833 nil
'face
'org-agenda-structure
) "\n")
2834 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2836 (if (< (- d2 d1
) 350)
2838 (format " (W%02d)" w1
)
2839 (format " (W%02d-W%02d)" w1 w2
))
2842 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2844 (while (setq d
(pop day-numbers
))
2845 (setq date
(calendar-gregorian-from-absolute d
)
2846 wd
(calendar-day-of-week date
)
2848 (if (or (setq todayp
(= d today
))
2849 (and (not start-pos
) (= d sd
)))
2850 (setq start-pos
(point))
2851 (if (and start-pos
(not end-pos
))
2852 (setq end-pos
(point))))
2853 (setq files thefiles
2855 (while (setq file
(pop files
))
2857 (org-check-agenda-file file
)
2859 ((eq org-agenda-show-log
'only
)
2860 (setq rtn
(org-agenda-get-day-entries
2861 file date
:closed
)))
2862 (org-agenda-show-log
2863 (setq rtn
(org-agenda-get-day-entries
2865 :deadline
:scheduled
:timestamp
:sexp
:closed
)))
2867 (setq rtn
(org-agenda-get-day-entries
2869 :deadline
:scheduled
:sexp
:timestamp
))))
2870 (setq rtnall
(append rtnall rtn
))))
2871 (if org-agenda-include-diary
2872 (let ((org-agenda-search-headline-for-time t
))
2873 (require 'diary-lib
)
2874 (setq rtn
(org-get-entries-from-diary date
))
2875 (setq rtnall
(append rtnall rtn
))))
2876 (if (or rtnall org-agenda-show-all-dates
)
2878 (setq day-cnt
(1+ day-cnt
))
2880 (if (stringp org-agenda-format-date
)
2881 (format-time-string org-agenda-format-date
2882 (org-time-from-absolute date
))
2883 (funcall org-agenda-format-date date
))
2885 (put-text-property s
(1- (point)) 'face
2886 (if (member wd org-agenda-weekend-days
)
2887 'org-agenda-date-weekend
2889 (put-text-property s
(1- (point)) 'org-date-line t
)
2890 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2892 (put-text-property s
(1- (point)) 'org-today t
)
2893 (put-text-property s
(1- (point)) 'face
'org-agenda-date-today
))
2895 (org-finalize-agenda-entries
2896 (org-agenda-add-time-grid-maybe
2899 (put-text-property s
(1- (point)) 'day d
)
2900 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2901 (when (and org-agenda-clockreport-mode clocktable-start
)
2902 (let ((org-agenda-files (org-agenda-files nil
'ifmode
))
2903 ;; the above line is to ensure the restricted range!
2904 (p org-agenda-clockreport-parameter-plist
)
2906 (setq p
(org-plist-delete p
:block
))
2907 (setq p
(plist-put p
:tstart clocktable-start
))
2908 (setq p
(plist-put p
:tend clocktable-end
))
2909 (setq p
(plist-put p
:scope
'agenda
))
2910 (setq tbl
(apply 'org-get-clocktable p
))
2912 (goto-char (point-min))
2913 (or org-agenda-multi
(org-fit-agenda-window))
2914 (unless (and (pos-visible-in-window-p (point-min))
2915 (pos-visible-in-window-p (point-max)))
2916 (goto-char (1- (point-max)))
2918 (if (not (pos-visible-in-window-p (or start-pos
1)))
2920 (goto-char (or start-pos
1))
2922 (goto-char (or start-pos
1))
2923 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2924 (org-finalize-agenda)
2925 (setq buffer-read-only t
)
2928 (defun org-agenda-ndays-to-span (n)
2929 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2931 ;;; Agenda word search
2933 (defvar org-agenda-search-history nil
)
2934 (defvar org-todo-only nil
)
2936 (defvar org-search-syntax-table nil
2937 "Special syntax table for org-mode search.
2938 In this table, we have single quotes not as word constituents, to
2939 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
2941 (defun org-search-syntax-table ()
2942 (unless org-search-syntax-table
2943 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2944 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2945 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2946 org-search-syntax-table
)
2949 (defun org-search-view (&optional todo-only string edit-at
)
2950 "Show all entries that contain words or regular expressions.
2951 If the first character of the search string is an asterisks,
2952 search only the headlines.
2954 With optional prefix argument TODO-ONLY, only consider entries that are
2955 TODO entries. The argument STRING can be used to pass a default search
2956 string into this function. If EDIT-AT is non-nil, it means that the
2957 user should get a chance to edit this string, with cursor at position
2960 The search string is broken into \"words\" by splitting at whitespace.
2961 The individual words are then interpreted as a boolean expression with
2962 logical AND. Words prefixed with a minus must not occur in the entry.
2963 Words without a prefix or prefixed with a plus must occur in the entry.
2964 Matching is case-insensitive and the words are enclosed by word delimiters.
2966 Words enclosed by curly braces are interpreted as regular expressions
2967 that must or must not match in the entry.
2969 If the search string starts with an asterisk, search only in headlines.
2970 If (possibly after the leading star) the search string starts with an
2971 exclamation mark, this also means to look at TODO entries only, an effect
2972 that can also be achieved with a prefix argument.
2974 This command searches the agenda files, and in addition the files listed
2975 in `org-agenda-text-search-extra-files'."
2977 (org-compile-prefix-format 'search
)
2978 (org-set-sorting-strategy 'search
)
2979 (org-prepare-agenda "SEARCH")
2980 (let* ((props (list 'face nil
2981 'done-face
'org-agenda-done
2982 'org-not-done-regexp org-not-done-regexp
2983 'org-todo-regexp org-todo-regexp
2984 'org-complex-heading-regexp org-complex-heading-regexp
2985 'mouse-face
'highlight
2986 'keymap org-agenda-keymap
2987 'help-echo
(format "mouse-2 or RET jump to location")))
2988 regexp rtn rtnall files file pos
2989 marker category tags c neg re
2990 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2991 (unless (and (not edit-at
)
2993 (string-match "\\S-" string
))
2994 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2996 ((integerp edit-at
) (cons string edit-at
))
2998 'org-agenda-search-history
)))
2999 (org-set-local 'org-todo-only todo-only
)
3000 (setq org-agenda-redo-command
3001 (list 'org-search-view
(if todo-only t nil
) string
3002 '(if current-prefix-arg
1 nil
)))
3003 (setq org-agenda-query-string string
)
3005 (if (equal (string-to-char string
) ?
*)
3007 words
(substring string
1))
3008 (setq words string
))
3009 (when (equal (string-to-char words
) ?
!)
3011 words
(substring words
1)))
3012 (setq words
(org-split-string words
))
3014 (setq c
(string-to-char w
))
3016 (setq neg t w
(substring w
1))
3018 (setq neg nil w
(substring w
1))
3020 (if (string-match "\\`{.*}\\'" w
)
3021 (setq re
(substring w
1 -
1))
3022 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
3023 (if neg
(push re regexps-
) (push re regexps
+)))
3025 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
3027 (setq regexp
(concat "^" org-outline-regexp
))
3028 (setq regexp
(pop regexps
+))
3029 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
3031 (setq files
(org-agenda-files nil
'ifmode
))
3032 (when (eq (car org-agenda-text-search-extra-files
) 'agenda-archives
)
3033 (pop org-agenda-text-search-extra-files
)
3034 (setq files
(org-add-archive-files files
)))
3035 (setq files
(append files org-agenda-text-search-extra-files
)
3037 (while (setq file
(pop files
))
3040 (org-check-agenda-file file
)
3041 (setq buffer
(if (file-exists-p file
)
3042 (org-get-agenda-file-buffer file
)
3043 (error "No such file %s" file
)))
3045 ;; If file does not exist, make sure an error message is sent
3046 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
3048 (with-current-buffer buffer
3049 (with-syntax-table (org-search-syntax-table)
3050 (unless (org-mode-p)
3051 (error "Agenda file %s is not in `org-mode'" file
))
3052 (let ((case-fold-search t
))
3055 (if org-agenda-restrict
3056 (narrow-to-region org-agenda-restrict-begin
3057 org-agenda-restrict-end
)
3059 (goto-char (point-min))
3060 (unless (or (org-on-heading-p)
3061 (outline-next-heading))
3062 (throw 'nextfile t
))
3063 (goto-char (max (point-min) (1- (point))))
3064 (while (re-search-forward regexp nil t
)
3065 (org-back-to-heading t
)
3066 (skip-chars-forward "* ")
3067 (setq beg
(point-at-bol)
3069 end
(progn (outline-next-heading) (point)))
3073 (setq str
(buffer-substring-no-properties
3075 (if hdl-only
(point-at-eol) end
)))
3076 (mapc (lambda (wr) (when (string-match wr str
)
3077 (goto-char (1- end
))
3080 (mapc (lambda (wr) (unless (string-match wr str
)
3081 (goto-char (1- end
))
3084 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
3088 (setq marker
(org-agenda-new-marker (point))
3089 category
(org-get-category)
3090 tags
(org-get-tags-at (point))
3091 txt
(org-format-agenda-item
3093 (buffer-substring-no-properties
3094 beg1
(point-at-eol))
3096 (org-add-props txt props
3097 'org-marker marker
'org-hd-marker marker
3098 'org-todo-regexp org-todo-regexp
3099 'org-complex-heading-regexp org-complex-heading-regexp
3100 'priority
1000 'org-category category
3103 (goto-char (1- end
))))))))))
3104 (setq rtn
(nreverse ee
))
3105 (setq rtnall
(append rtnall rtn
)))
3106 (if org-agenda-overriding-header
3107 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3108 nil
'face
'org-agenda-structure
) "\n")
3109 (insert "Search words: ")
3110 (add-text-properties (point-min) (1- (point))
3111 (list 'face
'org-agenda-structure
))
3113 (insert string
"\n")
3114 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3116 (unless org-agenda-multi
3117 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3118 (add-text-properties pos
(1- (point))
3119 (list 'face
'org-agenda-structure
))))
3121 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3122 (goto-char (point-min))
3123 (or org-agenda-multi
(org-fit-agenda-window))
3124 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
3125 (org-finalize-agenda)
3126 (setq buffer-read-only t
)))
3128 ;;; Agenda TODO list
3130 (defvar org-select-this-todo-keyword nil
)
3131 (defvar org-last-arg nil
)
3134 (defun org-todo-list (arg)
3135 "Show all TODO entries from all agenda file in a single list.
3136 The prefix arg can be used to select a specific TODO keyword and limit
3137 the list to these. When using \\[universal-argument], you will be prompted
3138 for a keyword. A numeric prefix directly selects the Nth keyword in
3139 `org-todo-keywords-1'."
3142 (org-compile-prefix-format 'todo
)
3143 (org-set-sorting-strategy 'todo
)
3144 (org-prepare-agenda "TODO")
3145 (let* ((today (time-to-days (current-time)))
3146 (date (calendar-gregorian-from-absolute today
))
3147 (kwds org-todo-keywords-for-agenda
)
3148 (completion-ignore-case t
)
3149 (org-select-this-todo-keyword
3150 (if (stringp arg
) arg
3151 (and arg
(integerp arg
) (> arg
0)
3152 (nth (1- arg
) kwds
))))
3153 rtn rtnall files file pos
)
3154 (when (equal arg
'(4))
3155 (setq org-select-this-todo-keyword
3156 (org-ido-completing-read "Keyword (or KWD1|K2D2|...): "
3157 (mapcar 'list kwds
) nil nil
)))
3158 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
3159 (org-set-local 'org-last-arg arg
)
3160 (setq org-agenda-redo-command
3161 '(org-todo-list (or current-prefix-arg org-last-arg
)))
3162 (setq files
(org-agenda-files nil
'ifmode
)
3164 (while (setq file
(pop files
))
3166 (org-check-agenda-file file
)
3167 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
3168 (setq rtnall
(append rtnall rtn
))))
3169 (if org-agenda-overriding-header
3170 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3171 nil
'face
'org-agenda-structure
) "\n")
3172 (insert "Global list of TODO items of type: ")
3173 (add-text-properties (point-min) (1- (point))
3174 (list 'face
'org-agenda-structure
))
3176 (insert (or org-select-this-todo-keyword
"ALL") "\n")
3177 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3179 (unless org-agenda-multi
3180 (insert "Available with `N r': (0)ALL")
3183 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
3184 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
3189 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3191 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3192 (goto-char (point-min))
3193 (or org-agenda-multi
(org-fit-agenda-window))
3194 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
3195 (org-finalize-agenda)
3196 (setq buffer-read-only t
)))
3198 ;;; Agenda tags match
3201 (defun org-tags-view (&optional todo-only match
)
3202 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3203 The prefix arg TODO-ONLY limits the search to TODO entries."
3205 (org-compile-prefix-format 'tags
)
3206 (org-set-sorting-strategy 'tags
)
3207 (let* ((org-tags-match-list-sublevels
3208 ;?????? (if todo-only t org-tags-match-list-sublevels))
3209 org-tags-match-list-sublevels
)
3210 (completion-ignore-case t
)
3211 rtn rtnall files file pos matcher
3213 (setq matcher
(org-make-tags-matcher match
)
3214 match
(car matcher
) matcher
(cdr matcher
))
3215 (org-prepare-agenda (concat "TAGS " match
))
3216 (setq org-agenda-query-string match
)
3217 (setq org-agenda-redo-command
3218 (list 'org-tags-view
(list 'quote todo-only
)
3219 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
3220 (setq files
(org-agenda-files nil
'ifmode
)
3222 (while (setq file
(pop files
))
3224 (org-check-agenda-file file
)
3225 (setq buffer
(if (file-exists-p file
)
3226 (org-get-agenda-file-buffer file
)
3227 (error "No such file %s" file
)))
3229 ;; If file does not exist, error message to agenda
3231 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3232 rtnall
(append rtnall rtn
))
3233 (with-current-buffer buffer
3234 (unless (org-mode-p)
3235 (error "Agenda file %s is not in `org-mode'" file
))
3238 (if org-agenda-restrict
3239 (narrow-to-region org-agenda-restrict-begin
3240 org-agenda-restrict-end
)
3242 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
3243 (setq rtnall
(append rtnall rtn
))))))))
3244 (if org-agenda-overriding-header
3245 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3246 nil
'face
'org-agenda-structure
) "\n")
3247 (insert "Headlines with TAGS match: ")
3248 (add-text-properties (point-min) (1- (point))
3249 (list 'face
'org-agenda-structure
))
3252 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3254 (unless org-agenda-multi
3255 (insert "Press `C-u r' to search again with new search string\n"))
3256 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3258 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3259 (goto-char (point-min))
3260 (or org-agenda-multi
(org-fit-agenda-window))
3261 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
3262 (org-finalize-agenda)
3263 (setq buffer-read-only t
)))
3265 ;;; Agenda Finding stuck projects
3267 (defvar org-agenda-skip-regexp nil
3268 "Regular expression used in skipping subtrees for the agenda.
3269 This is basically a temporary global variable that can be set and then
3270 used by user-defined selections using `org-agenda-skip-function'.")
3272 (defvar org-agenda-overriding-header nil
3273 "When this is set during todo and tags searches, will replace header.
3274 This variable should not be set directly, but custom commands can bind it
3275 in the options section.")
3277 (defun org-agenda-skip-entry-when-regexp-matches ()
3278 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3279 If yes, it returns the end position of this entry, causing agenda commands
3280 to skip the entry but continuing the search in the subtree. This is a
3281 function that can be put into `org-agenda-skip-function' for the duration
3283 (let ((end (save-excursion (org-end-of-subtree t
)))
3286 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3289 (defun org-agenda-skip-subtree-when-regexp-matches ()
3290 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3291 If yes, it returns the end position of this tree, causing agenda commands
3292 to skip this subtree. This is a function that can be put into
3293 `org-agenda-skip-function' for the duration of a command."
3294 (let ((end (save-excursion (org-end-of-subtree t
)))
3297 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3300 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3301 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3302 If yes, it returns the end position of the current entry (NOT the tree),
3303 causing agenda commands to skip the entry but continuing the search in
3304 the subtree. This is a function that can be put into
3305 `org-agenda-skip-function' for the duration of a command. An important
3306 use of this function is for the stuck project list."
3307 (let ((end (save-excursion (org-end-of-subtree t
)))
3308 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3311 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3312 (and skip entry-end
)))
3314 (defun org-agenda-skip-entry-if (&rest conditions
)
3315 "Skip entry if any of CONDITIONS is true.
3316 See `org-agenda-skip-if' for details."
3317 (org-agenda-skip-if nil conditions
))
3319 (defun org-agenda-skip-subtree-if (&rest conditions
)
3320 "Skip entry if any of CONDITIONS is true.
3321 See `org-agenda-skip-if' for details."
3322 (org-agenda-skip-if t conditions
))
3324 (defun org-agenda-skip-if (subtree conditions
)
3325 "Checks current entity for CONDITIONS.
3326 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3327 the entry, i.e. the text before the next heading is checked.
3329 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3330 from different tests. Valid conditions are:
3332 scheduled Check if there is a scheduled cookie
3333 notscheduled Check if there is no scheduled cookie
3334 deadline Check if there is a deadline
3335 notdeadline Check if there is no deadline
3336 timestamp Check if there is a timestamp (also deadline or scheduled)
3337 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3338 regexp Check if regexp matches
3339 notregexp Check if regexp does not match.
3341 The regexp is taken from the conditions list, it must come right after
3342 the `regexp' or `notregexp' element.
3344 If any of these conditions is met, this function returns the end point of
3345 the entity, causing the search to continue from there. This is a function
3346 that can be put into `org-agenda-skip-function' for the duration of a command."
3348 (org-back-to-heading t
)
3351 (progn (org-end-of-subtree t
) (point))
3352 (progn (outline-next-heading) (1- (point)))))
3356 (and (memq 'scheduled conditions
)
3357 (re-search-forward org-scheduled-time-regexp end t
))
3358 (and (memq 'notscheduled conditions
)
3359 (not (re-search-forward org-scheduled-time-regexp end t
)))
3360 (and (memq 'deadline conditions
)
3361 (re-search-forward org-deadline-time-regexp end t
))
3362 (and (memq 'notdeadline conditions
)
3363 (not (re-search-forward org-deadline-time-regexp end t
)))
3364 (and (memq 'timestamp conditions
)
3365 (re-search-forward org-ts-regexp end t
))
3366 (and (memq 'nottimestamp conditions
)
3367 (not (re-search-forward org-ts-regexp end t
)))
3368 (and (setq m
(memq 'regexp conditions
))
3370 (re-search-forward (nth 1 m
) end t
))
3371 (and (setq m
(memq 'notregexp conditions
))
3373 (not (re-search-forward (nth 1 m
) end t
))))
3377 (defun org-agenda-list-stuck-projects (&rest ignore
)
3378 "Create agenda view for projects that are stuck.
3379 Stuck projects are project that have no next actions. For the definitions
3380 of what a project is and how to check if it stuck, customize the variable
3381 `org-stuck-projects'.
3382 MATCH is being ignored."
3384 (let* ((org-agenda-skip-function
3385 'org-agenda-skip-entry-when-regexp-matches-in-subtree
)
3386 ;; We could have used org-agenda-skip-if here.
3387 (org-agenda-overriding-header
3388 (or org-agenda-overriding-header
"List of stuck projects: "))
3389 (matcher (nth 0 org-stuck-projects
))
3390 (todo (nth 1 org-stuck-projects
))
3391 (todo-wds (if (member "*" todo
)
3393 (org-prepare-agenda-buffers (org-agenda-files
3396 org-done-keywords-for-agenda
3397 (copy-sequence org-todo-keywords-for-agenda
)))
3399 (todo-re (concat "^\\*+[ \t]+\\("
3400 (mapconcat 'identity todo-wds
"\\|")
3402 (tags (nth 2 org-stuck-projects
))
3403 (tags-re (if (member "*" tags
)
3404 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3406 (concat "^\\*+ .*:\\("
3407 (mapconcat 'identity tags
"\\|")
3408 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3409 (gen-re (nth 3 org-stuck-projects
))
3415 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
3417 (setq org-agenda-skip-regexp
3419 (mapconcat 'identity re-list
"\\|")
3420 (error "No information how to identify unstuck projects")))
3421 (org-tags-view nil matcher
)
3422 (with-current-buffer org-agenda-buffer-name
3423 (setq org-agenda-redo-command
3424 '(org-agenda-list-stuck-projects
3425 (or current-prefix-arg org-last-arg
))))))
3427 ;;; Diary integration
3429 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
3430 (defvar list-diary-entries-hook
)
3432 (defun org-get-entries-from-diary (date)
3433 "Get the (Emacs Calendar) diary entries for DATE."
3434 (require 'diary-lib
)
3435 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3436 (fancy-diary-buffer diary-fancy-buffer
)
3437 (diary-display-hook '(fancy-diary-display))
3438 (diary-display-function 'fancy-diary-display
)
3440 (list-diary-entries-hook
3441 (cons 'org-diary-default-entry list-diary-entries-hook
))
3442 (diary-file-name-prefix-function nil
) ; turn this feature off
3443 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
3445 (org-disable-agenda-to-diary t
))
3447 (save-window-excursion
3448 (funcall (if (fboundp 'diary-list-entries
)
3449 'diary-list-entries
'list-diary-entries
)
3451 (if (not (get-buffer diary-fancy-buffer
))
3453 (with-current-buffer diary-fancy-buffer
3454 (setq buffer-read-only nil
)
3455 (if (zerop (buffer-size))
3458 ;; Omit the date and other unnecessary stuff
3459 (org-agenda-cleanup-fancy-diary)
3460 ;; Add prefix to each line and extend the text properties
3461 (if (zerop (buffer-size))
3463 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
3464 (set-buffer-modified-p nil
)
3465 (kill-buffer diary-fancy-buffer
)))
3467 (setq entries
(org-split-string entries
"\n"))
3471 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
3472 ;; Extend the text properties to the beginning of the line
3473 (org-add-props x
(text-properties-at (1- (length x
)) x
)
3474 'type
"diary" 'date date
))
3477 (defvar org-agenda-cleanup-fancy-diary-hook nil
3478 "Hook run when the fancy diary buffer is cleaned up.")
3480 (defun org-agenda-cleanup-fancy-diary ()
3481 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3482 This gets rid of the date, the underline under the date, and
3483 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3484 date. It also removes lines that contain only whitespace."
3485 (goto-char (point-min))
3486 (if (looking-at ".*?:[ \t]*")
3489 (re-search-forward "\n=+$" nil t
)
3491 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
3492 (re-search-forward "\n=+$" nil t
)
3493 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3494 (goto-char (point-min))
3495 (while (re-search-forward "^ +\n" nil t
)
3497 (goto-char (point-min))
3498 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
3500 (run-hooks 'org-agenda-cleanup-fancy-diary-hook
))
3502 ;; Make sure entries from the diary have the right text properties.
3503 (eval-after-load "diary-lib"
3504 '(if (boundp 'diary-modify-entry-list-string-function
)
3505 ;; We can rely on the hook, nothing to do
3507 ;; Hook not available, must use advice to make this work
3508 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
3509 "Make the position visible."
3510 (if (and org-disable-agenda-to-diary
;; called from org-agenda
3513 (setq string
(org-modify-diary-entry-string string
))))))
3515 (defun org-modify-diary-entry-string (string)
3516 "Add text properties to string, allowing org-mode to act on it."
3517 (org-add-props string nil
3518 'mouse-face
'highlight
3519 'keymap org-agenda-keymap
3520 'help-echo
(if buffer-file-name
3521 (format "mouse-2 or RET jump to diary file %s"
3522 (abbreviate-file-name buffer-file-name
))
3524 'org-agenda-diary-link t
3525 'org-marker
(org-agenda-new-marker (point-at-bol))))
3527 (defun org-diary-default-entry ()
3528 "Add a dummy entry to the diary.
3529 Needed to avoid empty dates which mess up holiday display."
3530 ;; Catch the error if dealing with the new add-to-diary-alist
3531 (when org-disable-agenda-to-diary
3533 (org-add-to-diary-list original-date
"Org-mode dummy" "")
3535 (org-add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
3537 (defun org-add-to-diary-list (&rest args
)
3538 (if (fboundp 'diary-add-to-list
)
3539 (apply 'diary-add-to-list args
)
3540 (apply 'add-to-diary-list args
)))
3543 (defun org-diary (&rest args
)
3544 "Return diary information from org-files.
3545 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3546 It accesses org files and extracts information from those files to be
3547 listed in the diary. The function accepts arguments specifying what
3548 items should be listed. The following arguments are allowed:
3550 :timestamp List the headlines of items containing a date stamp or
3551 date range matching the selected date. Deadlines will
3552 also be listed, on the expiration day.
3554 :sexp List entries resulting from diary-like sexps.
3556 :deadline List any deadlines past due, or due within
3557 `org-deadline-warning-days'. The listing occurs only
3558 in the diary for *today*, not at any other date. If
3559 an entry is marked DONE, it is no longer listed.
3561 :scheduled List all items which are scheduled for the given date.
3562 The diary for *today* also contains items which were
3563 scheduled earlier and are not yet marked DONE.
3565 :todo List all TODO items from the org-file. This may be a
3566 long list - so this is not turned on by default.
3567 Like deadlines, these entries only show up in the
3568 diary for *today*, not at any other date.
3570 The call in the diary file should look like this:
3572 &%%(org-diary) ~/path/to/some/orgfile.org
3574 Use a separate line for each org file to check. Or, if you omit the file name,
3575 all files listed in `org-agenda-files' will be checked automatically:
3579 If you don't give any arguments (as in the example above), the default
3580 arguments (:deadline :scheduled :timestamp :sexp) are used.
3581 So the example above may also be written as
3583 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3585 The function expects the lisp variables `entry' and `date' to be provided
3586 by the caller, because this is how the calendar works. Don't use this
3587 function from a program - use `org-agenda-get-day-entries' instead."
3588 (when (> (- (time-to-seconds (current-time))
3589 org-agenda-last-marker-time
)
3591 (org-agenda-reset-markers))
3592 (org-compile-prefix-format 'agenda
)
3593 (org-set-sorting-strategy 'agenda
)
3594 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3595 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
3597 (org-agenda-files t
)))
3599 (org-prepare-agenda-buffers files
)
3600 ;; If this is called during org-agenda, don't return any entries to
3601 ;; the calendar. Org Agenda will list these entries itself.
3602 (if org-disable-agenda-to-diary
(setq files nil
))
3603 (while (setq file
(pop files
))
3604 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
3605 (setq results
(append results rtn
)))
3607 (concat (org-finalize-agenda-entries results
) "\n"))))
3609 ;;; Agenda entry finders
3611 (defun org-agenda-get-day-entries (file date
&rest args
)
3612 "Does the work for `org-diary' and `org-agenda'.
3613 FILE is the path to a file to be checked for entries. DATE is date like
3614 the one returned by `calendar-current-date'. ARGS are symbols indicating
3615 which kind of entries should be extracted. For details about these, see
3616 the documentation of `org-diary'."
3617 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3618 (let* ((org-startup-folded nil
)
3619 (org-startup-align-all-tables nil
)
3620 (buffer (if (file-exists-p file
)
3621 (org-get-agenda-file-buffer file
)
3622 (error "No such file %s" file
)))
3623 arg results rtn deadline-results
)
3625 ;; If file does not exist, make sure an error message ends up in diary
3626 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3627 (with-current-buffer buffer
3628 (unless (org-mode-p)
3629 (error "Agenda file %s is not in `org-mode'" file
))
3630 (let ((case-fold-search nil
))
3633 (if org-agenda-restrict
3634 (narrow-to-region org-agenda-restrict-begin
3635 org-agenda-restrict-end
)
3637 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3638 (while (setq arg
(pop args
))
3640 ((and (eq arg
:todo
)
3641 (equal date
(calendar-current-date)))
3642 (setq rtn
(org-agenda-get-todos))
3643 (setq results
(append results rtn
)))
3644 ((eq arg
:timestamp
)
3645 (setq rtn
(org-agenda-get-blocks))
3646 (setq results
(append results rtn
))
3647 (setq rtn
(org-agenda-get-timestamps))
3648 (setq results
(append results rtn
)))
3650 (setq rtn
(org-agenda-get-sexps))
3651 (setq results
(append results rtn
)))
3652 ((eq arg
:scheduled
)
3653 (setq rtn
(org-agenda-get-scheduled deadline-results
))
3654 (setq results
(append results rtn
)))
3656 (setq rtn
(org-agenda-get-progress))
3657 (setq results
(append results rtn
)))
3659 (setq rtn
(org-agenda-get-deadlines))
3660 (setq deadline-results
(copy-sequence rtn
))
3661 (setq results
(append results rtn
))))))))
3664 (defun org-agenda-get-todos ()
3665 "Return the TODO information for agenda display."
3666 (let* ((props (list 'face nil
3667 'done-face
'org-agenda-done
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 (regexp (concat "^\\*+[ \t]+\\("
3677 (if org-select-this-todo-keyword
3678 (if (equal org-select-this-todo-keyword
"*")
3681 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3683 org-not-done-regexp
)
3685 marker priority category tags todo-state
3687 (goto-char (point-min))
3688 (while (re-search-forward regexp nil t
)
3692 (setq beg
(point) end
(save-excursion (outline-next-heading) (point)))
3693 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end
)
3694 (goto-char (1+ beg
))
3695 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3699 (goto-char (match-beginning 1))
3700 (setq marker
(org-agenda-new-marker (match-beginning 0))
3701 category
(org-get-category)
3702 txt
(match-string 1)
3703 tags
(org-get-tags-at (point))
3704 txt
(org-format-agenda-item "" txt category tags
)
3705 priority
(1+ (org-get-priority txt
))
3706 todo-state
(org-get-todo-state))
3707 (org-add-props txt props
3708 'org-marker marker
'org-hd-marker marker
3709 'priority priority
'org-category category
3710 'type
"todo" 'todo-state todo-state
)
3712 (if org-agenda-todo-list-sublevels
3713 (goto-char (match-end 1))
3714 (org-end-of-subtree 'invisible
))))
3718 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end
)
3719 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3720 (when (or org-agenda-todo-ignore-with-date
3721 org-agenda-todo-ignore-scheduled
3722 org-agenda-todo-ignore-deadlines
)
3723 (setq end
(or end
(save-excursion (outline-next-heading) (point))))
3725 (or (and org-agenda-todo-ignore-with-date
3726 (re-search-forward org-ts-regexp end t
))
3727 (and org-agenda-todo-ignore-scheduled
3728 (re-search-forward org-scheduled-time-regexp end t
))
3729 (and org-agenda-todo-ignore-deadlines
3730 (re-search-forward org-deadline-time-regexp end t
)
3731 (org-deadline-close (match-string 1)))))))
3733 (defconst org-agenda-no-heading-message
3734 "No heading for this item in buffer or region.")
3736 (defun org-agenda-get-timestamps ()
3737 "Return the date stamp information for agenda display."
3738 (let* ((props (list 'face nil
3739 'org-not-done-regexp org-not-done-regexp
3740 'org-todo-regexp org-todo-regexp
3741 'org-complex-heading-regexp org-complex-heading-regexp
3742 'mouse-face
'highlight
3743 'keymap org-agenda-keymap
3745 (format "mouse-2 or RET jump to org file %s"
3746 (abbreviate-file-name buffer-file-name
))))
3747 (d1 (calendar-absolute-from-gregorian date
))
3753 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3757 (if org-agenda-include-inactive-timestamps
"[[<]" "<")
3761 (car org-time-stamp-formats
)
3762 (apply 'encode-time
; DATE bound by calendar
3763 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3765 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3766 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3767 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3768 donep tmp priority category ee txt timestr tags b0 b3 e3 head
3769 todo-state end-of-match
)
3770 (goto-char (point-min))
3771 (while (setq end-of-match
(re-search-forward regexp nil t
))
3772 (setq b0
(match-beginning 0)
3773 b3
(match-beginning 3) e3
(match-end 3))
3775 (and (org-at-date-range-p) (throw :skip nil
))
3777 (if (and (match-end 1)
3778 (not (= d1
(org-time-string-to-absolute
3779 (match-string 1) d1 nil
3780 org-agenda-repeating-timestamp-show-all
))))
3783 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3785 (setq tmp
(buffer-substring (max (point-min)
3786 (- b0 org-ds-keyword-length
))
3788 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3789 inactivep
(= (char-after b0
) ?\
[)
3790 deadlinep
(string-match org-deadline-regexp tmp
)
3791 scheduledp
(string-match org-scheduled-regexp tmp
)
3792 closedp
(and org-agenda-include-inactive-timestamps
3793 (string-match org-closed-string tmp
))
3794 clockp
(and org-agenda-include-inactive-timestamps
3795 (or (string-match org-clock-string tmp
)
3796 (string-match "]-+\\'" tmp
)))
3797 todo-state
(org-get-todo-state)
3798 donep
(member todo-state org-done-keywords
))
3799 (if (or scheduledp deadlinep closedp clockp
3800 (and donep org-agenda-skip-timestamp-if-done
))
3802 (if (string-match ">" timestr
)
3803 ;; substring should only run to end of time stamp
3804 (setq timestr
(substring timestr
0 (match-end 0))))
3805 (setq marker
(org-agenda-new-marker b0
)
3806 category
(org-get-category b0
))
3808 (if (not (re-search-backward "^\\*+ " nil t
))
3809 (setq txt org-agenda-no-heading-message
)
3810 (goto-char (match-beginning 0))
3811 (setq hdmarker
(org-agenda-new-marker)
3812 tags
(org-get-tags-at))
3813 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3814 (setq head
(match-string 1))
3815 (setq txt
(org-format-agenda-item
3816 (if inactivep
"[" nil
)
3817 head category tags timestr nil
3819 (setq priority
(org-get-priority txt
))
3820 (org-add-props txt props
3821 'org-marker marker
'org-hd-marker hdmarker
)
3822 (org-add-props txt nil
'priority priority
3823 'org-category category
'date date
3824 'todo-state todo-state
3827 (if org-agenda-skip-additional-timestamps-same-entry
3828 (outline-next-heading)
3829 (goto-char end-of-match
))))
3832 (defun org-agenda-get-sexps ()
3833 "Return the sexp information for agenda display."
3834 (require 'diary-lib
)
3835 (let* ((props (list 'face nil
3836 'mouse-face
'highlight
3837 'keymap org-agenda-keymap
3839 (format "mouse-2 or RET jump to org file %s"
3840 (abbreviate-file-name buffer-file-name
))))
3842 marker category ee txt tags entry result beg b sexp sexp-entry
3844 (goto-char (point-min))
3845 (while (re-search-forward regexp nil t
)
3848 (setq beg
(match-beginning 0))
3849 (goto-char (1- (match-end 0)))
3852 (setq sexp
(buffer-substring b
(point)))
3853 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3854 (org-trim (match-string 1))
3856 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3858 (setq marker
(org-agenda-new-marker beg
)
3859 category
(org-get-category beg
)
3860 todo-state
(org-get-todo-state))
3862 (if (string-match "\\S-" result
)
3864 (setq txt
"SEXP entry returned empty string"))
3866 (setq txt
(org-format-agenda-item
3867 "" txt category tags
'time
))
3868 (org-add-props txt props
'org-marker marker
)
3869 (org-add-props txt nil
3870 'org-category category
'date date
'todo-state todo-state
3875 (defalias 'org-get-closed
'org-agenda-get-progress
)
3876 (defun org-agenda-get-progress ()
3877 "Return the logged TODO entries for agenda display."
3878 (let* ((props (list 'mouse-face
'highlight
3879 'org-not-done-regexp org-not-done-regexp
3880 'org-todo-regexp org-todo-regexp
3881 'org-complex-heading-regexp org-complex-heading-regexp
3882 'keymap org-agenda-keymap
3884 (format "mouse-2 or RET jump to org file %s"
3885 (abbreviate-file-name buffer-file-name
))))
3886 (items (if (consp org-agenda-show-log
)
3888 org-agenda-log-mode-items
))
3892 (if (memq 'closed items
) (concat "\\<" org-closed-string
))
3893 (if (memq 'clock items
) (concat "\\<" org-clock-string
))
3894 (if (memq 'state items
) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
3895 (parts-re (if parts
(mapconcat 'identity parts
"\\|")
3896 (error "`org-agenda-log-mode-items' is empty")))
3898 "\\(" parts-re
"\\)"
3903 (car org-time-stamp-formats
)
3904 (apply 'encode-time
; DATE bound by calendar
3905 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3907 (org-agenda-search-headline-for-time nil
)
3908 marker hdmarker priority category tags closedp statep clockp state
3909 ee txt extra timestr rest clocked
)
3910 (goto-char (point-min))
3911 (while (re-search-forward regexp nil t
)
3914 (setq marker
(org-agenda-new-marker (match-beginning 0))
3915 closedp
(equal (match-string 1) org-closed-string
)
3916 statep
(equal (string-to-char (match-string 1)) ?-
)
3917 clockp
(not (or closedp statep
))
3918 state
(and statep
(match-string 2))
3919 category
(org-get-category (match-beginning 0))
3920 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3922 (when (string-match "\\]" timestr
)
3923 ;; substring should only run to end of time stamp
3924 (setq rest
(substring timestr
(match-end 0))
3925 timestr
(substring timestr
0 (match-end 0)))
3926 (if (and (not closedp
) (not statep
)
3927 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest
))
3928 (progn (setq timestr
(concat (substring timestr
0 -
1)
3929 "-" (match-string 1 rest
) "]"))
3930 (setq clocked
(match-string 2 rest
)))
3931 (setq clocked
"-")))
3934 ((not org-agenda-log-mode-add-notes
) (setq extra nil
))
3936 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
3937 (setq extra
(match-string 1))))
3939 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
3940 (setq extra
(match-string 1))))
3941 (t (setq extra nil
)))
3942 (if (not (re-search-backward "^\\*+ " nil t
))
3943 (setq txt org-agenda-no-heading-message
)
3944 (goto-char (match-beginning 0))
3945 (setq hdmarker
(org-agenda-new-marker)
3946 tags
(org-get-tags-at))
3947 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3948 (setq txt
(match-string 1))
3950 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt
)
3951 (setq txt
(concat (substring txt
0 (match-beginning 1))
3952 " - " extra
" " (match-string 2 txt
)))
3953 (setq txt
(concat txt
" - " extra
))))
3954 (setq txt
(org-format-agenda-item
3956 (closedp "Closed: ")
3957 (statep (concat "State: (" state
")"))
3958 (t (concat "Clocked: (" clocked
")")))
3959 txt category tags timestr
)))
3960 (setq priority
100000)
3961 (org-add-props txt props
3962 'org-marker marker
'org-hd-marker hdmarker
'face
'org-agenda-done
3963 'priority priority
'org-category category
3964 'type
"closed" 'date date
3965 'undone-face
'org-warning
'done-face
'org-agenda-done
)
3967 (goto-char (point-at-eol))))
3970 (defun org-agenda-get-deadlines ()
3971 "Return the deadline information for agenda display."
3972 (let* ((props (list 'mouse-face
'highlight
3973 'org-not-done-regexp org-not-done-regexp
3974 'org-todo-regexp org-todo-regexp
3975 'org-complex-heading-regexp org-complex-heading-regexp
3976 'keymap org-agenda-keymap
3978 (format "mouse-2 or RET jump to org file %s"
3979 (abbreviate-file-name buffer-file-name
))))
3980 (regexp org-deadline-time-regexp
)
3981 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3982 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3983 d2 diff dfrac wdays pos pos1 category tags
3984 ee txt head face s todo-state upcomingp donep timestr
)
3985 (goto-char (point-min))
3986 (while (re-search-forward regexp nil t
)
3989 (setq s
(match-string 1)
3991 pos
(1- (match-beginning 1))
3992 d2
(org-time-string-to-absolute
3993 (match-string 1) d1
'past
3994 org-agenda-repeating-timestamp-show-all
)
3996 wdays
(org-get-wdays s
)
3997 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3998 upcomingp
(and todayp
(> diff
0)))
3999 ;; When to show a deadline in the calendar:
4000 ;; If the expiration is within wdays warning time.
4001 ;; Past-due deadlines are only shown on the current date
4002 (if (or (and (<= diff wdays
)
4003 (and todayp
(not org-agenda-only-exact-dates
)))
4006 (setq todo-state
(org-get-todo-state))
4007 (setq donep
(member todo-state org-done-keywords
))
4009 (or org-agenda-skip-deadline-if-done
4012 (setq category
(org-get-category))
4013 (if (not (re-search-backward "^\\*+[ \t]+" nil t
))
4014 (setq txt org-agenda-no-heading-message
)
4015 (goto-char (match-end 0))
4016 (setq pos1
(match-beginning 0))
4017 (setq tags
(org-get-tags-at pos1
))
4018 (setq head
(buffer-substring-no-properties
4020 (progn (skip-chars-forward "^\r\n")
4022 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
4024 (concat (substring s
(match-beginning 1)) " "))
4025 (setq timestr
'time
))
4026 (setq txt
(org-format-agenda-item
4028 (car org-agenda-deadline-leaders
)
4030 (nth 1 org-agenda-deadline-leaders
))
4032 (nth 1 org-agenda-deadline-leaders
)
4034 (format (nth 1 org-agenda-deadline-leaders
)
4037 (if (not (= diff
0)) nil timestr
)))))
4039 (setq face
(org-agenda-deadline-face dfrac wdays
))
4040 (org-add-props txt props
4041 'org-marker
(org-agenda-new-marker pos
)
4042 'org-hd-marker
(org-agenda-new-marker pos1
)
4043 'priority
(+ (- diff
)
4044 (org-get-priority txt
))
4045 'org-category category
4046 'todo-state todo-state
4047 'type
(if upcomingp
"upcoming-deadline" "deadline")
4048 'date
(if upcomingp date d2
)
4049 'face
(if donep
'org-agenda-done face
)
4050 'undone-face face
'done-face
'org-agenda-done
)
4054 (defun org-agenda-deadline-face (fraction &optional wdays
)
4055 "Return the face to displaying a deadline item.
4056 FRACTION is what fraction of the head-warning time has passed."
4057 (if (equal wdays
0) (setq fraction
1.
))
4058 (let ((faces org-agenda-deadline-faces
) f
)
4060 (while (setq f
(pop faces
))
4061 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
4063 (defun org-agenda-get-scheduled (&optional deadline-results
)
4064 "Return the scheduled information for agenda display."
4065 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4066 'org-todo-regexp org-todo-regexp
4067 'org-complex-heading-regexp org-complex-heading-regexp
4068 'done-face
'org-agenda-done
4069 'mouse-face
'highlight
4070 'keymap org-agenda-keymap
4072 (format "mouse-2 or RET jump to org file %s"
4073 (abbreviate-file-name buffer-file-name
))))
4074 (regexp org-scheduled-time-regexp
)
4075 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
4076 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
4078 (deadline-position-alist
4079 (mapcar (lambda (a) (and (setq mm
(get-text-property
4080 0 'org-hd-marker a
))
4081 (cons (marker-position mm
) a
)))
4083 d2 diff pos pos1 category tags donep
4084 ee txt head pastschedp todo-state face timestr s
)
4085 (goto-char (point-min))
4086 (while (re-search-forward regexp nil t
)
4089 (setq s
(match-string 1)
4091 pos
(1- (match-beginning 1))
4092 d2
(org-time-string-to-absolute
4093 (match-string 1) d1
'past
4094 org-agenda-repeating-timestamp-show-all
)
4096 (setq pastschedp
(and todayp
(< diff
0)))
4097 ;; When to show a scheduled item in the calendar:
4098 ;; If it is on or past the date.
4099 (if (or (and (< diff
0)
4100 (< (abs diff
) org-scheduled-past-days
)
4101 (and todayp
(not org-agenda-only-exact-dates
)))
4104 (setq todo-state
(org-get-todo-state))
4105 (setq donep
(member todo-state org-done-keywords
))
4107 (or org-agenda-skip-scheduled-if-done
4110 (setq category
(org-get-category))
4111 (if (not (re-search-backward "^\\*+[ \t]+" nil t
))
4112 (setq txt org-agenda-no-heading-message
)
4113 (goto-char (match-end 0))
4114 (setq pos1
(match-beginning 0))
4116 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown
)
4117 (and org-agenda-skip-scheduled-if-deadline-is-shown
4119 (setq mm
(assoc pos1 deadline-position-alist
)))
4121 (setq tags
(org-get-tags-at))
4122 (setq head
(buffer-substring-no-properties
4124 (progn (skip-chars-forward "^\r\n") (point))))
4125 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
4127 (concat (substring s
(match-beginning 1)) " "))
4128 (setq timestr
'time
))
4129 (setq txt
(org-format-agenda-item
4131 (car org-agenda-scheduled-leaders
)
4132 (format (nth 1 org-agenda-scheduled-leaders
)
4135 (if (not (= diff
0)) nil timestr
)))))
4139 (pastschedp 'org-scheduled-previously
)
4140 (todayp 'org-scheduled-today
)
4141 (t 'org-scheduled
)))
4142 (org-add-props txt props
4144 'face
(if donep
'org-agenda-done face
)
4145 'org-marker
(org-agenda-new-marker pos
)
4146 'org-hd-marker
(org-agenda-new-marker pos1
)
4147 'type
(if pastschedp
"past-scheduled" "scheduled")
4148 'date
(if pastschedp d2 date
)
4149 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
4150 'org-category category
4151 'todo-state todo-state
)
4155 (defun org-agenda-get-blocks ()
4156 "Return the date-range information for agenda display."
4157 (let* ((props (list 'face nil
4158 'org-not-done-regexp org-not-done-regexp
4159 'org-todo-regexp org-todo-regexp
4160 'org-complex-heading-regexp org-complex-heading-regexp
4161 'mouse-face
'highlight
4162 'keymap org-agenda-keymap
4164 (format "mouse-2 or RET jump to org file %s"
4165 (abbreviate-file-name buffer-file-name
))))
4166 (regexp org-tr-regexp
)
4167 (d0 (calendar-absolute-from-gregorian date
))
4168 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4170 (goto-char (point-min))
4171 (while (re-search-forward regexp nil t
)
4175 (setq timestr
(match-string 0)
4178 d1
(time-to-days (org-time-string-to-time s1
))
4179 d2
(time-to-days (org-time-string-to-time s2
)))
4180 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
4181 ;; Only allow days between the limits, because the normal
4182 ;; date stamps will catch the limits.
4184 (setq todo-state
(org-get-todo-state))
4185 (setq donep
(member todo-state org-done-keywords
))
4186 (if (and donep org-agenda-skip-timestamp-if-done
)
4188 (setq marker
(org-agenda-new-marker (point)))
4189 (setq category
(org-get-category))
4190 (if (not (re-search-backward "^\\*+ " nil t
))
4191 (setq txt org-agenda-no-heading-message
)
4192 (goto-char (match-beginning 0))
4193 (setq hdmarker
(org-agenda-new-marker (point)))
4194 (setq tags
(org-get-tags-at))
4195 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4196 (setq head
(match-string 1))
4197 (setq txt
(org-format-agenda-item
4199 (nth (if (= d1 d2
) 0 1)
4200 org-agenda-timerange-leaders
)
4201 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
4203 (if (= d0 d1
) timestr
))))
4204 (org-add-props txt props
4205 'org-marker marker
'org-hd-marker hdmarker
4206 'type
"block" 'date date
4207 'todo-state todo-state
4208 'priority
(org-get-priority txt
) 'org-category category
)
4211 ;; Sort the entries by expiration date.
4214 ;;; Agenda presentation and sorting
4216 (defvar org-prefix-has-time nil
4217 "A flag, set by `org-compile-prefix-format'.
4218 The flag is set if the currently compiled format contains a `%t'.")
4219 (defvar org-prefix-has-tag nil
4220 "A flag, set by `org-compile-prefix-format'.
4221 The flag is set if the currently compiled format contains a `%T'.")
4222 (defvar org-prefix-has-effort nil
4223 "A flag, set by `org-compile-prefix-format'.
4224 The flag is set if the currently compiled format contains a `%e'.")
4226 (defun org-format-agenda-item (extra txt
&optional category tags dotime
4228 "Format TXT to be inserted into the agenda buffer.
4229 In particular, it adds the prefix and corresponding text properties. EXTRA
4230 must be a string and replaces the `%s' specifier in the prefix format.
4231 CATEGORY (string, symbol or nil) may be used to overrule the default
4232 category taken from local variable or file name. It will replace the `%c'
4233 specifier in the format. DOTIME, when non-nil, indicates that a
4234 time-of-day should be extracted from TXT for sorting of this entry, and for
4235 the `%t' specifier in the format. When DOTIME is a string, this string is
4236 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4237 only the correctly processes TXT should be returned - this is used by
4238 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4239 Any match of REMOVE-RE will be removed from TXT."
4241 ;; Diary entries sometimes have extra whitespace at the beginning
4242 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
4243 (when org-agenda-show-inherited-tags
4244 ;; Fix the tags part in txt
4245 (setq txt
(org-agenda-add-inherited-tags txt tags
)))
4246 (let* ((category (or category
4248 (if buffer-file-name
4249 (file-name-sans-extension
4250 (file-name-nondirectory buffer-file-name
))
4252 ;; time, tag, effort are needed for the eval of the prefix format
4253 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
4255 (ts (if dotime
(concat
4256 (if (stringp dotime
) dotime
"")
4257 (and org-agenda-search-headline-for-time txt
))))
4258 (time-of-day (and dotime
(org-get-time-of-day ts
)))
4259 stamp plain s0 s1 s2 t1 t2 rtn srp
4261 (and (org-mode-p) buffer-file-name
4262 (add-to-list 'org-agenda-contributing-files buffer-file-name
))
4263 (when (and dotime time-of-day
)
4264 ;; Extract starting and ending time and move them to prefix
4265 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
4266 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
4267 (setq s0
(match-string 0 ts
)
4268 srp
(and stamp
(match-end 3))
4269 s1
(match-string (if plain
1 2) ts
)
4270 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
4272 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4273 ;; them, we might want to remove them there to avoid duplication.
4274 ;; The user can turn this off with a variable.
4275 (if (and org-prefix-has-time
4276 org-agenda-remove-times-when-in-prefix
(or stamp plain
)
4277 (string-match (concat (regexp-quote s0
) " *") txt
)
4278 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
4279 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
4280 (= (match-beginning 0) 0)
4282 (setq txt
(replace-match "" nil nil txt
))))
4283 ;; Normalize the time(s) to 24 hour
4284 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
4285 (if s2
(setq s2
(org-get-time-of-day s2
'string t
)))
4286 ;; Compute the duration
4288 (setq t1
(+ (* 60 (string-to-number (substring s1
0 2)))
4289 (string-to-number (substring s1
3)))
4291 (s2 (+ (* 60 (string-to-number (substring s2
0 2)))
4292 (string-to-number (substring s2
3))))
4293 (org-agenda-default-appointment-duration
4294 (+ t1 org-agenda-default-appointment-duration
))
4296 (setq duration
(if t2
(- t2 t1
)))))
4298 (when (and s1
(not s2
) org-agenda-default-appointment-duration
4299 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
4300 (let ((m (+ (string-to-number (match-string 2 s1
))
4301 (* 60 (string-to-number (match-string 1 s1
)))
4302 org-agenda-default-appointment-duration
))
4304 (setq h
(/ m
60) m
(- m
(* h
60)))
4305 (setq s2
(format "%02d:%02d" h m
))))
4307 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4309 ;; Tags are in the string
4310 (if (or (eq org-agenda-remove-tags t
)
4311 (and org-agenda-remove-tags
4312 org-prefix-has-tag
))
4313 (setq txt
(replace-match "" t t txt
))
4314 (setq txt
(replace-match
4315 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
4316 (match-string 2 txt
))
4322 (or (get-text-property 0 'org-hd-marker txt
)
4323 (get-text-property 0 'org-marker txt
)))
4326 (setq neffort
(org-hh:mm-string-to-minutes effort
)
4327 effort
(setq effort
(concat "[" effort
"]" )))))
4330 (while (string-match remove-re txt
)
4331 (setq txt
(replace-match "" t t txt
))))
4333 ;; Create the final string
4336 ;; Prepare the variables needed in the eval of the compiled format
4337 (setq time
(cond (s2 (concat s1
"-" s2
))
4338 (s1 (concat s1
"......"))
4341 category
(if (symbolp category
) (symbol-name category
) category
))
4342 ;; Evaluate the compiled format
4343 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
4345 ;; And finally add the text properties
4346 (remove-text-properties 0 (length rtn
) '(line-prefix t wrap-prefix t
) rtn
)
4347 (org-add-props rtn nil
4348 'org-category
(downcase category
)
4349 'tags
(mapcar 'org-downcase-keep-props tags
)
4350 'org-highest-priority org-highest-priority
4351 'org-lowest-priority org-lowest-priority
4352 'prefix-length
(- (length rtn
) (length txt
))
4353 'time-of-day time-of-day
4356 'effort-minutes neffort
4362 (defun org-agenda-add-inherited-tags (txt tags
)
4363 "Remove tags string from TXT, and add complete list of tags.
4364 The new list includes inherited tags. If any inherited tags are present,
4365 a double colon separates inherited tags from local tags."
4366 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt
)
4367 (setq txt
(substring txt
0 (match-beginning 0))))
4369 (let ((have-i (get-text-property 0 'inherited
(car tags
)))
4371 (setq txt
(concat txt
" :"
4374 (setq i
(get-text-property 0 'inherited x
))
4375 (if (and have-i
(not i
))
4381 (if have-i
"::" ":")))))
4384 (defun org-downcase-keep-props (s)
4385 (let ((props (text-properties-at 0 s
)))
4386 (setq s
(downcase s
))
4387 (add-text-properties 0 (length s
) props s
)
4390 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
4391 (defvar org-agenda-sorting-strategy-selected nil
)
4393 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
4395 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
4396 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
4397 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
4398 ((member 'weekly
(car org-agenda-time-grid
)))
4399 (t (throw 'exit list
)))
4400 (let* ((have (delq nil
(mapcar
4401 (lambda (x) (get-text-property 1 'time-of-day x
))
4403 (string (nth 1 org-agenda-time-grid
))
4404 (gridtimes (nth 2 org-agenda-time-grid
))
4405 (req (car org-agenda-time-grid
))
4406 (remove (member 'remove-match req
))
4408 (if (and (member 'require-timed req
) (not have
))
4409 ;; don't show empty grid
4411 (while (setq time
(pop gridtimes
))
4412 (unless (and remove
(member time have
))
4413 (setq time
(int-to-string time
))
4414 (push (org-format-agenda-item
4416 (concat (substring time
0 -
2) ":" (substring time -
2)))
4419 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
4420 (if (member 'time-up org-agenda-sorting-strategy-selected
)
4422 (append list new
)))))
4424 (defun org-compile-prefix-format (key)
4425 "Compile the prefix format into a Lisp form that can be evaluated.
4426 The resulting form is returned and stored in the variable
4427 `org-prefix-format-compiled'."
4428 (setq org-prefix-has-time nil org-prefix-has-tag nil
4429 org-prefix-has-effort nil
)
4431 ((stringp org-agenda-prefix-format
)
4432 org-agenda-prefix-format
)
4433 ((assq key org-agenda-prefix-format
)
4434 (cdr (assq key org-agenda-prefix-format
)))
4435 (t " %-12:c%?-12t% s")))
4437 varform vars var e c f opt
)
4438 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4440 (setq var
(cdr (assoc (match-string 4 s
)
4441 '(("c" . category
) ("t" . time
) ("s" . extra
)
4442 ("T" . tag
) ("e" . effort
))))
4443 c
(or (match-string 3 s
) "")
4444 opt
(match-beginning 1)
4445 start
(1+ (match-beginning 0)))
4446 (if (equal var
'time
) (setq org-prefix-has-time t
))
4447 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
4448 (if (equal var
'effort
) (setq org-prefix-has-effort t
))
4449 (setq f
(concat "%" (match-string 2 s
) "s"))
4452 `(if (equal "" ,var
)
4454 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
4455 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
4456 (setq s
(replace-match "%s" t nil s
))
4457 (push varform vars
))
4458 (setq vars
(nreverse vars
))
4459 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
4461 (defun org-set-sorting-strategy (key)
4462 (if (symbolp (car org-agenda-sorting-strategy
))
4464 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
4465 (setq org-agenda-sorting-strategy-selected
4466 (or (cdr (assq key org-agenda-sorting-strategy
))
4467 (cdr (assq 'agenda org-agenda-sorting-strategy
))
4468 '(time-up category-keep priority-down
)))))
4470 (defun org-get-time-of-day (s &optional string mod24
)
4471 "Check string S for a time of day.
4472 If found, return it as a military time number between 0 and 2400.
4473 If not found, return nil.
4474 The optional STRING argument forces conversion into a 5 character wide string
4478 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
4479 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
4480 (let* ((h (string-to-number (match-string 1 s
)))
4481 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
4482 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
4483 (am-p (equal ampm
"am"))
4484 (h1 (cond ((not ampm
) h
)
4485 ((= h
12) (if am-p
0 12))
4486 (t (+ h
(if am-p
0 12)))))
4487 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
4489 (t0 (+ (* 100 h2
) m
))
4490 (t1 (concat (if (>= h1
24) "+" " ")
4491 (if (< t0
100) "0" "")
4492 (if (< t0
10) "0" "")
4493 (int-to-string t0
))))
4494 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
4496 (defun org-finalize-agenda-entries (list &optional nosort
)
4497 "Sort and concatenate the agenda items."
4498 (setq list
(mapcar 'org-agenda-highlight-todo list
))
4501 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
4503 (defun org-agenda-highlight-todo (x)
4504 (let ((org-done-keywords org-done-keywords-for-agenda
)
4508 (beginning-of-line 1)
4509 (setq re
(get-text-property (point) 'org-todo-regexp
))
4510 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
4511 (when (looking-at (concat "[ \t]*\\.*\\(" re
"\\) +"))
4512 (add-text-properties (match-beginning 0) (match-end 1)
4513 (list 'face
(org-get-todo-face 1)))
4514 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4515 (delete-region (match-beginning 1) (1- (match-end 0)))
4516 (goto-char (match-beginning 1))
4517 (insert (format org-agenda-todo-keyword-format s
)))))
4518 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
4519 pl
(get-text-property 0 'prefix-length x
))
4521 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
4523 (add-text-properties
4524 (or (match-end 1) (match-end 0)) (match-end 0)
4525 (list 'face
(org-get-todo-face (match-string 2 x
)))
4527 (setq x
(concat (substring x
0 (match-end 1))
4528 (format org-agenda-todo-keyword-format
4531 (substring x
(match-end 3)))))
4534 (defsubst org-cmp-priority
(a b
)
4535 "Compare the priorities of string A and B."
4536 (let ((pa (or (get-text-property 1 'priority a
) 0))
4537 (pb (or (get-text-property 1 'priority b
) 0)))
4538 (cond ((> pa pb
) +1)
4542 (defsubst org-cmp-effort
(a b
)
4543 "Compare the priorities of string A and B."
4544 (let* ((def (if org-sort-agenda-noeffort-is-high
32767 -
1))
4545 (ea (or (get-text-property 1 'effort-minutes a
) def
))
4546 (eb (or (get-text-property 1 'effort-minutes b
) def
)))
4547 (cond ((> ea eb
) +1)
4551 (defsubst org-cmp-category
(a b
)
4552 "Compare the string values of categories of strings A and B."
4553 (let ((ca (or (get-text-property 1 'org-category a
) ""))
4554 (cb (or (get-text-property 1 'org-category b
) "")))
4555 (cond ((string-lessp ca cb
) -
1)
4556 ((string-lessp cb ca
) +1)
4559 (defsubst org-cmp-todo-state
(a b
)
4560 "Compare the todo states of strings A and B."
4561 (let* ((ma (or (get-text-property 1 'org-marker a
)
4562 (get-text-property 1 'org-hd-marker a
)))
4563 (mb (or (get-text-property 1 'org-marker b
)
4564 (get-text-property 1 'org-hd-marker b
)))
4565 (fa (and ma
(marker-buffer ma
)))
4566 (fb (and mb
(marker-buffer mb
)))
4568 (or (and fa
(with-current-buffer fa org-todo-keywords-1
))
4569 (and fb
(with-current-buffer fb org-todo-keywords-1
))))
4570 (ta (or (get-text-property 1 'todo-state a
) ""))
4571 (tb (or (get-text-property 1 'todo-state b
) ""))
4572 (la (- (length (member ta todo-kwds
))))
4573 (lb (- (length (member tb todo-kwds
))))
4574 (donepa (member ta org-done-keywords-for-agenda
))
4575 (donepb (member tb org-done-keywords-for-agenda
)))
4576 (cond ((and donepa
(not donepb
)) -
1)
4577 ((and (not donepa
) donepb
) +1)
4582 (defsubst org-cmp-tag
(a b
)
4583 "Compare the string values of the first tags of A and B."
4584 (let ((ta (car (last (get-text-property 1 'tags a
))))
4585 (tb (car (last (get-text-property 1 'tags b
)))))
4588 ((string-lessp ta tb
) -
1)
4589 ((string-lessp tb ta
) +1)
4592 (defsubst org-cmp-time
(a b
)
4593 "Compare the time-of-day values of strings A and B."
4594 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
4595 (ta (or (get-text-property 1 'time-of-day a
) def
))
4596 (tb (or (get-text-property 1 'time-of-day b
) def
)))
4597 (cond ((< ta tb
) -
1)
4601 (defun org-entries-lessp (a b
)
4602 "Predicate for sorting agenda entries."
4603 ;; The following variables will be used when the form is evaluated.
4604 ;; So even though the compiler complains, keep them.
4605 (let* ((time-up (org-cmp-time a b
))
4606 (time-down (if time-up
(- time-up
) nil
))
4607 (priority-up (org-cmp-priority a b
))
4608 (priority-down (if priority-up
(- priority-up
) nil
))
4609 (effort-up (org-cmp-effort a b
))
4610 (effort-down (if effort-up
(- effort-up
) nil
))
4611 (category-up (org-cmp-category a b
))
4612 (category-down (if category-up
(- category-up
) nil
))
4613 (category-keep (if category-up
+1 nil
))
4614 (tag-up (org-cmp-tag a b
))
4615 (tag-down (if tag-up
(- tag-up
) nil
))
4616 (todo-state-up (org-cmp-todo-state a b
))
4617 (todo-state-down (if todo-state-up
(- todo-state-up
) nil
))
4618 user-defined-up user-defined-down
)
4619 (if (and org-agenda-cmp-user-defined
4620 (functionp org-agenda-cmp-user-defined
))
4621 (setq user-defined-up
4622 (funcall org-agenda-cmp-user-defined a b
)
4623 user-defined-down
(if user-defined-up
(- user-defined-up
) nil
)))
4625 (eval (cons 'or org-agenda-sorting-strategy-selected
))
4626 '((-1 . t
) (1 . nil
) (nil . nil
))))))
4628 ;;; Agenda restriction lock
4630 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
4631 "Overlay to mark the headline to which arenda commands are restricted.")
4632 (org-overlay-put org-agenda-restriction-lock-overlay
4633 'face
'org-agenda-restriction-lock
)
4634 (org-overlay-put org-agenda-restriction-lock-overlay
4635 'help-echo
"Agendas are currently limited to this subtree.")
4636 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4638 (defun org-agenda-set-restriction-lock (&optional type
)
4639 "Set restriction lock for agenda, to current subtree or file.
4640 Restriction will be the file if TYPE is `file', or if type is the
4641 universal prefix '(4), or if the cursor is before the first headline
4642 in the file. Otherwise, restriction will be to the current subtree."
4644 (and (equal type
'(4)) (setq type
'file
))
4647 ((org-at-heading-p) 'subtree
)
4648 ((condition-case nil
(org-back-to-heading t
) (error nil
))
4651 (if (eq type
'subtree
)
4653 (setq org-agenda-restrict t
)
4654 (setq org-agenda-overriding-restriction
'subtree
)
4655 (put 'org-agenda-files
'org-restrict
4656 (list (buffer-file-name (buffer-base-buffer))))
4657 (org-back-to-heading t
)
4658 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
4659 (move-marker org-agenda-restrict-begin
(point))
4660 (move-marker org-agenda-restrict-end
4661 (save-excursion (org-end-of-subtree t
)))
4662 (message "Locking agenda restriction to subtree"))
4663 (put 'org-agenda-files
'org-restrict
4664 (list (buffer-file-name (buffer-base-buffer))))
4665 (setq org-agenda-restrict nil
)
4666 (setq org-agenda-overriding-restriction
'file
)
4667 (move-marker org-agenda-restrict-begin nil
)
4668 (move-marker org-agenda-restrict-end nil
)
4669 (message "Locking agenda restriction to file"))
4670 (setq current-prefix-arg nil
)
4671 (org-agenda-maybe-redo))
4673 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
4674 "Remove the agenda restriction lock."
4676 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4677 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
4678 (setq org-agenda-overriding-restriction nil
)
4679 (setq org-agenda-restrict nil
)
4680 (put 'org-agenda-files
'org-restrict nil
)
4681 (move-marker org-agenda-restrict-begin nil
)
4682 (move-marker org-agenda-restrict-end nil
)
4683 (setq current-prefix-arg nil
)
4684 (message "Agenda restriction lock removed")
4685 (or noupdate
(org-agenda-maybe-redo)))
4687 (defun org-agenda-maybe-redo ()
4688 "If there is any window showing the agenda view, update it."
4689 (let ((w (get-buffer-window org-agenda-buffer-name t
))
4690 (w0 (selected-window)))
4695 (if org-agenda-overriding-restriction
4696 (message "Agenda view shifted to new %s restriction"
4697 org-agenda-overriding-restriction
)
4698 (message "Agenda restriction lock removed")))))
4702 (defun org-agenda-check-type (error &rest types
)
4703 "Check if agenda buffer is of allowed type.
4704 If ERROR is non-nil, throw an error, otherwise just return nil."
4705 (if (memq org-agenda-type types
)
4708 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
4711 (defun org-agenda-quit ()
4712 "Exit agenda by removing the window or the buffer."
4714 (if org-agenda-columns-active
4716 (let ((buf (current-buffer)))
4717 (and (not (eq org-agenda-window-setup
'current-window
))
4718 (not (one-window-p))
4721 (org-agenda-reset-markers)
4722 (org-columns-remove-overlays)
4723 (setq org-agenda-archives-mode nil
))
4724 ;; Maybe restore the pre-agenda window configuration.
4725 (and org-agenda-restore-windows-after-quit
4726 (not (eq org-agenda-window-setup
'other-frame
))
4727 org-pre-agenda-window-conf
4728 (set-window-configuration org-pre-agenda-window-conf
))))
4730 (defun org-agenda-exit ()
4731 "Exit agenda by removing the window or the buffer.
4732 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
4733 Org-mode buffers visited directly by the user will not be touched."
4735 (org-release-buffers org-agenda-new-buffers
)
4736 (setq org-agenda-new-buffers nil
)
4739 (defun org-agenda-execute (arg)
4740 "Execute another agenda command, keeping same window.\\<global-map>
4741 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
4743 (let ((org-agenda-window-setup 'current-window
))
4746 (defun org-agenda-redo ()
4748 When this is the global TODO list, a prefix argument will be interpreted."
4750 (let* ((org-agenda-keep-modes t
)
4751 (filter org-agenda-filter
)
4752 (preset (get 'org-agenda-filter
:preset-filter
))
4753 (cols org-agenda-columns-active
)
4754 (line (org-current-line))
4755 (window-line (- line
(org-current-line (window-start))))
4756 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
4757 (put 'org-agenda-filter
:preset-filter nil
)
4758 (and cols
(org-columns-quit))
4759 (message "Rebuilding agenda buffer...")
4760 (org-let lprops
'(eval org-agenda-redo-command
))
4761 (setq org-agenda-undo-list nil
4762 org-agenda-pending-undo-list nil
)
4763 (message "Rebuilding agenda buffer...done")
4764 (put 'org-agenda-filter
:preset-filter preset
)
4765 (and (or filter preset
) (org-agenda-filter-apply filter
))
4766 (and cols
(interactive-p) (org-agenda-columns))
4768 (recenter window-line
)))
4771 (defvar org-global-tags-completion-table nil
)
4772 (defvar org-agenda-filter-form nil
)
4773 (defun org-agenda-filter-by-tag (strip &optional char narrow
)
4774 "Keep only those lines in the agenda buffer that have a specific tag.
4775 The tag is selected with its fast selection letter, as configured.
4776 With prefix argument STRIP, remove all lines that do have the tag.
4777 A lisp caller can specify CHAR. NARROW means that the new tag should be
4778 used to narrow the search - the interactive user can also press `-' or `+'
4779 to switch to narrowing."
4781 (let* ((alist org-tag-alist-for-agenda
)
4782 (tag-chars (mapconcat
4783 (lambda (x) (if (cdr x
) (char-to-string (cdr x
)) ""))
4785 (efforts (org-split-string
4786 (or (cdr (assoc (concat org-effort-property
"_ALL")
4787 org-global-properties
))
4788 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
4789 (effort-op org-agenda-filter-effort-default-operator
)
4791 (inhibit-read-only t
)
4792 (current org-agenda-filter
)
4796 "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
4797 (if narrow
"Narrow" "Filter") tag-chars
)
4798 (setq char
(read-char)))
4799 (when (member char
'(?
+ ?-
))
4801 (cond ((equal char ?-
) (setq strip t narrow t
))
4802 ((equal char ?
+) (setq strip nil narrow t
)))
4804 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars
)
4805 (setq char
(read-char)))
4806 (when (member char
'(?
< ?
> ?
= ??
))
4807 ;; An effort operator
4808 (setq effort-op
(char-to-string char
))
4809 (setq alist nil
) ; to make sure it will be interpreted as effort.
4810 (unless (equal char ??
)
4811 (loop for i from
0 to
9 do
4815 (if (= i
9) "0" (int-to-string (1+ i
)))
4816 "]" (nth i efforts
))))
4817 (message "Effort%s: %s " effort-op effort-prompt
)
4818 (setq char
(read-char))
4819 (when (or (< char ?
0) (> char ?
9))
4820 (error "Need 1-9,0 to select effort" ))))
4821 (when (equal char ?
\t)
4822 (unless (local-variable-p 'org-global-tags-completion-table
(current-buffer))
4823 (org-set-local 'org-global-tags-completion-table
4824 (org-global-tags-completion-table)))
4825 (let ((completion-ignore-case t
))
4826 (setq tag
(org-ido-completing-read
4827 "Tag: " org-global-tags-completion-table
))))
4830 (org-agenda-filter-by-tag-show-all)
4831 (when (get 'org-agenda-filter
:preset-filter
)
4832 (org-agenda-filter-apply org-agenda-filter
)))
4833 ((or (equal char ?\
)
4834 (setq a
(rassoc char alist
))
4835 (and (>= char ?
0) (<= char ?
9)
4836 (setq n
(if (= char ?
0) 9 (- char ?
0 1))
4837 tag
(concat effort-op
(nth n efforts
))
4842 (and tag
(setq a
(cons tag nil
))))
4843 (org-agenda-filter-by-tag-show-all)
4845 (setq org-agenda-filter
4846 (cons (concat (if strip
"-" "+") tag
)
4847 (if narrow current nil
)))
4848 (org-agenda-filter-apply org-agenda-filter
))
4849 (t (error "Invalid tag selection character %c" char
)))))
4851 (defun org-agenda-filter-by-tag-refine (strip &optional char
)
4852 "Refine the current filter. See `org-agenda-filter-by-tag."
4854 (org-agenda-filter-by-tag strip char
'refine
))
4856 (defun org-agenda-filter-make-matcher ()
4857 "Create the form that tests a line for the agenda filter."
4859 (dolist (x (append (get 'org-agenda-filter
:preset-filter
)
4861 (if (member x
'("-" "+"))
4862 (setq f1
'(not tags
))
4863 (if (string-match "[<=>?]" x
)
4864 (setq f1
(org-agenda-filter-effort-form x
))
4865 (setq f1
(list 'member
(downcase (substring x
1)) 'tags
)))
4866 (if (equal (string-to-char x
) ?-
)
4867 (setq f1
(list 'not f1
))))
4869 (cons 'and
(nreverse f
))))
4871 (defun org-agenda-filter-effort-form (e)
4872 "Return the form to compare the effort of the current line with what E says.
4873 E looks line \"+<2:25\"."
4875 (setq e
(substring e
1))
4876 (setq op
(string-to-char e
) e
(substring e
1))
4877 (setq op
(cond ((equal op ?
<) '<=)
4881 (list 'org-agenda-compare-effort
(list 'quote op
)
4882 (org-hh:mm-string-to-minutes e
))))
4884 (defun org-agenda-compare-effort (op value
)
4885 "Compare the effort of the current line with VALUE, using OP.
4886 If the line does not have an effort defined, return nil."
4887 (let ((eff (get-text-property (point) 'effort-minutes
)))
4890 (funcall op
(or eff
(if org-sort-agenda-noeffort-is-high
32767 0))
4893 (defun org-agenda-filter-apply (filter)
4894 "Set FILTER as the new agenda filter and apply it."
4896 (setq org-agenda-filter filter
4897 org-agenda-filter-form
(org-agenda-filter-make-matcher))
4898 (org-agenda-set-mode-name)
4900 (goto-char (point-min))
4902 (if (get-text-property (point) 'org-marker
)
4904 (setq tags
(get-text-property (point) 'tags
)) ; used in eval
4905 (if (not (eval org-agenda-filter-form
))
4906 (org-agenda-filter-by-tag-hide-line))
4907 (beginning-of-line 2))
4908 (beginning-of-line 2))))))
4910 (defun org-agenda-filter-by-tag-hide-line ()
4912 (setq ov
(org-make-overlay (max (point-min) (1- (point-at-bol)))
4914 (org-overlay-put ov
'invisible t
)
4915 (org-overlay-put ov
'type
'tags-filter
)
4916 (push ov org-agenda-filter-overlays
)))
4918 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos
)
4919 (setq pos
(or pos
(point)))
4921 (dolist (ov (org-overlays-at pos
))
4922 (when (and (org-overlay-get ov
'invisible
)
4923 (eq (org-overlay-get ov
'type
) 'tags-filter
))
4925 (if (< (org-overlay-start ov
) (point-at-eol))
4926 (org-move-overlay ov
(point-at-eol)
4927 (org-overlay-end ov
)))))))
4929 (defun org-agenda-filter-by-tag-show-all ()
4930 (mapc 'org-delete-overlay org-agenda-filter-overlays
)
4931 (setq org-agenda-filter-overlays nil
)
4932 (setq org-agenda-filter nil
)
4933 (setq org-agenda-filter-form nil
)
4934 (org-agenda-set-mode-name))
4936 (defun org-agenda-manipulate-query-add ()
4937 "Manipulate the query by adding a search term with positive selection.
4938 Positive selection means, the term must be matched for selection of an entry."
4940 (org-agenda-manipulate-query ?\
[))
4941 (defun org-agenda-manipulate-query-subtract ()
4942 "Manipulate the query by adding a search term with negative selection.
4943 Negative selection means, term must not be matched for selection of an entry."
4945 (org-agenda-manipulate-query ?\
]))
4946 (defun org-agenda-manipulate-query-add-re ()
4947 "Manipulate the query by adding a search regexp with positive selection.
4948 Positive selection means, the regexp must match for selection of an entry."
4950 (org-agenda-manipulate-query ?\
{))
4951 (defun org-agenda-manipulate-query-subtract-re ()
4952 "Manipulate the query by adding a search regexp with negative selection.
4953 Negative selection means, regexp must not match for selection of an entry."
4955 (org-agenda-manipulate-query ?\
}))
4956 (defun org-agenda-manipulate-query (char)
4958 ((memq org-agenda-type
'(timeline agenda
))
4959 (if (y-or-n-p "Re-display with inactive time stamps included? ")
4960 (let ((org-agenda-include-inactive-timestamps t
))
4963 ((eq org-agenda-type
'search
)
4965 'org-agenda-query-string
4966 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
4967 (?\
{ .
" +{}") (?\
} .
" -{}")))))
4968 (setq org-agenda-redo-command
4969 (list 'org-search-view
4971 org-agenda-query-string
4972 (+ (length org-agenda-query-string
)
4973 (if (member char
'(?\
{ ?\
})) 0 1))))
4974 (set-register org-agenda-query-register org-agenda-query-string
)
4976 (t (error "Cannot manipulate query for %s-type agenda buffers"
4979 (defun org-add-to-string (var string
)
4980 (set var
(concat (symbol-value var
) string
)))
4982 (defun org-agenda-goto-date (date)
4983 "Jump to DATE in agenda."
4984 (interactive (list (org-read-date)))
4985 (org-agenda-list nil date
))
4987 (defun org-agenda-goto-today ()
4990 (org-agenda-check-type t
'timeline
'agenda
)
4991 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
4993 (tdpos (goto-char tdpos
))
4994 ((eq org-agenda-type
'agenda
)
4995 (let* ((sd (time-to-days
4996 (time-subtract (current-time)
4997 (list 0 (* 3600 org-extend-today-until
) 0))))
4998 (comp (org-agenda-compute-time-span sd org-agenda-span
))
4999 (org-agenda-overriding-arguments org-agenda-last-arguments
))
5000 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
5001 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
5003 (org-agenda-find-same-or-today-or-agenda)))
5004 (t (error "Cannot find today")))))
5006 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
5008 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
5009 (text-property-any (point-min) (point-max) 'org-today t
)
5010 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
5013 (defun org-agenda-later (arg)
5014 "Go forward in time by thee current span.
5015 With prefix ARG, go forward that many times the current span."
5017 (org-agenda-check-type t
'agenda
)
5018 (let* ((span org-agenda-span
)
5019 (sd org-starting-day
)
5020 (greg (calendar-gregorian-from-absolute sd
))
5021 (cnt (get-text-property (point) 'org-day-cnt
))
5025 (setq sd
(+ arg sd
) nd
1))
5027 (setq sd
(+ (* 7 arg
) sd
) nd
7))
5029 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
5030 sd
(calendar-absolute-from-gregorian greg2
))
5031 (setcar greg2
(1+ (car greg2
)))
5032 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
5034 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
5035 sd
(calendar-absolute-from-gregorian greg2
))
5036 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
5037 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
5038 (let ((org-agenda-overriding-arguments
5039 (list (car org-agenda-last-arguments
) sd nd t
)))
5041 (org-agenda-find-same-or-today-or-agenda cnt
))))
5043 (defun org-agenda-earlier (arg)
5044 "Go backward in time by the current span.
5045 With prefix ARG, go backward that many times the current span."
5047 (org-agenda-later (- arg
)))
5049 (defun org-agenda-view-mode-dispatch ()
5050 "Call one of the view mode commands."
5052 (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
5053 clock[R]eport time[G]rid include[D]iary")
5054 (let ((a (read-char-exclusive)))
5056 (?d
(call-interactively 'org-agenda-day-view
))
5057 (?w
(call-interactively 'org-agenda-week-view
))
5058 (?m
(call-interactively 'org-agenda-month-view
))
5059 (?y
(call-interactively 'org-agenda-year-view
))
5060 (?l
(call-interactively 'org-agenda-log-mode
))
5061 (?a
(call-interactively 'org-agenda-archives-mode
))
5062 (?A
(org-agenda-archives-mode 'files
))
5063 (?R
(call-interactively 'org-agenda-clockreport-mode
))
5064 (?G
(call-interactively 'org-agenda-toggle-time-grid
))
5065 (?D
(call-interactively 'org-agenda-toggle-diary
))
5066 (?q
(message "Abort"))
5067 (otherwise (error "Invalid key" )))))
5069 (defun org-agenda-day-view (&optional day-of-year
)
5070 "Switch to daily view for agenda.
5071 With argument DAY-OF-YEAR, switch to that day of the year."
5073 (setq org-agenda-ndays
1)
5074 (org-agenda-change-time-span 'day day-of-year
))
5075 (defun org-agenda-week-view (&optional iso-week
)
5076 "Switch to daily view for agenda.
5077 With argument ISO-WEEK, switch to the corresponding ISO week.
5078 If ISO-WEEK has more then 2 digits, only the last two encode the
5079 week. Any digits before this encode a year. So 200712 means
5080 week 12 of year 2007. Years in the range 1938-2037 can also be
5081 written as 2-digit years."
5083 (setq org-agenda-ndays
7)
5084 (org-agenda-change-time-span 'week iso-week
))
5085 (defun org-agenda-month-view (&optional month
)
5086 "Switch to monthly view for agenda.
5087 With argument MONTH, switch to that month."
5089 (org-agenda-change-time-span 'month month
))
5090 (defun org-agenda-year-view (&optional year
)
5091 "Switch to yearly view for agenda.
5092 With argument YEAR, switch to that year.
5093 If MONTH has more then 2 digits, only the last two encode the
5094 month. Any digits before this encode a year. So 200712 means
5095 December year 2007. Years in the range 1938-2037 can also be
5096 written as 2-digit years."
5099 (setq year
(org-small-year-to-year year
)))
5100 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5101 (org-agenda-change-time-span 'year year
)
5104 (defun org-agenda-change-time-span (span &optional n
)
5105 "Change the agenda view to SPAN.
5106 SPAN may be `day', `week', `month', `year'."
5107 (org-agenda-check-type t
'agenda
)
5108 (if (and (not n
) (equal org-agenda-span span
))
5109 (error "Viewing span is already \"%s\"" span
))
5110 (let* ((sd (or (get-text-property (point) 'day
)
5112 (computed (org-agenda-compute-time-span sd span n
))
5113 (org-agenda-overriding-arguments
5114 (list (car org-agenda-last-arguments
)
5115 (car computed
) (cdr computed
) t
)))
5117 (org-agenda-find-same-or-today-or-agenda))
5118 (org-agenda-set-mode-name)
5119 (message "Switched to %s view" span
))
5121 (defun org-agenda-compute-time-span (sd span
&optional n
)
5122 "Compute starting date and number of days for agenda.
5123 SPAN may be `day', `week', `month', `year'. The return value
5124 is a cons cell with the starting date and the number of days,
5125 so that the date SD will be in that range."
5126 (let* ((greg (calendar-gregorian-from-absolute sd
))
5130 nd w1 y1 m1 thisweek
)
5134 (setq sd
(+ (calendar-absolute-from-gregorian
5139 (let* ((nt (calendar-day-of-week
5140 (calendar-gregorian-from-absolute sd
)))
5141 (d (if org-agenda-start-on-weekday
5142 (- nt org-agenda-start-on-weekday
)
5144 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
5147 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
5149 (setq y1
(org-small-year-to-year (/ n
100))
5152 (calendar-absolute-from-iso
5154 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
5157 (when (and n
(> n
99))
5158 (setq y1
(org-small-year-to-year (/ n
100))
5160 (setq sd
(calendar-absolute-from-gregorian
5161 (list (or n mg
) 1 (or y1 yg
)))
5162 nd
(- (calendar-absolute-from-gregorian
5163 (list (1+ (or n mg
)) 1 (or y1 yg
)))
5166 (setq sd
(calendar-absolute-from-gregorian
5167 (list 1 1 (or n yg
)))
5168 nd
(- (calendar-absolute-from-gregorian
5169 (list 1 1 (1+ (or n yg
))))
5173 (defun org-agenda-next-date-line (&optional arg
)
5174 "Jump to the next line indicating a date in agenda buffer."
5176 (org-agenda-check-type t
'agenda
'timeline
)
5177 (beginning-of-line 1)
5178 ;; This does not work if user makes date format that starts with a blank
5179 (if (looking-at "^\\S-") (forward-char 1))
5180 (if (not (re-search-forward "^\\S-" nil t arg
))
5183 (error "No next date after this line in this buffer")))
5184 (goto-char (match-beginning 0)))
5186 (defun org-agenda-previous-date-line (&optional arg
)
5187 "Jump to the previous line indicating a date in agenda buffer."
5189 (org-agenda-check-type t
'agenda
'timeline
)
5190 (beginning-of-line 1)
5191 (if (not (re-search-backward "^\\S-" nil t arg
))
5192 (error "No previous date before this line in this buffer")))
5194 ;; Initialize the highlight
5195 (defvar org-hl
(org-make-overlay 1 1))
5196 (org-overlay-put org-hl
'face
'highlight
)
5198 (defun org-highlight (begin end
&optional buffer
)
5199 "Highlight a region with overlay."
5200 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
5201 org-hl begin end
(or buffer
(current-buffer))))
5203 (defun org-unhighlight ()
5204 "Detach overlay INDEX."
5205 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
5207 ;; FIXME this is currently not used.
5208 (defun org-highlight-until-next-command (beg end
&optional buffer
)
5209 "Move the highlight overlay to BEG/END, remove it before the next command."
5210 (org-highlight beg end buffer
)
5211 (add-hook 'pre-command-hook
'org-unhighlight-once
))
5212 (defun org-unhighlight-once ()
5213 "Remove the highlight from its position, and this function from the hook."
5214 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
5217 (defun org-agenda-follow-mode ()
5218 "Toggle follow mode in an agenda buffer."
5220 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
5221 (org-agenda-set-mode-name)
5222 (message "Follow mode is %s"
5223 (if org-agenda-follow-mode
"on" "off")))
5225 (defun org-agenda-clockreport-mode ()
5226 "Toggle clocktable mode in an agenda buffer."
5228 (org-agenda-check-type t
'agenda
)
5229 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
5230 (org-agenda-set-mode-name)
5232 (message "Clocktable mode is %s"
5233 (if org-agenda-clockreport-mode
"on" "off")))
5235 (defun org-agenda-log-mode (&optional special
)
5236 "Toggle log mode in an agenda buffer.
5237 With argument SPECIAL, show all possible log items, not only the ones
5238 configured in `org-agenda-log-mode-items'.
5239 With a double `C-u' prefix arg, show *only* log items, nothing else."
5241 (org-agenda-check-type t
'agenda
'timeline
)
5242 (setq org-agenda-show-log
5243 (if (equal special
'(16))
5245 (if special
'(closed clock state
)
5246 (not org-agenda-show-log
))))
5247 (org-agenda-set-mode-name)
5249 (message "Log mode is %s"
5250 (if org-agenda-show-log
"on" "off")))
5252 (defun org-agenda-archives-mode (&optional with-files
)
5253 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5254 When called with a prefix argument, include all archive files as well."
5256 (setq org-agenda-archives-mode
5257 (if with-files t
(if org-agenda-archives-mode nil
'trees
)))
5258 (org-agenda-set-mode-name)
5263 ((eq org-agenda-archives-mode nil
)
5264 "No archives are included")
5265 ((eq org-agenda-archives-mode
'trees
)
5266 (format "Trees with :%s: tag are included" org-archive-tag
))
5267 ((eq org-agenda-archives-mode t
)
5268 (format "Trees with :%s: tag and all active archive files are included"
5269 org-archive-tag
)))))
5271 (defun org-agenda-toggle-diary ()
5272 "Toggle diary inclusion in an agenda buffer."
5274 (org-agenda-check-type t
'agenda
)
5275 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
5277 (org-agenda-set-mode-name)
5278 (message "Diary inclusion turned %s"
5279 (if org-agenda-include-diary
"on" "off")))
5281 (defun org-agenda-toggle-time-grid ()
5282 "Toggle time grid in an agenda buffer."
5284 (org-agenda-check-type t
'agenda
)
5285 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
5287 (org-agenda-set-mode-name)
5288 (message "Time-grid turned %s"
5289 (if org-agenda-use-time-grid
"on" "off")))
5291 (defun org-agenda-set-mode-name ()
5292 "Set the mode name to indicate all the small mode settings."
5294 (concat "Org-Agenda"
5295 (if (equal org-agenda-ndays
1) " Day" "")
5296 (if (equal org-agenda-ndays
7) " Week" "")
5297 (if org-agenda-follow-mode
" Follow" "")
5298 (if org-agenda-include-diary
" Diary" "")
5299 (if org-agenda-use-time-grid
" Grid" "")
5300 (if (consp org-agenda-show-log
) " LogAll"
5301 (if org-agenda-show-log
" Log" ""))
5302 (if (or org-agenda-filter
(get 'org-agenda-filter
5304 (concat " {" (mapconcat
5306 (append (get 'org-agenda-filter
5308 org-agenda-filter
) "") "}")
5310 (if org-agenda-archives-mode
5311 (if (eq org-agenda-archives-mode t
)
5313 (format " :%s:" org-archive-tag
))
5315 (if org-agenda-clockreport-mode
" Clock" "")))
5316 (force-mode-line-update))
5318 (defun org-agenda-post-command-hook ()
5319 (and (eolp) (not (bolp)) (backward-char 1))
5320 (setq org-agenda-type
5321 (or (get-text-property (point) 'org-agenda-type
)
5322 (get-text-property (max (point-min) (1- (point)))
5324 (if (and org-agenda-follow-mode
5325 (get-text-property (point) 'org-marker
))
5328 (defun org-agenda-show-priority ()
5329 "Show the priority of the current item.
5330 This priority is composed of the main priority given with the [#A] cookies,
5331 and by additional input from the age of a schedules or deadline entry."
5333 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
5334 (message "Priority is %d" (if pri pri -
1000))))
5336 (defun org-agenda-show-tags ()
5337 "Show the tags applicable to the current item."
5339 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
5341 (message "Tags are :%s:"
5342 (org-no-properties (mapconcat 'identity tags
":")))
5343 (message "No tags associated with this line"))))
5345 (defun org-agenda-goto (&optional highlight
)
5346 "Go to the Org-mode file which contains the item at point."
5348 (let* ((marker (or (get-text-property (point) 'org-marker
)
5349 (org-agenda-error)))
5350 (buffer (marker-buffer marker
))
5351 (pos (marker-position marker
)))
5352 (switch-to-buffer-other-window buffer
)
5356 (org-show-context 'agenda
)
5358 (and (outline-next-heading)
5359 (org-flag-heading nil
)))) ; show the next heading
5360 (recenter (/ (window-height) 2))
5361 (run-hooks 'org-agenda-after-show-hook
)
5362 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
5364 (defvar org-agenda-after-show-hook nil
5365 "Normal hook run after an item has been shown from the agenda.
5366 Point is in the buffer where the item originated.")
5368 (defun org-agenda-kill ()
5369 "Kill the entry or subtree belonging to the current agenda entry."
5371 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5372 (let* ((marker (or (get-text-property (point) 'org-marker
)
5373 (org-agenda-error)))
5374 (buffer (marker-buffer marker
))
5375 (pos (marker-position marker
))
5376 (type (get-text-property (point) 'type
))
5377 dbeg dend
(n 0) conf
)
5378 (org-with-remote-undo buffer
5379 (with-current-buffer buffer
5382 (if (and (org-mode-p) (not (member type
'("sexp"))))
5383 (setq dbeg
(progn (org-back-to-heading t
) (point))
5384 dend
(org-end-of-subtree t t
))
5385 (setq dbeg
(point-at-bol)
5386 dend
(min (point-max) (1+ (point-at-eol)))))
5388 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
5389 (setq conf
(or (eq t org-agenda-confirm-kill
)
5390 (and (numberp org-agenda-confirm-kill
)
5391 (> n org-agenda-confirm-kill
))))
5394 (format "Delete entry with %d lines in buffer \"%s\"? "
5395 n
(buffer-name buffer
))))
5397 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
5398 (with-current-buffer buffer
(delete-region dbeg dend
))
5399 (message "Agenda item and source killed"))))
5401 (defun org-agenda-archive ()
5402 "Archive the entry or subtree belonging to the current agenda entry."
5404 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5405 (let* ((marker (or (get-text-property (point) 'org-marker
)
5406 (org-agenda-error)))
5407 (buffer (marker-buffer marker
))
5408 (pos (marker-position marker
)))
5409 (org-with-remote-undo buffer
5410 (with-current-buffer buffer
5414 (org-remove-subtree-entries-from-agenda)
5415 (org-back-to-heading t
)
5416 (org-archive-subtree))
5417 (error "Archiving works only in Org-mode files"))))))
5419 (defun org-agenda-archive-to-archive-sibling ()
5420 "Move the entry to the archive sibling."
5422 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5423 (let* ((marker (or (get-text-property (point) 'org-marker
)
5424 (org-agenda-error)))
5425 (buffer (marker-buffer marker
))
5426 (pos (marker-position marker
)))
5427 (org-with-remote-undo buffer
5428 (with-current-buffer buffer
5432 (org-remove-subtree-entries-from-agenda)
5433 (org-back-to-heading t
)
5434 (org-archive-to-archive-sibling))
5435 (error "Archiving works only in Org-mode files"))))))
5437 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
5438 "Remove all lines in the agenda that correspond to a given subtree.
5439 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5440 If this information is not given, the function uses the tree at point."
5441 (let ((buf (or buf
(current-buffer))) m p
)
5443 (unless (and beg end
)
5444 (org-back-to-heading t
)
5446 (org-end-of-subtree t
)
5448 (set-buffer (get-buffer org-agenda-buffer-name
))
5450 (goto-char (point-max))
5451 (beginning-of-line 1)
5453 (when (and (setq m
(get-text-property (point) 'org-marker
))
5454 (equal buf
(marker-buffer m
))
5455 (setq p
(marker-position m
))
5458 (let ((inhibit-read-only t
))
5459 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5460 (beginning-of-line 0))))))
5462 (defun org-agenda-refile (&optional goto rfloc
)
5463 "Refile the item at point."
5465 (let* ((marker (or (get-text-property (point) 'org-hd-marker
)
5466 (org-agenda-error)))
5467 (buffer (marker-buffer marker
))
5468 (pos (marker-position marker
))
5470 (org-refile-get-location
5471 (if goto
"Goto: " "Refile to: ") buffer
5472 org-refile-allow-creating-parent-nodes
))))
5473 (with-current-buffer buffer
5478 (org-remove-subtree-entries-from-agenda)
5479 (org-refile goto buffer rfloc
))))))
5484 (defun org-agenda-open-link ()
5485 "Follow the link in the current line, if any."
5487 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
5490 (narrow-to-region (point-at-bol) (point-at-eol))
5491 (org-open-at-point))))
5493 (defun org-agenda-copy-local-variable (var)
5494 "Get a variable from a referenced buffer and install it here."
5495 (let ((m (get-text-property (point) 'org-marker
)))
5496 (when (and m
(buffer-live-p (marker-buffer m
)))
5497 (org-set-local var
(with-current-buffer (marker-buffer m
)
5498 (symbol-value var
))))))
5500 (defun org-agenda-switch-to (&optional delete-other-windows
)
5501 "Go to the Org-mode file which contains the item at point."
5503 (let* ((marker (or (get-text-property (point) 'org-marker
)
5504 (org-agenda-error)))
5505 (buffer (marker-buffer marker
))
5506 (pos (marker-position marker
)))
5507 (switch-to-buffer buffer
)
5508 (and delete-other-windows
(delete-other-windows))
5512 (org-show-context 'agenda
)
5514 (and (outline-next-heading)
5515 (org-flag-heading nil
)))))) ; show the next heading
5517 (defun org-agenda-goto-mouse (ev)
5518 "Go to the Org-mode file which contains the item at the mouse click."
5520 (mouse-set-point ev
)
5523 (defun org-agenda-show (&optional full-entry
)
5524 "Display the Org-mode file which contains the item at point.
5525 With prefix argument FULL-ENTRY, make the entire entry visible
5526 if it was hidden in the outline."
5528 (let ((win (selected-window)))
5530 (let ((org-show-entry-below t
))
5531 (org-agenda-goto t
))
5532 (org-agenda-goto t
))
5533 (select-window win
)))
5535 (defun org-agenda-show-1 (&optional more
)
5536 "Display the Org-mode file which contains the item at point.
5537 The prefix arg causes further revieling:
5540 1 just show the entry according to defaults.
5541 2 show the text below the heading
5542 3 show the entire subtree
5543 4 show the entire subtree and any LOGBOOK drawers
5544 5 show the entire subtree and any drawers
5545 With prefix argument FULL-ENTRY, make the entire entry visible
5546 if it was hidden in the outline."
5548 (let ((win (selected-window)))
5550 (org-recenter-heading 1)
5554 (message "Remote: hide subtree"))
5555 ((and (interactive-p) (= more
1))
5556 (message "Remote: show with default settings"))
5560 (org-back-to-heading)
5561 (org-cycle-hide-drawers 'children
))
5562 (message "Remote: show entry"))
5566 (org-back-to-heading)
5567 (org-cycle-hide-drawers 'subtree
))
5568 (message "Remote: show subtree"))
5570 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers
)))
5572 (concat "^[ \t]*:\\("
5573 (mapconcat 'regexp-quote org-drawers
"\\|")
5577 (org-back-to-heading)
5578 (org-cycle-hide-drawers 'subtree
)))
5579 (message "Remote: show subtree and LOGBOOK"))
5582 (message "Remote: show subtree and LOGBOOK")))
5583 (select-window win
)))
5585 (defun org-recenter-heading (n)
5587 (org-back-to-heading)
5590 (defvar org-agenda-cycle-counter nil
)
5591 (defun org-agenda-cycle-show (n)
5592 "Show the current entry in another window, with default settings.
5593 Default settings are taken from `org-show-hierarchy-above' and siblings.
5594 When use repeadedly in immediate succession, the remote entry will cycle
5597 entry -> subtree -> subtree with logbook"
5600 (not (eq last-command this-command
)))
5601 (setq org-agenda-cycle-counter
0))
5602 (setq org-agenda-cycle-counter
(1+ org-agenda-cycle-counter
))
5603 (if (> org-agenda-cycle-counter
4)
5604 (setq org-agenda-cycle-counter
0))
5605 (org-agenda-show-1 org-agenda-cycle-counter
))
5607 (defun org-agenda-recenter (arg)
5608 "Display the Org-mode file which contains the item at point and recenter."
5610 (let ((win (selected-window)))
5613 (select-window win
)))
5615 (defun org-agenda-show-mouse (ev)
5616 "Display the Org-mode file which contains the item at the mouse click."
5618 (mouse-set-point ev
)
5621 (defun org-agenda-check-no-diary ()
5622 "Check if the entry is a diary link and abort if yes."
5623 (if (get-text-property (point) 'org-agenda-diary-link
)
5624 (org-agenda-error)))
5626 (defun org-agenda-error ()
5627 (error "Command not allowed in this line"))
5629 (defun org-agenda-tree-to-indirect-buffer ()
5630 "Show the subtree corresponding to the current entry in an indirect buffer.
5631 This calls the command `org-tree-to-indirect-buffer' from the original
5633 With numerical prefix arg ARG, go up to this level and then take that tree.
5634 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
5637 (org-agenda-check-no-diary)
5638 (let* ((marker (or (get-text-property (point) 'org-marker
)
5639 (org-agenda-error)))
5640 (buffer (marker-buffer marker
))
5641 (pos (marker-position marker
)))
5642 (with-current-buffer buffer
5645 (call-interactively 'org-tree-to-indirect-buffer
)))))
5647 (defvar org-last-heading-marker
(make-marker)
5648 "Marker pointing to the headline that last changed its TODO state
5649 by a remote command from the agenda.")
5651 (defun org-agenda-todo-nextset ()
5652 "Switch TODO entry to next sequence."
5654 (org-agenda-todo 'nextset
))
5656 (defun org-agenda-todo-previousset ()
5657 "Switch TODO entry to previous sequence."
5659 (org-agenda-todo 'previousset
))
5661 (defun org-agenda-todo (&optional arg
)
5662 "Cycle TODO state of line at point, also in Org-mode file.
5663 This changes the line at point, all other lines in the agenda referring to
5664 the same tree node, and the headline of the tree node in the Org-mode file."
5666 (org-agenda-check-no-diary)
5667 (let* ((col (current-column))
5668 (marker (or (get-text-property (point) 'org-marker
)
5669 (org-agenda-error)))
5670 (buffer (marker-buffer marker
))
5671 (pos (marker-position marker
))
5672 (hdmarker (get-text-property (point) 'org-hd-marker
))
5673 (todayp (equal (get-text-property (point) 'day
)
5674 (time-to-days (current-time))))
5675 (inhibit-read-only t
)
5676 org-agenda-headline-snapshot-before-repeat newhead just-one
)
5677 (org-with-remote-undo buffer
5678 (with-current-buffer buffer
5681 (org-show-context 'agenda
)
5683 (and (outline-next-heading)
5684 (org-flag-heading nil
))) ; show the next heading
5685 (let ((current-prefix-arg arg
))
5686 (call-interactively 'org-todo
))
5687 (and (bolp) (forward-char 1))
5688 (setq newhead
(org-get-heading))
5689 (when (and (org-bound-and-true-p
5690 org-agenda-headline-snapshot-before-repeat
)
5691 (not (equal org-agenda-headline-snapshot-before-repeat
5694 (setq newhead org-agenda-headline-snapshot-before-repeat
5697 (org-back-to-heading)
5698 (move-marker org-last-heading-marker
(point))))
5699 (beginning-of-line 1)
5701 (org-agenda-change-all-lines newhead hdmarker
'fixface just-one
))
5702 (org-move-to-column col
))))
5704 (defun org-agenda-add-note (&optional arg
)
5705 "Add a time-stamped note to the entry at point."
5707 (org-agenda-check-no-diary)
5708 (let* ((marker (or (get-text-property (point) 'org-marker
)
5709 (org-agenda-error)))
5710 (buffer (marker-buffer marker
))
5711 (pos (marker-position marker
))
5712 (hdmarker (get-text-property (point) 'org-hd-marker
))
5713 (inhibit-read-only t
))
5714 (with-current-buffer buffer
5717 (org-show-context 'agenda
)
5719 (and (outline-next-heading)
5720 (org-flag-heading nil
))) ; show the next heading
5723 (defun org-agenda-change-all-lines (newhead hdmarker
5724 &optional fixface just-this
)
5725 "Change all lines in the agenda buffer which match HDMARKER.
5726 The new content of the line will be NEWHEAD (as modified by
5727 `org-format-agenda-item'). HDMARKER is checked with
5728 `equal' against all `org-hd-marker' text properties in the file.
5729 If FIXFACE is non-nil, the face of each item is modified according to
5731 If JUST-THIS is non-nil, change just the current line, not all.
5732 If FORCE-TAGS is non nil, the car of it returns the new tags."
5733 (let* ((inhibit-read-only t
)
5734 (line (org-current-line))
5735 (thetags (with-current-buffer (marker-buffer hdmarker
)
5736 (save-excursion (save-restriction (widen)
5737 (goto-char hdmarker
)
5738 (org-get-tags-at)))))
5739 props m pl undone-face done-face finish new dotime cat tags
)
5741 (goto-char (point-max))
5742 (beginning-of-line 1)
5744 (setq finish
(bobp))
5745 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
5746 (or (not just-this
) (= (org-current-line) line
))
5748 (setq props
(text-properties-at (point))
5749 dotime
(get-text-property (point) 'dotime
)
5750 cat
(get-text-property (point) 'org-category
)
5752 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
5753 pl
(get-text-property (point) 'prefix-length
)
5754 undone-face
(get-text-property (point) 'undone-face
)
5755 done-face
(get-text-property (point) 'done-face
))
5756 (org-move-to-column pl
)
5759 (beginning-of-line 1)
5760 (and (looking-at ".*\n?") (replace-match "")))
5762 (replace-match new t t
)
5763 (beginning-of-line 1)
5764 (add-text-properties (point-at-bol) (point-at-eol) props
)
5766 (add-text-properties
5767 (point-at-bol) (point-at-eol)
5769 (if org-last-todo-state-is-todo
5770 undone-face done-face
))))
5771 (org-agenda-highlight-todo 'line
)
5772 (beginning-of-line 1))
5773 (t (error "Line update did not work"))))
5774 (beginning-of-line 0)))
5775 (org-finalize-agenda)))
5777 (defun org-agenda-align-tags (&optional line
)
5778 "Align all tags in agenda items to `org-agenda-tags-column'."
5779 (let ((inhibit-read-only t
) l c
)
5781 (goto-char (if line
(point-at-bol) (point-min)))
5782 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
5783 (if line
(point-at-eol) nil
) t
)
5784 (add-text-properties
5785 (match-beginning 2) (match-end 2)
5786 (list 'face
(delq nil
(let ((prop (get-text-property
5787 (match-beginning 2) 'face
)))
5788 (or (listp prop
) (setq prop
(list prop
)))
5789 (if (memq 'org-tag prop
)
5791 (cons 'org-tag prop
))))))
5792 (setq l
(- (match-end 2) (match-beginning 2))
5793 c
(if (< org-agenda-tags-column
0)
5794 (- (abs org-agenda-tags-column
) l
)
5795 org-agenda-tags-column
))
5796 (delete-region (match-beginning 1) (match-end 1))
5797 (goto-char (match-beginning 1))
5798 (insert (org-add-props
5799 (make-string (max 1 (- c
(current-column))) ?\
)
5800 (text-properties-at (point)))))
5801 (goto-char (point-min))
5802 (org-font-lock-add-tag-faces (point-max)))))
5804 (defun org-agenda-priority-up ()
5805 "Increase the priority of line at point, also in Org-mode file."
5807 (org-agenda-priority 'up
))
5809 (defun org-agenda-priority-down ()
5810 "Decrease the priority of line at point, also in Org-mode file."
5812 (org-agenda-priority 'down
))
5814 (defun org-agenda-priority (&optional force-direction
)
5815 "Set the priority of line at point, also in Org-mode file.
5816 This changes the line at point, all other lines in the agenda referring to
5817 the same tree node, and the headline of the tree node in the Org-mode file."
5819 (unless org-enable-priority-commands
5820 (error "Priority commands are disabled"))
5821 (org-agenda-check-no-diary)
5822 (let* ((marker (or (get-text-property (point) 'org-marker
)
5823 (org-agenda-error)))
5824 (hdmarker (get-text-property (point) 'org-hd-marker
))
5825 (buffer (marker-buffer hdmarker
))
5826 (pos (marker-position hdmarker
))
5827 (inhibit-read-only t
)
5829 (org-with-remote-undo buffer
5830 (with-current-buffer buffer
5833 (org-show-context 'agenda
)
5835 (and (outline-next-heading)
5836 (org-flag-heading nil
))) ; show the next heading
5837 (funcall 'org-priority force-direction
)
5839 (setq newhead
(org-get-heading)))
5840 (org-agenda-change-all-lines newhead hdmarker
)
5841 (beginning-of-line 1))))
5843 ;; FIXME: should fix the tags property of the agenda line.
5844 (defun org-agenda-set-tags (&optional tag onoff
)
5845 "Set tags for the current headline."
5847 (org-agenda-check-no-diary)
5848 (if (and (org-region-active-p) (interactive-p))
5849 (call-interactively 'org-change-tag-in-region
)
5850 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5851 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5852 (org-agenda-error)))
5853 (buffer (marker-buffer hdmarker
))
5854 (pos (marker-position hdmarker
))
5855 (inhibit-read-only t
)
5857 (org-with-remote-undo buffer
5858 (with-current-buffer buffer
5862 (org-show-context 'agenda
))
5864 (and (outline-next-heading)
5865 (org-flag-heading nil
))) ; show the next heading
5868 (org-toggle-tag tag onoff
)
5869 (call-interactively 'org-set-tags
))
5871 (setq newhead
(org-get-heading)))
5872 (org-agenda-change-all-lines newhead hdmarker
)
5873 (beginning-of-line 1)))))
5875 (defun org-agenda-toggle-archive-tag ()
5876 "Toggle the archive tag for the current entry."
5878 (org-agenda-check-no-diary)
5879 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5880 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5881 (org-agenda-error)))
5882 (buffer (marker-buffer hdmarker
))
5883 (pos (marker-position hdmarker
))
5884 (inhibit-read-only t
)
5886 (org-with-remote-undo buffer
5887 (with-current-buffer buffer
5890 (org-show-context 'agenda
)
5892 (and (outline-next-heading)
5893 (org-flag-heading nil
))) ; show the next heading
5894 (call-interactively 'org-toggle-archive-tag
)
5896 (setq newhead
(org-get-heading)))
5897 (org-agenda-change-all-lines newhead hdmarker
)
5898 (beginning-of-line 1))))
5900 (defun org-agenda-do-date-later (arg)
5903 ((or (equal arg
'(16))
5905 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5906 (setq this-command
'org-agenda-date-later-minutes
)
5907 (org-agenda-date-later-minutes 1))
5908 ((or (equal arg
'(4))
5910 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5911 (setq this-command
'org-agenda-date-later-hours
)
5912 (org-agenda-date-later-hours 1))
5914 (org-agenda-date-later (prefix-numeric-value arg
)))))
5916 (defun org-agenda-do-date-earlier (arg)
5919 ((or (equal arg
'(16))
5921 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5922 (setq this-command
'org-agenda-date-earlier-minutes
)
5923 (org-agenda-date-earlier-minutes 1))
5924 ((or (equal arg
'(4))
5926 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5927 (setq this-command
'org-agenda-date-earlier-hours
)
5928 (org-agenda-date-earlier-hours 1))
5930 (org-agenda-date-earlier (prefix-numeric-value arg
)))))
5932 (defun org-agenda-date-later (arg &optional what
)
5933 "Change the date of this item to one day later."
5935 (org-agenda-check-type t
'agenda
'timeline
)
5936 (org-agenda-check-no-diary)
5937 (let* ((marker (or (get-text-property (point) 'org-marker
)
5938 (org-agenda-error)))
5939 (buffer (marker-buffer marker
))
5940 (pos (marker-position marker
)))
5941 (org-with-remote-undo buffer
5942 (with-current-buffer buffer
5945 (if (not (org-at-timestamp-p))
5946 (error "Cannot find time stamp"))
5947 (org-timestamp-change arg
(or what
'day
)))
5948 (org-agenda-show-new-time marker org-last-changed-timestamp
))
5949 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
5951 (defun org-agenda-date-earlier (arg &optional what
)
5952 "Change the date of this item to one day earlier."
5954 (org-agenda-date-later (- arg
) what
))
5956 (defun org-agenda-date-later-minutes (arg)
5957 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5959 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5960 (org-agenda-date-later arg
'minute
))
5962 (defun org-agenda-date-earlier-minutes (arg)
5963 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5965 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5966 (org-agenda-date-earlier arg
'minute
))
5968 (defun org-agenda-date-later-hours (arg)
5969 "Change the time of this item, in hour steps."
5971 (org-agenda-date-later arg
'hour
))
5973 (defun org-agenda-date-earlier-hours (arg)
5974 "Change the time of this item, in hour steps."
5976 (org-agenda-date-earlier arg
'hour
))
5978 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
5979 "Show new date stamp via text properties."
5980 ;; We use text properties to make this undoable
5981 (let ((inhibit-read-only t
)
5982 (buffer-invisibility-spec))
5983 (setq stamp
(concat " " prefix
" => " stamp
))
5985 (goto-char (point-max))
5987 (when (equal marker
(get-text-property (point) 'org-marker
))
5988 (org-move-to-column (- (window-width) (length stamp
)) t
)
5989 (org-agenda-fix-tags-filter-overlays-at (point))
5990 (if (featurep 'xemacs
)
5991 ;; Use `duplicable' property to trigger undo recording
5992 (let ((ex (make-extent nil nil
))
5993 (gl (make-glyph stamp
)))
5994 (set-glyph-face gl
'secondary-selection
)
5995 (set-extent-properties
5996 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
5997 (insert-extent ex
(1- (point)) (point-at-eol)))
5998 (add-text-properties
5999 (1- (point)) (point-at-eol)
6000 (list 'display
(org-add-props stamp nil
6001 'face
'secondary-selection
))))
6002 (beginning-of-line 1))
6003 (beginning-of-line 0)))))
6005 (defun org-agenda-date-prompt (arg)
6006 "Change the date of this item. Date is prompted for, with default today.
6007 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6008 be used to request time specification in the time stamp."
6010 (org-agenda-check-type t
'agenda
'timeline
)
6011 (org-agenda-check-no-diary)
6012 (let* ((marker (or (get-text-property (point) 'org-marker
)
6013 (org-agenda-error)))
6014 (buffer (marker-buffer marker
))
6015 (pos (marker-position marker
)))
6016 (org-with-remote-undo buffer
6017 (with-current-buffer buffer
6020 (if (not (org-at-timestamp-p))
6021 (error "Cannot find time stamp"))
6022 (org-time-stamp arg
)
6023 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
6025 (defun org-agenda-schedule (arg)
6026 "Schedule the item at point."
6028 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
6029 (org-agenda-check-no-diary)
6030 (let* ((marker (or (get-text-property (point) 'org-marker
)
6031 (org-agenda-error)))
6032 (type (marker-insertion-type marker
))
6033 (buffer (marker-buffer marker
))
6034 (pos (marker-position marker
))
6035 (org-insert-labeled-timestamps-at-point nil
)
6037 (set-marker-insertion-type marker t
)
6038 (org-with-remote-undo buffer
6039 (with-current-buffer buffer
6042 (setq ts
(org-schedule arg
)))
6043 (org-agenda-show-new-time marker ts
"S"))
6044 (message "Item scheduled for %s" ts
)))
6046 (defun org-agenda-deadline (arg)
6047 "Schedule the item at point."
6049 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
6050 (org-agenda-check-no-diary)
6051 (let* ((marker (or (get-text-property (point) 'org-marker
)
6052 (org-agenda-error)))
6053 (buffer (marker-buffer marker
))
6054 (pos (marker-position marker
))
6055 (org-insert-labeled-timestamps-at-point nil
)
6057 (org-with-remote-undo buffer
6058 (with-current-buffer buffer
6061 (setq ts
(org-deadline arg
)))
6062 (org-agenda-show-new-time marker ts
"S"))
6063 (message "Deadline for this item set to %s" ts
)))
6065 (defun org-agenda-action ()
6066 "Select entry for agenda action, or execute an agenda action.
6067 This command prompts for another letter. Valid inputs are:
6069 m Mark the entry at point for an agenda action
6070 s Schedule the marked entry to the date at the cursor
6071 d Set the deadline of the marked entry to the date at the cursor
6072 r Call `org-remember' with cursor date as the default date
6073 SPC Show marked entry in other window
6074 TAB Visit marked entry in other window
6076 The cursor may be at a date in the calendar, or in the Org agenda."
6079 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6080 (setq ans
(read-char-exclusive))
6084 (if (eq major-mode
'org-agenda-mode
)
6085 (let ((m (or (get-text-property (point) 'org-hd-marker
)
6086 (get-text-property (point) 'org-marker
))))
6089 (move-marker org-agenda-action-marker
6090 (marker-position m
) (marker-buffer m
))
6091 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6092 (error "Don't know which entry to mark")))
6093 (error "This command works only in the agenda")))
6095 (org-agenda-do-action '(org-schedule nil org-overriding-default-time
)))
6097 (org-agenda-do-action '(org-deadline nil org-overriding-default-time
)))
6099 (org-agenda-do-action '(org-remember) t
))
6101 (let ((cw (selected-window)))
6102 (org-switch-to-buffer-other-window
6103 (marker-buffer org-agenda-action-marker
))
6104 (goto-char org-agenda-action-marker
)
6105 (org-show-context 'agenda
)
6106 (select-window cw
)))
6108 (org-switch-to-buffer-other-window
6109 (marker-buffer org-agenda-action-marker
))
6110 (goto-char org-agenda-action-marker
)
6111 (org-show-context 'agenda
))
6112 (t (error "Invalid agenda action %c" ans
)))))
6114 (defun org-agenda-do-action (form &optional current-buffer
)
6115 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6116 (let ((org-overriding-default-time (org-get-cursor-date)))
6119 (if (not (marker-buffer org-agenda-action-marker
))
6120 (error "No entry has bee selected for agenda action")
6121 (with-current-buffer (marker-buffer org-agenda-action-marker
)
6125 (goto-char org-agenda-action-marker
)
6128 (defun org-agenda-clock-in (&optional arg
)
6129 "Start the clock on the currently selected item."
6131 (org-agenda-check-no-diary)
6132 (if (equal arg
'(4))
6134 (let* ((marker (or (get-text-property (point) 'org-marker
)
6135 (org-agenda-error)))
6136 (hdmarker (or (get-text-property (point) 'org-hd-marker
)
6138 (pos (marker-position marker
))
6140 (org-with-remote-undo (marker-buffer marker
)
6141 (with-current-buffer (marker-buffer marker
)
6144 (org-show-context 'agenda
)
6146 (org-cycle-hide-drawers 'children
)
6148 (setq newhead
(org-get-heading)))
6149 (org-agenda-change-all-lines newhead hdmarker
)))))
6151 (defun org-agenda-clock-out (&optional arg
)
6152 "Stop the currently running clock."
6154 (unless (marker-buffer org-clock-marker
)
6155 (error "No running clock"))
6156 (let ((marker (make-marker)) newhead
)
6157 (org-with-remote-undo (marker-buffer org-clock-marker
)
6158 (with-current-buffer (marker-buffer org-clock-marker
)
6162 (goto-char org-clock-marker
)
6163 (org-back-to-heading t
)
6164 (move-marker marker
(point))
6166 (setq newhead
(org-get-heading))))))
6167 (org-agenda-change-all-lines newhead marker
)
6168 (move-marker marker nil
)))
6170 (defun org-agenda-clock-cancel (&optional arg
)
6171 "Cancel the currently running clock."
6173 (unless (marker-buffer org-clock-marker
)
6174 (error "No running clock"))
6175 (org-with-remote-undo (marker-buffer org-clock-marker
)
6176 (org-clock-cancel)))
6178 (defun org-agenda-diary-entry ()
6179 "Make a diary entry, like the `i' command from the calendar.
6180 All the standard commands work: block, weekly etc."
6182 (org-agenda-check-type t
'agenda
'timeline
)
6183 (require 'diary-lib
)
6185 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6186 (read-char-exclusive)))
6187 (cmd (cdr (assoc char
6188 '((?d . insert-diary-entry
)
6189 (?w . insert-weekly-diary-entry
)
6190 (?m . insert-monthly-diary-entry
)
6191 (?y . insert-yearly-diary-entry
)
6192 (?a . insert-anniversary-diary-entry
)
6193 (?b . insert-block-diary-entry
)
6194 (?c . insert-cyclic-diary-entry
)))))
6195 (oldf (symbol-function 'calendar-cursor-to-date
))
6196 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6198 (mark (or (mark t
) (point))))
6200 (error "No command associated with <%c>" char
))
6201 (unless (and (get-text-property point
'day
)
6202 (or (not (equal ?b char
))
6203 (get-text-property mark
'day
)))
6204 (error "Don't know which date to use for diary entry"))
6205 ;; We implement this by hacking the `calendar-cursor-to-date' function
6206 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6207 (let ((calendar-mark-ring
6208 (list (calendar-gregorian-from-absolute
6209 (or (get-text-property mark
'day
)
6210 (get-text-property point
'day
))))))
6213 (fset 'calendar-cursor-to-date
6214 (lambda (&optional error dummy
)
6215 (calendar-gregorian-from-absolute
6216 (get-text-property point
'day
))))
6217 (call-interactively cmd
))
6218 (fset 'calendar-cursor-to-date oldf
)))))
6220 (defun org-agenda-execute-calendar-command (cmd)
6221 "Execute a calendar command from the agenda, with the date associated to
6222 the cursor position."
6223 (org-agenda-check-type t
'agenda
'timeline
)
6224 (require 'diary-lib
)
6225 (unless (get-text-property (point) 'day
)
6226 (error "Don't know which date to use for calendar command"))
6227 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
6229 (date (calendar-gregorian-from-absolute
6230 (get-text-property point
'day
)))
6231 ;; the following 2 vars are needed in the calendar
6232 (displayed-month (car date
))
6233 (displayed-year (nth 2 date
)))
6236 (fset 'calendar-cursor-to-date
6237 (lambda (&optional error dummy
)
6238 (calendar-gregorian-from-absolute
6239 (get-text-property point
'day
))))
6240 (call-interactively cmd
))
6241 (fset 'calendar-cursor-to-date oldf
))))
6243 (defun org-agenda-phases-of-moon ()
6244 "Display the phases of the moon for the 3 months around the cursor date."
6246 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
6248 (defun org-agenda-holidays ()
6249 "Display the holidays for the 3 months around the cursor date."
6251 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
6253 (defvar calendar-longitude
)
6254 (defvar calendar-latitude
)
6255 (defvar calendar-location-name
)
6257 (defun org-agenda-sunrise-sunset (arg)
6258 "Display sunrise and sunset for the cursor date.
6259 Latitude and longitude can be specified with the variables
6260 `calendar-latitude' and `calendar-longitude'. When called with prefix
6261 argument, latitude and longitude will be prompted for."
6264 (let ((calendar-longitude (if arg nil calendar-longitude
))
6265 (calendar-latitude (if arg nil calendar-latitude
))
6266 (calendar-location-name
6267 (if arg
"the given coordinates" calendar-location-name
)))
6268 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
6270 (defun org-agenda-goto-calendar ()
6271 "Open the Emacs calendar with the date at the cursor."
6273 (org-agenda-check-type t
'agenda
'timeline
)
6274 (let* ((day (or (get-text-property (point) 'day
)
6275 (error "Don't know which date to open in calendar")))
6276 (date (calendar-gregorian-from-absolute day
))
6277 (calendar-move-hook nil
)
6278 (calendar-view-holidays-initially-flag nil
)
6279 (calendar-view-diary-initially-flag nil
)
6280 (view-calendar-holidays-initially nil
)
6281 (view-diary-entries-initially nil
))
6283 (calendar-goto-date date
)))
6286 (defun org-calendar-goto-agenda ()
6287 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6288 This is a command that has to be installed in `calendar-mode-map'."
6290 (org-agenda-list nil
(calendar-absolute-from-gregorian
6291 (calendar-cursor-to-date))
6294 (defun org-agenda-convert-date ()
6296 (org-agenda-check-type t
'agenda
'timeline
)
6297 (let ((day (get-text-property (point) 'day
))
6300 (error "Don't know which date to convert"))
6301 (setq date
(calendar-gregorian-from-absolute day
))
6303 "Gregorian: " (calendar-date-string date
) "\n"
6304 "ISO: " (calendar-iso-date-string date
) "\n"
6305 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
6306 "Julian: " (calendar-julian-date-string date
) "\n"
6307 "Astron. JD: " (calendar-astro-date-string date
)
6308 " (Julian date number at noon UTC)\n"
6309 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
6310 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
6311 "French: " (calendar-french-date-string date
) "\n"
6312 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
6313 "Mayan: " (calendar-mayan-date-string date
) "\n"
6314 "Coptic: " (calendar-coptic-date-string date
) "\n"
6315 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
6316 "Persian: " (calendar-persian-date-string date
) "\n"
6317 "Chinese: " (calendar-chinese-date-string date
) "\n"))
6318 (with-output-to-temp-buffer "*Dates*"
6320 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6324 (defvar org-agenda-bulk-marked-entries nil
6325 "List of markers that refer to marked entries in the agenda.")
6327 (defun org-agenda-bulk-marked-p ()
6328 (eq (get-char-property (point-at-bol) 'type
)
6329 'org-marked-entry-overlay
))
6331 (defun org-agenda-bulk-mark ()
6332 "Mark the entry at point for future bulk action."
6334 (org-agenda-check-no-diary)
6335 (let* ((m (get-text-property (point) 'org-hd-marker
))
6337 (unless (org-agenda-bulk-marked-p)
6338 (unless m
(error "Nothing to mark at point"))
6339 (push m org-agenda-bulk-marked-entries
)
6340 (setq ov
(org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
6341 (org-overlay-display ov
">>"
6342 (org-get-todo-face "TODO")
6344 (org-overlay-put ov
'type
'org-marked-entry-overlay
))
6345 (beginning-of-line 2)
6346 (message "%d entries marked for bulk action"
6347 (length org-agenda-bulk-marked-entries
))))
6349 (defun org-agenda-bulk-unmark ()
6350 "Unmark the entry at point for future bulk action."
6352 (when (org-agenda-bulk-marked-p)
6353 (org-agenda-bulk-remove-overlays
6354 (point-at-bol) (+ 2 (point-at-bol)))
6355 (setq org-agenda-bulk-marked-entries
6356 (delete (get-text-property (point-at-bol) 'org-hd-marker
)
6357 org-agenda-bulk-marked-entries
)))
6358 (beginning-of-line 2)
6359 (message "%d entries marked for bulk action"
6360 (length org-agenda-bulk-marked-entries
)))
6362 (defun org-agenda-bulk-toggle ()
6363 "Toggle marking the entry at point for bulk action."
6365 (if (org-agenda-bulk-marked-p)
6366 (org-agenda-bulk-unmark)
6367 (org-agenda-bulk-mark)))
6369 (defun org-agenda-bulk-remove-overlays (&optional beg end
)
6370 "Remove the mark overlays between BEG and END in the agenda buffer.
6371 BEG and END default to the buffer limits.
6373 This only removes the overlays, it does not remove the markers
6374 from the list in `org-agenda-bulk-marked-entries'."
6377 (and (eq (org-overlay-get ov
'type
) 'org-marked-entry-overlay
)
6378 (org-delete-overlay ov
)))
6379 (org-overlays-in (or beg
(point-min)) (or end
(point-max)))))
6381 (defun org-agenda-bulk-remove-all-marks ()
6382 "Remove all marks in the agenda buffer.
6383 This will remove the markers, and the overlays."
6385 (mapc (lambda (m) (move-marker m nil
)) org-agenda-bulk-marked-entries
)
6386 (setq org-agenda-bulk-marked-entries nil
)
6387 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
6389 (defun org-agenda-bulk-action ()
6390 "Execute an remote-editing action on all marked entries."
6392 (unless org-agenda-bulk-marked-entries
6393 (error "No entries are marked"))
6394 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
6395 (let* ((action (read-char-exclusive))
6396 (entries (reverse org-agenda-bulk-marked-entries
))
6397 cmd rfloc state e tag pos
(cnt 0) (cntskip 0))
6400 (setq cmd
'(org-agenda-archive)))
6403 (setq cmd
'(org-agenda-archive-to-archive-sibling)))
6405 ((member action
'(?r ?w
))
6406 (setq rfloc
(org-refile-get-location
6408 (marker-buffer (car org-agenda-bulk-marked-entries
))
6409 org-refile-allow-creating-parent-nodes
))
6410 (setcar (nthcdr 3 rfloc
)
6411 (move-marker (make-marker) (nth 3 rfloc
)
6412 (or (get-file-buffer (nth 1 rfloc
))
6413 (find-buffer-visiting (nth 1 rfloc
))
6414 (error "This should not happen"))))
6416 (setq cmd
(list 'org-agenda-refile nil
(list 'quote rfloc
))))
6419 (setq state
(org-ido-completing-read
6421 (with-current-buffer (marker-buffer (car entries
))
6422 (mapcar 'list org-todo-keywords-1
))))
6423 (setq cmd
`(let ((org-inhibit-blocking t
)
6424 (org-inhibit-logging 'note
))
6425 (org-agenda-todo ,state
))))
6427 ((memq action
'(?- ?
+))
6428 (setq tag
(org-ido-completing-read
6429 (format "Tag to %s: " (if (eq action ?
+) "add" "remove"))
6430 (with-current-buffer (marker-buffer (car entries
))
6433 (if (stringp (car x
)) x
)) org-tag-alist
)))))
6434 (setq cmd
`(org-agenda-set-tags ,tag
,(if (eq action ?
+) ''on
''off
))))
6436 ((memq action
'(?s ?d
))
6437 (let* ((date (org-read-date
6439 (if (eq action ?s
) "(Re)Schedule to" "Set Deadline to")))
6440 (ans org-read-date-final-answer
)
6441 (c1 (if (eq action ?s
) 'org-agenda-schedule
'org-agenda-deadline
)))
6442 (setq cmd
`(let* ((bound (fboundp 'read-string
))
6443 (old (and bound
(symbol-function 'read-string
))))
6446 (fset 'read-string
(lambda (&rest ignore
) ,ans
))
6447 (call-interactively ',c1
))
6449 (fset 'read-string old
)
6450 (fmakunbound 'read-string
)))))))
6451 (t (error "Invalid bulk action")))
6453 ;; Sort the markers, to make sure that parents are handled before children
6454 (setq entries
(sort entries
6457 ((equal (marker-buffer a
) (marker-buffer b
))
6458 (< (marker-position a
) (marker-position b
)))
6460 (string< (buffer-name (marker-buffer a
))
6461 (buffer-name (marker-buffer b
))))))))
6463 ;; Now loop over all markers and apply cmd
6464 (while (setq e
(pop entries
))
6465 (setq pos
(text-property-any (point-min) (point-max) 'org-hd-marker e
))
6467 (progn (message "Skipping removed entry at %s" e
)
6468 (setq cntskip
(1+ cntskip
)))
6471 (setq org-agenda-bulk-marked-entries
6472 (delete e org-agenda-bulk-marked-entries
))
6473 (setq cnt
(1+ cnt
))))
6474 (setq org-agenda-bulk-marked-entries nil
)
6475 (org-agenda-bulk-remove-all-marks)
6476 (message "Acted on %d entries%s"
6480 (format ", skipped %d (disappeared before their turn)"
6483 ;;; Appointment reminders
6485 (defvar appt-time-msg-list
)
6488 (defun org-agenda-to-appt (&optional refresh filter
)
6489 "Activate appointments found in `org-agenda-files'.
6490 With a \\[universal-argument] prefix, refresh the list of
6493 If FILTER is t, interactively prompt the user for a regular
6494 expression, and filter out entries that don't match it.
6496 If FILTER is a string, use this string as a regular expression
6497 for filtering entries out.
6499 FILTER can also be an alist with the car of each cell being
6500 either 'headline or 'category. For example:
6502 '((headline \"IMPORTANT\")
6503 (category \"Work\"))
6505 will only add headlines containing IMPORTANT or headlines
6506 belonging to the \"Work\" category."
6509 (if refresh
(setq appt-time-msg-list nil
))
6511 (setq filter
(read-from-minibuffer "Regexp filter: ")))
6512 (let* ((cnt 0) ; count added events
6513 (org-agenda-new-buffers nil
)
6514 (org-deadline-warning-days 0)
6515 (today (org-date-to-gregorian
6516 (time-to-days (current-time))))
6517 (org-agenda-restrict nil
)
6518 (files (org-agenda-files 'unrestricted
)) entries file
)
6519 ;; Get all entries which may contain an appt
6520 (org-prepare-agenda-buffers files
)
6521 (while (setq file
(pop files
))
6524 (org-agenda-get-day-entries
6525 file today
:timestamp
:scheduled
:deadline
))))
6526 (setq entries
(delq nil entries
))
6527 ;; Map thru entries and find if we should filter them out
6530 (let* ((evt (org-trim (or (get-text-property 1 'txt x
) "")))
6531 (cat (get-text-property 1 'org-category x
))
6532 (tod (get-text-property 1 'time-of-day x
))
6533 (ok (or (null filter
)
6534 (and (stringp filter
) (string-match filter evt
))
6537 (cadr (assoc 'category filter
)) cat
)
6539 (cadr (assoc 'headline filter
)) evt
))))))
6540 ;; FIXME: Shall we remove text-properties for the appt text?
6541 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
6543 (setq tod
(concat "00" (number-to-string tod
))
6544 tod
(when (string-match
6545 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod
)
6546 (concat (match-string 1 tod
) ":"
6547 (match-string 2 tod
))))
6549 (setq cnt
(1+ cnt
))))) entries
)
6550 (org-release-buffers org-agenda-new-buffers
)
6552 (message "No event to add")
6553 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
6555 (defun org-agenda-todayp (date)
6556 "Does DATE mean today, when considering `org-extend-today-until'?"
6558 (if (listp date
) (setq date
(calendar-absolute-from-gregorian date
)))
6559 (setq today
(calendar-absolute-from-gregorian (calendar-current-date)))
6560 (setq h
(nth 2 (decode-time (current-time))))
6561 (or (and (>= h org-extend-today-until
)
6563 (and (< h org-extend-today-until
)
6564 (= date
(1- today
))))))
6566 (provide 'org-agenda
)
6568 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
6570 ;;; org-agenda.el ends here