1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
38 (declare-function diary-add-to-list
"diary-lib"
39 (date string specifier
&optional marker globcolor literal
))
40 (declare-function calendar-absolute-from-iso
"cal-iso" (date))
41 (declare-function calendar-astro-date-string
"cal-julian" (&optional date
))
42 (declare-function calendar-bahai-date-string
"cal-bahai" (&optional date
))
43 (declare-function calendar-check-holidays
"holidays" (date))
44 (declare-function calendar-chinese-date-string
"cal-china" (&optional date
))
45 (declare-function calendar-coptic-date-string
"cal-coptic" (&optional date
))
46 (declare-function calendar-ethiopic-date-string
"cal-coptic" (&optional date
))
47 (declare-function calendar-french-date-string
"cal-french" (&optional date
))
48 (declare-function calendar-goto-date
"cal-move" (date))
49 (declare-function calendar-hebrew-date-string
"cal-hebrew" (&optional date
))
50 (declare-function calendar-islamic-date-string
"cal-islam" (&optional date
))
51 (declare-function calendar-iso-date-string
"cal-iso" (&optional date
))
52 (declare-function calendar-iso-from-absolute
"cal-iso" (date))
53 (declare-function calendar-julian-date-string
"cal-julian" (&optional date
))
54 (declare-function calendar-mayan-date-string
"cal-mayan" (&optional date
))
55 (declare-function calendar-persian-date-string
"cal-persia" (&optional date
))
56 (declare-function org-columns-quit
"org-colview" ())
57 (defvar calendar-mode-map
)
59 ;; Defined somewhere in this file, but used before definition.
60 (defvar org-agenda-buffer-name
)
61 (defvar org-agenda-overriding-header
)
64 (defvar org-agenda-undo-list
)
65 (defvar org-agenda-pending-undo-list
)
66 (defvar original-date
) ; dynamically scoped, calendar.el does scope this
68 (defcustom org-agenda-confirm-kill
1
69 "When set, remote killing from the agenda buffer needs confirmation.
70 When t, a confirmation is always needed. When a number N, confirmation is
71 only needed when the text to be killed contains more than N non-white lines."
74 (const :tag
"Never" nil
)
75 (const :tag
"Always" t
)
76 (integer :tag
"When more than N lines")))
78 (defcustom org-agenda-compact-blocks nil
79 "Non-nil means, make the block agenda more compact.
80 This is done by leaving out unnecessary lines."
84 (defcustom org-agenda-block-separator ?
=
85 "The separator between blocks in the agenda.
86 If this is a string, it will be used as the separator, with a newline added.
87 If it is a character, it will be repeated to fill the window width."
93 (defgroup org-agenda-export nil
94 "Options concerning exporting agenda views in Org-mode."
95 :tag
"Org Agenda Export"
98 (defcustom org-agenda-with-colors t
99 "Non-nil means, use colors in agenda views."
100 :group
'org-agenda-export
103 (defcustom org-agenda-exporter-settings nil
104 "Alist of variable/value pairs that should be active during agenda export.
105 This is a good place to set options for ps-print and for htmlize."
106 :group
'org-agenda-export
110 (sexp :tag
"Value"))))
112 (defcustom org-agenda-before-write-hook
'(org-agenda-add-entry-text)
113 "Hook run in temporary buffer before writing it to an export file.
114 A useful function is `org-agenda-add-entry-text'."
115 :group
'org-agenda-export
117 :options
'(org-agenda-add-entry-text))
119 (defcustom org-agenda-add-entry-text-maxlines
0
120 "Maximum number of entry text lines to be added to agenda.
121 This is only relevant when `org-agenda-add-entry-text' is part of
122 `org-agenda-before-write-hook', which it is by default.
123 When this is 0, nothing will happen. When it is greater than 0, it
124 specifies the maximum number of lines that will be added for each entry
125 that is listed in the agenda view."
129 (defcustom org-agenda-add-entry-text-descriptive-links t
130 "Non-nil means, export org-links as descriptive links in agenda added text.
131 This variable applies to the text added to the agenda when
132 `org-agenda-add-entry-text-maxlines' is larger than 0.
133 When this variable nil, the URL will (also) be shown."
137 (defcustom org-agenda-export-html-style
""
138 "The style specification for exported HTML Agenda files.
139 If this variable contains a string, it will replace the default <style>
140 section as produced by `htmlize'.
141 Since there are different ways of setting style information, this variable
142 needs to contain the full HTML structure to provide a style, including the
143 surrounding HTML tags. The style specifications should include definitions
144 the fonts used by the agenda, here is an example:
146 <style type=\"text/css\">
147 p { font-weight: normal; color: gray; }
148 .org-agenda-structure {
163 .title { text-align: center; }
164 .todo, .deadline { color: red; }
165 .done { color: green; }
168 or, if you want to keep the style in a file,
170 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
172 As the value of this option simply gets inserted into the HTML <head> header,
173 you can \"misuse\" it to also add other text to the header. However,
174 <style>...</style> is required, if not present the variable will be ignored."
175 :group
'org-agenda-export
176 :group
'org-export-html
179 (defgroup org-agenda-custom-commands nil
180 "Options concerning agenda views in Org-mode."
181 :tag
"Org Agenda Custom Commands"
184 (defconst org-sorting-choice
186 (const time-up
) (const time-down
)
187 (const category-keep
) (const category-up
) (const category-down
)
188 (const tag-down
) (const tag-up
)
189 (const priority-up
) (const priority-down
)
190 (const todo-state-up
) (const todo-state-down
)
191 (const effort-up
) (const effort-down
)
192 (const user-defined-up
) (const user-defined-down
))
195 (defconst org-agenda-custom-commands-local-options
196 `(repeat :tag
"Local settings for this command. Remember to quote values"
197 (choice :tag
"Setting"
198 (list :tag
"Heading for this block"
199 (const org-agenda-overriding-header
)
200 (string :tag
"Headline"))
201 (list :tag
"Files to be searched"
202 (const org-agenda-files
)
204 (const :format
"" quote
)
206 (list :tag
"Sorting strategy"
207 (const org-agenda-sorting-strategy
)
209 (const :format
"" quote
)
211 ,org-sorting-choice
)))
212 (list :tag
"Prefix format"
213 (const org-agenda-prefix-format
:value
" %-12:c%?-12t% s")
215 (list :tag
"Number of days in agenda"
216 (const org-agenda-ndays
)
218 (list :tag
"Fixed starting date"
219 (const org-agenda-start-day
)
220 (string :value
"2007-11-01"))
221 (list :tag
"Start on day of week"
222 (const org-agenda-start-on-weekday
)
224 (const :tag
"Today" nil
)
225 (integer :tag
"Weekday No.")))
226 (list :tag
"Include data from diary"
227 (const org-agenda-include-diary
)
229 (list :tag
"Deadline Warning days"
230 (const org-deadline-warning-days
)
232 (list :tag
"Tags filter preset"
233 (const org-agenda-filter-preset
)
235 (const :format
"" quote
)
237 (string :tag
"+tag or -tag"))))
238 (list :tag
"Standard skipping condition"
239 :value
(org-agenda-skip-function '(org-agenda-skip-entry-if))
240 (const org-agenda-skip-function
)
242 (const :format
"" quote
)
245 :tag
"Skipping range"
246 (const :tag
"Skip entry" org-agenda-skip-entry-if
)
247 (const :tag
"Skip subtree" org-agenda-skip-subtree-if
))
248 (repeat :inline t
:tag
"Conditions for skipping"
250 :tag
"Condition type"
251 (list :tag
"Regexp matches" :inline t
(const :format
"" 'regexp
) (regexp))
252 (list :tag
"Regexp does not match" :inline t
(const :format
"" 'notregexp
) (regexp))
253 (const :tag
"scheduled" 'scheduled
)
254 (const :tag
"not scheduled" 'notscheduled
)
255 (const :tag
"deadline" 'deadline
)
256 (const :tag
"no deadline" 'notdeadline
)
257 (const :tag
"timestamp" 'timestamp
)
258 (const :tag
"no timestamp" 'nottimestamp
))))))
259 (list :tag
"Non-standard skipping condition"
260 :value
(org-agenda-skip-function)
261 (const org-agenda-skip-function
)
262 (sexp :tag
"Function or form (quoted!)"))
263 (list :tag
"Any variable"
264 (variable :tag
"Variable")
265 (sexp :tag
"Value (sexp)"))))
266 "Selection of examples for agenda command settings.
267 This will be spliced into the custom type of
268 `org-agenda-custom-commands'.")
271 (defcustom org-agenda-custom-commands nil
272 "Custom commands for the agenda.
273 These commands will be offered on the splash screen displayed by the
274 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
276 (key desc type match settings files)
278 key The key (one or more characters as a string) to be associated
280 desc A description of the command, when omitted or nil, a default
281 description is built using MATCH.
282 type The command type, any of the following symbols:
283 agenda The daily/weekly agenda.
284 todo Entries with a specific TODO keyword, in all agenda files.
285 search Entries containing search words entry or headline.
286 tags Tags/Property/TODO match in all agenda files.
287 tags-todo Tags/P/T match in all agenda files, TODO entries only.
288 todo-tree Sparse tree of specific TODO keyword in *current* file.
289 tags-tree Sparse tree with all tags matches in *current* file.
290 occur-tree Occur sparse tree for *current* file.
291 ... A user-defined function.
292 match What to search for:
293 - a single keyword for TODO keyword searches
294 - a tags match expression for tags searches
295 - a word search expression for text searches.
296 - a regular expression for occur searches
297 For all other commands, this should be the empty string.
298 settings A list of option settings, similar to that in a let form, so like
299 this: ((opt1 val1) (opt2 val2) ...). The values will be
300 evaluated at the moment of execution, so quote them when needed.
301 files A list of files file to write the produced agenda buffer to
302 with the command `org-store-agenda-views'.
303 If a file name ends in \".html\", an HTML version of the buffer
304 is written out. If it ends in \".ps\", a postscript version is
305 produced. Otherwise, only the plain text is written to the file.
307 You can also define a set of commands, to create a composite agenda buffer.
308 In this case, an entry looks like this:
310 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
314 desc A description string to be displayed in the dispatcher menu.
315 cmd An agenda command, similar to the above. However, tree commands
316 are no allowed, but instead you can get agenda and global todo list.
317 So valid commands for a set are:
318 (agenda \"\" settings)
319 (alltodo \"\" settings)
320 (stuck \"\" settings)
321 (todo \"match\" settings files)
322 (search \"match\" settings files)
323 (tags \"match\" settings files)
324 (tags-todo \"match\" settings files)
326 Each command can carry a list of options, and another set of options can be
327 given for the whole set of commands. Individual command options take
328 precedence over the general options.
330 When using several characters as key to a command, the first characters
331 are prefix commands. For the dispatcher to display useful information, you
332 should provide a description for the prefix, like
334 (setq org-agenda-custom-commands
335 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
336 (\"hl\" tags \"+HOME+Lisa\")
337 (\"hp\" tags \"+HOME+Peter\")
338 (\"hk\" tags \"+HOME+Kim\")))"
339 :group
'org-agenda-custom-commands
341 (choice :value
("x" "Describe command here" tags
"" nil
)
342 (list :tag
"Single command"
343 (string :tag
"Access Key(s) ")
344 (option (string :tag
"Description"))
346 (const :tag
"Agenda" agenda
)
347 (const :tag
"TODO list" alltodo
)
348 (const :tag
"Search words" search
)
349 (const :tag
"Stuck projects" stuck
)
350 (const :tag
"Tags/Property match (all agenda files)" tags
)
351 (const :tag
"Tags/Property match of TODO entries (all agenda files)" tags-todo
)
352 (const :tag
"TODO keyword search (all agenda files)" todo
)
353 (const :tag
"Tags sparse tree (current buffer)" tags-tree
)
354 (const :tag
"TODO keyword tree (current buffer)" todo-tree
)
355 (const :tag
"Occur tree (current buffer)" occur-tree
)
356 (sexp :tag
"Other, user-defined function"))
357 (string :tag
"Match (only for some commands)")
358 ,org-agenda-custom-commands-local-options
359 (option (repeat :tag
"Export" (file :tag
"Export to"))))
360 (list :tag
"Command series, all agenda files"
361 (string :tag
"Access Key(s)")
362 (string :tag
"Description ")
363 (repeat :tag
"Component"
366 (const :format
"" agenda
)
367 (const :tag
"" :format
"" "")
368 ,org-agenda-custom-commands-local-options
)
369 (list :tag
"TODO list (all keywords)"
370 (const :format
"" alltodo
)
371 (const :tag
"" :format
"" "")
372 ,org-agenda-custom-commands-local-options
)
373 (list :tag
"Search words"
374 (const :format
"" search
)
375 (string :tag
"Match")
376 ,org-agenda-custom-commands-local-options
)
377 (list :tag
"Stuck projects"
378 (const :format
"" stuck
)
379 (const :tag
"" :format
"" "")
380 ,org-agenda-custom-commands-local-options
)
381 (list :tag
"Tags search"
382 (const :format
"" tags
)
383 (string :tag
"Match")
384 ,org-agenda-custom-commands-local-options
)
385 (list :tag
"Tags search, TODO entries only"
386 (const :format
"" tags-todo
)
387 (string :tag
"Match")
388 ,org-agenda-custom-commands-local-options
)
389 (list :tag
"TODO keyword search"
390 (const :format
"" todo
)
391 (string :tag
"Match")
392 ,org-agenda-custom-commands-local-options
)
393 (list :tag
"Other, user-defined function"
394 (symbol :tag
"function")
395 (string :tag
"Match")
396 ,org-agenda-custom-commands-local-options
)))
398 (repeat :tag
"Settings for entire command set"
399 (list (variable :tag
"Any variable")
400 (sexp :tag
"Value")))
401 (option (repeat :tag
"Export" (file :tag
"Export to"))))
402 (cons :tag
"Prefix key documentation"
403 (string :tag
"Access Key(s)")
404 (string :tag
"Description ")))))
406 (defcustom org-agenda-query-register ?o
407 "The register holding the current query string.
408 The purpose of this is that if you construct a query string interactively,
409 you can then use it to define a custom command."
410 :group
'org-agenda-custom-commands
413 (defcustom org-stuck-projects
414 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil
"")
415 "How to identify stuck projects.
416 This is a list of four items:
417 1. A tags/todo/property matcher string that is used to identify a project.
418 See the manual for a description of tag and property searches.
419 The entire tree below a headline matched by this is considered one project.
420 2. A list of TODO keywords identifying non-stuck projects.
421 If the project subtree contains any headline with one of these todo
422 keywords, the project is considered to be not stuck. If you specify
423 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
424 3. A list of tags identifying non-stuck projects.
425 If the project subtree contains any headline with one of these tags,
426 the project is considered to be not stuck. If you specify \"*\" as
427 a tag, any tag will mark the project unstuck. Note that this is about
428 the explicit presence of a tag somewhere in the subtree, inherited
429 tags to not count here. If inherited tags make a project not stuck,
430 use \"-TAG\" in the tags part of the matcher under (1.) above.
431 4. An arbitrary regular expression matching non-stuck projects.
433 If the project turns out to be not stuck, search continues also in the
434 subtree to see if any of the subtasks have project status.
436 See also the variable `org-tags-match-list-sublevels' which applies
437 to projects matched by this search as well.
439 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
440 or `C-c a #' to produce the list."
441 :group
'org-agenda-custom-commands
443 (string :tag
"Tags/TODO match to identify a project")
444 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
445 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
446 (regexp :tag
"Projects are *not* stuck if this regexp matches inside the subtree")))
448 (defcustom org-agenda-filter-effort-default-operator
"<"
449 "The default operator for effort estimate filtering.
450 If you select an effort estimate limit without first pressing an operator,
451 this one will be used."
452 :group
'org-agenda-custom-commands
453 :type
'(choice (const :tag
"less or equal" "<")
454 (const :tag
"greater or equal"">")
455 (const :tag
"equal" "=")))
457 (defgroup org-agenda-skip nil
458 "Options concerning skipping parts of agenda files."
459 :tag
"Org Agenda Skip"
461 (defgroup org-agenda-daily
/weekly nil
462 "Options concerning the daily/weekly agenda."
463 :tag
"Org Agenda Daily/Weekly"
465 (defgroup org-agenda-todo-list nil
466 "Options concerning the global todo list agenda view."
467 :tag
"Org Agenda Todo List"
469 (defgroup org-agenda-match-view nil
470 "Options concerning the general tags/property/todo match agenda view."
471 :tag
"Org Agenda Match View"
474 (defvar org-agenda-archives-mode nil
475 "Non-nil means, the agenda will include archived items.
476 If this is the symbol `trees', trees in the selected agenda scope
477 that are marked with the ARCHIVE tag will be included anyway. When this is
478 t, also all archive files associated with the current selection of agenda
479 files will be included.")
481 (defcustom org-agenda-skip-comment-trees t
482 "Non-nil means, skip trees that start with the COMMENT keyword.
483 When nil, these trees are also scanned by agenda commands."
484 :group
'org-agenda-skip
487 (defcustom org-agenda-todo-list-sublevels t
488 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
489 When nil, the sublevels of a TODO entry are not checked, resulting in
490 potentially much shorter TODO lists."
491 :group
'org-agenda-skip
492 :group
'org-agenda-todo-list
495 (defcustom org-agenda-todo-ignore-with-date nil
496 "Non-nil means, don't show entries with a date in the global todo list.
497 You can use this if you prefer to mark mere appointments with a TODO keyword,
498 but don't want them to show up in the TODO list.
499 When this is set, it also covers deadlines and scheduled items, the settings
500 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
502 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
503 :group
'org-agenda-skip
504 :group
'org-agenda-todo-list
507 (defcustom org-agenda-todo-ignore-scheduled nil
508 "Non-nil means, don't show scheduled entries in the global todo list.
509 The idea behind this is that by scheduling it, you have already taken care
511 See also `org-agenda-todo-ignore-with-date'.
512 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
513 :group
'org-agenda-skip
514 :group
'org-agenda-todo-list
517 (defcustom org-agenda-todo-ignore-deadlines nil
518 "Non-nil means, don't show near deadline entries in the global todo list.
519 Near means closer than `org-deadline-warning-days' days.
520 The idea behind this is that such items will appear in the agenda anyway.
521 See also `org-agenda-todo-ignore-with-date'.
522 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
523 :group
'org-agenda-skip
524 :group
'org-agenda-todo-list
527 (defcustom org-agenda-tags-todo-honor-ignore-options nil
528 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
530 `org-agenda-todo-ignore-with-date',
531 `org-agenda-todo-ignore-scheduled'
532 `org-agenda-todo-ignore-deadlines'
533 make the global TODO list skip entries that have time stamps of certain
534 kinds. If this option is set, the same options will also apply for the
535 tags-todo search, which is the general tags/property matcher
536 restricted to unfinished TODO entries only."
537 :group
'org-agenda-skip
538 :group
'org-agenda-todo-list
539 :group
'org-agenda-match-view
542 (defcustom org-agenda-skip-scheduled-if-done nil
543 "Non-nil means don't show scheduled items in agenda when they are done.
544 This is relevant for the daily/weekly agenda, not for the TODO list. And
545 it applies only to the actual date of the scheduling. Warnings about
546 an item with a past scheduling dates are always turned off when the item
548 :group
'org-agenda-skip
549 :group
'org-agenda-daily
/weekly
552 (defcustom org-agenda-skip-deadline-if-done nil
553 "Non-nil means don't show deadlines when the corresponding item is done.
554 When nil, the deadline is still shown and should give you a happy feeling.
555 This is relevant for the daily/weekly agenda. And it applied only to the
556 actually date of the deadline. Warnings about approaching and past-due
557 deadlines are always turned off when the item is DONE."
558 :group
'org-agenda-skip
559 :group
'org-agenda-daily
/weekly
562 (defcustom org-agenda-skip-additional-timestamps-same-entry t
563 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
564 When non-nil, after the search for timestamps has matched once in an
565 entry, the rest of the entry will not be searched."
566 :group
'org-agenda-skip
569 (defcustom org-agenda-skip-timestamp-if-done nil
570 "Non-nil means don't select item by timestamp or -range if it is DONE."
571 :group
'org-agenda-skip
572 :group
'org-agenda-daily
/weekly
575 (defcustom org-agenda-dim-blocked-tasks t
576 "Non-nil means, dim blocked tasks in the agenda display.
577 This causes some overhead during agenda construction, but if you
578 have turned on `org-enforce-todo-dependencies',
579 `org-enforce-todo-checkbox-dependencies', or any other blocking
580 mechanism, this will create useful feedback in the agenda.
582 Instead ot t, this variable can also have the value `invisible'.
583 Then blocked tasks will be invisible and only become visible when
584 they become unblocked. An exemption to this behavior is when a task is
585 blocked because of unchecked checkboxes below it. Since checkboxes do
586 not show up in the agenda views, making this task invisible you remove any
587 trace from agenda views that there is something to do. Therefore, a task
588 that is blocked because of checkboxes will never be made invisible, it
589 will only be dimmed."
590 :group
'org-agenda-daily
/weekly
591 :group
'org-agenda-todo-list
593 (const :tag
"Do not dim" nil
)
594 (const :tag
"Dim to a grey face" t
)
595 (const :tag
"Make invisibe" invisible
)))
597 (defcustom org-timeline-show-empty-dates
3
598 "Non-nil means, `org-timeline' also shows dates without an entry.
599 When nil, only the days which actually have entries are shown.
600 When t, all days between the first and the last date are shown.
601 When an integer, show also empty dates, but if there is a gap of more than
602 N days, just insert a special line indicating the size of the gap."
603 :group
'org-agenda-skip
605 (const :tag
"None" nil
)
607 (integer :tag
"at most")))
609 (defgroup org-agenda-startup nil
610 "Options concerning initial settings in the Agenda in Org Mode."
611 :tag
"Org Agenda Startup"
614 (defcustom org-finalize-agenda-hook nil
615 "Hook run just before displaying an agenda buffer."
616 :group
'org-agenda-startup
619 (defcustom org-agenda-mouse-1-follows-link nil
620 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
621 A longer mouse click will still set point. Does not work on XEmacs.
622 Needs to be set before org.el is loaded."
623 :group
'org-agenda-startup
626 (defcustom org-agenda-start-with-follow-mode nil
627 "The initial value of follow-mode in a newly created agenda window."
628 :group
'org-agenda-startup
631 (defvar org-agenda-include-inactive-timestamps nil
632 "Non-nil means, include inactive time stamps in agenda and timeline.")
634 (defgroup org-agenda-windows nil
635 "Options concerning the windows used by the Agenda in Org Mode."
636 :tag
"Org Agenda Windows"
639 (defcustom org-agenda-window-setup
'reorganize-frame
640 "How the agenda buffer should be displayed.
641 Possible values for this option are:
643 current-window Show agenda in the current window, keeping all other windows.
644 other-frame Use `switch-to-buffer-other-frame' to display agenda.
645 other-window Use `switch-to-buffer-other-window' to display agenda.
646 reorganize-frame Show only two windows on the current frame, the current
647 window and the agenda.
648 See also the variable `org-agenda-restore-windows-after-quit'."
649 :group
'org-agenda-windows
651 (const current-window
)
654 (const reorganize-frame
)))
656 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
657 "The min and max height of the agenda window as a fraction of frame height.
658 The value of the variable is a cons cell with two numbers between 0 and 1.
659 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
660 :group
'org-agenda-windows
661 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
663 (defcustom org-agenda-restore-windows-after-quit nil
664 "Non-nil means, restore window configuration open exiting agenda.
665 Before the window configuration is changed for displaying the agenda,
666 the current status is recorded. When the agenda is exited with
667 `q' or `x' and this option is set, the old state is restored. If
668 `org-agenda-window-setup' is `other-frame', the value of this
669 option will be ignored.."
670 :group
'org-agenda-windows
673 (defcustom org-agenda-ndays
7
674 "Number of days to include in overview display.
676 Custom commands can set this variable in the options section."
677 :group
'org-agenda-daily
/weekly
680 (defcustom org-agenda-start-on-weekday
1
681 "Non-nil means, start the overview always on the specified weekday.
682 0 denotes Sunday, 1 denotes Monday etc.
683 When nil, always start on the current day.
684 Custom commands can set this variable in the options section."
685 :group
'org-agenda-daily
/weekly
686 :type
'(choice (const :tag
"Today" nil
)
687 (integer :tag
"Weekday No.")))
689 (defcustom org-agenda-show-all-dates t
690 "Non-nil means, `org-agenda' shows every day in the selected range.
691 When nil, only the days which actually have entries are shown."
692 :group
'org-agenda-daily
/weekly
695 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
696 "Format string for displaying dates in the agenda.
697 Used by the daily/weekly agenda and by the timeline. This should be
698 a format string understood by `format-time-string', or a function returning
699 the formatted date as a string. The function must take a single argument,
700 a calendar-style date list like (month day year)."
701 :group
'org-agenda-daily
/weekly
703 (string :tag
"Format string")
704 (function :tag
"Function")))
706 (defun org-agenda-format-date-aligned (date)
707 "Format a date string for display in the daily/weekly agenda, or timeline.
708 This function makes sure that dates are aligned for easy reading."
710 (let* ((dayname (calendar-day-name date
))
712 (day-of-week (calendar-day-of-week date
))
714 (monthname (calendar-month-name month
))
716 (iso-week (org-days-to-iso-week
717 (calendar-absolute-from-gregorian date
)))
718 (weekyear (cond ((and (= month
1) (>= iso-week
52))
720 ((and (= month
12) (<= iso-week
1))
723 (weekstring (if (= day-of-week
1)
724 (format " W%02d" iso-week
)
726 (format "%-10s %2d %s %4d%s"
727 dayname day monthname year weekstring
)))
729 (defcustom org-agenda-weekend-days
'(6 0)
730 "Which days are weekend?
731 These days get the special face `org-agenda-date-weekend' in the agenda
732 and timeline buffers."
733 :group
'org-agenda-daily
/weekly
734 :type
'(set :greedy t
735 (const :tag
"Monday" 1)
736 (const :tag
"Tuesday" 2)
737 (const :tag
"Wednesday" 3)
738 (const :tag
"Thursday" 4)
739 (const :tag
"Friday" 5)
740 (const :tag
"Saturday" 6)
741 (const :tag
"Sunday" 0)))
743 (defcustom org-agenda-include-diary nil
744 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
745 Custom commands can set this variable in the options section."
746 :group
'org-agenda-daily
/weekly
749 (defcustom org-agenda-include-all-todo nil
750 "Set means weekly/daily agenda will always contain all TODO entries.
751 The TODO entries will be listed at the top of the agenda, before
752 the entries for specific days.
753 This option is deprecated, it is better to define a block agenda instead."
754 :group
'org-agenda-daily
/weekly
757 (defcustom org-agenda-repeating-timestamp-show-all t
758 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
759 When nil, only one occurrence is shown, either today or the
760 nearest into the future."
761 :group
'org-agenda-daily
/weekly
764 (defcustom org-scheduled-past-days
10000
765 "No. of days to continue listing scheduled items that are not marked DONE.
766 When an item is scheduled on a date, it shows up in the agenda on this
767 day and will be listed until it is marked done for the number of days
769 :group
'org-agenda-daily
/weekly
772 (defcustom org-agenda-log-mode-items
'(closed clock
)
773 "List of items that should be shown in agenda log mode.
774 This list may contain the following symbols:
776 closed Show entries that have been closed on that day.
777 clock Show entries that have received clocked time on that day.
778 state Show all logged state changes.
779 Note that instead of changing this variable, you can also press `C-u l' in
780 the agenda to display all available LOG items temporarily."
781 :group
'org-agenda-daily
/weekly
782 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
784 (defcustom org-agenda-log-mode-add-notes t
785 "Non-nil means, add first line of notes to log entries in agenda views.
786 If a log item like a state change or a clock entry is associated with
787 notes, the first line of these notes will be added to the entry in the
789 :group
'org-agenda-daily
/weekly
792 (defcustom org-agenda-start-with-log-mode nil
793 "The initial value of log-mode in a newly created agenda window."
794 :group
'org-agenda-startup
795 :group
'org-agenda-daily
/weekly
798 (defcustom org-agenda-start-with-clockreport-mode nil
799 "The initial value of clockreport-mode in a newly created agenda window."
800 :group
'org-agenda-startup
801 :group
'org-agenda-daily
/weekly
804 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
805 "Property list with parameters for the clocktable in clockreport mode.
806 This is the display mode that shows a clock table in the daily/weekly
807 agenda, the properties for this dynamic block can be set here.
808 The usual clocktable parameters are allowed here, but you cannot set
809 the properties :name, :tstart, :tend, :block, and :scope - these will
810 be overwritten to make sure the content accurately reflects the
811 current display in the agenda."
812 :group
'org-agenda-daily
/weekly
816 (defgroup org-agenda-time-grid nil
817 "Options concerning the time grid in the Org-mode Agenda."
818 :tag
"Org Agenda Time Grid"
821 (defcustom org-agenda-search-headline-for-time t
822 "Non-nil means, search headline for a time-of-day.
823 If the headline contains a time-of-day in one format or another, it will
824 be used to sort the entry into the time sequence of items for a day.
825 Some people have time stamps in the headline that refer to the creation
826 time or so, and then this produces an unwanted side effect. If this is
827 the case for your, use this variable to turn off searching the headline
829 :group
'org-agenda-time-grid
832 (defcustom org-agenda-use-time-grid t
833 "Non-nil means, show a time grid in the agenda schedule.
834 A time grid is a set of lines for specific times (like every two hours between
835 8:00 and 20:00). The items scheduled for a day at specific times are
836 sorted in between these lines.
837 For details about when the grid will be shown, and what it will look like, see
838 the variable `org-agenda-time-grid'."
839 :group
'org-agenda-time-grid
842 (defcustom org-agenda-time-grid
843 '((daily today require-timed
)
845 (800 1000 1200 1400 1600 1800 2000))
847 "The settings for time grid for agenda display.
848 This is a list of three items. The first item is again a list. It contains
849 symbols specifying conditions when the grid should be displayed:
851 daily if the agenda shows a single day
852 weekly if the agenda shows an entire week
853 today show grid on current date, independent of daily/weekly display
854 require-timed show grid only if at least one item has a time specification
856 The second item is a string which will be placed behind the grid time.
858 The third item is a list of integers, indicating the times that should have
860 :group
'org-agenda-time-grid
863 (set :greedy t
:tag
"Grid Display Options"
864 (const :tag
"Show grid in single day agenda display" daily
)
865 (const :tag
"Show grid in weekly agenda display" weekly
)
866 (const :tag
"Always show grid for today" today
)
867 (const :tag
"Show grid only if any timed entries are present"
869 (const :tag
"Skip grid times already present in an entry"
871 (string :tag
"Grid String")
872 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
874 (defgroup org-agenda-sorting nil
875 "Options concerning sorting in the Org-mode Agenda."
876 :tag
"Org Agenda Sorting"
879 (defcustom org-agenda-sorting-strategy
880 '((agenda time-up priority-down category-keep
)
881 (todo priority-down category-keep
)
882 (tags priority-down category-keep
)
883 (search category-keep
))
884 "Sorting structure for the agenda items of a single day.
885 This is a list of symbols which will be used in sequence to determine
886 if an entry should be listed before another entry. The following
887 symbols are recognized:
889 time-up Put entries with time-of-day indications first, early first
890 time-down Put entries with time-of-day indications first, late first
891 category-keep Keep the default order of categories, corresponding to the
892 sequence in `org-agenda-files'.
893 category-up Sort alphabetically by category, A-Z.
894 category-down Sort alphabetically by category, Z-A.
895 tag-up Sort alphabetically by last tag, A-Z.
896 tag-down Sort alphabetically by last tag, Z-A.
897 priority-up Sort numerically by priority, high priority last.
898 priority-down Sort numerically by priority, high priority first.
899 todo-state-up Sort by todo state, tasks that are done last.
900 todo-state-down Sort by todo state, tasks that are done first.
901 effort-up Sort numerically by estimated effort, high effort last.
902 effort-down Sort numerically by estimated effort, high effort first.
903 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
904 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
906 The different possibilities will be tried in sequence, and testing stops
907 if one comparison returns a \"not-equal\". For example, the default
908 '(time-up category-keep priority-down)
909 means: Pull out all entries having a specified time of day and sort them,
910 in order to make a time schedule for the current day the first thing in the
911 agenda listing for the day. Of the entries without a time indication, keep
912 the grouped in categories, don't sort the categories, but keep them in
913 the sequence given in `org-agenda-files'. Within each category sort by
916 Leaving out `category-keep' would mean that items will be sorted across
917 categories by priority.
919 Instead of a single list, this can also be a set of list for specific
920 contents, with a context symbol in the car of the list, any of
921 `agenda', `todo', `tags' for the corresponding agenda views.
923 Custom commands can bind this variable in the options section."
924 :group
'org-agenda-sorting
926 (repeat :tag
"General" ,org-sorting-choice
)
927 (list :tag
"Individually"
928 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
929 (repeat ,org-sorting-choice
))
930 (cons (const :tag
"Strategy for TODO lists" todo
)
931 (repeat ,org-sorting-choice
))
932 (cons (const :tag
"Strategy for Tags matches" tags
)
933 (repeat ,org-sorting-choice
)))))
935 (defcustom org-agenda-cmp-user-defined nil
936 "A function to define the comparison `user-defined'.
937 This function must receive two arguments, agenda entry a and b.
938 If a>b, return +1. If a<b, return -1. If they are equal as seen by
939 the user comparison, return nil.
940 When this is defined, you can make `user-defined-up' and `user-defined-down'
941 part of an agenda sorting strategy."
942 :group
'org-agenda-sorting
945 (defcustom org-sort-agenda-notime-is-late t
946 "Non-nil means, items without time are considered late.
947 This is only relevant for sorting. When t, items which have no explicit
948 time like 15:30 will be considered as 99:01, i.e. later than any items which
949 do have a time. When nil, the default time is before 0:00. You can use this
950 option to decide if the schedule for today should come before or after timeless
952 :group
'org-agenda-sorting
955 (defcustom org-sort-agenda-noeffort-is-high t
956 "Non-nil means, items without effort estimate are sorted as high effort.
957 This also applies when filtering an agenda view with respect to the
958 < or > effort operator. Then, tasks with no effort defined will be treated
959 as tasks with high effort.
960 When nil, such items are sorted as 0 minutes effort."
961 :group
'org-agenda-sorting
964 (defgroup org-agenda-line-format nil
965 "Options concerning the entry prefix in the Org-mode agenda display."
966 :tag
"Org Agenda Line Format"
969 (defcustom org-agenda-prefix-format
970 '((agenda .
" %-12:c%?-12t% s")
974 (search .
" %-12:c"))
975 "Format specifications for the prefix of items in the agenda views.
976 An alist with four entries, for the different agenda types. The keys to the
977 sublists are `agenda', `timeline', `todo', and `tags'. The values
979 This format works similar to a printf format, with the following meaning:
981 %c the category of the item, \"Diary\" for entries from the diary, or
982 as given by the CATEGORY keyword or derived from the file name.
983 %T the *last* tag of the item. Last because inherited tags come
985 %t the time-of-day specification if one applies to the entry, in the
987 %s Scheduling/Deadline information, a short string
989 All specifiers work basically like the standard `%s' of printf, but may
990 contain two additional characters: A question mark just after the `%' and
991 a whitespace/punctuation character just before the final letter.
993 If the first character after `%' is a question mark, the entire field
994 will only be included if the corresponding value applies to the
995 current entry. This is useful for fields which should have fixed
996 width when present, but zero width when absent. For example,
997 \"%?-12t\" will result in a 12 character time field if a time of the
998 day is specified, but will completely disappear in entries which do
1001 If there is punctuation or whitespace character just before the final
1002 format letter, this character will be appended to the field value if
1003 the value is not empty. For example, the format \"%-12:c\" leads to
1004 \"Diary: \" if the category is \"Diary\". If the category were be
1005 empty, no additional colon would be interted.
1007 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1008 - Indent the line with two space characters
1009 - Give the category in a 12 chars wide field, padded with whitespace on
1010 the right (because of `-'). Append a colon if there is a category
1012 - If there is a time-of-day, put it into a 12 chars wide field. If no
1013 time, don't put in an empty field, just skip it (because of '?').
1014 - Finally, put the scheduling information and append a whitespace.
1016 As another example, if you don't want the time-of-day of entries in
1017 the prefix, you could use:
1019 (setq org-agenda-prefix-format \" %-11:c% s\")
1021 See also the variables `org-agenda-remove-times-when-in-prefix' and
1022 `org-agenda-remove-tags'.
1024 Custom commands can set this variable in the options section."
1026 (string :tag
"General format")
1027 (list :greedy t
:tag
"View dependent"
1028 (cons (const agenda
) (string :tag
"Format"))
1029 (cons (const timeline
) (string :tag
"Format"))
1030 (cons (const todo
) (string :tag
"Format"))
1031 (cons (const tags
) (string :tag
"Format"))
1032 (cons (const search
) (string :tag
"Format"))))
1033 :group
'org-agenda-line-format
)
1035 (defvar org-prefix-format-compiled nil
1036 "The compiled version of the most recently used prefix format.
1037 See the variable `org-agenda-prefix-format'.")
1039 (defcustom org-agenda-todo-keyword-format
"%-1s"
1040 "Format for the TODO keyword in agenda lines.
1041 Set this to something like \"%-12s\" if you want all TODO keywords
1042 to occupy a fixed space in the agenda display."
1043 :group
'org-agenda-line-format
1046 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1047 "Text preceding timerange entries in the agenda view.
1048 This is a list with two strings. The first applies when the range
1049 is entirely on one day. The second applies if the range spans several days.
1050 The strings may have two \"%d\" format specifiers which will be filled
1051 with the sequence number of the days, and the total number of days in the
1052 range, respectively."
1053 :group
'org-agenda-line-format
1055 (string :tag
"Deadline today ")
1056 (choice :tag
"Deadline relative"
1057 (string :tag
"Format string")
1060 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1061 "Text preceeding scheduled items in the agenda view.
1062 This is a list with two strings. The first applies when the item is
1063 scheduled on the current day. The second applies when it has been scheduled
1064 previously, it may contain a %d indicating that this is the nth time that
1065 this item is scheduled, due to automatic rescheduling of unfinished items
1066 for the following day. So this number is one larger than the number of days
1067 that passed since this item was scheduled first."
1068 :group
'org-agenda-line-format
1070 (string :tag
"Scheduled today ")
1071 (string :tag
"Scheduled previously")))
1073 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1074 "Text preceeding deadline items in the agenda view.
1075 This is a list with two strings. The first applies when the item has its
1076 deadline on the current day. The second applies when it is in the past or
1077 in the future, it may contain %d to capture how many days away the deadline
1079 :group
'org-agenda-line-format
1081 (string :tag
"Deadline today ")
1082 (choice :tag
"Deadline relative"
1083 (string :tag
"Format string")
1086 (defcustom org-agenda-remove-times-when-in-prefix t
1087 "Non-nil means, remove duplicate time specifications in agenda items.
1088 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1089 time-of-day specification in a headline or diary entry is extracted and
1090 placed into the prefix. If this option is non-nil, the original specification
1091 \(a timestamp or -range, or just a plain time(range) specification like
1092 11:30-4pm) will be removed for agenda display. This makes the agenda less
1094 The option can be t or nil. It may also be the symbol `beg', indicating
1095 that the time should only be removed what it is located at the beginning of
1096 the headline/diary entry."
1097 :group
'org-agenda-line-format
1099 (const :tag
"Always" t
)
1100 (const :tag
"Never" nil
)
1101 (const :tag
"When at beginning of entry" beg
)))
1104 (defcustom org-agenda-default-appointment-duration nil
1105 "Default duration for appointments that only have a starting time.
1106 When nil, no duration is specified in such cases.
1107 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1108 :group
'org-agenda-line-format
1110 (integer :tag
"Minutes")
1111 (const :tag
"No default duration")))
1113 (defcustom org-agenda-show-inherited-tags t
1114 "Non-nil means, show inherited tags in each agenda line."
1115 :group
'org-agenda-line-format
1118 (defcustom org-agenda-remove-tags nil
1119 "Non-nil means, remove the tags from the headline copy in the agenda.
1120 When this is the symbol `prefix', only remove tags when
1121 `org-agenda-prefix-format' contains a `%T' specifier."
1122 :group
'org-agenda-line-format
1124 (const :tag
"Always" t
)
1125 (const :tag
"Never" nil
)
1126 (const :tag
"When prefix format contains %T" prefix
)))
1128 (if (fboundp 'defvaralias
)
1129 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1130 'org-agenda-remove-tags
))
1132 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1133 "Shift tags in agenda items to this column.
1134 If this number is positive, it specifies the column. If it is negative,
1135 it means that the tags should be flushright to that column. For example,
1136 -80 works well for a normal 80 character screen."
1137 :group
'org-agenda-line-format
1140 (if (fboundp 'defvaralias
)
1141 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1143 (defcustom org-agenda-fontify-priorities
'cookies
1144 "Non-nil means, highlight low and high priorities in agenda.
1145 When t, the highest priority entries are bold, lowest priority italic.
1146 However, settings in org-priority-faces will overrule these faces.
1147 When this variable is the symbol `cookies', only fontify the
1148 cookies, not the entire task.
1149 This may also be an association list of priority faces, whose
1150 keys are the character values of `org-highest-priority',
1151 `org-default-priority', and `org-lowest-priority' (the default values
1152 are ?A, ?B, and ?C, respectively). The face may be a named face,
1153 or a list like `(:background \"Red\")'."
1154 :group
'org-agenda-line-format
1156 (const :tag
"Never" nil
)
1157 (const :tag
"Defaults" t
)
1158 (const :tag
"Cookies only" cookies
)
1159 (repeat :tag
"Specify"
1160 (list (character :tag
"Priority" :value ?A
)
1161 (sexp :tag
"face")))))
1163 (defgroup org-agenda-column-view nil
1164 "Options concerning column view in the agenda."
1165 :tag
"Org Agenda Column View"
1168 (defcustom org-agenda-columns-show-summaries t
1169 "Non-nil means, show summaries for columns displayed in the agenda view."
1170 :group
'org-agenda-column-view
1173 (defcustom org-agenda-columns-remove-prefix-from-item t
1174 "Non-nil means, remove the prefix from a headline for agenda column view.
1175 The special ITEM field in the columns format contains the current line, with
1176 all information shown in other columns (like the TODO state or a tag).
1177 When this variable is non-nil, also the agenda prefix will be removed from
1178 the content of the ITEM field, to make sure as much as possible of the
1179 headline can be shown in the limited width of the field."
1183 (defcustom org-agenda-columns-compute-summary-properties t
1184 "Non-nil means, recompute all summary properties before column view.
1185 When column view in the agenda is listing properties that have a summary
1186 operator, it can go to all relevant buffers and recompute the summaries
1187 there. This can mean overhead for the agenda column view, but is necessary
1188 to have thing up to date.
1189 As a special case, a CLOCKSUM property also makes sure that the clock
1190 computations are current."
1191 :group
'org-agenda-column-view
1194 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1195 "Non-nil means, the duration of an appointment will add to day effort.
1196 The property to which appointment durations will be added is the one given
1197 in the option `org-effort-property'. If an appointment does not have
1198 an end time, `org-agenda-default-appointment-duration' will be used. If that
1199 is not set, an appointment without end time will not contribute to the time
1201 :group
'org-agenda-column-view
1208 (defun org-add-agenda-custom-command (entry)
1209 "Replace or add a command in `org-agenda-custom-commands'.
1210 This is mostly for hacking and trying a new command - once the command
1211 works you probably want to add it to `org-agenda-custom-commands' for good."
1212 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1214 (setcdr ass
(cdr entry
))
1215 (push entry org-agenda-custom-commands
))))
1217 ;;; Define the Org-agenda-mode
1219 (defvar org-agenda-mode-map
(make-sparse-keymap)
1220 "Keymap for `org-agenda-mode'.")
1222 (defvar org-agenda-menu
) ; defined later in this file.
1223 (defvar org-agenda-follow-mode nil
)
1224 (defvar org-agenda-clockreport-mode nil
)
1225 (defvar org-agenda-show-log nil
)
1226 (defvar org-agenda-redo-command nil
)
1227 (defvar org-agenda-query-string nil
)
1228 (defvar org-agenda-mode-hook nil
1229 "Hook for org-agenda-mode, run after the mode is turned on.")
1230 (defvar org-agenda-type nil
)
1231 (defvar org-agenda-force-single-file nil
)
1233 (defun org-agenda-mode ()
1234 "Mode for time-sorted view on action items in Org-mode files.
1236 The following commands are available:
1238 \\{org-agenda-mode-map}"
1240 (kill-all-local-variables)
1241 (setq org-agenda-undo-list nil
1242 org-agenda-pending-undo-list nil
)
1243 (setq major-mode
'org-agenda-mode
)
1244 ;; Keep global-font-lock-mode from turning on font-lock-mode
1245 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1246 (setq mode-name
"Org-Agenda")
1247 (use-local-map org-agenda-mode-map
)
1248 (easy-menu-add org-agenda-menu
)
1249 (if org-startup-truncated
(setq truncate-lines t
))
1250 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1251 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1252 ;; Make sure properties are removed when copying text
1253 (when (boundp 'buffer-substring-filters
)
1254 (org-set-local 'buffer-substring-filters
1256 (set-text-properties 0 (length x
) nil x
) x
)
1257 buffer-substring-filters
)))
1258 (unless org-agenda-keep-modes
1259 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1260 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1261 org-agenda-show-log org-agenda-start-with-log-mode
))
1264 '("Agenda") "Agenda Files"
1268 (if (get 'org-agenda-files
'org-restrict
)
1269 "Restricted to single file"
1271 '(org-edit-agenda-file-list)
1272 (not (get 'org-agenda-files
'org-restrict
)))
1274 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1275 (org-agenda-set-mode-name)
1277 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1278 (list 'org-agenda-mode-hook
)))
1280 (substitute-key-definition 'undo
'org-agenda-undo
1281 org-agenda-mode-map global-map
)
1282 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1283 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1284 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1285 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1286 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1287 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1288 (org-defkey org-agenda-mode-map
"\C-c\C-x!" 'org-reload
)
1289 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1290 (org-defkey org-agenda-mode-map
"A" 'org-agenda-archive-to-archive-sibling
)
1291 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1292 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1293 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1294 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1295 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1296 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1297 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1298 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1299 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1300 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1301 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1302 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1303 (org-defkey org-agenda-mode-map
"\C-c\C-q" 'org-agenda-set-tags
)
1304 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1305 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1306 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1307 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1308 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1309 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1310 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1311 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1312 (org-defkey org-agenda-mode-map
"k" 'org-agenda-action
)
1313 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-k" 'org-agenda-action
)
1314 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-do-date-later
)
1315 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-do-date-earlier
)
1316 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-do-date-later
)
1317 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-do-date-earlier
)
1319 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1320 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1321 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1322 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1323 (while l
(org-defkey org-agenda-mode-map
1324 (int-to-string (pop l
)) 'digit-argument
)))
1326 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1327 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1328 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1329 (org-defkey org-agenda-mode-map
"v" 'org-agenda-archives-mode
)
1330 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1331 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1332 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1333 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1334 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1335 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1336 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1337 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1338 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1339 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1340 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1341 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1342 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1343 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1344 (org-defkey org-agenda-mode-map
"\C-c\C-a" 'org-attach
)
1345 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1346 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1347 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1348 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1349 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1350 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1351 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1352 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1353 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1354 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1355 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1356 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1357 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1358 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1359 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1360 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1361 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1362 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1363 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1364 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1365 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1366 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1367 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1368 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1369 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1370 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1371 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1372 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1374 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1375 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1376 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1377 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1378 (org-defkey org-agenda-mode-map
"/" 'org-agenda-filter-by-tag
)
1379 (org-defkey org-agenda-mode-map
"\\" 'org-agenda-filter-by-tag-refine
)
1381 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1382 "Local keymap for agenda entries from Org-mode.")
1384 (org-defkey org-agenda-keymap
1385 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1386 (org-defkey org-agenda-keymap
1387 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1388 (when org-agenda-mouse-1-follows-link
1389 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1390 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1394 ["Show" org-agenda-show t
]
1395 ["Go To (other window)" org-agenda-goto t
]
1396 ["Go To (this window)" org-agenda-switch-to t
]
1397 ["Follow Mode" org-agenda-follow-mode
1398 :style toggle
:selected org-agenda-follow-mode
:active t
]
1399 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1401 ["Cycle TODO" org-agenda-todo t
]
1403 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t
]
1404 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t
]
1405 ["Archive subtree" org-agenda-archive t
])
1406 ["Delete subtree" org-agenda-kill t
]
1407 ["Add note" org-agenda-add-note t
]
1409 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1410 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1411 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1412 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1414 ("Tags and Properties"
1415 ["Show all Tags" org-agenda-show-tags t
]
1416 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1417 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1419 ["Column View" org-columns t
])
1421 ["Schedule" org-agenda-schedule t
]
1422 ["Set Deadline" org-agenda-deadline t
]
1424 ["Mark item" org-agenda-action
:active t
:keys
"k m"]
1425 ["Show mark item" org-agenda-action
:active t
:keys
"k v"]
1426 ["Schedule marked item" org-agenda-action
:active t
:keys
"k s"]
1427 ["Set Deadline for marked item" org-agenda-action
:active t
:keys
"k d"]
1429 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1430 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1431 ["Change Time +1 hour" org-agenda-do-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-right"]
1432 ["Change Time -1 hour" org-agenda-do-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-left"]
1433 ["Change Time + min" org-agenda-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-right"]
1434 ["Change Time - min" org-agenda-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-left"]
1435 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1437 ["Clock in" org-agenda-clock-in t
]
1438 ["Clock out" org-agenda-clock-out t
]
1439 ["Clock cancel" org-agenda-clock-cancel t
]
1440 ["Goto running clock" org-clock-goto t
])
1442 ["Set Priority" org-agenda-priority t
]
1443 ["Increase Priority" org-agenda-priority-up t
]
1444 ["Decrease Priority" org-agenda-priority-down t
]
1445 ["Show Priority" org-agenda-show-priority t
])
1447 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1448 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1449 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1450 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1451 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1452 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1454 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1457 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1458 :style radio
:selected
(equal org-agenda-ndays
1)]
1459 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1460 :style radio
:selected
(equal org-agenda-ndays
7)]
1461 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1462 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1463 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1464 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1466 ["Include Diary" org-agenda-toggle-diary
1467 :style toggle
:selected org-agenda-include-diary
1468 :active
(org-agenda-check-type nil
'agenda
)]
1469 ["Use Time Grid" org-agenda-toggle-time-grid
1470 :style toggle
:selected org-agenda-use-time-grid
1471 :active
(org-agenda-check-type nil
'agenda
)]
1473 ["Show clock report" org-agenda-clockreport-mode
1474 :style toggle
:selected org-agenda-clockreport-mode
1475 :active
(org-agenda-check-type nil
'agenda
)]
1477 ["Show Logbook entries" org-agenda-log-mode
1478 :style toggle
:selected org-agenda-show-log
1479 :active
(org-agenda-check-type nil
'agenda
'timeline
)]
1480 ["Include archived trees" org-agenda-archives-mode
1481 :style toggle
:selected org-agenda-archives-mode
:active t
]
1482 ["Include archive files" (org-agenda-archives-mode t
)
1483 :style toggle
:selected
(eq org-agenda-archives-mode t
) :active t
1485 ["Write view to file" org-write-agenda t
]
1486 ["Rebuild buffer" org-agenda-redo t
]
1487 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1489 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1491 ["Quit" org-agenda-quit t
]
1492 ["Exit and Release Buffers" org-agenda-exit t
]
1497 (defvar org-agenda-allow-remote-undo t
1498 "Non-nil means, allow remote undo from the agenda buffer.")
1499 (defvar org-agenda-undo-list nil
1500 "List of undoable operations in the agenda since last refresh.")
1501 (defvar org-agenda-undo-has-started-in nil
1502 "Buffers that have already seen `undo-start' in the current undo sequence.")
1503 (defvar org-agenda-pending-undo-list nil
1504 "In a series of undo commands, this is the list of remaining undo items.")
1507 (defun org-agenda-undo ()
1508 "Undo a remote editing step in the agenda.
1509 This undoes changes both in the agenda buffer and in the remote buffer
1510 that have been changed along."
1512 (or org-agenda-allow-remote-undo
1513 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1514 (if (not (eq this-command last-command
))
1515 (setq org-agenda-undo-has-started-in nil
1516 org-agenda-pending-undo-list org-agenda-undo-list
))
1517 (if (not org-agenda-pending-undo-list
)
1518 (error "No further undo information"))
1519 (let* ((entry (pop org-agenda-pending-undo-list
))
1520 buf line cmd rembuf
)
1521 (setq cmd
(pop entry
) line
(pop entry
))
1522 (setq rembuf
(nth 2 entry
))
1523 (org-with-remote-undo rembuf
1524 (while (bufferp (setq buf
(pop entry
)))
1526 (with-current-buffer buf
1527 (let ((last-undo-buffer buf
)
1528 (inhibit-read-only t
))
1529 (unless (memq buf org-agenda-undo-has-started-in
)
1530 (push buf org-agenda-undo-has-started-in
)
1531 (make-local-variable 'pending-undo-list
)
1533 (while (and pending-undo-list
1534 (listp pending-undo-list
)
1535 (not (car pending-undo-list
)))
1536 (pop pending-undo-list
))
1539 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1541 (defun org-verify-change-for-undo (l1 l2
)
1542 "Verify that a real change occurred between the undo lists L1 and L2."
1543 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1544 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1549 (defvar org-agenda-restrict nil
)
1550 (defvar org-agenda-restrict-begin
(make-marker))
1551 (defvar org-agenda-restrict-end
(make-marker))
1552 (defvar org-agenda-last-dispatch-buffer nil
)
1553 (defvar org-agenda-overriding-restriction nil
)
1556 (defun org-agenda (&optional arg keys restriction
)
1557 "Dispatch agenda commands to collect entries to the agenda buffer.
1558 Prompts for a command to execute. Any prefix arg will be passed
1559 on to the selected command. The default selections are:
1561 a Call `org-agenda-list' to display the agenda for current day or week.
1562 t Call `org-todo-list' to display the global todo list.
1563 T Call `org-todo-list' to display the global todo list, select only
1564 entries with a specific TODO keyword (the user gets a prompt).
1565 m Call `org-tags-view' to display headlines with tags matching
1566 a condition (the user is prompted for the condition).
1567 M Like `m', but select only TODO entries, no ordinary headlines.
1568 L Create a timeline for the current buffer.
1569 e Export views to associated files.
1570 s Search entries for keywords.
1571 / Multi occur accros all agenda files and also files listed
1572 in `org-agenda-text-search-extra-files'.
1573 < Restrict agenda commands to buffer, subtree, or region.
1574 Press several times to get the desired effect.
1575 > Remove a previous restriction.
1576 # List \"stuck\" projects.
1577 ! Configure what \"stuck\" means.
1578 C Configure custom agenda commands.
1580 More commands can be added by configuring the variable
1581 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1582 searches can be pre-defined in this way.
1584 If the current buffer is in Org-mode and visiting a file, you can also
1585 first press `<' once to indicate that the agenda should be temporarily
1586 \(until the next use of \\[org-agenda]) restricted to the current file.
1587 Pressing `<' twice means to restrict to the current subtree or region
1591 (let* ((prefix-descriptions nil
)
1592 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1593 (org-agenda-custom-commands
1594 ;; normalize different versions
1598 (cond ((stringp (cdr x
))
1599 (push x prefix-descriptions
)
1601 ((stringp (nth 1 x
)) x
)
1602 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1603 (t (cons (car x
) (cons "" (cdr x
))))))
1604 org-agenda-custom-commands
)))
1605 (buf (current-buffer))
1606 (bfn (buffer-file-name (buffer-base-buffer)))
1607 entry key type match lprops ans
)
1608 ;; Turn off restriction unless there is an overriding one
1609 (unless org-agenda-overriding-restriction
1610 (put 'org-agenda-files
'org-restrict nil
)
1611 (setq org-agenda-restrict nil
)
1612 (move-marker org-agenda-restrict-begin nil
)
1613 (move-marker org-agenda-restrict-end nil
))
1614 ;; Delete old local properties
1615 (put 'org-agenda-redo-command
'org-lprops nil
)
1616 ;; Remember where this call originated
1617 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1619 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1621 restriction
(cdr ans
)))
1622 ;; Estabish the restriction, if any
1623 (when (and (not org-agenda-overriding-restriction
) restriction
)
1624 (put 'org-agenda-files
'org-restrict
(list bfn
))
1626 ((eq restriction
'region
)
1627 (setq org-agenda-restrict t
)
1628 (move-marker org-agenda-restrict-begin
(region-beginning))
1629 (move-marker org-agenda-restrict-end
(region-end)))
1630 ((eq restriction
'subtree
)
1632 (setq org-agenda-restrict t
)
1633 (org-back-to-heading t
)
1634 (move-marker org-agenda-restrict-begin
(point))
1635 (move-marker org-agenda-restrict-end
1636 (progn (org-end-of-subtree t
)))))))
1638 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1639 ;; For example the todo list should not need it (but does...)
1641 ((setq entry
(assoc keys org-agenda-custom-commands
))
1642 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1644 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1645 (put 'org-agenda-redo-command
'org-lprops lprops
)
1648 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1650 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1652 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1654 (org-let lprops
'(org-agenda-list-stuck-projects
1655 current-prefix-arg
)))
1657 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1658 ((eq type
'tags-todo
)
1659 (org-let lprops
'(org-tags-view '(4) match
)))
1661 (org-let lprops
'(org-todo-list match
)))
1662 ((eq type
'tags-tree
)
1663 (org-check-for-org-mode)
1664 (org-let lprops
'(org-match-sparse-tree current-prefix-arg match
)))
1665 ((eq type
'todo-tree
)
1666 (org-check-for-org-mode)
1668 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1669 (regexp-quote match
) "\\>"))))
1670 ((eq type
'occur-tree
)
1671 (org-check-for-org-mode)
1672 (org-let lprops
'(org-occur match
)))
1674 (org-let lprops
'(funcall type match
)))
1676 (org-let lprops
'(funcall type match
)))
1677 (t (error "Invalid custom agenda command type %s" type
))))
1678 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1680 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1681 (customize-variable 'org-agenda-custom-commands
))
1682 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1683 ((equal keys
"s") (call-interactively 'org-search-view
))
1684 ((equal keys
"t") (call-interactively 'org-todo-list
))
1685 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1686 ((equal keys
"m") (call-interactively 'org-tags-view
))
1687 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1688 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1690 (unless (org-mode-p)
1691 (error "This is not an Org-mode file"))
1693 (put 'org-agenda-files
'org-restrict
(list bfn
))
1694 (org-call-with-arg 'org-timeline arg
)))
1695 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1696 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1697 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1698 (t (error "Invalid agenda key"))))))
1700 (defun org-agenda-normalize-custom-commands (cmds)
1704 (cond ((stringp (cdr x
)) nil
)
1705 ((stringp (nth 1 x
)) x
)
1706 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1707 (t (cons (car x
) (cons "" (cdr x
))))))
1710 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1711 "The user interface for selecting an agenda command."
1713 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1714 (restrict-ok (and bfn
(org-mode-p)))
1715 (region-p (org-region-active-p))
1716 (custom org-agenda-custom-commands
)
1718 restriction second-time
1719 c entry key type match prefixes rmheader header-end custom1 desc
)
1720 (save-window-excursion
1721 (delete-other-windows)
1722 (org-switch-to-buffer-other-window " *Agenda Commands*")
1724 (insert (eval-when-compile
1727 Press key for an agenda command: < Buffer, subtree/region restriction
1728 -------------------------------- > Remove restriction
1729 a Agenda for current week or day e Export agenda views
1730 t List of all TODO entries T Entries with special TODO kwd
1731 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1732 L Timeline for current buffer # List stuck projects (!=configure)
1733 s Search for keywords C Configure custom agenda commands
1737 (while (string-match
1738 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1740 (setq start
(match-end 0))
1741 (add-text-properties (match-beginning 2) (match-end 2)
1742 '(face bold
) header
))
1744 (setq header-end
(move-marker (make-marker) (point)))
1746 (setq custom1 custom
)
1747 (when (eq rmheader t
)
1749 (re-search-forward ":" nil t
)
1750 (delete-region (match-end 0) (point-at-eol))
1753 (delete-region (match-end 0) (point-at-eol))
1754 (move-marker header-end
(match-end 0)))
1755 (goto-char header-end
)
1756 (delete-region (point) (point-max))
1757 (while (setq entry
(pop custom1
))
1758 (setq key
(car entry
) desc
(nth 1 entry
)
1759 type
(nth 2 entry
) match
(nth 3 entry
))
1760 (if (> (length key
) 1)
1761 (add-to-list 'prefixes
(string-to-char key
))
1765 (org-add-props (copy-sequence key
)
1768 ((string-match "\\S-" desc
) desc
)
1769 ((eq type
'agenda
) "Agenda for current week or day")
1770 ((eq type
'alltodo
) "List of all TODO entries")
1771 ((eq type
'search
) "Word search")
1772 ((eq type
'stuck
) "List of stuck projects")
1773 ((eq type
'todo
) "TODO keyword")
1774 ((eq type
'tags
) "Tags query")
1775 ((eq type
'tags-todo
) "Tags (TODO)")
1776 ((eq type
'tags-tree
) "Tags tree")
1777 ((eq type
'todo-tree
) "TODO kwd tree")
1778 ((eq type
'occur-tree
) "Occur tree")
1779 ((functionp type
) (if (symbolp type
)
1781 "Lambda expression"))
1785 (org-add-props match nil
'face
'org-warning
))
1787 (format "set of %d commands" (length match
)))
1793 (org-add-props (char-to-string x
)
1795 (or (cdr (assoc (concat selstring
(char-to-string x
))
1796 prefix-descriptions
))
1799 (goto-char (point-min))
1801 (if (not (pos-visible-in-window-p (point-max)))
1802 (org-fit-window-to-buffer))
1803 (setq second-time t
)
1804 (org-fit-window-to-buffer))
1805 (message "Press key for agenda command%s:"
1806 (if (or restrict-ok org-agenda-overriding-restriction
)
1807 (if org-agenda-overriding-restriction
1808 " (restriction lock active)"
1810 (format " (restricted to %s)" restriction
)
1813 (setq c
(read-char-exclusive))
1816 ((assoc (char-to-string c
) custom
)
1817 (setq selstring
(concat selstring
(char-to-string c
)))
1818 (throw 'exit
(cons selstring restriction
)))
1820 (setq selstring
(concat selstring
(char-to-string c
))
1822 rmheader
(or rmheader t
)
1823 custom
(delq nil
(mapcar
1825 (if (or (= (length (car x
)) 1)
1826 (/= (string-to-char (car x
)) c
))
1828 (cons (substring (car x
) 1) (cdr x
))))
1830 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1831 (message "Restriction is only possible in Org-mode buffers")
1834 (org-agenda-remove-restriction-lock 'noupdate
)
1835 (setq restriction
'buffer
))
1837 (org-agenda-remove-restriction-lock 'noupdate
)
1838 (setq restriction
(if region-p
'region
'subtree
)))
1840 (org-agenda-remove-restriction-lock 'noupdate
)
1843 ((eq restriction
'buffer
)
1844 (if region-p
'region
'subtree
))
1845 ((memq restriction
'(subtree region
))
1849 (org-agenda-remove-restriction-lock 'noupdate
)
1850 (setq restriction nil
))
1851 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1852 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1853 ((and (> (length selstring
) 0) (eq c ?\d
))
1855 (org-agenda-get-restriction-and-command prefix-descriptions
))
1857 ((equal c ?q
) (error "Abort"))
1858 (t (error "Invalid key %c" c
))))))))
1860 (defun org-run-agenda-series (name series
)
1861 (org-prepare-agenda name
)
1862 (let* ((org-agenda-multi t
)
1863 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1865 (gprops (nth 1 series
))
1866 match
;; The byte compiler incorrectly complains about this. Keep it!
1868 (while (setq cmd
(pop cmds
))
1869 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1872 (org-let2 gprops lprops
1873 '(call-interactively 'org-agenda-list
)))
1875 (org-let2 gprops lprops
1876 '(call-interactively 'org-todo-list
)))
1878 (org-let2 gprops lprops
1879 '(org-search-view current-prefix-arg match nil
)))
1881 (org-let2 gprops lprops
1882 '(call-interactively 'org-agenda-list-stuck-projects
)))
1884 (org-let2 gprops lprops
1885 '(org-tags-view current-prefix-arg match
)))
1886 ((eq type
'tags-todo
)
1887 (org-let2 gprops lprops
1888 '(org-tags-view '(4) match
)))
1890 (org-let2 gprops lprops
1891 '(org-todo-list match
)))
1893 (org-let2 gprops lprops
1894 '(funcall type match
)))
1895 (t (error "Invalid type in command series"))))
1897 (setq org-agenda-redo-command redo
)
1898 (goto-char (point-min)))
1899 (org-fit-agenda-window)
1900 (org-let (nth 1 series
) '(org-finalize-agenda)))
1903 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1904 "Run an agenda command in batch mode and send the result to STDOUT.
1905 If CMD-KEY is a string of length 1, it is used as a key in
1906 `org-agenda-custom-commands' and triggers this command. If it is a
1907 longer string it is used as a tags/todo match string.
1908 Paramters are alternating variable names and values that will be bound
1909 before running the agenda command."
1912 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1913 (if (> (length cmd-key
) 2)
1914 (eval (list 'let
(nreverse pars
)
1915 (list 'org-tags-view nil cmd-key
)))
1916 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1917 (set-buffer org-agenda-buffer-name
)
1918 (princ (org-encode-for-stdout (buffer-string)))))
1920 (defun org-encode-for-stdout (string)
1921 (if (fboundp 'encode-coding-string
)
1922 (encode-coding-string string buffer-file-coding-system
)
1925 (defvar org-agenda-info nil
)
1928 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1929 "Run an agenda command in batch mode and send the result to STDOUT.
1930 If CMD-KEY is a string of length 1, it is used as a key in
1931 `org-agenda-custom-commands' and triggers this command. If it is a
1932 longer string it is used as a tags/todo match string.
1933 Paramters are alternating variable names and values that will be bound
1934 before running the agenda command.
1936 The output gives a line for each selected agenda item. Each
1937 item is a list of comma-separated values, like this:
1939 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1941 category The category of the item
1942 head The headline, without TODO kwd, TAGS and PRIORITY
1943 type The type of the agenda entry, can be
1944 todo selected in TODO match
1945 tagsmatch selected in tags match
1946 diary imported from diary
1947 deadline a deadline on given date
1948 scheduled scheduled on given date
1949 timestamp entry has timestamp on given date
1950 closed entry was closed on given date
1951 upcoming-deadline warning about deadline
1952 past-scheduled forwarded scheduled item
1953 block entry has date block including g. date
1954 todo The todo keyword, if any
1955 tags All tags including inherited ones, separated by colons
1956 date The relevant date, like 2007-2-14
1957 time The time, like 15:00-16:50
1958 extra Sting with extra planning info
1959 priority-l The priority letter if any was given
1960 priority-n The computed numerical priority
1961 agenda-day The day in the agenda where this is listed"
1965 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1966 (push (list 'org-agenda-remove-tags t
) pars
)
1967 (if (> (length cmd-key
) 2)
1968 (eval (list 'let
(nreverse pars
)
1969 (list 'org-tags-view nil cmd-key
)))
1970 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1971 (set-buffer org-agenda-buffer-name
)
1972 (let* ((lines (org-split-string (buffer-string) "\n"))
1974 (while (setq line
(pop lines
))
1976 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1977 (setq org-agenda-info
1978 (org-fix-agenda-info (text-properties-at 0 line
)))
1980 (org-encode-for-stdout
1981 (mapconcat 'org-agenda-export-csv-mapper
1982 '(org-category txt type todo tags date time-of-day extra
1983 priority-letter priority agenda-day
)
1987 (defun org-fix-agenda-info (props)
1988 "Make sure all properties on an agenda item have a canonical form,
1989 so the export commands can easily use it."
1991 (when (setq tmp
(plist-get props
'tags
))
1992 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1993 (when (setq tmp
(plist-get props
'date
))
1994 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1995 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1996 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
1998 (setq tmp
(calendar-date-string tmp
)))
1999 (setq props
(plist-put props
'date tmp
)))
2000 (when (setq tmp
(plist-get props
'day
))
2001 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
2002 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
2003 (setq tmp
(calendar-date-string tmp
)))
2004 (setq props
(plist-put props
'day tmp
))
2005 (setq props
(plist-put props
'agenda-day tmp
)))
2006 (when (setq tmp
(plist-get props
'txt
))
2007 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
2008 (plist-put props
'priority-letter
(match-string 1 tmp
))
2009 (setq tmp
(replace-match "" t t tmp
)))
2010 (when (and (setq re
(plist-get props
'org-todo-regexp
))
2011 (setq re
(concat "\\`\\.*" re
" ?"))
2012 (string-match re tmp
))
2013 (plist-put props
'todo
(match-string 1 tmp
))
2014 (setq tmp
(replace-match "" t t tmp
)))
2015 (plist-put props
'txt tmp
)))
2018 (defun org-agenda-export-csv-mapper (prop)
2019 (let ((res (plist-get org-agenda-info prop
)))
2024 (t (prin1-to-string res
))))
2025 (while (string-match "," res
)
2026 (setq res
(replace-match ";" t t res
)))
2031 (defun org-store-agenda-views (&rest parameters
)
2033 (eval (list 'org-batch-store-agenda-views
)))
2035 ;; FIXME, why is this a macro?????
2037 (defmacro org-batch-store-agenda-views
(&rest parameters
)
2038 "Run all custom agenda commands that have a file argument."
2039 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
2041 (dir default-directory
)
2042 pars cmd thiscmdkey files opts cmd-or-set
)
2044 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
2045 (setq pars
(reverse pars
))
2046 (save-window-excursion
2048 (setq cmd
(pop cmds
)
2049 thiscmdkey
(car cmd
)
2050 cmd-or-set
(nth 2 cmd
)
2051 opts
(nth (if (listp cmd-or-set
) 3 4) cmd
)
2052 files
(nth (if (listp cmd-or-set
) 4 5) cmd
))
2053 (if (stringp files
) (setq files
(list files
)))
2055 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2056 (list 'org-agenda nil thiscmdkey
)))
2057 (set-buffer org-agenda-buffer-name
)
2059 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2060 (list 'org-write-agenda
2061 (expand-file-name (pop files
) dir
) nil t
))))
2062 (and (get-buffer org-agenda-buffer-name
)
2063 (kill-buffer org-agenda-buffer-name
)))))))
2065 (defun org-write-agenda (file &optional open nosettings
)
2066 "Write the current buffer (an agenda view) as a file.
2067 Depending on the extension of the file name, plain text (.txt),
2068 HTML (.html or .htm) or Postscript (.ps) is produced.
2069 If the extension is .ics, run icalendar export over all files used
2070 to construct the agenda and limit the export to entries listed in the
2072 With prefic argument OPEN, open the new file immediately.
2073 If NOSETTINGS is given, do not scope the settings of
2074 `org-agenda-exporter-settings' into the export commands. This is used when
2075 the settings have already been scoped and we do not wish to overrule other,
2076 higher priority settings."
2077 (interactive "FWrite agenda to file: \nP")
2078 (if (not (file-writable-p file
))
2079 (error "Cannot write agenda to file %s" file
))
2081 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
2082 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
2083 (org-let (if nosettings nil org-agenda-exporter-settings
)
2085 (save-window-excursion
2086 (org-agenda-mark-filtered-text)
2087 (let ((bs (copy-sequence (buffer-string))) beg
)
2088 (org-agenda-unmark-filtered-text)
2091 (org-agenda-remove-marked-text 'org-filtered
)
2092 (while (setq beg
(text-property-any (point-min) (point-max)
2095 beg
(or (next-single-property-change beg
'org-filtered
)
2097 (run-hooks 'org-agenda-before-write-hook
)
2099 ((string-match "\\.html?\\'" file
)
2100 (set-buffer (htmlize-buffer (current-buffer)))
2102 (when (and org-agenda-export-html-style
2103 (string-match "<style>" org-agenda-export-html-style
))
2104 ;; replace <style> section with org-agenda-export-html-style
2105 (goto-char (point-min))
2106 (kill-region (- (search-forward "<style") 6)
2107 (search-forward "</style>"))
2108 (insert org-agenda-export-html-style
))
2110 (kill-buffer (current-buffer))
2111 (message "HTML written to %s" file
))
2112 ((string-match "\\.ps\\'" file
)
2114 (flet ((ps-get-buffer-name () "Agenda View"))
2115 (ps-print-buffer-with-faces file
))
2116 (message "Postscript written to %s" file
))
2117 ((string-match "\\.pdf\\'" file
)
2119 (flet ((ps-get-buffer-name () "Agenda View"))
2120 (ps-print-buffer-with-faces
2121 (concat (file-name-sans-extension file
) ".ps")))
2122 (call-process "ps2pdf" nil nil nil
2124 (concat (file-name-sans-extension file
) ".ps"))
2125 (expand-file-name file
))
2126 (message "PDF written to %s" file
))
2127 ((string-match "\\.ics\\'" file
)
2128 (let ((org-agenda-marker-table
2129 (org-create-marker-find-array
2130 (org-agenda-collect-markers)))
2131 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
2132 (org-combined-agenda-icalendar-file file
))
2133 (apply 'org-export-icalendar
'combine
2134 (org-agenda-files nil
'ifmode
))))
2136 (let ((bs (buffer-string)))
2141 (kill-buffer (current-buffer))
2142 (message "Plain text written to %s" file
))))))))
2143 (set-buffer org-agenda-buffer-name
))
2144 (when open
(org-open-file file
)))
2146 (defvar org-agenda-filter-overlays nil
)
2148 (defun org-agenda-mark-filtered-text ()
2149 "Mark all text hidden by filtering with a text property."
2150 (let ((inhibit-read-only t
))
2153 (when (equal (org-overlay-buffer o
) (current-buffer))
2155 (org-overlay-start o
) (org-overlay-end o
)
2157 org-agenda-filter-overlays
)))
2159 (defun org-agenda-unmark-filtered-text ()
2160 "Remove the filtering text property."
2161 (let ((inhibit-read-only t
))
2162 (remove-text-properties (point-min) (point-max) '(org-filtered t
))))
2164 (defun org-agenda-remove-marked-text (property &optional value
)
2165 "Delete all text marked with VALUE of PROPERTY.
2166 VALUE defaults to t."
2168 (setq value
(or value t
))
2169 (while (setq beg
(text-property-any (point-min) (point-max)
2172 beg
(or (next-single-property-change beg
'org-filtered
)
2175 (defun org-agenda-add-entry-text ()
2176 "Add entry text to agenda lines.
2177 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2178 entry text following headings shown in the agenda.
2179 Drawers will be excluded, also the line with scheduling/deadline info."
2180 (when (> org-agenda-add-entry-text-maxlines
0)
2181 (let (m txt drawer-re kwd-time-re ind
)
2182 (goto-char (point-min))
2184 (if (not (setq m
(get-text-property (point) 'org-hd-marker
)))
2185 (beginning-of-line 2)
2187 (with-current-buffer (marker-buffer m
)
2188 (if (not (org-mode-p))
2194 (beginning-of-line 2)
2195 (setq txt
(buffer-substring
2197 (progn (outline-next-heading) (point)))
2198 drawer-re org-drawer-regexp
2199 kwd-time-re
(concat "^[ \t]*" org-keyword-time-regexp
2203 (when org-agenda-add-entry-text-descriptive-links
2204 (goto-char (point-min))
2205 (while (org-activate-bracket-links (point-max))
2206 (add-text-properties (match-beginning 0) (match-end 0)
2208 (goto-char (point-min))
2209 (while (re-search-forward org-bracket-link-regexp
(point-max) t
)
2210 (set-text-properties (match-beginning 0) (match-end 0)
2212 (goto-char (point-min))
2213 (while (re-search-forward drawer-re nil t
)
2216 (progn (re-search-forward
2217 "^[ \t]*:END:.*\n?" nil
'move
)
2219 (goto-char (point-min))
2220 (while (re-search-forward kwd-time-re nil t
)
2222 (if (re-search-forward "[ \t\n]+\\'" nil t
)
2224 (goto-char (point-min))
2225 ;; find min indentation
2226 (goto-char (point-min))
2227 (untabify (point-min) (point-max))
2228 (setq ind
(org-get-indentation))
2230 (unless (looking-at "[ \t]*$")
2231 (setq ind
(min ind
(org-get-indentation))))
2232 (beginning-of-line 2))
2233 (goto-char (point-min))
2235 (unless (looking-at "[ \t]*$")
2236 (move-to-column ind
)
2237 (delete-region (point-at-bol) (point)))
2238 (beginning-of-line 2))
2239 (goto-char (point-min))
2240 (while (and (not (eobp)) (re-search-forward "^" nil t
))
2241 (replace-match " > "))
2242 (goto-char (point-min))
2243 (while (looking-at "[ \t]*\n") (replace-match ""))
2244 (goto-char (point-max))
2245 (when (> (org-current-line)
2246 (1+ org-agenda-add-entry-text-maxlines
))
2247 (goto-line (1+ org-agenda-add-entry-text-maxlines
))
2249 (setq txt
(buffer-substring (point-min) (point)))))))))
2251 (if (string-match "\\S-" txt
) (insert "\n" txt
)))))))
2253 (defun org-agenda-collect-markers ()
2254 "Collect the markers pointing to entries in the agenda buffer."
2257 (goto-char (point-min))
2259 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
2260 (get-text-property (point) 'org-marker
)))
2262 (beginning-of-line 2)))
2263 (nreverse markers
)))
2265 (defun org-create-marker-find-array (marker-list)
2266 "Create a alist of files names with all marker positions in that file."
2268 (while (setq m
(pop marker-list
))
2269 (setq p
(marker-position m
)
2270 f
(buffer-file-name (or (buffer-base-buffer
2272 (marker-buffer m
))))
2273 (if (setq a
(assoc f tbl
))
2274 (push (marker-position m
) (cdr a
))
2275 (push (list f p
) tbl
)))
2276 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
2279 (defvar org-agenda-marker-table nil
) ; dynamically scoped parameter
2280 (defun org-check-agenda-marker-table ()
2281 "Check of the current entry is on the marker list."
2282 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2284 (and (setq a
(assoc file org-agenda-marker-table
))
2287 (org-back-to-heading t
)
2288 (member (point) (cdr a
)))))))
2290 (defun org-check-for-org-mode ()
2291 "Make sure current buffer is in org-mode. Error if not."
2293 (error "Cannot execute org-mode agenda command on buffer in %s."
2296 (defun org-fit-agenda-window ()
2297 "Fit the window to the buffer size."
2298 (and (memq org-agenda-window-setup
'(reorganize-frame))
2299 (fboundp 'fit-window-to-buffer
)
2300 (org-fit-window-to-buffer
2302 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
2303 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
2305 ;;; Agenda prepare and finalize
2307 (defvar org-agenda-multi nil
) ; dynamically scoped
2308 (defvar org-agenda-buffer-name
"*Org Agenda*")
2309 (defvar org-pre-agenda-window-conf nil
)
2310 (defvar org-agenda-columns-active nil
)
2311 (defvar org-agenda-name nil
)
2312 (defvar org-agenda-filter nil
)
2313 (defvar org-agenda-filter-preset nil
2314 "A preset of the tags filter used for secondary agenda filtering.
2315 This must be a list of strings, each string must be a single tag preceeded
2317 This variable should not be set directly, but agenda custom commands can
2318 bind it in the options section.")
2320 (defun org-prepare-agenda (&optional name
)
2321 (setq org-todo-keywords-for-agenda nil
)
2322 (setq org-done-keywords-for-agenda nil
)
2323 (setq org-agenda-filter nil
)
2324 (put 'org-agenda-filter
:preset-filter org-agenda-filter-preset
)
2325 (if org-agenda-multi
2327 (setq buffer-read-only nil
)
2328 (goto-char (point-max))
2329 (unless (or (bobp) org-agenda-compact-blocks
)
2331 (if (stringp org-agenda-block-separator
)
2332 org-agenda-block-separator
2333 (make-string (window-width) org-agenda-block-separator
))
2335 (narrow-to-region (point) (point-max)))
2336 (org-agenda-reset-markers)
2337 (setq org-agenda-contributing-files nil
)
2338 (setq org-agenda-columns-active nil
)
2339 (org-prepare-agenda-buffers (org-agenda-files nil
'ifmode
))
2340 (setq org-todo-keywords-for-agenda
2341 (org-uniquify org-todo-keywords-for-agenda
))
2342 (setq org-done-keywords-for-agenda
2343 (org-uniquify org-done-keywords-for-agenda
))
2344 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
2345 (awin (get-buffer-window abuf
)))
2347 ((equal (current-buffer) abuf
) nil
)
2348 (awin (select-window awin
))
2349 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
2350 ((equal org-agenda-window-setup
'current-window
)
2351 (switch-to-buffer abuf
))
2352 ((equal org-agenda-window-setup
'other-window
)
2353 (org-switch-to-buffer-other-window abuf
))
2354 ((equal org-agenda-window-setup
'other-frame
)
2355 (switch-to-buffer-other-frame abuf
))
2356 ((equal org-agenda-window-setup
'reorganize-frame
)
2357 (delete-other-windows)
2358 (org-switch-to-buffer-other-window abuf
))))
2359 (setq buffer-read-only nil
)
2360 (let ((inhibit-read-only t
)) (erase-buffer))
2362 (and name
(not org-agenda-name
)
2363 (org-set-local 'org-agenda-name name
)))
2364 (setq buffer-read-only nil
))
2366 (defun org-finalize-agenda ()
2367 "Finishing touch for the agenda buffer, called just before displaying it."
2368 (unless org-agenda-multi
2370 (let ((inhibit-read-only t
))
2371 (goto-char (point-min))
2372 (while (org-activate-bracket-links (point-max))
2373 (add-text-properties (match-beginning 0) (match-end 0)
2375 (org-agenda-align-tags)
2376 (unless org-agenda-with-colors
2377 (remove-text-properties (point-min) (point-max) '(face nil
))))
2378 (if (and (boundp 'org-agenda-overriding-columns-format
)
2379 org-agenda-overriding-columns-format
)
2380 (org-set-local 'org-agenda-overriding-columns-format
2381 org-agenda-overriding-columns-format
))
2382 (if (and (boundp 'org-agenda-view-columns-initially
)
2383 org-agenda-view-columns-initially
)
2384 (org-agenda-columns))
2385 (when org-agenda-fontify-priorities
2386 (org-agenda-fontify-priorities))
2387 (when (and org-agenda-dim-blocked-tasks org-blocker-hook
)
2388 (org-agenda-dim-blocked-tasks))
2389 (run-hooks 'org-finalize-agenda-hook
)
2390 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
2391 (when (get 'org-agenda-filter
:preset-filter
)
2392 (org-agenda-filter-apply org-agenda-filter
))
2395 (defun org-agenda-fontify-priorities ()
2396 "Make highest priority lines bold, and lowest italic."
2398 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
2399 (org-delete-overlay o
)))
2400 (org-overlays-in (point-min) (point-max)))
2402 (let ((inhibit-read-only t
)
2404 (goto-char (point-min))
2405 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
2406 (setq h
(or (get-char-property (point) 'org-highest-priority
)
2407 org-highest-priority
)
2408 l
(or (get-char-property (point) 'org-lowest-priority
)
2409 org-lowest-priority
)
2410 p
(string-to-char (match-string 1))
2411 b
(match-beginning 0)
2412 e
(if (eq org-agenda-fontify-priorities
'cookies
)
2415 ov
(org-make-overlay b e
))
2418 (cond ((cdr (assoc p org-priority-faces
)))
2419 ((and (listp org-agenda-fontify-priorities
)
2420 (cdr (assoc p org-agenda-fontify-priorities
))))
2421 ((equal p l
) 'italic
)
2422 ((equal p h
) 'bold
)))
2423 (org-overlay-put ov
'org-type
'org-priority
)))))
2425 (defun org-agenda-dim-blocked-tasks ()
2426 "Dim currently blocked TODO's in the agenda display."
2427 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-blocked-todo
)
2428 (org-delete-overlay o
)))
2429 (org-overlays-in (point-min) (point-max)))
2431 (let ((inhibit-read-only t
)
2432 (org-depend-tag-blocked nil
)
2433 (invis (eq org-agenda-dim-blocked-tasks
'invisible
))
2434 org-blocked-by-checkboxes
2435 invis1 b e p ov h l
)
2436 (goto-char (point-min))
2437 (while (let ((pos (next-single-property-change (point) 'todo-state
)))
2438 (and pos
(goto-char (1+ pos
))))
2439 (setq org-blocked-by-checkboxes nil invis1 invis
)
2440 (let ((marker (get-text-property (point) 'org-hd-marker
)))
2442 (not (with-current-buffer (marker-buffer marker
)
2445 (if (org-entry-get nil
"NOBLOCKING")
2446 t
;; Never block this entry
2447 (run-hook-with-args-until-failure
2449 (list :type
'todo-state-change
2453 (if org-blocked-by-checkboxes
(setq invis1 nil
))
2454 (setq b
(if invis1
(max (point-min) (1- (point))) (point))
2456 ov
(org-make-overlay b e
))
2458 (org-overlay-put ov
'invisible t
)
2459 (org-overlay-put ov
'face
'org-agenda-dimmed-todo-face
))
2460 (org-overlay-put ov
'org-type
'org-blocked-todo
)))))))
2462 (defvar org-agenda-skip-function nil
2463 "Function to be called at each match during agenda construction.
2464 If this function returns nil, the current match should not be skipped.
2465 Otherwise, the function must return a position from where the search
2466 should be continued.
2467 This may also be a Lisp form, it will be evaluated.
2468 Never set this variable using `setq' or so, because then it will apply
2469 to all future agenda commands. Instead, bind it with `let' to scope
2470 it dynamically into the agenda-constructing command. A good way to set
2471 it is through options in org-agenda-custom-commands.")
2473 (defun org-agenda-skip ()
2474 "Throw to `:skip' in places that should be skipped.
2475 Also moves point to the end of the skipped region, so that search can
2476 continue from there."
2477 (let ((p (point-at-bol)) to fp
)
2478 (and org-agenda-skip-archived-trees
(not org-agenda-archives-mode
)
2479 (get-text-property p
:org-archived
)
2480 (org-end-of-subtree t
)
2482 (and org-agenda-skip-comment-trees
2483 (get-text-property p
:org-comment
)
2484 (org-end-of-subtree t
)
2486 (if (equal (char-after p
) ?
#) (throw :skip t
))
2487 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
2488 (consp org-agenda-skip-function
))
2489 (setq to
(save-excursion
2492 (funcall org-agenda-skip-function
)
2493 (eval org-agenda-skip-function
))))))
2497 (defvar org-agenda-markers nil
2498 "List of all currently active markers created by `org-agenda'.")
2499 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
2500 "Creation time of the last agenda marker.")
2502 (defun org-agenda-new-marker (&optional pos
)
2503 "Return a new agenda marker.
2504 Org-mode keeps a list of these markers and resets them when they are
2506 (let ((m (copy-marker (or pos
(point)))))
2507 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
2508 (push m org-agenda-markers
)
2511 (defun org-agenda-reset-markers ()
2512 "Reset markers created by `org-agenda'."
2513 (while org-agenda-markers
2514 (move-marker (pop org-agenda-markers
) nil
)))
2516 (defun org-agenda-save-markers-for-cut-and-paste (beg end
)
2517 "Save relative positions of markers in region."
2518 (mapc (lambda (m) (org-check-and-save-marker m beg end
))
2519 org-agenda-markers
))
2523 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
2525 (defun org-timeline (&optional include-all
)
2526 "Show a time-sorted view of the entries in the current org file.
2527 Only entries with a time stamp of today or later will be listed. With
2528 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2529 under the current date.
2530 If the buffer contains an active region, only check the region for
2534 (org-compile-prefix-format 'timeline
)
2535 (org-set-sorting-strategy 'timeline
)
2537 (dotodo include-all
)
2538 (doclosed org-agenda-show-log
)
2539 (entry buffer-file-name
)
2540 (date (calendar-current-date))
2541 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2542 (end (if (org-region-active-p) (region-end) (point-max)))
2543 (day-numbers (org-get-all-dates beg end
'no-ranges
2544 t doclosed
; always include today
2545 org-timeline-show-empty-dates
))
2546 (org-deadline-warning-days 0)
2547 (org-agenda-only-exact-dates t
)
2548 (today (time-to-days (current-time)))
2551 s e rtn d emptyp wd
)
2552 (setq org-agenda-redo-command
2554 (list 'org-switch-to-buffer-other-window
(current-buffer))
2555 (list 'org-timeline
(list 'quote include-all
))))
2557 ;; Remove past dates from the list of dates.
2558 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2559 (if (>= x today
) x nil
))
2561 (org-prepare-agenda (concat "Timeline "
2562 (file-name-nondirectory buffer-file-name
)))
2563 (if doclosed
(push :closed args
))
2564 (push :timestamp args
)
2565 (push :deadline args
)
2566 (push :scheduled args
)
2568 (if dotodo
(push :todo args
))
2569 (while (setq d
(pop day-numbers
))
2570 (if (and (listp d
) (eq (car d
) :omitted
))
2573 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2574 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2575 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2576 (if (and (>= d today
)
2581 (insert (make-string 79 ?-
) "\n")))
2582 (setq date
(calendar-gregorian-from-absolute d
)
2583 wd
(calendar-day-of-week date
))
2585 (setq rtn
(and (not emptyp
)
2586 (apply 'org-agenda-get-day-entries entry
2588 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2591 (if (stringp org-agenda-format-date
)
2592 (format-time-string org-agenda-format-date
2593 (org-time-from-absolute date
))
2594 (funcall org-agenda-format-date date
))
2596 (put-text-property s
(1- (point)) 'face
2597 (if (member wd org-agenda-weekend-days
)
2598 'org-agenda-date-weekend
2600 (put-text-property s
(1- (point)) 'org-date-line t
)
2602 (put-text-property s
(1- (point)) 'org-today t
))
2603 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2604 (put-text-property s
(1- (point)) 'day d
)))))
2605 (goto-char (point-min))
2606 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2608 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2609 (org-finalize-agenda)
2610 (setq buffer-read-only t
)))
2612 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2613 "Return a list of all relevant day numbers from BEG to END buffer positions.
2614 If NO-RANGES is non-nil, include only the start and end dates of a range,
2615 not every single day in the range. If FORCE-TODAY is non-nil, make
2616 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2617 inactive time stamps (those in square brackets) are included.
2618 When EMPTY is non-nil, also include days without any entries."
2620 (if pre-re pre-re
"")
2621 (if inactive org-ts-regexp-both org-ts-regexp
)))
2622 dates dates1 date day day1 day2 ts1 ts2
)
2624 (setq dates
(list (time-to-days (current-time)))))
2627 (while (re-search-forward re end t
)
2628 (setq day
(time-to-days (org-time-string-to-time
2629 (substring (match-string 1) 0 10))))
2630 (or (memq day dates
) (push day dates
)))
2633 (while (re-search-forward org-tr-regexp end t
)
2634 (setq ts1
(substring (match-string 1) 0 10)
2635 ts2
(substring (match-string 2) 0 10)
2636 day1
(time-to-days (org-time-string-to-time ts1
))
2637 day2
(time-to-days (org-time-string-to-time ts2
)))
2638 (while (< (setq day1
(1+ day1
)) day2
)
2639 (or (memq day1 dates
) (push day1 dates
)))))
2640 (setq dates
(sort dates
'<))
2642 (while (setq day
(pop dates
))
2643 (setq day2
(car dates
))
2645 (when (and day2 empty
)
2646 (if (or (eq empty t
)
2647 (and (numberp empty
) (<= (- day2 day
) empty
)))
2648 (while (< (setq day
(1+ day
)) day2
)
2649 (push (list day
) dates1
))
2650 (push (cons :omitted
(- day2 day
)) dates1
))))
2651 (setq dates
(nreverse dates1
)))
2654 ;;; Agenda Daily/Weekly
2656 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2657 (defvar org-agenda-start-day nil
; dynamically scoped parameter
2658 "Custom commands can set this variable in the options section.")
2659 (defvar org-agenda-last-arguments nil
2660 "The arguments of the previous call to org-agenda")
2661 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2662 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2663 (defvar org-include-all-loc nil
) ; local variable
2664 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2667 (defun org-agenda-list (&optional include-all start-day ndays
)
2668 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2669 The view will be for the current day or week, but from the overview buffer
2670 you will be able to go to other days/weeks.
2672 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2673 all unfinished TODO items will also be shown, before the agenda.
2674 This feature is considered obsolete, please use the TODO list or a block
2677 With a numeric prefix argument in an interactive call, the agenda will
2678 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2679 the number of days. NDAYS defaults to `org-agenda-ndays'.
2681 START-DAY defaults to TODAY, or to the most recent match for the weekday
2682 given in `org-agenda-start-on-weekday'."
2684 (if (and (integerp include-all
) (> include-all
0))
2685 (setq ndays include-all include-all nil
))
2686 (setq ndays
(or ndays org-agenda-ndays
)
2687 start-day
(or start-day org-agenda-start-day
))
2688 (if org-agenda-overriding-arguments
2689 (setq include-all
(car org-agenda-overriding-arguments
)
2690 start-day
(nth 1 org-agenda-overriding-arguments
)
2691 ndays
(nth 2 org-agenda-overriding-arguments
)))
2692 (if (stringp start-day
)
2693 ;; Convert to an absolute day number
2694 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2695 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2696 (org-compile-prefix-format 'agenda
)
2697 (org-set-sorting-strategy 'agenda
)
2699 (let* ((org-agenda-start-on-weekday
2700 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2701 org-agenda-start-on-weekday nil
))
2702 (thefiles (org-agenda-files nil
'ifmode
))
2704 (today (time-to-days
2705 (time-subtract (current-time)
2706 (list 0 (* 3600 org-extend-today-until
) 0))))
2707 (sd (or start-day today
))
2708 (start (if (or (null org-agenda-start-on-weekday
)
2709 (< org-agenda-ndays
7))
2711 (let* ((nt (calendar-day-of-week
2712 (calendar-gregorian-from-absolute sd
)))
2713 (n1 org-agenda-start-on-weekday
)
2715 (- sd
(+ (if (< d
0) 7 0) d
)))))
2716 (day-numbers (list start
))
2718 (inhibit-redisplay (not debug-on-error
))
2719 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2720 clocktable-start clocktable-end
)
2721 (setq org-agenda-redo-command
2722 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2723 ;; Make the list of days
2724 (setq ndays
(or ndays org-agenda-ndays
)
2727 (push (1+ (car day-numbers
)) day-numbers
)
2728 (setq ndays
(1- ndays
)))
2729 (setq day-numbers
(nreverse day-numbers
))
2730 (setq clocktable-start
(car day-numbers
)
2731 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2732 (org-prepare-agenda "Day/Week")
2733 (org-set-local 'org-starting-day
(car day-numbers
))
2734 (org-set-local 'org-include-all-loc include-all
)
2735 (org-set-local 'org-agenda-span
2736 (org-agenda-ndays-to-span nd
))
2737 (when (and (or include-all org-agenda-include-all-todo
)
2738 (member today day-numbers
))
2739 (setq files thefiles
2741 (while (setq file
(pop files
))
2743 (org-check-agenda-file file
)
2744 (setq date
(calendar-gregorian-from-absolute today
)
2745 rtn
(org-agenda-get-day-entries
2747 (setq rtnall
(append rtnall rtn
))))
2749 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2750 (add-text-properties (point-min) (1- (point))
2751 (list 'face
'org-agenda-structure
))
2752 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2753 (unless org-agenda-compact-blocks
2754 (let* ((d1 (car day-numbers
))
2755 (d2 (org-last day-numbers
))
2756 (w1 (org-days-to-iso-week d1
))
2757 (w2 (org-days-to-iso-week d2
)))
2759 (if org-agenda-overriding-header
2760 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2761 nil
'face
'org-agenda-structure
) "\n")
2762 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2764 (if (< (- d2 d1
) 350)
2766 (format " (W%02d)" w1
)
2767 (format " (W%02d-W%02d)" w1 w2
))
2770 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2772 (while (setq d
(pop day-numbers
))
2773 (setq date
(calendar-gregorian-from-absolute d
)
2774 wd
(calendar-day-of-week date
)
2776 (if (or (setq todayp
(= d today
))
2777 (and (not start-pos
) (= d sd
)))
2778 (setq start-pos
(point))
2779 (if (and start-pos
(not end-pos
))
2780 (setq end-pos
(point))))
2781 (setq files thefiles
2783 (while (setq file
(pop files
))
2785 (org-check-agenda-file file
)
2787 ((eq org-agenda-show-log
'only
)
2788 (setq rtn
(org-agenda-get-day-entries
2789 file date
:closed
)))
2790 (org-agenda-show-log
2791 (setq rtn
(org-agenda-get-day-entries
2793 :deadline
:scheduled
:timestamp
:sexp
:closed
)))
2795 (setq rtn
(org-agenda-get-day-entries
2797 :deadline
:scheduled
:sexp
:timestamp
))))
2798 (setq rtnall
(append rtnall rtn
))))
2799 (if org-agenda-include-diary
2800 (let ((org-agenda-search-headline-for-time t
))
2801 (require 'diary-lib
)
2802 (setq rtn
(org-get-entries-from-diary date
))
2803 (setq rtnall
(append rtnall rtn
))))
2804 (if (or rtnall org-agenda-show-all-dates
)
2806 (setq day-cnt
(1+ day-cnt
))
2808 (if (stringp org-agenda-format-date
)
2809 (format-time-string org-agenda-format-date
2810 (org-time-from-absolute date
))
2811 (funcall org-agenda-format-date date
))
2813 (put-text-property s
(1- (point)) 'face
2814 (if (member wd org-agenda-weekend-days
)
2815 'org-agenda-date-weekend
2817 (put-text-property s
(1- (point)) 'org-date-line t
)
2818 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2819 (if todayp
(put-text-property s
(1- (point)) 'org-today t
))
2821 (org-finalize-agenda-entries
2822 (org-agenda-add-time-grid-maybe
2825 (put-text-property s
(1- (point)) 'day d
)
2826 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2827 (when (and org-agenda-clockreport-mode clocktable-start
)
2828 (let ((org-agenda-files (org-agenda-files nil
'ifmode
))
2829 ;; the above line is to ensure the restricted range!
2830 (p org-agenda-clockreport-parameter-plist
)
2832 (setq p
(org-plist-delete p
:block
))
2833 (setq p
(plist-put p
:tstart clocktable-start
))
2834 (setq p
(plist-put p
:tend clocktable-end
))
2835 (setq p
(plist-put p
:scope
'agenda
))
2836 (setq tbl
(apply 'org-get-clocktable p
))
2838 (goto-char (point-min))
2839 (or org-agenda-multi
(org-fit-agenda-window))
2840 (unless (and (pos-visible-in-window-p (point-min))
2841 (pos-visible-in-window-p (point-max)))
2842 (goto-char (1- (point-max)))
2844 (if (not (pos-visible-in-window-p (or start-pos
1)))
2846 (goto-char (or start-pos
1))
2848 (goto-char (or start-pos
1))
2849 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2850 (org-finalize-agenda)
2851 (setq buffer-read-only t
)
2854 (defun org-agenda-ndays-to-span (n)
2855 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2857 ;;; Agenda word search
2859 (defvar org-agenda-search-history nil
)
2860 (defvar org-todo-only nil
)
2862 (defvar org-search-syntax-table nil
2863 "Special syntax table for org-mode search.
2864 In this table, we have single quotes not as word constituents, to
2865 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
2867 (defun org-search-syntax-table ()
2868 (unless org-search-syntax-table
2869 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2870 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2871 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2872 org-search-syntax-table
)
2875 (defun org-search-view (&optional todo-only string edit-at
)
2876 "Show all entries that contain words or regular expressions.
2877 If the first character of the search string is an asterisks,
2878 search only the headlines.
2880 With optional prefix argument TODO-ONLY, only consider entries that are
2881 TODO entries. The argument STRING can be used to pass a default search
2882 string into this function. If EDIT-AT is non-nil, it means that the
2883 user should get a chance to edit this string, with cursor at position
2886 The search string is broken into \"words\" by splitting at whitespace.
2887 The individual words are then interpreted as a boolean expression with
2888 logical AND. Words prefixed with a minus must not occur in the entry.
2889 Words without a prefix or prefixed with a plus must occur in the entry.
2890 Matching is case-insensitive and the words are enclosed by word delimiters.
2892 Words enclosed by curly braces are interpreted as regular expressions
2893 that must or must not match in the entry.
2895 If the search string starts with an asterisk, search only in headlines.
2896 If (possibly after the leading star) the search string starts with an
2897 exclamation mark, this also means to look at TODO entries only, an effect
2898 that can also be achieved with a prefix argument.
2900 This command searches the agenda files, and in addition the files listed
2901 in `org-agenda-text-search-extra-files'."
2903 (org-compile-prefix-format 'search
)
2904 (org-set-sorting-strategy 'search
)
2905 (org-prepare-agenda "SEARCH")
2906 (let* ((props (list 'face nil
2907 'done-face
'org-agenda-done
2908 'org-not-done-regexp org-not-done-regexp
2909 'org-todo-regexp org-todo-regexp
2910 'org-complex-heading-regexp org-complex-heading-regexp
2911 'mouse-face
'highlight
2912 'keymap org-agenda-keymap
2913 'help-echo
(format "mouse-2 or RET jump to location")))
2914 regexp rtn rtnall files file pos
2915 marker category tags c neg re
2916 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2917 (unless (and (not edit-at
)
2919 (string-match "\\S-" string
))
2920 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2922 ((integerp edit-at
) (cons string edit-at
))
2924 'org-agenda-search-history
)))
2925 (org-set-local 'org-todo-only todo-only
)
2926 (setq org-agenda-redo-command
2927 (list 'org-search-view
(if todo-only t nil
) string
2928 '(if current-prefix-arg
1 nil
)))
2929 (setq org-agenda-query-string string
)
2931 (if (equal (string-to-char string
) ?
*)
2933 words
(substring string
1))
2934 (setq words string
))
2935 (when (equal (string-to-char words
) ?
!)
2937 words
(substring words
1)))
2938 (setq words
(org-split-string words
))
2940 (setq c
(string-to-char w
))
2942 (setq neg t w
(substring w
1))
2944 (setq neg nil w
(substring w
1))
2946 (if (string-match "\\`{.*}\\'" w
)
2947 (setq re
(substring w
1 -
1))
2948 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2949 (if neg
(push re regexps-
) (push re regexps
+)))
2951 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2953 (setq regexp
(concat "^" org-outline-regexp
))
2954 (setq regexp
(pop regexps
+))
2955 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2957 (setq files
(org-agenda-files nil
'ifmode
))
2958 (when (eq (car org-agenda-text-search-extra-files
) 'agenda-archives
)
2959 (pop org-agenda-text-search-extra-files
)
2960 (setq files
(org-add-archive-files files
)))
2961 (setq files
(append files org-agenda-text-search-extra-files
)
2963 (while (setq file
(pop files
))
2966 (org-check-agenda-file file
)
2967 (setq buffer
(if (file-exists-p file
)
2968 (org-get-agenda-file-buffer file
)
2969 (error "No such file %s" file
)))
2971 ;; If file does not exist, make sure an error message is sent
2972 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2974 (with-current-buffer buffer
2975 (with-syntax-table (org-search-syntax-table)
2976 (unless (org-mode-p)
2977 (error "Agenda file %s is not in `org-mode'" file
))
2978 (let ((case-fold-search t
))
2981 (if org-agenda-restrict
2982 (narrow-to-region org-agenda-restrict-begin
2983 org-agenda-restrict-end
)
2985 (goto-char (point-min))
2986 (unless (or (org-on-heading-p)
2987 (outline-next-heading))
2988 (throw 'nextfile t
))
2989 (goto-char (max (point-min) (1- (point))))
2990 (while (re-search-forward regexp nil t
)
2991 (org-back-to-heading t
)
2992 (skip-chars-forward "* ")
2993 (setq beg
(point-at-bol)
2995 end
(progn (outline-next-heading) (point)))
2999 (setq str
(buffer-substring-no-properties
3001 (if hdl-only
(point-at-eol) end
)))
3002 (mapc (lambda (wr) (when (string-match wr str
)
3003 (goto-char (1- end
))
3006 (mapc (lambda (wr) (unless (string-match wr str
)
3007 (goto-char (1- end
))
3010 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
3014 (setq marker
(org-agenda-new-marker (point))
3015 category
(org-get-category)
3016 tags
(org-get-tags-at (point))
3017 txt
(org-format-agenda-item
3019 (buffer-substring-no-properties
3020 beg1
(point-at-eol))
3022 (org-add-props txt props
3023 'org-marker marker
'org-hd-marker marker
3024 'org-todo-regexp org-todo-regexp
3025 'org-complex-heading-regexp org-complex-heading-regexp
3026 'priority
1000 'org-category category
3029 (goto-char (1- end
))))))))))
3030 (setq rtn
(nreverse ee
))
3031 (setq rtnall
(append rtnall rtn
)))
3032 (if org-agenda-overriding-header
3033 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3034 nil
'face
'org-agenda-structure
) "\n")
3035 (insert "Search words: ")
3036 (add-text-properties (point-min) (1- (point))
3037 (list 'face
'org-agenda-structure
))
3039 (insert string
"\n")
3040 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3042 (unless org-agenda-multi
3043 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3044 (add-text-properties pos
(1- (point))
3045 (list 'face
'org-agenda-structure
))))
3047 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3048 (goto-char (point-min))
3049 (or org-agenda-multi
(org-fit-agenda-window))
3050 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
3051 (org-finalize-agenda)
3052 (setq buffer-read-only t
)))
3054 ;;; Agenda TODO list
3056 (defvar org-select-this-todo-keyword nil
)
3057 (defvar org-last-arg nil
)
3060 (defun org-todo-list (arg)
3061 "Show all TODO entries from all agenda file in a single list.
3062 The prefix arg can be used to select a specific TODO keyword and limit
3063 the list to these. When using \\[universal-argument], you will be prompted
3064 for a keyword. A numeric prefix directly selects the Nth keyword in
3065 `org-todo-keywords-1'."
3068 (org-compile-prefix-format 'todo
)
3069 (org-set-sorting-strategy 'todo
)
3070 (org-prepare-agenda "TODO")
3071 (let* ((today (time-to-days (current-time)))
3072 (date (calendar-gregorian-from-absolute today
))
3073 (kwds org-todo-keywords-for-agenda
)
3074 (completion-ignore-case t
)
3075 (org-select-this-todo-keyword
3076 (if (stringp arg
) arg
3077 (and arg
(integerp arg
) (> arg
0)
3078 (nth (1- arg
) kwds
))))
3079 rtn rtnall files file pos
)
3080 (when (equal arg
'(4))
3081 (setq org-select-this-todo-keyword
3082 (org-ido-completing-read "Keyword (or KWD1|K2D2|...): "
3083 (mapcar 'list kwds
) nil nil
)))
3084 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
3085 (org-set-local 'org-last-arg arg
)
3086 (setq org-agenda-redo-command
3087 '(org-todo-list (or current-prefix-arg org-last-arg
)))
3088 (setq files
(org-agenda-files nil
'ifmode
)
3090 (while (setq file
(pop files
))
3092 (org-check-agenda-file file
)
3093 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
3094 (setq rtnall
(append rtnall rtn
))))
3095 (if org-agenda-overriding-header
3096 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3097 nil
'face
'org-agenda-structure
) "\n")
3098 (insert "Global list of TODO items of type: ")
3099 (add-text-properties (point-min) (1- (point))
3100 (list 'face
'org-agenda-structure
))
3102 (insert (or org-select-this-todo-keyword
"ALL") "\n")
3103 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3105 (unless org-agenda-multi
3106 (insert "Available with `N r': (0)ALL")
3109 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
3110 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
3115 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3117 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3118 (goto-char (point-min))
3119 (or org-agenda-multi
(org-fit-agenda-window))
3120 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
3121 (org-finalize-agenda)
3122 (setq buffer-read-only t
)))
3124 ;;; Agenda tags match
3127 (defun org-tags-view (&optional todo-only match
)
3128 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3129 The prefix arg TODO-ONLY limits the search to TODO entries."
3131 (org-compile-prefix-format 'tags
)
3132 (org-set-sorting-strategy 'tags
)
3133 (let* ((org-tags-match-list-sublevels
3134 (if todo-only t org-tags-match-list-sublevels
))
3135 (completion-ignore-case t
)
3136 rtn rtnall files file pos matcher
3138 (setq matcher
(org-make-tags-matcher match
)
3139 match
(car matcher
) matcher
(cdr matcher
))
3140 (org-prepare-agenda (concat "TAGS " match
))
3141 (setq org-agenda-query-string match
)
3142 (setq org-agenda-redo-command
3143 (list 'org-tags-view
(list 'quote todo-only
)
3144 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
3145 (setq files
(org-agenda-files nil
'ifmode
)
3147 (while (setq file
(pop files
))
3149 (org-check-agenda-file file
)
3150 (setq buffer
(if (file-exists-p file
)
3151 (org-get-agenda-file-buffer file
)
3152 (error "No such file %s" file
)))
3154 ;; If file does not exist, error message to agenda
3156 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3157 rtnall
(append rtnall rtn
))
3158 (with-current-buffer buffer
3159 (unless (org-mode-p)
3160 (error "Agenda file %s is not in `org-mode'" file
))
3163 (if org-agenda-restrict
3164 (narrow-to-region org-agenda-restrict-begin
3165 org-agenda-restrict-end
)
3167 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
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 "Headlines with TAGS match: ")
3173 (add-text-properties (point-min) (1- (point))
3174 (list 'face
'org-agenda-structure
))
3177 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3179 (unless org-agenda-multi
3180 (insert "Press `C-u r' to search again with new search string\n"))
3181 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3183 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3184 (goto-char (point-min))
3185 (or org-agenda-multi
(org-fit-agenda-window))
3186 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
3187 (org-finalize-agenda)
3188 (setq buffer-read-only t
)))
3190 ;;; Agenda Finding stuck projects
3192 (defvar org-agenda-skip-regexp nil
3193 "Regular expression used in skipping subtrees for the agenda.
3194 This is basically a temporary global variable that can be set and then
3195 used by user-defined selections using `org-agenda-skip-function'.")
3197 (defvar org-agenda-overriding-header nil
3198 "When this is set during todo and tags searches, will replace header.
3199 This variable should not be set directly, but custom commands can bind it
3200 in the options section.")
3202 (defun org-agenda-skip-entry-when-regexp-matches ()
3203 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3204 If yes, it returns the end position of this entry, causing agenda commands
3205 to skip the entry but continuing the search in the subtree. This is a
3206 function that can be put into `org-agenda-skip-function' for the duration
3208 (let ((end (save-excursion (org-end-of-subtree t
)))
3211 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3214 (defun org-agenda-skip-subtree-when-regexp-matches ()
3215 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3216 If yes, it returns the end position of this tree, causing agenda commands
3217 to skip this subtree. This is a function that can be put into
3218 `org-agenda-skip-function' for the duration of a command."
3219 (let ((end (save-excursion (org-end-of-subtree t
)))
3222 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3225 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3226 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3227 If yes, it returns the end position of the current entry (NOT the tree),
3228 causing agenda commands to skip the entry but continuing the search in
3229 the subtree. This is a function that can be put into
3230 `org-agenda-skip-function' for the duration of a command. An important
3231 use of this function is for the stuck project list."
3232 (let ((end (save-excursion (org-end-of-subtree t
)))
3233 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3236 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3237 (and skip entry-end
)))
3239 (defun org-agenda-skip-entry-if (&rest conditions
)
3240 "Skip entry if any of CONDITIONS is true.
3241 See `org-agenda-skip-if' for details."
3242 (org-agenda-skip-if nil conditions
))
3244 (defun org-agenda-skip-subtree-if (&rest conditions
)
3245 "Skip entry if any of CONDITIONS is true.
3246 See `org-agenda-skip-if' for details."
3247 (org-agenda-skip-if t conditions
))
3249 (defun org-agenda-skip-if (subtree conditions
)
3250 "Checks current entity for CONDITIONS.
3251 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3252 the entry, i.e. the text before the next heading is checked.
3254 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3255 from different tests. Valid conditions are:
3257 scheduled Check if there is a scheduled cookie
3258 notscheduled Check if there is no scheduled cookie
3259 deadline Check if there is a deadline
3260 notdeadline Check if there is no deadline
3261 timestamp Check if there is a timestamp (also deadline or scheduled)
3262 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3263 regexp Check if regexp matches
3264 notregexp Check if regexp does not match.
3266 The regexp is taken from the conditions list, it must come right after
3267 the `regexp' or `notregexp' element.
3269 If any of these conditions is met, this function returns the end point of
3270 the entity, causing the search to continue from there. This is a function
3271 that can be put into `org-agenda-skip-function' for the duration of a command."
3273 (org-back-to-heading t
)
3276 (progn (org-end-of-subtree t
) (point))
3277 (progn (outline-next-heading) (1- (point)))))
3281 (and (memq 'scheduled conditions
)
3282 (re-search-forward org-scheduled-time-regexp end t
))
3283 (and (memq 'notscheduled conditions
)
3284 (not (re-search-forward org-scheduled-time-regexp end t
)))
3285 (and (memq 'deadline conditions
)
3286 (re-search-forward org-deadline-time-regexp end t
))
3287 (and (memq 'notdeadline conditions
)
3288 (not (re-search-forward org-deadline-time-regexp end t
)))
3289 (and (memq 'timestamp conditions
)
3290 (re-search-forward org-ts-regexp end t
))
3291 (and (memq 'nottimestamp conditions
)
3292 (not (re-search-forward org-ts-regexp end t
)))
3293 (and (setq m
(memq 'regexp conditions
))
3295 (re-search-forward (nth 1 m
) end t
))
3296 (and (setq m
(memq 'notregexp conditions
))
3298 (not (re-search-forward (nth 1 m
) end t
))))
3302 (defun org-agenda-list-stuck-projects (&rest ignore
)
3303 "Create agenda view for projects that are stuck.
3304 Stuck projects are project that have no next actions. For the definitions
3305 of what a project is and how to check if it stuck, customize the variable
3306 `org-stuck-projects'.
3307 MATCH is being ignored."
3309 (let* ((org-agenda-skip-function
3310 'org-agenda-skip-entry-when-regexp-matches-in-subtree
)
3311 ;; We could have used org-agenda-skip-if here.
3312 (org-agenda-overriding-header "List of stuck projects: ")
3313 (matcher (nth 0 org-stuck-projects
))
3314 (todo (nth 1 org-stuck-projects
))
3315 (todo-wds (if (member "*" todo
)
3317 (org-prepare-agenda-buffers (org-agenda-files
3320 org-done-keywords-for-agenda
3321 (copy-sequence org-todo-keywords-for-agenda
)))
3323 (todo-re (concat "^\\*+[ \t]+\\("
3324 (mapconcat 'identity todo-wds
"\\|")
3326 (tags (nth 2 org-stuck-projects
))
3327 (tags-re (if (member "*" tags
)
3328 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3330 (concat "^\\*+ .*:\\("
3331 (mapconcat 'identity tags
"\\|")
3332 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3333 (gen-re (nth 3 org-stuck-projects
))
3339 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
3341 (setq org-agenda-skip-regexp
3343 (mapconcat 'identity re-list
"\\|")
3344 (error "No information how to identify unstuck projects")))
3345 (org-tags-view nil matcher
)
3346 (with-current-buffer org-agenda-buffer-name
3347 (setq org-agenda-redo-command
3348 '(org-agenda-list-stuck-projects
3349 (or current-prefix-arg org-last-arg
))))))
3351 ;;; Diary integration
3353 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
3354 (defvar list-diary-entries-hook
)
3356 (defun org-get-entries-from-diary (date)
3357 "Get the (Emacs Calendar) diary entries for DATE."
3358 (require 'diary-lib
)
3359 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3360 (fancy-diary-buffer diary-fancy-buffer
)
3361 (diary-display-hook '(fancy-diary-display))
3362 (diary-display-function 'fancy-diary-display
)
3364 (list-diary-entries-hook
3365 (cons 'org-diary-default-entry list-diary-entries-hook
))
3366 (diary-file-name-prefix-function nil
) ; turn this feature off
3367 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
3369 (org-disable-agenda-to-diary t
))
3371 (save-window-excursion
3372 (funcall (if (fboundp 'diary-list-entries
)
3373 'diary-list-entries
'list-diary-entries
)
3375 (if (not (get-buffer diary-fancy-buffer
))
3377 (with-current-buffer diary-fancy-buffer
3378 (setq buffer-read-only nil
)
3379 (if (zerop (buffer-size))
3382 ;; Omit the date and other unnecessary stuff
3383 (org-agenda-cleanup-fancy-diary)
3384 ;; Add prefix to each line and extend the text properties
3385 (if (zerop (buffer-size))
3387 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
3388 (set-buffer-modified-p nil
)
3389 (kill-buffer diary-fancy-buffer
)))
3391 (setq entries
(org-split-string entries
"\n"))
3395 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
3396 ;; Extend the text properties to the beginning of the line
3397 (org-add-props x
(text-properties-at (1- (length x
)) x
)
3398 'type
"diary" 'date date
))
3401 (defvar org-agenda-cleanup-fancy-diary-hook nil
3402 "Hook run when the fancy diary buffer is cleaned up.")
3404 (defun org-agenda-cleanup-fancy-diary ()
3405 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3406 This gets rid of the date, the underline under the date, and
3407 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3408 date. It also removes lines that contain only whitespace."
3409 (goto-char (point-min))
3410 (if (looking-at ".*?:[ \t]*")
3413 (re-search-forward "\n=+$" nil t
)
3415 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
3416 (re-search-forward "\n=+$" nil t
)
3417 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3418 (goto-char (point-min))
3419 (while (re-search-forward "^ +\n" nil t
)
3421 (goto-char (point-min))
3422 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
3424 (run-hooks 'org-agenda-cleanup-fancy-diary-hook
))
3426 ;; Make sure entries from the diary have the right text properties.
3427 (eval-after-load "diary-lib"
3428 '(if (boundp 'diary-modify-entry-list-string-function
)
3429 ;; We can rely on the hook, nothing to do
3431 ;; Hook not available, must use advice to make this work
3432 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
3433 "Make the position visible."
3434 (if (and org-disable-agenda-to-diary
;; called from org-agenda
3437 (setq string
(org-modify-diary-entry-string string
))))))
3439 (defun org-modify-diary-entry-string (string)
3440 "Add text properties to string, allowing org-mode to act on it."
3441 (org-add-props string nil
3442 'mouse-face
'highlight
3443 'keymap org-agenda-keymap
3444 'help-echo
(if buffer-file-name
3445 (format "mouse-2 or RET jump to diary file %s"
3446 (abbreviate-file-name buffer-file-name
))
3448 'org-agenda-diary-link t
3449 'org-marker
(org-agenda-new-marker (point-at-bol))))
3451 (defun org-diary-default-entry ()
3452 "Add a dummy entry to the diary.
3453 Needed to avoid empty dates which mess up holiday display."
3454 ;; Catch the error if dealing with the new add-to-diary-alist
3455 (when org-disable-agenda-to-diary
3457 (org-add-to-diary-list original-date
"Org-mode dummy" "")
3459 (org-add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
3461 (defun org-add-to-diary-list (&rest args
)
3462 (if (fboundp 'diary-add-to-list
)
3463 (apply 'diary-add-to-list args
)
3464 (apply 'add-to-diary-list args
)))
3467 (defun org-diary (&rest args
)
3468 "Return diary information from org-files.
3469 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3470 It accesses org files and extracts information from those files to be
3471 listed in the diary. The function accepts arguments specifying what
3472 items should be listed. The following arguments are allowed:
3474 :timestamp List the headlines of items containing a date stamp or
3475 date range matching the selected date. Deadlines will
3476 also be listed, on the expiration day.
3478 :sexp List entries resulting from diary-like sexps.
3480 :deadline List any deadlines past due, or due within
3481 `org-deadline-warning-days'. The listing occurs only
3482 in the diary for *today*, not at any other date. If
3483 an entry is marked DONE, it is no longer listed.
3485 :scheduled List all items which are scheduled for the given date.
3486 The diary for *today* also contains items which were
3487 scheduled earlier and are not yet marked DONE.
3489 :todo List all TODO items from the org-file. This may be a
3490 long list - so this is not turned on by default.
3491 Like deadlines, these entries only show up in the
3492 diary for *today*, not at any other date.
3494 The call in the diary file should look like this:
3496 &%%(org-diary) ~/path/to/some/orgfile.org
3498 Use a separate line for each org file to check. Or, if you omit the file name,
3499 all files listed in `org-agenda-files' will be checked automatically:
3503 If you don't give any arguments (as in the example above), the default
3504 arguments (:deadline :scheduled :timestamp :sexp) are used.
3505 So the example above may also be written as
3507 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3509 The function expects the lisp variables `entry' and `date' to be provided
3510 by the caller, because this is how the calendar works. Don't use this
3511 function from a program - use `org-agenda-get-day-entries' instead."
3512 (when (> (- (time-to-seconds (current-time))
3513 org-agenda-last-marker-time
)
3515 (org-agenda-reset-markers))
3516 (org-compile-prefix-format 'agenda
)
3517 (org-set-sorting-strategy 'agenda
)
3518 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3519 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
3521 (org-agenda-files t
)))
3523 (org-prepare-agenda-buffers files
)
3524 ;; If this is called during org-agenda, don't return any entries to
3525 ;; the calendar. Org Agenda will list these entries itself.
3526 (if org-disable-agenda-to-diary
(setq files nil
))
3527 (while (setq file
(pop files
))
3528 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
3529 (setq results
(append results rtn
)))
3531 (concat (org-finalize-agenda-entries results
) "\n"))))
3533 ;;; Agenda entry finders
3535 (defun org-agenda-get-day-entries (file date
&rest args
)
3536 "Does the work for `org-diary' and `org-agenda'.
3537 FILE is the path to a file to be checked for entries. DATE is date like
3538 the one returned by `calendar-current-date'. ARGS are symbols indicating
3539 which kind of entries should be extracted. For details about these, see
3540 the documentation of `org-diary'."
3541 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3542 (let* ((org-startup-folded nil
)
3543 (org-startup-align-all-tables nil
)
3544 (buffer (if (file-exists-p file
)
3545 (org-get-agenda-file-buffer file
)
3546 (error "No such file %s" file
)))
3549 ;; If file does not exist, make sure an error message ends up in diary
3550 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3551 (with-current-buffer buffer
3552 (unless (org-mode-p)
3553 (error "Agenda file %s is not in `org-mode'" file
))
3554 (let ((case-fold-search nil
))
3557 (if org-agenda-restrict
3558 (narrow-to-region org-agenda-restrict-begin
3559 org-agenda-restrict-end
)
3561 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3562 (while (setq arg
(pop args
))
3564 ((and (eq arg
:todo
)
3565 (equal date
(calendar-current-date)))
3566 (setq rtn
(org-agenda-get-todos))
3567 (setq results
(append results rtn
)))
3568 ((eq arg
:timestamp
)
3569 (setq rtn
(org-agenda-get-blocks))
3570 (setq results
(append results rtn
))
3571 (setq rtn
(org-agenda-get-timestamps))
3572 (setq results
(append results rtn
)))
3574 (setq rtn
(org-agenda-get-sexps))
3575 (setq results
(append results rtn
)))
3576 ((eq arg
:scheduled
)
3577 (setq rtn
(org-agenda-get-scheduled))
3578 (setq results
(append results rtn
)))
3580 (setq rtn
(org-agenda-get-progress))
3581 (setq results
(append results rtn
)))
3583 (setq rtn
(org-agenda-get-deadlines))
3584 (setq results
(append results rtn
))))))))
3587 (defun org-agenda-get-todos ()
3588 "Return the TODO information for agenda display."
3589 (let* ((props (list 'face nil
3590 'done-face
'org-agenda-done
3591 'org-not-done-regexp org-not-done-regexp
3592 'org-todo-regexp org-todo-regexp
3593 'org-complex-heading-regexp org-complex-heading-regexp
3594 'mouse-face
'highlight
3595 'keymap org-agenda-keymap
3597 (format "mouse-2 or RET jump to org file %s"
3598 (abbreviate-file-name buffer-file-name
))))
3599 (regexp (concat "^\\*+[ \t]+\\("
3600 (if org-select-this-todo-keyword
3601 (if (equal org-select-this-todo-keyword
"*")
3604 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3606 org-not-done-regexp
)
3608 marker priority category tags todo-state
3610 (goto-char (point-min))
3611 (while (re-search-forward regexp nil t
)
3615 (setq beg
(point) end
(save-excursion (outline-next-heading) (point)))
3616 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end
)
3617 (goto-char (1+ beg
))
3618 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3622 (goto-char (match-beginning 1))
3623 (setq marker
(org-agenda-new-marker (match-beginning 0))
3624 category
(org-get-category)
3625 txt
(match-string 1)
3626 tags
(org-get-tags-at (point))
3627 txt
(org-format-agenda-item "" txt category tags
)
3628 priority
(1+ (org-get-priority txt
))
3629 todo-state
(org-get-todo-state))
3630 (org-add-props txt props
3631 'org-marker marker
'org-hd-marker marker
3632 'priority priority
'org-category category
3633 'type
"todo" 'todo-state todo-state
)
3635 (if org-agenda-todo-list-sublevels
3636 (goto-char (match-end 1))
3637 (org-end-of-subtree 'invisible
))))
3641 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end
)
3642 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3643 (when (or org-agenda-todo-ignore-with-date
3644 org-agenda-todo-ignore-scheduled
3645 org-agenda-todo-ignore-deadlines
)
3646 (setq end
(or end
(save-excursion (outline-next-heading) (point))))
3648 (or (and org-agenda-todo-ignore-with-date
3649 (re-search-forward org-ts-regexp end t
))
3650 (and org-agenda-todo-ignore-scheduled
3651 (re-search-forward org-scheduled-time-regexp end t
))
3652 (and org-agenda-todo-ignore-deadlines
3653 (re-search-forward org-deadline-time-regexp end t
)
3654 (org-deadline-close (match-string 1)))))))
3656 (defconst org-agenda-no-heading-message
3657 "No heading for this item in buffer or region.")
3659 (defun org-agenda-get-timestamps ()
3660 "Return the date stamp information for agenda display."
3661 (let* ((props (list 'face nil
3662 'org-not-done-regexp org-not-done-regexp
3663 'org-todo-regexp org-todo-regexp
3664 'org-complex-heading-regexp org-complex-heading-regexp
3665 'mouse-face
'highlight
3666 'keymap org-agenda-keymap
3668 (format "mouse-2 or RET jump to org file %s"
3669 (abbreviate-file-name buffer-file-name
))))
3670 (d1 (calendar-absolute-from-gregorian date
))
3676 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3680 (if org-agenda-include-inactive-timestamps
"[[<]" "<")
3684 (car org-time-stamp-formats
)
3685 (apply 'encode-time
; DATE bound by calendar
3686 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3688 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3689 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3690 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3691 donep tmp priority category ee txt timestr tags b0 b3 e3 head
3692 todo-state end-of-match
)
3693 (goto-char (point-min))
3694 (while (setq end-of-match
(re-search-forward regexp nil t
))
3695 (setq b0
(match-beginning 0)
3696 b3
(match-beginning 3) e3
(match-end 3))
3698 (and (org-at-date-range-p) (throw :skip nil
))
3700 (if (and (match-end 1)
3701 (not (= d1
(org-time-string-to-absolute
3702 (match-string 1) d1 nil
3703 org-agenda-repeating-timestamp-show-all
))))
3706 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3708 (setq tmp
(buffer-substring (max (point-min)
3709 (- b0 org-ds-keyword-length
))
3711 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3712 inactivep
(= (char-after b0
) ?\
[)
3713 deadlinep
(string-match org-deadline-regexp tmp
)
3714 scheduledp
(string-match org-scheduled-regexp tmp
)
3715 closedp
(and org-agenda-include-inactive-timestamps
3716 (string-match org-closed-string tmp
))
3717 clockp
(and org-agenda-include-inactive-timestamps
3718 (or (string-match org-clock-string tmp
)
3719 (string-match "]-+\\'" tmp
)))
3720 todo-state
(org-get-todo-state)
3721 donep
(member todo-state org-done-keywords
))
3722 (if (or scheduledp deadlinep closedp clockp
3723 (and donep org-agenda-skip-timestamp-if-done
))
3725 (if (string-match ">" timestr
)
3726 ;; substring should only run to end of time stamp
3727 (setq timestr
(substring timestr
0 (match-end 0))))
3728 (setq marker
(org-agenda-new-marker b0
)
3729 category
(org-get-category b0
))
3731 (if (not (re-search-backward "^\\*+ " nil t
))
3732 (setq txt org-agenda-no-heading-message
)
3733 (goto-char (match-beginning 0))
3734 (setq hdmarker
(org-agenda-new-marker)
3735 tags
(org-get-tags-at))
3736 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3737 (setq head
(match-string 1))
3738 (setq txt
(org-format-agenda-item
3739 (if inactivep
"[" nil
)
3740 head category tags timestr nil
3742 (setq priority
(org-get-priority txt
))
3743 (org-add-props txt props
3744 'org-marker marker
'org-hd-marker hdmarker
)
3745 (org-add-props txt nil
'priority priority
3746 'org-category category
'date date
3747 'todo-state todo-state
3750 (if org-agenda-skip-additional-timestamps-same-entry
3751 (outline-next-heading)
3752 (goto-char end-of-match
))))
3755 (defun org-agenda-get-sexps ()
3756 "Return the sexp information for agenda display."
3757 (require 'diary-lib
)
3758 (let* ((props (list 'face nil
3759 'mouse-face
'highlight
3760 'keymap org-agenda-keymap
3762 (format "mouse-2 or RET jump to org file %s"
3763 (abbreviate-file-name buffer-file-name
))))
3765 marker category ee txt tags entry result beg b sexp sexp-entry
3767 (goto-char (point-min))
3768 (while (re-search-forward regexp nil t
)
3771 (setq beg
(match-beginning 0))
3772 (goto-char (1- (match-end 0)))
3775 (setq sexp
(buffer-substring b
(point)))
3776 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3777 (org-trim (match-string 1))
3779 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3781 (setq marker
(org-agenda-new-marker beg
)
3782 category
(org-get-category beg
)
3783 todo-state
(org-get-todo-state))
3785 (if (string-match "\\S-" result
)
3787 (setq txt
"SEXP entry returned empty string"))
3789 (setq txt
(org-format-agenda-item
3790 "" txt category tags
'time
))
3791 (org-add-props txt props
'org-marker marker
)
3792 (org-add-props txt nil
3793 'org-category category
'date date
'todo-state todo-state
3798 (defalias 'org-get-closed
'org-agenda-get-progress
)
3799 (defun org-agenda-get-progress ()
3800 "Return the logged TODO entries for agenda display."
3801 (let* ((props (list 'mouse-face
'highlight
3802 'org-not-done-regexp org-not-done-regexp
3803 'org-todo-regexp org-todo-regexp
3804 'org-complex-heading-regexp org-complex-heading-regexp
3805 'keymap org-agenda-keymap
3807 (format "mouse-2 or RET jump to org file %s"
3808 (abbreviate-file-name buffer-file-name
))))
3809 (items (if (consp org-agenda-show-log
)
3811 org-agenda-log-mode-items
))
3815 (if (memq 'closed items
) (concat "\\<" org-closed-string
))
3816 (if (memq 'clock items
) (concat "\\<" org-clock-string
))
3817 (if (memq 'state items
) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
3818 (parts-re (if parts
(mapconcat 'identity parts
"\\|")
3819 (error "`org-agenda-log-mode-items' is empty")))
3821 "\\(" parts-re
"\\)"
3826 (car org-time-stamp-formats
)
3827 (apply 'encode-time
; DATE bound by calendar
3828 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3830 marker hdmarker priority category tags closedp statep clockp state
3831 ee txt extra timestr rest clocked
)
3832 (goto-char (point-min))
3833 (while (re-search-forward regexp nil t
)
3836 (setq marker
(org-agenda-new-marker (match-beginning 0))
3837 closedp
(equal (match-string 1) org-closed-string
)
3838 statep
(equal (string-to-char (match-string 1)) ?-
)
3839 clockp
(not (or closedp statep
))
3840 state
(and statep
(match-string 2))
3841 category
(org-get-category (match-beginning 0))
3842 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3844 (when (string-match "\\]" timestr
)
3845 ;; substring should only run to end of time stamp
3846 (setq rest
(substring timestr
(match-end 0))
3847 timestr
(substring timestr
0 (match-end 0)))
3848 (if (and (not closedp
) (not statep
)
3849 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest
))
3850 (progn (setq timestr
(concat (substring timestr
0 -
1)
3851 "-" (match-string 1 rest
) "]"))
3852 (setq clocked
(match-string 2 rest
)))
3853 (setq clocked
"-")))
3856 ((not org-agenda-log-mode-add-notes
) (setq extra nil
))
3858 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
3859 (setq extra
(match-string 1))))
3861 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
3862 (setq extra
(match-string 1))))
3863 (t (setq extra nil
)))
3864 (if (not (re-search-backward "^\\*+ " nil t
))
3865 (setq txt org-agenda-no-heading-message
)
3866 (goto-char (match-beginning 0))
3867 (setq hdmarker
(org-agenda-new-marker)
3868 tags
(org-get-tags-at))
3869 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3870 (setq txt
(match-string 1))
3872 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt
)
3873 (setq txt
(concat (substring txt
0 (match-beginning 1))
3874 " - " extra
" " (match-string 2 txt
)))
3875 (setq txt
(concat txt
" - " extra
))))
3876 (setq txt
(org-format-agenda-item
3878 (closedp "Closed: ")
3879 (statep (concat "State: (" state
")"))
3880 (t (concat "Clocked: (" clocked
")")))
3881 txt category tags timestr
)))
3882 (setq priority
100000)
3883 (org-add-props txt props
3884 'org-marker marker
'org-hd-marker hdmarker
'face
'org-agenda-done
3885 'priority priority
'org-category category
3886 'type
"closed" 'date date
3887 'undone-face
'org-warning
'done-face
'org-agenda-done
)
3889 (goto-char (point-at-eol))))
3892 (defun org-agenda-get-deadlines ()
3893 "Return the deadline information for agenda display."
3894 (let* ((props (list 'mouse-face
'highlight
3895 'org-not-done-regexp org-not-done-regexp
3896 'org-todo-regexp org-todo-regexp
3897 'org-complex-heading-regexp org-complex-heading-regexp
3898 'keymap org-agenda-keymap
3900 (format "mouse-2 or RET jump to org file %s"
3901 (abbreviate-file-name buffer-file-name
))))
3902 (regexp org-deadline-time-regexp
)
3903 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3904 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3905 d2 diff dfrac wdays pos pos1 category tags
3906 ee txt head face s todo-state upcomingp donep timestr
)
3907 (goto-char (point-min))
3908 (while (re-search-forward regexp nil t
)
3911 (setq s
(match-string 1)
3913 pos
(1- (match-beginning 1))
3914 d2
(org-time-string-to-absolute
3915 (match-string 1) d1
'past
3916 org-agenda-repeating-timestamp-show-all
)
3918 wdays
(org-get-wdays s
)
3919 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3920 upcomingp
(and todayp
(> diff
0)))
3921 ;; When to show a deadline in the calendar:
3922 ;; If the expiration is within wdays warning time.
3923 ;; Past-due deadlines are only shown on the current date
3924 (if (or (and (<= diff wdays
)
3925 (and todayp
(not org-agenda-only-exact-dates
)))
3928 (setq todo-state
(org-get-todo-state))
3929 (setq donep
(member todo-state org-done-keywords
))
3931 (or org-agenda-skip-deadline-if-done
3934 (setq category
(org-get-category))
3935 (if (not (re-search-backward "^\\*+[ \t]+" nil t
))
3936 (setq txt org-agenda-no-heading-message
)
3937 (goto-char (match-end 0))
3938 (setq pos1
(match-beginning 0))
3939 (setq tags
(org-get-tags-at pos1
))
3940 (setq head
(buffer-substring-no-properties
3942 (progn (skip-chars-forward "^\r\n")
3944 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3946 (concat (substring s
(match-beginning 1)) " "))
3947 (setq timestr
'time
))
3948 (setq txt
(org-format-agenda-item
3950 (car org-agenda-deadline-leaders
)
3952 (nth 1 org-agenda-deadline-leaders
))
3954 (nth 1 org-agenda-deadline-leaders
)
3956 (format (nth 1 org-agenda-deadline-leaders
)
3959 (if (not (= diff
0)) nil timestr
)))))
3961 (setq face
(org-agenda-deadline-face dfrac wdays
))
3962 (org-add-props txt props
3963 'org-marker
(org-agenda-new-marker pos
)
3964 'org-hd-marker
(org-agenda-new-marker pos1
)
3965 'priority
(+ (- diff
)
3966 (org-get-priority txt
))
3967 'org-category category
3968 'todo-state todo-state
3969 'type
(if upcomingp
"upcoming-deadline" "deadline")
3970 'date
(if upcomingp date d2
)
3971 'face
(if donep
'org-agenda-done face
)
3972 'undone-face face
'done-face
'org-agenda-done
)
3976 (defun org-agenda-deadline-face (fraction &optional wdays
)
3977 "Return the face to displaying a deadline item.
3978 FRACTION is what fraction of the head-warning time has passed."
3979 (if (equal wdays
0) (setq fraction
1.
))
3980 (let ((faces org-agenda-deadline-faces
) f
)
3982 (while (setq f
(pop faces
))
3983 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3985 (defun org-agenda-get-scheduled ()
3986 "Return the scheduled information for agenda display."
3987 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3988 'org-todo-regexp org-todo-regexp
3989 'org-complex-heading-regexp org-complex-heading-regexp
3990 'done-face
'org-agenda-done
3991 'mouse-face
'highlight
3992 'keymap org-agenda-keymap
3994 (format "mouse-2 or RET jump to org file %s"
3995 (abbreviate-file-name buffer-file-name
))))
3996 (regexp org-scheduled-time-regexp
)
3997 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3998 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3999 d2 diff pos pos1 category tags donep
4000 ee txt head pastschedp todo-state face timestr s
)
4001 (goto-char (point-min))
4002 (while (re-search-forward regexp nil t
)
4005 (setq s
(match-string 1)
4007 pos
(1- (match-beginning 1))
4008 d2
(org-time-string-to-absolute
4009 (match-string 1) d1
'past
4010 org-agenda-repeating-timestamp-show-all
)
4012 (setq pastschedp
(and todayp
(< diff
0)))
4013 ;; When to show a scheduled item in the calendar:
4014 ;; If it is on or past the date.
4015 (if (or (and (< diff
0)
4016 (< (abs diff
) org-scheduled-past-days
)
4017 (and todayp
(not org-agenda-only-exact-dates
)))
4020 (setq todo-state
(org-get-todo-state))
4021 (setq donep
(member todo-state org-done-keywords
))
4023 (or org-agenda-skip-scheduled-if-done
4026 (setq category
(org-get-category))
4027 (if (not (re-search-backward "^\\*+[ \t]+" nil t
))
4028 (setq txt org-agenda-no-heading-message
)
4029 (goto-char (match-end 0))
4030 (setq pos1
(match-beginning 0))
4031 (setq tags
(org-get-tags-at))
4032 (setq head
(buffer-substring-no-properties
4034 (progn (skip-chars-forward "^\r\n") (point))))
4035 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
4037 (concat (substring s
(match-beginning 1)) " "))
4038 (setq timestr
'time
))
4039 (setq txt
(org-format-agenda-item
4041 (car org-agenda-scheduled-leaders
)
4042 (format (nth 1 org-agenda-scheduled-leaders
)
4045 (if (not (= diff
0)) nil timestr
)))))
4049 (pastschedp 'org-scheduled-previously
)
4050 (todayp 'org-scheduled-today
)
4051 (t 'org-scheduled
)))
4052 (org-add-props txt props
4054 'face
(if donep
'org-agenda-done face
)
4055 'org-marker
(org-agenda-new-marker pos
)
4056 'org-hd-marker
(org-agenda-new-marker pos1
)
4057 'type
(if pastschedp
"past-scheduled" "scheduled")
4058 'date
(if pastschedp d2 date
)
4059 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
4060 'org-category category
4061 'todo-state todo-state
)
4065 (defun org-agenda-get-blocks ()
4066 "Return the date-range information for agenda display."
4067 (let* ((props (list 'face nil
4068 'org-not-done-regexp org-not-done-regexp
4069 'org-todo-regexp org-todo-regexp
4070 'org-complex-heading-regexp org-complex-heading-regexp
4071 'mouse-face
'highlight
4072 'keymap org-agenda-keymap
4074 (format "mouse-2 or RET jump to org file %s"
4075 (abbreviate-file-name buffer-file-name
))))
4076 (regexp org-tr-regexp
)
4077 (d0 (calendar-absolute-from-gregorian date
))
4078 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4080 (goto-char (point-min))
4081 (while (re-search-forward regexp nil t
)
4085 (setq timestr
(match-string 0)
4088 d1
(time-to-days (org-time-string-to-time s1
))
4089 d2
(time-to-days (org-time-string-to-time s2
)))
4090 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
4091 ;; Only allow days between the limits, because the normal
4092 ;; date stamps will catch the limits.
4094 (setq todo-state
(org-get-todo-state))
4095 (setq donep
(member todo-state org-done-keywords
))
4096 (if (and donep org-agenda-skip-timestamp-if-done
)
4098 (setq marker
(org-agenda-new-marker (point)))
4099 (setq category
(org-get-category))
4100 (if (not (re-search-backward "^\\*+ " nil t
))
4101 (setq txt org-agenda-no-heading-message
)
4102 (goto-char (match-beginning 0))
4103 (setq hdmarker
(org-agenda-new-marker (point)))
4104 (setq tags
(org-get-tags-at))
4105 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4106 (setq head
(match-string 1))
4107 (setq txt
(org-format-agenda-item
4109 (nth (if (= d1 d2
) 0 1)
4110 org-agenda-timerange-leaders
)
4111 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
4113 (if (= d0 d1
) timestr
))))
4114 (org-add-props txt props
4115 'org-marker marker
'org-hd-marker hdmarker
4116 'type
"block" 'date date
4117 'todo-state todo-state
4118 'priority
(org-get-priority txt
) 'org-category category
)
4121 ;; Sort the entries by expiration date.
4124 ;;; Agenda presentation and sorting
4126 (defvar org-prefix-has-time nil
4127 "A flag, set by `org-compile-prefix-format'.
4128 The flag is set if the currently compiled format contains a `%t'.")
4129 (defvar org-prefix-has-tag nil
4130 "A flag, set by `org-compile-prefix-format'.
4131 The flag is set if the currently compiled format contains a `%T'.")
4132 (defvar org-prefix-has-effort nil
4133 "A flag, set by `org-compile-prefix-format'.
4134 The flag is set if the currently compiled format contains a `%e'.")
4136 (defun org-format-agenda-item (extra txt
&optional category tags dotime
4138 "Format TXT to be inserted into the agenda buffer.
4139 In particular, it adds the prefix and corresponding text properties. EXTRA
4140 must be a string and replaces the `%s' specifier in the prefix format.
4141 CATEGORY (string, symbol or nil) may be used to overrule the default
4142 category taken from local variable or file name. It will replace the `%c'
4143 specifier in the format. DOTIME, when non-nil, indicates that a
4144 time-of-day should be extracted from TXT for sorting of this entry, and for
4145 the `%t' specifier in the format. When DOTIME is a string, this string is
4146 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4147 only the correctly processes TXT should be returned - this is used by
4148 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4149 Any match of REMOVE-RE will be removed from TXT."
4151 ;; Diary entries sometimes have extra whitespace at the beginning
4152 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
4153 (when org-agenda-show-inherited-tags
4154 ;; Fix the tags part in txt
4155 (setq txt
(org-agenda-add-inherited-tags txt tags
)))
4156 (let* ((category (or category
4158 (if buffer-file-name
4159 (file-name-sans-extension
4160 (file-name-nondirectory buffer-file-name
))
4162 ;; time, tag, effort are needed for the eval of the prefix format
4163 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
4165 (ts (if dotime
(concat
4166 (if (stringp dotime
) dotime
"")
4167 (and org-agenda-search-headline-for-time txt
))))
4168 (time-of-day (and dotime
(org-get-time-of-day ts
)))
4169 stamp plain s0 s1 s2 t1 t2 rtn srp
4171 (and (org-mode-p) buffer-file-name
4172 (add-to-list 'org-agenda-contributing-files buffer-file-name
))
4173 (when (and dotime time-of-day
)
4174 ;; Extract starting and ending time and move them to prefix
4175 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
4176 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
4177 (setq s0
(match-string 0 ts
)
4178 srp
(and stamp
(match-end 3))
4179 s1
(match-string (if plain
1 2) ts
)
4180 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
4182 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4183 ;; them, we might want to remove them there to avoid duplication.
4184 ;; The user can turn this off with a variable.
4185 (if (and org-prefix-has-time
4186 org-agenda-remove-times-when-in-prefix
(or stamp plain
)
4187 (string-match (concat (regexp-quote s0
) " *") txt
)
4188 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
4189 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
4190 (= (match-beginning 0) 0)
4192 (setq txt
(replace-match "" nil nil txt
))))
4193 ;; Normalize the time(s) to 24 hour
4194 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
4195 (if s2
(setq s2
(org-get-time-of-day s2
'string t
)))
4196 ;; Compute the duration
4198 (setq t1
(+ (* 60 (string-to-number (substring s1
0 2)))
4199 (string-to-number (substring s1
3)))
4201 (s2 (+ (* 60 (string-to-number (substring s2
0 2)))
4202 (string-to-number (substring s2
3))))
4203 (org-agenda-default-appointment-duration
4204 (+ t1 org-agenda-default-appointment-duration
))
4206 (setq duration
(if t2
(- t2 t1
)))))
4208 (when (and s1
(not s2
) org-agenda-default-appointment-duration
4209 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
4210 (let ((m (+ (string-to-number (match-string 2 s1
))
4211 (* 60 (string-to-number (match-string 1 s1
)))
4212 org-agenda-default-appointment-duration
))
4214 (setq h
(/ m
60) m
(- m
(* h
60)))
4215 (setq s2
(format "%02d:%02d" h m
))))
4217 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4219 ;; Tags are in the string
4220 (if (or (eq org-agenda-remove-tags t
)
4221 (and org-agenda-remove-tags
4222 org-prefix-has-tag
))
4223 (setq txt
(replace-match "" t t txt
))
4224 (setq txt
(replace-match
4225 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
4226 (match-string 2 txt
))
4232 (or (get-text-property 0 'org-hd-marker txt
)
4233 (get-text-property 0 'org-marker txt
)))
4236 (setq neffort
(org-hh:mm-string-to-minutes effort
)
4237 effort
(setq effort
(concat "[" effort
"]" )))))
4240 (while (string-match remove-re txt
)
4241 (setq txt
(replace-match "" t t txt
))))
4243 ;; Create the final string
4246 ;; Prepare the variables needed in the eval of the compiled format
4247 (setq time
(cond (s2 (concat s1
"-" s2
))
4248 (s1 (concat s1
"......"))
4251 category
(if (symbolp category
) (symbol-name category
) category
))
4252 ;; Evaluate the compiled format
4253 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
4255 ;; And finally add the text properties
4256 (org-add-props rtn nil
4257 'org-category
(downcase category
)
4258 'tags
(mapcar 'org-downcase-keep-props tags
)
4259 'org-highest-priority org-highest-priority
4260 'org-lowest-priority org-lowest-priority
4261 'prefix-length
(- (length rtn
) (length txt
))
4262 'time-of-day time-of-day
4265 'effort-minutes neffort
4271 (defun org-agenda-add-inherited-tags (txt tags
)
4272 "Remove tags string from TXT, and add complete list of tags.
4273 The new list includes inherited tags. If any inherited tags are present,
4274 a double colon separates inherited tags from local tags."
4275 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt
)
4276 (setq txt
(substring txt
0 (match-beginning 0))))
4278 (let ((have-i (get-text-property 0 'inherited
(car tags
)))
4280 (setq txt
(concat txt
" :"
4283 (setq i
(get-text-property 0 'inherited x
))
4284 (if (and have-i
(not i
))
4290 (if have-i
"::" ":")))))
4293 (defun org-downcase-keep-props (s)
4294 (let ((props (text-properties-at 0 s
)))
4295 (setq s
(downcase s
))
4296 (add-text-properties 0 (length s
) props s
)
4299 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
4300 (defvar org-agenda-sorting-strategy-selected nil
)
4302 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
4304 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
4305 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
4306 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
4307 ((member 'weekly
(car org-agenda-time-grid
)))
4308 (t (throw 'exit list
)))
4309 (let* ((have (delq nil
(mapcar
4310 (lambda (x) (get-text-property 1 'time-of-day x
))
4312 (string (nth 1 org-agenda-time-grid
))
4313 (gridtimes (nth 2 org-agenda-time-grid
))
4314 (req (car org-agenda-time-grid
))
4315 (remove (member 'remove-match req
))
4317 (if (and (member 'require-timed req
) (not have
))
4318 ;; don't show empty grid
4320 (while (setq time
(pop gridtimes
))
4321 (unless (and remove
(member time have
))
4322 (setq time
(int-to-string time
))
4323 (push (org-format-agenda-item
4325 (concat (substring time
0 -
2) ":" (substring time -
2)))
4328 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
4329 (if (member 'time-up org-agenda-sorting-strategy-selected
)
4331 (append list new
)))))
4333 (defun org-compile-prefix-format (key)
4334 "Compile the prefix format into a Lisp form that can be evaluated.
4335 The resulting form is returned and stored in the variable
4336 `org-prefix-format-compiled'."
4337 (setq org-prefix-has-time nil org-prefix-has-tag nil
4338 org-prefix-has-effort nil
)
4340 ((stringp org-agenda-prefix-format
)
4341 org-agenda-prefix-format
)
4342 ((assq key org-agenda-prefix-format
)
4343 (cdr (assq key org-agenda-prefix-format
)))
4344 (t " %-12:c%?-12t% s")))
4346 varform vars var e c f opt
)
4347 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4349 (setq var
(cdr (assoc (match-string 4 s
)
4350 '(("c" . category
) ("t" . time
) ("s" . extra
)
4351 ("T" . tag
) ("e" . effort
))))
4352 c
(or (match-string 3 s
) "")
4353 opt
(match-beginning 1)
4354 start
(1+ (match-beginning 0)))
4355 (if (equal var
'time
) (setq org-prefix-has-time t
))
4356 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
4357 (if (equal var
'effort
) (setq org-prefix-has-effort t
))
4358 (setq f
(concat "%" (match-string 2 s
) "s"))
4361 `(if (equal "" ,var
)
4363 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
4364 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
4365 (setq s
(replace-match "%s" t nil s
))
4366 (push varform vars
))
4367 (setq vars
(nreverse vars
))
4368 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
4370 (defun org-set-sorting-strategy (key)
4371 (if (symbolp (car org-agenda-sorting-strategy
))
4373 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
4374 (setq org-agenda-sorting-strategy-selected
4375 (or (cdr (assq key org-agenda-sorting-strategy
))
4376 (cdr (assq 'agenda org-agenda-sorting-strategy
))
4377 '(time-up category-keep priority-down
)))))
4379 (defun org-get-time-of-day (s &optional string mod24
)
4380 "Check string S for a time of day.
4381 If found, return it as a military time number between 0 and 2400.
4382 If not found, return nil.
4383 The optional STRING argument forces conversion into a 5 character wide string
4387 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
4388 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
4389 (let* ((h (string-to-number (match-string 1 s
)))
4390 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
4391 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
4392 (am-p (equal ampm
"am"))
4393 (h1 (cond ((not ampm
) h
)
4394 ((= h
12) (if am-p
0 12))
4395 (t (+ h
(if am-p
0 12)))))
4396 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
4398 (t0 (+ (* 100 h2
) m
))
4399 (t1 (concat (if (>= h1
24) "+" " ")
4400 (if (< t0
100) "0" "")
4401 (if (< t0
10) "0" "")
4402 (int-to-string t0
))))
4403 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
4405 (defun org-finalize-agenda-entries (list &optional nosort
)
4406 "Sort and concatenate the agenda items."
4407 (setq list
(mapcar 'org-agenda-highlight-todo list
))
4410 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
4412 (defun org-agenda-highlight-todo (x)
4413 (let ((org-done-keywords org-done-keywords-for-agenda
)
4417 (beginning-of-line 1)
4418 (setq re
(get-text-property (point) 'org-todo-regexp
))
4419 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
4420 (when (looking-at (concat "[ \t]*\\.*\\(" re
"\\) +"))
4421 (add-text-properties (match-beginning 0) (match-end 0)
4422 (list 'face
(org-get-todo-face 1)))
4423 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4424 (delete-region (match-beginning 1) (1- (match-end 0)))
4425 (goto-char (match-beginning 1))
4426 (insert (format org-agenda-todo-keyword-format s
)))))
4427 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
4428 pl
(get-text-property 0 'prefix-length x
))
4430 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
4432 (add-text-properties
4433 (or (match-end 1) (match-end 0)) (match-end 0)
4434 (list 'face
(org-get-todo-face (match-string 2 x
)))
4436 (setq x
(concat (substring x
0 (match-end 1))
4437 (format org-agenda-todo-keyword-format
4440 (substring x
(match-end 3)))))
4443 (defsubst org-cmp-priority
(a b
)
4444 "Compare the priorities of string A and B."
4445 (let ((pa (or (get-text-property 1 'priority a
) 0))
4446 (pb (or (get-text-property 1 'priority b
) 0)))
4447 (cond ((> pa pb
) +1)
4451 (defsubst org-cmp-effort
(a b
)
4452 "Compare the priorities of string A and B."
4453 (let* ((def (if org-sort-agenda-noeffort-is-high
32767 -
1))
4454 (ea (or (get-text-property 1 'effort-minutes a
) def
))
4455 (eb (or (get-text-property 1 'effort-minutes b
) def
)))
4456 (cond ((> ea eb
) +1)
4460 (defsubst org-cmp-category
(a b
)
4461 "Compare the string values of categories of strings A and B."
4462 (let ((ca (or (get-text-property 1 'org-category a
) ""))
4463 (cb (or (get-text-property 1 'org-category b
) "")))
4464 (cond ((string-lessp ca cb
) -
1)
4465 ((string-lessp cb ca
) +1)
4468 (defsubst org-cmp-todo-state
(a b
)
4469 "Compare the todo states of strings A and B."
4470 (let* ((ma (or (get-text-property 1 'org-marker a
)
4471 (get-text-property 1 'org-hd-marker a
)))
4472 (mb (or (get-text-property 1 'org-marker b
)
4473 (get-text-property 1 'org-hd-marker b
)))
4474 (fa (and ma
(marker-buffer ma
)))
4475 (fb (and mb
(marker-buffer mb
)))
4477 (or (and fa
(with-current-buffer fa org-todo-keywords-1
))
4478 (and fb
(with-current-buffer fb org-todo-keywords-1
))))
4479 (ta (or (get-text-property 1 'todo-state a
) ""))
4480 (tb (or (get-text-property 1 'todo-state b
) ""))
4481 (la (- (length (member ta todo-kwds
))))
4482 (lb (- (length (member tb todo-kwds
))))
4483 (donepa (member ta org-done-keywords-for-agenda
))
4484 (donepb (member tb org-done-keywords-for-agenda
)))
4485 (cond ((and donepa
(not donepb
)) -
1)
4486 ((and (not donepa
) donepb
) +1)
4491 (defsubst org-cmp-tag
(a b
)
4492 "Compare the string values of the first tags of A and B."
4493 (let ((ta (car (last (get-text-property 1 'tags a
))))
4494 (tb (car (last (get-text-property 1 'tags b
)))))
4497 ((string-lessp ta tb
) -
1)
4498 ((string-lessp tb ta
) +1)
4501 (defsubst org-cmp-time
(a b
)
4502 "Compare the time-of-day values of strings A and B."
4503 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
4504 (ta (or (get-text-property 1 'time-of-day a
) def
))
4505 (tb (or (get-text-property 1 'time-of-day b
) def
)))
4506 (cond ((< ta tb
) -
1)
4510 (defun org-entries-lessp (a b
)
4511 "Predicate for sorting agenda entries."
4512 ;; The following variables will be used when the form is evaluated.
4513 ;; So even though the compiler complains, keep them.
4514 (let* ((time-up (org-cmp-time a b
))
4515 (time-down (if time-up
(- time-up
) nil
))
4516 (priority-up (org-cmp-priority a b
))
4517 (priority-down (if priority-up
(- priority-up
) nil
))
4518 (effort-up (org-cmp-effort a b
))
4519 (effort-down (if effort-up
(- effort-up
) nil
))
4520 (category-up (org-cmp-category a b
))
4521 (category-down (if category-up
(- category-up
) nil
))
4522 (category-keep (if category-up
+1 nil
))
4523 (tag-up (org-cmp-tag a b
))
4524 (tag-down (if tag-up
(- tag-up
) nil
))
4525 (todo-state-up (org-cmp-todo-state a b
))
4526 (todo-state-down (if todo-state-up
(- todo-state-up
) nil
))
4527 user-defined-up user-defined-down
)
4528 (if (and org-agenda-cmp-user-defined
4529 (functionp org-agenda-cmp-user-defined
))
4530 (setq user-defined-up
4531 (funcall org-agenda-cmp-user-defined a b
)
4532 user-defined-down
(if user-defined-up
(- user-defined-up
) nil
)))
4534 (eval (cons 'or org-agenda-sorting-strategy-selected
))
4535 '((-1 . t
) (1 . nil
) (nil . nil
))))))
4537 ;;; Agenda restriction lock
4539 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
4540 "Overlay to mark the headline to which arenda commands are restricted.")
4541 (org-overlay-put org-agenda-restriction-lock-overlay
4542 'face
'org-agenda-restriction-lock
)
4543 (org-overlay-put org-agenda-restriction-lock-overlay
4544 'help-echo
"Agendas are currently limited to this subtree.")
4545 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4547 (defun org-agenda-set-restriction-lock (&optional type
)
4548 "Set restriction lock for agenda, to current subtree or file.
4549 Restriction will be the file if TYPE is `file', or if type is the
4550 universal prefix '(4), or if the cursor is before the first headline
4551 in the file. Otherwise, restriction will be to the current subtree."
4553 (and (equal type
'(4)) (setq type
'file
))
4556 ((org-at-heading-p) 'subtree
)
4557 ((condition-case nil
(org-back-to-heading t
) (error nil
))
4560 (if (eq type
'subtree
)
4562 (setq org-agenda-restrict t
)
4563 (setq org-agenda-overriding-restriction
'subtree
)
4564 (put 'org-agenda-files
'org-restrict
4565 (list (buffer-file-name (buffer-base-buffer))))
4566 (org-back-to-heading t
)
4567 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
4568 (move-marker org-agenda-restrict-begin
(point))
4569 (move-marker org-agenda-restrict-end
4570 (save-excursion (org-end-of-subtree t
)))
4571 (message "Locking agenda restriction to subtree"))
4572 (put 'org-agenda-files
'org-restrict
4573 (list (buffer-file-name (buffer-base-buffer))))
4574 (setq org-agenda-restrict nil
)
4575 (setq org-agenda-overriding-restriction
'file
)
4576 (move-marker org-agenda-restrict-begin nil
)
4577 (move-marker org-agenda-restrict-end nil
)
4578 (message "Locking agenda restriction to file"))
4579 (setq current-prefix-arg nil
)
4580 (org-agenda-maybe-redo))
4582 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
4583 "Remove the agenda restriction lock."
4585 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4586 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
4587 (setq org-agenda-overriding-restriction nil
)
4588 (setq org-agenda-restrict nil
)
4589 (put 'org-agenda-files
'org-restrict nil
)
4590 (move-marker org-agenda-restrict-begin nil
)
4591 (move-marker org-agenda-restrict-end nil
)
4592 (setq current-prefix-arg nil
)
4593 (message "Agenda restriction lock removed")
4594 (or noupdate
(org-agenda-maybe-redo)))
4596 (defun org-agenda-maybe-redo ()
4597 "If there is any window showing the agenda view, update it."
4598 (let ((w (get-buffer-window org-agenda-buffer-name t
))
4599 (w0 (selected-window)))
4604 (if org-agenda-overriding-restriction
4605 (message "Agenda view shifted to new %s restriction"
4606 org-agenda-overriding-restriction
)
4607 (message "Agenda restriction lock removed")))))
4611 (defun org-agenda-check-type (error &rest types
)
4612 "Check if agenda buffer is of allowed type.
4613 If ERROR is non-nil, throw an error, otherwise just return nil."
4614 (if (memq org-agenda-type types
)
4617 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
4620 (defun org-agenda-quit ()
4621 "Exit agenda by removing the window or the buffer."
4623 (if org-agenda-columns-active
4625 (let ((buf (current-buffer)))
4626 (and (not (eq org-agenda-window-setup
'current-window
))
4627 (not (one-window-p))
4630 (org-agenda-reset-markers)
4631 (org-columns-remove-overlays)
4632 (setq org-agenda-archives-mode nil
))
4633 ;; Maybe restore the pre-agenda window configuration.
4634 (and org-agenda-restore-windows-after-quit
4635 (not (eq org-agenda-window-setup
'other-frame
))
4636 org-pre-agenda-window-conf
4637 (set-window-configuration org-pre-agenda-window-conf
))))
4639 (defun org-agenda-exit ()
4640 "Exit agenda by removing the window or the buffer.
4641 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
4642 Org-mode buffers visited directly by the user will not be touched."
4644 (org-release-buffers org-agenda-new-buffers
)
4645 (setq org-agenda-new-buffers nil
)
4648 (defun org-agenda-execute (arg)
4649 "Execute another agenda command, keeping same window.\\<global-map>
4650 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
4652 (let ((org-agenda-window-setup 'current-window
))
4655 (defun org-agenda-redo ()
4657 When this is the global TODO list, a prefix argument will be interpreted."
4659 (let* ((org-agenda-keep-modes t
)
4660 (filter org-agenda-filter
)
4661 (preset (get 'org-agenda-filter
:preset-filter
))
4662 (cols org-agenda-columns-active
)
4663 (line (org-current-line))
4664 (window-line (- line
(org-current-line (window-start))))
4665 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
4666 (put 'org-agenda-filter
:preset-filter nil
)
4667 (and cols
(org-columns-quit))
4668 (message "Rebuilding agenda buffer...")
4669 (org-let lprops
'(eval org-agenda-redo-command
))
4670 (setq org-agenda-undo-list nil
4671 org-agenda-pending-undo-list nil
)
4672 (message "Rebuilding agenda buffer...done")
4673 (put 'org-agenda-filter
:preset-filter preset
)
4674 (and (or filter preset
) (org-agenda-filter-apply filter
))
4675 (and cols
(interactive-p) (org-agenda-columns))
4677 (recenter window-line
)))
4680 (defvar org-global-tags-completion-table nil
)
4681 (defvar org-agenda-filter-form nil
)
4682 (defun org-agenda-filter-by-tag (strip &optional char narrow
)
4683 "Keep only those lines in the agenda buffer that have a specific tag.
4684 The tag is selected with its fast selection letter, as configured.
4685 With prefix argument STRIP, remove all lines that do have the tag.
4686 A lisp caller can specify CHAR. NARROW means that the new tag should be
4687 used to narrow the search - the interactive user can also press `-' or `+'
4688 to switch to narrowing."
4690 (let* ((alist org-tag-alist-for-agenda
)
4691 (tag-chars (mapconcat
4692 (lambda (x) (if (cdr x
) (char-to-string (cdr x
)) ""))
4694 (efforts (org-split-string
4695 (or (cdr (assoc (concat org-effort-property
"_ALL")
4696 org-global-properties
))
4697 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
4698 (effort-op org-agenda-filter-effort-default-operator
)
4700 (inhibit-read-only t
)
4701 (current org-agenda-filter
)
4705 "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
4706 (if narrow
"Narrow" "Filter") tag-chars
)
4707 (setq char
(read-char)))
4708 (when (member char
'(?
+ ?-
))
4710 (cond ((equal char ?-
) (setq strip t narrow t
))
4711 ((equal char ?
+) (setq strip nil narrow t
)))
4713 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars
)
4714 (setq char
(read-char)))
4715 (when (member char
'(?
< ?
> ?
= ??
))
4716 ;; An effort operator
4717 (setq effort-op
(char-to-string char
))
4718 (setq alist nil
) ; to make sure it will be interpreted as effort.
4719 (unless (equal char ??
)
4720 (loop for i from
0 to
9 do
4724 (if (= i
9) "0" (int-to-string (1+ i
)))
4725 "]" (nth i efforts
))))
4726 (message "Effort%s: %s " effort-op effort-prompt
)
4727 (setq char
(read-char))
4728 (when (or (< char ?
0) (> char ?
9))
4729 (error "Need 1-9,0 to select effort" ))))
4730 (when (equal char ?
\t)
4731 (unless (local-variable-p 'org-global-tags-completion-table
(current-buffer))
4732 (org-set-local 'org-global-tags-completion-table
4733 (org-global-tags-completion-table)))
4734 (let ((completion-ignore-case t
))
4735 (setq tag
(org-ido-completing-read
4736 "Tag: " org-global-tags-completion-table
))))
4739 (org-agenda-filter-by-tag-show-all)
4740 (when (get 'org-agenda-filter
:preset-filter
)
4741 (org-agenda-filter-apply org-agenda-filter
)))
4742 ((or (equal char ?\
)
4743 (setq a
(rassoc char alist
))
4744 (and (>= char ?
0) (<= char ?
9)
4745 (setq n
(if (= char ?
0) 9 (- char ?
0 1))
4746 tag
(concat effort-op
(nth n efforts
))
4751 (and tag
(setq a
(cons tag nil
))))
4752 (org-agenda-filter-by-tag-show-all)
4754 (setq org-agenda-filter
4755 (cons (concat (if strip
"-" "+") tag
)
4756 (if narrow current nil
)))
4757 (org-agenda-filter-apply org-agenda-filter
))
4758 (t (error "Invalid tag selection character %c" char
)))))
4760 (defun org-agenda-filter-by-tag-refine (strip &optional char
)
4761 "Refine the current filter. See `org-agenda-filter-by-tag."
4763 (org-agenda-filter-by-tag strip char
'refine
))
4765 (defun org-agenda-filter-make-matcher ()
4766 "Create the form that tests a line for the agenda filter."
4768 (dolist (x (append (get 'org-agenda-filter
:preset-filter
)
4770 (if (member x
'("-" "+"))
4771 (setq f1
'(not tags
))
4772 (if (string-match "[<=>?]" x
)
4773 (setq f1
(org-agenda-filter-effort-form x
))
4774 (setq f1
(list 'member
(downcase (substring x
1)) 'tags
)))
4775 (if (equal (string-to-char x
) ?-
)
4776 (setq f1
(list 'not f1
))))
4778 (cons 'and
(nreverse f
))))
4780 (defun org-agenda-filter-effort-form (e)
4781 "Return the form to compare the effort of the current line with what E says.
4782 E looks line \"+<2:25\"."
4784 (setq e
(substring e
1))
4785 (setq op
(string-to-char e
) e
(substring e
1))
4786 (setq op
(cond ((equal op ?
<) '<=)
4790 (list 'org-agenda-compare-effort
(list 'quote op
)
4791 (org-hh:mm-string-to-minutes e
))))
4793 (defun org-agenda-compare-effort (op value
)
4794 "Compare the effort of the current line with VALUE, using OP.
4795 If the line does not have an effort defined, return nil."
4796 (let ((eff (get-text-property (point) 'effort-minutes
)))
4799 (funcall op
(or eff
(if org-sort-agenda-noeffort-is-high
32767 0))
4802 (defun org-agenda-filter-apply (filter)
4803 "Set FILTER as the new agenda filter and apply it."
4805 (setq org-agenda-filter filter
4806 org-agenda-filter-form
(org-agenda-filter-make-matcher))
4807 (org-agenda-set-mode-name)
4809 (goto-char (point-min))
4811 (if (get-text-property (point) 'org-marker
)
4813 (setq tags
(get-text-property (point) 'tags
)) ; used in eval
4814 (if (not (eval org-agenda-filter-form
))
4815 (org-agenda-filter-by-tag-hide-line))
4816 (beginning-of-line 2))
4817 (beginning-of-line 2))))))
4819 (defun org-agenda-filter-by-tag-hide-line ()
4821 (setq ov
(org-make-overlay (max (point-min) (1- (point-at-bol)))
4823 (org-overlay-put ov
'invisible t
)
4824 (org-overlay-put ov
'type
'tags-filter
)
4825 (push ov org-agenda-filter-overlays
)))
4827 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos
)
4828 (setq pos
(or pos
(point)))
4830 (dolist (ov (org-overlays-at pos
))
4831 (when (and (org-overlay-get ov
'invisible
)
4832 (eq (org-overlay-get ov
'type
) 'tags-filter
))
4834 (if (< (org-overlay-start ov
) (point-at-eol))
4835 (org-move-overlay ov
(point-at-eol)
4836 (org-overlay-end ov
)))))))
4838 (defun org-agenda-filter-by-tag-show-all ()
4839 (mapc 'org-delete-overlay org-agenda-filter-overlays
)
4840 (setq org-agenda-filter-overlays nil
)
4841 (setq org-agenda-filter nil
)
4842 (setq org-agenda-filter-form nil
)
4843 (org-agenda-set-mode-name))
4845 (defun org-agenda-manipulate-query-add ()
4846 "Manipulate the query by adding a search term with positive selection.
4847 Positive selection means, the term must be matched for selection of an entry."
4849 (org-agenda-manipulate-query ?\
[))
4850 (defun org-agenda-manipulate-query-subtract ()
4851 "Manipulate the query by adding a search term with negative selection.
4852 Negative selection means, term must not be matched for selection of an entry."
4854 (org-agenda-manipulate-query ?\
]))
4855 (defun org-agenda-manipulate-query-add-re ()
4856 "Manipulate the query by adding a search regexp with positive selection.
4857 Positive selection means, the regexp must match for selection of an entry."
4859 (org-agenda-manipulate-query ?\
{))
4860 (defun org-agenda-manipulate-query-subtract-re ()
4861 "Manipulate the query by adding a search regexp with negative selection.
4862 Negative selection means, regexp must not match for selection of an entry."
4864 (org-agenda-manipulate-query ?\
}))
4865 (defun org-agenda-manipulate-query (char)
4867 ((memq org-agenda-type
'(timeline agenda
))
4868 (if (y-or-n-p "Re-display with inactive time stamps included? ")
4869 (let ((org-agenda-include-inactive-timestamps t
))
4872 ((eq org-agenda-type
'search
)
4874 'org-agenda-query-string
4875 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
4876 (?\
{ .
" +{}") (?\
} .
" -{}")))))
4877 (setq org-agenda-redo-command
4878 (list 'org-search-view
4880 org-agenda-query-string
4881 (+ (length org-agenda-query-string
)
4882 (if (member char
'(?\
{ ?\
})) 0 1))))
4883 (set-register org-agenda-query-register org-agenda-query-string
)
4885 (t (error "Cannot manipulate query for %s-type agenda buffers"
4888 (defun org-add-to-string (var string
)
4889 (set var
(concat (symbol-value var
) string
)))
4891 (defun org-agenda-goto-date (date)
4892 "Jump to DATE in agenda."
4893 (interactive (list (org-read-date)))
4894 (org-agenda-list nil date
))
4896 (defun org-agenda-goto-today ()
4899 (org-agenda-check-type t
'timeline
'agenda
)
4900 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
4902 (tdpos (goto-char tdpos
))
4903 ((eq org-agenda-type
'agenda
)
4904 (let* ((sd (time-to-days
4905 (time-subtract (current-time)
4906 (list 0 (* 3600 org-extend-today-until
) 0))))
4907 (comp (org-agenda-compute-time-span sd org-agenda-span
))
4908 (org-agenda-overriding-arguments org-agenda-last-arguments
))
4909 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
4910 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
4912 (org-agenda-find-same-or-today-or-agenda)))
4913 (t (error "Cannot find today")))))
4915 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
4917 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
4918 (text-property-any (point-min) (point-max) 'org-today t
)
4919 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
4922 (defun org-agenda-later (arg)
4923 "Go forward in time by thee current span.
4924 With prefix ARG, go forward that many times the current span."
4926 (org-agenda-check-type t
'agenda
)
4927 (let* ((span org-agenda-span
)
4928 (sd org-starting-day
)
4929 (greg (calendar-gregorian-from-absolute sd
))
4930 (cnt (get-text-property (point) 'org-day-cnt
))
4934 (setq sd
(+ arg sd
) nd
1))
4936 (setq sd
(+ (* 7 arg
) sd
) nd
7))
4938 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
4939 sd
(calendar-absolute-from-gregorian greg2
))
4940 (setcar greg2
(1+ (car greg2
)))
4941 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
4943 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
4944 sd
(calendar-absolute-from-gregorian greg2
))
4945 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
4946 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
4947 (let ((org-agenda-overriding-arguments
4948 (list (car org-agenda-last-arguments
) sd nd t
)))
4950 (org-agenda-find-same-or-today-or-agenda cnt
))))
4952 (defun org-agenda-earlier (arg)
4953 "Go backward in time by the current span.
4954 With prefix ARG, go backward that many times the current span."
4956 (org-agenda-later (- arg
)))
4958 (defun org-agenda-day-view (&optional day-of-year
)
4959 "Switch to daily view for agenda.
4960 With argument DAY-OF-YEAR, switch to that day of the year."
4962 (setq org-agenda-ndays
1)
4963 (org-agenda-change-time-span 'day day-of-year
))
4964 (defun org-agenda-week-view (&optional iso-week
)
4965 "Switch to daily view for agenda.
4966 With argument ISO-WEEK, switch to the corresponding ISO week.
4967 If ISO-WEEK has more then 2 digits, only the last two encode the
4968 week. Any digits before this encode a year. So 200712 means
4969 week 12 of year 2007. Years in the range 1938-2037 can also be
4970 written as 2-digit years."
4972 (setq org-agenda-ndays
7)
4973 (org-agenda-change-time-span 'week iso-week
))
4974 (defun org-agenda-month-view (&optional month
)
4975 "Switch to monthly view for agenda.
4976 With argument MONTH, switch to that month."
4978 (org-agenda-change-time-span 'month month
))
4979 (defun org-agenda-year-view (&optional year
)
4980 "Switch to yearly view for agenda.
4981 With argument YEAR, switch to that year.
4982 If MONTH has more then 2 digits, only the last two encode the
4983 month. Any digits before this encode a year. So 200712 means
4984 December year 2007. Years in the range 1938-2037 can also be
4985 written as 2-digit years."
4988 (setq year
(org-small-year-to-year year
)))
4989 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4990 (org-agenda-change-time-span 'year year
)
4993 (defun org-agenda-change-time-span (span &optional n
)
4994 "Change the agenda view to SPAN.
4995 SPAN may be `day', `week', `month', `year'."
4996 (org-agenda-check-type t
'agenda
)
4997 (if (and (not n
) (equal org-agenda-span span
))
4998 (error "Viewing span is already \"%s\"" span
))
4999 (let* ((sd (or (get-text-property (point) 'day
)
5001 (computed (org-agenda-compute-time-span sd span n
))
5002 (org-agenda-overriding-arguments
5003 (list (car org-agenda-last-arguments
)
5004 (car computed
) (cdr computed
) t
)))
5006 (org-agenda-find-same-or-today-or-agenda))
5007 (org-agenda-set-mode-name)
5008 (message "Switched to %s view" span
))
5010 (defun org-agenda-compute-time-span (sd span
&optional n
)
5011 "Compute starting date and number of days for agenda.
5012 SPAN may be `day', `week', `month', `year'. The return value
5013 is a cons cell with the starting date and the number of days,
5014 so that the date SD will be in that range."
5015 (let* ((greg (calendar-gregorian-from-absolute sd
))
5019 nd w1 y1 m1 thisweek
)
5023 (setq sd
(+ (calendar-absolute-from-gregorian
5028 (let* ((nt (calendar-day-of-week
5029 (calendar-gregorian-from-absolute sd
)))
5030 (d (if org-agenda-start-on-weekday
5031 (- nt org-agenda-start-on-weekday
)
5033 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
5036 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
5038 (setq y1
(org-small-year-to-year (/ n
100))
5041 (calendar-absolute-from-iso
5043 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
5046 (when (and n
(> n
99))
5047 (setq y1
(org-small-year-to-year (/ n
100))
5049 (setq sd
(calendar-absolute-from-gregorian
5050 (list (or n mg
) 1 (or y1 yg
)))
5051 nd
(- (calendar-absolute-from-gregorian
5052 (list (1+ (or n mg
)) 1 (or y1 yg
)))
5055 (setq sd
(calendar-absolute-from-gregorian
5056 (list 1 1 (or n yg
)))
5057 nd
(- (calendar-absolute-from-gregorian
5058 (list 1 1 (1+ (or n yg
))))
5062 (defun org-agenda-next-date-line (&optional arg
)
5063 "Jump to the next line indicating a date in agenda buffer."
5065 (org-agenda-check-type t
'agenda
'timeline
)
5066 (beginning-of-line 1)
5067 ;; This does not work if user makes date format that starts with a blank
5068 (if (looking-at "^\\S-") (forward-char 1))
5069 (if (not (re-search-forward "^\\S-" nil t arg
))
5072 (error "No next date after this line in this buffer")))
5073 (goto-char (match-beginning 0)))
5075 (defun org-agenda-previous-date-line (&optional arg
)
5076 "Jump to the previous line indicating a date in agenda buffer."
5078 (org-agenda-check-type t
'agenda
'timeline
)
5079 (beginning-of-line 1)
5080 (if (not (re-search-backward "^\\S-" nil t arg
))
5081 (error "No previous date before this line in this buffer")))
5083 ;; Initialize the highlight
5084 (defvar org-hl
(org-make-overlay 1 1))
5085 (org-overlay-put org-hl
'face
'highlight
)
5087 (defun org-highlight (begin end
&optional buffer
)
5088 "Highlight a region with overlay."
5089 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
5090 org-hl begin end
(or buffer
(current-buffer))))
5092 (defun org-unhighlight ()
5093 "Detach overlay INDEX."
5094 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
5096 ;; FIXME this is currently not used.
5097 (defun org-highlight-until-next-command (beg end
&optional buffer
)
5098 "Move the highlight overlay to BEG/END, remove it before the next command."
5099 (org-highlight beg end buffer
)
5100 (add-hook 'pre-command-hook
'org-unhighlight-once
))
5101 (defun org-unhighlight-once ()
5102 "Remove the highlight from its position, and this function from the hook."
5103 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
5106 (defun org-agenda-follow-mode ()
5107 "Toggle follow mode in an agenda buffer."
5109 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
5110 (org-agenda-set-mode-name)
5111 (message "Follow mode is %s"
5112 (if org-agenda-follow-mode
"on" "off")))
5114 (defun org-agenda-clockreport-mode ()
5115 "Toggle clocktable mode in an agenda buffer."
5117 (org-agenda-check-type t
'agenda
)
5118 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
5119 (org-agenda-set-mode-name)
5121 (message "Clocktable mode is %s"
5122 (if org-agenda-clockreport-mode
"on" "off")))
5124 (defun org-agenda-log-mode (&optional special
)
5125 "Toggle log mode in an agenda buffer.
5126 With argument SPECIAL, show all possible log items, not only the ones
5127 configured in `org-agenda-log-mode-items'.
5128 With a double `C-u' prefix arg, show *only* log items, nothing else."
5130 (org-agenda-check-type t
'agenda
'timeline
)
5131 (setq org-agenda-show-log
5132 (if (equal special
'(16))
5134 (if special
'(closed clock state
)
5135 (not org-agenda-show-log
))))
5136 (org-agenda-set-mode-name)
5138 (message "Log mode is %s"
5139 (if org-agenda-show-log
"on" "off")))
5141 (defun org-agenda-archives-mode (&optional with-files
)
5142 "Toggle log mode in an agenda buffer."
5144 (setq org-agenda-archives-mode
5145 (if with-files t
(if org-agenda-archives-mode nil
'trees
)))
5146 (org-agenda-set-mode-name)
5151 ((eq org-agenda-archives-mode nil
)
5152 "No archives are included")
5153 ((eq org-agenda-archives-mode
'trees
)
5154 (format "Trees with :%s: tag are included" org-archive-tag
))
5155 ((eq org-agenda-archives-mode t
)
5156 (format "Trees with :%s: tag and all active archive files are included"
5157 org-archive-tag
)))))
5159 (defun org-agenda-toggle-diary ()
5160 "Toggle diary inclusion in an agenda buffer."
5162 (org-agenda-check-type t
'agenda
)
5163 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
5165 (org-agenda-set-mode-name)
5166 (message "Diary inclusion turned %s"
5167 (if org-agenda-include-diary
"on" "off")))
5169 (defun org-agenda-toggle-time-grid ()
5170 "Toggle time grid in an agenda buffer."
5172 (org-agenda-check-type t
'agenda
)
5173 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
5175 (org-agenda-set-mode-name)
5176 (message "Time-grid turned %s"
5177 (if org-agenda-use-time-grid
"on" "off")))
5179 (defun org-agenda-set-mode-name ()
5180 "Set the mode name to indicate all the small mode settings."
5182 (concat "Org-Agenda"
5183 (if (equal org-agenda-ndays
1) " Day" "")
5184 (if (equal org-agenda-ndays
7) " Week" "")
5185 (if org-agenda-follow-mode
" Follow" "")
5186 (if org-agenda-include-diary
" Diary" "")
5187 (if org-agenda-use-time-grid
" Grid" "")
5188 (if (consp org-agenda-show-log
) " LogAll"
5189 (if org-agenda-show-log
" Log" ""))
5190 (if (or org-agenda-filter
(get 'org-agenda-filter
5192 (concat " {" (mapconcat
5194 (append (get 'org-agenda-filter
5196 org-agenda-filter
) "") "}")
5198 (if org-agenda-archives-mode
5199 (if (eq org-agenda-archives-mode t
)
5201 (format " :%s:" org-archive-tag
))
5203 (if org-agenda-clockreport-mode
" Clock" "")))
5204 (force-mode-line-update))
5206 (defun org-agenda-post-command-hook ()
5207 (and (eolp) (not (bolp)) (backward-char 1))
5208 (setq org-agenda-type
5209 (or (get-text-property (point) 'org-agenda-type
)
5210 (get-text-property (max (point-min) (1- (point)))
5212 (if (and org-agenda-follow-mode
5213 (get-text-property (point) 'org-marker
))
5216 (defun org-agenda-show-priority ()
5217 "Show the priority of the current item.
5218 This priority is composed of the main priority given with the [#A] cookies,
5219 and by additional input from the age of a schedules or deadline entry."
5221 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
5222 (message "Priority is %d" (if pri pri -
1000))))
5224 (defun org-agenda-show-tags ()
5225 "Show the tags applicable to the current item."
5227 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
5229 (message "Tags are :%s:"
5230 (org-no-properties (mapconcat 'identity tags
":")))
5231 (message "No tags associated with this line"))))
5233 (defun org-agenda-goto (&optional highlight
)
5234 "Go to the Org-mode file which contains the item at point."
5236 (let* ((marker (or (get-text-property (point) 'org-marker
)
5237 (org-agenda-error)))
5238 (buffer (marker-buffer marker
))
5239 (pos (marker-position marker
)))
5240 (switch-to-buffer-other-window buffer
)
5244 (org-show-context 'agenda
)
5246 (and (outline-next-heading)
5247 (org-flag-heading nil
)))) ; show the next heading
5248 (recenter (/ (window-height) 2))
5249 (run-hooks 'org-agenda-after-show-hook
)
5250 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
5252 (defvar org-agenda-after-show-hook nil
5253 "Normal hook run after an item has been shown from the agenda.
5254 Point is in the buffer where the item originated.")
5256 (defun org-agenda-kill ()
5257 "Kill the entry or subtree belonging to the current agenda entry."
5259 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5260 (let* ((marker (or (get-text-property (point) 'org-marker
)
5261 (org-agenda-error)))
5262 (buffer (marker-buffer marker
))
5263 (pos (marker-position marker
))
5264 (type (get-text-property (point) 'type
))
5265 dbeg dend
(n 0) conf
)
5266 (org-with-remote-undo buffer
5267 (with-current-buffer buffer
5270 (if (and (org-mode-p) (not (member type
'("sexp"))))
5271 (setq dbeg
(progn (org-back-to-heading t
) (point))
5272 dend
(org-end-of-subtree t t
))
5273 (setq dbeg
(point-at-bol)
5274 dend
(min (point-max) (1+ (point-at-eol)))))
5276 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
5277 (setq conf
(or (eq t org-agenda-confirm-kill
)
5278 (and (numberp org-agenda-confirm-kill
)
5279 (> n org-agenda-confirm-kill
))))
5282 (format "Delete entry with %d lines in buffer \"%s\"? "
5283 n
(buffer-name buffer
))))
5285 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
5286 (with-current-buffer buffer
(delete-region dbeg dend
))
5287 (message "Agenda item and source killed"))))
5289 (defun org-agenda-archive ()
5290 "Archive the entry or subtree belonging to the current agenda entry."
5292 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5293 (let* ((marker (or (get-text-property (point) 'org-marker
)
5294 (org-agenda-error)))
5295 (buffer (marker-buffer marker
))
5296 (pos (marker-position marker
)))
5297 (org-with-remote-undo buffer
5298 (with-current-buffer buffer
5302 (org-remove-subtree-entries-from-agenda)
5303 (org-back-to-heading t
)
5304 (org-archive-subtree))
5305 (error "Archiving works only in Org-mode files"))))))
5307 (defun org-agenda-archive-to-archive-sibling ()
5308 "Move the entry to the archive sibling."
5310 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5311 (let* ((marker (or (get-text-property (point) 'org-marker
)
5312 (org-agenda-error)))
5313 (buffer (marker-buffer marker
))
5314 (pos (marker-position marker
)))
5315 (org-with-remote-undo buffer
5316 (with-current-buffer buffer
5320 (org-remove-subtree-entries-from-agenda)
5321 (org-back-to-heading t
)
5322 (org-archive-to-archive-sibling))
5323 (error "Archiving works only in Org-mode files"))))))
5325 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
5326 "Remove all lines in the agenda that correspond to a given subtree.
5327 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5328 If this information is not given, the function uses the tree at point."
5329 (let ((buf (or buf
(current-buffer))) m p
)
5331 (unless (and beg end
)
5332 (org-back-to-heading t
)
5334 (org-end-of-subtree t
)
5336 (set-buffer (get-buffer org-agenda-buffer-name
))
5338 (goto-char (point-max))
5339 (beginning-of-line 1)
5341 (when (and (setq m
(get-text-property (point) 'org-marker
))
5342 (equal buf
(marker-buffer m
))
5343 (setq p
(marker-position m
))
5346 (let ((inhibit-read-only t
))
5347 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5348 (beginning-of-line 0))))))
5350 (defun org-agenda-open-link ()
5351 "Follow the link in the current line, if any."
5353 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
5356 (narrow-to-region (point-at-bol) (point-at-eol))
5357 (org-open-at-point))))
5359 (defun org-agenda-copy-local-variable (var)
5360 "Get a variable from a referenced buffer and install it here."
5361 (let ((m (get-text-property (point) 'org-marker
)))
5362 (when (and m
(buffer-live-p (marker-buffer m
)))
5363 (org-set-local var
(with-current-buffer (marker-buffer m
)
5364 (symbol-value var
))))))
5366 (defun org-agenda-switch-to (&optional delete-other-windows
)
5367 "Go to the Org-mode file which contains the item at point."
5369 (let* ((marker (or (get-text-property (point) 'org-marker
)
5370 (org-agenda-error)))
5371 (buffer (marker-buffer marker
))
5372 (pos (marker-position marker
)))
5373 (switch-to-buffer buffer
)
5374 (and delete-other-windows
(delete-other-windows))
5378 (org-show-context 'agenda
)
5380 (and (outline-next-heading)
5381 (org-flag-heading nil
)))))) ; show the next heading
5383 (defun org-agenda-goto-mouse (ev)
5384 "Go to the Org-mode file which contains the item at the mouse click."
5386 (mouse-set-point ev
)
5389 (defun org-agenda-show (&optional full-entry
)
5390 "Display the Org-mode file which contains the item at point.
5391 With prefix argument FULL-ENTRY, make the entire entry visible
5392 if it was hidden in the outline."
5394 (let ((win (selected-window)))
5396 (let ((org-show-entry-below t
))
5397 (org-agenda-goto t
))
5398 (org-agenda-goto t
))
5399 (select-window win
)))
5401 (defun org-agenda-show-1 (&optional more
)
5402 "Display the Org-mode file which contains the item at point.
5403 The prefix arg causes further revieling:
5406 1 just show the entry according to defaults.
5407 2 show the text below the heading
5408 3 show the entire subtree
5409 4 show the entire subtree and any LOGBOOK drawers
5410 5 show the entire subtree and any drawers
5411 With prefix argument FULL-ENTRY, make the entire entry visible
5412 if it was hidden in the outline."
5414 (let ((win (selected-window)))
5416 (org-recenter-heading 1)
5420 (message "Remote: hide subtree"))
5421 ((and (interactive-p) (= more
1))
5422 (message "Remote: show with default settings"))
5426 (org-back-to-heading)
5427 (org-cycle-hide-drawers 'children
))
5428 (message "Remote: show entry"))
5432 (org-back-to-heading)
5433 (org-cycle-hide-drawers 'subtree
))
5434 (message "Remote: show subtree"))
5436 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers
)))
5438 (concat "^[ \t]*:\\("
5439 (mapconcat 'regexp-quote org-drawers
"\\|")
5443 (org-back-to-heading)
5444 (org-cycle-hide-drawers 'subtree
)))
5445 (message "Remote: show subtree and LOGBOOK"))
5448 (message "Remote: show subtree and LOGBOOK")))
5449 (select-window win
)))
5451 (defun org-recenter-heading (n)
5453 (org-back-to-heading)
5456 (defvar org-agenda-cycle-counter nil
)
5457 (defun org-agenda-cycle-show (n)
5458 "Show the current entry in another window, with default settings.
5459 Default settings are taken from `org-show-hierarchy-above' and siblings.
5460 When use repeadedly in immediate succession, the remote entry will cycle
5463 entry -> subtree -> subtree with logbook"
5466 (not (eq last-command this-command
)))
5467 (setq org-agenda-cycle-counter
0))
5468 (setq org-agenda-cycle-counter
(1+ org-agenda-cycle-counter
))
5469 (if (> org-agenda-cycle-counter
4)
5470 (setq org-agenda-cycle-counter
0))
5471 (org-agenda-show-1 org-agenda-cycle-counter
))
5473 (defun org-agenda-recenter (arg)
5474 "Display the Org-mode file which contains the item at point and recenter."
5476 (let ((win (selected-window)))
5479 (select-window win
)))
5481 (defun org-agenda-show-mouse (ev)
5482 "Display the Org-mode file which contains the item at the mouse click."
5484 (mouse-set-point ev
)
5487 (defun org-agenda-check-no-diary ()
5488 "Check if the entry is a diary link and abort if yes."
5489 (if (get-text-property (point) 'org-agenda-diary-link
)
5490 (org-agenda-error)))
5492 (defun org-agenda-error ()
5493 (error "Command not allowed in this line"))
5495 (defun org-agenda-tree-to-indirect-buffer ()
5496 "Show the subtree corresponding to the current entry in an indirect buffer.
5497 This calls the command `org-tree-to-indirect-buffer' from the original
5499 With numerical prefix arg ARG, go up to this level and then take that tree.
5500 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
5503 (org-agenda-check-no-diary)
5504 (let* ((marker (or (get-text-property (point) 'org-marker
)
5505 (org-agenda-error)))
5506 (buffer (marker-buffer marker
))
5507 (pos (marker-position marker
)))
5508 (with-current-buffer buffer
5511 (call-interactively 'org-tree-to-indirect-buffer
)))))
5513 (defvar org-last-heading-marker
(make-marker)
5514 "Marker pointing to the headline that last changed its TODO state
5515 by a remote command from the agenda.")
5517 (defun org-agenda-todo-nextset ()
5518 "Switch TODO entry to next sequence."
5520 (org-agenda-todo 'nextset
))
5522 (defun org-agenda-todo-previousset ()
5523 "Switch TODO entry to previous sequence."
5525 (org-agenda-todo 'previousset
))
5527 (defun org-agenda-todo (&optional arg
)
5528 "Cycle TODO state of line at point, also in Org-mode file.
5529 This changes the line at point, all other lines in the agenda referring to
5530 the same tree node, and the headline of the tree node in the Org-mode file."
5532 (org-agenda-check-no-diary)
5533 (let* ((col (current-column))
5534 (marker (or (get-text-property (point) 'org-marker
)
5535 (org-agenda-error)))
5536 (buffer (marker-buffer marker
))
5537 (pos (marker-position marker
))
5538 (hdmarker (get-text-property (point) 'org-hd-marker
))
5539 (todayp (equal (get-text-property (point) 'day
)
5540 (time-to-days (current-time))))
5541 (inhibit-read-only t
)
5542 org-agenda-headline-snapshot-before-repeat newhead just-one
)
5543 (org-with-remote-undo buffer
5544 (with-current-buffer buffer
5547 (org-show-context 'agenda
)
5549 (and (outline-next-heading)
5550 (org-flag-heading nil
))) ; show the next heading
5551 (let ((current-prefix-arg arg
))
5552 (call-interactively 'org-todo
))
5553 (and (bolp) (forward-char 1))
5554 (setq newhead
(org-get-heading))
5555 (when (and (org-bound-and-true-p
5556 org-agenda-headline-snapshot-before-repeat
)
5557 (not (equal org-agenda-headline-snapshot-before-repeat
5560 (setq newhead org-agenda-headline-snapshot-before-repeat
5563 (org-back-to-heading)
5564 (move-marker org-last-heading-marker
(point))))
5565 (beginning-of-line 1)
5567 (org-agenda-change-all-lines newhead hdmarker
'fixface just-one
))
5568 (org-move-to-column col
))))
5570 (defun org-agenda-add-note (&optional arg
)
5571 "Add a time-stamped note to the entry at point."
5573 (org-agenda-check-no-diary)
5574 (let* ((marker (or (get-text-property (point) 'org-marker
)
5575 (org-agenda-error)))
5576 (buffer (marker-buffer marker
))
5577 (pos (marker-position marker
))
5578 (hdmarker (get-text-property (point) 'org-hd-marker
))
5579 (inhibit-read-only t
))
5580 (with-current-buffer buffer
5583 (org-show-context 'agenda
)
5585 (and (outline-next-heading)
5586 (org-flag-heading nil
))) ; show the next heading
5589 (defun org-agenda-change-all-lines (newhead hdmarker
5590 &optional fixface just-this
)
5591 "Change all lines in the agenda buffer which match HDMARKER.
5592 The new content of the line will be NEWHEAD (as modified by
5593 `org-format-agenda-item'). HDMARKER is checked with
5594 `equal' against all `org-hd-marker' text properties in the file.
5595 If FIXFACE is non-nil, the face of each item is modified according to
5597 If JUST-THIS is non-nil, change just the current line, not all.
5598 If FORCE-TAGS is non nil, the car of it returns the new tags."
5599 (let* ((inhibit-read-only t
)
5600 (line (org-current-line))
5601 (thetags (with-current-buffer (marker-buffer hdmarker
)
5602 (save-excursion (save-restriction (widen)
5603 (goto-char hdmarker
)
5604 (org-get-tags-at)))))
5605 props m pl undone-face done-face finish new dotime cat tags
)
5607 (goto-char (point-max))
5608 (beginning-of-line 1)
5610 (setq finish
(bobp))
5611 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
5612 (or (not just-this
) (= (org-current-line) line
))
5614 (setq props
(text-properties-at (point))
5615 dotime
(get-text-property (point) 'dotime
)
5616 cat
(get-text-property (point) 'org-category
)
5618 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
5619 pl
(get-text-property (point) 'prefix-length
)
5620 undone-face
(get-text-property (point) 'undone-face
)
5621 done-face
(get-text-property (point) 'done-face
))
5622 (org-move-to-column pl
)
5625 (beginning-of-line 1)
5626 (and (looking-at ".*\n?") (replace-match "")))
5628 (replace-match new t t
)
5629 (beginning-of-line 1)
5630 (add-text-properties (point-at-bol) (point-at-eol) props
)
5632 (add-text-properties
5633 (point-at-bol) (point-at-eol)
5635 (if org-last-todo-state-is-todo
5636 undone-face done-face
))))
5637 (org-agenda-highlight-todo 'line
)
5638 (beginning-of-line 1))
5639 (t (error "Line update did not work"))))
5640 (beginning-of-line 0)))
5641 (org-finalize-agenda)))
5643 (defun org-agenda-align-tags (&optional line
)
5644 "Align all tags in agenda items to `org-agenda-tags-column'."
5645 (let ((inhibit-read-only t
) l c
)
5647 (goto-char (if line
(point-at-bol) (point-min)))
5648 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
5649 (if line
(point-at-eol) nil
) t
)
5650 (add-text-properties
5651 (match-beginning 2) (match-end 2)
5652 (list 'face
(delq nil
(let ((prop (get-text-property
5653 (match-beginning 2) 'face
)))
5654 (or (listp prop
) (setq prop
(list prop
)))
5655 (if (memq 'org-tag prop
)
5657 (cons 'org-tag prop
))))))
5658 (setq l
(- (match-end 2) (match-beginning 2))
5659 c
(if (< org-agenda-tags-column
0)
5660 (- (abs org-agenda-tags-column
) l
)
5661 org-agenda-tags-column
))
5662 (delete-region (match-beginning 1) (match-end 1))
5663 (goto-char (match-beginning 1))
5664 (insert (org-add-props
5665 (make-string (max 1 (- c
(current-column))) ?\
)
5666 (text-properties-at (point)))))
5667 (goto-char (point-min))
5668 (org-font-lock-add-tag-faces (point-max)))))
5670 (defun org-agenda-priority-up ()
5671 "Increase the priority of line at point, also in Org-mode file."
5673 (org-agenda-priority 'up
))
5675 (defun org-agenda-priority-down ()
5676 "Decrease the priority of line at point, also in Org-mode file."
5678 (org-agenda-priority 'down
))
5680 (defun org-agenda-priority (&optional force-direction
)
5681 "Set the priority of line at point, also in Org-mode file.
5682 This changes the line at point, all other lines in the agenda referring to
5683 the same tree node, and the headline of the tree node in the Org-mode file."
5685 (org-agenda-check-no-diary)
5686 (let* ((marker (or (get-text-property (point) 'org-marker
)
5687 (org-agenda-error)))
5688 (hdmarker (get-text-property (point) 'org-hd-marker
))
5689 (buffer (marker-buffer hdmarker
))
5690 (pos (marker-position hdmarker
))
5691 (inhibit-read-only t
)
5693 (org-with-remote-undo buffer
5694 (with-current-buffer buffer
5697 (org-show-context 'agenda
)
5699 (and (outline-next-heading)
5700 (org-flag-heading nil
))) ; show the next heading
5701 (funcall 'org-priority force-direction
)
5703 (setq newhead
(org-get-heading)))
5704 (org-agenda-change-all-lines newhead hdmarker
)
5705 (beginning-of-line 1))))
5707 ;; FIXME: should fix the tags property of the agenda line.
5708 (defun org-agenda-set-tags ()
5709 "Set tags for the current headline."
5711 (org-agenda-check-no-diary)
5712 (if (and (org-region-active-p) (interactive-p))
5713 (call-interactively 'org-change-tag-in-region
)
5714 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5715 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5716 (org-agenda-error)))
5717 (buffer (marker-buffer hdmarker
))
5718 (pos (marker-position hdmarker
))
5719 (inhibit-read-only t
)
5721 (org-with-remote-undo buffer
5722 (with-current-buffer buffer
5726 (org-show-context 'agenda
))
5728 (and (outline-next-heading)
5729 (org-flag-heading nil
))) ; show the next heading
5731 (call-interactively 'org-set-tags
)
5733 (setq newhead
(org-get-heading)))
5734 (org-agenda-change-all-lines newhead hdmarker
)
5735 (beginning-of-line 1)))))
5737 (defun org-agenda-toggle-archive-tag ()
5738 "Toggle the archive tag for the current entry."
5740 (org-agenda-check-no-diary)
5741 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5742 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5743 (org-agenda-error)))
5744 (buffer (marker-buffer hdmarker
))
5745 (pos (marker-position hdmarker
))
5746 (inhibit-read-only t
)
5748 (org-with-remote-undo buffer
5749 (with-current-buffer buffer
5752 (org-show-context 'agenda
)
5754 (and (outline-next-heading)
5755 (org-flag-heading nil
))) ; show the next heading
5756 (call-interactively 'org-toggle-archive-tag
)
5758 (setq newhead
(org-get-heading)))
5759 (org-agenda-change-all-lines newhead hdmarker
)
5760 (beginning-of-line 1))))
5762 (defun org-agenda-do-date-later (arg)
5765 ((or (equal arg
'(16))
5767 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5768 (setq this-command
'org-agenda-date-later-minutes
)
5769 (org-agenda-date-later-minutes 1))
5770 ((or (equal arg
'(4))
5772 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5773 (setq this-command
'org-agenda-date-later-hours
)
5774 (org-agenda-date-later-hours 1))
5776 (org-agenda-date-later (prefix-numeric-value arg
)))))
5778 (defun org-agenda-do-date-earlier (arg)
5781 ((or (equal arg
'(16))
5783 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5784 (setq this-command
'org-agenda-date-earlier-minutes
)
5785 (org-agenda-date-earlier-minutes 1))
5786 ((or (equal arg
'(4))
5788 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5789 (setq this-command
'org-agenda-date-earlier-hours
)
5790 (org-agenda-date-earlier-hours 1))
5792 (org-agenda-date-earlier (prefix-numeric-value arg
)))))
5794 (defun org-agenda-date-later (arg &optional what
)
5795 "Change the date of this item to one day later."
5797 (org-agenda-check-type t
'agenda
'timeline
)
5798 (org-agenda-check-no-diary)
5799 (let* ((marker (or (get-text-property (point) 'org-marker
)
5800 (org-agenda-error)))
5801 (buffer (marker-buffer marker
))
5802 (pos (marker-position marker
)))
5803 (org-with-remote-undo buffer
5804 (with-current-buffer buffer
5807 (if (not (org-at-timestamp-p))
5808 (error "Cannot find time stamp"))
5809 (org-timestamp-change arg
(or what
'day
)))
5810 (org-agenda-show-new-time marker org-last-changed-timestamp
))
5811 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
5813 (defun org-agenda-date-earlier (arg &optional what
)
5814 "Change the date of this item to one day earlier."
5816 (org-agenda-date-later (- arg
) what
))
5818 (defun org-agenda-date-later-minutes (arg)
5819 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5821 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5822 (org-agenda-date-later arg
'minute
))
5824 (defun org-agenda-date-earlier-minutes (arg)
5825 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5827 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5828 (org-agenda-date-earlier arg
'minute
))
5830 (defun org-agenda-date-later-hours (arg)
5831 "Change the time of this item, in hour steps."
5833 (org-agenda-date-later arg
'hour
))
5835 (defun org-agenda-date-earlier-hours (arg)
5836 "Change the time of this item, in hour steps."
5838 (org-agenda-date-earlier arg
'hour
))
5840 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
5841 "Show new date stamp via text properties."
5842 ;; We use text properties to make this undoable
5843 (let ((inhibit-read-only t
)
5844 (buffer-invisibility-spec))
5845 (setq stamp
(concat " " prefix
" => " stamp
))
5847 (goto-char (point-max))
5849 (when (equal marker
(get-text-property (point) 'org-marker
))
5850 (org-move-to-column (- (window-width) (length stamp
)) t
)
5851 (org-agenda-fix-tags-filter-overlays-at (point))
5852 (if (featurep 'xemacs
)
5853 ;; Use `duplicable' property to trigger undo recording
5854 (let ((ex (make-extent nil nil
))
5855 (gl (make-glyph stamp
)))
5856 (set-glyph-face gl
'secondary-selection
)
5857 (set-extent-properties
5858 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
5859 (insert-extent ex
(1- (point)) (point-at-eol)))
5860 (add-text-properties
5861 (1- (point)) (point-at-eol)
5862 (list 'display
(org-add-props stamp nil
5863 'face
'secondary-selection
))))
5864 (beginning-of-line 1))
5865 (beginning-of-line 0)))))
5867 (defun org-agenda-date-prompt (arg)
5868 "Change the date of this item. Date is prompted for, with default today.
5869 The prefix ARG is passed to the `org-time-stamp' command and can therefore
5870 be used to request time specification in the time stamp."
5872 (org-agenda-check-type t
'agenda
'timeline
)
5873 (org-agenda-check-no-diary)
5874 (let* ((marker (or (get-text-property (point) 'org-marker
)
5875 (org-agenda-error)))
5876 (buffer (marker-buffer marker
))
5877 (pos (marker-position marker
)))
5878 (org-with-remote-undo buffer
5879 (with-current-buffer buffer
5882 (if (not (org-at-timestamp-p))
5883 (error "Cannot find time stamp"))
5884 (org-time-stamp arg
)
5885 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
5887 (defun org-agenda-schedule (arg)
5888 "Schedule the item at point."
5890 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
5891 (org-agenda-check-no-diary)
5892 (let* ((marker (or (get-text-property (point) 'org-marker
)
5893 (org-agenda-error)))
5894 (type (marker-insertion-type marker
))
5895 (buffer (marker-buffer marker
))
5896 (pos (marker-position marker
))
5897 (org-insert-labeled-timestamps-at-point nil
)
5899 (set-marker-insertion-type marker t
)
5900 (org-with-remote-undo buffer
5901 (with-current-buffer buffer
5904 (setq ts
(org-schedule arg
)))
5905 (org-agenda-show-new-time marker ts
"S"))
5906 (message "Item scheduled for %s" ts
)))
5908 (defun org-agenda-deadline (arg)
5909 "Schedule the item at point."
5911 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
5912 (org-agenda-check-no-diary)
5913 (let* ((marker (or (get-text-property (point) 'org-marker
)
5914 (org-agenda-error)))
5915 (buffer (marker-buffer marker
))
5916 (pos (marker-position marker
))
5917 (org-insert-labeled-timestamps-at-point nil
)
5919 (org-with-remote-undo buffer
5920 (with-current-buffer buffer
5923 (setq ts
(org-deadline arg
)))
5924 (org-agenda-show-new-time marker ts
"S"))
5925 (message "Deadline for this item set to %s" ts
)))
5927 (defun org-agenda-action ()
5928 "Select entry for agenda action, or execute an agenda action.
5929 This command prompts for another letter. Valid inputs are:
5931 m Mark the entry at point for an agenda action
5932 s Schedule the marked entry to the date at the cursor
5933 d Set the deadline of the marked entry to the date at the cursor
5934 r Call `org-remember' with cursor date as the default date
5935 SPC Show marked entry in other window
5936 TAB Visit marked entry in other window
5938 The cursor may be at a date in the calendar, or in the Org agenda."
5941 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
5942 (setq ans
(read-char-exclusive))
5946 (if (eq major-mode
'org-agenda-mode
)
5947 (let ((m (or (get-text-property (point) 'org-hd-marker
)
5948 (get-text-property (point) 'org-marker
))))
5951 (move-marker org-agenda-action-marker
5952 (marker-position m
) (marker-buffer m
))
5953 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
5954 (error "Don't know which entry to mark")))
5955 (error "This command works only in the agenda")))
5957 (org-agenda-do-action '(org-schedule nil org-overriding-default-time
)))
5959 (org-agenda-do-action '(org-deadline nil org-overriding-default-time
)))
5961 (org-agenda-do-action '(org-remember) t
))
5963 (let ((cw (selected-window)))
5964 (org-switch-to-buffer-other-window
5965 (marker-buffer org-agenda-action-marker
))
5966 (goto-char org-agenda-action-marker
)
5967 (org-show-context 'agenda
)
5968 (select-window cw
)))
5970 (org-switch-to-buffer-other-window
5971 (marker-buffer org-agenda-action-marker
))
5972 (goto-char org-agenda-action-marker
)
5973 (org-show-context 'agenda
))
5974 (t (error "Invalid agenda action %c" ans
)))))
5976 (defun org-agenda-do-action (form &optional current-buffer
)
5977 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
5978 (let ((org-overriding-default-time (org-get-cursor-date)))
5981 (if (not (marker-buffer org-agenda-action-marker
))
5982 (error "No entry has bee selected for agenda action")
5983 (with-current-buffer (marker-buffer org-agenda-action-marker
)
5987 (goto-char org-agenda-action-marker
)
5990 (defun org-agenda-clock-in (&optional arg
)
5991 "Start the clock on the currently selected item."
5993 (org-agenda-check-no-diary)
5994 (if (equal arg
'(4))
5996 (let* ((marker (or (get-text-property (point) 'org-marker
)
5997 (org-agenda-error)))
5998 (hdmarker (or (get-text-property (point) 'org-hd-marker
)
6000 (pos (marker-position marker
))
6002 (org-with-remote-undo (marker-buffer marker
)
6003 (with-current-buffer (marker-buffer marker
)
6006 (org-show-context 'agenda
)
6008 (org-cycle-hide-drawers 'children
)
6010 (setq newhead
(org-get-heading)))
6011 (org-agenda-change-all-lines newhead hdmarker t
)))))
6013 (defun org-agenda-clock-out (&optional arg
)
6014 "Stop the currently running clock."
6016 (unless (marker-buffer org-clock-marker
)
6017 (error "No running clock"))
6018 (org-with-remote-undo (marker-buffer org-clock-marker
)
6021 (defun org-agenda-clock-cancel (&optional arg
)
6022 "Cancel the currently running clock."
6024 (unless (marker-buffer org-clock-marker
)
6025 (error "No running clock"))
6026 (org-with-remote-undo (marker-buffer org-clock-marker
)
6027 (org-clock-cancel)))
6029 (defun org-agenda-diary-entry ()
6030 "Make a diary entry, like the `i' command from the calendar.
6031 All the standard commands work: block, weekly etc."
6033 (org-agenda-check-type t
'agenda
'timeline
)
6034 (require 'diary-lib
)
6036 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6037 (read-char-exclusive)))
6038 (cmd (cdr (assoc char
6039 '((?d . insert-diary-entry
)
6040 (?w . insert-weekly-diary-entry
)
6041 (?m . insert-monthly-diary-entry
)
6042 (?y . insert-yearly-diary-entry
)
6043 (?a . insert-anniversary-diary-entry
)
6044 (?b . insert-block-diary-entry
)
6045 (?c . insert-cyclic-diary-entry
)))))
6046 (oldf (symbol-function 'calendar-cursor-to-date
))
6047 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6049 (mark (or (mark t
) (point))))
6051 (error "No command associated with <%c>" char
))
6052 (unless (and (get-text-property point
'day
)
6053 (or (not (equal ?b char
))
6054 (get-text-property mark
'day
)))
6055 (error "Don't know which date to use for diary entry"))
6056 ;; We implement this by hacking the `calendar-cursor-to-date' function
6057 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6058 (let ((calendar-mark-ring
6059 (list (calendar-gregorian-from-absolute
6060 (or (get-text-property mark
'day
)
6061 (get-text-property point
'day
))))))
6064 (fset 'calendar-cursor-to-date
6065 (lambda (&optional error dummy
)
6066 (calendar-gregorian-from-absolute
6067 (get-text-property point
'day
))))
6068 (call-interactively cmd
))
6069 (fset 'calendar-cursor-to-date oldf
)))))
6071 (defun org-agenda-execute-calendar-command (cmd)
6072 "Execute a calendar command from the agenda, with the date associated to
6073 the cursor position."
6074 (org-agenda-check-type t
'agenda
'timeline
)
6075 (require 'diary-lib
)
6076 (unless (get-text-property (point) 'day
)
6077 (error "Don't know which date to use for calendar command"))
6078 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
6080 (date (calendar-gregorian-from-absolute
6081 (get-text-property point
'day
)))
6082 ;; the following 2 vars are needed in the calendar
6083 (displayed-month (car date
))
6084 (displayed-year (nth 2 date
)))
6087 (fset 'calendar-cursor-to-date
6088 (lambda (&optional error dummy
)
6089 (calendar-gregorian-from-absolute
6090 (get-text-property point
'day
))))
6091 (call-interactively cmd
))
6092 (fset 'calendar-cursor-to-date oldf
))))
6094 (defun org-agenda-phases-of-moon ()
6095 "Display the phases of the moon for the 3 months around the cursor date."
6097 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
6099 (defun org-agenda-holidays ()
6100 "Display the holidays for the 3 months around the cursor date."
6102 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
6104 (defvar calendar-longitude
)
6105 (defvar calendar-latitude
)
6106 (defvar calendar-location-name
)
6108 (defun org-agenda-sunrise-sunset (arg)
6109 "Display sunrise and sunset for the cursor date.
6110 Latitude and longitude can be specified with the variables
6111 `calendar-latitude' and `calendar-longitude'. When called with prefix
6112 argument, latitude and longitude will be prompted for."
6115 (let ((calendar-longitude (if arg nil calendar-longitude
))
6116 (calendar-latitude (if arg nil calendar-latitude
))
6117 (calendar-location-name
6118 (if arg
"the given coordinates" calendar-location-name
)))
6119 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
6121 (defun org-agenda-goto-calendar ()
6122 "Open the Emacs calendar with the date at the cursor."
6124 (org-agenda-check-type t
'agenda
'timeline
)
6125 (let* ((day (or (get-text-property (point) 'day
)
6126 (error "Don't know which date to open in calendar")))
6127 (date (calendar-gregorian-from-absolute day
))
6128 (calendar-move-hook nil
)
6129 (calendar-view-holidays-initially-flag nil
)
6130 (calendar-view-diary-initially-flag nil
)
6131 (view-calendar-holidays-initially nil
)
6132 (view-diary-entries-initially nil
))
6134 (calendar-goto-date date
)))
6137 (defun org-calendar-goto-agenda ()
6138 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6139 This is a command that has to be installed in `calendar-mode-map'."
6141 (org-agenda-list nil
(calendar-absolute-from-gregorian
6142 (calendar-cursor-to-date))
6145 (defun org-agenda-convert-date ()
6147 (org-agenda-check-type t
'agenda
'timeline
)
6148 (let ((day (get-text-property (point) 'day
))
6151 (error "Don't know which date to convert"))
6152 (setq date
(calendar-gregorian-from-absolute day
))
6154 "Gregorian: " (calendar-date-string date
) "\n"
6155 "ISO: " (calendar-iso-date-string date
) "\n"
6156 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
6157 "Julian: " (calendar-julian-date-string date
) "\n"
6158 "Astron. JD: " (calendar-astro-date-string date
)
6159 " (Julian date number at noon UTC)\n"
6160 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
6161 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
6162 "French: " (calendar-french-date-string date
) "\n"
6163 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
6164 "Mayan: " (calendar-mayan-date-string date
) "\n"
6165 "Coptic: " (calendar-coptic-date-string date
) "\n"
6166 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
6167 "Persian: " (calendar-persian-date-string date
) "\n"
6168 "Chinese: " (calendar-chinese-date-string date
) "\n"))
6169 (with-output-to-temp-buffer "*Dates*"
6171 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6173 ;;; Appointment reminders
6175 (defvar appt-time-msg-list
)
6178 (defun org-agenda-to-appt (&optional refresh filter
)
6179 "Activate appointments found in `org-agenda-files'.
6180 With a \\[universal-argument] prefix, refresh the list of
6183 If FILTER is t, interactively prompt the user for a regular
6184 expression, and filter out entries that don't match it.
6186 If FILTER is a string, use this string as a regular expression
6187 for filtering entries out.
6189 FILTER can also be an alist with the car of each cell being
6190 either 'headline or 'category. For example:
6192 '((headline \"IMPORTANT\")
6193 (category \"Work\"))
6195 will only add headlines containing IMPORTANT or headlines
6196 belonging to the \"Work\" category."
6199 (if refresh
(setq appt-time-msg-list nil
))
6201 (setq filter
(read-from-minibuffer "Regexp filter: ")))
6202 (let* ((cnt 0) ; count added events
6203 (org-agenda-new-buffers nil
)
6204 (org-deadline-warning-days 0)
6205 (today (org-date-to-gregorian
6206 (time-to-days (current-time))))
6207 (files (org-agenda-files 'unrestricted
)) entries file
)
6208 ;; Get all entries which may contain an appt
6209 (org-prepare-agenda-buffers files
)
6210 (while (setq file
(pop files
))
6213 (org-agenda-get-day-entries
6214 file today
:timestamp
:scheduled
:deadline
))))
6215 (setq entries
(delq nil entries
))
6216 ;; Map thru entries and find if we should filter them out
6219 (let* ((evt (org-trim (or (get-text-property 1 'txt x
) "")))
6220 (cat (get-text-property 1 'org-category x
))
6221 (tod (get-text-property 1 'time-of-day x
))
6222 (ok (or (null filter
)
6223 (and (stringp filter
) (string-match filter evt
))
6226 (cadr (assoc 'category filter
)) cat
)
6228 (cadr (assoc 'headline filter
)) evt
))))))
6229 ;; FIXME: Shall we remove text-properties for the appt text?
6230 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
6232 (setq tod
(concat "00" (number-to-string tod
))
6233 tod
(when (string-match
6234 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod
)
6235 (concat (match-string 1 tod
) ":"
6236 (match-string 2 tod
))))
6238 (setq cnt
(1+ cnt
))))) entries
)
6239 (org-release-buffers org-agenda-new-buffers
)
6241 (message "No event to add")
6242 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
6244 (defun org-agenda-todayp (date)
6245 "Does DATE mean today, when considering `org-extend-today-until'?"
6247 (if (listp date
) (setq date
(calendar-absolute-from-gregorian date
)))
6248 (setq today
(calendar-absolute-from-gregorian (calendar-current-date)))
6249 (setq h
(nth 2 (decode-time (current-time))))
6250 (or (and (>= h org-extend-today-until
)
6252 (and (< h org-extend-today-until
)
6253 (= date
(1- today
))))))
6255 (provide 'org-agenda
)
6257 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
6259 ;;; org-agenda.el ends here