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-start-with-clockreport-mode nil
775 "The initial value of clockreport-mode in a newly created agenda window."
776 :group
'org-agenda-startup
777 :group
'org-agenda-daily
/weekly
780 (defcustom org-agenda-clockreport-parameter-plist
'(:link t
:maxlevel
2)
781 "Property list with parameters for the clocktable in clockreport mode.
782 This is the display mode that shows a clock table in the daily/weekly
783 agenda, the properties for this dynamic block can be set here.
784 The usual clocktable parameters are allowed here, but you cannot set
785 the properties :name, :tstart, :tend, :block, and :scope - these will
786 be overwritten to make sure the content accurately reflects the
787 current display in the agenda."
788 :group
'org-agenda-daily
/weekly
792 (defgroup org-agenda-time-grid nil
793 "Options concerning the time grid in the Org-mode Agenda."
794 :tag
"Org Agenda Time Grid"
797 (defcustom org-agenda-search-headline-for-time t
798 "Non-nil means, search headline for a time-of-day.
799 If the headline contains a time-of-day in one format or another, it will
800 be used to sort the entry into the time sequence of items for a day.
801 Some people have time stamps in the headline that refer to the creation
802 time or so, and then this produces an unwanted side effect. If this is
803 the case for your, use this variable to turn off searching the headline
805 :group
'org-agenda-time-grid
808 (defcustom org-agenda-use-time-grid t
809 "Non-nil means, show a time grid in the agenda schedule.
810 A time grid is a set of lines for specific times (like every two hours between
811 8:00 and 20:00). The items scheduled for a day at specific times are
812 sorted in between these lines.
813 For details about when the grid will be shown, and what it will look like, see
814 the variable `org-agenda-time-grid'."
815 :group
'org-agenda-time-grid
818 (defcustom org-agenda-time-grid
819 '((daily today require-timed
)
821 (800 1000 1200 1400 1600 1800 2000))
823 "The settings for time grid for agenda display.
824 This is a list of three items. The first item is again a list. It contains
825 symbols specifying conditions when the grid should be displayed:
827 daily if the agenda shows a single day
828 weekly if the agenda shows an entire week
829 today show grid on current date, independent of daily/weekly display
830 require-timed show grid only if at least one item has a time specification
832 The second item is a string which will be placed behind the grid time.
834 The third item is a list of integers, indicating the times that should have
836 :group
'org-agenda-time-grid
839 (set :greedy t
:tag
"Grid Display Options"
840 (const :tag
"Show grid in single day agenda display" daily
)
841 (const :tag
"Show grid in weekly agenda display" weekly
)
842 (const :tag
"Always show grid for today" today
)
843 (const :tag
"Show grid only if any timed entries are present"
845 (const :tag
"Skip grid times already present in an entry"
847 (string :tag
"Grid String")
848 (repeat :tag
"Grid Times" (integer :tag
"Time"))))
850 (defgroup org-agenda-sorting nil
851 "Options concerning sorting in the Org-mode Agenda."
852 :tag
"Org Agenda Sorting"
855 (defcustom org-agenda-sorting-strategy
856 '((agenda time-up priority-down category-keep
)
857 (todo priority-down category-keep
)
858 (tags priority-down category-keep
)
859 (search category-keep
))
860 "Sorting structure for the agenda items of a single day.
861 This is a list of symbols which will be used in sequence to determine
862 if an entry should be listed before another entry. The following
863 symbols are recognized:
865 time-up Put entries with time-of-day indications first, early first
866 time-down Put entries with time-of-day indications first, late first
867 category-keep Keep the default order of categories, corresponding to the
868 sequence in `org-agenda-files'.
869 category-up Sort alphabetically by category, A-Z.
870 category-down Sort alphabetically by category, Z-A.
871 tag-up Sort alphabetically by last tag, A-Z.
872 tag-down Sort alphabetically by last tag, Z-A.
873 priority-up Sort numerically by priority, high priority last.
874 priority-down Sort numerically by priority, high priority first.
875 todo-state-up Sort by todo state, tasks that are done last.
876 todo-state-down Sort by todo state, tasks that are done first.
877 effort-up Sort numerically by estimated effort, high effort last.
878 effort-down Sort numerically by estimated effort, high effort first.
879 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
880 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
882 The different possibilities will be tried in sequence, and testing stops
883 if one comparison returns a \"not-equal\". For example, the default
884 '(time-up category-keep priority-down)
885 means: Pull out all entries having a specified time of day and sort them,
886 in order to make a time schedule for the current day the first thing in the
887 agenda listing for the day. Of the entries without a time indication, keep
888 the grouped in categories, don't sort the categories, but keep them in
889 the sequence given in `org-agenda-files'. Within each category sort by
892 Leaving out `category-keep' would mean that items will be sorted across
893 categories by priority.
895 Instead of a single list, this can also be a set of list for specific
896 contents, with a context symbol in the car of the list, any of
897 `agenda', `todo', `tags' for the corresponding agenda views.
899 Custom commands can bind this variable in the options section."
900 :group
'org-agenda-sorting
902 (repeat :tag
"General" ,org-sorting-choice
)
903 (list :tag
"Individually"
904 (cons (const :tag
"Strategy for Weekly/Daily agenda" agenda
)
905 (repeat ,org-sorting-choice
))
906 (cons (const :tag
"Strategy for TODO lists" todo
)
907 (repeat ,org-sorting-choice
))
908 (cons (const :tag
"Strategy for Tags matches" tags
)
909 (repeat ,org-sorting-choice
)))))
911 (defcustom org-agenda-cmp-user-defined nil
912 "A function to define the comparison `user-defined'.
913 This function must receive two arguments, agenda entry a and b.
914 If a>b, return +1. If a<b, return -1. If they are equal as seen by
915 the user comparison, return nil.
916 When this is defined, you can make `user-defined-up' and `user-defined-down'
917 part of an agenda sorting strategy."
918 :group
'org-agenda-sorting
921 (defcustom org-sort-agenda-notime-is-late t
922 "Non-nil means, items without time are considered late.
923 This is only relevant for sorting. When t, items which have no explicit
924 time like 15:30 will be considered as 99:01, i.e. later than any items which
925 do have a time. When nil, the default time is before 0:00. You can use this
926 option to decide if the schedule for today should come before or after timeless
928 :group
'org-agenda-sorting
931 (defcustom org-sort-agenda-noeffort-is-high t
932 "Non-nil means, items without effort estimate are sorted as high effort.
933 This also applies when filtering an agenda view with respect to the
934 < or > effort operator. Then, tasks with no effort defined will be treated
935 as tasks with high effort.
936 When nil, such items are sorted as 0 minutes effort."
937 :group
'org-agenda-sorting
940 (defgroup org-agenda-line-format nil
941 "Options concerning the entry prefix in the Org-mode agenda display."
942 :tag
"Org Agenda Line Format"
945 (defcustom org-agenda-prefix-format
946 '((agenda .
" %-12:c%?-12t% s")
950 (search .
" %-12:c"))
951 "Format specifications for the prefix of items in the agenda views.
952 An alist with four entries, for the different agenda types. The keys to the
953 sublists are `agenda', `timeline', `todo', and `tags'. The values
955 This format works similar to a printf format, with the following meaning:
957 %c the category of the item, \"Diary\" for entries from the diary, or
958 as given by the CATEGORY keyword or derived from the file name.
959 %T the *last* tag of the item. Last because inherited tags come
961 %t the time-of-day specification if one applies to the entry, in the
963 %s Scheduling/Deadline information, a short string
965 All specifiers work basically like the standard `%s' of printf, but may
966 contain two additional characters: A question mark just after the `%' and
967 a whitespace/punctuation character just before the final letter.
969 If the first character after `%' is a question mark, the entire field
970 will only be included if the corresponding value applies to the
971 current entry. This is useful for fields which should have fixed
972 width when present, but zero width when absent. For example,
973 \"%?-12t\" will result in a 12 character time field if a time of the
974 day is specified, but will completely disappear in entries which do
977 If there is punctuation or whitespace character just before the final
978 format letter, this character will be appended to the field value if
979 the value is not empty. For example, the format \"%-12:c\" leads to
980 \"Diary: \" if the category is \"Diary\". If the category were be
981 empty, no additional colon would be interted.
983 The default value of this option is \" %-12:c%?-12t% s\", meaning:
984 - Indent the line with two space characters
985 - Give the category in a 12 chars wide field, padded with whitespace on
986 the right (because of `-'). Append a colon if there is a category
988 - If there is a time-of-day, put it into a 12 chars wide field. If no
989 time, don't put in an empty field, just skip it (because of '?').
990 - Finally, put the scheduling information and append a whitespace.
992 As another example, if you don't want the time-of-day of entries in
993 the prefix, you could use:
995 (setq org-agenda-prefix-format \" %-11:c% s\")
997 See also the variables `org-agenda-remove-times-when-in-prefix' and
998 `org-agenda-remove-tags'.
1000 Custom commands can set this variable in the options section."
1002 (string :tag
"General format")
1003 (list :greedy t
:tag
"View dependent"
1004 (cons (const agenda
) (string :tag
"Format"))
1005 (cons (const timeline
) (string :tag
"Format"))
1006 (cons (const todo
) (string :tag
"Format"))
1007 (cons (const tags
) (string :tag
"Format"))
1008 (cons (const search
) (string :tag
"Format"))))
1009 :group
'org-agenda-line-format
)
1011 (defvar org-prefix-format-compiled nil
1012 "The compiled version of the most recently used prefix format.
1013 See the variable `org-agenda-prefix-format'.")
1015 (defcustom org-agenda-todo-keyword-format
"%-1s"
1016 "Format for the TODO keyword in agenda lines.
1017 Set this to something like \"%-12s\" if you want all TODO keywords
1018 to occupy a fixed space in the agenda display."
1019 :group
'org-agenda-line-format
1022 (defcustom org-agenda-timerange-leaders
'("" "(%d/%d): ")
1023 "Text preceding timerange entries in the agenda view.
1024 This is a list with two strings. The first applies when the range
1025 is entirely on one day. The second applies if the range spans several days.
1026 The strings may have two \"%d\" format specifiers which will be filled
1027 with the sequence number of the days, and the total number of days in the
1028 range, respectively."
1029 :group
'org-agenda-line-format
1031 (string :tag
"Deadline today ")
1032 (choice :tag
"Deadline relative"
1033 (string :tag
"Format string")
1036 (defcustom org-agenda-scheduled-leaders
'("Scheduled: " "Sched.%2dx: ")
1037 "Text preceeding scheduled items in the agenda view.
1038 This is a list with two strings. The first applies when the item is
1039 scheduled on the current day. The second applies when it has been scheduled
1040 previously, it may contain a %d indicating that this is the nth time that
1041 this item is scheduled, due to automatic rescheduling of unfinished items
1042 for the following day. So this number is one larger than the number of days
1043 that passed since this item was scheduled first."
1044 :group
'org-agenda-line-format
1046 (string :tag
"Scheduled today ")
1047 (string :tag
"Scheduled previously")))
1049 (defcustom org-agenda-deadline-leaders
'("Deadline: " "In %3d d.: ")
1050 "Text preceeding deadline items in the agenda view.
1051 This is a list with two strings. The first applies when the item has its
1052 deadline on the current day. The second applies when it is in the past or
1053 in the future, it may contain %d to capture how many days away the deadline
1055 :group
'org-agenda-line-format
1057 (string :tag
"Deadline today ")
1058 (choice :tag
"Deadline relative"
1059 (string :tag
"Format string")
1062 (defcustom org-agenda-remove-times-when-in-prefix t
1063 "Non-nil means, remove duplicate time specifications in agenda items.
1064 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1065 time-of-day specification in a headline or diary entry is extracted and
1066 placed into the prefix. If this option is non-nil, the original specification
1067 \(a timestamp or -range, or just a plain time(range) specification like
1068 11:30-4pm) will be removed for agenda display. This makes the agenda less
1070 The option can be t or nil. It may also be the symbol `beg', indicating
1071 that the time should only be removed what it is located at the beginning of
1072 the headline/diary entry."
1073 :group
'org-agenda-line-format
1075 (const :tag
"Always" t
)
1076 (const :tag
"Never" nil
)
1077 (const :tag
"When at beginning of entry" beg
)))
1080 (defcustom org-agenda-default-appointment-duration nil
1081 "Default duration for appointments that only have a starting time.
1082 When nil, no duration is specified in such cases.
1083 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1084 :group
'org-agenda-line-format
1086 (integer :tag
"Minutes")
1087 (const :tag
"No default duration")))
1089 (defcustom org-agenda-show-inherited-tags t
1090 "Non-nil means, show inherited tags in each agenda line."
1091 :group
'org-agenda-line-format
1094 (defcustom org-agenda-remove-tags nil
1095 "Non-nil means, remove the tags from the headline copy in the agenda.
1096 When this is the symbol `prefix', only remove tags when
1097 `org-agenda-prefix-format' contains a `%T' specifier."
1098 :group
'org-agenda-line-format
1100 (const :tag
"Always" t
)
1101 (const :tag
"Never" nil
)
1102 (const :tag
"When prefix format contains %T" prefix
)))
1104 (if (fboundp 'defvaralias
)
1105 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1106 'org-agenda-remove-tags
))
1108 (defcustom org-agenda-tags-column
(if (featurep 'xemacs
) -
79 -
80)
1109 "Shift tags in agenda items to this column.
1110 If this number is positive, it specifies the column. If it is negative,
1111 it means that the tags should be flushright to that column. For example,
1112 -80 works well for a normal 80 character screen."
1113 :group
'org-agenda-line-format
1116 (if (fboundp 'defvaralias
)
1117 (defvaralias 'org-agenda-align-tags-to-column
'org-agenda-tags-column
))
1119 (defcustom org-agenda-fontify-priorities
'cookies
1120 "Non-nil means, highlight low and high priorities in agenda.
1121 When t, the highest priority entries are bold, lowest priority italic.
1122 However, settings in org-priority-faces will overrule these faces.
1123 When this variable is the symbol `cookies', only fontify the
1124 cookies, not the entire task.
1125 This may also be an association list of priority faces, whose
1126 keys are the character values of `org-highest-priority',
1127 `org-default-priority', and `org-lowest-priority' (the default values
1128 are ?A, ?B, and ?C, respectively). The face may be a named face,
1129 or a list like `(:background \"Red\")'."
1130 :group
'org-agenda-line-format
1132 (const :tag
"Never" nil
)
1133 (const :tag
"Defaults" t
)
1134 (const :tag
"Cookies only" cookies
)
1135 (repeat :tag
"Specify"
1136 (list (character :tag
"Priority" :value ?A
)
1137 (sexp :tag
"face")))))
1139 (defgroup org-agenda-column-view nil
1140 "Options concerning column view in the agenda."
1141 :tag
"Org Agenda Column View"
1144 (defcustom org-agenda-columns-show-summaries t
1145 "Non-nil means, show summaries for columns displayed in the agenda view."
1146 :group
'org-agenda-column-view
1149 (defcustom org-agenda-columns-remove-prefix-from-item t
1150 "Non-nil means, remove the prefix from a headline for agenda column view.
1151 The special ITEM field in the columns format contains the current line, with
1152 all information shown in other columns (like the TODO state or a tag).
1153 When this variable is non-nil, also the agenda prefix will be removed from
1154 the content of the ITEM field, to make sure as much as possible of the
1155 headline can be shown in the limited width of the field."
1159 (defcustom org-agenda-columns-compute-summary-properties t
1160 "Non-nil means, recompute all summary properties before column view.
1161 When column view in the agenda is listing properties that have a summary
1162 operator, it can go to all relevant buffers and recompute the summaries
1163 there. This can mean overhead for the agenda column view, but is necessary
1164 to have thing up to date.
1165 As a special case, a CLOCKSUM property also makes sure that the clock
1166 computations are current."
1167 :group
'org-agenda-column-view
1170 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1171 "Non-nil means, the duration of an appointment will add to day effort.
1172 The property to which appointment durations will be added is the one given
1173 in the option `org-effort-property'. If an appointment does not have
1174 an end time, `org-agenda-default-appointment-duration' will be used. If that
1175 is not set, an appointment without end time will not contribute to the time
1177 :group
'org-agenda-column-view
1184 (defun org-add-agenda-custom-command (entry)
1185 "Replace or add a command in `org-agenda-custom-commands'.
1186 This is mostly for hacking and trying a new command - once the command
1187 works you probably want to add it to `org-agenda-custom-commands' for good."
1188 (let ((ass (assoc (car entry
) org-agenda-custom-commands
)))
1190 (setcdr ass
(cdr entry
))
1191 (push entry org-agenda-custom-commands
))))
1193 ;;; Define the Org-agenda-mode
1195 (defvar org-agenda-mode-map
(make-sparse-keymap)
1196 "Keymap for `org-agenda-mode'.")
1198 (defvar org-agenda-menu
) ; defined later in this file.
1199 (defvar org-agenda-follow-mode nil
)
1200 (defvar org-agenda-clockreport-mode nil
)
1201 (defvar org-agenda-show-log nil
)
1202 (defvar org-agenda-redo-command nil
)
1203 (defvar org-agenda-query-string nil
)
1204 (defvar org-agenda-mode-hook nil
1205 "Hook for org-agenda-mode, run after the mode is turned on.")
1206 (defvar org-agenda-type nil
)
1207 (defvar org-agenda-force-single-file nil
)
1209 (defun org-agenda-mode ()
1210 "Mode for time-sorted view on action items in Org-mode files.
1212 The following commands are available:
1214 \\{org-agenda-mode-map}"
1216 (kill-all-local-variables)
1217 (setq org-agenda-undo-list nil
1218 org-agenda-pending-undo-list nil
)
1219 (setq major-mode
'org-agenda-mode
)
1220 ;; Keep global-font-lock-mode from turning on font-lock-mode
1221 (org-set-local 'font-lock-global-modes
(list 'not major-mode
))
1222 (setq mode-name
"Org-Agenda")
1223 (use-local-map org-agenda-mode-map
)
1224 (easy-menu-add org-agenda-menu
)
1225 (if org-startup-truncated
(setq truncate-lines t
))
1226 (org-add-hook 'post-command-hook
'org-agenda-post-command-hook nil
'local
)
1227 (org-add-hook 'pre-command-hook
'org-unhighlight nil
'local
)
1228 ;; Make sure properties are removed when copying text
1229 (when (boundp 'buffer-substring-filters
)
1230 (org-set-local 'buffer-substring-filters
1232 (set-text-properties 0 (length x
) nil x
) x
)
1233 buffer-substring-filters
)))
1234 (unless org-agenda-keep-modes
1235 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1236 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1237 org-agenda-show-log nil
))
1239 '("Agenda") "Agenda Files"
1243 (if (get 'org-agenda-files
'org-restrict
)
1244 "Restricted to single file"
1246 '(org-edit-agenda-file-list)
1247 (not (get 'org-agenda-files
'org-restrict
)))
1249 (mapcar 'org-file-menu-entry
(org-agenda-files))))
1250 (org-agenda-set-mode-name)
1252 (if (fboundp 'run-mode-hooks
) 'run-mode-hooks
'run-hooks
)
1253 (list 'org-agenda-mode-hook
)))
1255 (substitute-key-definition 'undo
'org-agenda-undo
1256 org-agenda-mode-map global-map
)
1257 (org-defkey org-agenda-mode-map
"\C-i" 'org-agenda-goto
)
1258 (org-defkey org-agenda-mode-map
[(tab)] 'org-agenda-goto
)
1259 (org-defkey org-agenda-mode-map
"\C-m" 'org-agenda-switch-to
)
1260 (org-defkey org-agenda-mode-map
"\C-k" 'org-agenda-kill
)
1261 (org-defkey org-agenda-mode-map
"\C-c$" 'org-agenda-archive
)
1262 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-s" 'org-agenda-archive
)
1263 (org-defkey org-agenda-mode-map
"$" 'org-agenda-archive
)
1264 (org-defkey org-agenda-mode-map
"A" 'org-agenda-archive-to-archive-sibling
)
1265 (org-defkey org-agenda-mode-map
"\C-c\C-o" 'org-agenda-open-link
)
1266 (org-defkey org-agenda-mode-map
" " 'org-agenda-show
)
1267 (org-defkey org-agenda-mode-map
"\C-c\C-t" 'org-agenda-todo
)
1268 (org-defkey org-agenda-mode-map
[(control shift right
)] 'org-agenda-todo-nextset
)
1269 (org-defkey org-agenda-mode-map
[(control shift left
)] 'org-agenda-todo-previousset
)
1270 (org-defkey org-agenda-mode-map
"\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer
)
1271 (org-defkey org-agenda-mode-map
"b" 'org-agenda-tree-to-indirect-buffer
)
1272 (org-defkey org-agenda-mode-map
"o" 'delete-other-windows
)
1273 (org-defkey org-agenda-mode-map
"L" 'org-agenda-recenter
)
1274 (org-defkey org-agenda-mode-map
"t" 'org-agenda-todo
)
1275 (org-defkey org-agenda-mode-map
"a" 'org-agenda-toggle-archive-tag
)
1276 (org-defkey org-agenda-mode-map
":" 'org-agenda-set-tags
)
1277 (org-defkey org-agenda-mode-map
"\C-c\C-q" 'org-agenda-set-tags
)
1278 (org-defkey org-agenda-mode-map
"." 'org-agenda-goto-today
)
1279 (org-defkey org-agenda-mode-map
"j" 'org-agenda-goto-date
)
1280 (org-defkey org-agenda-mode-map
"d" 'org-agenda-day-view
)
1281 (org-defkey org-agenda-mode-map
"w" 'org-agenda-week-view
)
1282 (org-defkey org-agenda-mode-map
"m" 'org-agenda-month-view
)
1283 (org-defkey org-agenda-mode-map
"y" 'org-agenda-year-view
)
1284 (org-defkey org-agenda-mode-map
"\C-c\C-z" 'org-agenda-add-note
)
1285 (org-defkey org-agenda-mode-map
"z" 'org-agenda-add-note
)
1286 (org-defkey org-agenda-mode-map
"k" 'org-agenda-action
)
1287 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-k" 'org-agenda-action
)
1288 (org-defkey org-agenda-mode-map
[(shift right
)] 'org-agenda-do-date-later
)
1289 (org-defkey org-agenda-mode-map
[(shift left
)] 'org-agenda-do-date-earlier
)
1290 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(right)] 'org-agenda-do-date-later
)
1291 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(left)] 'org-agenda-do-date-earlier
)
1293 (org-defkey org-agenda-mode-map
">" 'org-agenda-date-prompt
)
1294 (org-defkey org-agenda-mode-map
"\C-c\C-s" 'org-agenda-schedule
)
1295 (org-defkey org-agenda-mode-map
"\C-c\C-d" 'org-agenda-deadline
)
1296 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1297 (while l
(org-defkey org-agenda-mode-map
1298 (int-to-string (pop l
)) 'digit-argument
)))
1300 (org-defkey org-agenda-mode-map
"f" 'org-agenda-follow-mode
)
1301 (org-defkey org-agenda-mode-map
"R" 'org-agenda-clockreport-mode
)
1302 (org-defkey org-agenda-mode-map
"l" 'org-agenda-log-mode
)
1303 (org-defkey org-agenda-mode-map
"v" 'org-agenda-archives-mode
)
1304 (org-defkey org-agenda-mode-map
"D" 'org-agenda-toggle-diary
)
1305 (org-defkey org-agenda-mode-map
"G" 'org-agenda-toggle-time-grid
)
1306 (org-defkey org-agenda-mode-map
"r" 'org-agenda-redo
)
1307 (org-defkey org-agenda-mode-map
"g" 'org-agenda-redo
)
1308 (org-defkey org-agenda-mode-map
"e" 'org-agenda-execute
)
1309 (org-defkey org-agenda-mode-map
"q" 'org-agenda-quit
)
1310 (org-defkey org-agenda-mode-map
"x" 'org-agenda-exit
)
1311 (org-defkey org-agenda-mode-map
"\C-x\C-w" 'org-write-agenda
)
1312 (org-defkey org-agenda-mode-map
"s" 'org-save-all-org-buffers
)
1313 (org-defkey org-agenda-mode-map
"\C-x\C-s" 'org-save-all-org-buffers
)
1314 (org-defkey org-agenda-mode-map
"P" 'org-agenda-show-priority
)
1315 (org-defkey org-agenda-mode-map
"T" 'org-agenda-show-tags
)
1316 (org-defkey org-agenda-mode-map
"n" 'next-line
)
1317 (org-defkey org-agenda-mode-map
"p" 'previous-line
)
1318 (org-defkey org-agenda-mode-map
"\C-c\C-a" 'org-attach
)
1319 (org-defkey org-agenda-mode-map
"\C-c\C-n" 'org-agenda-next-date-line
)
1320 (org-defkey org-agenda-mode-map
"\C-c\C-p" 'org-agenda-previous-date-line
)
1321 (org-defkey org-agenda-mode-map
"," 'org-agenda-priority
)
1322 (org-defkey org-agenda-mode-map
"\C-c," 'org-agenda-priority
)
1323 (org-defkey org-agenda-mode-map
"i" 'org-agenda-diary-entry
)
1324 (org-defkey org-agenda-mode-map
"c" 'org-agenda-goto-calendar
)
1325 (org-defkey org-agenda-mode-map
"C" 'org-agenda-convert-date
)
1326 (org-defkey org-agenda-mode-map
"M" 'org-agenda-phases-of-moon
)
1327 (org-defkey org-agenda-mode-map
"S" 'org-agenda-sunrise-sunset
)
1328 (org-defkey org-agenda-mode-map
"h" 'org-agenda-holidays
)
1329 (org-defkey org-agenda-mode-map
"H" 'org-agenda-holidays
)
1330 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-i" 'org-agenda-clock-in
)
1331 (org-defkey org-agenda-mode-map
"I" 'org-agenda-clock-in
)
1332 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-o" 'org-agenda-clock-out
)
1333 (org-defkey org-agenda-mode-map
"O" 'org-agenda-clock-out
)
1334 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-x" 'org-agenda-clock-cancel
)
1335 (org-defkey org-agenda-mode-map
"X" 'org-agenda-clock-cancel
)
1336 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-j" 'org-clock-goto
)
1337 (org-defkey org-agenda-mode-map
"J" 'org-clock-goto
)
1338 (org-defkey org-agenda-mode-map
"+" 'org-agenda-priority-up
)
1339 (org-defkey org-agenda-mode-map
"-" 'org-agenda-priority-down
)
1340 (org-defkey org-agenda-mode-map
[(shift up
)] 'org-agenda-priority-up
)
1341 (org-defkey org-agenda-mode-map
[(shift down
)] 'org-agenda-priority-down
)
1342 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(up)] 'org-agenda-priority-up
)
1343 (org-defkey org-agenda-mode-map
[?\C-c ?\C-x
(down)] 'org-agenda-priority-down
)
1344 (org-defkey org-agenda-mode-map
[(right)] 'org-agenda-later
)
1345 (org-defkey org-agenda-mode-map
[(left)] 'org-agenda-earlier
)
1346 (org-defkey org-agenda-mode-map
"\C-c\C-x\C-c" 'org-agenda-columns
)
1348 (org-defkey org-agenda-mode-map
"[" 'org-agenda-manipulate-query-add
)
1349 (org-defkey org-agenda-mode-map
"]" 'org-agenda-manipulate-query-subtract
)
1350 (org-defkey org-agenda-mode-map
"{" 'org-agenda-manipulate-query-add-re
)
1351 (org-defkey org-agenda-mode-map
"}" 'org-agenda-manipulate-query-subtract-re
)
1352 (org-defkey org-agenda-mode-map
"/" 'org-agenda-filter-by-tag
)
1353 (org-defkey org-agenda-mode-map
"\\" 'org-agenda-filter-by-tag-refine
)
1355 (defvar org-agenda-keymap
(copy-keymap org-agenda-mode-map
)
1356 "Local keymap for agenda entries from Org-mode.")
1358 (org-defkey org-agenda-keymap
1359 (if (featurep 'xemacs
) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse
)
1360 (org-defkey org-agenda-keymap
1361 (if (featurep 'xemacs
) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse
)
1362 (when org-agenda-mouse-1-follows-link
1363 (org-defkey org-agenda-keymap
[follow-link
] 'mouse-face
))
1364 (easy-menu-define org-agenda-menu org-agenda-mode-map
"Agenda menu"
1368 ["Show" org-agenda-show t
]
1369 ["Go To (other window)" org-agenda-goto t
]
1370 ["Go To (this window)" org-agenda-switch-to t
]
1371 ["Follow Mode" org-agenda-follow-mode
1372 :style toggle
:selected org-agenda-follow-mode
:active t
]
1373 ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t
]
1375 ["Cycle TODO" org-agenda-todo t
]
1377 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t
]
1378 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t
]
1379 ["Archive subtree" org-agenda-archive t
])
1380 ["Delete subtree" org-agenda-kill t
]
1381 ["Add note" org-agenda-add-note t
]
1383 ["Goto Today" org-agenda-goto-today
(org-agenda-check-type nil
'agenda
'timeline
)]
1384 ["Next Dates" org-agenda-later
(org-agenda-check-type nil
'agenda
)]
1385 ["Previous Dates" org-agenda-earlier
(org-agenda-check-type nil
'agenda
)]
1386 ["Jump to date" org-agenda-goto-date
(org-agenda-check-type nil
'agenda
)]
1388 ("Tags and Properties"
1389 ["Show all Tags" org-agenda-show-tags t
]
1390 ["Set Tags current line" org-agenda-set-tags
(not (org-region-active-p))]
1391 ["Change tag in region" org-agenda-set-tags
(org-region-active-p)]
1393 ["Column View" org-columns t
])
1395 ["Schedule" org-agenda-schedule t
]
1396 ["Set Deadline" org-agenda-deadline t
]
1398 ["Mark item" org-agenda-action
:active t
:keys
"k m"]
1399 ["Show mark item" org-agenda-action
:active t
:keys
"k v"]
1400 ["Schedule marked item" org-agenda-action
:active t
:keys
"k s"]
1401 ["Set Deadline for marked item" org-agenda-action
:active t
:keys
"k d"]
1403 ["Change Date +1 day" org-agenda-date-later
(org-agenda-check-type nil
'agenda
'timeline
)]
1404 ["Change Date -1 day" org-agenda-date-earlier
(org-agenda-check-type nil
'agenda
'timeline
)]
1405 ["Change Time +1 hour" org-agenda-do-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-right"]
1406 ["Change Time -1 hour" org-agenda-do-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u S-left"]
1407 ["Change Time + min" org-agenda-date-later
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-right"]
1408 ["Change Time - min" org-agenda-date-earlier
:active
(org-agenda-check-type nil
'agenda
'timeline
) :keys
"C-u C-u S-left"]
1409 ["Change Date to ..." org-agenda-date-prompt
(org-agenda-check-type nil
'agenda
'timeline
)])
1411 ["Clock in" org-agenda-clock-in t
]
1412 ["Clock out" org-agenda-clock-out t
]
1413 ["Clock cancel" org-agenda-clock-cancel t
]
1414 ["Goto running clock" org-clock-goto t
])
1416 ["Set Priority" org-agenda-priority t
]
1417 ["Increase Priority" org-agenda-priority-up t
]
1418 ["Decrease Priority" org-agenda-priority-down t
]
1419 ["Show Priority" org-agenda-show-priority t
])
1421 ["New Diary Entry" org-agenda-diary-entry
(org-agenda-check-type nil
'agenda
'timeline
)]
1422 ["Goto Calendar" org-agenda-goto-calendar
(org-agenda-check-type nil
'agenda
'timeline
)]
1423 ["Phases of the Moon" org-agenda-phases-of-moon
(org-agenda-check-type nil
'agenda
'timeline
)]
1424 ["Sunrise/Sunset" org-agenda-sunrise-sunset
(org-agenda-check-type nil
'agenda
'timeline
)]
1425 ["Holidays" org-agenda-holidays
(org-agenda-check-type nil
'agenda
'timeline
)]
1426 ["Convert" org-agenda-convert-date
(org-agenda-check-type nil
'agenda
'timeline
)]
1428 ["Create iCalendar file" org-export-icalendar-combine-agenda-files t
])
1431 ["Day View" org-agenda-day-view
:active
(org-agenda-check-type nil
'agenda
)
1432 :style radio
:selected
(equal org-agenda-ndays
1)]
1433 ["Week View" org-agenda-week-view
:active
(org-agenda-check-type nil
'agenda
)
1434 :style radio
:selected
(equal org-agenda-ndays
7)]
1435 ["Month View" org-agenda-month-view
:active
(org-agenda-check-type nil
'agenda
)
1436 :style radio
:selected
(member org-agenda-ndays
'(28 29 30 31))]
1437 ["Year View" org-agenda-year-view
:active
(org-agenda-check-type nil
'agenda
)
1438 :style radio
:selected
(member org-agenda-ndays
'(365 366))]
1440 ["Include Diary" org-agenda-toggle-diary
1441 :style toggle
:selected org-agenda-include-diary
1442 :active
(org-agenda-check-type nil
'agenda
)]
1443 ["Use Time Grid" org-agenda-toggle-time-grid
1444 :style toggle
:selected org-agenda-use-time-grid
1445 :active
(org-agenda-check-type nil
'agenda
)]
1447 ["Show clock report" org-agenda-clockreport-mode
1448 :style toggle
:selected org-agenda-clockreport-mode
1449 :active
(org-agenda-check-type nil
'agenda
)]
1451 ["Show Logbook entries" org-agenda-log-mode
1452 :style toggle
:selected org-agenda-show-log
1453 :active
(org-agenda-check-type nil
'agenda
'timeline
)]
1454 ["Include archived trees" org-agenda-archives-mode
1455 :style toggle
:selected org-agenda-archives-mode
:active t
]
1456 ["Include archive files" (org-agenda-archives-mode t
)
1457 :style toggle
:selected
(eq org-agenda-archives-mode t
) :active t
1459 ["Write view to file" org-write-agenda t
]
1460 ["Rebuild buffer" org-agenda-redo t
]
1461 ["Save all Org-mode Buffers" org-save-all-org-buffers t
]
1463 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list
]
1465 ["Quit" org-agenda-quit t
]
1466 ["Exit and Release Buffers" org-agenda-exit t
]
1471 (defvar org-agenda-allow-remote-undo t
1472 "Non-nil means, allow remote undo from the agenda buffer.")
1473 (defvar org-agenda-undo-list nil
1474 "List of undoable operations in the agenda since last refresh.")
1475 (defvar org-agenda-undo-has-started-in nil
1476 "Buffers that have already seen `undo-start' in the current undo sequence.")
1477 (defvar org-agenda-pending-undo-list nil
1478 "In a series of undo commands, this is the list of remaining undo items.")
1481 (defun org-agenda-undo ()
1482 "Undo a remote editing step in the agenda.
1483 This undoes changes both in the agenda buffer and in the remote buffer
1484 that have been changed along."
1486 (or org-agenda-allow-remote-undo
1487 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo."))
1488 (if (not (eq this-command last-command
))
1489 (setq org-agenda-undo-has-started-in nil
1490 org-agenda-pending-undo-list org-agenda-undo-list
))
1491 (if (not org-agenda-pending-undo-list
)
1492 (error "No further undo information"))
1493 (let* ((entry (pop org-agenda-pending-undo-list
))
1494 buf line cmd rembuf
)
1495 (setq cmd
(pop entry
) line
(pop entry
))
1496 (setq rembuf
(nth 2 entry
))
1497 (org-with-remote-undo rembuf
1498 (while (bufferp (setq buf
(pop entry
)))
1500 (with-current-buffer buf
1501 (let ((last-undo-buffer buf
)
1502 (inhibit-read-only t
))
1503 (unless (memq buf org-agenda-undo-has-started-in
)
1504 (push buf org-agenda-undo-has-started-in
)
1505 (make-local-variable 'pending-undo-list
)
1507 (while (and pending-undo-list
1508 (listp pending-undo-list
)
1509 (not (car pending-undo-list
)))
1510 (pop pending-undo-list
))
1513 (message "`%s' undone (buffer %s)" cmd
(buffer-name rembuf
))))
1515 (defun org-verify-change-for-undo (l1 l2
)
1516 "Verify that a real change occurred between the undo lists L1 and L2."
1517 (while (and l1
(listp l1
) (null (car l1
))) (pop l1
))
1518 (while (and l2
(listp l2
) (null (car l2
))) (pop l2
))
1523 (defvar org-agenda-restrict nil
)
1524 (defvar org-agenda-restrict-begin
(make-marker))
1525 (defvar org-agenda-restrict-end
(make-marker))
1526 (defvar org-agenda-last-dispatch-buffer nil
)
1527 (defvar org-agenda-overriding-restriction nil
)
1530 (defun org-agenda (&optional arg keys restriction
)
1531 "Dispatch agenda commands to collect entries to the agenda buffer.
1532 Prompts for a command to execute. Any prefix arg will be passed
1533 on to the selected command. The default selections are:
1535 a Call `org-agenda-list' to display the agenda for current day or week.
1536 t Call `org-todo-list' to display the global todo list.
1537 T Call `org-todo-list' to display the global todo list, select only
1538 entries with a specific TODO keyword (the user gets a prompt).
1539 m Call `org-tags-view' to display headlines with tags matching
1540 a condition (the user is prompted for the condition).
1541 M Like `m', but select only TODO entries, no ordinary headlines.
1542 L Create a timeline for the current buffer.
1543 e Export views to associated files.
1544 s Search entries for keywords.
1545 / Multi occur accros all agenda files and also files listed
1546 in `org-agenda-text-search-extra-files'.
1547 < Restrict agenda commands to buffer, subtree, or region.
1548 Press several times to get the desired effect.
1549 > Remove a previous restriction.
1550 # List \"stuck\" projects.
1551 ! Configure what \"stuck\" means.
1552 C Configure custom agenda commands.
1554 More commands can be added by configuring the variable
1555 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1556 searches can be pre-defined in this way.
1558 If the current buffer is in Org-mode and visiting a file, you can also
1559 first press `<' once to indicate that the agenda should be temporarily
1560 \(until the next use of \\[org-agenda]) restricted to the current file.
1561 Pressing `<' twice means to restrict to the current subtree or region
1565 (let* ((prefix-descriptions nil
)
1566 (org-agenda-custom-commands-orig org-agenda-custom-commands
)
1567 (org-agenda-custom-commands
1568 ;; normalize different versions
1572 (cond ((stringp (cdr x
))
1573 (push x prefix-descriptions
)
1575 ((stringp (nth 1 x
)) x
)
1576 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1577 (t (cons (car x
) (cons "" (cdr x
))))))
1578 org-agenda-custom-commands
)))
1579 (buf (current-buffer))
1580 (bfn (buffer-file-name (buffer-base-buffer)))
1581 entry key type match lprops ans
)
1582 ;; Turn off restriction unless there is an overriding one
1583 (unless org-agenda-overriding-restriction
1584 (put 'org-agenda-files
'org-restrict nil
)
1585 (setq org-agenda-restrict nil
)
1586 (move-marker org-agenda-restrict-begin nil
)
1587 (move-marker org-agenda-restrict-end nil
))
1588 ;; Delete old local properties
1589 (put 'org-agenda-redo-command
'org-lprops nil
)
1590 ;; Remember where this call originated
1591 (setq org-agenda-last-dispatch-buffer
(current-buffer))
1593 (setq ans
(org-agenda-get-restriction-and-command prefix-descriptions
)
1595 restriction
(cdr ans
)))
1596 ;; Estabish the restriction, if any
1597 (when (and (not org-agenda-overriding-restriction
) restriction
)
1598 (put 'org-agenda-files
'org-restrict
(list bfn
))
1600 ((eq restriction
'region
)
1601 (setq org-agenda-restrict t
)
1602 (move-marker org-agenda-restrict-begin
(region-beginning))
1603 (move-marker org-agenda-restrict-end
(region-end)))
1604 ((eq restriction
'subtree
)
1606 (setq org-agenda-restrict t
)
1607 (org-back-to-heading t
)
1608 (move-marker org-agenda-restrict-begin
(point))
1609 (move-marker org-agenda-restrict-end
1610 (progn (org-end-of-subtree t
)))))))
1612 (require 'calendar
) ; FIXME: can we avoid this for some commands?
1613 ;; For example the todo list should not need it (but does...)
1615 ((setq entry
(assoc keys org-agenda-custom-commands
))
1616 (if (or (symbolp (nth 2 entry
)) (functionp (nth 2 entry
)))
1618 (setq type
(nth 2 entry
) match
(nth 3 entry
) lprops
(nth 4 entry
))
1619 (put 'org-agenda-redo-command
'org-lprops lprops
)
1622 (org-let lprops
'(org-agenda-list current-prefix-arg
)))
1624 (org-let lprops
'(org-todo-list current-prefix-arg
)))
1626 (org-let lprops
'(org-search-view current-prefix-arg match nil
)))
1628 (org-let lprops
'(org-agenda-list-stuck-projects
1629 current-prefix-arg
)))
1631 (org-let lprops
'(org-tags-view current-prefix-arg match
)))
1632 ((eq type
'tags-todo
)
1633 (org-let lprops
'(org-tags-view '(4) match
)))
1635 (org-let lprops
'(org-todo-list match
)))
1636 ((eq type
'tags-tree
)
1637 (org-check-for-org-mode)
1638 (org-let lprops
'(org-match-sparse-tree current-prefix-arg match
)))
1639 ((eq type
'todo-tree
)
1640 (org-check-for-org-mode)
1642 '(org-occur (concat "^" outline-regexp
"[ \t]*"
1643 (regexp-quote match
) "\\>"))))
1644 ((eq type
'occur-tree
)
1645 (org-check-for-org-mode)
1646 (org-let lprops
'(org-occur match
)))
1648 (org-let lprops
'(funcall type match
)))
1650 (org-let lprops
'(funcall type match
)))
1651 (t (error "Invalid custom agenda command type %s" type
))))
1652 (org-run-agenda-series (nth 1 entry
) (cddr entry
))))
1654 (setq org-agenda-custom-commands org-agenda-custom-commands-orig
)
1655 (customize-variable 'org-agenda-custom-commands
))
1656 ((equal keys
"a") (call-interactively 'org-agenda-list
))
1657 ((equal keys
"s") (call-interactively 'org-search-view
))
1658 ((equal keys
"t") (call-interactively 'org-todo-list
))
1659 ((equal keys
"T") (org-call-with-arg 'org-todo-list
(or arg
'(4))))
1660 ((equal keys
"m") (call-interactively 'org-tags-view
))
1661 ((equal keys
"M") (org-call-with-arg 'org-tags-view
(or arg
'(4))))
1662 ((equal keys
"e") (call-interactively 'org-store-agenda-views
))
1664 (unless (org-mode-p)
1665 (error "This is not an Org-mode file"))
1667 (put 'org-agenda-files
'org-restrict
(list bfn
))
1668 (org-call-with-arg 'org-timeline arg
)))
1669 ((equal keys
"#") (call-interactively 'org-agenda-list-stuck-projects
))
1670 ((equal keys
"/") (call-interactively 'org-occur-in-agenda-files
))
1671 ((equal keys
"!") (customize-variable 'org-stuck-projects
))
1672 (t (error "Invalid agenda key"))))))
1674 (defun org-agenda-normalize-custom-commands (cmds)
1678 (cond ((stringp (cdr x
)) nil
)
1679 ((stringp (nth 1 x
)) x
)
1680 ((not (nth 1 x
)) (cons (car x
) (cons "" (cddr x
))))
1681 (t (cons (car x
) (cons "" (cdr x
))))))
1684 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1685 "The user interface for selecting an agenda command."
1687 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1688 (restrict-ok (and bfn
(org-mode-p)))
1689 (region-p (org-region-active-p))
1690 (custom org-agenda-custom-commands
)
1692 restriction second-time
1693 c entry key type match prefixes rmheader header-end custom1 desc
)
1694 (save-window-excursion
1695 (delete-other-windows)
1696 (org-switch-to-buffer-other-window " *Agenda Commands*")
1698 (insert (eval-when-compile
1701 Press key for an agenda command: < Buffer, subtree/region restriction
1702 -------------------------------- > Remove restriction
1703 a Agenda for current week or day e Export agenda views
1704 t List of all TODO entries T Entries with special TODO kwd
1705 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1706 L Timeline for current buffer # List stuck projects (!=configure)
1707 s Search for keywords C Configure custom agenda commands
1711 (while (string-match
1712 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1714 (setq start
(match-end 0))
1715 (add-text-properties (match-beginning 2) (match-end 2)
1716 '(face bold
) header
))
1718 (setq header-end
(move-marker (make-marker) (point)))
1720 (setq custom1 custom
)
1721 (when (eq rmheader t
)
1723 (re-search-forward ":" nil t
)
1724 (delete-region (match-end 0) (point-at-eol))
1727 (delete-region (match-end 0) (point-at-eol))
1728 (move-marker header-end
(match-end 0)))
1729 (goto-char header-end
)
1730 (delete-region (point) (point-max))
1731 (while (setq entry
(pop custom1
))
1732 (setq key
(car entry
) desc
(nth 1 entry
)
1733 type
(nth 2 entry
) match
(nth 3 entry
))
1734 (if (> (length key
) 1)
1735 (add-to-list 'prefixes
(string-to-char key
))
1739 (org-add-props (copy-sequence key
)
1742 ((string-match "\\S-" desc
) desc
)
1743 ((eq type
'agenda
) "Agenda for current week or day")
1744 ((eq type
'alltodo
) "List of all TODO entries")
1745 ((eq type
'search
) "Word search")
1746 ((eq type
'stuck
) "List of stuck projects")
1747 ((eq type
'todo
) "TODO keyword")
1748 ((eq type
'tags
) "Tags query")
1749 ((eq type
'tags-todo
) "Tags (TODO)")
1750 ((eq type
'tags-tree
) "Tags tree")
1751 ((eq type
'todo-tree
) "TODO kwd tree")
1752 ((eq type
'occur-tree
) "Occur tree")
1753 ((functionp type
) (if (symbolp type
)
1755 "Lambda expression"))
1759 (org-add-props match nil
'face
'org-warning
))
1761 (format "set of %d commands" (length match
)))
1767 (org-add-props (char-to-string x
)
1769 (or (cdr (assoc (concat selstring
(char-to-string x
))
1770 prefix-descriptions
))
1773 (goto-char (point-min))
1775 (if (not (pos-visible-in-window-p (point-max)))
1776 (org-fit-window-to-buffer))
1777 (setq second-time t
)
1778 (org-fit-window-to-buffer))
1779 (message "Press key for agenda command%s:"
1780 (if (or restrict-ok org-agenda-overriding-restriction
)
1781 (if org-agenda-overriding-restriction
1782 " (restriction lock active)"
1784 (format " (restricted to %s)" restriction
)
1787 (setq c
(read-char-exclusive))
1790 ((assoc (char-to-string c
) custom
)
1791 (setq selstring
(concat selstring
(char-to-string c
)))
1792 (throw 'exit
(cons selstring restriction
)))
1794 (setq selstring
(concat selstring
(char-to-string c
))
1796 rmheader
(or rmheader t
)
1797 custom
(delq nil
(mapcar
1799 (if (or (= (length (car x
)) 1)
1800 (/= (string-to-char (car x
)) c
))
1802 (cons (substring (car x
) 1) (cdr x
))))
1804 ((and (not restrict-ok
) (memq c
'(?
1 ?
0 ?
<)))
1805 (message "Restriction is only possible in Org-mode buffers")
1808 (org-agenda-remove-restriction-lock 'noupdate
)
1809 (setq restriction
'buffer
))
1811 (org-agenda-remove-restriction-lock 'noupdate
)
1812 (setq restriction
(if region-p
'region
'subtree
)))
1814 (org-agenda-remove-restriction-lock 'noupdate
)
1817 ((eq restriction
'buffer
)
1818 (if region-p
'region
'subtree
))
1819 ((memq restriction
'(subtree region
))
1823 (org-agenda-remove-restriction-lock 'noupdate
)
1824 (setq restriction nil
))
1825 ((and (equal selstring
"") (memq c
'(?s ?a ?t ?m ?L ?C ?e ?T ?M ?
# ?
! ?
/)))
1826 (throw 'exit
(cons (setq selstring
(char-to-string c
)) restriction
)))
1827 ((and (> (length selstring
) 0) (eq c ?\d
))
1829 (org-agenda-get-restriction-and-command prefix-descriptions
))
1831 ((equal c ?q
) (error "Abort"))
1832 (t (error "Invalid key %c" c
))))))))
1834 (defun org-run-agenda-series (name series
)
1835 (org-prepare-agenda name
)
1836 (let* ((org-agenda-multi t
)
1837 (redo (list 'org-run-agenda-series name
(list 'quote series
)))
1839 (gprops (nth 1 series
))
1840 match
;; The byte compiler incorrectly complains about this. Keep it!
1842 (while (setq cmd
(pop cmds
))
1843 (setq type
(car cmd
) match
(nth 1 cmd
) lprops
(nth 2 cmd
))
1846 (org-let2 gprops lprops
1847 '(call-interactively 'org-agenda-list
)))
1849 (org-let2 gprops lprops
1850 '(call-interactively 'org-todo-list
)))
1852 (org-let2 gprops lprops
1853 '(org-search-view current-prefix-arg match nil
)))
1855 (org-let2 gprops lprops
1856 '(call-interactively 'org-agenda-list-stuck-projects
)))
1858 (org-let2 gprops lprops
1859 '(org-tags-view current-prefix-arg match
)))
1860 ((eq type
'tags-todo
)
1861 (org-let2 gprops lprops
1862 '(org-tags-view '(4) match
)))
1864 (org-let2 gprops lprops
1865 '(org-todo-list match
)))
1867 (org-let2 gprops lprops
1868 '(funcall type match
)))
1869 (t (error "Invalid type in command series"))))
1871 (setq org-agenda-redo-command redo
)
1872 (goto-char (point-min)))
1873 (org-fit-agenda-window)
1874 (org-let (nth 1 series
) '(org-finalize-agenda)))
1877 (defmacro org-batch-agenda
(cmd-key &rest parameters
)
1878 "Run an agenda command in batch mode and send the result to STDOUT.
1879 If CMD-KEY is a string of length 1, it is used as a key in
1880 `org-agenda-custom-commands' and triggers this command. If it is a
1881 longer string it is used as a tags/todo match string.
1882 Paramters are alternating variable names and values that will be bound
1883 before running the agenda command."
1886 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1887 (if (> (length cmd-key
) 2)
1888 (eval (list 'let
(nreverse pars
)
1889 (list 'org-tags-view nil cmd-key
)))
1890 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1891 (set-buffer org-agenda-buffer-name
)
1892 (princ (org-encode-for-stdout (buffer-string)))))
1894 (defun org-encode-for-stdout (string)
1895 (if (fboundp 'encode-coding-string
)
1896 (encode-coding-string string buffer-file-coding-system
)
1899 (defvar org-agenda-info nil
)
1902 (defmacro org-batch-agenda-csv
(cmd-key &rest parameters
)
1903 "Run an agenda command in batch mode and send the result to STDOUT.
1904 If CMD-KEY is a string of length 1, it is used as a key in
1905 `org-agenda-custom-commands' and triggers this command. If it is a
1906 longer string it is used as a tags/todo match string.
1907 Paramters are alternating variable names and values that will be bound
1908 before running the agenda command.
1910 The output gives a line for each selected agenda item. Each
1911 item is a list of comma-separated values, like this:
1913 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
1915 category The category of the item
1916 head The headline, without TODO kwd, TAGS and PRIORITY
1917 type The type of the agenda entry, can be
1918 todo selected in TODO match
1919 tagsmatch selected in tags match
1920 diary imported from diary
1921 deadline a deadline on given date
1922 scheduled scheduled on given date
1923 timestamp entry has timestamp on given date
1924 closed entry was closed on given date
1925 upcoming-deadline warning about deadline
1926 past-scheduled forwarded scheduled item
1927 block entry has date block including g. date
1928 todo The todo keyword, if any
1929 tags All tags including inherited ones, separated by colons
1930 date The relevant date, like 2007-2-14
1931 time The time, like 15:00-16:50
1932 extra Sting with extra planning info
1933 priority-l The priority letter if any was given
1934 priority-n The computed numerical priority
1935 agenda-day The day in the agenda where this is listed"
1939 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
1940 (push (list 'org-agenda-remove-tags t
) pars
)
1941 (if (> (length cmd-key
) 2)
1942 (eval (list 'let
(nreverse pars
)
1943 (list 'org-tags-view nil cmd-key
)))
1944 (eval (list 'let
(nreverse pars
) (list 'org-agenda nil cmd-key
))))
1945 (set-buffer org-agenda-buffer-name
)
1946 (let* ((lines (org-split-string (buffer-string) "\n"))
1948 (while (setq line
(pop lines
))
1950 (if (not (get-text-property 0 'org-category line
)) (throw 'next nil
))
1951 (setq org-agenda-info
1952 (org-fix-agenda-info (text-properties-at 0 line
)))
1954 (org-encode-for-stdout
1955 (mapconcat 'org-agenda-export-csv-mapper
1956 '(org-category txt type todo tags date time-of-day extra
1957 priority-letter priority agenda-day
)
1961 (defun org-fix-agenda-info (props)
1962 "Make sure all properties on an agenda item have a canonical form,
1963 so the export commands can easily use it."
1965 (when (setq tmp
(plist-get props
'tags
))
1966 (setq props
(plist-put props
'tags
(mapconcat 'identity tmp
":"))))
1967 (when (setq tmp
(plist-get props
'date
))
1968 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1969 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1970 '((format "%4d, %9s %2s, %4s" dayname monthname day year
))
1972 (setq tmp
(calendar-date-string tmp
)))
1973 (setq props
(plist-put props
'date tmp
)))
1974 (when (setq tmp
(plist-get props
'day
))
1975 (if (integerp tmp
) (setq tmp
(calendar-gregorian-from-absolute tmp
)))
1976 (let ((calendar-date-display-form '(year "-" month
"-" day
)))
1977 (setq tmp
(calendar-date-string tmp
)))
1978 (setq props
(plist-put props
'day tmp
))
1979 (setq props
(plist-put props
'agenda-day tmp
)))
1980 (when (setq tmp
(plist-get props
'txt
))
1981 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp
)
1982 (plist-put props
'priority-letter
(match-string 1 tmp
))
1983 (setq tmp
(replace-match "" t t tmp
)))
1984 (when (and (setq re
(plist-get props
'org-todo-regexp
))
1985 (setq re
(concat "\\`\\.*" re
" ?"))
1986 (string-match re tmp
))
1987 (plist-put props
'todo
(match-string 1 tmp
))
1988 (setq tmp
(replace-match "" t t tmp
)))
1989 (plist-put props
'txt tmp
)))
1992 (defun org-agenda-export-csv-mapper (prop)
1993 (let ((res (plist-get org-agenda-info prop
)))
1998 (t (prin1-to-string res
))))
1999 (while (string-match "," res
)
2000 (setq res
(replace-match ";" t t res
)))
2005 (defun org-store-agenda-views (&rest parameters
)
2007 (eval (list 'org-batch-store-agenda-views
)))
2009 ;; FIXME, why is this a macro?????
2011 (defmacro org-batch-store-agenda-views
(&rest parameters
)
2012 "Run all custom agenda commands that have a file argument."
2013 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands
))
2015 (dir default-directory
)
2016 pars cmd thiscmdkey files opts cmd-or-set
)
2018 (push (list (pop parameters
) (if parameters
(pop parameters
))) pars
))
2019 (setq pars
(reverse pars
))
2020 (save-window-excursion
2022 (setq cmd
(pop cmds
)
2023 thiscmdkey
(car cmd
)
2024 cmd-or-set
(nth 2 cmd
)
2025 opts
(nth (if (listp cmd-or-set
) 3 4) cmd
)
2026 files
(nth (if (listp cmd-or-set
) 4 5) cmd
))
2027 (if (stringp files
) (setq files
(list files
)))
2029 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2030 (list 'org-agenda nil thiscmdkey
)))
2031 (set-buffer org-agenda-buffer-name
)
2033 (eval (list 'let
(append org-agenda-exporter-settings opts pars
)
2034 (list 'org-write-agenda
2035 (expand-file-name (pop files
) dir
) nil t
))))
2036 (and (get-buffer org-agenda-buffer-name
)
2037 (kill-buffer org-agenda-buffer-name
)))))))
2039 (defun org-write-agenda (file &optional open nosettings
)
2040 "Write the current buffer (an agenda view) as a file.
2041 Depending on the extension of the file name, plain text (.txt),
2042 HTML (.html or .htm) or Postscript (.ps) is produced.
2043 If the extension is .ics, run icalendar export over all files used
2044 to construct the agenda and limit the export to entries listed in the
2046 With prefic argument OPEN, open the new file immediately.
2047 If NOSETTINGS is given, do not scope the settings of
2048 `org-agenda-exporter-settings' into the export commands. This is used when
2049 the settings have already been scoped and we do not wish to overrule other,
2050 higher priority settings."
2051 (interactive "FWrite agenda to file: \nP")
2052 (if (not (file-writable-p file
))
2053 (error "Cannot write agenda to file %s" file
))
2055 ((string-match "\\.html?\\'" file
) (require 'htmlize
))
2056 ((string-match "\\.ps\\'" file
) (require 'ps-print
)))
2057 (org-let (if nosettings nil org-agenda-exporter-settings
)
2059 (save-window-excursion
2060 (org-agenda-mark-filtered-text)
2061 (let ((bs (copy-sequence (buffer-string))) beg
)
2062 (org-agenda-unmark-filtered-text)
2065 (org-agenda-remove-marked-text 'org-filtered
)
2066 (while (setq beg
(text-property-any (point-min) (point-max)
2069 beg
(or (next-single-property-change beg
'org-filtered
)
2071 (run-hooks 'org-agenda-before-write-hook
)
2073 ((string-match "\\.html?\\'" file
)
2074 (set-buffer (htmlize-buffer (current-buffer)))
2076 (when (and org-agenda-export-html-style
2077 (string-match "<style>" org-agenda-export-html-style
))
2078 ;; replace <style> section with org-agenda-export-html-style
2079 (goto-char (point-min))
2080 (kill-region (- (search-forward "<style") 6)
2081 (search-forward "</style>"))
2082 (insert org-agenda-export-html-style
))
2084 (kill-buffer (current-buffer))
2085 (message "HTML written to %s" file
))
2086 ((string-match "\\.ps\\'" file
)
2088 (flet ((ps-get-buffer-name () "Agenda View"))
2089 (ps-print-buffer-with-faces file
))
2090 (message "Postscript written to %s" file
))
2091 ((string-match "\\.pdf\\'" file
)
2093 (flet ((ps-get-buffer-name () "Agenda View"))
2094 (ps-print-buffer-with-faces
2095 (concat (file-name-sans-extension file
) ".ps")))
2096 (call-process "ps2pdf" nil nil nil
2098 (concat (file-name-sans-extension file
) ".ps"))
2099 (expand-file-name file
))
2100 (message "PDF written to %s" file
))
2101 ((string-match "\\.ics\\'" file
)
2102 (let ((org-agenda-marker-table
2103 (org-create-marker-find-array
2104 (org-agenda-collect-markers)))
2105 (org-icalendar-verify-function 'org-check-agenda-marker-table
)
2106 (org-combined-agenda-icalendar-file file
))
2107 (apply 'org-export-icalendar
'combine
2108 (org-agenda-files nil
'ifmode
))))
2110 (let ((bs (buffer-string)))
2115 (kill-buffer (current-buffer))
2116 (message "Plain text written to %s" file
))))))))
2117 (set-buffer org-agenda-buffer-name
))
2118 (when open
(org-open-file file
)))
2120 (defvar org-agenda-filter-overlays nil
)
2122 (defun org-agenda-mark-filtered-text ()
2123 "Mark all text hidden by filtering with a text property."
2124 (let ((inhibit-read-only t
))
2127 (when (equal (org-overlay-buffer o
) (current-buffer))
2129 (org-overlay-start o
) (org-overlay-end o
)
2131 org-agenda-filter-overlays
)))
2133 (defun org-agenda-unmark-filtered-text ()
2134 "Remove the filtering text property."
2135 (let ((inhibit-read-only t
))
2136 (remove-text-properties (point-min) (point-max) '(org-filtered t
))))
2138 (defun org-agenda-remove-marked-text (property &optional value
)
2139 "Delete all text marked with VALUE of PROPERTY.
2140 VALUE defaults to t."
2142 (setq value
(or value t
))
2143 (while (setq beg
(text-property-any (point-min) (point-max)
2146 beg
(or (next-single-property-change beg
'org-filtered
)
2149 (defun org-agenda-add-entry-text ()
2150 "Add entry text to agenda lines.
2151 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2152 entry text following headings shown in the agenda.
2153 Drawers will be excluded, also the line with scheduling/deadline info."
2154 (when (> org-agenda-add-entry-text-maxlines
0)
2155 (let (m txt drawer-re kwd-time-re ind
)
2156 (goto-char (point-min))
2158 (if (not (setq m
(get-text-property (point) 'org-hd-marker
)))
2159 (beginning-of-line 2)
2161 (with-current-buffer (marker-buffer m
)
2162 (if (not (org-mode-p))
2168 (beginning-of-line 2)
2169 (setq txt
(buffer-substring
2171 (progn (outline-next-heading) (point)))
2172 drawer-re org-drawer-regexp
2173 kwd-time-re
(concat "^[ \t]*" org-keyword-time-regexp
2177 (when org-agenda-add-entry-text-descriptive-links
2178 (goto-char (point-min))
2179 (while (org-activate-bracket-links (point-max))
2180 (add-text-properties (match-beginning 0) (match-end 0)
2182 (goto-char (point-min))
2183 (while (re-search-forward org-bracket-link-regexp
(point-max) t
)
2184 (set-text-properties (match-beginning 0) (match-end 0)
2186 (goto-char (point-min))
2187 (while (re-search-forward drawer-re nil t
)
2190 (progn (re-search-forward
2191 "^[ \t]*:END:.*\n?" nil
'move
)
2193 (goto-char (point-min))
2194 (while (re-search-forward kwd-time-re nil t
)
2196 (if (re-search-forward "[ \t\n]+\\'" nil t
)
2198 (goto-char (point-min))
2199 ;; find min indentation
2200 (goto-char (point-min))
2201 (untabify (point-min) (point-max))
2202 (setq ind
(org-get-indentation))
2204 (unless (looking-at "[ \t]*$")
2205 (setq ind
(min ind
(org-get-indentation))))
2206 (beginning-of-line 2))
2207 (goto-char (point-min))
2209 (unless (looking-at "[ \t]*$")
2210 (move-to-column ind
)
2211 (delete-region (point-at-bol) (point)))
2212 (beginning-of-line 2))
2213 (goto-char (point-min))
2214 (while (and (not (eobp)) (re-search-forward "^" nil t
))
2215 (replace-match " > "))
2216 (goto-char (point-min))
2217 (while (looking-at "[ \t]*\n") (replace-match ""))
2218 (goto-char (point-max))
2219 (when (> (org-current-line)
2220 (1+ org-agenda-add-entry-text-maxlines
))
2221 (goto-line (1+ org-agenda-add-entry-text-maxlines
))
2223 (setq txt
(buffer-substring (point-min) (point)))))))))
2225 (if (string-match "\\S-" txt
) (insert "\n" txt
)))))))
2227 (defun org-agenda-collect-markers ()
2228 "Collect the markers pointing to entries in the agenda buffer."
2231 (goto-char (point-min))
2233 (when (setq m
(or (get-text-property (point) 'org-hd-marker
)
2234 (get-text-property (point) 'org-marker
)))
2236 (beginning-of-line 2)))
2237 (nreverse markers
)))
2239 (defun org-create-marker-find-array (marker-list)
2240 "Create a alist of files names with all marker positions in that file."
2242 (while (setq m
(pop marker-list
))
2243 (setq p
(marker-position m
)
2244 f
(buffer-file-name (or (buffer-base-buffer
2246 (marker-buffer m
))))
2247 (if (setq a
(assoc f tbl
))
2248 (push (marker-position m
) (cdr a
))
2249 (push (list f p
) tbl
)))
2250 (mapcar (lambda (x) (setcdr x
(sort (copy-sequence (cdr x
)) '<)) x
)
2253 (defvar org-agenda-marker-table nil
) ; dynamically scoped parameter
2254 (defun org-check-agenda-marker-table ()
2255 "Check of the current entry is on the marker list."
2256 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2258 (and (setq a
(assoc file org-agenda-marker-table
))
2261 (org-back-to-heading t
)
2262 (member (point) (cdr a
)))))))
2264 (defun org-check-for-org-mode ()
2265 "Make sure current buffer is in org-mode. Error if not."
2267 (error "Cannot execute org-mode agenda command on buffer in %s."
2270 (defun org-fit-agenda-window ()
2271 "Fit the window to the buffer size."
2272 (and (memq org-agenda-window-setup
'(reorganize-frame))
2273 (fboundp 'fit-window-to-buffer
)
2274 (org-fit-window-to-buffer
2276 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions
)))
2277 (floor (* (frame-height) (car org-agenda-window-frame-fractions
))))))
2279 ;;; Agenda prepare and finalize
2281 (defvar org-agenda-multi nil
) ; dynamically scoped
2282 (defvar org-agenda-buffer-name
"*Org Agenda*")
2283 (defvar org-pre-agenda-window-conf nil
)
2284 (defvar org-agenda-columns-active nil
)
2285 (defvar org-agenda-name nil
)
2286 (defvar org-agenda-filter nil
)
2287 (defvar org-agenda-filter-preset nil
2288 "A preset of the tags filter used for secondary agenda filtering.
2289 This must be a list of strings, each string must be a single tag preceeded
2291 This variable should not be set directly, but agenda custom commands can
2292 bind it in the options section.")
2294 (defun org-prepare-agenda (&optional name
)
2295 (setq org-todo-keywords-for-agenda nil
)
2296 (setq org-done-keywords-for-agenda nil
)
2297 (setq org-agenda-filter nil
)
2298 (put 'org-agenda-filter
:preset-filter org-agenda-filter-preset
)
2299 (if org-agenda-multi
2301 (setq buffer-read-only nil
)
2302 (goto-char (point-max))
2303 (unless (or (bobp) org-agenda-compact-blocks
)
2305 (if (stringp org-agenda-block-separator
)
2306 org-agenda-block-separator
2307 (make-string (window-width) org-agenda-block-separator
))
2309 (narrow-to-region (point) (point-max)))
2310 (org-agenda-reset-markers)
2311 (setq org-agenda-contributing-files nil
)
2312 (setq org-agenda-columns-active nil
)
2313 (org-prepare-agenda-buffers (org-agenda-files nil
'ifmode
))
2314 (setq org-todo-keywords-for-agenda
2315 (org-uniquify org-todo-keywords-for-agenda
))
2316 (setq org-done-keywords-for-agenda
2317 (org-uniquify org-done-keywords-for-agenda
))
2318 (let* ((abuf (get-buffer-create org-agenda-buffer-name
))
2319 (awin (get-buffer-window abuf
)))
2321 ((equal (current-buffer) abuf
) nil
)
2322 (awin (select-window awin
))
2323 ((not (setq org-pre-agenda-window-conf
(current-window-configuration))))
2324 ((equal org-agenda-window-setup
'current-window
)
2325 (switch-to-buffer abuf
))
2326 ((equal org-agenda-window-setup
'other-window
)
2327 (org-switch-to-buffer-other-window abuf
))
2328 ((equal org-agenda-window-setup
'other-frame
)
2329 (switch-to-buffer-other-frame abuf
))
2330 ((equal org-agenda-window-setup
'reorganize-frame
)
2331 (delete-other-windows)
2332 (org-switch-to-buffer-other-window abuf
))))
2333 (setq buffer-read-only nil
)
2334 (let ((inhibit-read-only t
)) (erase-buffer))
2336 (and name
(not org-agenda-name
)
2337 (org-set-local 'org-agenda-name name
)))
2338 (setq buffer-read-only nil
))
2340 (defun org-finalize-agenda ()
2341 "Finishing touch for the agenda buffer, called just before displaying it."
2342 (unless org-agenda-multi
2344 (let ((inhibit-read-only t
))
2345 (goto-char (point-min))
2346 (while (org-activate-bracket-links (point-max))
2347 (add-text-properties (match-beginning 0) (match-end 0)
2349 (org-agenda-align-tags)
2350 (unless org-agenda-with-colors
2351 (remove-text-properties (point-min) (point-max) '(face nil
))))
2352 (if (and (boundp 'org-agenda-overriding-columns-format
)
2353 org-agenda-overriding-columns-format
)
2354 (org-set-local 'org-agenda-overriding-columns-format
2355 org-agenda-overriding-columns-format
))
2356 (if (and (boundp 'org-agenda-view-columns-initially
)
2357 org-agenda-view-columns-initially
)
2358 (org-agenda-columns))
2359 (when org-agenda-fontify-priorities
2360 (org-agenda-fontify-priorities))
2361 (when (and org-agenda-dim-blocked-tasks org-blocker-hook
)
2362 (org-agenda-dim-blocked-tasks))
2363 (run-hooks 'org-finalize-agenda-hook
)
2364 (setq org-agenda-type
(get-text-property (point) 'org-agenda-type
))
2365 (when (get 'org-agenda-filter
:preset-filter
)
2366 (org-agenda-filter-apply org-agenda-filter
))
2369 (defun org-agenda-fontify-priorities ()
2370 "Make highest priority lines bold, and lowest italic."
2372 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-priority
)
2373 (org-delete-overlay o
)))
2374 (org-overlays-in (point-min) (point-max)))
2376 (let ((inhibit-read-only t
)
2378 (goto-char (point-min))
2379 (while (re-search-forward "\\[#\\(.\\)\\]" nil t
)
2380 (setq h
(or (get-char-property (point) 'org-highest-priority
)
2381 org-highest-priority
)
2382 l
(or (get-char-property (point) 'org-lowest-priority
)
2383 org-lowest-priority
)
2384 p
(string-to-char (match-string 1))
2385 b
(match-beginning 0)
2386 e
(if (eq org-agenda-fontify-priorities
'cookies
)
2389 ov
(org-make-overlay b e
))
2392 (cond ((cdr (assoc p org-priority-faces
)))
2393 ((and (listp org-agenda-fontify-priorities
)
2394 (cdr (assoc p org-agenda-fontify-priorities
))))
2395 ((equal p l
) 'italic
)
2396 ((equal p h
) 'bold
)))
2397 (org-overlay-put ov
'org-type
'org-priority
)))))
2399 (defun org-agenda-dim-blocked-tasks ()
2400 "Dim currently blocked TODO's in the agenda display."
2401 (mapc (lambda (o) (if (eq (org-overlay-get o
'org-type
) 'org-blocked-todo
)
2402 (org-delete-overlay o
)))
2403 (org-overlays-in (point-min) (point-max)))
2405 (let ((inhibit-read-only t
)
2406 (org-depend-tag-blocked nil
)
2407 (invis (eq org-agenda-dim-blocked-tasks
'invisible
))
2408 org-blocked-by-checkboxes
2409 invis1 b e p ov h l
)
2410 (goto-char (point-min))
2411 (while (let ((pos (next-single-property-change (point) 'todo-state
)))
2412 (and pos
(goto-char (1+ pos
))))
2413 (setq org-blocked-by-checkboxes nil invis1 invis
)
2414 (let ((marker (get-text-property (point) 'org-hd-marker
)))
2416 (not (with-current-buffer (marker-buffer marker
)
2419 (run-hook-with-args-until-failure
2421 (list :type
'todo-state-change
2425 (if org-blocked-by-checkboxes
(setq invis1 nil
))
2426 (setq b
(if invis1
(max (point-min) (1- (point))) (point))
2428 ov
(org-make-overlay b e
))
2430 (org-overlay-put ov
'invisible t
)
2431 (org-overlay-put ov
'face
'org-agenda-dimmed-todo-face
))
2432 (org-overlay-put ov
'org-type
'org-blocked-todo
)))))))
2434 (defvar org-agenda-skip-function nil
2435 "Function to be called at each match during agenda construction.
2436 If this function returns nil, the current match should not be skipped.
2437 Otherwise, the function must return a position from where the search
2438 should be continued.
2439 This may also be a Lisp form, it will be evaluated.
2440 Never set this variable using `setq' or so, because then it will apply
2441 to all future agenda commands. Instead, bind it with `let' to scope
2442 it dynamically into the agenda-constructing command. A good way to set
2443 it is through options in org-agenda-custom-commands.")
2445 (defun org-agenda-skip ()
2446 "Throw to `:skip' in places that should be skipped.
2447 Also moves point to the end of the skipped region, so that search can
2448 continue from there."
2449 (let ((p (point-at-bol)) to fp
)
2450 (and org-agenda-skip-archived-trees
(not org-agenda-archives-mode
)
2451 (get-text-property p
:org-archived
)
2452 (org-end-of-subtree t
)
2454 (and org-agenda-skip-comment-trees
2455 (get-text-property p
:org-comment
)
2456 (org-end-of-subtree t
)
2458 (if (equal (char-after p
) ?
#) (throw :skip t
))
2459 (when (and (or (setq fp
(functionp org-agenda-skip-function
))
2460 (consp org-agenda-skip-function
))
2461 (setq to
(save-excursion
2464 (funcall org-agenda-skip-function
)
2465 (eval org-agenda-skip-function
))))))
2469 (defvar org-agenda-markers nil
2470 "List of all currently active markers created by `org-agenda'.")
2471 (defvar org-agenda-last-marker-time
(time-to-seconds (current-time))
2472 "Creation time of the last agenda marker.")
2474 (defun org-agenda-new-marker (&optional pos
)
2475 "Return a new agenda marker.
2476 Org-mode keeps a list of these markers and resets them when they are
2478 (let ((m (copy-marker (or pos
(point)))))
2479 (setq org-agenda-last-marker-time
(time-to-seconds (current-time)))
2480 (push m org-agenda-markers
)
2483 (defun org-agenda-reset-markers ()
2484 "Reset markers created by `org-agenda'."
2485 (while org-agenda-markers
2486 (move-marker (pop org-agenda-markers
) nil
)))
2488 (defun org-agenda-save-markers-for-cut-and-paste (beg end
)
2489 "Save relative positions of markers in region."
2490 (mapc (lambda (m) (org-check-and-save-marker m beg end
))
2491 org-agenda-markers
))
2495 (defvar org-agenda-only-exact-dates nil
) ; dynamically scoped
2497 (defun org-timeline (&optional include-all
)
2498 "Show a time-sorted view of the entries in the current org file.
2499 Only entries with a time stamp of today or later will be listed. With
2500 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2501 under the current date.
2502 If the buffer contains an active region, only check the region for
2506 (org-compile-prefix-format 'timeline
)
2507 (org-set-sorting-strategy 'timeline
)
2509 (dotodo include-all
)
2510 (doclosed org-agenda-show-log
)
2511 (entry buffer-file-name
)
2512 (date (calendar-current-date))
2513 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2514 (end (if (org-region-active-p) (region-end) (point-max)))
2515 (day-numbers (org-get-all-dates beg end
'no-ranges
2516 t doclosed
; always include today
2517 org-timeline-show-empty-dates
))
2518 (org-deadline-warning-days 0)
2519 (org-agenda-only-exact-dates t
)
2520 (today (time-to-days (current-time)))
2523 s e rtn d emptyp wd
)
2524 (setq org-agenda-redo-command
2526 (list 'org-switch-to-buffer-other-window
(current-buffer))
2527 (list 'org-timeline
(list 'quote include-all
))))
2529 ;; Remove past dates from the list of dates.
2530 (setq day-numbers
(delq nil
(mapcar (lambda(x)
2531 (if (>= x today
) x nil
))
2533 (org-prepare-agenda (concat "Timeline "
2534 (file-name-nondirectory buffer-file-name
)))
2535 (if doclosed
(push :closed args
))
2536 (push :timestamp args
)
2537 (push :deadline args
)
2538 (push :scheduled args
)
2540 (if dotodo
(push :todo args
))
2541 (while (setq d
(pop day-numbers
))
2542 (if (and (listp d
) (eq (car d
) :omitted
))
2545 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d
)))
2546 (put-text-property s
(1- (point)) 'face
'org-agenda-structure
))
2547 (if (listp d
) (setq d
(car d
) emptyp t
) (setq emptyp nil
))
2548 (if (and (>= d today
)
2553 (insert (make-string 79 ?-
) "\n")))
2554 (setq date
(calendar-gregorian-from-absolute d
)
2555 wd
(calendar-day-of-week date
))
2557 (setq rtn
(and (not emptyp
)
2558 (apply 'org-agenda-get-day-entries entry
2560 (if (or rtn
(equal d today
) org-timeline-show-empty-dates
)
2563 (if (stringp org-agenda-format-date
)
2564 (format-time-string org-agenda-format-date
2565 (org-time-from-absolute date
))
2566 (funcall org-agenda-format-date date
))
2568 (put-text-property s
(1- (point)) 'face
2569 (if (member wd org-agenda-weekend-days
)
2570 'org-agenda-date-weekend
2572 (put-text-property s
(1- (point)) 'org-date-line t
)
2574 (put-text-property s
(1- (point)) 'org-today t
))
2575 (and rtn
(insert (org-finalize-agenda-entries rtn
) "\n"))
2576 (put-text-property s
(1- (point)) 'day d
)))))
2577 (goto-char (point-min))
2578 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t
)
2580 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline
))
2581 (org-finalize-agenda)
2582 (setq buffer-read-only t
)))
2584 (defun org-get-all-dates (beg end
&optional no-ranges force-today inactive empty pre-re
)
2585 "Return a list of all relevant day numbers from BEG to END buffer positions.
2586 If NO-RANGES is non-nil, include only the start and end dates of a range,
2587 not every single day in the range. If FORCE-TODAY is non-nil, make
2588 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2589 inactive time stamps (those in square brackets) are included.
2590 When EMPTY is non-nil, also include days without any entries."
2592 (if pre-re pre-re
"")
2593 (if inactive org-ts-regexp-both org-ts-regexp
)))
2594 dates dates1 date day day1 day2 ts1 ts2
)
2596 (setq dates
(list (time-to-days (current-time)))))
2599 (while (re-search-forward re end t
)
2600 (setq day
(time-to-days (org-time-string-to-time
2601 (substring (match-string 1) 0 10))))
2602 (or (memq day dates
) (push day dates
)))
2605 (while (re-search-forward org-tr-regexp end t
)
2606 (setq ts1
(substring (match-string 1) 0 10)
2607 ts2
(substring (match-string 2) 0 10)
2608 day1
(time-to-days (org-time-string-to-time ts1
))
2609 day2
(time-to-days (org-time-string-to-time ts2
)))
2610 (while (< (setq day1
(1+ day1
)) day2
)
2611 (or (memq day1 dates
) (push day1 dates
)))))
2612 (setq dates
(sort dates
'<))
2614 (while (setq day
(pop dates
))
2615 (setq day2
(car dates
))
2617 (when (and day2 empty
)
2618 (if (or (eq empty t
)
2619 (and (numberp empty
) (<= (- day2 day
) empty
)))
2620 (while (< (setq day
(1+ day
)) day2
)
2621 (push (list day
) dates1
))
2622 (push (cons :omitted
(- day2 day
)) dates1
))))
2623 (setq dates
(nreverse dates1
)))
2626 ;;; Agenda Daily/Weekly
2628 (defvar org-agenda-overriding-arguments nil
) ; dynamically scoped parameter
2629 (defvar org-agenda-start-day nil
; dynamically scoped parameter
2630 "Custom commands can set this variable in the options section.")
2631 (defvar org-agenda-last-arguments nil
2632 "The arguments of the previous call to org-agenda")
2633 (defvar org-starting-day nil
) ; local variable in the agenda buffer
2634 (defvar org-agenda-span nil
) ; local variable in the agenda buffer
2635 (defvar org-include-all-loc nil
) ; local variable
2636 (defvar org-agenda-remove-date nil
) ; dynamically scoped FIXME: not used???
2639 (defun org-agenda-list (&optional include-all start-day ndays
)
2640 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2641 The view will be for the current day or week, but from the overview buffer
2642 you will be able to go to other days/weeks.
2644 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2645 all unfinished TODO items will also be shown, before the agenda.
2646 This feature is considered obsolete, please use the TODO list or a block
2649 With a numeric prefix argument in an interactive call, the agenda will
2650 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2651 the number of days. NDAYS defaults to `org-agenda-ndays'.
2653 START-DAY defaults to TODAY, or to the most recent match for the weekday
2654 given in `org-agenda-start-on-weekday'."
2656 (if (and (integerp include-all
) (> include-all
0))
2657 (setq ndays include-all include-all nil
))
2658 (setq ndays
(or ndays org-agenda-ndays
)
2659 start-day
(or start-day org-agenda-start-day
))
2660 (if org-agenda-overriding-arguments
2661 (setq include-all
(car org-agenda-overriding-arguments
)
2662 start-day
(nth 1 org-agenda-overriding-arguments
)
2663 ndays
(nth 2 org-agenda-overriding-arguments
)))
2664 (if (stringp start-day
)
2665 ;; Convert to an absolute day number
2666 (setq start-day
(time-to-days (org-read-date nil t start-day
))))
2667 (setq org-agenda-last-arguments
(list include-all start-day ndays
))
2668 (org-compile-prefix-format 'agenda
)
2669 (org-set-sorting-strategy 'agenda
)
2671 (let* ((org-agenda-start-on-weekday
2672 (if (or (equal ndays
7) (and (null ndays
) (equal 7 org-agenda-ndays
)))
2673 org-agenda-start-on-weekday nil
))
2674 (thefiles (org-agenda-files nil
'ifmode
))
2676 (today (time-to-days
2677 (time-subtract (current-time)
2678 (list 0 (* 3600 org-extend-today-until
) 0))))
2679 (sd (or start-day today
))
2680 (start (if (or (null org-agenda-start-on-weekday
)
2681 (< org-agenda-ndays
7))
2683 (let* ((nt (calendar-day-of-week
2684 (calendar-gregorian-from-absolute sd
)))
2685 (n1 org-agenda-start-on-weekday
)
2687 (- sd
(+ (if (< d
0) 7 0) d
)))))
2688 (day-numbers (list start
))
2690 (inhibit-redisplay (not debug-on-error
))
2691 s e rtn rtnall file date d start-pos end-pos todayp nd wd
2692 clocktable-start clocktable-end
)
2693 (setq org-agenda-redo-command
2694 (list 'org-agenda-list
(list 'quote include-all
) start-day ndays
))
2695 ;; Make the list of days
2696 (setq ndays
(or ndays org-agenda-ndays
)
2699 (push (1+ (car day-numbers
)) day-numbers
)
2700 (setq ndays
(1- ndays
)))
2701 (setq day-numbers
(nreverse day-numbers
))
2702 (setq clocktable-start
(car day-numbers
)
2703 clocktable-end
(1+ (or (org-last day-numbers
) 0)))
2704 (org-prepare-agenda "Day/Week")
2705 (org-set-local 'org-starting-day
(car day-numbers
))
2706 (org-set-local 'org-include-all-loc include-all
)
2707 (org-set-local 'org-agenda-span
2708 (org-agenda-ndays-to-span nd
))
2709 (when (and (or include-all org-agenda-include-all-todo
)
2710 (member today day-numbers
))
2711 (setq files thefiles
2713 (while (setq file
(pop files
))
2715 (org-check-agenda-file file
)
2716 (setq date
(calendar-gregorian-from-absolute today
)
2717 rtn
(org-agenda-get-day-entries
2719 (setq rtnall
(append rtnall rtn
))))
2721 (insert "ALL CURRENTLY OPEN TODO ITEMS:\n")
2722 (add-text-properties (point-min) (1- (point))
2723 (list 'face
'org-agenda-structure
))
2724 (insert (org-finalize-agenda-entries rtnall
) "\n")))
2725 (unless org-agenda-compact-blocks
2726 (let* ((d1 (car day-numbers
))
2727 (d2 (org-last day-numbers
))
2728 (w1 (org-days-to-iso-week d1
))
2729 (w2 (org-days-to-iso-week d2
)))
2731 (if org-agenda-overriding-header
2732 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
2733 nil
'face
'org-agenda-structure
) "\n")
2734 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd
)))
2736 (if (< (- d2 d1
) 350)
2738 (format " (W%02d)" w1
)
2739 (format " (W%02d-W%02d)" w1 w2
))
2742 (add-text-properties s
(1- (point)) (list 'face
'org-agenda-structure
2744 (while (setq d
(pop day-numbers
))
2745 (setq date
(calendar-gregorian-from-absolute d
)
2746 wd
(calendar-day-of-week date
)
2748 (if (or (setq todayp
(= d today
))
2749 (and (not start-pos
) (= d sd
)))
2750 (setq start-pos
(point))
2751 (if (and start-pos
(not end-pos
))
2752 (setq end-pos
(point))))
2753 (setq files thefiles
2755 (while (setq file
(pop files
))
2757 (org-check-agenda-file file
)
2759 ((eq org-agenda-show-log
'only
)
2760 (setq rtn
(org-agenda-get-day-entries
2761 file date
:closed
)))
2762 (org-agenda-show-log
2763 (setq rtn
(org-agenda-get-day-entries
2765 :deadline
:scheduled
:timestamp
:sexp
:closed
)))
2767 (setq rtn
(org-agenda-get-day-entries
2769 :deadline
:scheduled
:sexp
:timestamp
))))
2770 (setq rtnall
(append rtnall rtn
))))
2771 (if org-agenda-include-diary
2772 (let ((org-agenda-search-headline-for-time t
))
2773 (require 'diary-lib
)
2774 (setq rtn
(org-get-entries-from-diary date
))
2775 (setq rtnall
(append rtnall rtn
))))
2776 (if (or rtnall org-agenda-show-all-dates
)
2778 (setq day-cnt
(1+ day-cnt
))
2780 (if (stringp org-agenda-format-date
)
2781 (format-time-string org-agenda-format-date
2782 (org-time-from-absolute date
))
2783 (funcall org-agenda-format-date date
))
2785 (put-text-property s
(1- (point)) 'face
2786 (if (member wd org-agenda-weekend-days
)
2787 'org-agenda-date-weekend
2789 (put-text-property s
(1- (point)) 'org-date-line t
)
2790 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
)
2791 (if todayp
(put-text-property s
(1- (point)) 'org-today t
))
2793 (org-finalize-agenda-entries
2794 (org-agenda-add-time-grid-maybe
2797 (put-text-property s
(1- (point)) 'day d
)
2798 (put-text-property s
(1- (point)) 'org-day-cnt day-cnt
))))
2799 (when (and org-agenda-clockreport-mode clocktable-start
)
2800 (let ((org-agenda-files (org-agenda-files nil
'ifmode
))
2801 ;; the above line is to ensure the restricted range!
2802 (p org-agenda-clockreport-parameter-plist
)
2804 (setq p
(org-plist-delete p
:block
))
2805 (setq p
(plist-put p
:tstart clocktable-start
))
2806 (setq p
(plist-put p
:tend clocktable-end
))
2807 (setq p
(plist-put p
:scope
'agenda
))
2808 (setq tbl
(apply 'org-get-clocktable p
))
2810 (goto-char (point-min))
2811 (or org-agenda-multi
(org-fit-agenda-window))
2812 (unless (and (pos-visible-in-window-p (point-min))
2813 (pos-visible-in-window-p (point-max)))
2814 (goto-char (1- (point-max)))
2816 (if (not (pos-visible-in-window-p (or start-pos
1)))
2818 (goto-char (or start-pos
1))
2820 (goto-char (or start-pos
1))
2821 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda
))
2822 (org-finalize-agenda)
2823 (setq buffer-read-only t
)
2826 (defun org-agenda-ndays-to-span (n)
2827 (cond ((< n
7) 'day
) ((= n
7) 'week
) ((< n
32) 'month
) (t 'year
)))
2829 ;;; Agenda word search
2831 (defvar org-agenda-search-history nil
)
2832 (defvar org-todo-only nil
)
2834 (defvar org-search-syntax-table nil
2835 "Special syntax table for org-mode search.
2836 In this table, we have single quotes not as word constituents, to
2837 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
2839 (defun org-search-syntax-table ()
2840 (unless org-search-syntax-table
2841 (setq org-search-syntax-table
(copy-syntax-table org-mode-syntax-table
))
2842 (modify-syntax-entry ?
' "." org-search-syntax-table
)
2843 (modify-syntax-entry ?
` "." org-search-syntax-table
))
2844 org-search-syntax-table
)
2847 (defun org-search-view (&optional todo-only string edit-at
)
2848 "Show all entries that contain words or regular expressions.
2849 If the first character of the search string is an asterisks,
2850 search only the headlines.
2852 With optional prefix argument TODO-ONLY, only consider entries that are
2853 TODO entries. The argument STRING can be used to pass a default search
2854 string into this function. If EDIT-AT is non-nil, it means that the
2855 user should get a chance to edit this string, with cursor at position
2858 The search string is broken into \"words\" by splitting at whitespace.
2859 The individual words are then interpreted as a boolean expression with
2860 logical AND. Words prefixed with a minus must not occur in the entry.
2861 Words without a prefix or prefixed with a plus must occur in the entry.
2862 Matching is case-insensitive and the words are enclosed by word delimiters.
2864 Words enclosed by curly braces are interpreted as regular expressions
2865 that must or must not match in the entry.
2867 If the search string starts with an asterisk, search only in headlines.
2868 If (possibly after the leading star) the search string starts with an
2869 exclamation mark, this also means to look at TODO entries only, an effect
2870 that can also be achieved with a prefix argument.
2872 This command searches the agenda files, and in addition the files listed
2873 in `org-agenda-text-search-extra-files'."
2875 (org-compile-prefix-format 'search
)
2876 (org-set-sorting-strategy 'search
)
2877 (org-prepare-agenda "SEARCH")
2878 (let* ((props (list 'face nil
2879 'done-face
'org-agenda-done
2880 'org-not-done-regexp org-not-done-regexp
2881 'org-todo-regexp org-todo-regexp
2882 'org-complex-heading-regexp org-complex-heading-regexp
2883 'mouse-face
'highlight
2884 'keymap org-agenda-keymap
2885 'help-echo
(format "mouse-2 or RET jump to location")))
2886 regexp rtn rtnall files file pos
2887 marker category tags c neg re
2888 ee txt beg end words regexps
+ regexps- hdl-only buffer beg1 str
)
2889 (unless (and (not edit-at
)
2891 (string-match "\\S-" string
))
2892 (setq string
(read-string "[+-]Word/{Regexp} ...: "
2894 ((integerp edit-at
) (cons string edit-at
))
2896 'org-agenda-search-history
)))
2897 (org-set-local 'org-todo-only todo-only
)
2898 (setq org-agenda-redo-command
2899 (list 'org-search-view
(if todo-only t nil
) string
2900 '(if current-prefix-arg
1 nil
)))
2901 (setq org-agenda-query-string string
)
2903 (if (equal (string-to-char string
) ?
*)
2905 words
(substring string
1))
2906 (setq words string
))
2907 (when (equal (string-to-char words
) ?
!)
2909 words
(substring words
1)))
2910 (setq words
(org-split-string words
))
2912 (setq c
(string-to-char w
))
2914 (setq neg t w
(substring w
1))
2916 (setq neg nil w
(substring w
1))
2918 (if (string-match "\\`{.*}\\'" w
)
2919 (setq re
(substring w
1 -
1))
2920 (setq re
(concat "\\<" (regexp-quote (downcase w
)) "\\>")))
2921 (if neg
(push re regexps-
) (push re regexps
+)))
2923 (setq regexps
+ (sort regexps
+ (lambda (a b
) (> (length a
) (length b
)))))
2925 (setq regexp
(concat "^" org-outline-regexp
))
2926 (setq regexp
(pop regexps
+))
2927 (if hdl-only
(setq regexp
(concat "^" org-outline-regexp
".*?"
2929 (setq files
(org-agenda-files nil
'ifmode
))
2930 (when (eq (car org-agenda-text-search-extra-files
) 'agenda-archives
)
2931 (pop org-agenda-text-search-extra-files
)
2932 (setq files
(org-add-archive-files files
)))
2933 (setq files
(append files org-agenda-text-search-extra-files
)
2935 (while (setq file
(pop files
))
2938 (org-check-agenda-file file
)
2939 (setq buffer
(if (file-exists-p file
)
2940 (org-get-agenda-file-buffer file
)
2941 (error "No such file %s" file
)))
2943 ;; If file does not exist, make sure an error message is sent
2944 (setq rtn
(list (format "ORG-AGENDA-ERROR: No such org-file %s"
2946 (with-current-buffer buffer
2947 (with-syntax-table (org-search-syntax-table)
2948 (unless (org-mode-p)
2949 (error "Agenda file %s is not in `org-mode'" file
))
2950 (let ((case-fold-search t
))
2953 (if org-agenda-restrict
2954 (narrow-to-region org-agenda-restrict-begin
2955 org-agenda-restrict-end
)
2957 (goto-char (point-min))
2958 (unless (or (org-on-heading-p)
2959 (outline-next-heading))
2960 (throw 'nextfile t
))
2961 (goto-char (max (point-min) (1- (point))))
2962 (while (re-search-forward regexp nil t
)
2963 (org-back-to-heading t
)
2964 (skip-chars-forward "* ")
2965 (setq beg
(point-at-bol)
2967 end
(progn (outline-next-heading) (point)))
2971 (setq str
(buffer-substring-no-properties
2973 (if hdl-only
(point-at-eol) end
)))
2974 (mapc (lambda (wr) (when (string-match wr str
)
2975 (goto-char (1- end
))
2978 (mapc (lambda (wr) (unless (string-match wr str
)
2979 (goto-char (1- end
))
2982 (cons (concat "^\*+[ \t]+" org-not-done-regexp
)
2986 (setq marker
(org-agenda-new-marker (point))
2987 category
(org-get-category)
2988 tags
(org-get-tags-at (point))
2989 txt
(org-format-agenda-item
2991 (buffer-substring-no-properties
2992 beg1
(point-at-eol))
2994 (org-add-props txt props
2995 'org-marker marker
'org-hd-marker marker
2996 'org-todo-regexp org-todo-regexp
2997 'org-complex-heading-regexp org-complex-heading-regexp
2998 'priority
1000 'org-category category
3001 (goto-char (1- end
))))))))))
3002 (setq rtn
(nreverse ee
))
3003 (setq rtnall
(append rtnall rtn
)))
3004 (if org-agenda-overriding-header
3005 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3006 nil
'face
'org-agenda-structure
) "\n")
3007 (insert "Search words: ")
3008 (add-text-properties (point-min) (1- (point))
3009 (list 'face
'org-agenda-structure
))
3011 (insert string
"\n")
3012 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3014 (unless org-agenda-multi
3015 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3016 (add-text-properties pos
(1- (point))
3017 (list 'face
'org-agenda-structure
))))
3019 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3020 (goto-char (point-min))
3021 (or org-agenda-multi
(org-fit-agenda-window))
3022 (add-text-properties (point-min) (point-max) '(org-agenda-type search
))
3023 (org-finalize-agenda)
3024 (setq buffer-read-only t
)))
3026 ;;; Agenda TODO list
3028 (defvar org-select-this-todo-keyword nil
)
3029 (defvar org-last-arg nil
)
3032 (defun org-todo-list (arg)
3033 "Show all TODO entries from all agenda file in a single list.
3034 The prefix arg can be used to select a specific TODO keyword and limit
3035 the list to these. When using \\[universal-argument], you will be prompted
3036 for a keyword. A numeric prefix directly selects the Nth keyword in
3037 `org-todo-keywords-1'."
3040 (org-compile-prefix-format 'todo
)
3041 (org-set-sorting-strategy 'todo
)
3042 (org-prepare-agenda "TODO")
3043 (let* ((today (time-to-days (current-time)))
3044 (date (calendar-gregorian-from-absolute today
))
3045 (kwds org-todo-keywords-for-agenda
)
3046 (completion-ignore-case t
)
3047 (org-select-this-todo-keyword
3048 (if (stringp arg
) arg
3049 (and arg
(integerp arg
) (> arg
0)
3050 (nth (1- arg
) kwds
))))
3051 rtn rtnall files file pos
)
3052 (when (equal arg
'(4))
3053 (setq org-select-this-todo-keyword
3054 (org-ido-completing-read "Keyword (or KWD1|K2D2|...): "
3055 (mapcar 'list kwds
) nil nil
)))
3056 (and (equal 0 arg
) (setq org-select-this-todo-keyword nil
))
3057 (org-set-local 'org-last-arg arg
)
3058 (setq org-agenda-redo-command
3059 '(org-todo-list (or current-prefix-arg org-last-arg
)))
3060 (setq files
(org-agenda-files nil
'ifmode
)
3062 (while (setq file
(pop files
))
3064 (org-check-agenda-file file
)
3065 (setq rtn
(org-agenda-get-day-entries file date
:todo
))
3066 (setq rtnall
(append rtnall rtn
))))
3067 (if org-agenda-overriding-header
3068 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3069 nil
'face
'org-agenda-structure
) "\n")
3070 (insert "Global list of TODO items of type: ")
3071 (add-text-properties (point-min) (1- (point))
3072 (list 'face
'org-agenda-structure
))
3074 (insert (or org-select-this-todo-keyword
"ALL") "\n")
3075 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3077 (unless org-agenda-multi
3078 (insert "Available with `N r': (0)ALL")
3081 (setq s
(format "(%d)%s" (setq n
(1+ n
)) x
))
3082 (if (> (+ (current-column) (string-width s
) 1) (frame-width))
3087 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3089 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3090 (goto-char (point-min))
3091 (or org-agenda-multi
(org-fit-agenda-window))
3092 (add-text-properties (point-min) (point-max) '(org-agenda-type todo
))
3093 (org-finalize-agenda)
3094 (setq buffer-read-only t
)))
3096 ;;; Agenda tags match
3099 (defun org-tags-view (&optional todo-only match
)
3100 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3101 The prefix arg TODO-ONLY limits the search to TODO entries."
3103 (org-compile-prefix-format 'tags
)
3104 (org-set-sorting-strategy 'tags
)
3105 (let* ((org-tags-match-list-sublevels
3106 (if todo-only t org-tags-match-list-sublevels
))
3107 (completion-ignore-case t
)
3108 rtn rtnall files file pos matcher
3110 (setq matcher
(org-make-tags-matcher match
)
3111 match
(car matcher
) matcher
(cdr matcher
))
3112 (org-prepare-agenda (concat "TAGS " match
))
3113 (setq org-agenda-query-string match
)
3114 (setq org-agenda-redo-command
3115 (list 'org-tags-view
(list 'quote todo-only
)
3116 (list 'if
'current-prefix-arg nil
'org-agenda-query-string
)))
3117 (setq files
(org-agenda-files nil
'ifmode
)
3119 (while (setq file
(pop files
))
3121 (org-check-agenda-file file
)
3122 (setq buffer
(if (file-exists-p file
)
3123 (org-get-agenda-file-buffer file
)
3124 (error "No such file %s" file
)))
3126 ;; If file does not exist, error message to agenda
3128 (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3129 rtnall
(append rtnall rtn
))
3130 (with-current-buffer buffer
3131 (unless (org-mode-p)
3132 (error "Agenda file %s is not in `org-mode'" file
))
3135 (if org-agenda-restrict
3136 (narrow-to-region org-agenda-restrict-begin
3137 org-agenda-restrict-end
)
3139 (setq rtn
(org-scan-tags 'agenda matcher todo-only
))
3140 (setq rtnall
(append rtnall rtn
))))))))
3141 (if org-agenda-overriding-header
3142 (insert (org-add-props (copy-sequence org-agenda-overriding-header
)
3143 nil
'face
'org-agenda-structure
) "\n")
3144 (insert "Headlines with TAGS match: ")
3145 (add-text-properties (point-min) (1- (point))
3146 (list 'face
'org-agenda-structure
))
3149 (add-text-properties pos
(1- (point)) (list 'face
'org-warning
))
3151 (unless org-agenda-multi
3152 (insert "Press `C-u r' to search again with new search string\n"))
3153 (add-text-properties pos
(1- (point)) (list 'face
'org-agenda-structure
)))
3155 (insert (org-finalize-agenda-entries rtnall
) "\n"))
3156 (goto-char (point-min))
3157 (or org-agenda-multi
(org-fit-agenda-window))
3158 (add-text-properties (point-min) (point-max) '(org-agenda-type tags
))
3159 (org-finalize-agenda)
3160 (setq buffer-read-only t
)))
3162 ;;; Agenda Finding stuck projects
3164 (defvar org-agenda-skip-regexp nil
3165 "Regular expression used in skipping subtrees for the agenda.
3166 This is basically a temporary global variable that can be set and then
3167 used by user-defined selections using `org-agenda-skip-function'.")
3169 (defvar org-agenda-overriding-header nil
3170 "When this is set during todo and tags searches, will replace header.
3171 This variable should not be set directly, but custom commands can bind it
3172 in the options section.")
3174 (defun org-agenda-skip-entry-when-regexp-matches ()
3175 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3176 If yes, it returns the end position of this entry, causing agenda commands
3177 to skip the entry but continuing the search in the subtree. This is a
3178 function that can be put into `org-agenda-skip-function' for the duration
3180 (let ((end (save-excursion (org-end-of-subtree t
)))
3183 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3186 (defun org-agenda-skip-subtree-when-regexp-matches ()
3187 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3188 If yes, it returns the end position of this tree, causing agenda commands
3189 to skip this subtree. This is a function that can be put into
3190 `org-agenda-skip-function' for the duration of a command."
3191 (let ((end (save-excursion (org-end-of-subtree t
)))
3194 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3197 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3198 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3199 If yes, it returns the end position of the current entry (NOT the tree),
3200 causing agenda commands to skip the entry but continuing the search in
3201 the subtree. This is a function that can be put into
3202 `org-agenda-skip-function' for the duration of a command. An important
3203 use of this function is for the stuck project list."
3204 (let ((end (save-excursion (org-end-of-subtree t
)))
3205 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3208 (setq skip
(re-search-forward org-agenda-skip-regexp end t
)))
3209 (and skip entry-end
)))
3211 (defun org-agenda-skip-entry-if (&rest conditions
)
3212 "Skip entry if any of CONDITIONS is true.
3213 See `org-agenda-skip-if' for details."
3214 (org-agenda-skip-if nil conditions
))
3216 (defun org-agenda-skip-subtree-if (&rest conditions
)
3217 "Skip entry if any of CONDITIONS is true.
3218 See `org-agenda-skip-if' for details."
3219 (org-agenda-skip-if t conditions
))
3221 (defun org-agenda-skip-if (subtree conditions
)
3222 "Checks current entity for CONDITIONS.
3223 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3224 the entry, i.e. the text before the next heading is checked.
3226 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3227 from different tests. Valid conditions are:
3229 scheduled Check if there is a scheduled cookie
3230 notscheduled Check if there is no scheduled cookie
3231 deadline Check if there is a deadline
3232 notdeadline Check if there is no deadline
3233 timestamp Check if there is a timestamp (also deadline or scheduled)
3234 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3235 regexp Check if regexp matches
3236 notregexp Check if regexp does not match.
3238 The regexp is taken from the conditions list, it must come right after
3239 the `regexp' or `notregexp' element.
3241 If any of these conditions is met, this function returns the end point of
3242 the entity, causing the search to continue from there. This is a function
3243 that can be put into `org-agenda-skip-function' for the duration of a command."
3245 (org-back-to-heading t
)
3248 (progn (org-end-of-subtree t
) (point))
3249 (progn (outline-next-heading) (1- (point)))))
3253 (and (memq 'scheduled conditions
)
3254 (re-search-forward org-scheduled-time-regexp end t
))
3255 (and (memq 'notscheduled conditions
)
3256 (not (re-search-forward org-scheduled-time-regexp end t
)))
3257 (and (memq 'deadline conditions
)
3258 (re-search-forward org-deadline-time-regexp end t
))
3259 (and (memq 'notdeadline conditions
)
3260 (not (re-search-forward org-deadline-time-regexp end t
)))
3261 (and (memq 'timestamp conditions
)
3262 (re-search-forward org-ts-regexp end t
))
3263 (and (memq 'nottimestamp conditions
)
3264 (not (re-search-forward org-ts-regexp end t
)))
3265 (and (setq m
(memq 'regexp conditions
))
3267 (re-search-forward (nth 1 m
) end t
))
3268 (and (setq m
(memq 'notregexp conditions
))
3270 (not (re-search-forward (nth 1 m
) end t
))))
3274 (defun org-agenda-list-stuck-projects (&rest ignore
)
3275 "Create agenda view for projects that are stuck.
3276 Stuck projects are project that have no next actions. For the definitions
3277 of what a project is and how to check if it stuck, customize the variable
3278 `org-stuck-projects'.
3279 MATCH is being ignored."
3281 (let* ((org-agenda-skip-function
3282 'org-agenda-skip-entry-when-regexp-matches-in-subtree
)
3283 ;; We could have used org-agenda-skip-if here.
3284 (org-agenda-overriding-header "List of stuck projects: ")
3285 (matcher (nth 0 org-stuck-projects
))
3286 (todo (nth 1 org-stuck-projects
))
3287 (todo-wds (if (member "*" todo
)
3289 (org-prepare-agenda-buffers (org-agenda-files
3292 org-done-keywords-for-agenda
3293 (copy-sequence org-todo-keywords-for-agenda
)))
3295 (todo-re (concat "^\\*+[ \t]+\\("
3296 (mapconcat 'identity todo-wds
"\\|")
3298 (tags (nth 2 org-stuck-projects
))
3299 (tags-re (if (member "*" tags
)
3300 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3302 (concat "^\\*+ .*:\\("
3303 (mapconcat 'identity tags
"\\|")
3304 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3305 (gen-re (nth 3 org-stuck-projects
))
3311 (and gen-re
(stringp gen-re
) (string-match "\\S-" gen-re
)
3313 (setq org-agenda-skip-regexp
3315 (mapconcat 'identity re-list
"\\|")
3316 (error "No information how to identify unstuck projects")))
3317 (org-tags-view nil matcher
)
3318 (with-current-buffer org-agenda-buffer-name
3319 (setq org-agenda-redo-command
3320 '(org-agenda-list-stuck-projects
3321 (or current-prefix-arg org-last-arg
))))))
3323 ;;; Diary integration
3325 (defvar org-disable-agenda-to-diary nil
) ;Dynamically-scoped param.
3326 (defvar list-diary-entries-hook
)
3328 (defun org-get-entries-from-diary (date)
3329 "Get the (Emacs Calendar) diary entries for DATE."
3330 (require 'diary-lib
)
3331 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3332 (fancy-diary-buffer diary-fancy-buffer
)
3333 (diary-display-hook '(fancy-diary-display))
3334 (diary-display-function 'fancy-diary-display
)
3336 (list-diary-entries-hook
3337 (cons 'org-diary-default-entry list-diary-entries-hook
))
3338 (diary-file-name-prefix-function nil
) ; turn this feature off
3339 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string
)
3341 (org-disable-agenda-to-diary t
))
3343 (save-window-excursion
3344 (funcall (if (fboundp 'diary-list-entries
)
3345 'diary-list-entries
'list-diary-entries
)
3347 (if (not (get-buffer diary-fancy-buffer
))
3349 (with-current-buffer diary-fancy-buffer
3350 (setq buffer-read-only nil
)
3351 (if (zerop (buffer-size))
3354 ;; Omit the date and other unnecessary stuff
3355 (org-agenda-cleanup-fancy-diary)
3356 ;; Add prefix to each line and extend the text properties
3357 (if (zerop (buffer-size))
3359 (setq entries
(buffer-substring (point-min) (- (point-max) 1)))))
3360 (set-buffer-modified-p nil
)
3361 (kill-buffer diary-fancy-buffer
)))
3363 (setq entries
(org-split-string entries
"\n"))
3367 (setq x
(org-format-agenda-item "" x
"Diary" nil
'time
))
3368 ;; Extend the text properties to the beginning of the line
3369 (org-add-props x
(text-properties-at (1- (length x
)) x
)
3370 'type
"diary" 'date date
))
3373 (defun org-agenda-cleanup-fancy-diary ()
3374 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3375 This gets rid of the date, the underline under the date, and
3376 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3377 date. It also removes lines that contain only whitespace."
3378 (goto-char (point-min))
3379 (if (looking-at ".*?:[ \t]*")
3382 (re-search-forward "\n=+$" nil t
)
3384 (while (re-search-backward "^ +\n?" nil t
) (replace-match "")))
3385 (re-search-forward "\n=+$" nil t
)
3386 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3387 (goto-char (point-min))
3388 (while (re-search-forward "^ +\n" nil t
)
3390 (goto-char (point-min))
3391 (if (re-search-forward "^Org-mode dummy\n?" nil t
)
3392 (replace-match "")))
3394 ;; Make sure entries from the diary have the right text properties.
3395 (eval-after-load "diary-lib"
3396 '(if (boundp 'diary-modify-entry-list-string-function
)
3397 ;; We can rely on the hook, nothing to do
3399 ;; Hook not available, must use advice to make this work
3400 (defadvice add-to-diary-list
(before org-mark-diary-entry activate
)
3401 "Make the position visible."
3402 (if (and org-disable-agenda-to-diary
;; called from org-agenda
3405 (setq string
(org-modify-diary-entry-string string
))))))
3407 (defun org-modify-diary-entry-string (string)
3408 "Add text properties to string, allowing org-mode to act on it."
3409 (org-add-props string nil
3410 'mouse-face
'highlight
3411 'keymap org-agenda-keymap
3412 'help-echo
(if buffer-file-name
3413 (format "mouse-2 or RET jump to diary file %s"
3414 (abbreviate-file-name buffer-file-name
))
3416 'org-agenda-diary-link t
3417 'org-marker
(org-agenda-new-marker (point-at-bol))))
3419 (defun org-diary-default-entry ()
3420 "Add a dummy entry to the diary.
3421 Needed to avoid empty dates which mess up holiday display."
3422 ;; Catch the error if dealing with the new add-to-diary-alist
3423 (when org-disable-agenda-to-diary
3425 (org-add-to-diary-list original-date
"Org-mode dummy" "")
3427 (org-add-to-diary-list original-date
"Org-mode dummy" "" nil
)))))
3429 (defun org-add-to-diary-list (&rest args
)
3430 (if (fboundp 'diary-add-to-list
)
3431 (apply 'diary-add-to-list args
)
3432 (apply 'add-to-diary-list args
)))
3435 (defun org-diary (&rest args
)
3436 "Return diary information from org-files.
3437 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3438 It accesses org files and extracts information from those files to be
3439 listed in the diary. The function accepts arguments specifying what
3440 items should be listed. The following arguments are allowed:
3442 :timestamp List the headlines of items containing a date stamp or
3443 date range matching the selected date. Deadlines will
3444 also be listed, on the expiration day.
3446 :sexp List entries resulting from diary-like sexps.
3448 :deadline List any deadlines past due, or due within
3449 `org-deadline-warning-days'. The listing occurs only
3450 in the diary for *today*, not at any other date. If
3451 an entry is marked DONE, it is no longer listed.
3453 :scheduled List all items which are scheduled for the given date.
3454 The diary for *today* also contains items which were
3455 scheduled earlier and are not yet marked DONE.
3457 :todo List all TODO items from the org-file. This may be a
3458 long list - so this is not turned on by default.
3459 Like deadlines, these entries only show up in the
3460 diary for *today*, not at any other date.
3462 The call in the diary file should look like this:
3464 &%%(org-diary) ~/path/to/some/orgfile.org
3466 Use a separate line for each org file to check. Or, if you omit the file name,
3467 all files listed in `org-agenda-files' will be checked automatically:
3471 If you don't give any arguments (as in the example above), the default
3472 arguments (:deadline :scheduled :timestamp :sexp) are used.
3473 So the example above may also be written as
3475 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3477 The function expects the lisp variables `entry' and `date' to be provided
3478 by the caller, because this is how the calendar works. Don't use this
3479 function from a program - use `org-agenda-get-day-entries' instead."
3480 (when (> (- (time-to-seconds (current-time))
3481 org-agenda-last-marker-time
)
3483 (org-agenda-reset-markers))
3484 (org-compile-prefix-format 'agenda
)
3485 (org-set-sorting-strategy 'agenda
)
3486 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3487 (let* ((files (if (and entry
(stringp entry
) (string-match "\\S-" entry
))
3489 (org-agenda-files t
)))
3491 (org-prepare-agenda-buffers files
)
3492 ;; If this is called during org-agenda, don't return any entries to
3493 ;; the calendar. Org Agenda will list these entries itself.
3494 (if org-disable-agenda-to-diary
(setq files nil
))
3495 (while (setq file
(pop files
))
3496 (setq rtn
(apply 'org-agenda-get-day-entries file date args
))
3497 (setq results
(append results rtn
)))
3499 (concat (org-finalize-agenda-entries results
) "\n"))))
3501 ;;; Agenda entry finders
3503 (defun org-agenda-get-day-entries (file date
&rest args
)
3504 "Does the work for `org-diary' and `org-agenda'.
3505 FILE is the path to a file to be checked for entries. DATE is date like
3506 the one returned by `calendar-current-date'. ARGS are symbols indicating
3507 which kind of entries should be extracted. For details about these, see
3508 the documentation of `org-diary'."
3509 (setq args
(or args
'(:deadline
:scheduled
:timestamp
:sexp
)))
3510 (let* ((org-startup-folded nil
)
3511 (org-startup-align-all-tables nil
)
3512 (buffer (if (file-exists-p file
)
3513 (org-get-agenda-file-buffer file
)
3514 (error "No such file %s" file
)))
3517 ;; If file does not exist, make sure an error message ends up in diary
3518 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file
))
3519 (with-current-buffer buffer
3520 (unless (org-mode-p)
3521 (error "Agenda file %s is not in `org-mode'" file
))
3522 (let ((case-fold-search nil
))
3525 (if org-agenda-restrict
3526 (narrow-to-region org-agenda-restrict-begin
3527 org-agenda-restrict-end
)
3529 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3530 (while (setq arg
(pop args
))
3532 ((and (eq arg
:todo
)
3533 (equal date
(calendar-current-date)))
3534 (setq rtn
(org-agenda-get-todos))
3535 (setq results
(append results rtn
)))
3536 ((eq arg
:timestamp
)
3537 (setq rtn
(org-agenda-get-blocks))
3538 (setq results
(append results rtn
))
3539 (setq rtn
(org-agenda-get-timestamps))
3540 (setq results
(append results rtn
)))
3542 (setq rtn
(org-agenda-get-sexps))
3543 (setq results
(append results rtn
)))
3544 ((eq arg
:scheduled
)
3545 (setq rtn
(org-agenda-get-scheduled))
3546 (setq results
(append results rtn
)))
3548 (setq rtn
(org-agenda-get-progress))
3549 (setq results
(append results rtn
)))
3551 (setq rtn
(org-agenda-get-deadlines))
3552 (setq results
(append results rtn
))))))))
3555 (defun org-agenda-get-todos ()
3556 "Return the TODO information for agenda display."
3557 (let* ((props (list 'face nil
3558 'done-face
'org-agenda-done
3559 'org-not-done-regexp org-not-done-regexp
3560 'org-todo-regexp org-todo-regexp
3561 'org-complex-heading-regexp org-complex-heading-regexp
3562 'mouse-face
'highlight
3563 'keymap org-agenda-keymap
3565 (format "mouse-2 or RET jump to org file %s"
3566 (abbreviate-file-name buffer-file-name
))))
3567 (regexp (concat "^\\*+[ \t]+\\("
3568 (if org-select-this-todo-keyword
3569 (if (equal org-select-this-todo-keyword
"*")
3572 (mapconcat 'identity
(org-split-string org-select-this-todo-keyword
"|") "\\|")
3574 org-not-done-regexp
)
3576 marker priority category tags todo-state
3578 (goto-char (point-min))
3579 (while (re-search-forward regexp nil t
)
3583 (setq beg
(point) end
(save-excursion (outline-next-heading) (point)))
3584 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end
)
3585 (goto-char (1+ beg
))
3586 (or org-agenda-todo-list-sublevels
(org-end-of-subtree 'invisible
))
3590 (goto-char (match-beginning 1))
3591 (setq marker
(org-agenda-new-marker (match-beginning 0))
3592 category
(org-get-category)
3593 txt
(match-string 1)
3594 tags
(org-get-tags-at (point))
3595 txt
(org-format-agenda-item "" txt category tags
)
3596 priority
(1+ (org-get-priority txt
))
3597 todo-state
(org-get-todo-state))
3598 (org-add-props txt props
3599 'org-marker marker
'org-hd-marker marker
3600 'priority priority
'org-category category
3601 'type
"todo" 'todo-state todo-state
)
3603 (if org-agenda-todo-list-sublevels
3604 (goto-char (match-end 1))
3605 (org-end-of-subtree 'invisible
))))
3609 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end
)
3610 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3611 (when (or org-agenda-todo-ignore-with-date
3612 org-agenda-todo-ignore-scheduled
3613 org-agenda-todo-ignore-deadlines
)
3614 (setq end
(or end
(save-excursion (outline-next-heading) (point))))
3616 (or (and org-agenda-todo-ignore-with-date
3617 (re-search-forward org-ts-regexp end t
))
3618 (and org-agenda-todo-ignore-scheduled
3619 (re-search-forward org-scheduled-time-regexp end t
))
3620 (and org-agenda-todo-ignore-deadlines
3621 (re-search-forward org-deadline-time-regexp end t
)
3622 (org-deadline-close (match-string 1)))))))
3624 (defconst org-agenda-no-heading-message
3625 "No heading for this item in buffer or region.")
3627 (defun org-agenda-get-timestamps ()
3628 "Return the date stamp information for agenda display."
3629 (let* ((props (list 'face nil
3630 'org-not-done-regexp org-not-done-regexp
3631 'org-todo-regexp org-todo-regexp
3632 'org-complex-heading-regexp org-complex-heading-regexp
3633 'mouse-face
'highlight
3634 'keymap org-agenda-keymap
3636 (format "mouse-2 or RET jump to org file %s"
3637 (abbreviate-file-name buffer-file-name
))))
3638 (d1 (calendar-absolute-from-gregorian date
))
3644 (encode-time 0 0 0 (nth 1 date
) (nth 0 date
) (nth 2 date
))))
3648 (if org-agenda-include-inactive-timestamps
"[[<]" "<")
3652 (car org-time-stamp-formats
)
3653 (apply 'encode-time
; DATE bound by calendar
3654 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3656 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
3657 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
3658 marker hdmarker deadlinep scheduledp clockp closedp inactivep
3659 donep tmp priority category ee txt timestr tags b0 b3 e3 head
3661 (goto-char (point-min))
3662 (while (re-search-forward regexp nil t
)
3663 (setq b0
(match-beginning 0)
3664 b3
(match-beginning 3) e3
(match-end 3))
3666 (and (org-at-date-range-p) (throw :skip nil
))
3668 (if (and (match-end 1)
3669 (not (= d1
(org-time-string-to-absolute
3670 (match-string 1) d1 nil
3671 org-agenda-repeating-timestamp-show-all
))))
3674 (not (org-diary-sexp-entry (buffer-substring b3 e3
) "" date
)))
3676 (setq marker
(org-agenda-new-marker b0
)
3677 category
(org-get-category b0
)
3678 tmp
(buffer-substring (max (point-min)
3679 (- b0 org-ds-keyword-length
))
3681 timestr
(if b3
"" (buffer-substring b0
(point-at-eol)))
3682 inactivep
(= (char-after b0
) ?\
[)
3683 deadlinep
(string-match org-deadline-regexp tmp
)
3684 scheduledp
(string-match org-scheduled-regexp tmp
)
3685 closedp
(and org-agenda-include-inactive-timestamps
3686 (string-match org-closed-string tmp
))
3687 clockp
(and org-agenda-include-inactive-timestamps
3688 (or (string-match org-clock-string tmp
)
3689 (string-match "]-+\\'" tmp
)))
3690 todo-state
(org-get-todo-state)
3691 donep
(member todo-state org-done-keywords
))
3692 (if (or scheduledp deadlinep closedp clockp
)
3694 (if (string-match ">" timestr
)
3695 ;; substring should only run to end of time stamp
3696 (setq timestr
(substring timestr
0 (match-end 0))))
3698 (if (re-search-backward "^\\*+ " nil t
)
3700 (goto-char (match-beginning 0))
3701 (setq hdmarker
(org-agenda-new-marker)
3702 tags
(org-get-tags-at))
3703 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3704 (setq head
(match-string 1))
3705 (and org-agenda-skip-timestamp-if-done donep
(throw :skip t
))
3706 (setq txt
(org-format-agenda-item
3707 (if inactivep
"[" nil
)
3708 head category tags timestr nil
3710 (setq txt org-agenda-no-heading-message
))
3711 (setq priority
(org-get-priority txt
))
3712 (org-add-props txt props
3713 'org-marker marker
'org-hd-marker hdmarker
)
3714 (org-add-props txt nil
'priority priority
3715 'org-category category
'date date
3716 'todo-state todo-state
3719 (outline-next-heading)))
3722 (defun org-agenda-get-sexps ()
3723 "Return the sexp information for agenda display."
3724 (require 'diary-lib
)
3725 (let* ((props (list 'face nil
3726 'mouse-face
'highlight
3727 'keymap org-agenda-keymap
3729 (format "mouse-2 or RET jump to org file %s"
3730 (abbreviate-file-name buffer-file-name
))))
3732 marker category ee txt tags entry result beg b sexp sexp-entry
3734 (goto-char (point-min))
3735 (while (re-search-forward regexp nil t
)
3738 (setq beg
(match-beginning 0))
3739 (goto-char (1- (match-end 0)))
3742 (setq sexp
(buffer-substring b
(point)))
3743 (setq sexp-entry
(if (looking-at "[ \t]*\\(\\S-.*\\)")
3744 (org-trim (match-string 1))
3746 (setq result
(org-diary-sexp-entry sexp sexp-entry date
))
3748 (setq marker
(org-agenda-new-marker beg
)
3749 category
(org-get-category beg
)
3750 todo-state
(org-get-todo-state))
3752 (if (string-match "\\S-" result
)
3754 (setq txt
"SEXP entry returned empty string"))
3756 (setq txt
(org-format-agenda-item
3757 "" txt category tags
'time
))
3758 (org-add-props txt props
'org-marker marker
)
3759 (org-add-props txt nil
3760 'org-category category
'date date
'todo-state todo-state
3765 (defalias 'org-get-closed
'org-agenda-get-progress
)
3766 (defun org-agenda-get-progress ()
3767 "Return the logged TODO entries for agenda display."
3768 (let* ((props (list 'mouse-face
'highlight
3769 'org-not-done-regexp org-not-done-regexp
3770 'org-todo-regexp org-todo-regexp
3771 'org-complex-heading-regexp org-complex-heading-regexp
3772 'keymap org-agenda-keymap
3774 (format "mouse-2 or RET jump to org file %s"
3775 (abbreviate-file-name buffer-file-name
))))
3776 (items (if (consp org-agenda-show-log
)
3778 org-agenda-log-mode-items
))
3782 (if (memq 'closed items
) (concat "\\<" org-closed-string
))
3783 (if (memq 'clock items
) (concat "\\<" org-clock-string
))
3784 (if (memq 'state items
) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
3785 (parts-re (if parts
(mapconcat 'identity parts
"\\|")
3786 (error "`org-agenda-log-mode-items' is empty")))
3788 "\\(" parts-re
"\\)"
3793 (car org-time-stamp-formats
)
3794 (apply 'encode-time
; DATE bound by calendar
3795 (list 0 0 0 (nth 1 date
) (car date
) (nth 2 date
))))
3797 marker hdmarker priority category tags closedp statep state
3798 ee txt timestr rest clocked
)
3799 (goto-char (point-min))
3800 (while (re-search-forward regexp nil t
)
3803 (setq marker
(org-agenda-new-marker (match-beginning 0))
3804 closedp
(equal (match-string 1) org-closed-string
)
3805 statep
(equal (string-to-char (match-string 1)) ?-
)
3806 state
(and statep
(match-string 2))
3807 category
(org-get-category (match-beginning 0))
3808 timestr
(buffer-substring (match-beginning 0) (point-at-eol))
3809 ;; donep (org-entry-is-done-p)
3811 (when (string-match "\\]" timestr
)
3812 ;; substring should only run to end of time stamp
3813 (setq rest
(substring timestr
(match-end 0))
3814 timestr
(substring timestr
0 (match-end 0)))
3815 (if (and (not closedp
) (not statep
)
3816 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest
))
3817 (progn (setq timestr
(concat (substring timestr
0 -
1)
3818 "-" (match-string 1 rest
) "]"))
3819 (setq clocked
(match-string 2 rest
)))
3820 (setq clocked
"-")))
3822 (if (re-search-backward "^\\*+ " nil t
)
3824 (goto-char (match-beginning 0))
3825 (setq hdmarker
(org-agenda-new-marker)
3826 tags
(org-get-tags-at))
3827 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
3828 (setq txt
(org-format-agenda-item
3830 (closedp "Closed: ")
3831 (statep (concat "State: (" state
")"))
3832 (t (concat "Clocked: (" clocked
")")))
3833 (match-string 1) category tags timestr
)))
3834 (setq txt org-agenda-no-heading-message
))
3835 (setq priority
100000)
3836 (org-add-props txt props
3837 'org-marker marker
'org-hd-marker hdmarker
'face
'org-agenda-done
3838 'priority priority
'org-category category
3839 'type
"closed" 'date date
3840 'undone-face
'org-warning
'done-face
'org-agenda-done
)
3842 (goto-char (point-at-eol))))
3845 (defun org-agenda-get-deadlines ()
3846 "Return the deadline information for agenda display."
3847 (let* ((props (list 'mouse-face
'highlight
3848 'org-not-done-regexp org-not-done-regexp
3849 'org-todo-regexp org-todo-regexp
3850 'org-complex-heading-regexp org-complex-heading-regexp
3851 'keymap org-agenda-keymap
3853 (format "mouse-2 or RET jump to org file %s"
3854 (abbreviate-file-name buffer-file-name
))))
3855 (regexp org-deadline-time-regexp
)
3856 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3857 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3858 d2 diff dfrac wdays pos pos1 category tags
3859 ee txt head face s todo-state upcomingp donep timestr
)
3860 (goto-char (point-min))
3861 (while (re-search-forward regexp nil t
)
3864 (setq s
(match-string 1)
3865 pos
(1- (match-beginning 1))
3866 d2
(org-time-string-to-absolute
3867 (match-string 1) d1
'past
3868 org-agenda-repeating-timestamp-show-all
)
3870 wdays
(org-get-wdays s
)
3871 dfrac
(/ (* 1.0 (- wdays diff
)) (max wdays
1))
3872 upcomingp
(and todayp
(> diff
0)))
3873 ;; When to show a deadline in the calendar:
3874 ;; If the expiration is within wdays warning time.
3875 ;; Past-due deadlines are only shown on the current date
3876 (if (or (and (<= diff wdays
)
3877 (and todayp
(not org-agenda-only-exact-dates
)))
3880 (setq category
(org-get-category))
3881 (setq todo-state
(org-get-todo-state))
3882 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3884 (goto-char (match-end 0))
3885 (setq pos1
(match-beginning 0))
3886 (setq tags
(org-get-tags-at pos1
))
3887 (setq head
(buffer-substring-no-properties
3889 (progn (skip-chars-forward "^\r\n")
3891 (setq donep
(member todo-state org-done-keywords
))
3892 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3894 (concat (substring s
(match-beginning 1)) " "))
3895 (setq timestr
'time
))
3897 (or org-agenda-skip-deadline-if-done
3900 (setq txt
(org-format-agenda-item
3902 (car org-agenda-deadline-leaders
)
3903 (if (functionp (nth 1 org-agenda-deadline-leaders
))
3904 (funcall (nth 1 org-agenda-deadline-leaders
) diff date
)
3905 (format (nth 1 org-agenda-deadline-leaders
)
3908 (if (not (= diff
0)) nil timestr
)))))
3909 (setq txt org-agenda-no-heading-message
))
3911 (setq face
(org-agenda-deadline-face dfrac wdays
))
3912 (org-add-props txt props
3913 'org-marker
(org-agenda-new-marker pos
)
3914 'org-hd-marker
(org-agenda-new-marker pos1
)
3915 'priority
(+ (- diff
)
3916 (org-get-priority txt
))
3917 'org-category category
3918 'todo-state todo-state
3919 'type
(if upcomingp
"upcoming-deadline" "deadline")
3920 'date
(if upcomingp date d2
)
3921 'face
(if donep
'org-agenda-done face
)
3922 'undone-face face
'done-face
'org-agenda-done
)
3926 (defun org-agenda-deadline-face (fraction &optional wdays
)
3927 "Return the face to displaying a deadline item.
3928 FRACTION is what fraction of the head-warning time has passed."
3929 (if (equal wdays
0) (setq fraction
1.
))
3930 (let ((faces org-agenda-deadline-faces
) f
)
3932 (while (setq f
(pop faces
))
3933 (if (>= fraction
(car f
)) (throw 'exit
(cdr f
)))))))
3935 (defun org-agenda-get-scheduled ()
3936 "Return the scheduled information for agenda display."
3937 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
3938 'org-todo-regexp org-todo-regexp
3939 'org-complex-heading-regexp org-complex-heading-regexp
3940 'done-face
'org-agenda-done
3941 'mouse-face
'highlight
3942 'keymap org-agenda-keymap
3944 (format "mouse-2 or RET jump to org file %s"
3945 (abbreviate-file-name buffer-file-name
))))
3946 (regexp org-scheduled-time-regexp
)
3947 (todayp (org-agenda-todayp date
)) ; DATE bound by calendar
3948 (d1 (calendar-absolute-from-gregorian date
)) ; DATE bound by calendar
3949 d2 diff pos pos1 category tags donep
3950 ee txt head pastschedp todo-state face timestr s
)
3951 (goto-char (point-min))
3952 (while (re-search-forward regexp nil t
)
3955 (setq s
(match-string 1)
3956 pos
(1- (match-beginning 1))
3957 d2
(org-time-string-to-absolute
3958 (match-string 1) d1
'past
3959 org-agenda-repeating-timestamp-show-all
)
3961 (setq pastschedp
(and todayp
(< diff
0)))
3962 ;; When to show a scheduled item in the calendar:
3963 ;; If it is on or past the date.
3964 (if (or (and (< diff
0)
3965 (< (abs diff
) org-scheduled-past-days
)
3966 (and todayp
(not org-agenda-only-exact-dates
)))
3969 (setq category
(org-get-category))
3970 (setq todo-state
(org-get-todo-state))
3971 (if (re-search-backward "^\\*+[ \t]+" nil t
)
3973 (goto-char (match-end 0))
3974 (setq pos1
(match-beginning 0))
3975 (setq tags
(org-get-tags-at))
3976 (setq head
(buffer-substring-no-properties
3978 (progn (skip-chars-forward "^\r\n") (point))))
3979 (setq donep
(member todo-state org-done-keywords
))
3980 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s
)
3982 (concat (substring s
(match-beginning 1)) " "))
3983 (setq timestr
'time
))
3985 (or org-agenda-skip-scheduled-if-done
3988 (setq txt
(org-format-agenda-item
3990 (car org-agenda-scheduled-leaders
)
3991 (format (nth 1 org-agenda-scheduled-leaders
)
3994 (if (not (= diff
0)) nil timestr
)))))
3995 (setq txt org-agenda-no-heading-message
))
3999 (pastschedp 'org-scheduled-previously
)
4000 (todayp 'org-scheduled-today
)
4001 (t 'org-scheduled
)))
4002 (org-add-props txt props
4004 'face
(if donep
'org-agenda-done face
)
4005 'org-marker
(org-agenda-new-marker pos
)
4006 'org-hd-marker
(org-agenda-new-marker pos1
)
4007 'type
(if pastschedp
"past-scheduled" "scheduled")
4008 'date
(if pastschedp d2 date
)
4009 'priority
(+ 94 (- 5 diff
) (org-get-priority txt
))
4010 'org-category category
4011 'todo-state todo-state
)
4015 (defun org-agenda-get-blocks ()
4016 "Return the date-range information for agenda display."
4017 (let* ((props (list 'face nil
4018 'org-not-done-regexp org-not-done-regexp
4019 'org-todo-regexp org-todo-regexp
4020 'org-complex-heading-regexp org-complex-heading-regexp
4021 'mouse-face
'highlight
4022 'keymap org-agenda-keymap
4024 (format "mouse-2 or RET jump to org file %s"
4025 (abbreviate-file-name buffer-file-name
))))
4026 (regexp org-tr-regexp
)
4027 (d0 (calendar-absolute-from-gregorian date
))
4028 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4030 (goto-char (point-min))
4031 (while (re-search-forward regexp nil t
)
4035 (setq timestr
(match-string 0)
4038 d1
(time-to-days (org-time-string-to-time s1
))
4039 d2
(time-to-days (org-time-string-to-time s2
)))
4040 (if (and (> (- d0 d1
) -
1) (> (- d2 d0
) -
1))
4041 ;; Only allow days between the limits, because the normal
4042 ;; date stamps will catch the limits.
4044 (setq marker
(org-agenda-new-marker (point)))
4045 (setq category
(org-get-category))
4046 (setq todo-state
(org-get-todo-state))
4047 (if (re-search-backward "^\\*+ " nil t
)
4049 (goto-char (match-beginning 0))
4050 (setq hdmarker
(org-agenda-new-marker (point)))
4051 (setq tags
(org-get-tags-at))
4052 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4053 (setq head
(match-string 1))
4054 (and org-agenda-skip-timestamp-if-done
4055 (org-entry-is-done-p)
4057 (setq txt
(org-format-agenda-item
4059 (nth (if (= d1 d2
) 0 1)
4060 org-agenda-timerange-leaders
)
4061 (1+ (- d0 d1
)) (1+ (- d2 d1
)))
4063 (if (= d0 d1
) timestr
))))
4064 (setq txt org-agenda-no-heading-message
))
4065 (org-add-props txt props
4066 'org-marker marker
'org-hd-marker hdmarker
4067 'type
"block" 'date date
4068 'todo-state todo-state
4069 'priority
(org-get-priority txt
) 'org-category category
)
4072 ;; Sort the entries by expiration date.
4075 ;;; Agenda presentation and sorting
4077 (defvar org-prefix-has-time nil
4078 "A flag, set by `org-compile-prefix-format'.
4079 The flag is set if the currently compiled format contains a `%t'.")
4080 (defvar org-prefix-has-tag nil
4081 "A flag, set by `org-compile-prefix-format'.
4082 The flag is set if the currently compiled format contains a `%T'.")
4083 (defvar org-prefix-has-effort nil
4084 "A flag, set by `org-compile-prefix-format'.
4085 The flag is set if the currently compiled format contains a `%e'.")
4087 (defun org-format-agenda-item (extra txt
&optional category tags dotime
4089 "Format TXT to be inserted into the agenda buffer.
4090 In particular, it adds the prefix and corresponding text properties. EXTRA
4091 must be a string and replaces the `%s' specifier in the prefix format.
4092 CATEGORY (string, symbol or nil) may be used to overrule the default
4093 category taken from local variable or file name. It will replace the `%c'
4094 specifier in the format. DOTIME, when non-nil, indicates that a
4095 time-of-day should be extracted from TXT for sorting of this entry, and for
4096 the `%t' specifier in the format. When DOTIME is a string, this string is
4097 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4098 only the correctly processes TXT should be returned - this is used by
4099 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4100 Any match of REMOVE-RE will be removed from TXT."
4102 ;; Diary entries sometimes have extra whitespace at the beginning
4103 (if (string-match "^ +" txt
) (setq txt
(replace-match "" nil nil txt
)))
4104 (when org-agenda-show-inherited-tags
4105 ;; Fix the tags part in txt
4106 (setq txt
(org-agenda-add-inherited-tags txt tags
)))
4107 (let* ((category (or category
4109 (if buffer-file-name
4110 (file-name-sans-extension
4111 (file-name-nondirectory buffer-file-name
))
4113 ;; time, tag, effort are needed for the eval of the prefix format
4114 (tag (if tags
(nth (1- (length tags
)) tags
) ""))
4116 (ts (if dotime
(concat
4117 (if (stringp dotime
) dotime
"")
4118 (and org-agenda-search-headline-for-time txt
))))
4119 (time-of-day (and dotime
(org-get-time-of-day ts
)))
4120 stamp plain s0 s1 s2 t1 t2 rtn srp
4122 (and (org-mode-p) buffer-file-name
4123 (add-to-list 'org-agenda-contributing-files buffer-file-name
))
4124 (when (and dotime time-of-day
)
4125 ;; Extract starting and ending time and move them to prefix
4126 (when (or (setq stamp
(string-match org-stamp-time-of-day-regexp ts
))
4127 (setq plain
(string-match org-plain-time-of-day-regexp ts
)))
4128 (setq s0
(match-string 0 ts
)
4129 srp
(and stamp
(match-end 3))
4130 s1
(match-string (if plain
1 2) ts
)
4131 s2
(match-string (if plain
8 (if srp
4 6)) ts
))
4133 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4134 ;; them, we might want to remove them there to avoid duplication.
4135 ;; The user can turn this off with a variable.
4136 (if (and org-prefix-has-time
4137 org-agenda-remove-times-when-in-prefix
(or stamp plain
)
4138 (string-match (concat (regexp-quote s0
) " *") txt
)
4139 (not (equal ?\
] (string-to-char (substring txt
(match-end 0)))))
4140 (if (eq org-agenda-remove-times-when-in-prefix
'beg
)
4141 (= (match-beginning 0) 0)
4143 (setq txt
(replace-match "" nil nil txt
))))
4144 ;; Normalize the time(s) to 24 hour
4145 (if s1
(setq s1
(org-get-time-of-day s1
'string t
)))
4146 (if s2
(setq s2
(org-get-time-of-day s2
'string t
)))
4147 ;; Compute the duration
4149 (setq t1
(+ (* 60 (string-to-number (substring s1
0 2)))
4150 (string-to-number (substring s1
3)))
4152 (s2 (+ (* 60 (string-to-number (substring s2
0 2)))
4153 (string-to-number (substring s2
3))))
4154 (org-agenda-default-appointment-duration
4155 (+ t1 org-agenda-default-appointment-duration
))
4157 (setq duration
(if t2
(- t2 t1
)))))
4159 (when (and s1
(not s2
) org-agenda-default-appointment-duration
4160 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1
))
4161 (let ((m (+ (string-to-number (match-string 2 s1
))
4162 (* 60 (string-to-number (match-string 1 s1
)))
4163 org-agenda-default-appointment-duration
))
4165 (setq h
(/ m
60) m
(- m
(* h
60)))
4166 (setq s2
(format "%02d:%02d" h m
))))
4168 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4170 ;; Tags are in the string
4171 (if (or (eq org-agenda-remove-tags t
)
4172 (and org-agenda-remove-tags
4173 org-prefix-has-tag
))
4174 (setq txt
(replace-match "" t t txt
))
4175 (setq txt
(replace-match
4176 (concat (make-string (max (- 50 (length txt
)) 1) ?\
)
4177 (match-string 2 txt
))
4183 (or (get-text-property 0 'org-hd-marker txt
)
4184 (get-text-property 0 'org-marker txt
)))
4187 (setq neffort
(org-hh:mm-string-to-minutes effort
)
4188 effort
(setq effort
(concat "[" effort
"]" )))))
4191 (while (string-match remove-re txt
)
4192 (setq txt
(replace-match "" t t txt
))))
4194 ;; Create the final string
4197 ;; Prepare the variables needed in the eval of the compiled format
4198 (setq time
(cond (s2 (concat s1
"-" s2
))
4199 (s1 (concat s1
"......"))
4202 category
(if (symbolp category
) (symbol-name category
) category
))
4203 ;; Evaluate the compiled format
4204 (setq rtn
(concat (eval org-prefix-format-compiled
) txt
)))
4206 ;; And finally add the text properties
4207 (org-add-props rtn nil
4208 'org-category
(downcase category
)
4209 'tags
(mapcar 'org-downcase-keep-props tags
)
4210 'org-highest-priority org-highest-priority
4211 'org-lowest-priority org-lowest-priority
4212 'prefix-length
(- (length rtn
) (length txt
))
4213 'time-of-day time-of-day
4216 'effort-minutes neffort
4222 (defun org-agenda-add-inherited-tags (txt tags
)
4223 "Remove tags string from TXT, and add complete list of tags.
4224 The new list includes inherited tags. If any inherited tags are present,
4225 a double colon separates inherited tags from local tags."
4226 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt
)
4227 (setq txt
(substring txt
0 (match-beginning 0))))
4229 (let ((have-i (get-text-property 0 'inherited
(car tags
)))
4231 (setq txt
(concat txt
" :"
4234 (setq i
(get-text-property 0 'inherited x
))
4235 (if (and have-i
(not i
))
4241 (if have-i
"::" ":")))))
4244 (defun org-downcase-keep-props (s)
4245 (let ((props (text-properties-at 0 s
)))
4246 (setq s
(downcase s
))
4247 (add-text-properties 0 (length s
) props s
)
4250 (defvar org-agenda-sorting-strategy
) ;; because the def is in a let form
4251 (defvar org-agenda-sorting-strategy-selected nil
)
4253 (defun org-agenda-add-time-grid-maybe (list ndays todayp
)
4255 (cond ((not org-agenda-use-time-grid
) (throw 'exit list
))
4256 ((and todayp
(member 'today
(car org-agenda-time-grid
))))
4257 ((and (= ndays
1) (member 'daily
(car org-agenda-time-grid
))))
4258 ((member 'weekly
(car org-agenda-time-grid
)))
4259 (t (throw 'exit list
)))
4260 (let* ((have (delq nil
(mapcar
4261 (lambda (x) (get-text-property 1 'time-of-day x
))
4263 (string (nth 1 org-agenda-time-grid
))
4264 (gridtimes (nth 2 org-agenda-time-grid
))
4265 (req (car org-agenda-time-grid
))
4266 (remove (member 'remove-match req
))
4268 (if (and (member 'require-timed req
) (not have
))
4269 ;; don't show empty grid
4271 (while (setq time
(pop gridtimes
))
4272 (unless (and remove
(member time have
))
4273 (setq time
(int-to-string time
))
4274 (push (org-format-agenda-item
4276 (concat (substring time
0 -
2) ":" (substring time -
2)))
4279 1 (length (car new
)) 'face
'org-time-grid
(car new
))))
4280 (if (member 'time-up org-agenda-sorting-strategy-selected
)
4282 (append list new
)))))
4284 (defun org-compile-prefix-format (key)
4285 "Compile the prefix format into a Lisp form that can be evaluated.
4286 The resulting form is returned and stored in the variable
4287 `org-prefix-format-compiled'."
4288 (setq org-prefix-has-time nil org-prefix-has-tag nil
4289 org-prefix-has-effort nil
)
4291 ((stringp org-agenda-prefix-format
)
4292 org-agenda-prefix-format
)
4293 ((assq key org-agenda-prefix-format
)
4294 (cdr (assq key org-agenda-prefix-format
)))
4295 (t " %-12:c%?-12t% s")))
4297 varform vars var e c f opt
)
4298 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4300 (setq var
(cdr (assoc (match-string 4 s
)
4301 '(("c" . category
) ("t" . time
) ("s" . extra
)
4302 ("T" . tag
) ("e" . effort
))))
4303 c
(or (match-string 3 s
) "")
4304 opt
(match-beginning 1)
4305 start
(1+ (match-beginning 0)))
4306 (if (equal var
'time
) (setq org-prefix-has-time t
))
4307 (if (equal var
'tag
) (setq org-prefix-has-tag t
))
4308 (if (equal var
'effort
) (setq org-prefix-has-effort t
))
4309 (setq f
(concat "%" (match-string 2 s
) "s"))
4312 `(if (equal "" ,var
)
4314 (format ,f
(if (equal "" ,var
) "" (concat ,var
,c
)))))
4315 (setq varform
`(format ,f
(if (equal ,var
"") "" (concat ,var
,c
)))))
4316 (setq s
(replace-match "%s" t nil s
))
4317 (push varform vars
))
4318 (setq vars
(nreverse vars
))
4319 (setq org-prefix-format-compiled
`(format ,s
,@vars
))))
4321 (defun org-set-sorting-strategy (key)
4322 (if (symbolp (car org-agenda-sorting-strategy
))
4324 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy
)
4325 (setq org-agenda-sorting-strategy-selected
4326 (or (cdr (assq key org-agenda-sorting-strategy
))
4327 (cdr (assq 'agenda org-agenda-sorting-strategy
))
4328 '(time-up category-keep priority-down
)))))
4330 (defun org-get-time-of-day (s &optional string mod24
)
4331 "Check string S for a time of day.
4332 If found, return it as a military time number between 0 and 2400.
4333 If not found, return nil.
4334 The optional STRING argument forces conversion into a 5 character wide string
4338 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s
)
4339 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s
))
4340 (let* ((h (string-to-number (match-string 1 s
)))
4341 (m (if (match-end 3) (string-to-number (match-string 3 s
)) 0))
4342 (ampm (if (match-end 4) (downcase (match-string 4 s
))))
4343 (am-p (equal ampm
"am"))
4344 (h1 (cond ((not ampm
) h
)
4345 ((= h
12) (if am-p
0 12))
4346 (t (+ h
(if am-p
0 12)))))
4347 (h2 (if (and string mod24
(not (and (= m
0) (= h1
24))))
4349 (t0 (+ (* 100 h2
) m
))
4350 (t1 (concat (if (>= h1
24) "+" " ")
4351 (if (< t0
100) "0" "")
4352 (if (< t0
10) "0" "")
4353 (int-to-string t0
))))
4354 (if string
(concat (substring t1 -
4 -
2) ":" (substring t1 -
2)) t0
)))))
4356 (defun org-finalize-agenda-entries (list &optional nosort
)
4357 "Sort and concatenate the agenda items."
4358 (setq list
(mapcar 'org-agenda-highlight-todo list
))
4361 (mapconcat 'identity
(sort list
'org-entries-lessp
) "\n")))
4363 (defun org-agenda-highlight-todo (x)
4364 (let ((org-done-keywords org-done-keywords-for-agenda
)
4368 (beginning-of-line 1)
4369 (setq re
(get-text-property (point) 'org-todo-regexp
))
4370 (goto-char (+ (point) (or (get-text-property (point) 'prefix-length
) 0)))
4371 (when (looking-at (concat "[ \t]*\\.*\\(" re
"\\) +"))
4372 (add-text-properties (match-beginning 0) (match-end 0)
4373 (list 'face
(org-get-todo-face 1)))
4374 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4375 (delete-region (match-beginning 1) (1- (match-end 0)))
4376 (goto-char (match-beginning 1))
4377 (insert (format org-agenda-todo-keyword-format s
)))))
4378 (setq re
(concat (get-text-property 0 'org-todo-regexp x
))
4379 pl
(get-text-property 0 'prefix-length x
))
4381 (equal (string-match (concat "\\(\\.*\\)" re
"\\( +\\)")
4383 (add-text-properties
4384 (or (match-end 1) (match-end 0)) (match-end 0)
4385 (list 'face
(org-get-todo-face (match-string 2 x
)))
4387 (setq x
(concat (substring x
0 (match-end 1))
4388 (format org-agenda-todo-keyword-format
4391 (substring x
(match-end 3)))))
4394 (defsubst org-cmp-priority
(a b
)
4395 "Compare the priorities of string A and B."
4396 (let ((pa (or (get-text-property 1 'priority a
) 0))
4397 (pb (or (get-text-property 1 'priority b
) 0)))
4398 (cond ((> pa pb
) +1)
4402 (defsubst org-cmp-effort
(a b
)
4403 "Compare the priorities of string A and B."
4404 (let* ((def (if org-sort-agenda-noeffort-is-high
32767 -
1))
4405 (ea (or (get-text-property 1 'effort-minutes a
) def
))
4406 (eb (or (get-text-property 1 'effort-minutes b
) def
)))
4407 (cond ((> ea eb
) +1)
4411 (defsubst org-cmp-category
(a b
)
4412 "Compare the string values of categories of strings A and B."
4413 (let ((ca (or (get-text-property 1 'org-category a
) ""))
4414 (cb (or (get-text-property 1 'org-category b
) "")))
4415 (cond ((string-lessp ca cb
) -
1)
4416 ((string-lessp cb ca
) +1)
4419 (defsubst org-cmp-todo-state
(a b
)
4420 "Compare the todo states of strings A and B."
4421 (let* ((ma (or (get-text-property 1 'org-marker a
)
4422 (get-text-property 1 'org-hd-marker a
)))
4423 (mb (or (get-text-property 1 'org-marker b
)
4424 (get-text-property 1 'org-hd-marker b
)))
4425 (fa (and ma
(marker-buffer ma
)))
4426 (fb (and mb
(marker-buffer mb
)))
4428 (or (and fa
(with-current-buffer fa org-todo-keywords-1
))
4429 (and fb
(with-current-buffer fb org-todo-keywords-1
))))
4430 (ta (or (get-text-property 1 'todo-state a
) ""))
4431 (tb (or (get-text-property 1 'todo-state b
) ""))
4432 (la (- (length (member ta todo-kwds
))))
4433 (lb (- (length (member tb todo-kwds
))))
4434 (donepa (member ta org-done-keywords-for-agenda
))
4435 (donepb (member tb org-done-keywords-for-agenda
)))
4436 (cond ((and donepa
(not donepb
)) -
1)
4437 ((and (not donepa
) donepb
) +1)
4442 (defsubst org-cmp-tag
(a b
)
4443 "Compare the string values of the first tags of A and B."
4444 (let ((ta (car (last (get-text-property 1 'tags a
))))
4445 (tb (car (last (get-text-property 1 'tags b
)))))
4448 ((string-lessp ta tb
) -
1)
4449 ((string-lessp tb ta
) +1)
4452 (defsubst org-cmp-time
(a b
)
4453 "Compare the time-of-day values of strings A and B."
4454 (let* ((def (if org-sort-agenda-notime-is-late
9901 -
1))
4455 (ta (or (get-text-property 1 'time-of-day a
) def
))
4456 (tb (or (get-text-property 1 'time-of-day b
) def
)))
4457 (cond ((< ta tb
) -
1)
4461 (defun org-entries-lessp (a b
)
4462 "Predicate for sorting agenda entries."
4463 ;; The following variables will be used when the form is evaluated.
4464 ;; So even though the compiler complains, keep them.
4465 (let* ((time-up (org-cmp-time a b
))
4466 (time-down (if time-up
(- time-up
) nil
))
4467 (priority-up (org-cmp-priority a b
))
4468 (priority-down (if priority-up
(- priority-up
) nil
))
4469 (effort-up (org-cmp-effort a b
))
4470 (effort-down (if effort-up
(- effort-up
) nil
))
4471 (category-up (org-cmp-category a b
))
4472 (category-down (if category-up
(- category-up
) nil
))
4473 (category-keep (if category-up
+1 nil
))
4474 (tag-up (org-cmp-tag a b
))
4475 (tag-down (if tag-up
(- tag-up
) nil
))
4476 (todo-state-up (org-cmp-todo-state a b
))
4477 (todo-state-down (if todo-state-up
(- todo-state-up
) nil
))
4478 user-defined-up user-defined-down
)
4479 (if (and org-agenda-cmp-user-defined
4480 (functionp org-agenda-cmp-user-defined
))
4481 (setq user-defined-up
4482 (funcall org-agenda-cmp-user-defined a b
)
4483 user-defined-down
(if user-defined-up
(- user-defined-up
) nil
)))
4485 (eval (cons 'or org-agenda-sorting-strategy-selected
))
4486 '((-1 . t
) (1 . nil
) (nil . nil
))))))
4488 ;;; Agenda restriction lock
4490 (defvar org-agenda-restriction-lock-overlay
(org-make-overlay 1 1)
4491 "Overlay to mark the headline to which arenda commands are restricted.")
4492 (org-overlay-put org-agenda-restriction-lock-overlay
4493 'face
'org-agenda-restriction-lock
)
4494 (org-overlay-put org-agenda-restriction-lock-overlay
4495 'help-echo
"Agendas are currently limited to this subtree.")
4496 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4498 (defun org-agenda-set-restriction-lock (&optional type
)
4499 "Set restriction lock for agenda, to current subtree or file.
4500 Restriction will be the file if TYPE is `file', or if type is the
4501 universal prefix '(4), or if the cursor is before the first headline
4502 in the file. Otherwise, restriction will be to the current subtree."
4504 (and (equal type
'(4)) (setq type
'file
))
4507 ((org-at-heading-p) 'subtree
)
4508 ((condition-case nil
(org-back-to-heading t
) (error nil
))
4511 (if (eq type
'subtree
)
4513 (setq org-agenda-restrict t
)
4514 (setq org-agenda-overriding-restriction
'subtree
)
4515 (put 'org-agenda-files
'org-restrict
4516 (list (buffer-file-name (buffer-base-buffer))))
4517 (org-back-to-heading t
)
4518 (org-move-overlay org-agenda-restriction-lock-overlay
(point) (point-at-eol))
4519 (move-marker org-agenda-restrict-begin
(point))
4520 (move-marker org-agenda-restrict-end
4521 (save-excursion (org-end-of-subtree t
)))
4522 (message "Locking agenda restriction to subtree"))
4523 (put 'org-agenda-files
'org-restrict
4524 (list (buffer-file-name (buffer-base-buffer))))
4525 (setq org-agenda-restrict nil
)
4526 (setq org-agenda-overriding-restriction
'file
)
4527 (move-marker org-agenda-restrict-begin nil
)
4528 (move-marker org-agenda-restrict-end nil
)
4529 (message "Locking agenda restriction to file"))
4530 (setq current-prefix-arg nil
)
4531 (org-agenda-maybe-redo))
4533 (defun org-agenda-remove-restriction-lock (&optional noupdate
)
4534 "Remove the agenda restriction lock."
4536 (org-detach-overlay org-agenda-restriction-lock-overlay
)
4537 (org-detach-overlay org-speedbar-restriction-lock-overlay
)
4538 (setq org-agenda-overriding-restriction nil
)
4539 (setq org-agenda-restrict nil
)
4540 (put 'org-agenda-files
'org-restrict nil
)
4541 (move-marker org-agenda-restrict-begin nil
)
4542 (move-marker org-agenda-restrict-end nil
)
4543 (setq current-prefix-arg nil
)
4544 (message "Agenda restriction lock removed")
4545 (or noupdate
(org-agenda-maybe-redo)))
4547 (defun org-agenda-maybe-redo ()
4548 "If there is any window showing the agenda view, update it."
4549 (let ((w (get-buffer-window org-agenda-buffer-name t
))
4550 (w0 (selected-window)))
4555 (if org-agenda-overriding-restriction
4556 (message "Agenda view shifted to new %s restriction"
4557 org-agenda-overriding-restriction
)
4558 (message "Agenda restriction lock removed")))))
4562 (defun org-agenda-check-type (error &rest types
)
4563 "Check if agenda buffer is of allowed type.
4564 If ERROR is non-nil, throw an error, otherwise just return nil."
4565 (if (memq org-agenda-type types
)
4568 (error "Not allowed in %s-type agenda buffers" org-agenda-type
)
4571 (defun org-agenda-quit ()
4572 "Exit agenda by removing the window or the buffer."
4574 (if org-agenda-columns-active
4576 (let ((buf (current-buffer)))
4577 (and (not (eq org-agenda-window-setup
'current-window
))
4578 (not (one-window-p))
4581 (org-agenda-reset-markers)
4582 (org-columns-remove-overlays)
4583 (setq org-agenda-archives-mode nil
))
4584 ;; Maybe restore the pre-agenda window configuration.
4585 (and org-agenda-restore-windows-after-quit
4586 (not (eq org-agenda-window-setup
'other-frame
))
4587 org-pre-agenda-window-conf
4588 (set-window-configuration org-pre-agenda-window-conf
))))
4590 (defun org-agenda-exit ()
4591 "Exit agenda by removing the window or the buffer.
4592 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
4593 Org-mode buffers visited directly by the user will not be touched."
4595 (org-release-buffers org-agenda-new-buffers
)
4596 (setq org-agenda-new-buffers nil
)
4599 (defun org-agenda-execute (arg)
4600 "Execute another agenda command, keeping same window.\\<global-map>
4601 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
4603 (let ((org-agenda-window-setup 'current-window
))
4606 (defun org-agenda-redo ()
4608 When this is the global TODO list, a prefix argument will be interpreted."
4610 (let* ((org-agenda-keep-modes t
)
4611 (filter org-agenda-filter
)
4612 (preset (get 'org-agenda-filter
:preset-filter
))
4613 (cols org-agenda-columns-active
)
4614 (line (org-current-line))
4615 (window-line (- line
(org-current-line (window-start))))
4616 (lprops (get 'org-agenda-redo-command
'org-lprops
)))
4617 (put 'org-agenda-filter
:preset-filter nil
)
4618 (and cols
(org-columns-quit))
4619 (message "Rebuilding agenda buffer...")
4620 (org-let lprops
'(eval org-agenda-redo-command
))
4621 (setq org-agenda-undo-list nil
4622 org-agenda-pending-undo-list nil
)
4623 (message "Rebuilding agenda buffer...done")
4624 (put 'org-agenda-filter
:preset-filter preset
)
4625 (and (or filter preset
) (org-agenda-filter-apply filter
))
4626 (and cols
(interactive-p) (org-agenda-columns))
4628 (recenter window-line
)))
4631 (defvar org-global-tags-completion-table nil
)
4632 (defvar org-agenda-filter-form nil
)
4633 (defun org-agenda-filter-by-tag (strip &optional char narrow
)
4634 "Keep only those lines in the agenda buffer that have a specific tag.
4635 The tag is selected with its fast selection letter, as configured.
4636 With prefix argument STRIP, remove all lines that do have the tag.
4637 A lisp caller can specify CHAR. NARROW means that the new tag should be
4638 used to narrow the search - the interactive user can also press `-' or `+'
4639 to switch to narrowing."
4641 (let* ((alist org-tag-alist-for-agenda
)
4642 (tag-chars (mapconcat
4643 (lambda (x) (if (cdr x
) (char-to-string (cdr x
)) ""))
4645 (efforts (org-split-string
4646 (or (cdr (assoc (concat org-effort-property
"_ALL")
4647 org-global-properties
))
4648 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
4649 (effort-op org-agenda-filter-effort-default-operator
)
4651 (inhibit-read-only t
)
4652 (current org-agenda-filter
)
4656 "%s by tag [%s ], [TAB], [/]:off, [+-]:narrow, [>=<?]:effort: "
4657 (if narrow
"Narrow" "Filter") tag-chars
)
4658 (setq char
(read-char)))
4659 (when (member char
'(?
+ ?-
))
4661 (cond ((equal char ?-
) (setq strip t narrow t
))
4662 ((equal char ?
+) (setq strip nil narrow t
)))
4664 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars
)
4665 (setq char
(read-char)))
4666 (when (member char
'(?
< ?
> ?
= ??
))
4667 ;; An effort operator
4668 (setq effort-op
(char-to-string char
))
4669 (setq alist nil
) ; to make sure it will be interpreted as effort.
4670 (unless (equal char ??
)
4671 (loop for i from
0 to
9 do
4675 (if (= i
9) "0" (int-to-string (1+ i
)))
4676 "]" (nth i efforts
))))
4677 (message "Effort%s: %s " effort-op effort-prompt
)
4678 (setq char
(read-char))
4679 (when (or (< char ?
0) (> char ?
9))
4680 (error "Need 1-9,0 to select effort" ))))
4681 (when (equal char ?
\t)
4682 (unless (local-variable-p 'org-global-tags-completion-table
(current-buffer))
4683 (org-set-local 'org-global-tags-completion-table
4684 (org-global-tags-completion-table)))
4685 (let ((completion-ignore-case t
))
4686 (setq tag
(org-ido-completing-read
4687 "Tag: " org-global-tags-completion-table
))))
4690 (org-agenda-filter-by-tag-show-all)
4691 (when (get 'org-agenda-filter
:preset-filter
)
4692 (org-agenda-filter-apply org-agenda-filter
)))
4693 ((or (equal char ?\
)
4694 (setq a
(rassoc char alist
))
4695 (and (>= char ?
0) (<= char ?
9)
4696 (setq n
(if (= char ?
0) 9 (- char ?
0 1))
4697 tag
(concat effort-op
(nth n efforts
))
4702 (and tag
(setq a
(cons tag nil
))))
4703 (org-agenda-filter-by-tag-show-all)
4705 (setq org-agenda-filter
4706 (cons (concat (if strip
"-" "+") tag
)
4707 (if narrow current nil
)))
4708 (org-agenda-filter-apply org-agenda-filter
))
4709 (t (error "Invalid tag selection character %c" char
)))))
4711 (defun org-agenda-filter-by-tag-refine (strip &optional char
)
4712 "Refine the current filter. See `org-agenda-filter-by-tag."
4714 (org-agenda-filter-by-tag strip char
'refine
))
4716 (defun org-agenda-filter-make-matcher ()
4717 "Create the form that tests a line for the agenda filter."
4719 (dolist (x (append (get 'org-agenda-filter
:preset-filter
)
4721 (if (member x
'("-" "+"))
4722 (setq f1
'(not tags
))
4723 (if (string-match "[<=>?]" x
)
4724 (setq f1
(org-agenda-filter-effort-form x
))
4725 (setq f1
(list 'member
(downcase (substring x
1)) 'tags
)))
4726 (if (equal (string-to-char x
) ?-
)
4727 (setq f1
(list 'not f1
))))
4729 (cons 'and
(nreverse f
))))
4731 (defun org-agenda-filter-effort-form (e)
4732 "Return the form to compare the effort of the current line with what E says.
4733 E looks line \"+<2:25\"."
4735 (setq e
(substring e
1))
4736 (setq op
(string-to-char e
) e
(substring e
1))
4737 (setq op
(cond ((equal op ?
<) '<=)
4741 (list 'org-agenda-compare-effort
(list 'quote op
)
4742 (org-hh:mm-string-to-minutes e
))))
4744 (defun org-agenda-compare-effort (op value
)
4745 "Compare the effort of the current line with VALUE, using OP.
4746 If the line does not have an effort defined, return nil."
4747 (let ((eff (get-text-property (point) 'effort-minutes
)))
4750 (funcall op
(or eff
(if org-sort-agenda-noeffort-is-high
32767 0))
4753 (defun org-agenda-filter-apply (filter)
4754 "Set FILTER as the new agenda filter and apply it."
4756 (setq org-agenda-filter filter
4757 org-agenda-filter-form
(org-agenda-filter-make-matcher))
4758 (org-agenda-set-mode-name)
4760 (goto-char (point-min))
4762 (if (get-text-property (point) 'org-marker
)
4764 (setq tags
(get-text-property (point) 'tags
)) ; used in eval
4765 (if (not (eval org-agenda-filter-form
))
4766 (org-agenda-filter-by-tag-hide-line))
4767 (beginning-of-line 2))
4768 (beginning-of-line 2))))))
4770 (defun org-agenda-filter-by-tag-hide-line ()
4772 (setq ov
(org-make-overlay (max (point-min) (1- (point-at-bol)))
4774 (org-overlay-put ov
'invisible t
)
4775 (org-overlay-put ov
'type
'tags-filter
)
4776 (push ov org-agenda-filter-overlays
)))
4778 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos
)
4779 (setq pos
(or pos
(point)))
4781 (dolist (ov (org-overlays-at pos
))
4782 (when (and (org-overlay-get ov
'invisible
)
4783 (eq (org-overlay-get ov
'type
) 'tags-filter
))
4785 (if (< (org-overlay-start ov
) (point-at-eol))
4786 (org-move-overlay ov
(point-at-eol)
4787 (org-overlay-end ov
)))))))
4789 (defun org-agenda-filter-by-tag-show-all ()
4790 (mapc 'org-delete-overlay org-agenda-filter-overlays
)
4791 (setq org-agenda-filter-overlays nil
)
4792 (setq org-agenda-filter nil
)
4793 (setq org-agenda-filter-form nil
)
4794 (org-agenda-set-mode-name))
4796 (defun org-agenda-manipulate-query-add ()
4797 "Manipulate the query by adding a search term with positive selection.
4798 Positive selection means, the term must be matched for selection of an entry."
4800 (org-agenda-manipulate-query ?\
[))
4801 (defun org-agenda-manipulate-query-subtract ()
4802 "Manipulate the query by adding a search term with negative selection.
4803 Negative selection means, term must not be matched for selection of an entry."
4805 (org-agenda-manipulate-query ?\
]))
4806 (defun org-agenda-manipulate-query-add-re ()
4807 "Manipulate the query by adding a search regexp with positive selection.
4808 Positive selection means, the regexp must match for selection of an entry."
4810 (org-agenda-manipulate-query ?\
{))
4811 (defun org-agenda-manipulate-query-subtract-re ()
4812 "Manipulate the query by adding a search regexp with negative selection.
4813 Negative selection means, regexp must not match for selection of an entry."
4815 (org-agenda-manipulate-query ?\
}))
4816 (defun org-agenda-manipulate-query (char)
4818 ((memq org-agenda-type
'(timeline agenda
))
4819 (if (y-or-n-p "Re-display with inactive time stamps included? ")
4820 (let ((org-agenda-include-inactive-timestamps t
))
4823 ((eq org-agenda-type
'search
)
4825 'org-agenda-query-string
4826 (cdr (assoc char
'((?\
[ .
" +") (?\
] .
" -")
4827 (?\
{ .
" +{}") (?\
} .
" -{}")))))
4828 (setq org-agenda-redo-command
4829 (list 'org-search-view
4831 org-agenda-query-string
4832 (+ (length org-agenda-query-string
)
4833 (if (member char
'(?\
{ ?\
})) 0 1))))
4834 (set-register org-agenda-query-register org-agenda-query-string
)
4836 (t (error "Cannot manipulate query for %s-type agenda buffers"
4839 (defun org-add-to-string (var string
)
4840 (set var
(concat (symbol-value var
) string
)))
4842 (defun org-agenda-goto-date (date)
4843 "Jump to DATE in agenda."
4844 (interactive (list (org-read-date)))
4845 (org-agenda-list nil date
))
4847 (defun org-agenda-goto-today ()
4850 (org-agenda-check-type t
'timeline
'agenda
)
4851 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t
)))
4853 (tdpos (goto-char tdpos
))
4854 ((eq org-agenda-type
'agenda
)
4855 (let* ((sd (time-to-days
4856 (time-subtract (current-time)
4857 (list 0 (* 3600 org-extend-today-until
) 0))))
4858 (comp (org-agenda-compute-time-span sd org-agenda-span
))
4859 (org-agenda-overriding-arguments org-agenda-last-arguments
))
4860 (setf (nth 1 org-agenda-overriding-arguments
) (car comp
))
4861 (setf (nth 2 org-agenda-overriding-arguments
) (cdr comp
))
4863 (org-agenda-find-same-or-today-or-agenda)))
4864 (t (error "Cannot find today")))))
4866 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt
)
4868 (or (and cnt
(text-property-any (point-min) (point-max) 'org-day-cnt cnt
))
4869 (text-property-any (point-min) (point-max) 'org-today t
)
4870 (text-property-any (point-min) (point-max) 'org-agenda-type
'agenda
)
4873 (defun org-agenda-later (arg)
4874 "Go forward in time by thee current span.
4875 With prefix ARG, go forward that many times the current span."
4877 (org-agenda-check-type t
'agenda
)
4878 (let* ((span org-agenda-span
)
4879 (sd org-starting-day
)
4880 (greg (calendar-gregorian-from-absolute sd
))
4881 (cnt (get-text-property (point) 'org-day-cnt
))
4885 (setq sd
(+ arg sd
) nd
1))
4887 (setq sd
(+ (* 7 arg
) sd
) nd
7))
4889 (setq greg2
(list (+ (car greg
) arg
) (nth 1 greg
) (nth 2 greg
))
4890 sd
(calendar-absolute-from-gregorian greg2
))
4891 (setcar greg2
(1+ (car greg2
)))
4892 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
)))
4894 (setq greg2
(list (car greg
) (nth 1 greg
) (+ arg
(nth 2 greg
)))
4895 sd
(calendar-absolute-from-gregorian greg2
))
4896 (setcar (nthcdr 2 greg2
) (1+ (nth 2 greg2
)))
4897 (setq nd
(- (calendar-absolute-from-gregorian greg2
) sd
))))
4898 (let ((org-agenda-overriding-arguments
4899 (list (car org-agenda-last-arguments
) sd nd t
)))
4901 (org-agenda-find-same-or-today-or-agenda cnt
))))
4903 (defun org-agenda-earlier (arg)
4904 "Go backward in time by the current span.
4905 With prefix ARG, go backward that many times the current span."
4907 (org-agenda-later (- arg
)))
4909 (defun org-agenda-day-view (&optional day-of-year
)
4910 "Switch to daily view for agenda.
4911 With argument DAY-OF-YEAR, switch to that day of the year."
4913 (setq org-agenda-ndays
1)
4914 (org-agenda-change-time-span 'day day-of-year
))
4915 (defun org-agenda-week-view (&optional iso-week
)
4916 "Switch to daily view for agenda.
4917 With argument ISO-WEEK, switch to the corresponding ISO week.
4918 If ISO-WEEK has more then 2 digits, only the last two encode the
4919 week. Any digits before this encode a year. So 200712 means
4920 week 12 of year 2007. Years in the range 1938-2037 can also be
4921 written as 2-digit years."
4923 (setq org-agenda-ndays
7)
4924 (org-agenda-change-time-span 'week iso-week
))
4925 (defun org-agenda-month-view (&optional month
)
4926 "Switch to monthly view for agenda.
4927 With argument MONTH, switch to that month."
4929 (org-agenda-change-time-span 'month month
))
4930 (defun org-agenda-year-view (&optional year
)
4931 "Switch to yearly view for agenda.
4932 With argument YEAR, switch to that year.
4933 If MONTH has more then 2 digits, only the last two encode the
4934 month. Any digits before this encode a year. So 200712 means
4935 December year 2007. Years in the range 1938-2037 can also be
4936 written as 2-digit years."
4939 (setq year
(org-small-year-to-year year
)))
4940 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
4941 (org-agenda-change-time-span 'year year
)
4944 (defun org-agenda-change-time-span (span &optional n
)
4945 "Change the agenda view to SPAN.
4946 SPAN may be `day', `week', `month', `year'."
4947 (org-agenda-check-type t
'agenda
)
4948 (if (and (not n
) (equal org-agenda-span span
))
4949 (error "Viewing span is already \"%s\"" span
))
4950 (let* ((sd (or (get-text-property (point) 'day
)
4952 (computed (org-agenda-compute-time-span sd span n
))
4953 (org-agenda-overriding-arguments
4954 (list (car org-agenda-last-arguments
)
4955 (car computed
) (cdr computed
) t
)))
4957 (org-agenda-find-same-or-today-or-agenda))
4958 (org-agenda-set-mode-name)
4959 (message "Switched to %s view" span
))
4961 (defun org-agenda-compute-time-span (sd span
&optional n
)
4962 "Compute starting date and number of days for agenda.
4963 SPAN may be `day', `week', `month', `year'. The return value
4964 is a cons cell with the starting date and the number of days,
4965 so that the date SD will be in that range."
4966 (let* ((greg (calendar-gregorian-from-absolute sd
))
4970 nd w1 y1 m1 thisweek
)
4974 (setq sd
(+ (calendar-absolute-from-gregorian
4979 (let* ((nt (calendar-day-of-week
4980 (calendar-gregorian-from-absolute sd
)))
4981 (d (if org-agenda-start-on-weekday
4982 (- nt org-agenda-start-on-weekday
)
4984 (setq sd
(- sd
(+ (if (< d
0) 7 0) d
)))
4987 (setq thisweek
(car (calendar-iso-from-absolute sd
)))
4989 (setq y1
(org-small-year-to-year (/ n
100))
4992 (calendar-absolute-from-iso
4994 (or y1
(nth 2 (calendar-iso-from-absolute sd
)))))))
4997 (when (and n
(> n
99))
4998 (setq y1
(org-small-year-to-year (/ n
100))
5000 (setq sd
(calendar-absolute-from-gregorian
5001 (list (or n mg
) 1 (or y1 yg
)))
5002 nd
(- (calendar-absolute-from-gregorian
5003 (list (1+ (or n mg
)) 1 (or y1 yg
)))
5006 (setq sd
(calendar-absolute-from-gregorian
5007 (list 1 1 (or n yg
)))
5008 nd
(- (calendar-absolute-from-gregorian
5009 (list 1 1 (1+ (or n yg
))))
5013 (defun org-agenda-next-date-line (&optional arg
)
5014 "Jump to the next line indicating a date in agenda buffer."
5016 (org-agenda-check-type t
'agenda
'timeline
)
5017 (beginning-of-line 1)
5018 ;; This does not work if user makes date format that starts with a blank
5019 (if (looking-at "^\\S-") (forward-char 1))
5020 (if (not (re-search-forward "^\\S-" nil t arg
))
5023 (error "No next date after this line in this buffer")))
5024 (goto-char (match-beginning 0)))
5026 (defun org-agenda-previous-date-line (&optional arg
)
5027 "Jump to the previous line indicating a date in agenda buffer."
5029 (org-agenda-check-type t
'agenda
'timeline
)
5030 (beginning-of-line 1)
5031 (if (not (re-search-backward "^\\S-" nil t arg
))
5032 (error "No previous date before this line in this buffer")))
5034 ;; Initialize the highlight
5035 (defvar org-hl
(org-make-overlay 1 1))
5036 (org-overlay-put org-hl
'face
'highlight
)
5038 (defun org-highlight (begin end
&optional buffer
)
5039 "Highlight a region with overlay."
5040 (funcall (if (featurep 'xemacs
) 'set-extent-endpoints
'move-overlay
)
5041 org-hl begin end
(or buffer
(current-buffer))))
5043 (defun org-unhighlight ()
5044 "Detach overlay INDEX."
5045 (funcall (if (featurep 'xemacs
) 'detach-extent
'delete-overlay
) org-hl
))
5047 ;; FIXME this is currently not used.
5048 (defun org-highlight-until-next-command (beg end
&optional buffer
)
5049 "Move the highlight overlay to BEG/END, remove it before the next command."
5050 (org-highlight beg end buffer
)
5051 (add-hook 'pre-command-hook
'org-unhighlight-once
))
5052 (defun org-unhighlight-once ()
5053 "Remove the highlight from its position, and this function from the hook."
5054 (remove-hook 'pre-command-hook
'org-unhighlight-once
)
5057 (defun org-agenda-follow-mode ()
5058 "Toggle follow mode in an agenda buffer."
5060 (setq org-agenda-follow-mode
(not org-agenda-follow-mode
))
5061 (org-agenda-set-mode-name)
5062 (message "Follow mode is %s"
5063 (if org-agenda-follow-mode
"on" "off")))
5065 (defun org-agenda-clockreport-mode ()
5066 "Toggle clocktable mode in an agenda buffer."
5068 (org-agenda-check-type t
'agenda
)
5069 (setq org-agenda-clockreport-mode
(not org-agenda-clockreport-mode
))
5070 (org-agenda-set-mode-name)
5072 (message "Clocktable mode is %s"
5073 (if org-agenda-clockreport-mode
"on" "off")))
5075 (defun org-agenda-log-mode (&optional special
)
5076 "Toggle log mode in an agenda buffer.
5077 With argument SPECIAL, show all possible log items, not only the ones
5078 configured in `org-agenda-log-mode-items'.
5079 With a double `C-u' prefix arg, show *only* log items, nothing else."
5081 (org-agenda-check-type t
'agenda
'timeline
)
5082 (setq org-agenda-show-log
5083 (if (equal special
'(16))
5085 (if special
'(closed clock state
)
5086 (not org-agenda-show-log
))))
5087 (org-agenda-set-mode-name)
5089 (message "Log mode is %s"
5090 (if org-agenda-show-log
"on" "off")))
5092 (defun org-agenda-archives-mode (&optional with-files
)
5093 "Toggle log mode in an agenda buffer."
5095 (setq org-agenda-archives-mode
5096 (if with-files t
(if org-agenda-archives-mode nil
'trees
)))
5097 (org-agenda-set-mode-name)
5102 ((eq org-agenda-archives-mode nil
)
5103 "No archives are included")
5104 ((eq org-agenda-archives-mode
'trees
)
5105 (format "Trees with :%s: tag are included" org-archive-tag
))
5106 ((eq org-agenda-archives-mode t
)
5107 (format "Trees with :%s: tag and all active archive files are included"
5108 org-archive-tag
)))))
5110 (defun org-agenda-toggle-diary ()
5111 "Toggle diary inclusion in an agenda buffer."
5113 (org-agenda-check-type t
'agenda
)
5114 (setq org-agenda-include-diary
(not org-agenda-include-diary
))
5116 (org-agenda-set-mode-name)
5117 (message "Diary inclusion turned %s"
5118 (if org-agenda-include-diary
"on" "off")))
5120 (defun org-agenda-toggle-time-grid ()
5121 "Toggle time grid in an agenda buffer."
5123 (org-agenda-check-type t
'agenda
)
5124 (setq org-agenda-use-time-grid
(not org-agenda-use-time-grid
))
5126 (org-agenda-set-mode-name)
5127 (message "Time-grid turned %s"
5128 (if org-agenda-use-time-grid
"on" "off")))
5130 (defun org-agenda-set-mode-name ()
5131 "Set the mode name to indicate all the small mode settings."
5133 (concat "Org-Agenda"
5134 (if (equal org-agenda-ndays
1) " Day" "")
5135 (if (equal org-agenda-ndays
7) " Week" "")
5136 (if org-agenda-follow-mode
" Follow" "")
5137 (if org-agenda-include-diary
" Diary" "")
5138 (if org-agenda-use-time-grid
" Grid" "")
5139 (if (consp org-agenda-show-log
) " LogAll"
5140 (if org-agenda-show-log
" Log" ""))
5141 (if (or org-agenda-filter
(get 'org-agenda-filter
5143 (concat " {" (mapconcat
5145 (append (get 'org-agenda-filter
5147 org-agenda-filter
) "") "}")
5149 (if org-agenda-archives-mode
5150 (if (eq org-agenda-archives-mode t
)
5152 (format " :%s:" org-archive-tag
))
5154 (if org-agenda-clockreport-mode
" Clock" "")))
5155 (force-mode-line-update))
5157 (defun org-agenda-post-command-hook ()
5158 (and (eolp) (not (bolp)) (backward-char 1))
5159 (setq org-agenda-type
5160 (or (get-text-property (point) 'org-agenda-type
)
5161 (get-text-property (max (point-min) (1- (point)))
5163 (if (and org-agenda-follow-mode
5164 (get-text-property (point) 'org-marker
))
5167 (defun org-agenda-show-priority ()
5168 "Show the priority of the current item.
5169 This priority is composed of the main priority given with the [#A] cookies,
5170 and by additional input from the age of a schedules or deadline entry."
5172 (let* ((pri (get-text-property (point-at-bol) 'priority
)))
5173 (message "Priority is %d" (if pri pri -
1000))))
5175 (defun org-agenda-show-tags ()
5176 "Show the tags applicable to the current item."
5178 (let* ((tags (get-text-property (point-at-bol) 'tags
)))
5180 (message "Tags are :%s:"
5181 (org-no-properties (mapconcat 'identity tags
":")))
5182 (message "No tags associated with this line"))))
5184 (defun org-agenda-goto (&optional highlight
)
5185 "Go to the Org-mode file which contains the item at point."
5187 (let* ((marker (or (get-text-property (point) 'org-marker
)
5188 (org-agenda-error)))
5189 (buffer (marker-buffer marker
))
5190 (pos (marker-position marker
)))
5191 (switch-to-buffer-other-window buffer
)
5195 (org-show-context 'agenda
)
5197 (and (outline-next-heading)
5198 (org-flag-heading nil
)))) ; show the next heading
5199 (recenter (/ (window-height) 2))
5200 (run-hooks 'org-agenda-after-show-hook
)
5201 (and highlight
(org-highlight (point-at-bol) (point-at-eol)))))
5203 (defvar org-agenda-after-show-hook nil
5204 "Normal hook run after an item has been shown from the agenda.
5205 Point is in the buffer where the item originated.")
5207 (defun org-agenda-kill ()
5208 "Kill the entry or subtree belonging to the current agenda entry."
5210 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5211 (let* ((marker (or (get-text-property (point) 'org-marker
)
5212 (org-agenda-error)))
5213 (buffer (marker-buffer marker
))
5214 (pos (marker-position marker
))
5215 (type (get-text-property (point) 'type
))
5216 dbeg dend
(n 0) conf
)
5217 (org-with-remote-undo buffer
5218 (with-current-buffer buffer
5221 (if (and (org-mode-p) (not (member type
'("sexp"))))
5222 (setq dbeg
(progn (org-back-to-heading t
) (point))
5223 dend
(org-end-of-subtree t t
))
5224 (setq dbeg
(point-at-bol)
5225 dend
(min (point-max) (1+ (point-at-eol)))))
5227 (while (re-search-forward "^[ \t]*\\S-" dend t
) (setq n
(1+ n
)))))
5228 (setq conf
(or (eq t org-agenda-confirm-kill
)
5229 (and (numberp org-agenda-confirm-kill
)
5230 (> n org-agenda-confirm-kill
))))
5233 (format "Delete entry with %d lines in buffer \"%s\"? "
5234 n
(buffer-name buffer
))))
5236 (org-remove-subtree-entries-from-agenda buffer dbeg dend
)
5237 (with-current-buffer buffer
(delete-region dbeg dend
))
5238 (message "Agenda item and source killed"))))
5240 (defun org-agenda-archive ()
5241 "Archive the entry or subtree belonging to the current agenda entry."
5243 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5244 (let* ((marker (or (get-text-property (point) 'org-marker
)
5245 (org-agenda-error)))
5246 (buffer (marker-buffer marker
))
5247 (pos (marker-position marker
)))
5248 (org-with-remote-undo buffer
5249 (with-current-buffer buffer
5253 (org-remove-subtree-entries-from-agenda)
5254 (org-back-to-heading t
)
5255 (org-archive-subtree))
5256 (error "Archiving works only in Org-mode files"))))))
5258 (defun org-agenda-archive-to-archive-sibling ()
5259 "Move the entry to the archive sibling."
5261 (or (eq major-mode
'org-agenda-mode
) (error "Not in agenda"))
5262 (let* ((marker (or (get-text-property (point) 'org-marker
)
5263 (org-agenda-error)))
5264 (buffer (marker-buffer marker
))
5265 (pos (marker-position marker
)))
5266 (org-with-remote-undo buffer
5267 (with-current-buffer buffer
5271 (org-remove-subtree-entries-from-agenda)
5272 (org-back-to-heading t
)
5273 (org-archive-to-archive-sibling))
5274 (error "Archiving works only in Org-mode files"))))))
5276 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end
)
5277 "Remove all lines in the agenda that correspond to a given subtree.
5278 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5279 If this information is not given, the function uses the tree at point."
5280 (let ((buf (or buf
(current-buffer))) m p
)
5282 (unless (and beg end
)
5283 (org-back-to-heading t
)
5285 (org-end-of-subtree t
)
5287 (set-buffer (get-buffer org-agenda-buffer-name
))
5289 (goto-char (point-max))
5290 (beginning-of-line 1)
5292 (when (and (setq m
(get-text-property (point) 'org-marker
))
5293 (equal buf
(marker-buffer m
))
5294 (setq p
(marker-position m
))
5297 (let ((inhibit-read-only t
))
5298 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5299 (beginning-of-line 0))))))
5301 (defun org-agenda-open-link ()
5302 "Follow the link in the current line, if any."
5304 (org-agenda-copy-local-variable 'org-link-abbrev-alist-local
)
5307 (narrow-to-region (point-at-bol) (point-at-eol))
5308 (org-open-at-point))))
5310 (defun org-agenda-copy-local-variable (var)
5311 "Get a variable from a referenced buffer and install it here."
5312 (let ((m (get-text-property (point) 'org-marker
)))
5313 (when (and m
(buffer-live-p (marker-buffer m
)))
5314 (org-set-local var
(with-current-buffer (marker-buffer m
)
5315 (symbol-value var
))))))
5317 (defun org-agenda-switch-to (&optional delete-other-windows
)
5318 "Go to the Org-mode file which contains the item at point."
5320 (let* ((marker (or (get-text-property (point) 'org-marker
)
5321 (org-agenda-error)))
5322 (buffer (marker-buffer marker
))
5323 (pos (marker-position marker
)))
5324 (switch-to-buffer buffer
)
5325 (and delete-other-windows
(delete-other-windows))
5329 (org-show-context 'agenda
)
5331 (and (outline-next-heading)
5332 (org-flag-heading nil
)))))) ; show the next heading
5334 (defun org-agenda-goto-mouse (ev)
5335 "Go to the Org-mode file which contains the item at the mouse click."
5337 (mouse-set-point ev
)
5340 (defun org-agenda-show (&optional full-entry
)
5341 "Display the Org-mode file which contains the item at point.
5342 With prefix argument FULL-ENTRY, make the entire entry visible
5343 if it was hidden in the outline."
5345 (let ((win (selected-window)))
5347 (let ((org-show-entry-below t
))
5348 (org-agenda-goto t
))
5349 (org-agenda-goto t
))
5350 (select-window win
)))
5352 (defun org-agenda-show-1 (&optional more
)
5353 "Display the Org-mode file which contains the item at point.
5354 The prefix arg causes further revieling:
5357 1 just show the entry according to defaults.
5358 2 show the text below the heading
5359 3 show the entire subtree
5360 4 show the entire subtree and any LOGBOOK drawers
5361 5 show the entire subtree and any drawers
5362 With prefix argument FULL-ENTRY, make the entire entry visible
5363 if it was hidden in the outline."
5365 (let ((win (selected-window)))
5367 (org-recenter-heading 1)
5371 (message "Remote: hide subtree"))
5372 ((and (interactive-p) (= more
1))
5373 (message "Remote: show with default settings"))
5377 (org-back-to-heading)
5378 (org-cycle-hide-drawers 'children
))
5379 (message "Remote: show entry"))
5383 (org-back-to-heading)
5384 (org-cycle-hide-drawers 'subtree
))
5385 (message "Remote: show subtree"))
5387 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers
)))
5389 (concat "^[ \t]*:\\("
5390 (mapconcat 'regexp-quote org-drawers
"\\|")
5394 (org-back-to-heading)
5395 (org-cycle-hide-drawers 'subtree
)))
5396 (message "Remote: show subtree and LOGBOOK"))
5399 (message "Remote: show subtree and LOGBOOK")))
5400 (select-window win
)))
5402 (defun org-recenter-heading (n)
5404 (org-back-to-heading)
5407 (defvar org-agenda-cycle-counter nil
)
5408 (defun org-agenda-cycle-show (n)
5409 "Show the current entry in another window, with default settings.
5410 Default settings are taken from `org-show-hierarchy-above' and siblings.
5411 When use repeadedly in immediate succession, the remote entry will cycle
5414 entry -> subtree -> subtree with logbook"
5417 (not (eq last-command this-command
)))
5418 (setq org-agenda-cycle-counter
0))
5419 (setq org-agenda-cycle-counter
(1+ org-agenda-cycle-counter
))
5420 (if (> org-agenda-cycle-counter
4)
5421 (setq org-agenda-cycle-counter
0))
5422 (org-agenda-show-1 org-agenda-cycle-counter
))
5424 (defun org-agenda-recenter (arg)
5425 "Display the Org-mode file which contains the item at point and recenter."
5427 (let ((win (selected-window)))
5430 (select-window win
)))
5432 (defun org-agenda-show-mouse (ev)
5433 "Display the Org-mode file which contains the item at the mouse click."
5435 (mouse-set-point ev
)
5438 (defun org-agenda-check-no-diary ()
5439 "Check if the entry is a diary link and abort if yes."
5440 (if (get-text-property (point) 'org-agenda-diary-link
)
5441 (org-agenda-error)))
5443 (defun org-agenda-error ()
5444 (error "Command not allowed in this line"))
5446 (defun org-agenda-tree-to-indirect-buffer ()
5447 "Show the subtree corresponding to the current entry in an indirect buffer.
5448 This calls the command `org-tree-to-indirect-buffer' from the original
5450 With numerical prefix arg ARG, go up to this level and then take that tree.
5451 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
5454 (org-agenda-check-no-diary)
5455 (let* ((marker (or (get-text-property (point) 'org-marker
)
5456 (org-agenda-error)))
5457 (buffer (marker-buffer marker
))
5458 (pos (marker-position marker
)))
5459 (with-current-buffer buffer
5462 (call-interactively 'org-tree-to-indirect-buffer
)))))
5464 (defvar org-last-heading-marker
(make-marker)
5465 "Marker pointing to the headline that last changed its TODO state
5466 by a remote command from the agenda.")
5468 (defun org-agenda-todo-nextset ()
5469 "Switch TODO entry to next sequence."
5471 (org-agenda-todo 'nextset
))
5473 (defun org-agenda-todo-previousset ()
5474 "Switch TODO entry to previous sequence."
5476 (org-agenda-todo 'previousset
))
5478 (defun org-agenda-todo (&optional arg
)
5479 "Cycle TODO state of line at point, also in Org-mode file.
5480 This changes the line at point, all other lines in the agenda referring to
5481 the same tree node, and the headline of the tree node in the Org-mode file."
5483 (org-agenda-check-no-diary)
5484 (let* ((col (current-column))
5485 (marker (or (get-text-property (point) 'org-marker
)
5486 (org-agenda-error)))
5487 (buffer (marker-buffer marker
))
5488 (pos (marker-position marker
))
5489 (hdmarker (get-text-property (point) 'org-hd-marker
))
5490 (todayp (equal (get-text-property (point) 'day
)
5491 (time-to-days (current-time))))
5492 (inhibit-read-only t
)
5493 org-agenda-headline-snapshot-before-repeat newhead just-one
)
5494 (org-with-remote-undo buffer
5495 (with-current-buffer buffer
5498 (org-show-context 'agenda
)
5500 (and (outline-next-heading)
5501 (org-flag-heading nil
))) ; show the next heading
5502 (let ((current-prefix-arg arg
))
5503 (call-interactively 'org-todo
))
5504 (and (bolp) (forward-char 1))
5505 (setq newhead
(org-get-heading))
5506 (when (and (org-bound-and-true-p
5507 org-agenda-headline-snapshot-before-repeat
)
5508 (not (equal org-agenda-headline-snapshot-before-repeat
5511 (setq newhead org-agenda-headline-snapshot-before-repeat
5514 (org-back-to-heading)
5515 (move-marker org-last-heading-marker
(point))))
5516 (beginning-of-line 1)
5518 (org-agenda-change-all-lines newhead hdmarker
'fixface just-one
))
5519 (org-move-to-column col
))))
5521 (defun org-agenda-add-note (&optional arg
)
5522 "Add a time-stamped note to the entry at point."
5524 (org-agenda-check-no-diary)
5525 (let* ((marker (or (get-text-property (point) 'org-marker
)
5526 (org-agenda-error)))
5527 (buffer (marker-buffer marker
))
5528 (pos (marker-position marker
))
5529 (hdmarker (get-text-property (point) 'org-hd-marker
))
5530 (inhibit-read-only t
))
5531 (with-current-buffer buffer
5534 (org-show-context 'agenda
)
5536 (and (outline-next-heading)
5537 (org-flag-heading nil
))) ; show the next heading
5540 (defun org-agenda-change-all-lines (newhead hdmarker
5541 &optional fixface just-this
)
5542 "Change all lines in the agenda buffer which match HDMARKER.
5543 The new content of the line will be NEWHEAD (as modified by
5544 `org-format-agenda-item'). HDMARKER is checked with
5545 `equal' against all `org-hd-marker' text properties in the file.
5546 If FIXFACE is non-nil, the face of each item is modified according to
5548 If JUST-THIS is non-nil, change just the current line, not all.
5549 If FORCE-TAGS is non nil, the car of it returns the new tags."
5550 (let* ((inhibit-read-only t
)
5551 (line (org-current-line))
5552 (thetags (with-current-buffer (marker-buffer hdmarker
)
5553 (save-excursion (save-restriction (widen)
5554 (goto-char hdmarker
)
5555 (org-get-tags-at)))))
5556 props m pl undone-face done-face finish new dotime cat tags
)
5558 (goto-char (point-max))
5559 (beginning-of-line 1)
5561 (setq finish
(bobp))
5562 (when (and (setq m
(get-text-property (point) 'org-hd-marker
))
5563 (or (not just-this
) (= (org-current-line) line
))
5565 (setq props
(text-properties-at (point))
5566 dotime
(get-text-property (point) 'dotime
)
5567 cat
(get-text-property (point) 'org-category
)
5569 new
(org-format-agenda-item "x" newhead cat tags dotime
'noprefix
)
5570 pl
(get-text-property (point) 'prefix-length
)
5571 undone-face
(get-text-property (point) 'undone-face
)
5572 done-face
(get-text-property (point) 'done-face
))
5573 (org-move-to-column pl
)
5576 (beginning-of-line 1)
5577 (and (looking-at ".*\n?") (replace-match "")))
5579 (replace-match new t t
)
5580 (beginning-of-line 1)
5581 (add-text-properties (point-at-bol) (point-at-eol) props
)
5583 (add-text-properties
5584 (point-at-bol) (point-at-eol)
5586 (if org-last-todo-state-is-todo
5587 undone-face done-face
))))
5588 (org-agenda-highlight-todo 'line
)
5589 (beginning-of-line 1))
5590 (t (error "Line update did not work"))))
5591 (beginning-of-line 0)))
5592 (org-finalize-agenda)))
5594 (defun org-agenda-align-tags (&optional line
)
5595 "Align all tags in agenda items to `org-agenda-tags-column'."
5596 (let ((inhibit-read-only t
) l c
)
5598 (goto-char (if line
(point-at-bol) (point-min)))
5599 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
5600 (if line
(point-at-eol) nil
) t
)
5601 (add-text-properties
5602 (match-beginning 2) (match-end 2)
5603 (list 'face
(delq nil
(let ((prop (get-text-property
5604 (match-beginning 2) 'face
)))
5605 (or (listp prop
) (setq prop
(list prop
)))
5606 (if (memq 'org-tag prop
)
5608 (cons 'org-tag prop
))))))
5609 (setq l
(- (match-end 2) (match-beginning 2))
5610 c
(if (< org-agenda-tags-column
0)
5611 (- (abs org-agenda-tags-column
) l
)
5612 org-agenda-tags-column
))
5613 (delete-region (match-beginning 1) (match-end 1))
5614 (goto-char (match-beginning 1))
5615 (insert (org-add-props
5616 (make-string (max 1 (- c
(current-column))) ?\
)
5617 (text-properties-at (point)))))
5618 (goto-char (point-min))
5619 (org-font-lock-add-tag-faces (point-max)))))
5621 (defun org-agenda-priority-up ()
5622 "Increase the priority of line at point, also in Org-mode file."
5624 (org-agenda-priority 'up
))
5626 (defun org-agenda-priority-down ()
5627 "Decrease the priority of line at point, also in Org-mode file."
5629 (org-agenda-priority 'down
))
5631 (defun org-agenda-priority (&optional force-direction
)
5632 "Set the priority of line at point, also in Org-mode file.
5633 This changes the line at point, all other lines in the agenda referring to
5634 the same tree node, and the headline of the tree node in the Org-mode file."
5636 (org-agenda-check-no-diary)
5637 (let* ((marker (or (get-text-property (point) 'org-marker
)
5638 (org-agenda-error)))
5639 (hdmarker (get-text-property (point) 'org-hd-marker
))
5640 (buffer (marker-buffer hdmarker
))
5641 (pos (marker-position hdmarker
))
5642 (inhibit-read-only t
)
5644 (org-with-remote-undo buffer
5645 (with-current-buffer buffer
5648 (org-show-context 'agenda
)
5650 (and (outline-next-heading)
5651 (org-flag-heading nil
))) ; show the next heading
5652 (funcall 'org-priority force-direction
)
5654 (setq newhead
(org-get-heading)))
5655 (org-agenda-change-all-lines newhead hdmarker
)
5656 (beginning-of-line 1))))
5658 ;; FIXME: should fix the tags property of the agenda line.
5659 (defun org-agenda-set-tags ()
5660 "Set tags for the current headline."
5662 (org-agenda-check-no-diary)
5663 (if (and (org-region-active-p) (interactive-p))
5664 (call-interactively 'org-change-tag-in-region
)
5665 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5666 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5667 (org-agenda-error)))
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
5677 (org-show-context 'agenda
))
5679 (and (outline-next-heading)
5680 (org-flag-heading nil
))) ; show the next heading
5682 (call-interactively 'org-set-tags
)
5684 (setq newhead
(org-get-heading)))
5685 (org-agenda-change-all-lines newhead hdmarker
)
5686 (beginning-of-line 1)))))
5688 (defun org-agenda-toggle-archive-tag ()
5689 "Toggle the archive tag for the current entry."
5691 (org-agenda-check-no-diary)
5692 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
5693 (let* ((hdmarker (or (get-text-property (point) 'org-hd-marker
)
5694 (org-agenda-error)))
5695 (buffer (marker-buffer hdmarker
))
5696 (pos (marker-position hdmarker
))
5697 (inhibit-read-only t
)
5699 (org-with-remote-undo buffer
5700 (with-current-buffer buffer
5703 (org-show-context 'agenda
)
5705 (and (outline-next-heading)
5706 (org-flag-heading nil
))) ; show the next heading
5707 (call-interactively 'org-toggle-archive-tag
)
5709 (setq newhead
(org-get-heading)))
5710 (org-agenda-change-all-lines newhead hdmarker
)
5711 (beginning-of-line 1))))
5713 (defun org-agenda-do-date-later (arg)
5716 ((or (equal arg
'(16))
5718 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5719 (setq this-command
'org-agenda-date-later-minutes
)
5720 (org-agenda-date-later-minutes 1))
5721 ((or (equal arg
'(4))
5723 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5724 (setq this-command
'org-agenda-date-later-hours
)
5725 (org-agenda-date-later-hours 1))
5727 (org-agenda-date-later (prefix-numeric-value arg
)))))
5729 (defun org-agenda-do-date-earlier (arg)
5732 ((or (equal arg
'(16))
5734 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes
)))
5735 (setq this-command
'org-agenda-date-earlier-minutes
)
5736 (org-agenda-date-earlier-minutes 1))
5737 ((or (equal arg
'(4))
5739 '(org-agenda-date-later-hours org-agenda-date-earlier-hours
)))
5740 (setq this-command
'org-agenda-date-earlier-hours
)
5741 (org-agenda-date-earlier-hours 1))
5743 (org-agenda-date-earlier (prefix-numeric-value arg
)))))
5745 (defun org-agenda-date-later (arg &optional what
)
5746 "Change the date of this item to one day later."
5748 (org-agenda-check-type t
'agenda
'timeline
)
5749 (org-agenda-check-no-diary)
5750 (let* ((marker (or (get-text-property (point) 'org-marker
)
5751 (org-agenda-error)))
5752 (buffer (marker-buffer marker
))
5753 (pos (marker-position marker
)))
5754 (org-with-remote-undo buffer
5755 (with-current-buffer buffer
5758 (if (not (org-at-timestamp-p))
5759 (error "Cannot find time stamp"))
5760 (org-timestamp-change arg
(or what
'day
)))
5761 (org-agenda-show-new-time marker org-last-changed-timestamp
))
5762 (message "Time stamp changed to %s" org-last-changed-timestamp
)))
5764 (defun org-agenda-date-earlier (arg &optional what
)
5765 "Change the date of this item to one day earlier."
5767 (org-agenda-date-later (- arg
) what
))
5769 (defun org-agenda-date-later-minutes (arg)
5770 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5772 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5773 (org-agenda-date-later arg
'minute
))
5775 (defun org-agenda-date-earlier-minutes (arg)
5776 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
5778 (setq arg
(* arg
(cadr org-time-stamp-rounding-minutes
)))
5779 (org-agenda-date-earlier arg
'minute
))
5781 (defun org-agenda-date-later-hours (arg)
5782 "Change the time of this item, in hour steps."
5784 (org-agenda-date-later arg
'hour
))
5786 (defun org-agenda-date-earlier-hours (arg)
5787 "Change the time of this item, in hour steps."
5789 (org-agenda-date-earlier arg
'hour
))
5791 (defun org-agenda-show-new-time (marker stamp
&optional prefix
)
5792 "Show new date stamp via text properties."
5793 ;; We use text properties to make this undoable
5794 (let ((inhibit-read-only t
)
5795 (buffer-invisibility-spec))
5796 (setq stamp
(concat " " prefix
" => " stamp
))
5798 (goto-char (point-max))
5800 (when (equal marker
(get-text-property (point) 'org-marker
))
5801 (org-move-to-column (- (window-width) (length stamp
)) t
)
5802 (org-agenda-fix-tags-filter-overlays-at (point))
5803 (if (featurep 'xemacs
)
5804 ;; Use `duplicable' property to trigger undo recording
5805 (let ((ex (make-extent nil nil
))
5806 (gl (make-glyph stamp
)))
5807 (set-glyph-face gl
'secondary-selection
)
5808 (set-extent-properties
5809 ex
(list 'invisible t
'end-glyph gl
'duplicable t
))
5810 (insert-extent ex
(1- (point)) (point-at-eol)))
5811 (add-text-properties
5812 (1- (point)) (point-at-eol)
5813 (list 'display
(org-add-props stamp nil
5814 'face
'secondary-selection
))))
5815 (beginning-of-line 1))
5816 (beginning-of-line 0)))))
5818 (defun org-agenda-date-prompt (arg)
5819 "Change the date of this item. Date is prompted for, with default today.
5820 The prefix ARG is passed to the `org-time-stamp' command and can therefore
5821 be used to request time specification in the time stamp."
5823 (org-agenda-check-type t
'agenda
'timeline
)
5824 (org-agenda-check-no-diary)
5825 (let* ((marker (or (get-text-property (point) 'org-marker
)
5826 (org-agenda-error)))
5827 (buffer (marker-buffer marker
))
5828 (pos (marker-position marker
)))
5829 (org-with-remote-undo buffer
5830 (with-current-buffer buffer
5833 (if (not (org-at-timestamp-p))
5834 (error "Cannot find time stamp"))
5835 (org-time-stamp arg
)
5836 (message "Time stamp changed to %s" org-last-changed-timestamp
)))))
5838 (defun org-agenda-schedule (arg)
5839 "Schedule the item at point."
5841 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
5842 (org-agenda-check-no-diary)
5843 (let* ((marker (or (get-text-property (point) 'org-marker
)
5844 (org-agenda-error)))
5845 (type (marker-insertion-type marker
))
5846 (buffer (marker-buffer marker
))
5847 (pos (marker-position marker
))
5848 (org-insert-labeled-timestamps-at-point nil
)
5850 (set-marker-insertion-type marker t
)
5851 (org-with-remote-undo buffer
5852 (with-current-buffer buffer
5855 (setq ts
(org-schedule arg
)))
5856 (org-agenda-show-new-time marker ts
"S"))
5857 (message "Item scheduled for %s" ts
)))
5859 (defun org-agenda-deadline (arg)
5860 "Schedule the item at point."
5862 (org-agenda-check-type t
'agenda
'timeline
'todo
'tags
'search
)
5863 (org-agenda-check-no-diary)
5864 (let* ((marker (or (get-text-property (point) 'org-marker
)
5865 (org-agenda-error)))
5866 (buffer (marker-buffer marker
))
5867 (pos (marker-position marker
))
5868 (org-insert-labeled-timestamps-at-point nil
)
5870 (org-with-remote-undo buffer
5871 (with-current-buffer buffer
5874 (setq ts
(org-deadline arg
)))
5875 (org-agenda-show-new-time marker ts
"S"))
5876 (message "Deadline for this item set to %s" ts
)))
5878 (defun org-agenda-action ()
5879 "Select entry for agenda action, or execute an agenda action.
5880 This command prompts for another letter. Valid inputs are:
5882 m Mark the entry at point for an agenda action
5883 s Schedule the marked entry to the date at the cursor
5884 d Set the deadline of the marked entry to the date at the cursor
5885 r Call `org-remember' with cursor date as the default date
5886 SPC Show marked entry in other window
5887 TAB Visit marked entry in other window
5889 The cursor may be at a date in the calendar, or in the Org agenda."
5892 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
5893 (setq ans
(read-char-exclusive))
5897 (if (eq major-mode
'org-agenda-mode
)
5898 (let ((m (or (get-text-property (point) 'org-hd-marker
)
5899 (get-text-property (point) 'org-marker
))))
5902 (move-marker org-agenda-action-marker
5903 (marker-position m
) (marker-buffer m
))
5904 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
5905 (error "Don't know which entry to mark")))
5906 (error "This command works only in the agenda")))
5908 (org-agenda-do-action '(org-schedule nil org-overriding-default-time
)))
5910 (org-agenda-do-action '(org-deadline nil org-overriding-default-time
)))
5912 (org-agenda-do-action '(org-remember) t
))
5914 (let ((cw (selected-window)))
5915 (org-switch-to-buffer-other-window
5916 (marker-buffer org-agenda-action-marker
))
5917 (goto-char org-agenda-action-marker
)
5918 (org-show-context 'agenda
)
5919 (select-window cw
)))
5921 (org-switch-to-buffer-other-window
5922 (marker-buffer org-agenda-action-marker
))
5923 (goto-char org-agenda-action-marker
)
5924 (org-show-context 'agenda
))
5925 (t (error "Invalid agenda action %c" ans
)))))
5927 (defun org-agenda-do-action (form &optional current-buffer
)
5928 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
5929 (let ((org-overriding-default-time (org-get-cursor-date)))
5932 (if (not (marker-buffer org-agenda-action-marker
))
5933 (error "No entry has bee selected for agenda action")
5934 (with-current-buffer (marker-buffer org-agenda-action-marker
)
5938 (goto-char org-agenda-action-marker
)
5941 (defun org-agenda-clock-in (&optional arg
)
5942 "Start the clock on the currently selected item."
5944 (org-agenda-check-no-diary)
5945 (if (equal arg
'(4))
5947 (let* ((marker (or (get-text-property (point) 'org-marker
)
5948 (org-agenda-error)))
5949 (hdmarker (or (get-text-property (point) 'org-hd-marker
)
5951 (pos (marker-position marker
))
5953 (org-with-remote-undo (marker-buffer marker
)
5954 (with-current-buffer (marker-buffer marker
)
5957 (org-show-context 'agenda
)
5959 (org-cycle-hide-drawers 'children
)
5961 (setq newhead
(org-get-heading)))
5962 (org-agenda-change-all-lines newhead hdmarker t
)))))
5964 (defun org-agenda-clock-out (&optional arg
)
5965 "Stop the currently running clock."
5967 (unless (marker-buffer org-clock-marker
)
5968 (error "No running clock"))
5969 (org-with-remote-undo (marker-buffer org-clock-marker
)
5972 (defun org-agenda-clock-cancel (&optional arg
)
5973 "Cancel the currently running clock."
5975 (unless (marker-buffer org-clock-marker
)
5976 (error "No running clock"))
5977 (org-with-remote-undo (marker-buffer org-clock-marker
)
5978 (org-clock-cancel)))
5980 (defun org-agenda-diary-entry ()
5981 "Make a diary entry, like the `i' command from the calendar.
5982 All the standard commands work: block, weekly etc."
5984 (org-agenda-check-type t
'agenda
'timeline
)
5985 (require 'diary-lib
)
5987 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
5988 (read-char-exclusive)))
5989 (cmd (cdr (assoc char
5990 '((?d . insert-diary-entry
)
5991 (?w . insert-weekly-diary-entry
)
5992 (?m . insert-monthly-diary-entry
)
5993 (?y . insert-yearly-diary-entry
)
5994 (?a . insert-anniversary-diary-entry
)
5995 (?b . insert-block-diary-entry
)
5996 (?c . insert-cyclic-diary-entry
)))))
5997 (oldf (symbol-function 'calendar-cursor-to-date
))
5998 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6000 (mark (or (mark t
) (point))))
6002 (error "No command associated with <%c>" char
))
6003 (unless (and (get-text-property point
'day
)
6004 (or (not (equal ?b char
))
6005 (get-text-property mark
'day
)))
6006 (error "Don't know which date to use for diary entry"))
6007 ;; We implement this by hacking the `calendar-cursor-to-date' function
6008 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6009 (let ((calendar-mark-ring
6010 (list (calendar-gregorian-from-absolute
6011 (or (get-text-property mark
'day
)
6012 (get-text-property point
'day
))))))
6015 (fset 'calendar-cursor-to-date
6016 (lambda (&optional error dummy
)
6017 (calendar-gregorian-from-absolute
6018 (get-text-property point
'day
))))
6019 (call-interactively cmd
))
6020 (fset 'calendar-cursor-to-date oldf
)))))
6022 (defun org-agenda-execute-calendar-command (cmd)
6023 "Execute a calendar command from the agenda, with the date associated to
6024 the cursor position."
6025 (org-agenda-check-type t
'agenda
'timeline
)
6026 (require 'diary-lib
)
6027 (unless (get-text-property (point) 'day
)
6028 (error "Don't know which date to use for calendar command"))
6029 (let* ((oldf (symbol-function 'calendar-cursor-to-date
))
6031 (date (calendar-gregorian-from-absolute
6032 (get-text-property point
'day
)))
6033 ;; the following 2 vars are needed in the calendar
6034 (displayed-month (car date
))
6035 (displayed-year (nth 2 date
)))
6038 (fset 'calendar-cursor-to-date
6039 (lambda (&optional error dummy
)
6040 (calendar-gregorian-from-absolute
6041 (get-text-property point
'day
))))
6042 (call-interactively cmd
))
6043 (fset 'calendar-cursor-to-date oldf
))))
6045 (defun org-agenda-phases-of-moon ()
6046 "Display the phases of the moon for the 3 months around the cursor date."
6048 (org-agenda-execute-calendar-command 'calendar-phases-of-moon
))
6050 (defun org-agenda-holidays ()
6051 "Display the holidays for the 3 months around the cursor date."
6053 (org-agenda-execute-calendar-command 'list-calendar-holidays
))
6055 (defvar calendar-longitude
)
6056 (defvar calendar-latitude
)
6057 (defvar calendar-location-name
)
6059 (defun org-agenda-sunrise-sunset (arg)
6060 "Display sunrise and sunset for the cursor date.
6061 Latitude and longitude can be specified with the variables
6062 `calendar-latitude' and `calendar-longitude'. When called with prefix
6063 argument, latitude and longitude will be prompted for."
6066 (let ((calendar-longitude (if arg nil calendar-longitude
))
6067 (calendar-latitude (if arg nil calendar-latitude
))
6068 (calendar-location-name
6069 (if arg
"the given coordinates" calendar-location-name
)))
6070 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset
)))
6072 (defun org-agenda-goto-calendar ()
6073 "Open the Emacs calendar with the date at the cursor."
6075 (org-agenda-check-type t
'agenda
'timeline
)
6076 (let* ((day (or (get-text-property (point) 'day
)
6077 (error "Don't know which date to open in calendar")))
6078 (date (calendar-gregorian-from-absolute day
))
6079 (calendar-move-hook nil
)
6080 (calendar-view-holidays-initially-flag nil
)
6081 (calendar-view-diary-initially-flag nil
)
6082 (view-calendar-holidays-initially nil
)
6083 (view-diary-entries-initially nil
))
6085 (calendar-goto-date date
)))
6088 (defun org-calendar-goto-agenda ()
6089 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6090 This is a command that has to be installed in `calendar-mode-map'."
6092 (org-agenda-list nil
(calendar-absolute-from-gregorian
6093 (calendar-cursor-to-date))
6096 (defun org-agenda-convert-date ()
6098 (org-agenda-check-type t
'agenda
'timeline
)
6099 (let ((day (get-text-property (point) 'day
))
6102 (error "Don't know which date to convert"))
6103 (setq date
(calendar-gregorian-from-absolute day
))
6105 "Gregorian: " (calendar-date-string date
) "\n"
6106 "ISO: " (calendar-iso-date-string date
) "\n"
6107 "Day of Yr: " (calendar-day-of-year-string date
) "\n"
6108 "Julian: " (calendar-julian-date-string date
) "\n"
6109 "Astron. JD: " (calendar-astro-date-string date
)
6110 " (Julian date number at noon UTC)\n"
6111 "Hebrew: " (calendar-hebrew-date-string date
) " (until sunset)\n"
6112 "Islamic: " (calendar-islamic-date-string date
) " (until sunset)\n"
6113 "French: " (calendar-french-date-string date
) "\n"
6114 "Baha'i: " (calendar-bahai-date-string date
) " (until sunset)\n"
6115 "Mayan: " (calendar-mayan-date-string date
) "\n"
6116 "Coptic: " (calendar-coptic-date-string date
) "\n"
6117 "Ethiopic: " (calendar-ethiopic-date-string date
) "\n"
6118 "Persian: " (calendar-persian-date-string date
) "\n"
6119 "Chinese: " (calendar-chinese-date-string date
) "\n"))
6120 (with-output-to-temp-buffer "*Dates*"
6122 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6124 ;;; Appointment reminders
6126 (defvar appt-time-msg-list
)
6129 (defun org-agenda-to-appt (&optional refresh filter
)
6130 "Activate appointments found in `org-agenda-files'.
6131 With a \\[universal-argument] prefix, refresh the list of
6134 If FILTER is t, interactively prompt the user for a regular
6135 expression, and filter out entries that don't match it.
6137 If FILTER is a string, use this string as a regular expression
6138 for filtering entries out.
6140 FILTER can also be an alist with the car of each cell being
6141 either 'headline or 'category. For example:
6143 '((headline \"IMPORTANT\")
6144 (category \"Work\"))
6146 will only add headlines containing IMPORTANT or headlines
6147 belonging to the \"Work\" category."
6150 (if refresh
(setq appt-time-msg-list nil
))
6152 (setq filter
(read-from-minibuffer "Regexp filter: ")))
6153 (let* ((cnt 0) ; count added events
6154 (org-agenda-new-buffers nil
)
6155 (org-deadline-warning-days 0)
6156 (today (org-date-to-gregorian
6157 (time-to-days (current-time))))
6158 (files (org-agenda-files 'unrestricted
)) entries file
)
6159 ;; Get all entries which may contain an appt
6160 (org-prepare-agenda-buffers files
)
6161 (while (setq file
(pop files
))
6164 (org-agenda-get-day-entries
6165 file today
:timestamp
:scheduled
:deadline
))))
6166 (setq entries
(delq nil entries
))
6167 ;; Map thru entries and find if we should filter them out
6170 (let* ((evt (org-trim (or (get-text-property 1 'txt x
) "")))
6171 (cat (get-text-property 1 'org-category x
))
6172 (tod (get-text-property 1 'time-of-day x
))
6173 (ok (or (null filter
)
6174 (and (stringp filter
) (string-match filter evt
))
6177 (cadr (assoc 'category filter
)) cat
)
6179 (cadr (assoc 'headline filter
)) evt
))))))
6180 ;; FIXME: Shall we remove text-properties for the appt text?
6181 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
6183 (setq tod
(concat "00" (number-to-string tod
))
6184 tod
(when (string-match
6185 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod
)
6186 (concat (match-string 1 tod
) ":"
6187 (match-string 2 tod
))))
6189 (setq cnt
(1+ cnt
))))) entries
)
6190 (org-release-buffers org-agenda-new-buffers
)
6192 (message "No event to add")
6193 (message "Added %d event%s for today" cnt
(if (> cnt
1) "s" "")))))
6195 (defun org-agenda-todayp (date)
6196 "Does DATE mean today, when considering `org-extend-today-until'?"
6198 (if (listp date
) (setq date
(calendar-absolute-from-gregorian date
)))
6199 (setq today
(calendar-absolute-from-gregorian (calendar-current-date)))
6200 (setq h
(nth 2 (decode-time (current-time))))
6201 (or (and (>= h org-extend-today-until
)
6203 (and (< h org-extend-today-until
)
6204 (= date
(1- today
))))))
6206 (provide 'org-agenda
)
6208 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
6210 ;;; org-agenda.el ends here