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.
428 4. An arbitrary regular expression matching non-stuck projects.
430 If the project turns out to be not stuck, search continues also in the
431 subtree to see if any of the subtasks have project status.
433 See also the variable `org-tags-match-list-sublevels' which applies
434 to projects matched by this search as well.
436 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
437 or `C-c a #' to produce the list."
438 :group
'org-agenda-custom-commands
440 (string :tag
"Tags/TODO match to identify a project")
441 (repeat :tag
"Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
442 (repeat :tag
"Projects are *not* stuck if they have an entry with TAG being any of" (string))
443 (regexp :tag
"Projects are *not* stuck if this regexp matches\ninside the subtree")))
445 (defcustom org-agenda-filter-effort-default-operator
"<"
446 "The default operator for effort estimate filtering.
447 If you select an effort estimate limit without first pressing an operator,
448 this one will be used."
449 :group
'org-agenda-custom-commands
450 :type
'(choice (const :tag
"less or equal" "<")
451 (const :tag
"greater or equal"">")
452 (const :tag
"equal" "=")))
454 (defgroup org-agenda-skip nil
455 "Options concerning skipping parts of agenda files."
456 :tag
"Org Agenda Skip"
458 (defgroup org-agenda-daily
/weekly nil
459 "Options concerning the daily/weekly agenda."
460 :tag
"Org Agenda Daily/Weekly"
462 (defgroup org-agenda-todo-list nil
463 "Options concerning the global todo list agenda view."
464 :tag
"Org Agenda Todo List"
466 (defgroup org-agenda-match-view nil
467 "Options concerning the general tags/property/todo match agenda view."
468 :tag
"Org Agenda Match View"
471 (defvar org-agenda-archives-mode nil
472 "Non-nil means, the agenda will include archived items.
473 If this is the symbol `trees', trees in the selected agenda scope
474 that are marked with the ARCHIVE tag will be included anyway. When this is
475 t, also all archive files associated with the current selection of agenda
476 files will be included.")
478 (defcustom org-agenda-skip-comment-trees t
479 "Non-nil means, skip trees that start with the COMMENT keyword.
480 When nil, these trees are also scanned by agenda commands."
481 :group
'org-agenda-skip
484 (defcustom org-agenda-todo-list-sublevels t
485 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
486 When nil, the sublevels of a TODO entry are not checked, resulting in
487 potentially much shorter TODO lists."
488 :group
'org-agenda-skip
489 :group
'org-agenda-todo-list
492 (defcustom org-agenda-todo-ignore-with-date nil
493 "Non-nil means, don't show entries with a date in the global todo list.
494 You can use this if you prefer to mark mere appointments with a TODO keyword,
495 but don't want them to show up in the TODO list.
496 When this is set, it also covers deadlines and scheduled items, the settings
497 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
499 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
500 :group
'org-agenda-skip
501 :group
'org-agenda-todo-list
504 (defcustom org-agenda-todo-ignore-scheduled nil
505 "Non-nil means, don't show scheduled entries in the global todo list.
506 The idea behind this is that by scheduling it, you have already taken care
508 See also `org-agenda-todo-ignore-with-date'.
509 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
510 :group
'org-agenda-skip
511 :group
'org-agenda-todo-list
514 (defcustom org-agenda-todo-ignore-deadlines nil
515 "Non-nil means, don't show near deadline entries in the global todo list.
516 Near means closer than `org-deadline-warning-days' days.
517 The idea behind this is that such items will appear in the agenda anyway.
518 See also `org-agenda-todo-ignore-with-date'.
519 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
520 :group
'org-agenda-skip
521 :group
'org-agenda-todo-list
524 (defcustom org-agenda-tags-todo-honor-ignore-options nil
525 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
527 `org-agenda-todo-ignore-with-date',
528 `org-agenda-todo-ignore-scheduled'
529 `org-agenda-todo-ignore-deadlines'
530 make the global TODO list skip entries that have time stamps of certain
531 kinds. If this option is set, the same options will also apply for the
532 tags-todo search, which is the general tags/property matcher
533 restricted to unfinished TODO entries only."
534 :group
'org-agenda-skip
535 :group
'org-agenda-todo-list
536 :group
'org-agenda-match-view
539 (defcustom org-agenda-skip-scheduled-if-done nil
540 "Non-nil means don't show scheduled items in agenda when they are done.
541 This is relevant for the daily/weekly agenda, not for the TODO list. And
542 it applies only to the actual date of the scheduling. Warnings about
543 an item with a past scheduling dates are always turned off when the item
545 :group
'org-agenda-skip
546 :group
'org-agenda-daily
/weekly
549 (defcustom org-agenda-skip-deadline-if-done nil
550 "Non-nil means don't show deadlines when the corresponding item is done.
551 When nil, the deadline is still shown and should give you a happy feeling.
552 This is relevant for the daily/weekly agenda. And it applied only to the
553 actually date of the deadline. Warnings about approaching and past-due
554 deadlines are always turned off when the item is DONE."
555 :group
'org-agenda-skip
556 :group
'org-agenda-daily
/weekly
559 (defcustom org-agenda-skip-timestamp-if-done nil
560 "Non-nil means don't select item by timestamp or -range if it is DONE."
561 :group
'org-agenda-skip
562 :group
'org-agenda-daily
/weekly
565 (defcustom org-agenda-dim-blocked-tasks t
566 "Non-nil means, dim blocked tasks in the agenda display.
567 This causes some overhead during agenda construction, but if you
568 have turned on `org-enforce-todo-dependencies',
569 `org-enforce-todo-checkbox-dependencies', or any other blocking
570 mechanism, this will create useful feedback in the agenda.
572 Instead ot t, this variable can also have the value `invisible'.
573 Then blocked tasks will be invisible and only become visible when
574 they become unblocked. An exemption to this behavior is when a task is
575 blocked because of unchecked checkboxes below it. Since checkboxes do
576 not show up in the agenda views, making this task invisible you remove any
577 trace from agenda views that there is something to do. Therefore, a task
578 that is blocked because of checkboxes will never be made invisible, it
579 will only be dimmed."
580 :group
'org-agenda-daily
/weekly
581 :group
'org-agenda-todo-list
583 (const :tag
"Do not dim" nil
)
584 (const :tag
"Dim to a grey face" t
)
585 (const :tag
"Make invisibe" invisible
)))
587 (defcustom org-timeline-show-empty-dates
3
588 "Non-nil means, `org-timeline' also shows dates without an entry.
589 When nil, only the days which actually have entries are shown.
590 When t, all days between the first and the last date are shown.
591 When an integer, show also empty dates, but if there is a gap of more than
592 N days, just insert a special line indicating the size of the gap."
593 :group
'org-agenda-skip
595 (const :tag
"None" nil
)
597 (integer :tag
"at most")))
599 (defgroup org-agenda-startup nil
600 "Options concerning initial settings in the Agenda in Org Mode."
601 :tag
"Org Agenda Startup"
604 (defcustom org-finalize-agenda-hook nil
605 "Hook run just before displaying an agenda buffer."
606 :group
'org-agenda-startup
609 (defcustom org-agenda-mouse-1-follows-link nil
610 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
611 A longer mouse click will still set point. Does not work on XEmacs.
612 Needs to be set before org.el is loaded."
613 :group
'org-agenda-startup
616 (defcustom org-agenda-start-with-follow-mode nil
617 "The initial value of follow-mode in a newly created agenda window."
618 :group
'org-agenda-startup
621 (defvar org-agenda-include-inactive-timestamps nil
622 "Non-nil means, include inactive time stamps in agenda and timeline.")
624 (defgroup org-agenda-windows nil
625 "Options concerning the windows used by the Agenda in Org Mode."
626 :tag
"Org Agenda Windows"
629 (defcustom org-agenda-window-setup
'reorganize-frame
630 "How the agenda buffer should be displayed.
631 Possible values for this option are:
633 current-window Show agenda in the current window, keeping all other windows.
634 other-frame Use `switch-to-buffer-other-frame' to display agenda.
635 other-window Use `switch-to-buffer-other-window' to display agenda.
636 reorganize-frame Show only two windows on the current frame, the current
637 window and the agenda.
638 See also the variable `org-agenda-restore-windows-after-quit'."
639 :group
'org-agenda-windows
641 (const current-window
)
644 (const reorganize-frame
)))
646 (defcustom org-agenda-window-frame-fractions
'(0.5 .
0.75)
647 "The min and max height of the agenda window as a fraction of frame height.
648 The value of the variable is a cons cell with two numbers between 0 and 1.
649 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
650 :group
'org-agenda-windows
651 :type
'(cons (number :tag
"Minimum") (number :tag
"Maximum")))
653 (defcustom org-agenda-restore-windows-after-quit nil
654 "Non-nil means, restore window configuration open exiting agenda.
655 Before the window configuration is changed for displaying the agenda,
656 the current status is recorded. When the agenda is exited with
657 `q' or `x' and this option is set, the old state is restored. If
658 `org-agenda-window-setup' is `other-frame', the value of this
659 option will be ignored.."
660 :group
'org-agenda-windows
663 (defcustom org-agenda-ndays
7
664 "Number of days to include in overview display.
666 Custom commands can set this variable in the options section."
667 :group
'org-agenda-daily
/weekly
670 (defcustom org-agenda-start-on-weekday
1
671 "Non-nil means, start the overview always on the specified weekday.
672 0 denotes Sunday, 1 denotes Monday etc.
673 When nil, always start on the current day.
674 Custom commands can set this variable in the options section."
675 :group
'org-agenda-daily
/weekly
676 :type
'(choice (const :tag
"Today" nil
)
677 (integer :tag
"Weekday No.")))
679 (defcustom org-agenda-show-all-dates t
680 "Non-nil means, `org-agenda' shows every day in the selected range.
681 When nil, only the days which actually have entries are shown."
682 :group
'org-agenda-daily
/weekly
685 (defcustom org-agenda-format-date
'org-agenda-format-date-aligned
686 "Format string for displaying dates in the agenda.
687 Used by the daily/weekly agenda and by the timeline. This should be
688 a format string understood by `format-time-string', or a function returning
689 the formatted date as a string. The function must take a single argument,
690 a calendar-style date list like (month day year)."
691 :group
'org-agenda-daily
/weekly
693 (string :tag
"Format string")
694 (function :tag
"Function")))
696 (defun org-agenda-format-date-aligned (date)
697 "Format a date string for display in the daily/weekly agenda, or timeline.
698 This function makes sure that dates are aligned for easy reading."
700 (let* ((dayname (calendar-day-name date
))
702 (day-of-week (calendar-day-of-week date
))
704 (monthname (calendar-month-name month
))
706 (iso-week (org-days-to-iso-week
707 (calendar-absolute-from-gregorian date
)))
708 (weekyear (cond ((and (= month
1) (>= iso-week
52))
710 ((and (= month
12) (<= iso-week
1))
713 (weekstring (if (= day-of-week
1)
714 (format " W%02d" iso-week
)
716 (format "%-10s %2d %s %4d%s"
717 dayname day monthname year weekstring
)))
719 (defcustom org-agenda-weekend-days
'(6 0)
720 "Which days are weekend?
721 These days get the special face `org-agenda-date-weekend' in the agenda
722 and timeline buffers."
723 :group
'org-agenda-daily
/weekly
724 :type
'(set :greedy t
725 (const :tag
"Monday" 1)
726 (const :tag
"Tuesday" 2)
727 (const :tag
"Wednesday" 3)
728 (const :tag
"Thursday" 4)
729 (const :tag
"Friday" 5)
730 (const :tag
"Saturday" 6)
731 (const :tag
"Sunday" 0)))
733 (defcustom org-agenda-include-diary nil
734 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
735 Custom commands can set this variable in the options section."
736 :group
'org-agenda-daily
/weekly
739 (defcustom org-agenda-include-all-todo nil
740 "Set means weekly/daily agenda will always contain all TODO entries.
741 The TODO entries will be listed at the top of the agenda, before
742 the entries for specific days.
743 This option is deprecated, it is better to define a block agenda instead."
744 :group
'org-agenda-daily
/weekly
747 (defcustom org-agenda-repeating-timestamp-show-all t
748 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
749 When nil, only one occurrence is shown, either today or the
750 nearest into the future."
751 :group
'org-agenda-daily
/weekly
754 (defcustom org-scheduled-past-days
10000
755 "No. of days to continue listing scheduled items that are not marked DONE.
756 When an item is scheduled on a date, it shows up in the agenda on this
757 day and will be listed until it is marked done for the number of days
759 :group
'org-agenda-daily
/weekly
762 (defcustom org-agenda-log-mode-items
'(closed clock
)
763 "List of items that should be shown in agenda log mode.
764 This list may contain the following symbols:
766 closed Show entries that have been closed on that day.
767 clock Show entries that have received clocked time on that day.
768 state Show all logged state changes.
769 Note that instead of changing this variable, you can also press `C-u l' in
770 the agenda to display all available LOG items temporarily."
771 :group
'org-agenda-daily
/weekly
772 :type
'(set :greedy t
(const closed
) (const clock
) (const state
)))
774 (defcustom org-agenda-log-mode-add-notes t
775 "Non-nil means, add first line of notes to log entries in agenda views.
776 If a log item like a state change or a clock entry is associated with
777 notes, the first line of these notes will be added to the entry in the
779 :group
'org-agenda-daily
/weekly
782 (defcustom org-agenda-start-with-clockreport-mode nil
783 "The initial value of clockreport-mode in a newly created agenda window."
784 :group
'org-agenda-startup
785 :group
'org-agenda-daily
/weekly
788 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
789 "Property list with parameters for the clocktable in clockreport mode.
790 This is the display mode that shows a clock table in the daily/weekly
791 agenda, the properties for this dynamic block can be set here.
792 The usual clocktable parameters are allowed here, but you cannot set
793 the properties :name, :tstart, :tend, :block, and :scope - these will
794 be overwritten to make sure the content accurately reflects the
795 current display in the agenda."
796 :group
'org-agenda-daily
/weekly
800 (defgroup org-agenda-time-grid nil
801 "Options concerning the time grid in the Org-mode Agenda."
802 :tag
"Org Agenda Time Grid"
805 (defcustom org-agenda-search-headline-for-time t
806 "Non-nil means, search headline for a time-of-day.
807 If the headline contains a time-of-day in one format or another, it will
808 be used to sort the entry into the time sequence of items for a day.
809 Some people have time stamps in the headline that refer to the creation
810 time or so, and then this produces an unwanted side effect. If this is
811 the case for your, use this variable to turn off searching the headline
813 :group
'org-agenda-time-grid
816 (defcustom org-agenda-use-time-grid t
817 "Non-nil means, show a time grid in the agenda schedule.
818 A time grid is a set of lines for specific times (like every two hours between
819 8:00 and 20:00). The items scheduled for a day at specific times are
820 sorted in between these lines.
821 For details about when the grid will be shown, and what it will look like, see
822 the variable `org-agenda-time-grid'."
823 :group
'org-agenda-time-grid
826 (defcustom org-agenda-time-grid
827 '((daily today require-timed
)
829 (800 1000 1200 1400 1600 1800 2000))
831 "The settings for time grid for agenda display.
832 This is a list of three items. The first item is again a list. It contains
833 symbols specifying conditions when the grid should be displayed:
835 daily if the agenda shows a single day
836 weekly if the agenda shows an entire week
837 today show grid on current date, independent of daily/weekly display
838 require-timed show grid only if at least one item has a time specification
840 The second item is a string which will be placed behind the grid time.
842 The third item is a list of integers, indicating the times that should have
844 :group
'org-agenda-time-grid
847 (set :greedy t
:tag
"Grid Display Options"
848 (const :tag
"Show grid in single day agenda display" daily
)
849 (const :tag
"Show grid in weekly agenda display" weekly
)
850 (const :tag
"Always show grid for today" today
)
851 (const :tag
"Show grid only if any timed entries are present"
853 (const :tag
"Skip grid times already present in an entry"
855 (string :tag
"Grid String")
856 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
858 (defgroup org-agenda-sorting nil
859 "Options concerning sorting in the Org-mode Agenda."
860 :tag
"Org Agenda Sorting"
863 (defcustom org-agenda-sorting-strategy
864 '((agenda time-up priority-down category-keep
)
865 (todo priority-down category-keep
)
866 (tags priority-down category-keep
)
867 (search category-keep
))
868 "Sorting structure for the agenda items of a single day.
869 This is a list of symbols which will be used in sequence to determine
870 if an entry should be listed before another entry. The following
871 symbols are recognized:
873 time-up Put entries with time-of-day indications first, early first
874 time-down Put entries with time-of-day indications first, late first
875 category-keep Keep the default order of categories, corresponding to the
876 sequence in `org-agenda-files'.
877 category-up Sort alphabetically by category, A-Z.
878 category-down Sort alphabetically by category, Z-A.
879 tag-up Sort alphabetically by last tag, A-Z.
880 tag-down Sort alphabetically by last tag, Z-A.
881 priority-up Sort numerically by priority, high priority last.
882 priority-down Sort numerically by priority, high priority first.
883 todo-state-up Sort by todo state, tasks that are done last.
884 todo-state-down Sort by todo state, tasks that are done first.
885 effort-up Sort numerically by estimated effort, high effort last.
886 effort-down Sort numerically by estimated effort, high effort first.
887 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
888 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
890 The different possibilities will be tried in sequence, and testing stops
891 if one comparison returns a \"not-equal\". For example, the default
892 '(time-up category-keep priority-down)
893 means: Pull out all entries having a specified time of day and sort them,
894 in order to make a time schedule for the current day the first thing in the
895 agenda listing for the day. Of the entries without a time indication, keep
896 the grouped in categories, don't sort the categories, but keep them in
897 the sequence given in `org-agenda-files'. Within each category sort by
900 Leaving out `category-keep' would mean that items will be sorted across
901 categories by priority.
903 Instead of a single list, this can also be a set of list for specific
904 contents, with a context symbol in the car of the list, any of
905 `agenda', `todo', `tags' for the corresponding agenda views.
907 Custom commands can bind this variable in the options section."
908 :group
'org-agenda-sorting
910 (repeat :tag
"General" ,org-sorting-choice
)
911 (list :tag
"Individually"
912 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
913 (repeat ,org-sorting-choice
))
914 (cons (const :tag
"Strategy for TODO lists" todo
)
915 (repeat ,org-sorting-choice
))
916 (cons (const :tag
"Strategy for Tags matches" tags
)
917 (repeat ,org-sorting-choice
)))))
919 (defcustom org-agenda-cmp-user-defined nil
920 "A function to define the comparison `user-defined'.
921 This function must receive two arguments, agenda entry a and b.
922 If a>b, return +1. If a<b, return -1. If they are equal as seen by
923 the user comparison, return nil.
924 When this is defined, you can make `user-defined-up' and `user-defined-down'
925 part of an agenda sorting strategy."
926 :group
'org-agenda-sorting
929 (defcustom org-sort-agenda-notime-is-late t
930 "Non-nil means, items without time are considered late.
931 This is only relevant for sorting. When t, items which have no explicit
932 time like 15:30 will be considered as 99:01, i.e. later than any items which
933 do have a time. When nil, the default time is before 0:00. You can use this
934 option to decide if the schedule for today should come before or after timeless
936 :group
'org-agenda-sorting
939 (defcustom org-sort-agenda-noeffort-is-high t
940 "Non-nil means, items without effort estimate are sorted as high effort.
941 This also applies when filtering an agenda view with respect to the
942 < or > effort operator. Then, tasks with no effort defined will be treated
943 as tasks with high effort.
944 When nil, such items are sorted as 0 minutes effort."
945 :group
'org-agenda-sorting
948 (defgroup org-agenda-line-format nil
949 "Options concerning the entry prefix in the Org-mode agenda display."
950 :tag
"Org Agenda Line Format"
953 (defcustom org-agenda-prefix-format
954 '((agenda .
" %-12:c%?-12t% s")
958 (search .
" %-12:c"))
959 "Format specifications for the prefix of items in the agenda views.
960 An alist with four entries, for the different agenda types. The keys to the
961 sublists are `agenda', `timeline', `todo', and `tags'. The values
963 This format works similar to a printf format, with the following meaning:
965 %c the category of the item, \"Diary\" for entries from the diary, or
966 as given by the CATEGORY keyword or derived from the file name.
967 %T the *last* tag of the item. Last because inherited tags come
969 %t the time-of-day specification if one applies to the entry, in the
971 %s Scheduling/Deadline information, a short string
973 All specifiers work basically like the standard `%s' of printf, but may
974 contain two additional characters: A question mark just after the `%' and
975 a whitespace/punctuation character just before the final letter.
977 If the first character after `%' is a question mark, the entire field
978 will only be included if the corresponding value applies to the
979 current entry. This is useful for fields which should have fixed
980 width when present, but zero width when absent. For example,
981 \"%?-12t\" will result in a 12 character time field if a time of the
982 day is specified, but will completely disappear in entries which do
985 If there is punctuation or whitespace character just before the final
986 format letter, this character will be appended to the field value if
987 the value is not empty. For example, the format \"%-12:c\" leads to
988 \"Diary: \" if the category is \"Diary\". If the category were be
989 empty, no additional colon would be interted.
991 The default value of this option is \" %-12:c%?-12t% s\", meaning:
992 - Indent the line with two space characters
993 - Give the category in a 12 chars wide field, padded with whitespace on
994 the right (because of `-'). Append a colon if there is a category
996 - If there is a time-of-day, put it into a 12 chars wide field. If no
997 time, don't put in an empty field, just skip it (because of '?').
998 - Finally, put the scheduling information and append a whitespace.
1000 As another example, if you don't want the time-of-day of entries in
1001 the prefix, you could use:
1003 (setq org-agenda-prefix-format \" %-11:c% s\")
1005 See also the variables `org-agenda-remove-times-when-in-prefix' and
1006 `org-agenda-remove-tags'.
1008 Custom commands can set this variable in the options section."
1010 (string :tag
"General format")
1011 (list :greedy t
:tag
"View dependent"
1012 (cons (const agenda
) (string :tag
"Format"))
1013 (cons (const timeline
) (string :tag
"Format"))
1014 (cons (const todo
) (string :tag
"Format"))
1015 (cons (const tags
) (string :tag
"Format"))
1016 (cons (const search
) (string :tag
"Format"))))
1017 :group
'org-agenda-line-format
)
1019 (defvar org-prefix-format-compiled nil
1020 "The compiled version of the most recently used prefix format.
1021 See the variable `org-agenda-prefix-format'.")
1023 (defcustom org-agenda-todo-keyword-format
"%-1s"
1024 "Format for the TODO keyword in agenda lines.
1025 Set this to something like \"%-12s\" if you want all TODO keywords
1026 to occupy a fixed space in the agenda display."
1027 :group
'org-agenda-line-format
1030 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1031 "Text preceding timerange entries in the agenda view.
1032 This is a list with two strings. The first applies when the range
1033 is entirely on one day. The second applies if the range spans several days.
1034 The strings may have two \"%d\" format specifiers which will be filled
1035 with the sequence number of the days, and the total number of days in the
1036 range, respectively."
1037 :group
'org-agenda-line-format
1039 (string :tag
"Deadline today ")
1040 (choice :tag
"Deadline relative"
1041 (string :tag
"Format string")
1044 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1045 "Text preceeding scheduled items in the agenda view.
1046 This is a list with two strings. The first applies when the item is
1047 scheduled on the current day. The second applies when it has been scheduled
1048 previously, it may contain a %d indicating that this is the nth time that
1049 this item is scheduled, due to automatic rescheduling of unfinished items
1050 for the following day. So this number is one larger than the number of days
1051 that passed since this item was scheduled first."
1052 :group
'org-agenda-line-format
1054 (string :tag
"Scheduled today ")
1055 (string :tag
"Scheduled previously")))
1057 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1058 "Text preceeding deadline items in the agenda view.
1059 This is a list with two strings. The first applies when the item has its
1060 deadline on the current day. The second applies when it is in the past or
1061 in the future, it may contain %d to capture how many days away the deadline
1063 :group
'org-agenda-line-format
1065 (string :tag
"Deadline today ")
1066 (choice :tag
"Deadline relative"
1067 (string :tag
"Format string")
1070 (defcustom org-agenda-remove-times-when-in-prefix t
1071 "Non-nil means, remove duplicate time specifications in agenda items.
1072 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1073 time-of-day specification in a headline or diary entry is extracted and
1074 placed into the prefix. If this option is non-nil, the original specification
1075 \(a timestamp or -range, or just a plain time(range) specification like
1076 11:30-4pm) will be removed for agenda display. This makes the agenda less
1078 The option can be t or nil. It may also be the symbol `beg', indicating
1079 that the time should only be removed what it is located at the beginning of
1080 the headline/diary entry."
1081 :group
'org-agenda-line-format
1083 (const :tag
"Always" t
)
1084 (const :tag
"Never" nil
)
1085 (const :tag
"When at beginning of entry" beg
)))
1088 (defcustom org-agenda-default-appointment-duration nil
1089 "Default duration for appointments that only have a starting time.
1090 When nil, no duration is specified in such cases.
1091 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1092 :group
'org-agenda-line-format
1094 (integer :tag
"Minutes")
1095 (const :tag
"No default duration")))
1097 (defcustom org-agenda-show-inherited-tags t
1098 "Non-nil means, show inherited tags in each agenda line."
1099 :group
'org-agenda-line-format
1102 (defcustom org-agenda-remove-tags nil
1103 "Non-nil means, remove the tags from the headline copy in the agenda.
1104 When this is the symbol `prefix', only remove tags when
1105 `org-agenda-prefix-format' contains a `%T' specifier."
1106 :group
'org-agenda-line-format
1108 (const :tag
"Always" t
)
1109 (const :tag
"Never" nil
)
1110 (const :tag
"When prefix format contains %T" prefix
)))
1112 (if (fboundp 'defvaralias
)
1113 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1114 'org-agenda-remove-tags
))
1116 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1117 "Shift tags in agenda items to this column.
1118 If this number is positive, it specifies the column. If it is negative,
1119 it means that the tags should be flushright to that column. For example,
1120 -80 works well for a normal 80 character screen."
1121 :group
'org-agenda-line-format
1124 (if (fboundp 'defvaralias
)
1125 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1127 (defcustom org-agenda-fontify-priorities
'cookies
1128 "Non-nil means, highlight low and high priorities in agenda.
1129 When t, the highest priority entries are bold, lowest priority italic.
1130 However, settings in org-priority-faces will overrule these faces.
1131 When this variable is the symbol `cookies', only fontify the
1132 cookies, not the entire task.
1133 This may also be an association list of priority faces, whose
1134 keys are the character values of `org-highest-priority',
1135 `org-default-priority', and `org-lowest-priority' (the default values
1136 are ?A, ?B, and ?C, respectively). The face may be a named face,
1137 or a list like `(:background \"Red\")'."
1138 :group
'org-agenda-line-format
1140 (const :tag
"Never" nil
)
1141 (const :tag
"Defaults" t
)
1142 (const :tag
"Cookies only" cookies
)
1143 (repeat :tag
"Specify"
1144 (list (character :tag
"Priority" :value ?A
)
1145 (sexp :tag
"face")))))
1147 (defgroup org-agenda-column-view nil
1148 "Options concerning column view in the agenda."
1149 :tag
"Org Agenda Column View"
1152 (defcustom org-agenda-columns-show-summaries t
1153 "Non-nil means, show summaries for columns displayed in the agenda view."
1154 :group
'org-agenda-column-view
1157 (defcustom org-agenda-columns-remove-prefix-from-item t
1158 "Non-nil means, remove the prefix from a headline for agenda column view.
1159 The special ITEM field in the columns format contains the current line, with
1160 all information shown in other columns (like the TODO state or a tag).
1161 When this variable is non-nil, also the agenda prefix will be removed from
1162 the content of the ITEM field, to make sure as much as possible of the
1163 headline can be shown in the limited width of the field."
1167 (defcustom org-agenda-columns-compute-summary-properties t
1168 "Non-nil means, recompute all summary properties before column view.
1169 When column view in the agenda is listing properties that have a summary
1170 operator, it can go to all relevant buffers and recompute the summaries
1171 there. This can mean overhead for the agenda column view, but is necessary
1172 to have thing up to date.
1173 As a special case, a CLOCKSUM property also makes sure that the clock
1174 computations are current."
1175 :group
'org-agenda-column-view
1178 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1179 "Non-nil means, the duration of an appointment will add to day effort.
1180 The property to which appointment durations will be added is the one given
1181 in the option `org-effort-property'. If an appointment does not have
1182 an end time, `org-agenda-default-appointment-duration' will be used. If that
1183 is not set, an appointment without end time will not contribute to the time
1185 :group
'org-agenda-column-view
1192 (defun org-add-agenda-custom-command (entry)
1193 "Replace or add a command in `org-agenda-custom-commands'.
1194 This is mostly for hacking and trying a new command - once the command
1195 works you probably want to add it to `org-agenda-custom-commands' for good."
1196 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1198 (setcdr ass
(cdr entry
))
1199 (push entry org-agenda-custom-commands
))))
1201 ;;; Define the Org-agenda-mode
1203 (defvar org-agenda-mode-map
(make-sparse-keymap)
1204 "Keymap for `org-agenda-mode'.")
1206 (defvar org-agenda-menu
) ; defined later in this file.
1207 (defvar org-agenda-follow-mode nil
)
1208 (defvar org-agenda-clockreport-mode nil
)
1209 (defvar org-agenda-show-log nil
)
1210 (defvar org-agenda-redo-command nil
)
1211 (defvar org-agenda-query-string nil
)
1212 (defvar org-agenda-mode-hook nil
1213 "Hook for org-agenda-mode, run after the mode is turned on.")
1214 (defvar org-agenda-type nil
)
1215 (defvar org-agenda-force-single-file nil
)
1217 (defun org-agenda-mode ()
1218 "Mode for time-sorted view on action items in Org-mode files.
1220 The following commands are available:
1222 \\{org-agenda-mode-map}"
1224 (kill-all-local-variables)
1225 (setq org-agenda-undo-list nil
1226 org-agenda-pending-undo-list nil
)
1227 (setq major-mode
'org-agenda-mode
)
1228 ;; Keep global-font-lock-mode from turning on font-lock-mode
1229 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1230 (setq mode-name
"Org-Agenda")
1231 (use-local-map org-agenda-mode-map
)
1232 (easy-menu-add org-agenda-menu
)
1233 (if org-startup-truncated
(setq truncate-lines t
))
1234 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1235 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1236 ;; Make sure properties are removed when copying text
1237 (when (boundp 'buffer-substring-filters
)
1238 (org-set-local 'buffer-substring-filters
1240 (set-text-properties 0 (length x
) nil x
) x
)
1241 buffer-substring-filters
)))
1242 (unless org-agenda-keep-modes
1243 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1244 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1245 org-agenda-show-log nil
))
1247 '("Agenda") "Agenda Files"
1251 (if (get 'org-agenda-files
'org-restrict
)
1252 "Restricted to single file"
1254 '(org-edit-agenda-file-list)
1255 (not (get 'org-agenda-files
'org-restrict
)))
1257 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1258 (org-agenda-set-mode-name)
1260 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1261 (list 'org-agenda-mode-hook
)))
1263 (substitute-key-definition 'undo
'org-agenda-undo
1264 org-agenda-mode-map global-map
)
1265 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1266 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1267 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1268 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1269 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1270 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1271 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1272 (org-defkey org-agenda-mode-map
"A" 'org-agenda-archive-to-archive-sibling
)
1273 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1274 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1275 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1276 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1277 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1278 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1279 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1280 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1281 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1282 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1283 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1284 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1285 (org-defkey org-agenda-mode-map
"\C-c\C-q" 'org-agenda-set-tags
)
1286 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1287 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1288 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1289 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1290 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1291 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1292 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1293 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1294 (org-defkey org-agenda-mode-map
"k" 'org-agenda-action
)
1295 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-k" 'org-agenda-action
)
1296 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-do-date-later
)
1297 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-do-date-earlier
)
1298 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-do-date-later
)
1299 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-do-date-earlier
)
1301 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1302 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1303 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1304 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1305 (while l
(org-defkey org-agenda-mode-map
1306 (int-to-string (pop l
)) 'digit-argument
)))
1308 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1309 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1310 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1311 (org-defkey org-agenda-mode-map
"v" 'org-agenda-archives-mode
)
1312 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1313 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1314 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1315 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1316 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1317 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1318 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1319 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1320 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1321 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1322 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1323 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1324 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1325 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1326 (org-defkey org-agenda-mode-map
"\C-c\C-a" 'org-attach
)
1327 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1328 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1329 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1330 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1331 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1332 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1333 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1334 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1335 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1336 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1337 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1338 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1339 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1340 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1341 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1342 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1343 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1344 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1345 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1346 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1347 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1348 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1349 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1350 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1351 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1352 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1353 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1354 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1356 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1357 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1358 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1359 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1360 (org-defkey org-agenda-mode-map
"/" 'org-agenda-filter-by-tag
)
1361 (org-defkey org-agenda-mode-map
"\\" 'org-agenda-filter-by-tag-refine
)
1363 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1364 "Local keymap for agenda entries from Org-mode.")
1366 (org-defkey org-agenda-keymap
1367 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1368 (org-defkey org-agenda-keymap
1369 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1370 (when org-agenda-mouse-1-follows-link
1371 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1372 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1376 ["Show" org-agenda-show t
]
1377 ["Go To (other window)" org-agenda-goto t
]
1378 ["Go To (this window)" org-agenda-switch-to t
]
1379 ["Follow Mode" org-agenda-follow-mode
1380 :style toggle
:selected org-agenda-follow-mode
:active t
]
1381 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1383 ["Cycle TODO" org-agenda-todo t
]
1385 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t
]
1386 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t
]
1387 ["Archive subtree" org-agenda-archive t
])
1388 ["Delete subtree" org-agenda-kill t
]
1389 ["Add note" org-agenda-add-note t
]
1391 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1392 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1393 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1394 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1396 ("Tags and Properties"
1397 ["Show all Tags" org-agenda-show-tags t
]
1398 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1399 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1401 ["Column View" org-columns t
])
1403 ["Schedule" org-agenda-schedule t
]
1404 ["Set Deadline" org-agenda-deadline t
]
1406 ["Mark item" org-agenda-action
:active t
:keys
"k m"]
1407 ["Show mark item" org-agenda-action
:active t
:keys
"k v"]
1408 ["Schedule marked item" org-agenda-action
:active t
:keys
"k s"]
1409 ["Set Deadline for marked item" org-agenda-action
:active t
:keys
"k d"]
1411 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1412 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1413 ["Change Time +1 hour" org-agenda-do-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-right"]
1414 ["Change Time -1 hour" org-agenda-do-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-left"]
1415 ["Change Time + min" org-agenda-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-right"]
1416 ["Change Time - min" org-agenda-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-left"]
1417 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1419 ["Clock in" org-agenda-clock-in t
]
1420 ["Clock out" org-agenda-clock-out t
]
1421 ["Clock cancel" org-agenda-clock-cancel t
]
1422 ["Goto running clock" org-clock-goto t
])
1424 ["Set Priority" org-agenda-priority t
]
1425 ["Increase Priority" org-agenda-priority-up t
]
1426 ["Decrease Priority" org-agenda-priority-down t
]
1427 ["Show Priority" org-agenda-show-priority t
])
1429 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1430 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1431 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1432 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1433 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1434 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1436 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1439 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1440 :style radio
:selected
(equal org-agenda-ndays
1)]
1441 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1442 :style radio
:selected
(equal org-agenda-ndays
7)]
1443 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1444 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1445 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1446 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1448 ["Include Diary" org-agenda-toggle-diary
1449 :style toggle
:selected org-agenda-include-diary
1450 :active
(org-agenda-check-type nil
'agenda
)]
1451 ["Use Time Grid" org-agenda-toggle-time-grid
1452 :style toggle
:selected org-agenda-use-time-grid
1453 :active
(org-agenda-check-type nil
'agenda
)]
1455 ["Show clock report" org-agenda-clockreport-mode
1456 :style toggle
:selected org-agenda-clockreport-mode
1457 :active
(org-agenda-check-type nil
'agenda
)]
1459 ["Show Logbook entries" org-agenda-log-mode
1460 :style toggle
:selected org-agenda-show-log
1461 :active
(org-agenda-check-type nil
'agenda
'timeline
)]
1462 ["Include archived trees" org-agenda-archives-mode
1463 :style toggle
:selected org-agenda-archives-mode
:active t
]
1464 ["Include archive files" (org-agenda-archives-mode t
)
1465 :style toggle
:selected
(eq org-agenda-archives-mode t
) :active t
1467 ["Write view to file" org-write-agenda t
]
1468 ["Rebuild buffer" org-agenda-redo t
]
1469 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1471 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1473 ["Quit" org-agenda-quit t
]
1474 ["Exit and Release Buffers" org-agenda-exit t
]
1479 (defvar org-agenda-allow-remote-undo t
1480 "Non-nil means, allow remote undo from the agenda buffer.")
1481 (defvar org-agenda-undo-list nil
1482 "List of undoable operations in the agenda since last refresh.")
1483 (defvar org-agenda-undo-has-started-in nil
1484 "Buffers that have already seen `undo-start' in the current undo sequence.")
1485 (defvar org-agenda-pending-undo-list nil
1486 "In a series of undo commands, this is the list of remaining undo items.")
1489 (defun org-agenda-undo ()
1490 "Undo a remote editing step in the agenda.
1491 This undoes changes both in the agenda buffer and in the remote buffer
1492 that have been changed along."
1494 (or org-agenda-allow-remote-undo
1495 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1496 (if (not (eq this-command last-command
))
1497 (setq org-agenda-undo-has-started-in nil
1498 org-agenda-pending-undo-list org-agenda-undo-list
))
1499 (if (not org-agenda-pending-undo-list
)
1500 (error "No further undo information"))
1501 (let* ((entry (pop org-agenda-pending-undo-list
))
1502 buf line cmd rembuf
)
1503 (setq cmd
(pop entry
) line
(pop entry
))
1504 (setq rembuf
(nth 2 entry
))
1505 (org-with-remote-undo rembuf
1506 (while (bufferp (setq buf
(pop entry
)))
1508 (with-current-buffer buf
1509 (let ((last-undo-buffer buf
)
1510 (inhibit-read-only t
))
1511 (unless (memq buf org-agenda-undo-has-started-in
)
1512 (push buf org-agenda-undo-has-started-in
)
1513 (make-local-variable 'pending-undo-list
)
1515 (while (and pending-undo-list
1516 (listp pending-undo-list
)
1517 (not (car pending-undo-list
)))
1518 (pop pending-undo-list
))
1521 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1523 (defun org-verify-change-for-undo (l1 l2
)
1524 "Verify that a real change occurred between the undo lists L1 and L2."
1525 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1526 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1531 (defvar org-agenda-restrict nil
)
1532 (defvar org-agenda-restrict-begin
(make-marker))
1533 (defvar org-agenda-restrict-end
(make-marker))
1534 (defvar org-agenda-last-dispatch-buffer nil
)
1535 (defvar org-agenda-overriding-restriction nil
)
1538 (defun org-agenda (&optional arg keys restriction
)
1539 "Dispatch agenda commands to collect entries to the agenda buffer.
1540 Prompts for a command to execute. Any prefix arg will be passed
1541 on to the selected command. The default selections are:
1543 a Call `org-agenda-list' to display the agenda for current day or week.
1544 t Call `org-todo-list' to display the global todo list.
1545 T Call `org-todo-list' to display the global todo list, select only
1546 entries with a specific TODO keyword (the user gets a prompt).
1547 m Call `org-tags-view' to display headlines with tags matching
1548 a condition (the user is prompted for the condition).
1549 M Like `m', but select only TODO entries, no ordinary headlines.
1550 L Create a timeline for the current buffer.
1551 e Export views to associated files.
1552 s Search entries for keywords.
1553 / Multi occur accros all agenda files and also files listed
1554 in `org-agenda-text-search-extra-files'.
1555 < Restrict agenda commands to buffer, subtree, or region.
1556 Press several times to get the desired effect.
1557 > Remove a previous restriction.
1558 # List \"stuck\" projects.
1559 ! Configure what \"stuck\" means.
1560 C Configure custom agenda commands.
1562 More commands can be added by configuring the variable
1563 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1564 searches can be pre-defined in this way.
1566 If the current buffer is in Org-mode and visiting a file, you can also
1567 first press `<' once to indicate that the agenda should be temporarily
1568 \(until the next use of \\[org-agenda]) restricted to the current file.
1569 Pressing `<' twice means to restrict to the current subtree or region
1573 (let* ((prefix-descriptions nil
)
1574 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1575 (org-agenda-custom-commands
1576 ;; normalize different versions
1580 (cond ((stringp (cdr x
))
1581 (push x prefix-descriptions
)
1583 ((stringp (nth 1 x
)) x
)
1584 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1585 (t (cons (car x
) (cons "" (cdr x
))))))
1586 org-agenda-custom-commands
)))
1587 (buf (current-buffer))
1588 (bfn (buffer-file-name (buffer-base-buffer)))
1589 entry key type match lprops ans
)
1590 ;; Turn off restriction unless there is an overriding one
1591 (unless org-agenda-overriding-restriction
1592 (put 'org-agenda-files
'org-restrict nil
)
1593 (setq org-agenda-restrict nil
)
1594 (move-marker org-agenda-restrict-begin nil
)
1595 (move-marker org-agenda-restrict-end nil
))
1596 ;; Delete old local properties
1597 (put 'org-agenda-redo-command
'org-lprops nil
)
1598 ;; Remember where this call originated
1599 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1601 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1603 restriction
(cdr ans
)))
1604 ;; Estabish the restriction, if any
1605 (when (and (not org-agenda-overriding-restriction
) restriction
)
1606 (put 'org-agenda-files
'org-restrict
(list bfn
))
1608 ((eq restriction
'region
)
1609 (setq org-agenda-restrict t
)
1610 (move-marker org-agenda-restrict-begin
(region-beginning))
1611 (move-marker org-agenda-restrict-end
(region-end)))
1612 ((eq restriction
'subtree
)
1614 (setq org-agenda-restrict t
)
1615 (org-back-to-heading t
)
1616 (move-marker org-agenda-restrict-begin
(point))
1617 (move-marker org-agenda-restrict-end
1618 (progn (org-end-of-subtree t
)))))))
1620 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1621 ;; For example the todo list should not need it (but does...)
1623 ((setq entry
(assoc keys org-agenda-custom-commands
))
1624 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1626 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1627 (put 'org-agenda-redo-command
'org-lprops lprops
)
1630 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1632 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1634 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1636 (org-let lprops
'(org-agenda-list-stuck-projects
1637 current-prefix-arg
)))
1639 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1640 ((eq type
'tags-todo
)
1641 (org-let lprops
'(org-tags-view '(4) match
)))
1643 (org-let lprops
'(org-todo-list match
)))
1644 ((eq type
'tags-tree
)
1645 (org-check-for-org-mode)
1646 (org-let lprops
'(org-match-sparse-tree current-prefix-arg match
)))
1647 ((eq type
'todo-tree
)
1648 (org-check-for-org-mode)
1650 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1651 (regexp-quote match
) "\\>"))))
1652 ((eq type
'occur-tree
)
1653 (org-check-for-org-mode)
1654 (org-let lprops
'(org-occur match
)))
1656 (org-let lprops
'(funcall type match
)))
1658 (org-let lprops
'(funcall type match
)))
1659 (t (error "Invalid custom agenda command type %s" type
))))
1660 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1662 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1663 (customize-variable 'org-agenda-custom-commands
))
1664 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1665 ((equal keys
"s") (call-interactively 'org-search-view
))
1666 ((equal keys
"t") (call-interactively 'org-todo-list
))
1667 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1668 ((equal keys
"m") (call-interactively 'org-tags-view
))
1669 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1670 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1672 (unless (org-mode-p)
1673 (error "This is not an Org-mode file"))
1675 (put 'org-agenda-files
'org-restrict
(list bfn
))
1676 (org-call-with-arg 'org-timeline arg
)))
1677 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1678 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1679 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1680 (t (error "Invalid agenda key"))))))
1682 (defun org-agenda-normalize-custom-commands (cmds)
1686 (cond ((stringp (cdr x
)) nil
)
1687 ((stringp (nth 1 x
)) x
)
1688 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1689 (t (cons (car x
) (cons "" (cdr x
))))))
1692 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1693 "The user interface for selecting an agenda command."
1695 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1696 (restrict-ok (and bfn
(org-mode-p)))
1697 (region-p (org-region-active-p))
1698 (custom org-agenda-custom-commands
)
1700 restriction second-time
1701 c entry key type match prefixes rmheader header-end custom1 desc
)
1702 (save-window-excursion
1703 (delete-other-windows)
1704 (org-switch-to-buffer-other-window " *Agenda Commands*")
1706 (insert (eval-when-compile
1709 Press key for an agenda command: < Buffer, subtree/region restriction
1710 -------------------------------- > Remove restriction
1711 a Agenda for current week or day e Export agenda views
1712 t List of all TODO entries T Entries with special TODO kwd
1713 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1714 L Timeline for current buffer # List stuck projects (!=configure)
1715 s Search for keywords C Configure custom agenda commands
1719 (while (string-match
1720 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1722 (setq start
(match-end 0))
1723 (add-text-properties (match-beginning 2) (match-end 2)
1724 '(face bold
) header
))
1726 (setq header-end
(move-marker (make-marker) (point)))
1728 (setq custom1 custom
)
1729 (when (eq rmheader t
)
1731 (re-search-forward ":" nil t
)
1732 (delete-region (match-end 0) (point-at-eol))
1735 (delete-region (match-end 0) (point-at-eol))
1736 (move-marker header-end
(match-end 0)))
1737 (goto-char header-end
)
1738 (delete-region (point) (point-max))
1739 (while (setq entry
(pop custom1
))
1740 (setq key
(car entry
) desc
(nth 1 entry
)
1741 type
(nth 2 entry
) match
(nth 3 entry
))
1742 (if (> (length key
) 1)
1743 (add-to-list 'prefixes
(string-to-char key
))
1747 (org-add-props (copy-sequence key
)
1750 ((string-match "\\S-" desc
) desc
)
1751 ((eq type
'agenda
) "Agenda for current week or day")
1752 ((eq type
'alltodo
) "List of all TODO entries")
1753 ((eq type
'search
) "Word search")
1754 ((eq type
'stuck
) "List of stuck projects")
1755 ((eq type
'todo
) "TODO keyword")
1756 ((eq type
'tags
) "Tags query")
1757 ((eq type
'tags-todo
) "Tags (TODO)")
1758 ((eq type
'tags-tree
) "Tags tree")
1759 ((eq type
'todo-tree
) "TODO kwd tree")
1760 ((eq type
'occur-tree
) "Occur tree")
1761 ((functionp type
) (if (symbolp type
)
1763 "Lambda expression"))
1767 (org-add-props match nil
'face
'org-warning
))
1769 (format "set of %d commands" (length match
)))
1775 (org-add-props (char-to-string x
)
1777 (or (cdr (assoc (concat selstring
(char-to-string x
))
1778 prefix-descriptions
))
1781 (goto-char (point-min))
1783 (if (not (pos-visible-in-window-p (point-max)))
1784 (org-fit-window-to-buffer))
1785 (setq second-time t
)
1786 (org-fit-window-to-buffer))
1787 (message "Press key for agenda command%s:"
1788 (if (or restrict-ok org-agenda-overriding-restriction
)
1789 (if org-agenda-overriding-restriction
1790 " (restriction lock active)"
1792 (format " (restricted to %s)" restriction
)
1795 (setq c
(read-char-exclusive))
1798 ((assoc (char-to-string c
) custom
)
1799 (setq selstring
(concat selstring
(char-to-string c
)))
1800 (throw 'exit
(cons selstring restriction
)))
1802 (setq selstring
(concat selstring
(char-to-string c
))
1804 rmheader
(or rmheader t
)
1805 custom
(delq nil
(mapcar
1807 (if (or (= (length (car x
)) 1)
1808 (/= (string-to-char (car x
)) c
))
1810 (cons (substring (car x
) 1) (cdr x
))))
1812 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1813 (message "Restriction is only possible in Org-mode buffers")
1816 (org-agenda-remove-restriction-lock 'noupdate
)
1817 (setq restriction
'buffer
))
1819 (org-agenda-remove-restriction-lock 'noupdate
)
1820 (setq restriction
(if region-p
'region
'subtree
)))
1822 (org-agenda-remove-restriction-lock 'noupdate
)
1825 ((eq restriction
'buffer
)
1826 (if region-p
'region
'subtree
))
1827 ((memq restriction
'(subtree region
))
1831 (org-agenda-remove-restriction-lock 'noupdate
)
1832 (setq restriction nil
))
1833 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1834 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1835 ((and (> (length selstring
) 0) (eq c ?\d
))
1837 (org-agenda-get-restriction-and-command prefix-descriptions
))
1839 ((equal c ?q
) (error "Abort"))
1840 (t (error "Invalid key %c" c
))))))))
1842 (defun org-run-agenda-series (name series
)
1843 (org-prepare-agenda name
)
1844 (let* ((org-agenda-multi t
)
1845 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1847 (gprops (nth 1 series
))
1848 match
;; The byte compiler incorrectly complains about this. Keep it!
1850 (while (setq cmd
(pop cmds
))
1851 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1854 (org-let2 gprops lprops
1855 '(call-interactively 'org-agenda-list
)))
1857 (org-let2 gprops lprops
1858 '(call-interactively 'org-todo-list
)))
1860 (org-let2 gprops lprops
1861 '(org-search-view current-prefix-arg match nil
)))
1863 (org-let2 gprops lprops
1864 '(call-interactively 'org-agenda-list-stuck-projects
)))
1866 (org-let2 gprops lprops
1867 '(org-tags-view current-prefix-arg match
)))
1868 ((eq type
'tags-todo
)
1869 (org-let2 gprops lprops
1870 '(org-tags-view '(4) match
)))
1872 (org-let2 gprops lprops
1873 '(org-todo-list match
)))
1875 (org-let2 gprops lprops
1876 '(funcall type match
)))
1877 (t (error "Invalid type in command series"))))
1879 (setq org-agenda-redo-command redo
)
1880 (goto-char (point-min)))
1881 (org-fit-agenda-window)
1882 (org-let (nth 1 series
) '(org-finalize-agenda)))
1885 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1886 "Run an agenda command in batch mode and send the result to STDOUT.
1887 If CMD-KEY is a string of length 1, it is used as a key in
1888 `org-agenda-custom-commands' and triggers this command. If it is a
1889 longer string it is used as a tags/todo match string.
1890 Paramters are alternating variable names and values that will be bound
1891 before running the agenda command."
1894 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1895 (if (> (length cmd-key
) 2)
1896 (eval (list 'let
(nreverse pars
)
1897 (list 'org-tags-view nil cmd-key
)))
1898 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1899 (set-buffer org-agenda-buffer-name
)
1900 (princ (org-encode-for-stdout (buffer-string)))))
1902 (defun org-encode-for-stdout (string)
1903 (if (fboundp 'encode-coding-string
)
1904 (encode-coding-string string buffer-file-coding-system
)
1907 (defvar org-agenda-info nil
)
1910 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1911 "Run an agenda command in batch mode and send the result to STDOUT.
1912 If CMD-KEY is a string of length 1, it is used as a key in
1913 `org-agenda-custom-commands' and triggers this command. If it is a
1914 longer string it is used as a tags/todo match string.
1915 Paramters are alternating variable names and values that will be bound
1916 before running the agenda command.
1918 The output gives a line for each selected agenda item. Each
1919 item is a list of comma-separated values, like this:
1921 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1923 category The category of the item
1924 head The headline, without TODO kwd, TAGS and PRIORITY
1925 type The type of the agenda entry, can be
1926 todo selected in TODO match
1927 tagsmatch selected in tags match
1928 diary imported from diary
1929 deadline a deadline on given date
1930 scheduled scheduled on given date
1931 timestamp entry has timestamp on given date
1932 closed entry was closed on given date
1933 upcoming-deadline warning about deadline
1934 past-scheduled forwarded scheduled item
1935 block entry has date block including g. date
1936 todo The todo keyword, if any
1937 tags All tags including inherited ones, separated by colons
1938 date The relevant date, like 2007-2-14
1939 time The time, like 15:00-16:50
1940 extra Sting with extra planning info
1941 priority-l The priority letter if any was given
1942 priority-n The computed numerical priority
1943 agenda-day The day in the agenda where this is listed"
1947 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1948 (push (list 'org-agenda-remove-tags t
) pars
)
1949 (if (> (length cmd-key
) 2)
1950 (eval (list 'let
(nreverse pars
)
1951 (list 'org-tags-view nil cmd-key
)))
1952 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1953 (set-buffer org-agenda-buffer-name
)
1954 (let* ((lines (org-split-string (buffer-string) "\n"))
1956 (while (setq line
(pop lines
))
1958 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1959 (setq org-agenda-info
1960 (org-fix-agenda-info (text-properties-at 0 line
)))
1962 (org-encode-for-stdout
1963 (mapconcat 'org-agenda-export-csv-mapper
1964 '(org-category txt type todo tags date time-of-day extra
1965 priority-letter priority agenda-day
)
1969 (defun org-fix-agenda-info (props)
1970 "Make sure all properties on an agenda item have a canonical form,
1971 so the export commands can easily use it."
1973 (when (setq tmp
(plist-get props
'tags
))
1974 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1975 (when (setq tmp
(plist-get props
'date
))
1976 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1977 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1978 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
1980 (setq tmp
(calendar-date-string tmp
)))
1981 (setq props
(plist-put props
'date tmp
)))
1982 (when (setq tmp
(plist-get props
'day
))
1983 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1984 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1985 (setq tmp
(calendar-date-string tmp
)))
1986 (setq props
(plist-put props
'day tmp
))
1987 (setq props
(plist-put props
'agenda-day tmp
)))
1988 (when (setq tmp
(plist-get props
'txt
))
1989 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
1990 (plist-put props
'priority-letter
(match-string 1 tmp
))
1991 (setq tmp
(replace-match "" t t tmp
)))
1992 (when (and (setq re
(plist-get props
'org-todo-regexp
))
1993 (setq re
(concat "\\`\\.*" re
" ?"))
1994 (string-match re tmp
))
1995 (plist-put props
'todo
(match-string 1 tmp
))
1996 (setq tmp
(replace-match "" t t tmp
)))
1997 (plist-put props
'txt tmp
)))
2000 (defun org-agenda-export-csv-mapper (prop)
2001 (let ((res (plist-get org-agenda-info prop
)))
2006 (t (prin1-to-string res
))))
2007 (while (string-match "," res
)
2008 (setq res
(replace-match ";" t t res
)))
2013 (defun org-store-agenda-views (&rest parameters
)
2015 (eval (list 'org-batch-store-agenda-views
)))
2017 ;; FIXME, why is this a macro?????
2019 (defmacro org-batch-store-agenda-views
(&rest parameters
)
2020 "Run all custom agenda commands that have a file argument."
2021 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
2023 (dir default-directory
)
2024 pars cmd thiscmdkey files opts cmd-or-set
)
2026 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
2027 (setq pars
(reverse pars
))
2028 (save-window-excursion
2030 (setq cmd
(pop cmds
)
2031 thiscmdkey
(car cmd
)
2032 cmd-or-set
(nth 2 cmd
)
2033 opts
(nth (if (listp cmd-or-set
) 3 4) cmd
)
2034 files
(nth (if (listp cmd-or-set
) 4 5) cmd
))
2035 (if (stringp files
) (setq files
(list files
)))
2037 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2038 (list 'org-agenda nil thiscmdkey
)))
2039 (set-buffer org-agenda-buffer-name
)
2041 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2042 (list 'org-write-agenda
2043 (expand-file-name (pop files
) dir
) nil t
))))
2044 (and (get-buffer org-agenda-buffer-name
)
2045 (kill-buffer org-agenda-buffer-name
)))))))
2047 (defun org-write-agenda (file &optional open nosettings
)
2048 "Write the current buffer (an agenda view) as a file.
2049 Depending on the extension of the file name, plain text (.txt),
2050 HTML (.html or .htm) or Postscript (.ps) is produced.
2051 If the extension is .ics, run icalendar export over all files used
2052 to construct the agenda and limit the export to entries listed in the
2054 With prefic argument OPEN, open the new file immediately.
2055 If NOSETTINGS is given, do not scope the settings of
2056 `org-agenda-exporter-settings' into the export commands. This is used when
2057 the settings have already been scoped and we do not wish to overrule other,
2058 higher priority settings."
2059 (interactive "FWrite agenda to file: \nP")
2060 (if (not (file-writable-p file
))
2061 (error "Cannot write agenda to file %s" file
))
2063 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
2064 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
2065 (org-let (if nosettings nil org-agenda-exporter-settings
)
2067 (save-window-excursion
2068 (org-agenda-mark-filtered-text)
2069 (let ((bs (copy-sequence (buffer-string))) beg
)
2070 (org-agenda-unmark-filtered-text)
2073 (org-agenda-remove-marked-text 'org-filtered
)
2074 (while (setq beg
(text-property-any (point-min) (point-max)
2077 beg
(or (next-single-property-change beg
'org-filtered
)
2079 (run-hooks 'org-agenda-before-write-hook
)
2081 ((string-match "\\.html?\\'" file
)
2082 (set-buffer (htmlize-buffer (current-buffer)))
2084 (when (and org-agenda-export-html-style
2085 (string-match "<style>" org-agenda-export-html-style
))
2086 ;; replace <style> section with org-agenda-export-html-style
2087 (goto-char (point-min))
2088 (kill-region (- (search-forward "<style") 6)
2089 (search-forward "</style>"))
2090 (insert org-agenda-export-html-style
))
2092 (kill-buffer (current-buffer))
2093 (message "HTML written to %s" file
))
2094 ((string-match "\\.ps\\'" file
)
2096 (flet ((ps-get-buffer-name () "Agenda View"))
2097 (ps-print-buffer-with-faces file
))
2098 (message "Postscript written to %s" file
))
2099 ((string-match "\\.pdf\\'" file
)
2101 (flet ((ps-get-buffer-name () "Agenda View"))
2102 (ps-print-buffer-with-faces
2103 (concat (file-name-sans-extension file
) ".ps")))
2104 (call-process "ps2pdf" nil nil nil
2106 (concat (file-name-sans-extension file
) ".ps"))
2107 (expand-file-name file
))
2108 (message "PDF written to %s" file
))
2109 ((string-match "\\.ics\\'" file
)
2110 (let ((org-agenda-marker-table
2111 (org-create-marker-find-array
2112 (org-agenda-collect-markers)))
2113 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
2114 (org-combined-agenda-icalendar-file file
))
2115 (apply 'org-export-icalendar
'combine
2116 (org-agenda-files nil
'ifmode
))))
2118 (let ((bs (buffer-string)))
2123 (kill-buffer (current-buffer))
2124 (message "Plain text written to %s" file
))))))))
2125 (set-buffer org-agenda-buffer-name
))
2126 (when open
(org-open-file file
)))
2128 (defvar org-agenda-filter-overlays nil
)
2130 (defun org-agenda-mark-filtered-text ()
2131 "Mark all text hidden by filtering with a text property."
2132 (let ((inhibit-read-only t
))
2135 (when (equal (org-overlay-buffer o
) (current-buffer))
2137 (org-overlay-start o
) (org-overlay-end o
)
2139 org-agenda-filter-overlays
)))
2141 (defun org-agenda-unmark-filtered-text ()
2142 "Remove the filtering text property."
2143 (let ((inhibit-read-only t
))
2144 (remove-text-properties (point-min) (point-max) '(org-filtered t
))))
2146 (defun org-agenda-remove-marked-text (property &optional value
)
2147 "Delete all text marked with VALUE of PROPERTY.
2148 VALUE defaults to t."
2150 (setq value
(or value t
))
2151 (while (setq beg
(text-property-any (point-min) (point-max)
2154 beg
(or (next-single-property-change beg
'org-filtered
)
2157 (defun org-agenda-add-entry-text ()
2158 "Add entry text to agenda lines.
2159 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2160 entry text following headings shown in the agenda.
2161 Drawers will be excluded, also the line with scheduling/deadline info."
2162 (when (> org-agenda-add-entry-text-maxlines
0)
2163 (let (m txt drawer-re kwd-time-re ind
)
2164 (goto-char (point-min))
2166 (if (not (setq m
(get-text-property (point) 'org-hd-marker
)))
2167 (beginning-of-line 2)
2169 (with-current-buffer (marker-buffer m
)
2170 (if (not (org-mode-p))
2176 (beginning-of-line 2)
2177 (setq txt
(buffer-substring
2179 (progn (outline-next-heading) (point)))
2180 drawer-re org-drawer-regexp
2181 kwd-time-re
(concat "^[ \t]*" org-keyword-time-regexp
2185 (when org-agenda-add-entry-text-descriptive-links
2186 (goto-char (point-min))
2187 (while (org-activate-bracket-links (point-max))
2188 (add-text-properties (match-beginning 0) (match-end 0)
2190 (goto-char (point-min))
2191 (while (re-search-forward org-bracket-link-regexp
(point-max) t
)
2192 (set-text-properties (match-beginning 0) (match-end 0)
2194 (goto-char (point-min))
2195 (while (re-search-forward drawer-re nil t
)
2198 (progn (re-search-forward
2199 "^[ \t]*:END:.*\n?" nil
'move
)
2201 (goto-char (point-min))
2202 (while (re-search-forward kwd-time-re nil t
)
2204 (if (re-search-forward "[ \t\n]+\\'" nil t
)
2206 (goto-char (point-min))
2207 ;; find min indentation
2208 (goto-char (point-min))
2209 (untabify (point-min) (point-max))
2210 (setq ind
(org-get-indentation))
2212 (unless (looking-at "[ \t]*$")
2213 (setq ind
(min ind
(org-get-indentation))))
2214 (beginning-of-line 2))
2215 (goto-char (point-min))
2217 (unless (looking-at "[ \t]*$")
2218 (move-to-column ind
)
2219 (delete-region (point-at-bol) (point)))
2220 (beginning-of-line 2))
2221 (goto-char (point-min))
2222 (while (and (not (eobp)) (re-search-forward "^" nil t
))
2223 (replace-match " > "))
2224 (goto-char (point-min))
2225 (while (looking-at "[ \t]*\n") (replace-match ""))
2226 (goto-char (point-max))
2227 (when (> (org-current-line)
2228 (1+ org-agenda-add-entry-text-maxlines
))
2229 (goto-line (1+ org-agenda-add-entry-text-maxlines
))
2231 (setq txt
(buffer-substring (point-min) (point)))))))))
2233 (if (string-match "\\S-" txt
) (insert "\n" txt
)))))))
2235 (defun org-agenda-collect-markers ()
2236 "Collect the markers pointing to entries in the agenda buffer."
2239 (goto-char (point-min))
2241 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
2242 (get-text-property (point) 'org-marker
)))
2244 (beginning-of-line 2)))
2245 (nreverse markers
)))
2247 (defun org-create-marker-find-array (marker-list)
2248 "Create a alist of files names with all marker positions in that file."
2250 (while (setq m
(pop marker-list
))
2251 (setq p
(marker-position m
)
2252 f
(buffer-file-name (or (buffer-base-buffer
2254 (marker-buffer m
))))
2255 (if (setq a
(assoc f tbl
))
2256 (push (marker-position m
) (cdr a
))
2257 (push (list f p
) tbl
)))
2258 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
2261 (defvar org-agenda-marker-table nil
) ; dynamically scoped parameter
2262 (defun org-check-agenda-marker-table ()
2263 "Check of the current entry is on the marker list."
2264 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2266 (and (setq a
(assoc file org-agenda-marker-table
))
2269 (org-back-to-heading t
)
2270 (member (point) (cdr a
)))))))
2272 (defun org-check-for-org-mode ()
2273 "Make sure current buffer is in org-mode. Error if not."
2275 (error "Cannot execute org-mode agenda command on buffer in %s."
2278 (defun org-fit-agenda-window ()
2279 "Fit the window to the buffer size."
2280 (and (memq org-agenda-window-setup
'(reorganize-frame))
2281 (fboundp 'fit-window-to-buffer
)
2282 (org-fit-window-to-buffer
2284 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
2285 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
2287 ;;; Agenda prepare and finalize
2289 (defvar org-agenda-multi nil
) ; dynamically scoped
2290 (defvar org-agenda-buffer-name
"*Org Agenda*")
2291 (defvar org-pre-agenda-window-conf nil
)
2292 (defvar org-agenda-columns-active nil
)
2293 (defvar org-agenda-name nil
)
2294 (defvar org-agenda-filter nil
)
2295 (defvar org-agenda-filter-preset nil
2296 "A preset of the tags filter used for secondary agenda filtering.
2297 This must be a list of strings, each string must be a single tag preceeded
2299 This variable should not be set directly, but agenda custom commands can
2300 bind it in the options section.")
2302 (defun org-prepare-agenda (&optional name
)
2303 (setq org-todo-keywords-for-agenda nil
)
2304 (setq org-done-keywords-for-agenda nil
)
2305 (setq org-agenda-filter nil
)
2306 (put 'org-agenda-filter
:preset-filter org-agenda-filter-preset
)
2307 (if org-agenda-multi
2309 (setq buffer-read-only nil
)
2310 (goto-char (point-max))
2311 (unless (or (bobp) org-agenda-compact-blocks
)
2313 (if (stringp org-agenda-block-separator
)
2314 org-agenda-block-separator
2315 (make-string (window-width) org-agenda-block-separator
))
2317 (narrow-to-region (point) (point-max)))
2318 (org-agenda-reset-markers)
2319 (setq org-agenda-contributing-files nil
)
2320 (setq org-agenda-columns-active nil
)
2321 (org-prepare-agenda-buffers (org-agenda-files nil
'ifmode
))
2322 (setq org-todo-keywords-for-agenda
2323 (org-uniquify org-todo-keywords-for-agenda
))
2324 (setq org-done-keywords-for-agenda
2325 (org-uniquify org-done-keywords-for-agenda
))
2326 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
2327 (awin (get-buffer-window abuf
)))
2329 ((equal (current-buffer) abuf
) nil
)
2330 (awin (select-window awin
))
2331 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
2332 ((equal org-agenda-window-setup
'current-window
)
2333 (switch-to-buffer abuf
))
2334 ((equal org-agenda-window-setup
'other-window
)
2335 (org-switch-to-buffer-other-window abuf
))
2336 ((equal org-agenda-window-setup
'other-frame
)
2337 (switch-to-buffer-other-frame abuf
))
2338 ((equal org-agenda-window-setup
'reorganize-frame
)
2339 (delete-other-windows)
2340 (org-switch-to-buffer-other-window abuf
))))
2341 (setq buffer-read-only nil
)
2342 (let ((inhibit-read-only t
)) (erase-buffer))
2344 (and name
(not org-agenda-name
)
2345 (org-set-local 'org-agenda-name name
)))
2346 (setq buffer-read-only nil
))
2348 (defun org-finalize-agenda ()
2349 "Finishing touch for the agenda buffer, called just before displaying it."
2350 (unless org-agenda-multi
2352 (let ((inhibit-read-only t
))
2353 (goto-char (point-min))
2354 (while (org-activate-bracket-links (point-max))
2355 (add-text-properties (match-beginning 0) (match-end 0)
2357 (org-agenda-align-tags)
2358 (unless org-agenda-with-colors
2359 (remove-text-properties (point-min) (point-max) '(face nil
))))
2360 (if (and (boundp 'org-agenda-overriding-columns-format
)
2361 org-agenda-overriding-columns-format
)
2362 (org-set-local 'org-agenda-overriding-columns-format
2363 org-agenda-overriding-columns-format
))
2364 (if (and (boundp 'org-agenda-view-columns-initially
)
2365 org-agenda-view-columns-initially
)
2366 (org-agenda-columns))
2367 (when org-agenda-fontify-priorities
2368 (org-agenda-fontify-priorities))
2369 (when (and org-agenda-dim-blocked-tasks org-blocker-hook
)
2370 (org-agenda-dim-blocked-tasks))
2371 (run-hooks 'org-finalize-agenda-hook
)
2372 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
2373 (when (get 'org-agenda-filter
:preset-filter
)
2374 (org-agenda-filter-apply org-agenda-filter
))
2377 (defun org-agenda-fontify-priorities ()
2378 "Make highest priority lines bold, and lowest italic."
2380 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
2381 (org-delete-overlay o
)))
2382 (org-overlays-in (point-min) (point-max)))
2384 (let ((inhibit-read-only t
)
2386 (goto-char (point-min))
2387 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
2388 (setq h
(or (get-char-property (point) 'org-highest-priority
)
2389 org-highest-priority
)
2390 l
(or (get-char-property (point) 'org-lowest-priority
)
2391 org-lowest-priority
)
2392 p
(string-to-char (match-string 1))
2393 b
(match-beginning 0)
2394 e
(if (eq org-agenda-fontify-priorities
'cookies
)
2397 ov
(org-make-overlay b e
))
2400 (cond ((cdr (assoc p org-priority-faces
)))
2401 ((and (listp org-agenda-fontify-priorities
)
2402 (cdr (assoc p org-agenda-fontify-priorities
))))
2403 ((equal p l
) 'italic
)
2404 ((equal p h
) 'bold
)))
2405 (org-overlay-put ov
'org-type
'org-priority
)))))
2407 (defun org-agenda-dim-blocked-tasks ()
2408 "Dim currently blocked TODO's in the agenda display."
2409 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-blocked-todo
)
2410 (org-delete-overlay o
)))
2411 (org-overlays-in (point-min) (point-max)))
2413 (let ((inhibit-read-only t
)
2414 (org-depend-tag-blocked nil
)
2415 (invis (eq org-agenda-dim-blocked-tasks
'invisible
))
2416 org-blocked-by-checkboxes
2417 invis1 b e p ov h l
)
2418 (goto-char (point-min))
2419 (while (let ((pos (next-single-property-change (point) 'todo-state
)))
2420 (and pos
(goto-char (1+ pos
))))
2421 (setq org-blocked-by-checkboxes nil invis1 invis
)
2422 (let ((marker (get-text-property (point) 'org-hd-marker
)))
2424 (not (with-current-buffer (marker-buffer marker
)
2427 (run-hook-with-args-until-failure
2429 (list :type
'todo-state-change
2433 (if org-blocked-by-checkboxes
(setq invis1 nil
))
2434 (setq b
(if invis1
(max (point-min) (1- (point))) (point))
2436 ov
(org-make-overlay b e
))
2438 (org-overlay-put ov
'invisible t
)
2439 (org-overlay-put ov
'face
'org-agenda-dimmed-todo-face
))
2440 (org-overlay-put ov
'org-type
'org-blocked-todo
)))))))
2442 (defvar org-agenda-skip-function nil
2443 "Function to be called at each match during agenda construction.
2444 If this function returns nil, the current match should not be skipped.
2445 Otherwise, the function must return a position from where the search
2446 should be continued.
2447 This may also be a Lisp form, it will be evaluated.
2448 Never set this variable using `setq' or so, because then it will apply
2449 to all future agenda commands. Instead, bind it with `let' to scope
2450 it dynamically into the agenda-constructing command. A good way to set
2451 it is through options in org-agenda-custom-commands.")
2453 (defun org-agenda-skip ()
2454 "Throw to `:skip' in places that should be skipped.
2455 Also moves point to the end of the skipped region, so that search can
2456 continue from there."
2457 (let ((p (point-at-bol)) to fp
)
2458 (and org-agenda-skip-archived-trees
(not org-agenda-archives-mode
)
2459 (get-text-property p
:org-archived
)
2460 (org-end-of-subtree t
)
2462 (and org-agenda-skip-comment-trees
2463 (get-text-property p
:org-comment
)
2464 (org-end-of-subtree t
)
2466 (if (equal (char-after p
) ?
#) (throw :skip t
))
2467 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
2468 (consp org-agenda-skip-function
))
2469 (setq to
(save-excursion
2472 (funcall org-agenda-skip-function
)
2473 (eval org-agenda-skip-function
))))))
2477 (defvar org-agenda-markers nil
2478 "List of all currently active markers created by `org-agenda'.")
2479 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
2480 "Creation time of the last agenda marker.")
2482 (defun org-agenda-new-marker (&optional pos
)
2483 "Return a new agenda marker.
2484 Org-mode keeps a list of these markers and resets them when they are
2486 (let ((m (copy-marker (or pos
(point)))))
2487 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
2488 (push m org-agenda-markers
)
2491 (defun org-agenda-reset-markers ()
2492 "Reset markers created by `org-agenda'."
2493 (while org-agenda-markers
2494 (move-marker (pop org-agenda-markers
) nil
)))
2496 (defun org-agenda-save-markers-for-cut-and-paste (beg end
)
2497 "Save relative positions of markers in region."
2498 (mapc (lambda (m) (org-check-and-save-marker m beg end
))
2499 org-agenda-markers
))
2503 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
2505 (defun org-timeline (&optional include-all
)
2506 "Show a time-sorted view of the entries in the current org file.
2507 Only entries with a time stamp of today or later will be listed. With
2508 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2509 under the current date.
2510 If the buffer contains an active region, only check the region for
2514 (org-compile-prefix-format 'timeline
)
2515 (org-set-sorting-strategy 'timeline
)
2517 (dotodo include-all
)
2518 (doclosed org-agenda-show-log
)
2519 (entry buffer-file-name
)
2520 (date (calendar-current-date))
2521 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2522 (end (if (org-region-active-p) (region-end) (point-max)))
2523 (day-numbers (org-get-all-dates beg end
'no-ranges
2524 t doclosed
; always include today
2525 org-timeline-show-empty-dates
))
2526 (org-deadline-warning-days 0)
2527 (org-agenda-only-exact-dates t
)
2528 (today (time-to-days (current-time)))
2531 s e rtn d emptyp wd
)
2532 (setq org-agenda-redo-command
2534 (list 'org-switch-to-buffer-other-window
(current-buffer))
2535 (list 'org-timeline
(list 'quote include-all
))))
2537 ;; Remove past dates from the list of dates.
2538 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2539 (if (>= x today
) x nil
))
2541 (org-prepare-agenda (concat "Timeline "
2542 (file-name-nondirectory buffer-file-name
)))
2543 (if doclosed
(push :closed args
))
2544 (push :timestamp args
)
2545 (push :deadline args
)
2546 (push :scheduled args
)
2548 (if dotodo
(push :todo args
))
2549 (while (setq d
(pop day-numbers
))
2550 (if (and (listp d
) (eq (car d
) :omitted
))
2553 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2554 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2555 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2556 (if (and (>= d today
)
2561 (insert (make-string 79 ?-
) "\n")))
2562 (setq date
(calendar-gregorian-from-absolute d
)
2563 wd
(calendar-day-of-week date
))
2565 (setq rtn
(and (not emptyp
)
2566 (apply 'org-agenda-get-day-entries entry
2568 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2571 (if (stringp org-agenda-format-date
)
2572 (format-time-string org-agenda-format-date
2573 (org-time-from-absolute date
))
2574 (funcall org-agenda-format-date date
))
2576 (put-text-property s
(1- (point)) 'face
2577 (if (member wd org-agenda-weekend-days
)
2578 'org-agenda-date-weekend
2580 (put-text-property s
(1- (point)) 'org-date-line t
)
2582 (put-text-property s
(1- (point)) 'org-today t
))
2583 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2584 (put-text-property s
(1- (point)) 'day d
)))))
2585 (goto-char (point-min))
2586 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2588 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2589 (org-finalize-agenda)
2590 (setq buffer-read-only t
)))
2592 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2593 "Return a list of all relevant day numbers from BEG to END buffer positions.
2594 If NO-RANGES is non-nil, include only the start and end dates of a range,
2595 not every single day in the range. If FORCE-TODAY is non-nil, make
2596 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2597 inactive time stamps (those in square brackets) are included.
2598 When EMPTY is non-nil, also include days without any entries."
2600 (if pre-re pre-re
"")
2601 (if inactive org-ts-regexp-both org-ts-regexp
)))
2602 dates dates1 date day day1 day2 ts1 ts2
)
2604 (setq dates
(list (time-to-days (current-time)))))
2607 (while (re-search-forward re end t
)
2608 (setq day
(time-to-days (org-time-string-to-time
2609 (substring (match-string 1) 0 10))))
2610 (or (memq day dates
) (push day dates
)))
2613 (while (re-search-forward org-tr-regexp end t
)
2614 (setq ts1
(substring (match-string 1) 0 10)
2615 ts2
(substring (match-string 2) 0 10)
2616 day1
(time-to-days (org-time-string-to-time ts1
))
2617 day2
(time-to-days (org-time-string-to-time ts2
)))
2618 (while (< (setq day1
(1+ day1
)) day2
)
2619 (or (memq day1 dates
) (push day1 dates
)))))
2620 (setq dates
(sort dates
'<))
2622 (while (setq day
(pop dates
))
2623 (setq day2
(car dates
))
2625 (when (and day2 empty
)
2626 (if (or (eq empty t
)
2627 (and (numberp empty
) (<= (- day2 day
) empty
)))
2628 (while (< (setq day
(1+ day
)) day2
)
2629 (push (list day
) dates1
))
2630 (push (cons :omitted
(- day2 day
)) dates1
))))
2631 (setq dates
(nreverse dates1
)))
2634 ;;; Agenda Daily/Weekly
2636 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2637 (defvar org-agenda-start-day nil
; dynamically scoped parameter
2638 "Custom commands can set this variable in the options section.")
2639 (defvar org-agenda-last-arguments nil
2640 "The arguments of the previous call to org-agenda")
2641 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2642 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2643 (defvar org-include-all-loc nil
) ; local variable
2644 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2647 (defun org-agenda-list (&optional include-all start-day ndays
)
2648 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2649 The view will be for the current day or week, but from the overview buffer
2650 you will be able to go to other days/weeks.
2652 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2653 all unfinished TODO items will also be shown, before the agenda.
2654 This feature is considered obsolete, please use the TODO list or a block
2657 With a numeric prefix argument in an interactive call, the agenda will
2658 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2659 the number of days. NDAYS defaults to `org-agenda-ndays'.
2661 START-DAY defaults to TODAY, or to the most recent match for the weekday
2662 given in `org-agenda-start-on-weekday'."
2664 (if (and (integerp include-all
) (> include-all
0))
2665 (setq ndays include-all include-all nil
))
2666 (setq ndays
(or ndays org-agenda-ndays
)
2667 start-day
(or start-day org-agenda-start-day
))
2668 (if org-agenda-overriding-arguments
2669 (setq include-all
(car org-agenda-overriding-arguments
)
2670 start-day
(nth 1 org-agenda-overriding-arguments
)
2671 ndays
(nth 2 org-agenda-overriding-arguments
)))
2672 (if (stringp start-day
)
2673 ;; Convert to an absolute day number
2674 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2675 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2676 (org-compile-prefix-format 'agenda
)
2677 (org-set-sorting-strategy 'agenda
)
2679 (let* ((org-agenda-start-on-weekday
2680 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2681 org-agenda-start-on-weekday nil
))
2682 (thefiles (org-agenda-files nil
'ifmode
))
2684 (today (time-to-days
2685 (time-subtract (current-time)
2686 (list 0 (* 3600 org-extend-today-until
) 0))))
2687 (sd (or start-day today
))
2688 (start (if (or (null org-agenda-start-on-weekday
)
2689 (< org-agenda-ndays
7))
2691 (let* ((nt (calendar-day-of-week
2692 (calendar-gregorian-from-absolute sd
)))
2693 (n1 org-agenda-start-on-weekday
)
2695 (- sd
(+ (if (< d
0) 7 0) d
)))))
2696 (day-numbers (list start
))
2698 (inhibit-redisplay (not debug-on-error
))
2699 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2700 clocktable-start clocktable-end
)
2701 (setq org-agenda-redo-command
2702 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2703 ;; Make the list of days
2704 (setq ndays
(or ndays org-agenda-ndays
)
2707 (push (1+ (car day-numbers
)) day-numbers
)
2708 (setq ndays
(1- ndays
)))
2709 (setq day-numbers
(nreverse day-numbers
))
2710 (setq clocktable-start
(car day-numbers
)
2711 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2712 (org-prepare-agenda "Day/Week")
2713 (org-set-local 'org-starting-day
(car day-numbers
))
2714 (org-set-local 'org-include-all-loc include-all
)
2715 (org-set-local 'org-agenda-span
2716 (org-agenda-ndays-to-span nd
))
2717 (when (and (or include-all org-agenda-include-all-todo
)
2718 (member today day-numbers
))
2719 (setq files thefiles
2721 (while (setq file
(pop files
))
2723 (org-check-agenda-file file
)
2724 (setq date
(calendar-gregorian-from-absolute today
)
2725 rtn
(org-agenda-get-day-entries
2727 (setq rtnall
(append rtnall rtn
))))
2729 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2730 (add-text-properties (point-min) (1- (point))
2731 (list 'face
'org-agenda-structure
))
2732 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2733 (unless org-agenda-compact-blocks
2734 (let* ((d1 (car day-numbers
))
2735 (d2 (org-last day-numbers
))
2736 (w1 (org-days-to-iso-week d1
))
2737 (w2 (org-days-to-iso-week d2
)))
2739 (if org-agenda-overriding-header
2740 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2741 nil
'face
'org-agenda-structure
) "\n")
2742 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2744 (if (< (- d2 d1
) 350)
2746 (format " (W%02d)" w1
)
2747 (format " (W%02d-W%02d)" w1 w2
))
2750 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2752 (while (setq d
(pop day-numbers
))
2753 (setq date
(calendar-gregorian-from-absolute d
)
2754 wd
(calendar-day-of-week date
)
2756 (if (or (setq todayp
(= d today
))
2757 (and (not start-pos
) (= d sd
)))
2758 (setq start-pos
(point))
2759 (if (and start-pos
(not end-pos
))
2760 (setq end-pos
(point))))
2761 (setq files thefiles
2763 (while (setq file
(pop files
))
2765 (org-check-agenda-file file
)
2767 ((eq org-agenda-show-log
'only
)
2768 (setq rtn
(org-agenda-get-day-entries
2769 file date
:closed
)))
2770 (org-agenda-show-log
2771 (setq rtn
(org-agenda-get-day-entries
2773 :deadline
:scheduled
:timestamp
:sexp
:closed
)))
2775 (setq rtn
(org-agenda-get-day-entries
2777 :deadline
:scheduled
:sexp
:timestamp
))))
2778 (setq rtnall
(append rtnall rtn
))))
2779 (if org-agenda-include-diary
2780 (let ((org-agenda-search-headline-for-time t
))
2781 (require 'diary-lib
)
2782 (setq rtn
(org-get-entries-from-diary date
))
2783 (setq rtnall
(append rtnall rtn
))))
2784 (if (or rtnall org-agenda-show-all-dates
)
2786 (setq day-cnt
(1+ day-cnt
))
2788 (if (stringp org-agenda-format-date
)
2789 (format-time-string org-agenda-format-date
2790 (org-time-from-absolute date
))
2791 (funcall org-agenda-format-date date
))
2793 (put-text-property s
(1- (point)) 'face
2794 (if (member wd org-agenda-weekend-days
)
2795 'org-agenda-date-weekend
2797 (put-text-property s
(1- (point)) 'org-date-line t
)
2798 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2799 (if todayp
(put-text-property s
(1- (point)) 'org-today t
))
2801 (org-finalize-agenda-entries
2802 (org-agenda-add-time-grid-maybe
2805 (put-text-property s
(1- (point)) 'day d
)
2806 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2807 (when (and org-agenda-clockreport-mode clocktable-start
)
2808 (let ((org-agenda-files (org-agenda-files nil
'ifmode
))
2809 ;; the above line is to ensure the restricted range!
2810 (p org-agenda-clockreport-parameter-plist
)
2812 (setq p
(org-plist-delete p
:block
))
2813 (setq p
(plist-put p
:tstart clocktable-start
))
2814 (setq p
(plist-put p
:tend clocktable-end
))
2815 (setq p
(plist-put p
:scope
'agenda
))
2816 (setq tbl
(apply 'org-get-clocktable p
))
2818 (goto-char (point-min))
2819 (or org-agenda-multi
(org-fit-agenda-window))
2820 (unless (and (pos-visible-in-window-p (point-min))
2821 (pos-visible-in-window-p (point-max)))
2822 (goto-char (1- (point-max)))
2824 (if (not (pos-visible-in-window-p (or start-pos
1)))
2826 (goto-char (or start-pos
1))
2828 (goto-char (or start-pos
1))
2829 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2830 (org-finalize-agenda)
2831 (setq buffer-read-only t
)
2834 (defun org-agenda-ndays-to-span (n)
2835 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2837 ;;; Agenda word search
2839 (defvar org-agenda-search-history nil
)
2840 (defvar org-todo-only nil
)
2842 (defvar org-search-syntax-table nil
2843 "Special syntax table for org-mode search.
2844 In this table, we have single quotes not as word constituents, to
2845 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
2847 (defun org-search-syntax-table ()
2848 (unless org-search-syntax-table
2849 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2850 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2851 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2852 org-search-syntax-table
)
2855 (defun org-search-view (&optional todo-only string edit-at
)
2856 "Show all entries that contain words or regular expressions.
2857 If the first character of the search string is an asterisks,
2858 search only the headlines.
2860 With optional prefix argument TODO-ONLY, only consider entries that are
2861 TODO entries. The argument STRING can be used to pass a default search
2862 string into this function. If EDIT-AT is non-nil, it means that the
2863 user should get a chance to edit this string, with cursor at position
2866 The search string is broken into \"words\" by splitting at whitespace.
2867 The individual words are then interpreted as a boolean expression with
2868 logical AND. Words prefixed with a minus must not occur in the entry.
2869 Words without a prefix or prefixed with a plus must occur in the entry.
2870 Matching is case-insensitive and the words are enclosed by word delimiters.
2872 Words enclosed by curly braces are interpreted as regular expressions
2873 that must or must not match in the entry.
2875 If the search string starts with an asterisk, search only in headlines.
2876 If (possibly after the leading star) the search string starts with an
2877 exclamation mark, this also means to look at TODO entries only, an effect
2878 that can also be achieved with a prefix argument.
2880 This command searches the agenda files, and in addition the files listed
2881 in `org-agenda-text-search-extra-files'."
2883 (org-compile-prefix-format 'search
)
2884 (org-set-sorting-strategy 'search
)
2885 (org-prepare-agenda "SEARCH")
2886 (let* ((props (list 'face nil
2887 'done-face
'org-agenda-done
2888 'org-not-done-regexp org-not-done-regexp
2889 'org-todo-regexp org-todo-regexp
2890 'org-complex-heading-regexp org-complex-heading-regexp
2891 'mouse-face
'highlight
2892 'keymap org-agenda-keymap
2893 'help-echo
(format "mouse-2 or RET jump to location")))
2894 regexp rtn rtnall files file pos
2895 marker category tags c neg re
2896 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2897 (unless (and (not edit-at
)
2899 (string-match "\\S-" string
))
2900 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2902 ((integerp edit-at
) (cons string edit-at
))
2904 'org-agenda-search-history
)))
2905 (org-set-local 'org-todo-only todo-only
)
2906 (setq org-agenda-redo-command
2907 (list 'org-search-view
(if todo-only t nil
) string
2908 '(if current-prefix-arg
1 nil
)))
2909 (setq org-agenda-query-string string
)
2911 (if (equal (string-to-char string
) ?
*)
2913 words
(substring string
1))
2914 (setq words string
))
2915 (when (equal (string-to-char words
) ?
!)
2917 words
(substring words
1)))
2918 (setq words
(org-split-string words
))
2920 (setq c
(string-to-char w
))
2922 (setq neg t w
(substring w
1))
2924 (setq neg nil w
(substring w
1))
2926 (if (string-match "\\`{.*}\\'" w
)
2927 (setq re
(substring w
1 -
1))
2928 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2929 (if neg
(push re regexps-
) (push re regexps
+)))
2931 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2933 (setq regexp
(concat "^" org-outline-regexp
))
2934 (setq regexp
(pop regexps
+))
2935 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2937 (setq files
(org-agenda-files nil
'ifmode
))
2938 (when (eq (car org-agenda-text-search-extra-files
) 'agenda-archives
)
2939 (pop org-agenda-text-search-extra-files
)
2940 (setq files
(org-add-archive-files files
)))
2941 (setq files
(append files org-agenda-text-search-extra-files
)
2943 (while (setq file
(pop files
))
2946 (org-check-agenda-file file
)
2947 (setq buffer
(if (file-exists-p file
)
2948 (org-get-agenda-file-buffer file
)
2949 (error "No such file %s" file
)))
2951 ;; If file does not exist, make sure an error message is sent
2952 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2954 (with-current-buffer buffer
2955 (with-syntax-table (org-search-syntax-table)
2956 (unless (org-mode-p)
2957 (error "Agenda file %s is not in `org-mode'" file
))
2958 (let ((case-fold-search t
))
2961 (if org-agenda-restrict
2962 (narrow-to-region org-agenda-restrict-begin
2963 org-agenda-restrict-end
)
2965 (goto-char (point-min))
2966 (unless (or (org-on-heading-p)
2967 (outline-next-heading))
2968 (throw 'nextfile t
))
2969 (goto-char (max (point-min) (1- (point))))
2970 (while (re-search-forward regexp nil t
)
2971 (org-back-to-heading t
)
2972 (skip-chars-forward "* ")
2973 (setq beg
(point-at-bol)
2975 end
(progn (outline-next-heading) (point)))
2979 (setq str
(buffer-substring-no-properties
2981 (if hdl-only
(point-at-eol) end
)))
2982 (mapc (lambda (wr) (when (string-match wr str
)
2983 (goto-char (1- end
))
2986 (mapc (lambda (wr) (unless (string-match wr str
)
2987 (goto-char (1- end
))
2990 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
2994 (setq marker
(org-agenda-new-marker (point))
2995 category
(org-get-category)
2996 tags
(org-get-tags-at (point))
2997 txt
(org-format-agenda-item
2999 (buffer-substring-no-properties
3000 beg1
(point-at-eol))
3002 (org-add-props txt props
3003 'org-marker marker
'org-hd-marker marker
3004 'org-todo-regexp org-todo-regexp
3005 'org-complex-heading-regexp org-complex-heading-regexp
3006 'priority
1000 'org-category category
3009 (goto-char (1- end
))))))))))
3010 (setq rtn
(nreverse ee
))
3011 (setq rtnall
(append rtnall rtn
)))
3012 (if org-agenda-overriding-header
3013 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3014 nil
'face
'org-agenda-structure
) "\n")
3015 (insert "Search words: ")
3016 (add-text-properties (point-min) (1- (point))
3017 (list 'face
'org-agenda-structure
))
3019 (insert string
"\n")
3020 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3022 (unless org-agenda-multi
3023 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3024 (add-text-properties pos
(1- (point))
3025 (list 'face
'org-agenda-structure
))))
3027 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3028 (goto-char (point-min))
3029 (or org-agenda-multi
(org-fit-agenda-window))
3030 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
3031 (org-finalize-agenda)
3032 (setq buffer-read-only t
)))
3034 ;;; Agenda TODO list
3036 (defvar org-select-this-todo-keyword nil
)
3037 (defvar org-last-arg nil
)
3040 (defun org-todo-list (arg)
3041 "Show all TODO entries from all agenda file in a single list.
3042 The prefix arg can be used to select a specific TODO keyword and limit
3043 the list to these. When using \\[universal-argument], you will be prompted
3044 for a keyword. A numeric prefix directly selects the Nth keyword in
3045 `org-todo-keywords-1'."
3048 (org-compile-prefix-format 'todo
)
3049 (org-set-sorting-strategy 'todo
)
3050 (org-prepare-agenda "TODO")
3051 (let* ((today (time-to-days (current-time)))
3052 (date (calendar-gregorian-from-absolute today
))
3053 (kwds org-todo-keywords-for-agenda
)
3054 (completion-ignore-case t
)
3055 (org-select-this-todo-keyword
3056 (if (stringp arg
) arg
3057 (and arg
(integerp arg
) (> arg
0)
3058 (nth (1- arg
) kwds
))))
3059 rtn rtnall files file pos
)
3060 (when (equal arg
'(4))
3061 (setq org-select-this-todo-keyword
3062 (org-ido-completing-read "Keyword (or KWD1|K2D2|...): "
3063 (mapcar 'list kwds
) nil nil
)))
3064 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
3065 (org-set-local 'org-last-arg arg
)
3066 (setq org-agenda-redo-command
3067 '(org-todo-list (or current-prefix-arg org-last-arg
)))
3068 (setq files
(org-agenda-files nil
'ifmode
)
3070 (while (setq file
(pop files
))
3072 (org-check-agenda-file file
)
3073 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
3074 (setq rtnall
(append rtnall rtn
))))
3075 (if org-agenda-overriding-header
3076 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3077 nil
'face
'org-agenda-structure
) "\n")
3078 (insert "Global list of TODO items of type: ")
3079 (add-text-properties (point-min) (1- (point))
3080 (list 'face
'org-agenda-structure
))
3082 (insert (or org-select-this-todo-keyword
"ALL") "\n")
3083 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3085 (unless org-agenda-multi
3086 (insert "Available with `N r': (0)ALL")
3089 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
3090 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
3095 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3097 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3098 (goto-char (point-min))
3099 (or org-agenda-multi
(org-fit-agenda-window))
3100 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
3101 (org-finalize-agenda)
3102 (setq buffer-read-only t
)))
3104 ;;; Agenda tags match
3107 (defun org-tags-view (&optional todo-only match
)
3108 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3109 The prefix arg TODO-ONLY limits the search to TODO entries."
3111 (org-compile-prefix-format 'tags
)
3112 (org-set-sorting-strategy 'tags
)
3113 (let* ((org-tags-match-list-sublevels
3114 (if todo-only t org-tags-match-list-sublevels
))
3115 (completion-ignore-case t
)
3116 rtn rtnall files file pos matcher
3118 (setq matcher
(org-make-tags-matcher match
)
3119 match
(car matcher
) matcher
(cdr matcher
))
3120 (org-prepare-agenda (concat "TAGS " match
))
3121 (setq org-agenda-query-string match
)
3122 (setq org-agenda-redo-command
3123 (list 'org-tags-view
(list 'quote todo-only
)
3124 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
3125 (setq files
(org-agenda-files nil
'ifmode
)
3127 (while (setq file
(pop files
))
3129 (org-check-agenda-file file
)
3130 (setq buffer
(if (file-exists-p file
)
3131 (org-get-agenda-file-buffer file
)
3132 (error "No such file %s" file
)))
3134 ;; If file does not exist, error message to agenda
3136 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3137 rtnall
(append rtnall rtn
))
3138 (with-current-buffer buffer
3139 (unless (org-mode-p)
3140 (error "Agenda file %s is not in `org-mode'" file
))
3143 (if org-agenda-restrict
3144 (narrow-to-region org-agenda-restrict-begin
3145 org-agenda-restrict-end
)
3147 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
3148 (setq rtnall
(append rtnall rtn
))))))))
3149 (if org-agenda-overriding-header
3150 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3151 nil
'face
'org-agenda-structure
) "\n")
3152 (insert "Headlines with TAGS match: ")
3153 (add-text-properties (point-min) (1- (point))
3154 (list 'face
'org-agenda-structure
))
3157 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3159 (unless org-agenda-multi
3160 (insert "Press `C-u r' to search again with new search string\n"))
3161 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3163 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3164 (goto-char (point-min))
3165 (or org-agenda-multi
(org-fit-agenda-window))
3166 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
3167 (org-finalize-agenda)
3168 (setq buffer-read-only t
)))
3170 ;;; Agenda Finding stuck projects
3172 (defvar org-agenda-skip-regexp nil
3173 "Regular expression used in skipping subtrees for the agenda.
3174 This is basically a temporary global variable that can be set and then
3175 used by user-defined selections using `org-agenda-skip-function'.")
3177 (defvar org-agenda-overriding-header nil
3178 "When this is set during todo and tags searches, will replace header.
3179 This variable should not be set directly, but custom commands can bind it
3180 in the options section.")
3182 (defun org-agenda-skip-entry-when-regexp-matches ()
3183 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3184 If yes, it returns the end position of this entry, causing agenda commands
3185 to skip the entry but continuing the search in the subtree. This is a
3186 function that can be put into `org-agenda-skip-function' for the duration
3188 (let ((end (save-excursion (org-end-of-subtree t
)))
3191 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3194 (defun org-agenda-skip-subtree-when-regexp-matches ()
3195 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3196 If yes, it returns the end position of this tree, causing agenda commands
3197 to skip this subtree. This is a function that can be put into
3198 `org-agenda-skip-function' for the duration of a command."
3199 (let ((end (save-excursion (org-end-of-subtree t
)))
3202 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3205 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3206 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3207 If yes, it returns the end position of the current entry (NOT the tree),
3208 causing agenda commands to skip the entry but continuing the search in
3209 the subtree. This is a function that can be put into
3210 `org-agenda-skip-function' for the duration of a command. An important
3211 use of this function is for the stuck project list."
3212 (let ((end (save-excursion (org-end-of-subtree t
)))
3213 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3216 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3217 (and skip entry-end
)))
3219 (defun org-agenda-skip-entry-if (&rest conditions
)
3220 "Skip entry if any of CONDITIONS is true.
3221 See `org-agenda-skip-if' for details."
3222 (org-agenda-skip-if nil conditions
))
3224 (defun org-agenda-skip-subtree-if (&rest conditions
)
3225 "Skip entry if any of CONDITIONS is true.
3226 See `org-agenda-skip-if' for details."
3227 (org-agenda-skip-if t conditions
))
3229 (defun org-agenda-skip-if (subtree conditions
)
3230 "Checks current entity for CONDITIONS.
3231 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3232 the entry, i.e. the text before the next heading is checked.
3234 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3235 from different tests. Valid conditions are:
3237 scheduled Check if there is a scheduled cookie
3238 notscheduled Check if there is no scheduled cookie
3239 deadline Check if there is a deadline
3240 notdeadline Check if there is no deadline
3241 timestamp Check if there is a timestamp (also deadline or scheduled)
3242 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3243 regexp Check if regexp matches
3244 notregexp Check if regexp does not match.
3246 The regexp is taken from the conditions list, it must come right after
3247 the `regexp' or `notregexp' element.
3249 If any of these conditions is met, this function returns the end point of
3250 the entity, causing the search to continue from there. This is a function
3251 that can be put into `org-agenda-skip-function' for the duration of a command."
3253 (org-back-to-heading t
)
3256 (progn (org-end-of-subtree t
) (point))
3257 (progn (outline-next-heading) (1- (point)))))
3261 (and (memq 'scheduled conditions
)
3262 (re-search-forward org-scheduled-time-regexp end t
))
3263 (and (memq 'notscheduled conditions
)
3264 (not (re-search-forward org-scheduled-time-regexp end t
)))
3265 (and (memq 'deadline conditions
)
3266 (re-search-forward org-deadline-time-regexp end t
))
3267 (and (memq 'notdeadline conditions
)
3268 (not (re-search-forward org-deadline-time-regexp end t
)))
3269 (and (memq 'timestamp conditions
)
3270 (re-search-forward org-ts-regexp end t
))
3271 (and (memq 'nottimestamp conditions
)
3272 (not (re-search-forward org-ts-regexp end t
)))
3273 (and (setq m
(memq 'regexp conditions
))
3275 (re-search-forward (nth 1 m
) end t
))
3276 (and (setq m
(memq 'notregexp conditions
))
3278 (not (re-search-forward (nth 1 m
) end t
))))
3282 (defun org-agenda-list-stuck-projects (&rest ignore
)
3283 "Create agenda view for projects that are stuck.
3284 Stuck projects are project that have no next actions. For the definitions
3285 of what a project is and how to check if it stuck, customize the variable
3286 `org-stuck-projects'.
3287 MATCH is being ignored."
3289 (let* ((org-agenda-skip-function
3290 'org-agenda-skip-entry-when-regexp-matches-in-subtree
)
3291 ;; We could have used org-agenda-skip-if here.
3292 (org-agenda-overriding-header "List of stuck projects: ")
3293 (matcher (nth 0 org-stuck-projects
))
3294 (todo (nth 1 org-stuck-projects
))
3295 (todo-wds (if (member "*" todo
)
3297 (org-prepare-agenda-buffers (org-agenda-files
3300 org-done-keywords-for-agenda
3301 (copy-sequence org-todo-keywords-for-agenda
)))
3303 (todo-re (concat "^\\*+[ \t]+\\("
3304 (mapconcat 'identity todo-wds
"\\|")
3306 (tags (nth 2 org-stuck-projects
))
3307 (tags-re (if (member "*" tags
)
3308 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3310 (concat "^\\*+ .*:\\("
3311 (mapconcat 'identity tags
"\\|")
3312 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3313 (gen-re (nth 3 org-stuck-projects
))
3319 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
3321 (setq org-agenda-skip-regexp
3323 (mapconcat 'identity re-list
"\\|")
3324 (error "No information how to identify unstuck projects")))
3325 (org-tags-view nil matcher
)
3326 (with-current-buffer org-agenda-buffer-name
3327 (setq org-agenda-redo-command
3328 '(org-agenda-list-stuck-projects
3329 (or current-prefix-arg org-last-arg
))))))
3331 ;;; Diary integration
3333 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
3334 (defvar list-diary-entries-hook
)
3336 (defun org-get-entries-from-diary (date)
3337 "Get the (Emacs Calendar) diary entries for DATE."
3338 (require 'diary-lib
)
3339 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3340 (fancy-diary-buffer diary-fancy-buffer
)
3341 (diary-display-hook '(fancy-diary-display))
3342 (diary-display-function 'fancy-diary-display
)
3344 (list-diary-entries-hook
3345 (cons 'org-diary-default-entry list-diary-entries-hook
))
3346 (diary-file-name-prefix-function nil
) ; turn this feature off
3347 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
3349 (org-disable-agenda-to-diary t
))
3351 (save-window-excursion
3352 (funcall (if (fboundp 'diary-list-entries
)
3353 'diary-list-entries
'list-diary-entries
)
3355 (if (not (get-buffer diary-fancy-buffer
))
3357 (with-current-buffer diary-fancy-buffer
3358 (setq buffer-read-only nil
)
3359 (if (zerop (buffer-size))
3362 ;; Omit the date and other unnecessary stuff
3363 (org-agenda-cleanup-fancy-diary)
3364 ;; Add prefix to each line and extend the text properties
3365 (if (zerop (buffer-size))
3367 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
3368 (set-buffer-modified-p nil
)
3369 (kill-buffer diary-fancy-buffer
)))
3371 (setq entries
(org-split-string entries
"\n"))
3375 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
3376 ;; Extend the text properties to the beginning of the line
3377 (org-add-props x
(text-properties-at (1- (length x
)) x
)
3378 'type
"diary" 'date date
))
3381 (defvar org-agenda-cleanup-fancy-diary-hook nil
3382 "Hook run when the fancy diary buffer is cleaned up.")
3384 (defun org-agenda-cleanup-fancy-diary ()
3385 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3386 This gets rid of the date, the underline under the date, and
3387 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3388 date. It also removes lines that contain only whitespace."
3389 (goto-char (point-min))
3390 (if (looking-at ".*?:[ \t]*")
3393 (re-search-forward "\n=+$" nil t
)
3395 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
3396 (re-search-forward "\n=+$" nil t
)
3397 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3398 (goto-char (point-min))
3399 (while (re-search-forward "^ +\n" nil t
)
3401 (goto-char (point-min))
3402 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
3404 (run-hooks 'org-agenda-cleanup-fancy-diary-hook
))
3406 ;; Make sure entries from the diary have the right text properties.
3407 (eval-after-load "diary-lib"
3408 '(if (boundp 'diary-modify-entry-list-string-function
)
3409 ;; We can rely on the hook, nothing to do
3411 ;; Hook not available, must use advice to make this work
3412 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
3413 "Make the position visible."
3414 (if (and org-disable-agenda-to-diary
;; called from org-agenda
3417 (setq string
(org-modify-diary-entry-string string
))))))
3419 (defun org-modify-diary-entry-string (string)
3420 "Add text properties to string, allowing org-mode to act on it."
3421 (org-add-props string nil
3422 'mouse-face
'highlight
3423 'keymap org-agenda-keymap
3424 'help-echo
(if buffer-file-name
3425 (format "mouse-2 or RET jump to diary file %s"
3426 (abbreviate-file-name buffer-file-name
))
3428 'org-agenda-diary-link t
3429 'org-marker
(org-agenda-new-marker (point-at-bol))))
3431 (defun org-diary-default-entry ()
3432 "Add a dummy entry to the diary.
3433 Needed to avoid empty dates which mess up holiday display."
3434 ;; Catch the error if dealing with the new add-to-diary-alist
3435 (when org-disable-agenda-to-diary
3437 (org-add-to-diary-list original-date
"Org-mode dummy" "")
3439 (org-add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
3441 (defun org-add-to-diary-list (&rest args
)
3442 (if (fboundp 'diary-add-to-list
)
3443 (apply 'diary-add-to-list args
)
3444 (apply 'add-to-diary-list args
)))
3447 (defun org-diary (&rest args
)
3448 "Return diary information from org-files.
3449 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3450 It accesses org files and extracts information from those files to be
3451 listed in the diary. The function accepts arguments specifying what
3452 items should be listed. The following arguments are allowed:
3454 :timestamp List the headlines of items containing a date stamp or
3455 date range matching the selected date. Deadlines will
3456 also be listed, on the expiration day.
3458 :sexp List entries resulting from diary-like sexps.
3460 :deadline List any deadlines past due, or due within
3461 `org-deadline-warning-days'. The listing occurs only
3462 in the diary for *today*, not at any other date. If
3463 an entry is marked DONE, it is no longer listed.
3465 :scheduled List all items which are scheduled for the given date.
3466 The diary for *today* also contains items which were
3467 scheduled earlier and are not yet marked DONE.
3469 :todo List all TODO items from the org-file. This may be a
3470 long list - so this is not turned on by default.
3471 Like deadlines, these entries only show up in the
3472 diary for *today*, not at any other date.
3474 The call in the diary file should look like this:
3476 &%%(org-diary) ~/path/to/some/orgfile.org
3478 Use a separate line for each org file to check. Or, if you omit the file name,
3479 all files listed in `org-agenda-files' will be checked automatically:
3483 If you don't give any arguments (as in the example above), the default
3484 arguments (:deadline :scheduled :timestamp :sexp) are used.
3485 So the example above may also be written as
3487 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3489 The function expects the lisp variables `entry' and `date' to be provided
3490 by the caller, because this is how the calendar works. Don't use this
3491 function from a program - use `org-agenda-get-day-entries' instead."
3492 (when (> (- (time-to-seconds (current-time))
3493 org-agenda-last-marker-time
)
3495 (org-agenda-reset-markers))
3496 (org-compile-prefix-format 'agenda
)
3497 (org-set-sorting-strategy 'agenda
)
3498 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3499 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
3501 (org-agenda-files t
)))
3503 (org-prepare-agenda-buffers files
)
3504 ;; If this is called during org-agenda, don't return any entries to
3505 ;; the calendar. Org Agenda will list these entries itself.
3506 (if org-disable-agenda-to-diary
(setq files nil
))
3507 (while (setq file
(pop files
))
3508 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
3509 (setq results
(append results rtn
)))
3511 (concat (org-finalize-agenda-entries results
) "\n"))))
3513 ;;; Agenda entry finders
3515 (defun org-agenda-get-day-entries (file date
&rest args
)
3516 "Does the work for `org-diary' and `org-agenda'.
3517 FILE is the path to a file to be checked for entries. DATE is date like
3518 the one returned by `calendar-current-date'. ARGS are symbols indicating
3519 which kind of entries should be extracted. For details about these, see
3520 the documentation of `org-diary'."
3521 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3522 (let* ((org-startup-folded nil
)
3523 (org-startup-align-all-tables nil
)
3524 (buffer (if (file-exists-p file
)
3525 (org-get-agenda-file-buffer file
)
3526 (error "No such file %s" file
)))
3529 ;; If file does not exist, make sure an error message ends up in diary
3530 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3531 (with-current-buffer buffer
3532 (unless (org-mode-p)
3533 (error "Agenda file %s is not in `org-mode'" file
))
3534 (let ((case-fold-search nil
))
3537 (if org-agenda-restrict
3538 (narrow-to-region org-agenda-restrict-begin
3539 org-agenda-restrict-end
)
3541 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3542 (while (setq arg
(pop args
))
3544 ((and (eq arg
:todo
)
3545 (equal date
(calendar-current-date)))
3546 (setq rtn
(org-agenda-get-todos))
3547 (setq results
(append results rtn
)))
3548 ((eq arg
:timestamp
)
3549 (setq rtn
(org-agenda-get-blocks))
3550 (setq results
(append results rtn
))
3551 (setq rtn
(org-agenda-get-timestamps))
3552 (setq results
(append results rtn
)))
3554 (setq rtn
(org-agenda-get-sexps))
3555 (setq results
(append results rtn
)))
3556 ((eq arg
:scheduled
)
3557 (setq rtn
(org-agenda-get-scheduled))
3558 (setq results
(append results rtn
)))
3560 (setq rtn
(org-agenda-get-progress))
3561 (setq results
(append results rtn
)))
3563 (setq rtn
(org-agenda-get-deadlines))
3564 (setq results
(append results rtn
))))))))
3567 (defun org-agenda-get-todos ()
3568 "Return the TODO information for agenda display."
3569 (let* ((props (list 'face nil
3570 'done-face
'org-agenda-done
3571 'org-not-done-regexp org-not-done-regexp
3572 'org-todo-regexp org-todo-regexp
3573 'org-complex-heading-regexp org-complex-heading-regexp
3574 'mouse-face
'highlight
3575 'keymap org-agenda-keymap
3577 (format "mouse-2 or RET jump to org file %s"
3578 (abbreviate-file-name buffer-file-name
))))
3579 (regexp (concat "^\\*+[ \t]+\\("
3580 (if org-select-this-todo-keyword
3581 (if (equal org-select-this-todo-keyword
"*")
3584 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3586 org-not-done-regexp
)
3588 marker priority category tags todo-state
3590 (goto-char (point-min))
3591 (while (re-search-forward regexp nil t
)
3595 (setq beg
(point) end
(save-excursion (outline-next-heading) (point)))
3596 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end
)
3597 (goto-char (1+ beg
))
3598 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3602 (goto-char (match-beginning 1))
3603 (setq marker
(org-agenda-new-marker (match-beginning 0))
3604 category
(org-get-category)
3605 txt
(match-string 1)
3606 tags
(org-get-tags-at (point))
3607 txt
(org-format-agenda-item "" txt category tags
)
3608 priority
(1+ (org-get-priority txt
))
3609 todo-state
(org-get-todo-state))
3610 (org-add-props txt props
3611 'org-marker marker
'org-hd-marker marker
3612 'priority priority
'org-category category
3613 'type
"todo" 'todo-state todo-state
)
3615 (if org-agenda-todo-list-sublevels
3616 (goto-char (match-end 1))
3617 (org-end-of-subtree 'invisible
))))
3621 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end
)
3622 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3623 (when (or org-agenda-todo-ignore-with-date
3624 org-agenda-todo-ignore-scheduled
3625 org-agenda-todo-ignore-deadlines
)
3626 (setq end
(or end
(save-excursion (outline-next-heading) (point))))
3628 (or (and org-agenda-todo-ignore-with-date
3629 (re-search-forward org-ts-regexp end t
))
3630 (and org-agenda-todo-ignore-scheduled
3631 (re-search-forward org-scheduled-time-regexp end t
))
3632 (and org-agenda-todo-ignore-deadlines
3633 (re-search-forward org-deadline-time-regexp end t
)
3634 (org-deadline-close (match-string 1)))))))
3636 (defconst org-agenda-no-heading-message
3637 "No heading for this item in buffer or region.")
3639 (defun org-agenda-get-timestamps ()
3640 "Return the date stamp information for agenda display."
3641 (let* ((props (list 'face nil
3642 'org-not-done-regexp org-not-done-regexp
3643 'org-todo-regexp org-todo-regexp
3644 'org-complex-heading-regexp org-complex-heading-regexp
3645 'mouse-face
'highlight
3646 'keymap org-agenda-keymap
3648 (format "mouse-2 or RET jump to org file %s"
3649 (abbreviate-file-name buffer-file-name
))))
3650 (d1 (calendar-absolute-from-gregorian date
))
3656 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3660 (if org-agenda-include-inactive-timestamps
"[[<]" "<")
3664 (car org-time-stamp-formats
)
3665 (apply 'encode-time
; DATE bound by calendar
3666 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3668 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3669 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3670 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3671 donep tmp priority category ee txt timestr tags b0 b3 e3 head
3673 (goto-char (point-min))
3674 (while (re-search-forward regexp nil t
)
3675 (setq b0
(match-beginning 0)
3676 b3
(match-beginning 3) e3
(match-end 3))
3678 (and (org-at-date-range-p) (throw :skip nil
))
3680 (if (and (match-end 1)
3681 (not (= d1
(org-time-string-to-absolute
3682 (match-string 1) d1 nil
3683 org-agenda-repeating-timestamp-show-all
))))
3686 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3688 (setq marker
(org-agenda-new-marker b0
)
3689 category
(org-get-category b0
)
3690 tmp
(buffer-substring (max (point-min)
3691 (- b0 org-ds-keyword-length
))
3693 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3694 inactivep
(= (char-after b0
) ?\
[)
3695 deadlinep
(string-match org-deadline-regexp tmp
)
3696 scheduledp
(string-match org-scheduled-regexp tmp
)
3697 closedp
(and org-agenda-include-inactive-timestamps
3698 (string-match org-closed-string tmp
))
3699 clockp
(and org-agenda-include-inactive-timestamps
3700 (or (string-match org-clock-string tmp
)
3701 (string-match "]-+\\'" tmp
)))
3702 todo-state
(org-get-todo-state)
3703 donep
(member todo-state org-done-keywords
))
3704 (if (or scheduledp deadlinep closedp clockp
)
3706 (if (string-match ">" timestr
)
3707 ;; substring should only run to end of time stamp
3708 (setq timestr
(substring timestr
0 (match-end 0))))
3710 (if (re-search-backward "^\\*+ " nil t
)
3712 (goto-char (match-beginning 0))
3713 (setq hdmarker
(org-agenda-new-marker)
3714 tags
(org-get-tags-at))
3715 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3716 (setq head
(match-string 1))
3717 (and org-agenda-skip-timestamp-if-done donep
(throw :skip t
))
3718 (setq txt
(org-format-agenda-item
3719 (if inactivep
"[" nil
)
3720 head category tags timestr nil
3722 (setq txt org-agenda-no-heading-message
))
3723 (setq priority
(org-get-priority txt
))
3724 (org-add-props txt props
3725 'org-marker marker
'org-hd-marker hdmarker
)
3726 (org-add-props txt nil
'priority priority
3727 'org-category category
'date date
3728 'todo-state todo-state
3731 (outline-next-heading)))
3734 (defun org-agenda-get-sexps ()
3735 "Return the sexp information for agenda display."
3736 (require 'diary-lib
)
3737 (let* ((props (list 'face nil
3738 'mouse-face
'highlight
3739 'keymap org-agenda-keymap
3741 (format "mouse-2 or RET jump to org file %s"
3742 (abbreviate-file-name buffer-file-name
))))
3744 marker category ee txt tags entry result beg b sexp sexp-entry
3746 (goto-char (point-min))
3747 (while (re-search-forward regexp nil t
)
3750 (setq beg
(match-beginning 0))
3751 (goto-char (1- (match-end 0)))
3754 (setq sexp
(buffer-substring b
(point)))
3755 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3756 (org-trim (match-string 1))
3758 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3760 (setq marker
(org-agenda-new-marker beg
)
3761 category
(org-get-category beg
)
3762 todo-state
(org-get-todo-state))
3764 (if (string-match "\\S-" result
)
3766 (setq txt
"SEXP entry returned empty string"))
3768 (setq txt
(org-format-agenda-item
3769 "" txt category tags
'time
))
3770 (org-add-props txt props
'org-marker marker
)
3771 (org-add-props txt nil
3772 'org-category category
'date date
'todo-state todo-state
3777 (defalias 'org-get-closed
'org-agenda-get-progress
)
3778 (defun org-agenda-get-progress ()
3779 "Return the logged TODO entries for agenda display."
3780 (let* ((props (list 'mouse-face
'highlight
3781 'org-not-done-regexp org-not-done-regexp
3782 'org-todo-regexp org-todo-regexp
3783 'org-complex-heading-regexp org-complex-heading-regexp
3784 'keymap org-agenda-keymap
3786 (format "mouse-2 or RET jump to org file %s"
3787 (abbreviate-file-name buffer-file-name
))))
3788 (items (if (consp org-agenda-show-log
)
3790 org-agenda-log-mode-items
))
3794 (if (memq 'closed items
) (concat "\\<" org-closed-string
))
3795 (if (memq 'clock items
) (concat "\\<" org-clock-string
))
3796 (if (memq 'state items
) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
3797 (parts-re (if parts
(mapconcat 'identity parts
"\\|")
3798 (error "`org-agenda-log-mode-items' is empty")))
3800 "\\(" parts-re
"\\)"
3805 (car org-time-stamp-formats
)
3806 (apply 'encode-time
; DATE bound by calendar
3807 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3809 marker hdmarker priority category tags closedp statep clockp state
3810 ee txt extra timestr rest clocked
)
3811 (goto-char (point-min))
3812 (while (re-search-forward regexp nil t
)
3815 (setq marker
(org-agenda-new-marker (match-beginning 0))
3816 closedp
(equal (match-string 1) org-closed-string
)
3817 statep
(equal (string-to-char (match-string 1)) ?-
)
3818 clockp
(not (or closedp statep
))
3819 state
(and statep
(match-string 2))
3820 category
(org-get-category (match-beginning 0))
3821 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3822 ;; donep (org-entry-is-done-p)
3824 (when (string-match "\\]" timestr
)
3825 ;; substring should only run to end of time stamp
3826 (setq rest
(substring timestr
(match-end 0))
3827 timestr
(substring timestr
0 (match-end 0)))
3828 (if (and (not closedp
) (not statep
)
3829 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest
))
3830 (progn (setq timestr
(concat (substring timestr
0 -
1)
3831 "-" (match-string 1 rest
) "]"))
3832 (setq clocked
(match-string 2 rest
)))
3833 (setq clocked
"-")))
3836 ((not org-agenda-log-mode-add-notes
) (setq extra nil
))
3838 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
3839 (setq extra
(match-string 1))))
3841 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
3842 (setq extra
(match-string 1))))
3843 (t (setq extra nil
)))
3844 (if (re-search-backward "^\\*+ " nil t
)
3846 (goto-char (match-beginning 0))
3847 (setq hdmarker
(org-agenda-new-marker)
3848 tags
(org-get-tags-at))
3849 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3850 (setq txt
(match-string 1))
3852 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt
)
3853 (setq txt
(concat (substring txt
0 (match-beginning 1))
3854 " - " extra
" " (match-string 2 txt
)))
3855 (setq txt
(concat txt
" - " extra
))))
3856 (setq txt
(org-format-agenda-item
3858 (closedp "Closed: ")
3859 (statep (concat "State: (" state
")"))
3860 (t (concat "Clocked: (" clocked
")")))
3861 txt category tags timestr
)))
3862 (setq txt org-agenda-no-heading-message
))
3863 (setq priority
100000)
3864 (org-add-props txt props
3865 'org-marker marker
'org-hd-marker hdmarker
'face
'org-agenda-done
3866 'priority priority
'org-category category
3867 'type
"closed" 'date date
3868 'undone-face
'org-warning
'done-face
'org-agenda-done
)
3870 (goto-char (point-at-eol))))
3873 (defun org-agenda-get-deadlines ()
3874 "Return the deadline information for agenda display."
3875 (let* ((props (list 'mouse-face
'highlight
3876 'org-not-done-regexp org-not-done-regexp
3877 'org-todo-regexp org-todo-regexp
3878 'org-complex-heading-regexp org-complex-heading-regexp
3879 'keymap org-agenda-keymap
3881 (format "mouse-2 or RET jump to org file %s"
3882 (abbreviate-file-name buffer-file-name
))))
3883 (regexp org-deadline-time-regexp
)
3884 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3885 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3886 d2 diff dfrac wdays pos pos1 category tags
3887 ee txt head face s todo-state upcomingp donep timestr
)
3888 (goto-char (point-min))
3889 (while (re-search-forward regexp nil t
)
3892 (setq s
(match-string 1)
3893 pos
(1- (match-beginning 1))
3894 d2
(org-time-string-to-absolute
3895 (match-string 1) d1
'past
3896 org-agenda-repeating-timestamp-show-all
)
3898 wdays
(org-get-wdays s
)
3899 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3900 upcomingp
(and todayp
(> diff
0)))
3901 ;; When to show a deadline in the calendar:
3902 ;; If the expiration is within wdays warning time.
3903 ;; Past-due deadlines are only shown on the current date
3904 (if (or (and (<= diff wdays
)
3905 (and todayp
(not org-agenda-only-exact-dates
)))
3908 (setq category
(org-get-category))
3909 (setq todo-state
(org-get-todo-state))
3910 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3912 (goto-char (match-end 0))
3913 (setq pos1
(match-beginning 0))
3914 (setq tags
(org-get-tags-at pos1
))
3915 (setq head
(buffer-substring-no-properties
3917 (progn (skip-chars-forward "^\r\n")
3919 (setq donep
(member todo-state org-done-keywords
))
3920 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3922 (concat (substring s
(match-beginning 1)) " "))
3923 (setq timestr
'time
))
3925 (or org-agenda-skip-deadline-if-done
3928 (setq txt
(org-format-agenda-item
3930 (car org-agenda-deadline-leaders
)
3931 (if (functionp (nth 1 org-agenda-deadline-leaders
))
3932 (funcall (nth 1 org-agenda-deadline-leaders
) diff date
)
3933 (format (nth 1 org-agenda-deadline-leaders
)
3936 (if (not (= diff
0)) nil timestr
)))))
3937 (setq txt org-agenda-no-heading-message
))
3939 (setq face
(org-agenda-deadline-face dfrac wdays
))
3940 (org-add-props txt props
3941 'org-marker
(org-agenda-new-marker pos
)
3942 'org-hd-marker
(org-agenda-new-marker pos1
)
3943 'priority
(+ (- diff
)
3944 (org-get-priority txt
))
3945 'org-category category
3946 'todo-state todo-state
3947 'type
(if upcomingp
"upcoming-deadline" "deadline")
3948 'date
(if upcomingp date d2
)
3949 'face
(if donep
'org-agenda-done face
)
3950 'undone-face face
'done-face
'org-agenda-done
)
3954 (defun org-agenda-deadline-face (fraction &optional wdays
)
3955 "Return the face to displaying a deadline item.
3956 FRACTION is what fraction of the head-warning time has passed."
3957 (if (equal wdays
0) (setq fraction
1.
))
3958 (let ((faces org-agenda-deadline-faces
) f
)
3960 (while (setq f
(pop faces
))
3961 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3963 (defun org-agenda-get-scheduled ()
3964 "Return the scheduled information for agenda display."
3965 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3966 'org-todo-regexp org-todo-regexp
3967 'org-complex-heading-regexp org-complex-heading-regexp
3968 'done-face
'org-agenda-done
3969 'mouse-face
'highlight
3970 'keymap org-agenda-keymap
3972 (format "mouse-2 or RET jump to org file %s"
3973 (abbreviate-file-name buffer-file-name
))))
3974 (regexp org-scheduled-time-regexp
)
3975 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3976 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3977 d2 diff pos pos1 category tags donep
3978 ee txt head pastschedp todo-state face timestr s
)
3979 (goto-char (point-min))
3980 (while (re-search-forward regexp nil t
)
3983 (setq s
(match-string 1)
3984 pos
(1- (match-beginning 1))
3985 d2
(org-time-string-to-absolute
3986 (match-string 1) d1
'past
3987 org-agenda-repeating-timestamp-show-all
)
3989 (setq pastschedp
(and todayp
(< diff
0)))
3990 ;; When to show a scheduled item in the calendar:
3991 ;; If it is on or past the date.
3992 (if (or (and (< diff
0)
3993 (< (abs diff
) org-scheduled-past-days
)
3994 (and todayp
(not org-agenda-only-exact-dates
)))
3997 (setq category
(org-get-category))
3998 (setq todo-state
(org-get-todo-state))
3999 (if (re-search-backward "^\\*+[ \t]+" nil t
)
4001 (goto-char (match-end 0))
4002 (setq pos1
(match-beginning 0))
4003 (setq tags
(org-get-tags-at))
4004 (setq head
(buffer-substring-no-properties
4006 (progn (skip-chars-forward "^\r\n") (point))))
4007 (setq donep
(member todo-state org-done-keywords
))
4008 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
4010 (concat (substring s
(match-beginning 1)) " "))
4011 (setq timestr
'time
))
4013 (or org-agenda-skip-scheduled-if-done
4016 (setq txt
(org-format-agenda-item
4018 (car org-agenda-scheduled-leaders
)
4019 (format (nth 1 org-agenda-scheduled-leaders
)
4022 (if (not (= diff
0)) nil timestr
)))))
4023 (setq txt org-agenda-no-heading-message
))
4027 (pastschedp 'org-scheduled-previously
)
4028 (todayp 'org-scheduled-today
)
4029 (t 'org-scheduled
)))
4030 (org-add-props txt props
4032 'face
(if donep
'org-agenda-done face
)
4033 'org-marker
(org-agenda-new-marker pos
)
4034 'org-hd-marker
(org-agenda-new-marker pos1
)
4035 'type
(if pastschedp
"past-scheduled" "scheduled")
4036 'date
(if pastschedp d2 date
)
4037 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
4038 'org-category category
4039 'todo-state todo-state
)
4043 (defun org-agenda-get-blocks ()
4044 "Return the date-range information for agenda display."
4045 (let* ((props (list 'face nil
4046 'org-not-done-regexp org-not-done-regexp
4047 'org-todo-regexp org-todo-regexp
4048 'org-complex-heading-regexp org-complex-heading-regexp
4049 'mouse-face
'highlight
4050 'keymap org-agenda-keymap
4052 (format "mouse-2 or RET jump to org file %s"
4053 (abbreviate-file-name buffer-file-name
))))
4054 (regexp org-tr-regexp
)
4055 (d0 (calendar-absolute-from-gregorian date
))
4056 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4058 (goto-char (point-min))
4059 (while (re-search-forward regexp nil t
)
4063 (setq timestr
(match-string 0)
4066 d1
(time-to-days (org-time-string-to-time s1
))
4067 d2
(time-to-days (org-time-string-to-time s2
)))
4068 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
4069 ;; Only allow days between the limits, because the normal
4070 ;; date stamps will catch the limits.
4072 (setq marker
(org-agenda-new-marker (point)))
4073 (setq category
(org-get-category))
4074 (setq todo-state
(org-get-todo-state))
4075 (if (re-search-backward "^\\*+ " nil t
)
4077 (goto-char (match-beginning 0))
4078 (setq hdmarker
(org-agenda-new-marker (point)))
4079 (setq tags
(org-get-tags-at))
4080 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4081 (setq head
(match-string 1))
4082 (and org-agenda-skip-timestamp-if-done
4083 (org-entry-is-done-p)
4085 (setq txt
(org-format-agenda-item
4087 (nth (if (= d1 d2
) 0 1)
4088 org-agenda-timerange-leaders
)
4089 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
4091 (if (= d0 d1
) timestr
))))
4092 (setq txt org-agenda-no-heading-message
))
4093 (org-add-props txt props
4094 'org-marker marker
'org-hd-marker hdmarker
4095 'type
"block" 'date date
4096 'todo-state todo-state
4097 'priority
(org-get-priority txt
) 'org-category category
)
4100 ;; Sort the entries by expiration date.
4103 ;;; Agenda presentation and sorting
4105 (defvar org-prefix-has-time nil
4106 "A flag, set by `org-compile-prefix-format'.
4107 The flag is set if the currently compiled format contains a `%t'.")
4108 (defvar org-prefix-has-tag nil
4109 "A flag, set by `org-compile-prefix-format'.
4110 The flag is set if the currently compiled format contains a `%T'.")
4111 (defvar org-prefix-has-effort nil
4112 "A flag, set by `org-compile-prefix-format'.
4113 The flag is set if the currently compiled format contains a `%e'.")
4115 (defun org-format-agenda-item (extra txt
&optional category tags dotime
4117 "Format TXT to be inserted into the agenda buffer.
4118 In particular, it adds the prefix and corresponding text properties. EXTRA
4119 must be a string and replaces the `%s' specifier in the prefix format.
4120 CATEGORY (string, symbol or nil) may be used to overrule the default
4121 category taken from local variable or file name. It will replace the `%c'
4122 specifier in the format. DOTIME, when non-nil, indicates that a
4123 time-of-day should be extracted from TXT for sorting of this entry, and for
4124 the `%t' specifier in the format. When DOTIME is a string, this string is
4125 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4126 only the correctly processes TXT should be returned - this is used by
4127 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4128 Any match of REMOVE-RE will be removed from TXT."
4130 ;; Diary entries sometimes have extra whitespace at the beginning
4131 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
4132 (when org-agenda-show-inherited-tags
4133 ;; Fix the tags part in txt
4134 (setq txt
(org-agenda-add-inherited-tags txt tags
)))
4135 (let* ((category (or category
4137 (if buffer-file-name
4138 (file-name-sans-extension
4139 (file-name-nondirectory buffer-file-name
))
4141 ;; time, tag, effort are needed for the eval of the prefix format
4142 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
4144 (ts (if dotime
(concat
4145 (if (stringp dotime
) dotime
"")
4146 (and org-agenda-search-headline-for-time txt
))))
4147 (time-of-day (and dotime
(org-get-time-of-day ts
)))
4148 stamp plain s0 s1 s2 t1 t2 rtn srp
4150 (and (org-mode-p) buffer-file-name
4151 (add-to-list 'org-agenda-contributing-files buffer-file-name
))
4152 (when (and dotime time-of-day
)
4153 ;; Extract starting and ending time and move them to prefix
4154 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
4155 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
4156 (setq s0
(match-string 0 ts
)
4157 srp
(and stamp
(match-end 3))
4158 s1
(match-string (if plain
1 2) ts
)
4159 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
4161 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4162 ;; them, we might want to remove them there to avoid duplication.
4163 ;; The user can turn this off with a variable.
4164 (if (and org-prefix-has-time
4165 org-agenda-remove-times-when-in-prefix
(or stamp plain
)
4166 (string-match (concat (regexp-quote s0
) " *") txt
)
4167 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
4168 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
4169 (= (match-beginning 0) 0)
4171 (setq txt
(replace-match "" nil nil txt
))))
4172 ;; Normalize the time(s) to 24 hour
4173 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
4174 (if s2
(setq s2
(org-get-time-of-day s2
'string t
)))
4175 ;; Compute the duration
4177 (setq t1
(+ (* 60 (string-to-number (substring s1
0 2)))
4178 (string-to-number (substring s1
3)))
4180 (s2 (+ (* 60 (string-to-number (substring s2
0 2)))
4181 (string-to-number (substring s2
3))))
4182 (org-agenda-default-appointment-duration
4183 (+ t1 org-agenda-default-appointment-duration
))
4185 (setq duration
(if t2
(- t2 t1
)))))
4187 (when (and s1
(not s2
) org-agenda-default-appointment-duration
4188 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
4189 (let ((m (+ (string-to-number (match-string 2 s1
))
4190 (* 60 (string-to-number (match-string 1 s1
)))
4191 org-agenda-default-appointment-duration
))
4193 (setq h
(/ m
60) m
(- m
(* h
60)))
4194 (setq s2
(format "%02d:%02d" h m
))))
4196 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4198 ;; Tags are in the string
4199 (if (or (eq org-agenda-remove-tags t
)
4200 (and org-agenda-remove-tags
4201 org-prefix-has-tag
))
4202 (setq txt
(replace-match "" t t txt
))
4203 (setq txt
(replace-match
4204 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
4205 (match-string 2 txt
))
4211 (or (get-text-property 0 'org-hd-marker txt
)
4212 (get-text-property 0 'org-marker txt
)))
4215 (setq neffort
(org-hh:mm-string-to-minutes effort
)
4216 effort
(setq effort
(concat "[" effort
"]" )))))
4219 (while (string-match remove-re txt
)
4220 (setq txt
(replace-match "" t t txt
))))
4222 ;; Create the final string
4225 ;; Prepare the variables needed in the eval of the compiled format
4226 (setq time
(cond (s2 (concat s1
"-" s2
))
4227 (s1 (concat s1
"......"))
4230 category
(if (symbolp category
) (symbol-name category
) category
))
4231 ;; Evaluate the compiled format
4232 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
4234 ;; And finally add the text properties
4235 (org-add-props rtn nil
4236 'org-category
(downcase category
)
4237 'tags
(mapcar 'org-downcase-keep-props tags
)
4238 'org-highest-priority org-highest-priority
4239 'org-lowest-priority org-lowest-priority
4240 'prefix-length
(- (length rtn
) (length txt
))
4241 'time-of-day time-of-day
4244 'effort-minutes neffort
4250 (defun org-agenda-add-inherited-tags (txt tags
)
4251 "Remove tags string from TXT, and add complete list of tags.
4252 The new list includes inherited tags. If any inherited tags are present,
4253 a double colon separates inherited tags from local tags."
4254 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt
)
4255 (setq txt
(substring txt
0 (match-beginning 0))))
4257 (let ((have-i (get-text-property 0 'inherited
(car tags
)))
4259 (setq txt
(concat txt
" :"
4262 (setq i
(get-text-property 0 'inherited x
))
4263 (if (and have-i
(not i
))
4269 (if have-i
"::" ":")))))
4272 (defun org-downcase-keep-props (s)
4273 (let ((props (text-properties-at 0 s
)))
4274 (setq s
(downcase s
))
4275 (add-text-properties 0 (length s
) props s
)
4278 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
4279 (defvar org-agenda-sorting-strategy-selected nil
)
4281 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
4283 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
4284 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
4285 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
4286 ((member 'weekly
(car org-agenda-time-grid
)))
4287 (t (throw 'exit list
)))
4288 (let* ((have (delq nil
(mapcar
4289 (lambda (x) (get-text-property 1 'time-of-day x
))
4291 (string (nth 1 org-agenda-time-grid
))
4292 (gridtimes (nth 2 org-agenda-time-grid
))
4293 (req (car org-agenda-time-grid
))
4294 (remove (member 'remove-match req
))
4296 (if (and (member 'require-timed req
) (not have
))
4297 ;; don't show empty grid
4299 (while (setq time
(pop gridtimes
))
4300 (unless (and remove
(member time have
))
4301 (setq time
(int-to-string time
))
4302 (push (org-format-agenda-item
4304 (concat (substring time
0 -
2) ":" (substring time -
2)))
4307 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
4308 (if (member 'time-up org-agenda-sorting-strategy-selected
)
4310 (append list new
)))))
4312 (defun org-compile-prefix-format (key)
4313 "Compile the prefix format into a Lisp form that can be evaluated.
4314 The resulting form is returned and stored in the variable
4315 `org-prefix-format-compiled'."
4316 (setq org-prefix-has-time nil org-prefix-has-tag nil
4317 org-prefix-has-effort nil
)
4319 ((stringp org-agenda-prefix-format
)
4320 org-agenda-prefix-format
)
4321 ((assq key org-agenda-prefix-format
)
4322 (cdr (assq key org-agenda-prefix-format
)))
4323 (t " %-12:c%?-12t% s")))
4325 varform vars var e c f opt
)
4326 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4328 (setq var
(cdr (assoc (match-string 4 s
)
4329 '(("c" . category
) ("t" . time
) ("s" . extra
)
4330 ("T" . tag
) ("e" . effort
))))
4331 c
(or (match-string 3 s
) "")
4332 opt
(match-beginning 1)
4333 start
(1+ (match-beginning 0)))
4334 (if (equal var
'time
) (setq org-prefix-has-time t
))
4335 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
4336 (if (equal var
'effort
) (setq org-prefix-has-effort t
))
4337 (setq f
(concat "%" (match-string 2 s
) "s"))
4340 `(if (equal "" ,var
)
4342 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
4343 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
4344 (setq s
(replace-match "%s" t nil s
))
4345 (push varform vars
))
4346 (setq vars
(nreverse vars
))
4347 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
4349 (defun org-set-sorting-strategy (key)
4350 (if (symbolp (car org-agenda-sorting-strategy
))
4352 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
4353 (setq org-agenda-sorting-strategy-selected
4354 (or (cdr (assq key org-agenda-sorting-strategy
))
4355 (cdr (assq 'agenda org-agenda-sorting-strategy
))
4356 '(time-up category-keep priority-down
)))))
4358 (defun org-get-time-of-day (s &optional string mod24
)
4359 "Check string S for a time of day.
4360 If found, return it as a military time number between 0 and 2400.
4361 If not found, return nil.
4362 The optional STRING argument forces conversion into a 5 character wide string
4366 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
4367 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
4368 (let* ((h (string-to-number (match-string 1 s
)))
4369 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
4370 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
4371 (am-p (equal ampm
"am"))
4372 (h1 (cond ((not ampm
) h
)
4373 ((= h
12) (if am-p
0 12))
4374 (t (+ h
(if am-p
0 12)))))
4375 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
4377 (t0 (+ (* 100 h2
) m
))
4378 (t1 (concat (if (>= h1
24) "+" " ")
4379 (if (< t0
100) "0" "")
4380 (if (< t0
10) "0" "")
4381 (int-to-string t0
))))
4382 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
4384 (defun org-finalize-agenda-entries (list &optional nosort
)
4385 "Sort and concatenate the agenda items."
4386 (setq list
(mapcar 'org-agenda-highlight-todo list
))
4389 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
4391 (defun org-agenda-highlight-todo (x)
4392 (let ((org-done-keywords org-done-keywords-for-agenda
)
4396 (beginning-of-line 1)
4397 (setq re
(get-text-property (point) 'org-todo-regexp
))
4398 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
4399 (when (looking-at (concat "[ \t]*\\.*\\(" re
"\\) +"))
4400 (add-text-properties (match-beginning 0) (match-end 0)
4401 (list 'face
(org-get-todo-face 1)))
4402 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4403 (delete-region (match-beginning 1) (1- (match-end 0)))
4404 (goto-char (match-beginning 1))
4405 (insert (format org-agenda-todo-keyword-format s
)))))
4406 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
4407 pl
(get-text-property 0 'prefix-length x
))
4409 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
4411 (add-text-properties
4412 (or (match-end 1) (match-end 0)) (match-end 0)
4413 (list 'face
(org-get-todo-face (match-string 2 x
)))
4415 (setq x
(concat (substring x
0 (match-end 1))
4416 (format org-agenda-todo-keyword-format
4419 (substring x
(match-end 3)))))
4422 (defsubst org-cmp-priority
(a b
)
4423 "Compare the priorities of string A and B."
4424 (let ((pa (or (get-text-property 1 'priority a
) 0))
4425 (pb (or (get-text-property 1 'priority b
) 0)))
4426 (cond ((> pa pb
) +1)
4430 (defsubst org-cmp-effort
(a b
)
4431 "Compare the priorities of string A and B."
4432 (let* ((def (if org-sort-agenda-noeffort-is-high
32767 -
1))
4433 (ea (or (get-text-property 1 'effort-minutes a
) def
))
4434 (eb (or (get-text-property 1 'effort-minutes b
) def
)))
4435 (cond ((> ea eb
) +1)
4439 (defsubst org-cmp-category
(a b
)
4440 "Compare the string values of categories of strings A and B."
4441 (let ((ca (or (get-text-property 1 'org-category a
) ""))
4442 (cb (or (get-text-property 1 'org-category b
) "")))
4443 (cond ((string-lessp ca cb
) -
1)
4444 ((string-lessp cb ca
) +1)
4447 (defsubst org-cmp-todo-state
(a b
)
4448 "Compare the todo states of strings A and B."
4449 (let* ((ma (or (get-text-property 1 'org-marker a
)
4450 (get-text-property 1 'org-hd-marker a
)))
4451 (mb (or (get-text-property 1 'org-marker b
)
4452 (get-text-property 1 'org-hd-marker b
)))
4453 (fa (and ma
(marker-buffer ma
)))
4454 (fb (and mb
(marker-buffer mb
)))
4456 (or (and fa
(with-current-buffer fa org-todo-keywords-1
))
4457 (and fb
(with-current-buffer fb org-todo-keywords-1
))))
4458 (ta (or (get-text-property 1 'todo-state a
) ""))
4459 (tb (or (get-text-property 1 'todo-state b
) ""))
4460 (la (- (length (member ta todo-kwds
))))
4461 (lb (- (length (member tb todo-kwds
))))
4462 (donepa (member ta org-done-keywords-for-agenda
))
4463 (donepb (member tb org-done-keywords-for-agenda
)))
4464 (cond ((and donepa
(not donepb
)) -
1)
4465 ((and (not donepa
) donepb
) +1)
4470 (defsubst org-cmp-tag
(a b
)
4471 "Compare the string values of the first tags of A and B."
4472 (let ((ta (car (last (get-text-property 1 'tags a
))))
4473 (tb (car (last (get-text-property 1 'tags b
)))))
4476 ((string-lessp ta tb
) -
1)
4477 ((string-lessp tb ta
) +1)
4480 (defsubst org-cmp-time
(a b
)
4481 "Compare the time-of-day values of strings A and B."
4482 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
4483 (ta (or (get-text-property 1 'time-of-day a
) def
))
4484 (tb (or (get-text-property 1 'time-of-day b
) def
)))
4485 (cond ((< ta tb
) -
1)
4489 (defun org-entries-lessp (a b
)
4490 "Predicate for sorting agenda entries."
4491 ;; The following variables will be used when the form is evaluated.
4492 ;; So even though the compiler complains, keep them.
4493 (let* ((time-up (org-cmp-time a b
))
4494 (time-down (if time-up
(- time-up
) nil
))
4495 (priority-up (org-cmp-priority a b
))
4496 (priority-down (if priority-up
(- priority-up
) nil
))
4497 (effort-up (org-cmp-effort a b
))
4498 (effort-down (if effort-up
(- effort-up
) nil
))
4499 (category-up (org-cmp-category a b
))
4500 (category-down (if category-up
(- category-up
) nil
))
4501 (category-keep (if category-up
+1 nil
))
4502 (tag-up (org-cmp-tag a b
))
4503 (tag-down (if tag-up
(- tag-up
) nil
))
4504 (todo-state-up (org-cmp-todo-state a b
))
4505 (todo-state-down (if todo-state-up
(- todo-state-up
) nil
))
4506 user-defined-up user-defined-down
)
4507 (if (and org-agenda-cmp-user-defined
4508 (functionp org-agenda-cmp-user-defined
))
4509 (setq user-defined-up
4510 (funcall org-agenda-cmp-user-defined a b
)
4511 user-defined-down
(if user-defined-up
(- user-defined-up
) nil
)))
4513 (eval (cons 'or org-agenda-sorting-strategy-selected
))
4514 '((-1 . t
) (1 . nil
) (nil . nil
))))))
4516 ;;; Agenda restriction lock
4518 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
4519 "Overlay to mark the headline to which arenda commands are restricted.")
4520 (org-overlay-put org-agenda-restriction-lock-overlay
4521 'face
'org-agenda-restriction-lock
)
4522 (org-overlay-put org-agenda-restriction-lock-overlay
4523 'help-echo
"Agendas are currently limited to this subtree.")
4524 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4526 (defun org-agenda-set-restriction-lock (&optional type
)
4527 "Set restriction lock for agenda, to current subtree or file.
4528 Restriction will be the file if TYPE is `file', or if type is the
4529 universal prefix '(4), or if the cursor is before the first headline
4530 in the file. Otherwise, restriction will be to the current subtree."
4532 (and (equal type
'(4)) (setq type
'file
))
4535 ((org-at-heading-p) 'subtree
)
4536 ((condition-case nil
(org-back-to-heading t
) (error nil
))
4539 (if (eq type
'subtree
)
4541 (setq org-agenda-restrict t
)
4542 (setq org-agenda-overriding-restriction
'subtree
)
4543 (put 'org-agenda-files
'org-restrict
4544 (list (buffer-file-name (buffer-base-buffer))))
4545 (org-back-to-heading t
)
4546 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
4547 (move-marker org-agenda-restrict-begin
(point))
4548 (move-marker org-agenda-restrict-end
4549 (save-excursion (org-end-of-subtree t
)))
4550 (message "Locking agenda restriction to subtree"))
4551 (put 'org-agenda-files
'org-restrict
4552 (list (buffer-file-name (buffer-base-buffer))))
4553 (setq org-agenda-restrict nil
)
4554 (setq org-agenda-overriding-restriction
'file
)
4555 (move-marker org-agenda-restrict-begin nil
)
4556 (move-marker org-agenda-restrict-end nil
)
4557 (message "Locking agenda restriction to file"))
4558 (setq current-prefix-arg nil
)
4559 (org-agenda-maybe-redo))
4561 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
4562 "Remove the agenda restriction lock."
4564 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4565 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
4566 (setq org-agenda-overriding-restriction nil
)
4567 (setq org-agenda-restrict nil
)
4568 (put 'org-agenda-files
'org-restrict nil
)
4569 (move-marker org-agenda-restrict-begin nil
)
4570 (move-marker org-agenda-restrict-end nil
)
4571 (setq current-prefix-arg nil
)
4572 (message "Agenda restriction lock removed")
4573 (or noupdate
(org-agenda-maybe-redo)))
4575 (defun org-agenda-maybe-redo ()
4576 "If there is any window showing the agenda view, update it."
4577 (let ((w (get-buffer-window org-agenda-buffer-name t
))
4578 (w0 (selected-window)))
4583 (if org-agenda-overriding-restriction
4584 (message "Agenda view shifted to new %s restriction"
4585 org-agenda-overriding-restriction
)
4586 (message "Agenda restriction lock removed")))))
4590 (defun org-agenda-check-type (error &rest types
)
4591 "Check if agenda buffer is of allowed type.
4592 If ERROR is non-nil, throw an error, otherwise just return nil."
4593 (if (memq org-agenda-type types
)
4596 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
4599 (defun org-agenda-quit ()
4600 "Exit agenda by removing the window or the buffer."
4602 (if org-agenda-columns-active
4604 (let ((buf (current-buffer)))
4605 (and (not (eq org-agenda-window-setup
'current-window
))
4606 (not (one-window-p))
4609 (org-agenda-reset-markers)
4610 (org-columns-remove-overlays)
4611 (setq org-agenda-archives-mode nil
))
4612 ;; Maybe restore the pre-agenda window configuration.
4613 (and org-agenda-restore-windows-after-quit
4614 (not (eq org-agenda-window-setup
'other-frame
))
4615 org-pre-agenda-window-conf
4616 (set-window-configuration org-pre-agenda-window-conf
))))
4618 (defun org-agenda-exit ()
4619 "Exit agenda by removing the window or the buffer.
4620 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
4621 Org-mode buffers visited directly by the user will not be touched."
4623 (org-release-buffers org-agenda-new-buffers
)
4624 (setq org-agenda-new-buffers nil
)
4627 (defun org-agenda-execute (arg)
4628 "Execute another agenda command, keeping same window.\\<global-map>
4629 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
4631 (let ((org-agenda-window-setup 'current-window
))
4634 (defun org-agenda-redo ()
4636 When this is the global TODO list, a prefix argument will be interpreted."
4638 (let* ((org-agenda-keep-modes t
)
4639 (filter org-agenda-filter
)
4640 (preset (get 'org-agenda-filter
:preset-filter
))
4641 (cols org-agenda-columns-active
)
4642 (line (org-current-line))
4643 (window-line (- line
(org-current-line (window-start))))
4644 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
4645 (put 'org-agenda-filter
:preset-filter nil
)
4646 (and cols
(org-columns-quit))
4647 (message "Rebuilding agenda buffer...")
4648 (org-let lprops
'(eval org-agenda-redo-command
))
4649 (setq org-agenda-undo-list nil
4650 org-agenda-pending-undo-list nil
)
4651 (message "Rebuilding agenda buffer...done")
4652 (put 'org-agenda-filter
:preset-filter preset
)
4653 (and (or filter preset
) (org-agenda-filter-apply filter
))
4654 (and cols
(interactive-p) (org-agenda-columns))
4656 (recenter window-line
)))
4659 (defvar org-global-tags-completion-table nil
)
4660 (defvar org-agenda-filter-form nil
)
4661 (defun org-agenda-filter-by-tag (strip &optional char narrow
)
4662 "Keep only those lines in the agenda buffer that have a specific tag.
4663 The tag is selected with its fast selection letter, as configured.
4664 With prefix argument STRIP, remove all lines that do have the tag.
4665 A lisp caller can specify CHAR. NARROW means that the new tag should be
4666 used to narrow the search - the interactive user can also press `-' or `+'
4667 to switch to narrowing."
4669 (let* ((alist org-tag-alist-for-agenda
)
4670 (tag-chars (mapconcat
4671 (lambda (x) (if (cdr x
) (char-to-string (cdr x
)) ""))
4673 (efforts (org-split-string
4674 (or (cdr (assoc (concat org-effort-property
"_ALL")
4675 org-global-properties
))
4676 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
4677 (effort-op org-agenda-filter-effort-default-operator
)
4679 (inhibit-read-only t
)
4680 (current org-agenda-filter
)
4684 "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
4685 (if narrow
"Narrow" "Filter") tag-chars
)
4686 (setq char
(read-char)))
4687 (when (member char
'(?
+ ?-
))
4689 (cond ((equal char ?-
) (setq strip t narrow t
))
4690 ((equal char ?
+) (setq strip nil narrow t
)))
4692 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars
)
4693 (setq char
(read-char)))
4694 (when (member char
'(?
< ?
> ?
= ??
))
4695 ;; An effort operator
4696 (setq effort-op
(char-to-string char
))
4697 (setq alist nil
) ; to make sure it will be interpreted as effort.
4698 (unless (equal char ??
)
4699 (loop for i from
0 to
9 do
4703 (if (= i
9) "0" (int-to-string (1+ i
)))
4704 "]" (nth i efforts
))))
4705 (message "Effort%s: %s " effort-op effort-prompt
)
4706 (setq char
(read-char))
4707 (when (or (< char ?
0) (> char ?
9))
4708 (error "Need 1-9,0 to select effort" ))))
4709 (when (equal char ?
\t)
4710 (unless (local-variable-p 'org-global-tags-completion-table
(current-buffer))
4711 (org-set-local 'org-global-tags-completion-table
4712 (org-global-tags-completion-table)))
4713 (let ((completion-ignore-case t
))
4714 (setq tag
(org-ido-completing-read
4715 "Tag: " org-global-tags-completion-table
))))
4718 (org-agenda-filter-by-tag-show-all)
4719 (when (get 'org-agenda-filter
:preset-filter
)
4720 (org-agenda-filter-apply org-agenda-filter
)))
4721 ((or (equal char ?\
)
4722 (setq a
(rassoc char alist
))
4723 (and (>= char ?
0) (<= char ?
9)
4724 (setq n
(if (= char ?
0) 9 (- char ?
0 1))
4725 tag
(concat effort-op
(nth n efforts
))
4730 (and tag
(setq a
(cons tag nil
))))
4731 (org-agenda-filter-by-tag-show-all)
4733 (setq org-agenda-filter
4734 (cons (concat (if strip
"-" "+") tag
)
4735 (if narrow current nil
)))
4736 (org-agenda-filter-apply org-agenda-filter
))
4737 (t (error "Invalid tag selection character %c" char
)))))
4739 (defun org-agenda-filter-by-tag-refine (strip &optional char
)
4740 "Refine the current filter. See `org-agenda-filter-by-tag."
4742 (org-agenda-filter-by-tag strip char
'refine
))
4744 (defun org-agenda-filter-make-matcher ()
4745 "Create the form that tests a line for the agenda filter."
4747 (dolist (x (append (get 'org-agenda-filter
:preset-filter
)
4749 (if (member x
'("-" "+"))
4750 (setq f1
'(not tags
))
4751 (if (string-match "[<=>?]" x
)
4752 (setq f1
(org-agenda-filter-effort-form x
))
4753 (setq f1
(list 'member
(downcase (substring x
1)) 'tags
)))
4754 (if (equal (string-to-char x
) ?-
)
4755 (setq f1
(list 'not f1
))))
4757 (cons 'and
(nreverse f
))))
4759 (defun org-agenda-filter-effort-form (e)
4760 "Return the form to compare the effort of the current line with what E says.
4761 E looks line \"+<2:25\"."
4763 (setq e
(substring e
1))
4764 (setq op
(string-to-char e
) e
(substring e
1))
4765 (setq op
(cond ((equal op ?
<) '<=)
4769 (list 'org-agenda-compare-effort
(list 'quote op
)
4770 (org-hh:mm-string-to-minutes e
))))
4772 (defun org-agenda-compare-effort (op value
)
4773 "Compare the effort of the current line with VALUE, using OP.
4774 If the line does not have an effort defined, return nil."
4775 (let ((eff (get-text-property (point) 'effort-minutes
)))
4778 (funcall op
(or eff
(if org-sort-agenda-noeffort-is-high
32767 0))
4781 (defun org-agenda-filter-apply (filter)
4782 "Set FILTER as the new agenda filter and apply it."
4784 (setq org-agenda-filter filter
4785 org-agenda-filter-form
(org-agenda-filter-make-matcher))
4786 (org-agenda-set-mode-name)
4788 (goto-char (point-min))
4790 (if (get-text-property (point) 'org-marker
)
4792 (setq tags
(get-text-property (point) 'tags
)) ; used in eval
4793 (if (not (eval org-agenda-filter-form
))
4794 (org-agenda-filter-by-tag-hide-line))
4795 (beginning-of-line 2))
4796 (beginning-of-line 2))))))
4798 (defun org-agenda-filter-by-tag-hide-line ()
4800 (setq ov
(org-make-overlay (max (point-min) (1- (point-at-bol)))
4802 (org-overlay-put ov
'invisible t
)
4803 (org-overlay-put ov
'type
'tags-filter
)
4804 (push ov org-agenda-filter-overlays
)))
4806 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos
)
4807 (setq pos
(or pos
(point)))
4809 (dolist (ov (org-overlays-at pos
))
4810 (when (and (org-overlay-get ov
'invisible
)
4811 (eq (org-overlay-get ov
'type
) 'tags-filter
))
4813 (if (< (org-overlay-start ov
) (point-at-eol))
4814 (org-move-overlay ov
(point-at-eol)
4815 (org-overlay-end ov
)))))))
4817 (defun org-agenda-filter-by-tag-show-all ()
4818 (mapc 'org-delete-overlay org-agenda-filter-overlays
)
4819 (setq org-agenda-filter-overlays nil
)
4820 (setq org-agenda-filter nil
)
4821 (setq org-agenda-filter-form nil
)
4822 (org-agenda-set-mode-name))
4824 (defun org-agenda-manipulate-query-add ()
4825 "Manipulate the query by adding a search term with positive selection.
4826 Positive selection means, the term must be matched for selection of an entry."
4828 (org-agenda-manipulate-query ?\
[))
4829 (defun org-agenda-manipulate-query-subtract ()
4830 "Manipulate the query by adding a search term with negative selection.
4831 Negative selection means, term must not be matched for selection of an entry."
4833 (org-agenda-manipulate-query ?\
]))
4834 (defun org-agenda-manipulate-query-add-re ()
4835 "Manipulate the query by adding a search regexp with positive selection.
4836 Positive selection means, the regexp must match for selection of an entry."
4838 (org-agenda-manipulate-query ?\
{))
4839 (defun org-agenda-manipulate-query-subtract-re ()
4840 "Manipulate the query by adding a search regexp with negative selection.
4841 Negative selection means, regexp must not match for selection of an entry."
4843 (org-agenda-manipulate-query ?\
}))
4844 (defun org-agenda-manipulate-query (char)
4846 ((memq org-agenda-type
'(timeline agenda
))
4847 (if (y-or-n-p "Re-display with inactive time stamps included? ")
4848 (let ((org-agenda-include-inactive-timestamps t
))
4851 ((eq org-agenda-type
'search
)
4853 'org-agenda-query-string
4854 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
4855 (?\
{ .
" +{}") (?\
} .
" -{}")))))
4856 (setq org-agenda-redo-command
4857 (list 'org-search-view
4859 org-agenda-query-string
4860 (+ (length org-agenda-query-string
)
4861 (if (member char
'(?\
{ ?\
})) 0 1))))
4862 (set-register org-agenda-query-register org-agenda-query-string
)
4864 (t (error "Cannot manipulate query for %s-type agenda buffers"
4867 (defun org-add-to-string (var string
)
4868 (set var
(concat (symbol-value var
) string
)))
4870 (defun org-agenda-goto-date (date)
4871 "Jump to DATE in agenda."
4872 (interactive (list (org-read-date)))
4873 (org-agenda-list nil date
))
4875 (defun org-agenda-goto-today ()
4878 (org-agenda-check-type t
'timeline
'agenda
)
4879 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
4881 (tdpos (goto-char tdpos
))
4882 ((eq org-agenda-type
'agenda
)
4883 (let* ((sd (time-to-days
4884 (time-subtract (current-time)
4885 (list 0 (* 3600 org-extend-today-until
) 0))))
4886 (comp (org-agenda-compute-time-span sd org-agenda-span
))
4887 (org-agenda-overriding-arguments org-agenda-last-arguments
))
4888 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
4889 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
4891 (org-agenda-find-same-or-today-or-agenda)))
4892 (t (error "Cannot find today")))))
4894 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
4896 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
4897 (text-property-any (point-min) (point-max) 'org-today t
)
4898 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
4901 (defun org-agenda-later (arg)
4902 "Go forward in time by thee current span.
4903 With prefix ARG, go forward that many times the current span."
4905 (org-agenda-check-type t
'agenda
)
4906 (let* ((span org-agenda-span
)
4907 (sd org-starting-day
)
4908 (greg (calendar-gregorian-from-absolute sd
))
4909 (cnt (get-text-property (point) 'org-day-cnt
))
4913 (setq sd
(+ arg sd
) nd
1))
4915 (setq sd
(+ (* 7 arg
) sd
) nd
7))
4917 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
4918 sd
(calendar-absolute-from-gregorian greg2
))
4919 (setcar greg2
(1+ (car greg2
)))
4920 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
4922 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
4923 sd
(calendar-absolute-from-gregorian greg2
))
4924 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
4925 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
4926 (let ((org-agenda-overriding-arguments
4927 (list (car org-agenda-last-arguments
) sd nd t
)))
4929 (org-agenda-find-same-or-today-or-agenda cnt
))))
4931 (defun org-agenda-earlier (arg)
4932 "Go backward in time by the current span.
4933 With prefix ARG, go backward that many times the current span."
4935 (org-agenda-later (- arg
)))
4937 (defun org-agenda-day-view (&optional day-of-year
)
4938 "Switch to daily view for agenda.
4939 With argument DAY-OF-YEAR, switch to that day of the year."
4941 (setq org-agenda-ndays
1)
4942 (org-agenda-change-time-span 'day day-of-year
))
4943 (defun org-agenda-week-view (&optional iso-week
)
4944 "Switch to daily view for agenda.
4945 With argument ISO-WEEK, switch to the corresponding ISO week.
4946 If ISO-WEEK has more then 2 digits, only the last two encode the
4947 week. Any digits before this encode a year. So 200712 means
4948 week 12 of year 2007. Years in the range 1938-2037 can also be
4949 written as 2-digit years."
4951 (setq org-agenda-ndays
7)
4952 (org-agenda-change-time-span 'week iso-week
))
4953 (defun org-agenda-month-view (&optional month
)
4954 "Switch to monthly view for agenda.
4955 With argument MONTH, switch to that month."
4957 (org-agenda-change-time-span 'month month
))
4958 (defun org-agenda-year-view (&optional year
)
4959 "Switch to yearly view for agenda.
4960 With argument YEAR, switch to that year.
4961 If MONTH has more then 2 digits, only the last two encode the
4962 month. Any digits before this encode a year. So 200712 means
4963 December year 2007. Years in the range 1938-2037 can also be
4964 written as 2-digit years."
4967 (setq year
(org-small-year-to-year year
)))
4968 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4969 (org-agenda-change-time-span 'year year
)
4972 (defun org-agenda-change-time-span (span &optional n
)
4973 "Change the agenda view to SPAN.
4974 SPAN may be `day', `week', `month', `year'."
4975 (org-agenda-check-type t
'agenda
)
4976 (if (and (not n
) (equal org-agenda-span span
))
4977 (error "Viewing span is already \"%s\"" span
))
4978 (let* ((sd (or (get-text-property (point) 'day
)
4980 (computed (org-agenda-compute-time-span sd span n
))
4981 (org-agenda-overriding-arguments
4982 (list (car org-agenda-last-arguments
)
4983 (car computed
) (cdr computed
) t
)))
4985 (org-agenda-find-same-or-today-or-agenda))
4986 (org-agenda-set-mode-name)
4987 (message "Switched to %s view" span
))
4989 (defun org-agenda-compute-time-span (sd span
&optional n
)
4990 "Compute starting date and number of days for agenda.
4991 SPAN may be `day', `week', `month', `year'. The return value
4992 is a cons cell with the starting date and the number of days,
4993 so that the date SD will be in that range."
4994 (let* ((greg (calendar-gregorian-from-absolute sd
))
4998 nd w1 y1 m1 thisweek
)
5002 (setq sd
(+ (calendar-absolute-from-gregorian
5007 (let* ((nt (calendar-day-of-week
5008 (calendar-gregorian-from-absolute sd
)))
5009 (d (if org-agenda-start-on-weekday
5010 (- nt org-agenda-start-on-weekday
)
5012 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
5015 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
5017 (setq y1
(org-small-year-to-year (/ n
100))
5020 (calendar-absolute-from-iso
5022 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
5025 (when (and n
(> n
99))
5026 (setq y1
(org-small-year-to-year (/ n
100))
5028 (setq sd
(calendar-absolute-from-gregorian
5029 (list (or n mg
) 1 (or y1 yg
)))
5030 nd
(- (calendar-absolute-from-gregorian
5031 (list (1+ (or n mg
)) 1 (or y1 yg
)))
5034 (setq sd
(calendar-absolute-from-gregorian
5035 (list 1 1 (or n yg
)))
5036 nd
(- (calendar-absolute-from-gregorian
5037 (list 1 1 (1+ (or n yg
))))
5041 (defun org-agenda-next-date-line (&optional arg
)
5042 "Jump to the next line indicating a date in agenda buffer."
5044 (org-agenda-check-type t
'agenda
'timeline
)
5045 (beginning-of-line 1)
5046 ;; This does not work if user makes date format that starts with a blank
5047 (if (looking-at "^\\S-") (forward-char 1))
5048 (if (not (re-search-forward "^\\S-" nil t arg
))
5051 (error "No next date after this line in this buffer")))
5052 (goto-char (match-beginning 0)))
5054 (defun org-agenda-previous-date-line (&optional arg
)
5055 "Jump to the previous line indicating a date in agenda buffer."
5057 (org-agenda-check-type t
'agenda
'timeline
)
5058 (beginning-of-line 1)
5059 (if (not (re-search-backward "^\\S-" nil t arg
))
5060 (error "No previous date before this line in this buffer")))
5062 ;; Initialize the highlight
5063 (defvar org-hl
(org-make-overlay 1 1))
5064 (org-overlay-put org-hl
'face
'highlight
)
5066 (defun org-highlight (begin end
&optional buffer
)
5067 "Highlight a region with overlay."
5068 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
5069 org-hl begin end
(or buffer
(current-buffer))))
5071 (defun org-unhighlight ()
5072 "Detach overlay INDEX."
5073 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
5075 ;; FIXME this is currently not used.
5076 (defun org-highlight-until-next-command (beg end
&optional buffer
)
5077 "Move the highlight overlay to BEG/END, remove it before the next command."
5078 (org-highlight beg end buffer
)
5079 (add-hook 'pre-command-hook
'org-unhighlight-once
))
5080 (defun org-unhighlight-once ()
5081 "Remove the highlight from its position, and this function from the hook."
5082 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
5085 (defun org-agenda-follow-mode ()
5086 "Toggle follow mode in an agenda buffer."
5088 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
5089 (org-agenda-set-mode-name)
5090 (message "Follow mode is %s"
5091 (if org-agenda-follow-mode
"on" "off")))
5093 (defun org-agenda-clockreport-mode ()
5094 "Toggle clocktable mode in an agenda buffer."
5096 (org-agenda-check-type t
'agenda
)
5097 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
5098 (org-agenda-set-mode-name)
5100 (message "Clocktable mode is %s"
5101 (if org-agenda-clockreport-mode
"on" "off")))
5103 (defun org-agenda-log-mode (&optional special
)
5104 "Toggle log mode in an agenda buffer.
5105 With argument SPECIAL, show all possible log items, not only the ones
5106 configured in `org-agenda-log-mode-items'.
5107 With a double `C-u' prefix arg, show *only* log items, nothing else."
5109 (org-agenda-check-type t
'agenda
'timeline
)
5110 (setq org-agenda-show-log
5111 (if (equal special
'(16))
5113 (if special
'(closed clock state
)
5114 (not org-agenda-show-log
))))
5115 (org-agenda-set-mode-name)
5117 (message "Log mode is %s"
5118 (if org-agenda-show-log
"on" "off")))
5120 (defun org-agenda-archives-mode (&optional with-files
)
5121 "Toggle log mode in an agenda buffer."
5123 (setq org-agenda-archives-mode
5124 (if with-files t
(if org-agenda-archives-mode nil
'trees
)))
5125 (org-agenda-set-mode-name)
5130 ((eq org-agenda-archives-mode nil
)
5131 "No archives are included")
5132 ((eq org-agenda-archives-mode
'trees
)
5133 (format "Trees with :%s: tag are included" org-archive-tag
))
5134 ((eq org-agenda-archives-mode t
)
5135 (format "Trees with :%s: tag and all active archive files are included"
5136 org-archive-tag
)))))
5138 (defun org-agenda-toggle-diary ()
5139 "Toggle diary inclusion in an agenda buffer."
5141 (org-agenda-check-type t
'agenda
)
5142 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
5144 (org-agenda-set-mode-name)
5145 (message "Diary inclusion turned %s"
5146 (if org-agenda-include-diary
"on" "off")))
5148 (defun org-agenda-toggle-time-grid ()
5149 "Toggle time grid in an agenda buffer."
5151 (org-agenda-check-type t
'agenda
)
5152 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
5154 (org-agenda-set-mode-name)
5155 (message "Time-grid turned %s"
5156 (if org-agenda-use-time-grid
"on" "off")))
5158 (defun org-agenda-set-mode-name ()
5159 "Set the mode name to indicate all the small mode settings."
5161 (concat "Org-Agenda"
5162 (if (equal org-agenda-ndays
1) " Day" "")
5163 (if (equal org-agenda-ndays
7) " Week" "")
5164 (if org-agenda-follow-mode
" Follow" "")
5165 (if org-agenda-include-diary
" Diary" "")
5166 (if org-agenda-use-time-grid
" Grid" "")
5167 (if (consp org-agenda-show-log
) " LogAll"
5168 (if org-agenda-show-log
" Log" ""))
5169 (if (or org-agenda-filter
(get 'org-agenda-filter
5171 (concat " {" (mapconcat
5173 (append (get 'org-agenda-filter
5175 org-agenda-filter
) "") "}")
5177 (if org-agenda-archives-mode
5178 (if (eq org-agenda-archives-mode t
)
5180 (format " :%s:" org-archive-tag
))
5182 (if org-agenda-clockreport-mode
" Clock" "")))
5183 (force-mode-line-update))
5185 (defun org-agenda-post-command-hook ()
5186 (and (eolp) (not (bolp)) (backward-char 1))
5187 (setq org-agenda-type
5188 (or (get-text-property (point) 'org-agenda-type
)
5189 (get-text-property (max (point-min) (1- (point)))
5191 (if (and org-agenda-follow-mode
5192 (get-text-property (point) 'org-marker
))
5195 (defun org-agenda-show-priority ()
5196 "Show the priority of the current item.
5197 This priority is composed of the main priority given with the [#A] cookies,
5198 and by additional input from the age of a schedules or deadline entry."
5200 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
5201 (message "Priority is %d" (if pri pri -
1000))))
5203 (defun org-agenda-show-tags ()
5204 "Show the tags applicable to the current item."
5206 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
5208 (message "Tags are :%s:"
5209 (org-no-properties (mapconcat 'identity tags
":")))
5210 (message "No tags associated with this line"))))
5212 (defun org-agenda-goto (&optional highlight
)
5213 "Go to the Org-mode file which contains the item at point."
5215 (let* ((marker (or (get-text-property (point) 'org-marker
)
5216 (org-agenda-error)))
5217 (buffer (marker-buffer marker
))
5218 (pos (marker-position marker
)))
5219 (switch-to-buffer-other-window buffer
)
5223 (org-show-context 'agenda
)
5225 (and (outline-next-heading)
5226 (org-flag-heading nil
)))) ; show the next heading
5227 (recenter (/ (window-height) 2))
5228 (run-hooks 'org-agenda-after-show-hook
)
5229 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
5231 (defvar org-agenda-after-show-hook nil
5232 "Normal hook run after an item has been shown from the agenda.
5233 Point is in the buffer where the item originated.")
5235 (defun org-agenda-kill ()
5236 "Kill the entry or subtree belonging to the current agenda entry."
5238 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5239 (let* ((marker (or (get-text-property (point) 'org-marker
)
5240 (org-agenda-error)))
5241 (buffer (marker-buffer marker
))
5242 (pos (marker-position marker
))
5243 (type (get-text-property (point) 'type
))
5244 dbeg dend
(n 0) conf
)
5245 (org-with-remote-undo buffer
5246 (with-current-buffer buffer
5249 (if (and (org-mode-p) (not (member type
'("sexp"))))
5250 (setq dbeg
(progn (org-back-to-heading t
) (point))
5251 dend
(org-end-of-subtree t t
))
5252 (setq dbeg
(point-at-bol)
5253 dend
(min (point-max) (1+ (point-at-eol)))))
5255 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
5256 (setq conf
(or (eq t org-agenda-confirm-kill
)
5257 (and (numberp org-agenda-confirm-kill
)
5258 (> n org-agenda-confirm-kill
))))
5261 (format "Delete entry with %d lines in buffer \"%s\"? "
5262 n
(buffer-name buffer
))))
5264 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
5265 (with-current-buffer buffer
(delete-region dbeg dend
))
5266 (message "Agenda item and source killed"))))
5268 (defun org-agenda-archive ()
5269 "Archive the entry or subtree belonging to the current agenda entry."
5271 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5272 (let* ((marker (or (get-text-property (point) 'org-marker
)
5273 (org-agenda-error)))
5274 (buffer (marker-buffer marker
))
5275 (pos (marker-position marker
)))
5276 (org-with-remote-undo buffer
5277 (with-current-buffer buffer
5281 (org-remove-subtree-entries-from-agenda)
5282 (org-back-to-heading t
)
5283 (org-archive-subtree))
5284 (error "Archiving works only in Org-mode files"))))))
5286 (defun org-agenda-archive-to-archive-sibling ()
5287 "Move the entry to the archive sibling."
5289 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5290 (let* ((marker (or (get-text-property (point) 'org-marker
)
5291 (org-agenda-error)))
5292 (buffer (marker-buffer marker
))
5293 (pos (marker-position marker
)))
5294 (org-with-remote-undo buffer
5295 (with-current-buffer buffer
5299 (org-remove-subtree-entries-from-agenda)
5300 (org-back-to-heading t
)
5301 (org-archive-to-archive-sibling))
5302 (error "Archiving works only in Org-mode files"))))))
5304 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
5305 "Remove all lines in the agenda that correspond to a given subtree.
5306 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5307 If this information is not given, the function uses the tree at point."
5308 (let ((buf (or buf
(current-buffer))) m p
)
5310 (unless (and beg end
)
5311 (org-back-to-heading t
)
5313 (org-end-of-subtree t
)
5315 (set-buffer (get-buffer org-agenda-buffer-name
))
5317 (goto-char (point-max))
5318 (beginning-of-line 1)
5320 (when (and (setq m
(get-text-property (point) 'org-marker
))
5321 (equal buf
(marker-buffer m
))
5322 (setq p
(marker-position m
))
5325 (let ((inhibit-read-only t
))
5326 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5327 (beginning-of-line 0))))))
5329 (defun org-agenda-open-link ()
5330 "Follow the link in the current line, if any."
5332 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
5335 (narrow-to-region (point-at-bol) (point-at-eol))
5336 (org-open-at-point))))
5338 (defun org-agenda-copy-local-variable (var)
5339 "Get a variable from a referenced buffer and install it here."
5340 (let ((m (get-text-property (point) 'org-marker
)))
5341 (when (and m
(buffer-live-p (marker-buffer m
)))
5342 (org-set-local var
(with-current-buffer (marker-buffer m
)
5343 (symbol-value var
))))))
5345 (defun org-agenda-switch-to (&optional delete-other-windows
)
5346 "Go to the Org-mode file which contains the item at point."
5348 (let* ((marker (or (get-text-property (point) 'org-marker
)
5349 (org-agenda-error)))
5350 (buffer (marker-buffer marker
))
5351 (pos (marker-position marker
)))
5352 (switch-to-buffer buffer
)
5353 (and delete-other-windows
(delete-other-windows))
5357 (org-show-context 'agenda
)
5359 (and (outline-next-heading)
5360 (org-flag-heading nil
)))))) ; show the next heading
5362 (defun org-agenda-goto-mouse (ev)
5363 "Go to the Org-mode file which contains the item at the mouse click."
5365 (mouse-set-point ev
)
5368 (defun org-agenda-show (&optional full-entry
)
5369 "Display the Org-mode file which contains the item at point.
5370 With prefix argument FULL-ENTRY, make the entire entry visible
5371 if it was hidden in the outline."
5373 (let ((win (selected-window)))
5375 (let ((org-show-entry-below t
))
5376 (org-agenda-goto t
))
5377 (org-agenda-goto t
))
5378 (select-window win
)))
5380 (defun org-agenda-show-1 (&optional more
)
5381 "Display the Org-mode file which contains the item at point.
5382 The prefix arg causes further revieling:
5385 1 just show the entry according to defaults.
5386 2 show the text below the heading
5387 3 show the entire subtree
5388 4 show the entire subtree and any LOGBOOK drawers
5389 5 show the entire subtree and any drawers
5390 With prefix argument FULL-ENTRY, make the entire entry visible
5391 if it was hidden in the outline."
5393 (let ((win (selected-window)))
5395 (org-recenter-heading 1)
5399 (message "Remote: hide subtree"))
5400 ((and (interactive-p) (= more
1))
5401 (message "Remote: show with default settings"))
5405 (org-back-to-heading)
5406 (org-cycle-hide-drawers 'children
))
5407 (message "Remote: show entry"))
5411 (org-back-to-heading)
5412 (org-cycle-hide-drawers 'subtree
))
5413 (message "Remote: show subtree"))
5415 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers
)))
5417 (concat "^[ \t]*:\\("
5418 (mapconcat 'regexp-quote org-drawers
"\\|")
5422 (org-back-to-heading)
5423 (org-cycle-hide-drawers 'subtree
)))
5424 (message "Remote: show subtree and LOGBOOK"))
5427 (message "Remote: show subtree and LOGBOOK")))
5428 (select-window win
)))
5430 (defun org-recenter-heading (n)
5432 (org-back-to-heading)
5435 (defvar org-agenda-cycle-counter nil
)
5436 (defun org-agenda-cycle-show (n)
5437 "Show the current entry in another window, with default settings.
5438 Default settings are taken from `org-show-hierarchy-above' and siblings.
5439 When use repeadedly in immediate succession, the remote entry will cycle
5442 entry -> subtree -> subtree with logbook"
5445 (not (eq last-command this-command
)))
5446 (setq org-agenda-cycle-counter
0))
5447 (setq org-agenda-cycle-counter
(1+ org-agenda-cycle-counter
))
5448 (if (> org-agenda-cycle-counter
4)
5449 (setq org-agenda-cycle-counter
0))
5450 (org-agenda-show-1 org-agenda-cycle-counter
))
5452 (defun org-agenda-recenter (arg)
5453 "Display the Org-mode file which contains the item at point and recenter."
5455 (let ((win (selected-window)))
5458 (select-window win
)))
5460 (defun org-agenda-show-mouse (ev)
5461 "Display the Org-mode file which contains the item at the mouse click."
5463 (mouse-set-point ev
)
5466 (defun org-agenda-check-no-diary ()
5467 "Check if the entry is a diary link and abort if yes."
5468 (if (get-text-property (point) 'org-agenda-diary-link
)
5469 (org-agenda-error)))
5471 (defun org-agenda-error ()
5472 (error "Command not allowed in this line"))
5474 (defun org-agenda-tree-to-indirect-buffer ()
5475 "Show the subtree corresponding to the current entry in an indirect buffer.
5476 This calls the command `org-tree-to-indirect-buffer' from the original
5478 With numerical prefix arg ARG, go up to this level and then take that tree.
5479 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
5482 (org-agenda-check-no-diary)
5483 (let* ((marker (or (get-text-property (point) 'org-marker
)
5484 (org-agenda-error)))
5485 (buffer (marker-buffer marker
))
5486 (pos (marker-position marker
)))
5487 (with-current-buffer buffer
5490 (call-interactively 'org-tree-to-indirect-buffer
)))))
5492 (defvar org-last-heading-marker
(make-marker)
5493 "Marker pointing to the headline that last changed its TODO state
5494 by a remote command from the agenda.")
5496 (defun org-agenda-todo-nextset ()
5497 "Switch TODO entry to next sequence."
5499 (org-agenda-todo 'nextset
))
5501 (defun org-agenda-todo-previousset ()
5502 "Switch TODO entry to previous sequence."
5504 (org-agenda-todo 'previousset
))
5506 (defun org-agenda-todo (&optional arg
)
5507 "Cycle TODO state of line at point, also in Org-mode file.
5508 This changes the line at point, all other lines in the agenda referring to
5509 the same tree node, and the headline of the tree node in the Org-mode file."
5511 (org-agenda-check-no-diary)
5512 (let* ((col (current-column))
5513 (marker (or (get-text-property (point) 'org-marker
)
5514 (org-agenda-error)))
5515 (buffer (marker-buffer marker
))
5516 (pos (marker-position marker
))
5517 (hdmarker (get-text-property (point) 'org-hd-marker
))
5518 (todayp (equal (get-text-property (point) 'day
)
5519 (time-to-days (current-time))))
5520 (inhibit-read-only t
)
5521 org-agenda-headline-snapshot-before-repeat newhead just-one
)
5522 (org-with-remote-undo buffer
5523 (with-current-buffer buffer
5526 (org-show-context 'agenda
)
5528 (and (outline-next-heading)
5529 (org-flag-heading nil
))) ; show the next heading
5530 (let ((current-prefix-arg arg
))
5531 (call-interactively 'org-todo
))
5532 (and (bolp) (forward-char 1))
5533 (setq newhead
(org-get-heading))
5534 (when (and (org-bound-and-true-p
5535 org-agenda-headline-snapshot-before-repeat
)
5536 (not (equal org-agenda-headline-snapshot-before-repeat
5539 (setq newhead org-agenda-headline-snapshot-before-repeat
5542 (org-back-to-heading)
5543 (move-marker org-last-heading-marker
(point))))
5544 (beginning-of-line 1)
5546 (org-agenda-change-all-lines newhead hdmarker
'fixface just-one
))
5547 (org-move-to-column col
))))
5549 (defun org-agenda-add-note (&optional arg
)
5550 "Add a time-stamped note to the entry at point."
5552 (org-agenda-check-no-diary)
5553 (let* ((marker (or (get-text-property (point) 'org-marker
)
5554 (org-agenda-error)))
5555 (buffer (marker-buffer marker
))
5556 (pos (marker-position marker
))
5557 (hdmarker (get-text-property (point) 'org-hd-marker
))
5558 (inhibit-read-only t
))
5559 (with-current-buffer buffer
5562 (org-show-context 'agenda
)
5564 (and (outline-next-heading)
5565 (org-flag-heading nil
))) ; show the next heading
5568 (defun org-agenda-change-all-lines (newhead hdmarker
5569 &optional fixface just-this
)
5570 "Change all lines in the agenda buffer which match HDMARKER.
5571 The new content of the line will be NEWHEAD (as modified by
5572 `org-format-agenda-item'). HDMARKER is checked with
5573 `equal' against all `org-hd-marker' text properties in the file.
5574 If FIXFACE is non-nil, the face of each item is modified according to
5576 If JUST-THIS is non-nil, change just the current line, not all.
5577 If FORCE-TAGS is non nil, the car of it returns the new tags."
5578 (let* ((inhibit-read-only t
)
5579 (line (org-current-line))
5580 (thetags (with-current-buffer (marker-buffer hdmarker
)
5581 (save-excursion (save-restriction (widen)
5582 (goto-char hdmarker
)
5583 (org-get-tags-at)))))
5584 props m pl undone-face done-face finish new dotime cat tags
)
5586 (goto-char (point-max))
5587 (beginning-of-line 1)
5589 (setq finish
(bobp))
5590 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
5591 (or (not just-this
) (= (org-current-line) line
))
5593 (setq props
(text-properties-at (point))
5594 dotime
(get-text-property (point) 'dotime
)
5595 cat
(get-text-property (point) 'org-category
)
5597 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
5598 pl
(get-text-property (point) 'prefix-length
)
5599 undone-face
(get-text-property (point) 'undone-face
)
5600 done-face
(get-text-property (point) 'done-face
))
5601 (org-move-to-column pl
)
5604 (beginning-of-line 1)
5605 (and (looking-at ".*\n?") (replace-match "")))
5607 (replace-match new t t
)
5608 (beginning-of-line 1)
5609 (add-text-properties (point-at-bol) (point-at-eol) props
)
5611 (add-text-properties
5612 (point-at-bol) (point-at-eol)
5614 (if org-last-todo-state-is-todo
5615 undone-face done-face
))))
5616 (org-agenda-highlight-todo 'line
)
5617 (beginning-of-line 1))
5618 (t (error "Line update did not work"))))
5619 (beginning-of-line 0)))
5620 (org-finalize-agenda)))
5622 (defun org-agenda-align-tags (&optional line
)
5623 "Align all tags in agenda items to `org-agenda-tags-column'."
5624 (let ((inhibit-read-only t
) l c
)
5626 (goto-char (if line
(point-at-bol) (point-min)))
5627 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
5628 (if line
(point-at-eol) nil
) t
)
5629 (add-text-properties
5630 (match-beginning 2) (match-end 2)
5631 (list 'face
(delq nil
(let ((prop (get-text-property
5632 (match-beginning 2) 'face
)))
5633 (or (listp prop
) (setq prop
(list prop
)))
5634 (if (memq 'org-tag prop
)
5636 (cons 'org-tag prop
))))))
5637 (setq l
(- (match-end 2) (match-beginning 2))
5638 c
(if (< org-agenda-tags-column
0)
5639 (- (abs org-agenda-tags-column
) l
)
5640 org-agenda-tags-column
))
5641 (delete-region (match-beginning 1) (match-end 1))
5642 (goto-char (match-beginning 1))
5643 (insert (org-add-props
5644 (make-string (max 1 (- c
(current-column))) ?\
)
5645 (text-properties-at (point)))))
5646 (goto-char (point-min))
5647 (org-font-lock-add-tag-faces (point-max)))))
5649 (defun org-agenda-priority-up ()
5650 "Increase the priority of line at point, also in Org-mode file."
5652 (org-agenda-priority 'up
))
5654 (defun org-agenda-priority-down ()
5655 "Decrease the priority of line at point, also in Org-mode file."
5657 (org-agenda-priority 'down
))
5659 (defun org-agenda-priority (&optional force-direction
)
5660 "Set the priority of line at point, also in Org-mode file.
5661 This changes the line at point, all other lines in the agenda referring to
5662 the same tree node, and the headline of the tree node in the Org-mode file."
5664 (org-agenda-check-no-diary)
5665 (let* ((marker (or (get-text-property (point) 'org-marker
)
5666 (org-agenda-error)))
5667 (hdmarker (get-text-property (point) 'org-hd-marker
))
5668 (buffer (marker-buffer hdmarker
))
5669 (pos (marker-position hdmarker
))
5670 (inhibit-read-only t
)
5672 (org-with-remote-undo buffer
5673 (with-current-buffer buffer
5676 (org-show-context 'agenda
)
5678 (and (outline-next-heading)
5679 (org-flag-heading nil
))) ; show the next heading
5680 (funcall 'org-priority force-direction
)
5682 (setq newhead
(org-get-heading)))
5683 (org-agenda-change-all-lines newhead hdmarker
)
5684 (beginning-of-line 1))))
5686 ;; FIXME: should fix the tags property of the agenda line.
5687 (defun org-agenda-set-tags ()
5688 "Set tags for the current headline."
5690 (org-agenda-check-no-diary)
5691 (if (and (org-region-active-p) (interactive-p))
5692 (call-interactively 'org-change-tag-in-region
)
5693 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5694 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5695 (org-agenda-error)))
5696 (buffer (marker-buffer hdmarker
))
5697 (pos (marker-position hdmarker
))
5698 (inhibit-read-only t
)
5700 (org-with-remote-undo buffer
5701 (with-current-buffer buffer
5705 (org-show-context 'agenda
))
5707 (and (outline-next-heading)
5708 (org-flag-heading nil
))) ; show the next heading
5710 (call-interactively 'org-set-tags
)
5712 (setq newhead
(org-get-heading)))
5713 (org-agenda-change-all-lines newhead hdmarker
)
5714 (beginning-of-line 1)))))
5716 (defun org-agenda-toggle-archive-tag ()
5717 "Toggle the archive tag for the current entry."
5719 (org-agenda-check-no-diary)
5720 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5721 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5722 (org-agenda-error)))
5723 (buffer (marker-buffer hdmarker
))
5724 (pos (marker-position hdmarker
))
5725 (inhibit-read-only t
)
5727 (org-with-remote-undo buffer
5728 (with-current-buffer buffer
5731 (org-show-context 'agenda
)
5733 (and (outline-next-heading)
5734 (org-flag-heading nil
))) ; show the next heading
5735 (call-interactively 'org-toggle-archive-tag
)
5737 (setq newhead
(org-get-heading)))
5738 (org-agenda-change-all-lines newhead hdmarker
)
5739 (beginning-of-line 1))))
5741 (defun org-agenda-do-date-later (arg)
5744 ((or (equal arg
'(16))
5746 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5747 (setq this-command
'org-agenda-date-later-minutes
)
5748 (org-agenda-date-later-minutes 1))
5749 ((or (equal arg
'(4))
5751 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5752 (setq this-command
'org-agenda-date-later-hours
)
5753 (org-agenda-date-later-hours 1))
5755 (org-agenda-date-later (prefix-numeric-value arg
)))))
5757 (defun org-agenda-do-date-earlier (arg)
5760 ((or (equal arg
'(16))
5762 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5763 (setq this-command
'org-agenda-date-earlier-minutes
)
5764 (org-agenda-date-earlier-minutes 1))
5765 ((or (equal arg
'(4))
5767 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5768 (setq this-command
'org-agenda-date-earlier-hours
)
5769 (org-agenda-date-earlier-hours 1))
5771 (org-agenda-date-earlier (prefix-numeric-value arg
)))))
5773 (defun org-agenda-date-later (arg &optional what
)
5774 "Change the date of this item to one day later."
5776 (org-agenda-check-type t
'agenda
'timeline
)
5777 (org-agenda-check-no-diary)
5778 (let* ((marker (or (get-text-property (point) 'org-marker
)
5779 (org-agenda-error)))
5780 (buffer (marker-buffer marker
))
5781 (pos (marker-position marker
)))
5782 (org-with-remote-undo buffer
5783 (with-current-buffer buffer
5786 (if (not (org-at-timestamp-p))
5787 (error "Cannot find time stamp"))
5788 (org-timestamp-change arg
(or what
'day
)))
5789 (org-agenda-show-new-time marker org-last-changed-timestamp
))
5790 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
5792 (defun org-agenda-date-earlier (arg &optional what
)
5793 "Change the date of this item to one day earlier."
5795 (org-agenda-date-later (- arg
) what
))
5797 (defun org-agenda-date-later-minutes (arg)
5798 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5800 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5801 (org-agenda-date-later arg
'minute
))
5803 (defun org-agenda-date-earlier-minutes (arg)
5804 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5806 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5807 (org-agenda-date-earlier arg
'minute
))
5809 (defun org-agenda-date-later-hours (arg)
5810 "Change the time of this item, in hour steps."
5812 (org-agenda-date-later arg
'hour
))
5814 (defun org-agenda-date-earlier-hours (arg)
5815 "Change the time of this item, in hour steps."
5817 (org-agenda-date-earlier arg
'hour
))
5819 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
5820 "Show new date stamp via text properties."
5821 ;; We use text properties to make this undoable
5822 (let ((inhibit-read-only t
)
5823 (buffer-invisibility-spec))
5824 (setq stamp
(concat " " prefix
" => " stamp
))
5826 (goto-char (point-max))
5828 (when (equal marker
(get-text-property (point) 'org-marker
))
5829 (org-move-to-column (- (window-width) (length stamp
)) t
)
5830 (org-agenda-fix-tags-filter-overlays-at (point))
5831 (if (featurep 'xemacs
)
5832 ;; Use `duplicable' property to trigger undo recording
5833 (let ((ex (make-extent nil nil
))
5834 (gl (make-glyph stamp
)))
5835 (set-glyph-face gl
'secondary-selection
)
5836 (set-extent-properties
5837 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
5838 (insert-extent ex
(1- (point)) (point-at-eol)))
5839 (add-text-properties
5840 (1- (point)) (point-at-eol)
5841 (list 'display
(org-add-props stamp nil
5842 'face
'secondary-selection
))))
5843 (beginning-of-line 1))
5844 (beginning-of-line 0)))))
5846 (defun org-agenda-date-prompt (arg)
5847 "Change the date of this item. Date is prompted for, with default today.
5848 The prefix ARG is passed to the `org-time-stamp' command and can therefore
5849 be used to request time specification in the time stamp."
5851 (org-agenda-check-type t
'agenda
'timeline
)
5852 (org-agenda-check-no-diary)
5853 (let* ((marker (or (get-text-property (point) 'org-marker
)
5854 (org-agenda-error)))
5855 (buffer (marker-buffer marker
))
5856 (pos (marker-position marker
)))
5857 (org-with-remote-undo buffer
5858 (with-current-buffer buffer
5861 (if (not (org-at-timestamp-p))
5862 (error "Cannot find time stamp"))
5863 (org-time-stamp arg
)
5864 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
5866 (defun org-agenda-schedule (arg)
5867 "Schedule the item at point."
5869 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
5870 (org-agenda-check-no-diary)
5871 (let* ((marker (or (get-text-property (point) 'org-marker
)
5872 (org-agenda-error)))
5873 (type (marker-insertion-type marker
))
5874 (buffer (marker-buffer marker
))
5875 (pos (marker-position marker
))
5876 (org-insert-labeled-timestamps-at-point nil
)
5878 (set-marker-insertion-type marker t
)
5879 (org-with-remote-undo buffer
5880 (with-current-buffer buffer
5883 (setq ts
(org-schedule arg
)))
5884 (org-agenda-show-new-time marker ts
"S"))
5885 (message "Item scheduled for %s" ts
)))
5887 (defun org-agenda-deadline (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 (buffer (marker-buffer marker
))
5895 (pos (marker-position marker
))
5896 (org-insert-labeled-timestamps-at-point nil
)
5898 (org-with-remote-undo buffer
5899 (with-current-buffer buffer
5902 (setq ts
(org-deadline arg
)))
5903 (org-agenda-show-new-time marker ts
"S"))
5904 (message "Deadline for this item set to %s" ts
)))
5906 (defun org-agenda-action ()
5907 "Select entry for agenda action, or execute an agenda action.
5908 This command prompts for another letter. Valid inputs are:
5910 m Mark the entry at point for an agenda action
5911 s Schedule the marked entry to the date at the cursor
5912 d Set the deadline of the marked entry to the date at the cursor
5913 r Call `org-remember' with cursor date as the default date
5914 SPC Show marked entry in other window
5915 TAB Visit marked entry in other window
5917 The cursor may be at a date in the calendar, or in the Org agenda."
5920 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
5921 (setq ans
(read-char-exclusive))
5925 (if (eq major-mode
'org-agenda-mode
)
5926 (let ((m (or (get-text-property (point) 'org-hd-marker
)
5927 (get-text-property (point) 'org-marker
))))
5930 (move-marker org-agenda-action-marker
5931 (marker-position m
) (marker-buffer m
))
5932 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
5933 (error "Don't know which entry to mark")))
5934 (error "This command works only in the agenda")))
5936 (org-agenda-do-action '(org-schedule nil org-overriding-default-time
)))
5938 (org-agenda-do-action '(org-deadline nil org-overriding-default-time
)))
5940 (org-agenda-do-action '(org-remember) t
))
5942 (let ((cw (selected-window)))
5943 (org-switch-to-buffer-other-window
5944 (marker-buffer org-agenda-action-marker
))
5945 (goto-char org-agenda-action-marker
)
5946 (org-show-context 'agenda
)
5947 (select-window cw
)))
5949 (org-switch-to-buffer-other-window
5950 (marker-buffer org-agenda-action-marker
))
5951 (goto-char org-agenda-action-marker
)
5952 (org-show-context 'agenda
))
5953 (t (error "Invalid agenda action %c" ans
)))))
5955 (defun org-agenda-do-action (form &optional current-buffer
)
5956 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
5957 (let ((org-overriding-default-time (org-get-cursor-date)))
5960 (if (not (marker-buffer org-agenda-action-marker
))
5961 (error "No entry has bee selected for agenda action")
5962 (with-current-buffer (marker-buffer org-agenda-action-marker
)
5966 (goto-char org-agenda-action-marker
)
5969 (defun org-agenda-clock-in (&optional arg
)
5970 "Start the clock on the currently selected item."
5972 (org-agenda-check-no-diary)
5973 (if (equal arg
'(4))
5975 (let* ((marker (or (get-text-property (point) 'org-marker
)
5976 (org-agenda-error)))
5977 (hdmarker (or (get-text-property (point) 'org-hd-marker
)
5979 (pos (marker-position marker
))
5981 (org-with-remote-undo (marker-buffer marker
)
5982 (with-current-buffer (marker-buffer marker
)
5985 (org-show-context 'agenda
)
5987 (org-cycle-hide-drawers 'children
)
5989 (setq newhead
(org-get-heading)))
5990 (org-agenda-change-all-lines newhead hdmarker t
)))))
5992 (defun org-agenda-clock-out (&optional arg
)
5993 "Stop the currently running clock."
5995 (unless (marker-buffer org-clock-marker
)
5996 (error "No running clock"))
5997 (org-with-remote-undo (marker-buffer org-clock-marker
)
6000 (defun org-agenda-clock-cancel (&optional arg
)
6001 "Cancel the currently running clock."
6003 (unless (marker-buffer org-clock-marker
)
6004 (error "No running clock"))
6005 (org-with-remote-undo (marker-buffer org-clock-marker
)
6006 (org-clock-cancel)))
6008 (defun org-agenda-diary-entry ()
6009 "Make a diary entry, like the `i' command from the calendar.
6010 All the standard commands work: block, weekly etc."
6012 (org-agenda-check-type t
'agenda
'timeline
)
6013 (require 'diary-lib
)
6015 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6016 (read-char-exclusive)))
6017 (cmd (cdr (assoc char
6018 '((?d . insert-diary-entry
)
6019 (?w . insert-weekly-diary-entry
)
6020 (?m . insert-monthly-diary-entry
)
6021 (?y . insert-yearly-diary-entry
)
6022 (?a . insert-anniversary-diary-entry
)
6023 (?b . insert-block-diary-entry
)
6024 (?c . insert-cyclic-diary-entry
)))))
6025 (oldf (symbol-function 'calendar-cursor-to-date
))
6026 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6028 (mark (or (mark t
) (point))))
6030 (error "No command associated with <%c>" char
))
6031 (unless (and (get-text-property point
'day
)
6032 (or (not (equal ?b char
))
6033 (get-text-property mark
'day
)))
6034 (error "Don't know which date to use for diary entry"))
6035 ;; We implement this by hacking the `calendar-cursor-to-date' function
6036 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6037 (let ((calendar-mark-ring
6038 (list (calendar-gregorian-from-absolute
6039 (or (get-text-property mark
'day
)
6040 (get-text-property point
'day
))))))
6043 (fset 'calendar-cursor-to-date
6044 (lambda (&optional error dummy
)
6045 (calendar-gregorian-from-absolute
6046 (get-text-property point
'day
))))
6047 (call-interactively cmd
))
6048 (fset 'calendar-cursor-to-date oldf
)))))
6050 (defun org-agenda-execute-calendar-command (cmd)
6051 "Execute a calendar command from the agenda, with the date associated to
6052 the cursor position."
6053 (org-agenda-check-type t
'agenda
'timeline
)
6054 (require 'diary-lib
)
6055 (unless (get-text-property (point) 'day
)
6056 (error "Don't know which date to use for calendar command"))
6057 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
6059 (date (calendar-gregorian-from-absolute
6060 (get-text-property point
'day
)))
6061 ;; the following 2 vars are needed in the calendar
6062 (displayed-month (car date
))
6063 (displayed-year (nth 2 date
)))
6066 (fset 'calendar-cursor-to-date
6067 (lambda (&optional error dummy
)
6068 (calendar-gregorian-from-absolute
6069 (get-text-property point
'day
))))
6070 (call-interactively cmd
))
6071 (fset 'calendar-cursor-to-date oldf
))))
6073 (defun org-agenda-phases-of-moon ()
6074 "Display the phases of the moon for the 3 months around the cursor date."
6076 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
6078 (defun org-agenda-holidays ()
6079 "Display the holidays for the 3 months around the cursor date."
6081 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
6083 (defvar calendar-longitude
)
6084 (defvar calendar-latitude
)
6085 (defvar calendar-location-name
)
6087 (defun org-agenda-sunrise-sunset (arg)
6088 "Display sunrise and sunset for the cursor date.
6089 Latitude and longitude can be specified with the variables
6090 `calendar-latitude' and `calendar-longitude'. When called with prefix
6091 argument, latitude and longitude will be prompted for."
6094 (let ((calendar-longitude (if arg nil calendar-longitude
))
6095 (calendar-latitude (if arg nil calendar-latitude
))
6096 (calendar-location-name
6097 (if arg
"the given coordinates" calendar-location-name
)))
6098 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
6100 (defun org-agenda-goto-calendar ()
6101 "Open the Emacs calendar with the date at the cursor."
6103 (org-agenda-check-type t
'agenda
'timeline
)
6104 (let* ((day (or (get-text-property (point) 'day
)
6105 (error "Don't know which date to open in calendar")))
6106 (date (calendar-gregorian-from-absolute day
))
6107 (calendar-move-hook nil
)
6108 (calendar-view-holidays-initially-flag nil
)
6109 (calendar-view-diary-initially-flag nil
)
6110 (view-calendar-holidays-initially nil
)
6111 (view-diary-entries-initially nil
))
6113 (calendar-goto-date date
)))
6116 (defun org-calendar-goto-agenda ()
6117 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6118 This is a command that has to be installed in `calendar-mode-map'."
6120 (org-agenda-list nil
(calendar-absolute-from-gregorian
6121 (calendar-cursor-to-date))
6124 (defun org-agenda-convert-date ()
6126 (org-agenda-check-type t
'agenda
'timeline
)
6127 (let ((day (get-text-property (point) 'day
))
6130 (error "Don't know which date to convert"))
6131 (setq date
(calendar-gregorian-from-absolute day
))
6133 "Gregorian: " (calendar-date-string date
) "\n"
6134 "ISO: " (calendar-iso-date-string date
) "\n"
6135 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
6136 "Julian: " (calendar-julian-date-string date
) "\n"
6137 "Astron. JD: " (calendar-astro-date-string date
)
6138 " (Julian date number at noon UTC)\n"
6139 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
6140 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
6141 "French: " (calendar-french-date-string date
) "\n"
6142 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
6143 "Mayan: " (calendar-mayan-date-string date
) "\n"
6144 "Coptic: " (calendar-coptic-date-string date
) "\n"
6145 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
6146 "Persian: " (calendar-persian-date-string date
) "\n"
6147 "Chinese: " (calendar-chinese-date-string date
) "\n"))
6148 (with-output-to-temp-buffer "*Dates*"
6150 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6152 ;;; Appointment reminders
6154 (defvar appt-time-msg-list
)
6157 (defun org-agenda-to-appt (&optional refresh filter
)
6158 "Activate appointments found in `org-agenda-files'.
6159 With a \\[universal-argument] prefix, refresh the list of
6162 If FILTER is t, interactively prompt the user for a regular
6163 expression, and filter out entries that don't match it.
6165 If FILTER is a string, use this string as a regular expression
6166 for filtering entries out.
6168 FILTER can also be an alist with the car of each cell being
6169 either 'headline or 'category. For example:
6171 '((headline \"IMPORTANT\")
6172 (category \"Work\"))
6174 will only add headlines containing IMPORTANT or headlines
6175 belonging to the \"Work\" category."
6178 (if refresh
(setq appt-time-msg-list nil
))
6180 (setq filter
(read-from-minibuffer "Regexp filter: ")))
6181 (let* ((cnt 0) ; count added events
6182 (org-agenda-new-buffers nil
)
6183 (org-deadline-warning-days 0)
6184 (today (org-date-to-gregorian
6185 (time-to-days (current-time))))
6186 (files (org-agenda-files 'unrestricted
)) entries file
)
6187 ;; Get all entries which may contain an appt
6188 (org-prepare-agenda-buffers files
)
6189 (while (setq file
(pop files
))
6192 (org-agenda-get-day-entries
6193 file today
:timestamp
:scheduled
:deadline
))))
6194 (setq entries
(delq nil entries
))
6195 ;; Map thru entries and find if we should filter them out
6198 (let* ((evt (org-trim (or (get-text-property 1 'txt x
) "")))
6199 (cat (get-text-property 1 'org-category x
))
6200 (tod (get-text-property 1 'time-of-day x
))
6201 (ok (or (null filter
)
6202 (and (stringp filter
) (string-match filter evt
))
6205 (cadr (assoc 'category filter
)) cat
)
6207 (cadr (assoc 'headline filter
)) evt
))))))
6208 ;; FIXME: Shall we remove text-properties for the appt text?
6209 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
6211 (setq tod
(concat "00" (number-to-string tod
))
6212 tod
(when (string-match
6213 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod
)
6214 (concat (match-string 1 tod
) ":"
6215 (match-string 2 tod
))))
6217 (setq cnt
(1+ cnt
))))) entries
)
6218 (org-release-buffers org-agenda-new-buffers
)
6220 (message "No event to add")
6221 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
6223 (defun org-agenda-todayp (date)
6224 "Does DATE mean today, when considering `org-extend-today-until'?"
6226 (if (listp date
) (setq date
(calendar-absolute-from-gregorian date
)))
6227 (setq today
(calendar-absolute-from-gregorian (calendar-current-date)))
6228 (setq h
(nth 2 (decode-time (current-time))))
6229 (or (and (>= h org-extend-today-until
)
6231 (and (< h org-extend-today-until
)
6232 (= date
(1- today
))))))
6234 (provide 'org-agenda
)
6236 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
6238 ;;; org-agenda.el ends here